index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="container" :style="appThemeStyle">
  3. <!-- 表单 -->
  4. <view class="submit-form">
  5. <!-- 页面头部 -->
  6. <view class="header">
  7. <view class="title">
  8. <text>绑定您的手机号</text>
  9. </view>
  10. <view class="sub-title">
  11. <text>为了更好的服务您,请绑定手机号</text>
  12. </view>
  13. </view>
  14. <!-- 手机号 -->
  15. <view class="form-item">
  16. <input class="form-item--input" type="number" v-model="mobile" maxlength="11" placeholder="请输入手机号码" />
  17. </view>
  18. <!-- 图形验证码 -->
  19. <!-- <view class="form-item">
  20. <input class="form-item--input" type="text" v-model="captchaCode" maxlength="5" placeholder="请输入图形验证码" />
  21. <view class="form-item--parts">
  22. <view class="captcha" @click="getCaptcha()">
  23. <image class="image" :src="captcha.base64"></image>
  24. </view>
  25. </view>
  26. </view> -->
  27. <!-- 短信验证码 -->
  28. <view class="form-item">
  29. <input class="form-item--input" type="number" v-model="smsCode" maxlength="6" placeholder="请输入短信验证码" />
  30. <view class="form-item--parts">
  31. <view class="captcha-sms" @click="handelSmsCaptcha()">
  32. <text v-if="!smsState" class="activate">获取验证码</text>
  33. <text v-else class="un-activate">重新发送({{ times }})秒</text>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 页面头部 -->
  38. <!-- <view class="header shiming">
  39. <view class="title">
  40. <text>绑定您的证件信息</text>
  41. </view>
  42. <view class="sub-title">
  43. <text>为了更好的服务您,实名您的信息</text>
  44. </view>
  45. </view> -->
  46. </view>
  47. <!-- 确认绑定 -->
  48. <view class="submit-button" @click="handleSubmit()">
  49. <text>确认绑定</text>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import store from '@/store'
  55. import * as UserApi from '@/api/user'
  56. import * as CaptchaApi from '@/api/captcha'
  57. import * as Verify from '@/utils/verify'
  58. import * as AppApi from '@/api/app'
  59. import storage from '@/utils/storage'
  60. // 倒计时时长(秒)
  61. const times = 60
  62. // 表单验证场景
  63. const GET_CAPTCHA = 10
  64. const FORM_SUBMIT = 20
  65. export default {
  66. data() {
  67. return {
  68. // 正在加载
  69. isLoading: false,
  70. // 图形验证码信息
  71. captcha: {},
  72. // 短信验证码发送状态
  73. smsState: false,
  74. // 倒计时
  75. times,
  76. // 手机号
  77. mobile: '',
  78. // 图形验证码
  79. captchaCode: '',
  80. // 短信验证码
  81. smsCode: ''
  82. }
  83. },
  84. /**
  85. * 生命周期函数--监听页面加载
  86. */
  87. created() {
  88. // 获取图形验证码
  89. // this.getCaptcha()
  90. },
  91. methods: {
  92. // 获取图形验证码
  93. getCaptcha() {
  94. const app = this
  95. CaptchaApi.image().then((result) => (app.captcha = result.data))
  96. },
  97. // 点击发送短信验证码
  98. handelSmsCaptcha() {
  99. const app = this
  100. if (!app.isLoading && !app.smsState && app.formValidation(GET_CAPTCHA)) {
  101. app.sendSmsCaptcha()
  102. }
  103. },
  104. // 表单验证
  105. formValidation(scene = GET_CAPTCHA) {
  106. const app = this
  107. // 验证获取短信验证码
  108. if (scene === GET_CAPTCHA) {
  109. if (!app.validteMobile(app.mobile)) {
  110. return false
  111. }
  112. }
  113. // 验证表单提交
  114. if (scene === FORM_SUBMIT) {
  115. if (!app.validteMobile(app.mobile) || !app.validteSmsCode(app.smsCode)) {
  116. return false
  117. }
  118. }
  119. return true
  120. },
  121. // 验证手机号
  122. validteMobile(str) {
  123. if (Verify.isEmpty(str)) {
  124. this.$toast('请先输入手机号')
  125. return false
  126. }
  127. if (!Verify.isMobile(str)) {
  128. this.$toast('请输入正确格式的手机号')
  129. return false
  130. }
  131. return true
  132. },
  133. // 验证图形验证码
  134. validteCaptchaCode(str) {
  135. if (Verify.isEmpty(str)) {
  136. this.$toast('请先输入图形验证码')
  137. return false
  138. }
  139. return true
  140. },
  141. // 验证短信验证码
  142. validteSmsCode(str) {
  143. if (Verify.isEmpty(str)) {
  144. this.$toast('请先输入短信验证码')
  145. return false
  146. }
  147. return true
  148. },
  149. // 请求发送短信验证码接口
  150. sendSmsCaptcha() {
  151. const app = this
  152. app.isLoading = true
  153. AppApi.getPalList()
  154. .then((result) => {
  155. // 显示发送成功
  156. app.$toast(result.message)
  157. // 执行定时器
  158. app.timer()
  159. })
  160. .finally(() => {
  161. // 显示发送成功
  162. app.$toast('发送成功')
  163. // 执行定时器
  164. app.timer()
  165. app.isLoading = false
  166. })
  167. },
  168. // 执行定时器
  169. timer() {
  170. const app = this
  171. app.smsState = true
  172. const inter = setInterval(() => {
  173. app.times = app.times - 1
  174. if (app.times <= 0) {
  175. app.smsState = false
  176. app.times = times
  177. clearInterval(inter)
  178. }
  179. }, 1000)
  180. },
  181. // 点击提交
  182. handleSubmit() {
  183. const app = this
  184. if (!app.isLoading && app.formValidation(FORM_SUBMIT)) {
  185. app.onSubmitEvent()
  186. }
  187. },
  188. // 确认提交事件
  189. onSubmitEvent() {
  190. const app = this
  191. app.isLoading = true
  192. AppApi.bindCustomer({'customerid.value': storage.get('wx_userid'), customertel: app.mobile, code: app.smsCode})
  193. .then((result) => {
  194. console.log(result, 'result')
  195. // 显示操作成功
  196. app.$toast('绑定成功')
  197. // 跳转回原页面
  198. setTimeout(() => {
  199. this.$navTo('pages/user/index')
  200. }, 1000)
  201. })
  202. .finally(() => (app.isLoading = false))
  203. },
  204. /**
  205. * 提交成功-跳转回原页面
  206. */
  207. onNavigateBack(delta) {
  208. uni.navigateBack({
  209. delta: Number(delta || 1)
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .container {
  217. padding: 30rpx 60rpx;
  218. min-height: 100vh;
  219. background-color: #fff;
  220. }
  221. // 页面头部
  222. .header {
  223. margin-bottom: 50rpx;
  224. .title {
  225. color: #191919;
  226. font-size: 50rpx;
  227. }
  228. .sub-title {
  229. margin-top: 20rpx;
  230. color: #b3b3b3;
  231. font-size: 25rpx;
  232. }
  233. }
  234. .shiming {
  235. margin-top: 90rpx;
  236. }
  237. // 输入框元素
  238. .form-item {
  239. display: flex;
  240. padding: 18rpx;
  241. border-bottom: 1rpx solid #f3f1f2;
  242. border-bottom: 2px solid #f3f1f2;
  243. margin-bottom: 25rpx;
  244. height: 96rpx;
  245. &--input {
  246. font-size: 30rpx;
  247. letter-spacing: 1rpx;
  248. flex: 1;
  249. height: 100%;
  250. }
  251. &--parts {
  252. min-width: 100rpx;
  253. height: 100%;
  254. }
  255. // 图形验证码
  256. .captcha {
  257. height: 100%;
  258. .image {
  259. display: block;
  260. width: 192rpx;
  261. height: 100%;
  262. }
  263. }
  264. // 短信验证码
  265. .captcha-sms {
  266. font-size: 30rpx;
  267. line-height: 50rpx;
  268. padding-right: 20rpx;
  269. .activate {
  270. color: #ff9200;
  271. }
  272. .un-activate {
  273. color: #9e9e9e;
  274. }
  275. }
  276. }
  277. // 提交按钮
  278. .submit-button {
  279. width: 100%;
  280. height: 86rpx;
  281. margin-top: 70rpx;
  282. background: linear-gradient(to right, $main-bg, $main-bg2);
  283. color: $main-text;
  284. border-radius: 80rpx;
  285. box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.1);
  286. letter-spacing: 5rpx;
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. background-image: linear-gradient(to right, #f1b92b 0%, #f5a520 100%);
  291. }
  292. </style>