index.vue 5.7 KB

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