index.vue 5.2 KB

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