index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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: true, //弹窗
  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. }
  159. },
  160. /**
  161. * 查询用户
  162. */
  163. async selectUser(code) {
  164. const res = await this.$myRequest({
  165. host: this.ceshi,
  166. url: '/HotWaters/wpget_stu.action',
  167. method: 'POST',
  168. header: {
  169. 'content-type': 'application/x-www-form-urlencoded'
  170. },
  171. data: {
  172. code: code
  173. }
  174. })
  175. // console.log(res);
  176. if (res.data.mess == '未查询到用户信息') {
  177. this.showPop = true
  178. }
  179. }
  180. }
  181. }
  182. </script>
  183. <style scoped lang="scss">
  184. .container {
  185. display: flex;
  186. flex-direction: column;
  187. width: 750rpx;
  188. font-family: Microsoft YaHei-3970(82674968);
  189. color: #333333;
  190. .banner {
  191. width: 100%;
  192. height: 360rpx;
  193. image {
  194. width: 100%;
  195. height: 100%;
  196. }
  197. }
  198. .nav {
  199. position: relative;
  200. width: 100%;
  201. .menu,
  202. .reset {
  203. margin: 25rpx auto;
  204. width: 640rpx;
  205. }
  206. .menu_item {
  207. display: inline-flex;
  208. flex-direction: column;
  209. text-align: center;
  210. width: 25%;
  211. padding: 30rpx 0 39rpx;
  212. border-radius: 20rpx;
  213. font-family: Microsoft YaHei-3970(82674968);
  214. color: #333333;
  215. image {
  216. width: 90rpx;
  217. height: 90rpx;
  218. margin: 0 auto;
  219. }
  220. text {
  221. height: 29rpx;
  222. line-height: 54rpx;
  223. font-size: 30rpx;
  224. color: #333333;
  225. }
  226. }
  227. }
  228. .banding-bg {
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. position: fixed;
  233. width: 750rpx;
  234. height: 1500rpx;
  235. background: rgba(0, 0, 0, 0.5);
  236. .banding-model {
  237. display: flex;
  238. flex-direction: column;
  239. justify-content: flex-start;
  240. background-color: #FFFFFF;
  241. position: fixed;
  242. left: 25rpx;
  243. top: 300rpx;
  244. width: 650rpx;
  245. border-radius: 15rpx;
  246. padding: 30rpx;
  247. .title-model {
  248. font-size: 46rpx;
  249. font-weight: bold;
  250. padding: 20rpx 0 20rpx 30rpx;
  251. }
  252. .lineGroup-model {
  253. display: flex;
  254. flex-direction: row;
  255. box-shadow: none;
  256. border-bottom: 1px solid #c2c2c2;
  257. font-size: 38rpx;
  258. white-space: nowrap;
  259. .label-icon-model {
  260. display: flex;
  261. flex-direction: row;
  262. align-items: center;
  263. font-size: 58rpx;
  264. width: 88rpx;
  265. height: 108rpx;
  266. line-height: 108rpx;
  267. color: $my-color-primary;
  268. margin: 22rpx 0 0 50rpx;
  269. }
  270. .input-model {
  271. margin-top: 20rpx;
  272. color: #00c200;
  273. height: 108rpx;
  274. line-height: 108rpx;
  275. }
  276. }
  277. .btn-model {
  278. display: flex;
  279. justify-content: center;
  280. align-items: center;
  281. padding: 50rpx;
  282. .btn {
  283. width: 280rpx;
  284. height: 110rpx;
  285. line-height: 110rpx;
  286. background-color: $my-color-primary;
  287. border-radius: 15rpx;
  288. font-size: 38rpx;
  289. text-align: center;
  290. color: #FFFFFF;
  291. }
  292. }
  293. }
  294. }
  295. }
  296. </style>