bindPhone.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="container">
  3. <view class="card-wrapper">
  4. <!-- 顶部蓝色卡片 -->
  5. <view class="top-card">
  6. <view class="top-left">物联网智能抄表管理系统</view>
  7. <picker @change="changeCity" :value="cityIndex" :range="cityList">
  8. <view class="top-right">{{ cityList.length > 0 ? cityList[cityIndex] : '请选择城市' }}</view>
  9. </picker>
  10. </view>
  11. <!-- 缴费单位 -->
  12. <view class="unit-section">
  13. <text class="label">缴费单位</text>
  14. <picker @change="changeCompany" :value="companyIndex" :range="companyList">
  15. <view class="unit-box">
  16. <text class="unit-name">{{ companyList.length > 0 ? companyList[companyIndex] : '请选择缴纳单位' }}</text>
  17. <text class="arrow">></text>
  18. </view>
  19. </picker>
  20. </view>
  21. <!-- 电话输入 -->
  22. <view class="input-section">
  23. <text class="label">电话号码</text>
  24. <input type="text" placeholder="请输入电话号码" v-model="phone" class="input" />
  25. </view>
  26. <!-- 密码输入 -->
  27. <view class="input-section">
  28. <text class="label">用户密码</text>
  29. <input type="text" password placeholder="请输入用户密码" v-model="password" class="input" />
  30. </view>
  31. <!-- 协议 -->
  32. <view class="agreement">
  33. <checkbox :checked="checked" @click="checked = !checked" />
  34. <text>同意</text>
  35. <navigator url="/pages/agreement/index">
  36. <text class="link" @tap="gotourl('/pages/agreement/payfees')">《缴费协议》</text>
  37. </navigator>
  38. </view>
  39. <!-- 提交按钮 -->
  40. <button type="primary" class="confirm-btn" :loading="loading" @click="bindPhone">确定绑定</button>
  41. </view>
  42. </view>
  43. </template>
  44. <script setup>
  45. import { ref } from 'vue'
  46. import { post, get } from '@/utils/request'
  47. import { onLoad } from '@dcloudio/uni-app'
  48. const phone = ref('')
  49. const password = ref('')
  50. const checked = ref(false)
  51. const loading = ref(false)
  52. const cityList = ref([]);
  53. const cityIndex = ref(0);
  54. const changeCity = e => {
  55. cityIndex.value = e.detail.value
  56. }
  57. const companyList = ref([]);
  58. const companyIndex = ref(0)
  59. const changeCompany = e => {
  60. companyIndex.value = e.detail.value
  61. }
  62. const gotourl = (text) => {
  63. uni.navigateTo({
  64. url: text
  65. });
  66. }
  67. const bindPhone = async () => {
  68. if (!phone.value) {
  69. return uni.showToast({ title: '请输入手机号', icon: 'none' })
  70. }
  71. if (!/^1[3-9]\d{9}$/.test(phone.value)) {
  72. return uni.showToast({ title: '手机号格式不正确', icon: 'none' })
  73. }
  74. if (!password.value) {
  75. return uni.showToast({ title: '请输入用户密码', icon: 'none' })
  76. }
  77. if (!checked.value) {
  78. return uni.showToast({ title: '请同意协议', icon: 'none' })
  79. }
  80. loading.value = true
  81. try {
  82. const res = await get('/api/waterUser/findByPhoneNumber', {
  83. phoneNumber: phone.value,
  84. password: password.value
  85. })
  86. // 这里根据接口返回数据继续判断
  87. if (res.code === '200') {
  88. uni.showToast({ title: '绑定成功', icon: 'success' })
  89. const userInfoStr = encodeURIComponent(JSON.stringify(res.data))
  90. // 存储用户信息
  91. uni.setStorageSync('userInfo', res.data)
  92. // 关闭所有页面,跳转首页
  93. uni.navigateTo({
  94. url: '/pages/index/index'
  95. })
  96. } else {
  97. uni.showToast({ title: res.message || '绑定失败', icon: 'none' })
  98. }
  99. } catch (err) {
  100. // console.log('请求失败:', err)
  101. uni.showToast({ title: '请求失败,请稍后重试', icon: 'none' })
  102. } finally {
  103. loading.value = false
  104. }
  105. }
  106. const getCity = async () => {
  107. try {
  108. const res = await get('/api/communityManage/getCity')
  109. // 这里根据接口返回数据继续判断
  110. if (res.code === '200') {
  111. cityList.value = res.data.map(item => item.name)
  112. cityIndex.value = 0
  113. } else {
  114. uni.showToast({ title: res.message || '获取失败', icon: 'none' })
  115. }
  116. } catch (err) {
  117. // console.log('请求失败:', err)
  118. uni.showToast({ title: '请求失败,请稍后重试', icon: 'none' })
  119. }
  120. }
  121. const getCompany = async () => {
  122. try {
  123. const res = await get('/api/companyManage/findAll')
  124. // 这里根据接口返回数据继续判断
  125. if (res.code === '200') {
  126. companyList.value = res.data.map(item => item.companyName)
  127. cityIndex.value = 0
  128. } else {
  129. uni.showToast({ title: res.message || '获取失败', icon: 'none' })
  130. }
  131. } catch (err) {
  132. // console.log('请求失败:', err)
  133. uni.showToast({ title: '请求失败,请稍后重试', icon: 'none' })
  134. }
  135. }
  136. onLoad((options) => {
  137. if (options.phone) {
  138. phone.value = decodeURIComponent(options.phone); // 解码手机号
  139. // console.log('接收到的手机号:', phone.value);
  140. }
  141. getCity()
  142. getCompany()
  143. })
  144. </script>
  145. <style scoped>
  146. .container {
  147. background-color: #f5f5f5;
  148. min-height: 100vh;
  149. padding: 30rpx;
  150. box-sizing: border-box;
  151. }
  152. .card-wrapper {
  153. background-color: #ffffff;
  154. border-radius: 20rpx;
  155. padding: 0rpx 0rpx 60rpx 0rpx;
  156. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  157. }
  158. .top-card {
  159. background: linear-gradient(to right, #6ca3fe, #3f83fd);
  160. border-radius: 20rpx 20rpx 0rpx 0rpx;
  161. padding: 20rpx 20px 30px 20px;
  162. color: white;
  163. display: flex;
  164. justify-content: space-between;
  165. align-items: center;
  166. }
  167. .top-left {
  168. font-size: 26rpx;
  169. }
  170. .top-right {
  171. background: white;
  172. color: #2979ff;
  173. padding: 10rpx 20rpx;
  174. border-radius: 8rpx;
  175. font-size: 24rpx;
  176. }
  177. .unit-section {
  178. padding: 20px 30rpx;
  179. border-radius: 20rpx 20rpx 0rpx 0rpx;
  180. margin-top: -20px;
  181. background: #ffffff;
  182. }
  183. .label {
  184. font-size: 28rpx;
  185. color: #b5b5b5;
  186. margin-bottom: 10rpx;
  187. display: block;
  188. }
  189. .unit-box {
  190. border-radius: 12rpx;
  191. font-weight: 600;
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. }
  196. .unit-name {
  197. font-size: 30rpx;
  198. }
  199. .arrow {
  200. font-size: 34rpx;
  201. color: #999;
  202. }
  203. .input-section {
  204. padding: 20rpx 30rpx;
  205. }
  206. .input {
  207. padding: 17rpx;
  208. border: 1px solid #ccc;
  209. border-radius: 12rpx;
  210. font-size: 28rpx;
  211. }
  212. .agreement {
  213. display: flex;
  214. align-items: center;
  215. margin-bottom: 40rpx;
  216. font-size: 26rpx;
  217. padding: 0 30rpx;
  218. margin-top: 40rpx;
  219. }
  220. .link {
  221. color: #2979ff;
  222. margin-left: 10rpx;
  223. }
  224. .confirm-btn {
  225. width: calc(100% - 40rpx);
  226. margin: 0 20rpx;
  227. border-radius: 35rpx;
  228. background: linear-gradient(to bottom, #6ca3fe, #3f83fd);
  229. color: white;
  230. font-size: 30rpx;
  231. }
  232. </style>