index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. <modal v-if="showPop" title="请输入学号、身份证号" confirm-text="确定" cancel-text="取消" @cancel="cancelPop"
  20. @confirm="confirmPop">
  21. <view class="">学号:</view>
  22. <input type='text' class="stu-number" maxlength="14" placeholder="请输入学号" v-model="stu_number" />
  23. <view class="">身份证号:</view>
  24. <input type='text' class="stu-number" maxlength="18" placeholder="请输入身份证号" v-model="id_card" />
  25. </modal>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. code: '',
  33. showPop: false, //弹窗
  34. // stu_number: '20210210140101',
  35. // id_card: '88888888',
  36. stu_number: '',
  37. id_card: '',
  38. ceshi: 'code'
  39. }
  40. },
  41. onLoad() {
  42. // 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
  43. this.getCode()
  44. },
  45. methods: {
  46. /**
  47. * 控制环境,test为true测试环境,false则是正式环境
  48. */
  49. async isTestEnvironment() {
  50. const res = await this.$myRequest({
  51. host: this.ceshi,
  52. url: '/',
  53. method: 'POST',
  54. header: {
  55. 'content-type': 'application/x-www-form-urlencoded'
  56. }
  57. })
  58. // console.log(res.data.mess);
  59. // if (res.data.mess == '绑定成功') {
  60. // this.$store.state.test = res.data.test
  61. // }
  62. },
  63. /**
  64. * 弹窗
  65. */
  66. confirmPop() { //确认
  67. if (this.stu_number.length == 14 && this.id_card.length == 18) {
  68. this.showPop = false
  69. // 获得code
  70. this.getCode('confirm')
  71. } else {
  72. uni.showToast({
  73. title: '学号长度错误 或 身份证号 长度错误!',
  74. icon: 'none'
  75. });
  76. }
  77. },
  78. cancelPop() { //取消
  79. // this.stu_number = ''
  80. // this.showPop = false
  81. },
  82. // 获得code
  83. getCode(param) {
  84. uni.login({
  85. success: (res) => {
  86. // console.log('index', res);
  87. if (res.code) {
  88. // 请求服务器,获得openid
  89. if (param == 'confirm')
  90. this.getOpenId(res.code)
  91. else
  92. this.selectUser(res.code)
  93. } else {
  94. uni.showToast({
  95. title: res.errMsg,
  96. icon: 'none'
  97. });
  98. }
  99. }
  100. })
  101. },
  102. /**
  103. * 请求服务器,获得openid
  104. */
  105. async getOpenId(code) {
  106. const res = await this.$myRequest({
  107. host: this.ceshi,
  108. url: '/HotWaters/wpopenid.action',
  109. method: 'POST',
  110. header: {
  111. 'content-type': 'application/x-www-form-urlencoded'
  112. },
  113. data: {
  114. code: code,
  115. stu_number: this.stu_number,
  116. id_card: this.id_card
  117. }
  118. })
  119. // console.log(res.data.mess);
  120. if (res.data.mess == '绑定成功') {
  121. uni.showToast({
  122. title: '用户绑定成功!',
  123. icon: 'success'
  124. });
  125. } else {
  126. uni.showToast({
  127. title: res.data.mess,
  128. icon: 'success'
  129. });
  130. }
  131. },
  132. /**
  133. * 查询用户
  134. */
  135. async selectUser(code) {
  136. const res = await this.$myRequest({
  137. host: this.ceshi,
  138. url: '/HotWaters/wpget_stu.action',
  139. method: 'POST',
  140. header: {
  141. 'content-type': 'application/x-www-form-urlencoded'
  142. },
  143. data: {
  144. code: code
  145. }
  146. })
  147. // console.log(res);
  148. if (res.data.mess == '未查询到用户信息') {
  149. this.showPop = true
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .container {
  157. display: flex;
  158. flex-direction: column;
  159. width: 750rpx;
  160. font-family: Microsoft YaHei-3970(82674968);
  161. color: #333333;
  162. .banner {
  163. width: 100%;
  164. height: 360rpx;
  165. image {
  166. width: 100%;
  167. height: 100%;
  168. }
  169. }
  170. .nav {
  171. position: relative;
  172. width: 100%;
  173. .menu,
  174. .reset {
  175. margin: 25rpx auto;
  176. width: 640rpx;
  177. }
  178. .menu_item {
  179. display: inline-flex;
  180. flex-direction: column;
  181. text-align: center;
  182. width: 25%;
  183. padding: 30rpx 0 39rpx;
  184. border-radius: 20rpx;
  185. font-family: Microsoft YaHei-3970(82674968);
  186. color: #333333;
  187. image {
  188. width: 90rpx;
  189. height: 90rpx;
  190. margin: 0 auto;
  191. }
  192. text {
  193. height: 29rpx;
  194. line-height: 54rpx;
  195. font-size: 30rpx;
  196. color: #333333;
  197. }
  198. }
  199. }
  200. .stu-number {
  201. margin-top: 20rpx;
  202. color: #00c200;
  203. text-align: center;
  204. font-size: 38rpx;
  205. font-weight: bold;
  206. height: 50rpx;
  207. line-height: 50rpx;
  208. }
  209. }
  210. </style>