index.vue 5.7 KB

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