index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="container">
  3. <view class="banner">
  4. <image src="../../static/images/banner2x.png" mode=""></image>
  5. </view>
  6. <view class="nav">
  7. <view class="menu">
  8. <navigator :url="'/pages/reshui/reshui'" open-type="redirect" class="menu_item">
  9. <image src="../../static/images/shower2x.png" mode=""></image>
  10. <text>洗 浴</text>
  11. </navigator>
  12. <navigator :url="'/pages/jiaofei/jiaofei?o=index'" open-type="redirect" class="menu_item">
  13. <image src="../../static/images/recharge2x.png" mode=""></image>
  14. <text>电费充值</text>
  15. </navigator>
  16. </view>
  17. </view>
  18. <!--弹窗-->
  19. <view class="banding-bg" v-if="showPop">
  20. <view class="banding-model">
  21. <view class="title-model">绑定</view>
  22. <view class="lineGroup-model">
  23. <text class="iconfont icon-shengchengmingpianicon label-icon-model"></text>
  24. <input type='number' class="input-model" maxlength="14" placeholder="请输入学号" v-model="stu_number" />
  25. </view>
  26. <view class="lineGroup-model">
  27. <text class="iconfont icon-cardid label-icon-model"></text>
  28. <input type='number' class="input-model" maxlength="18" placeholder="请输入身份证号码" v-model="id_card" />
  29. </view>
  30. <view class="btn-model">
  31. <button class="btn" @tap="confirmPop">绑定</button>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. code: '',
  42. showPop: true, //弹窗
  43. stu_number: '',
  44. id_card: '',
  45. ceshi: 'code',
  46. huanjing: '部署环境' // 部署环境是key,用来获取环境
  47. }
  48. },
  49. onLoad() {
  50. // 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
  51. this.isTestEnvironment()
  52. },
  53. methods: {
  54. /**
  55. * 控制环境,test为true测试环境,false则是正式环境
  56. */
  57. async isTestEnvironment() {
  58. const res = await this.$myRequest({
  59. host: this.ceshi,
  60. url: '/HotWaters/conEnvi.action',
  61. method: 'POST',
  62. header: {
  63. 'content-type': 'application/x-www-form-urlencoded'
  64. },
  65. data: {
  66. name: this.huanjing
  67. }
  68. })
  69. // console.log(res);
  70. if (res.data.mess == '返回成功') {
  71. // 0 测试环境, 1 部署环境
  72. if (res.data.data[0].value == 0) {
  73. this.$store.state.test = true
  74. } else {
  75. this.$store.state.test = false
  76. }
  77. } else {
  78. uni.showToast({
  79. title: res.data.mess,
  80. icon: 'success'
  81. });
  82. }
  83. // 获取code
  84. this.getCode()
  85. },
  86. /**
  87. * 弹窗
  88. */
  89. confirmPop() { // 确认
  90. if (this.stu_number.length == 14 && this.id_card.length == 18) {
  91. this.showPop = false
  92. // 获得code
  93. this.getCode('confirm')
  94. } else {
  95. uni.showToast({
  96. title: '学号长度错误 或 身份证号 长度错误!',
  97. icon: 'none'
  98. });
  99. }
  100. },
  101. /**
  102. * param获得code
  103. */
  104. getCode(param) {
  105. uni.login({
  106. success: (res) => {
  107. // console.log('index', res);
  108. if (res.code) {
  109. if (param == 'confirm')
  110. // 请求服务器,获得openid
  111. this.getOpenId(res.code)
  112. else
  113. this.selectUser(res.code)
  114. } else {
  115. uni.showToast({
  116. title: res.errMsg,
  117. icon: 'none'
  118. });
  119. this.showPop = true
  120. }
  121. }
  122. })
  123. },
  124. /**
  125. * 请求服务器,获得openid
  126. */
  127. async getOpenId(code) {
  128. if (this.stu_number == '' || this.id_card == '') {
  129. uni.showToast({
  130. title: '学号或身份证号为空'
  131. });
  132. return
  133. }
  134. const res = await this.$myRequest({
  135. host: this.ceshi,
  136. url: '/HotWaters/wpopenid.action',
  137. method: 'POST',
  138. header: {
  139. 'content-type': 'application/x-www-form-urlencoded'
  140. },
  141. data: {
  142. code: code,
  143. stu_number: this.stu_number,
  144. id_card: this.id_card
  145. }
  146. })
  147. // console.log(res.data.mess);
  148. if (res.data.mess == '绑定成功') {
  149. uni.showToast({
  150. title: '用户绑定成功!',
  151. icon: 'success'
  152. });
  153. } else {
  154. uni.showToast({
  155. title: res.data.mess,
  156. icon: 'success'
  157. });
  158. this.showPop = true
  159. }
  160. },
  161. /**
  162. * 查询用户
  163. */
  164. async selectUser(code) {
  165. const res = await this.$myRequest({
  166. host: this.ceshi,
  167. url: '/HotWaters/wpget_stu.action',
  168. method: 'POST',
  169. header: {
  170. 'content-type': 'application/x-www-form-urlencoded'
  171. },
  172. data: {
  173. code: code
  174. }
  175. })
  176. // console.log(res);
  177. if (res.data.mess == '未查询到用户信息') {
  178. this.showPop = true
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style scoped lang="scss">
  185. .container {
  186. display: flex;
  187. flex-direction: column;
  188. width: 750rpx;
  189. font-family: Microsoft YaHei-3970(82674968);
  190. color: #333333;
  191. .banner {
  192. width: 100%;
  193. height: 360rpx;
  194. image {
  195. width: 100%;
  196. height: 100%;
  197. }
  198. }
  199. .nav {
  200. position: relative;
  201. width: 100%;
  202. .menu,
  203. .reset {
  204. margin: 25rpx auto;
  205. width: 640rpx;
  206. }
  207. .menu_item {
  208. display: inline-flex;
  209. flex-direction: column;
  210. text-align: center;
  211. width: 25%;
  212. padding: 30rpx 0 39rpx;
  213. border-radius: 20rpx;
  214. font-family: Microsoft YaHei-3970(82674968);
  215. color: #333333;
  216. image {
  217. width: 90rpx;
  218. height: 90rpx;
  219. margin: 0 auto;
  220. }
  221. text {
  222. height: 29rpx;
  223. line-height: 54rpx;
  224. font-size: 30rpx;
  225. color: #333333;
  226. }
  227. }
  228. }
  229. .banding-bg {
  230. display: flex;
  231. justify-content: center;
  232. align-items: center;
  233. position: fixed;
  234. width: 750rpx;
  235. height: 1500rpx;
  236. background: rgba(0, 0, 0, 0.5);
  237. .banding-model {
  238. display: flex;
  239. flex-direction: column;
  240. justify-content: flex-start;
  241. background-color: #FFFFFF;
  242. position: fixed;
  243. left: 25rpx;
  244. top: 300rpx;
  245. width: 650rpx;
  246. border-radius: 15rpx;
  247. padding: 30rpx;
  248. .title-model {
  249. font-size: 46rpx;
  250. font-weight: bold;
  251. padding: 20rpx 0 20rpx 30rpx;
  252. }
  253. .lineGroup-model {
  254. display: flex;
  255. flex-direction: row;
  256. box-shadow: none;
  257. border-bottom: 1px solid #c2c2c2;
  258. font-size: 38rpx;
  259. white-space: nowrap;
  260. .label-icon-model {
  261. display: flex;
  262. flex-direction: row;
  263. align-items: center;
  264. font-size: 58rpx;
  265. width: 88rpx;
  266. height: 108rpx;
  267. line-height: 108rpx;
  268. color: $my-color-primary;
  269. margin: 22rpx 0 0 50rpx;
  270. }
  271. .input-model {
  272. margin-top: 20rpx;
  273. color: #00c200;
  274. height: 108rpx;
  275. line-height: 108rpx;
  276. }
  277. }
  278. .btn-model {
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. padding: 50rpx;
  283. .btn {
  284. width: 280rpx;
  285. height: 110rpx;
  286. line-height: 110rpx;
  287. background-color: $my-color-primary;
  288. border-radius: 15rpx;
  289. font-size: 38rpx;
  290. text-align: center;
  291. color: #FFFFFF;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. </style>