setting-telphone.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view class="container">
  3. <view class="login-wrap">
  4. <view class="login-form">
  5. <u--form
  6. labelPosition="left"
  7. :model="userInfo"
  8. :rules="rules"
  9. ref="form1"
  10. >
  11. <u-form-item
  12. label="手机号"
  13. prop="phonenumber"
  14. labelWidth="auto"
  15. labelAlign="right"
  16. >
  17. <u--input
  18. v-model="userInfo.phonenumber"
  19. placeholder="请输入手机号"
  20. border="bottom"
  21. type="number"
  22. maxlength="11"
  23. ></u--input>
  24. </u-form-item>
  25. <u-form-item
  26. labelWidth="auto"
  27. labelAlign="right"
  28. label="验证码"
  29. prop="smsCode"
  30. width="120"
  31. >
  32. <u--input
  33. v-model="userInfo.smsCode"
  34. disabledColor="#ffffff"
  35. placeholder="请输入验证码"
  36. border="bottom"
  37. maxlength="4"
  38. ></u--input>
  39. <template #right>
  40. <view class="identifying-code">
  41. <u-code
  42. ref="uCode3"
  43. @change="codeChange2"
  44. keep-running
  45. start-text="获取验证码"
  46. ></u-code>
  47. <text
  48. @tap="getCode2"
  49. :text="tips2"
  50. class="u-page__code-text"
  51. >{{ tips2 }}
  52. </text>
  53. </view>
  54. </template>
  55. </u-form-item>
  56. <view style="font-size: 26rpx">
  57. 请输入您在娇骄儿的会员手机号,如需要找回账号请点击
  58. <navigator url="/loginPages/login/retrieve-account">
  59. <text style="color: #007aff">找回账号</text>
  60. </navigator>
  61. </view>
  62. </u--form>
  63. </view>
  64. </view>
  65. <view v-if="errTipShow" class="h-err">
  66. <text>你输入的手机号码已存在,请换一个</text>
  67. </view>
  68. <view @click="setPhone()" class="op-btn-wrap">
  69. <view class="h-btn">
  70. <text>确定</text>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. errTipShow: false,
  80. errShow: false,
  81. userInfo: {
  82. auth: true,
  83. phonenumber: '',
  84. phone: '',
  85. smsCode: '',
  86. openId: '',
  87. password: "",
  88. transactionPassword: "",
  89. reference: "",
  90. type: '' // 实名认证创建新账号
  91. },
  92. tips2: '',
  93. rules: {
  94. phonenumber: [
  95. {
  96. required: true,
  97. min: 10,
  98. max: 12,
  99. message: '请输入11位电话号码',
  100. trigger: ['blur', 'change'],
  101. },
  102. {
  103. // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
  104. validator: (rule, value, callback) => {
  105. // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
  106. return !this.$isDataEmpty(value);
  107. },
  108. message: "请认真填写电话号码",
  109. trigger: ['blur', 'change'],
  110. }
  111. ],
  112. smsCode: {
  113. required: true,
  114. min: 4,
  115. max: 6,
  116. message: '请输入4位验证码',
  117. trigger: ['blur', 'change'],
  118. },
  119. },
  120. }
  121. },
  122. onLoad(option) {
  123. },
  124. onReady() {
  125. this.$refs.form1.setRules(this.rules)
  126. },
  127. methods: {
  128. getUserInfo() {
  129. this.$api.getUserInfo().then(res => {
  130. uni.setStorageSync('userInfo', res.data.data)
  131. })
  132. },
  133. // 验证电话号码是否存在
  134. saveSetPhoneData() {
  135. let that = this;
  136. // 验证电话号码是否存在
  137. this.$api.setPhone(this.userInfo).then((res) => {
  138. uni.showToast({
  139. title: '绑定成功'
  140. })
  141. this.getUserInfo()
  142. setTimeout(function () {
  143. // 绑定成功,返回我的页面
  144. uni.switchTab({
  145. url: '/pages/my/index',
  146. });
  147. }, 2000); // 延迟2秒执行
  148. }).catch(() => {
  149. uni.showToast({
  150. title: "操作失败"
  151. })
  152. });
  153. },
  154. // 去绑定账号密码页面
  155. setPhone() {
  156. let that = this;
  157. this.$refs.form1.validate().then(res => {
  158. that.saveSetPhoneData();
  159. }).catch(errors => {
  160. uni.$u.toast('校验失败,请认真填写')
  161. })
  162. },
  163. codeChange2(text) {
  164. this.tips2 = text;
  165. },
  166. getCode2() {
  167. let that = this;
  168. if (this.$refs.uCode3.canGetCode) {
  169. that.getSmsCode();
  170. } else {
  171. uni.$u.toast('倒计时结束后再发送');
  172. }
  173. },
  174. // 获取手机验证码
  175. getSmsCode() {
  176. let that = this;
  177. if (!this.userInfo.phonenumber) {
  178. uni.$u.toast('请认真填写手机号');
  179. return;
  180. }
  181. // 验证电话号码是否存在
  182. this.$api.phoneIsExist(this.userInfo).then((res) => {
  183. if (res.phoneIsExist) { // 存在
  184. that.errTipShow = true;
  185. setTimeout(() => {
  186. that.errTipShow = false;
  187. // 在这里编写延迟执行的代码
  188. that.userInfo.phonenumber = null;
  189. }, 3000);
  190. } else {
  191. that.getPhoneCode();
  192. }
  193. }).catch(() => {
  194. uni.showToast({
  195. title: "操作失败",
  196. duration: 3000
  197. })
  198. });
  199. },
  200. // 获取验证码
  201. getPhoneCode() {
  202. let that = this;
  203. // 模拟向后端请求验证码
  204. uni.showLoading({
  205. title: '正在获取验证码'
  206. })
  207. this.$api.getSmsCode({phonenumber: this.userInfo.phonenumber, auth: true}).then((res) => {
  208. uni.hideLoading();
  209. // 这里此提示会被this.start()方法中的提示覆盖
  210. uni.$u.toast('验证码已发送');
  211. // 通知验证码组件内部开始倒计时
  212. that.$refs.uCode3.start();
  213. }).catch(() => {
  214. uni.showToast({
  215. title: "操作失败"
  216. })
  217. });
  218. },
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. page, body {
  224. background: #fff;
  225. }
  226. .h-err {
  227. color: red;
  228. text-align: center;
  229. font-size: 14px;
  230. }
  231. .h-popo-content {
  232. height: 170px;
  233. padding: 12px;
  234. width: 300px;
  235. text-align: center;
  236. font-size: 14px;
  237. font-family: PingFangSC-Semibold, PingFang SC;
  238. .h-img {
  239. display: flex;
  240. justify-content: center;
  241. }
  242. .h-text {
  243. margin-top: 12px;
  244. font-weight: 400;
  245. color: #666666;
  246. }
  247. .text {
  248. margin-top: 6px;
  249. font-weight: 400;
  250. color: #666666;
  251. }
  252. .h-btn-wrap {
  253. display: flex;
  254. justify-content: space-between;
  255. color: #333333;
  256. text-align: center;
  257. margin-top: 14px;
  258. .h-left-btn {
  259. height: 32px;
  260. line-height: 30px;
  261. background: #EEEEEE;
  262. width: 100px;
  263. text-align: center;
  264. border-radius: 16px;
  265. margin: 0 auto;
  266. }
  267. .h-right-btn {
  268. height: 32px;
  269. line-height: 30px;
  270. background: #FFE05C;
  271. width: 100px;
  272. border-radius: 16px;
  273. margin: 0 auto;
  274. }
  275. }
  276. }
  277. .container {
  278. background: #fff;
  279. height: 300px;
  280. .login-wrap {
  281. display: flex;
  282. justify-content: center;
  283. .login-form {
  284. width: 90%;
  285. }
  286. .account {
  287. display: flex;
  288. }
  289. .identifying-code {
  290. }
  291. }
  292. .op-btn-wrap {
  293. margin-top: 30px;
  294. display: flex;
  295. justify-content: center;
  296. align-items: center;
  297. .h-btn {
  298. text-align: center;
  299. width: 343px;
  300. height: 42px;
  301. background: #FFE05C;
  302. border-radius: 27px;
  303. line-height: 42px;
  304. }
  305. }
  306. }
  307. </style>