setting-telphone.vue 7.6 KB

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