index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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='text' 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: false, //弹窗
  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. // 获得code
  92. this.getCode('confirm')
  93. } else {
  94. uni.showToast({
  95. title: '学号长度错误 或 身份证号 长度错误!',
  96. icon: 'none'
  97. });
  98. }
  99. },
  100. /**
  101. * param获得code
  102. */
  103. getCode(param) {
  104. uni.login({
  105. success: (res) => {
  106. // console.log('index', res);
  107. if (res.code) {
  108. if (param == 'confirm')
  109. // 请求服务器,获得openid
  110. this.getOpenId(res.code)
  111. else
  112. this.selectUser(res.code)
  113. } else {
  114. uni.showToast({
  115. title: res.errMsg,
  116. icon: 'none'
  117. });
  118. this.showPop = true
  119. }
  120. }
  121. })
  122. },
  123. /**
  124. * 请求服务器,获得openid
  125. */
  126. async getOpenId(code) {
  127. if (this.stu_number == '' || this.id_card == '') {
  128. uni.showToast({
  129. title: '学号或身份证号为空'
  130. });
  131. return
  132. }
  133. const res = await this.$myRequest({
  134. host: this.ceshi,
  135. url: '/HotWaters/wpopenid.action',
  136. method: 'POST',
  137. header: {
  138. 'content-type': 'application/x-www-form-urlencoded'
  139. },
  140. data: {
  141. code: code,
  142. stu_number: this.stu_number,
  143. id_card: this.id_card
  144. }
  145. })
  146. // console.log(res.data.mess);
  147. if (res.data.mess == '绑定成功') {
  148. uni.showToast({
  149. title: '用户绑定成功!',
  150. icon: 'success'
  151. });
  152. this.showPop = false
  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. } else {
  180. this.showPop = false
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style scoped lang="scss">
  187. .container {
  188. display: flex;
  189. flex-direction: column;
  190. width: 750rpx;
  191. font-family: Microsoft YaHei-3970(82674968);
  192. color: #333333;
  193. .banner {
  194. width: 100%;
  195. height: 360rpx;
  196. image {
  197. width: 100%;
  198. height: 100%;
  199. }
  200. }
  201. .nav {
  202. position: relative;
  203. width: 100%;
  204. .menu,
  205. .reset {
  206. margin: 25rpx auto;
  207. width: 640rpx;
  208. }
  209. .menu_item {
  210. display: inline-flex;
  211. flex-direction: column;
  212. text-align: center;
  213. width: 25%;
  214. padding: 30rpx 0 39rpx;
  215. border-radius: 20rpx;
  216. font-family: Microsoft YaHei-3970(82674968);
  217. color: #333333;
  218. image {
  219. width: 90rpx;
  220. height: 90rpx;
  221. margin: 0 auto;
  222. }
  223. text {
  224. height: 29rpx;
  225. line-height: 54rpx;
  226. font-size: 30rpx;
  227. color: #333333;
  228. }
  229. }
  230. }
  231. .banding-bg {
  232. display: flex;
  233. justify-content: center;
  234. align-items: center;
  235. position: fixed;
  236. width: 750rpx;
  237. height: 1500rpx;
  238. background: rgba(0, 0, 0, 0.5);
  239. .banding-model {
  240. display: flex;
  241. flex-direction: column;
  242. justify-content: flex-start;
  243. background-color: #FFFFFF;
  244. position: fixed;
  245. left: 25rpx;
  246. top: 300rpx;
  247. width: 650rpx;
  248. border-radius: 15rpx;
  249. padding: 30rpx;
  250. .title-model {
  251. font-size: 46rpx;
  252. font-weight: bold;
  253. padding: 20rpx 0 20rpx 30rpx;
  254. }
  255. .lineGroup-model {
  256. display: flex;
  257. flex-direction: row;
  258. box-shadow: none;
  259. border-bottom: 1px solid #c2c2c2;
  260. font-size: 38rpx;
  261. white-space: nowrap;
  262. .label-icon-model {
  263. display: flex;
  264. flex-direction: row;
  265. align-items: center;
  266. font-size: 58rpx;
  267. width: 88rpx;
  268. height: 108rpx;
  269. line-height: 108rpx;
  270. color: $my-color-primary;
  271. margin: 22rpx 0 0 50rpx;
  272. }
  273. .input-model {
  274. margin-top: 20rpx;
  275. color: #00c200;
  276. height: 108rpx;
  277. line-height: 108rpx;
  278. }
  279. }
  280. .btn-model {
  281. display: flex;
  282. justify-content: center;
  283. align-items: center;
  284. padding: 50rpx;
  285. .btn {
  286. width: 280rpx;
  287. height: 110rpx;
  288. line-height: 110rpx;
  289. background-color: $my-color-primary;
  290. border-radius: 15rpx;
  291. font-size: 38rpx;
  292. text-align: center;
  293. color: #FFFFFF;
  294. }
  295. }
  296. }
  297. }
  298. }
  299. </style>