setting-telphone.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. <!-- 确认绑定弹框-->
  75. <uni-popup ref="popupMigrate" :isMaskClick="false">
  76. <view class="popup-content">
  77. <view style="text-align: center">
  78. <view class="text">当前会员编号为{{ storageUserInfo.no }}</view>
  79. <text class="text">是否确认与该会员绑定并获取验证码?</text>
  80. </view>
  81. <view style="height:10px"></view>
  82. <view class="button-popup">
  83. <button class="h-btn" style="background-color: #EEEEEE;" @click="popupClose()">取消</button>
  84. <view class="h-btn" style="background-color: #FFE05C;" @click="getPhoneCode()"
  85. :disabled="currentStep === steps.length - 1">
  86. <text>确定</text>
  87. </view>
  88. </view>
  89. </view>
  90. </uni-popup>
  91. </view>
  92. </template>
  93. <script>
  94. export default {
  95. data() {
  96. return {
  97. errTipShow: false,
  98. errShow: false,
  99. userInfo: {
  100. auth: true,
  101. phonenumber: '',
  102. phone: '',
  103. smsCode: '',
  104. openId: '',
  105. password: "",
  106. transactionPassword: "",
  107. reference: "",
  108. type: '' // 实名认证创建新账号
  109. },
  110. tips2: '',
  111. storageUserInfo:{},
  112. rules: {
  113. phonenumber: [
  114. {
  115. required: true,
  116. min: 11,
  117. max: 11,
  118. message: '请输入11位电话号码',
  119. trigger: ['blur', 'change'],
  120. },
  121. {
  122. // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
  123. validator: (rule, value, callback) => {
  124. // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
  125. return !this.$isDataEmpty(value);
  126. },
  127. message: "请认真填写电话号码",
  128. trigger: ['blur', 'change'],
  129. }
  130. ],
  131. smsCode: {
  132. required: true,
  133. min: 4,
  134. max: 6,
  135. message: '请输入4位验证码',
  136. trigger: ['blur', 'change'],
  137. },
  138. },
  139. }
  140. },
  141. onLoad(option) {
  142. this.storageUserInfo = uni.getStorageSync('userInfo')
  143. },
  144. onReady() {
  145. this.$refs.form1.setRules(this.rules)
  146. },
  147. methods: {
  148. popupClose(){
  149. this.$refs.popupMigrate.close()
  150. },
  151. getUserInfo() {
  152. this.$api.getUserInfo().then(res => {
  153. uni.setStorageSync('userInfo', res.data.data)
  154. })
  155. },
  156. // 验证电话号码是否存在
  157. saveSetPhoneData() {
  158. let that = this;
  159. // 验证电话号码是否存在
  160. this.$api.setPhone(this.userInfo).then((res) => {
  161. uni.showToast({
  162. title: '绑定成功'
  163. })
  164. this.getUserInfo()
  165. setTimeout(function () {
  166. // 绑定成功,返回上一页
  167. uni.navigateBack({
  168. delta: 1,
  169. });
  170. }, 2000); // 延迟2秒执行
  171. })
  172. },
  173. // 去绑定账号密码页面
  174. setPhone() {
  175. let that = this;
  176. this.$refs.form1.validate().then(res => {
  177. that.saveSetPhoneData();
  178. }).catch(errors => {
  179. uni.$u.toast('校验失败,请认真填写')
  180. })
  181. },
  182. codeChange2(text) {
  183. this.tips2 = text;
  184. },
  185. getCode2() {
  186. let that = this;
  187. if (this.$refs.uCode3.canGetCode) {
  188. that.getSmsCode();
  189. } else {
  190. uni.$u.toast('倒计时结束后再发送');
  191. }
  192. },
  193. // 获取手机验证码
  194. getSmsCode() {
  195. console.log('cacacacacacaca', this.userInfo)
  196. let that = this;
  197. if (!this.userInfo.phonenumber) {
  198. uni.$u.toast('请认真填写手机号');
  199. return;
  200. }
  201. // 验证电话号码是否存在
  202. this.$api.phoneIsExist(this.userInfo).then((res) => {
  203. console.log(res.data.data.phoneIsExist)
  204. if (res.data.data.phoneIsExist) { // 存在
  205. that.errTipShow = true;
  206. setTimeout(() => {
  207. that.errTipShow = false;
  208. // 在这里编写延迟执行的代码
  209. that.userInfo.phonenumber = null;
  210. }, 3000);
  211. } else {
  212. this.$refs.popupMigrate.open()
  213. // that.getPhoneCode();
  214. }
  215. })
  216. },
  217. // 获取验证码
  218. getPhoneCode() {
  219. let that = this;
  220. that.$refs.popupMigrate.close()
  221. // 模拟向后端请求验证码
  222. uni.showLoading({
  223. title: '正在获取验证码'
  224. })
  225. this.$api.getSmsCodeByType({phonenumber: this.userInfo.phonenumber, auth: true, type: 0}).then((res) => {
  226. uni.hideLoading();
  227. // 这里此提示会被this.start()方法中的提示覆盖
  228. uni.$u.toast('验证码已发送');
  229. // 通知验证码组件内部开始倒计时
  230. that.$refs.uCode3.start();
  231. })
  232. },
  233. }
  234. }
  235. </script>
  236. <style lang="scss">
  237. page, body {
  238. background: #fff;
  239. }
  240. .h-err {
  241. color: red;
  242. text-align: center;
  243. font-size: 14px;
  244. }
  245. .h-popo-content {
  246. height: 170px;
  247. padding: 12px;
  248. width: 300px;
  249. text-align: center;
  250. font-size: 14px;
  251. font-family: PingFangSC-Semibold, PingFang SC;
  252. .h-img {
  253. display: flex;
  254. justify-content: center;
  255. }
  256. .h-text {
  257. margin-top: 12px;
  258. font-weight: 400;
  259. color: #666666;
  260. }
  261. .text {
  262. margin-top: 6px;
  263. font-weight: 400;
  264. color: #666666;
  265. }
  266. .h-btn-wrap {
  267. display: flex;
  268. justify-content: space-between;
  269. color: #333333;
  270. text-align: center;
  271. margin-top: 14px;
  272. .h-left-btn {
  273. height: 32px;
  274. line-height: 30px;
  275. background: #EEEEEE;
  276. width: 100px;
  277. text-align: center;
  278. border-radius: 16px;
  279. margin: 0 auto;
  280. }
  281. .h-right-btn {
  282. height: 32px;
  283. line-height: 30px;
  284. background: #FFE05C;
  285. width: 100px;
  286. border-radius: 16px;
  287. margin: 0 auto;
  288. }
  289. }
  290. }
  291. .container {
  292. background: #fff;
  293. height: 300px;
  294. .login-wrap {
  295. display: flex;
  296. justify-content: center;
  297. .login-form {
  298. width: 90%;
  299. }
  300. .account {
  301. display: flex;
  302. }
  303. .identifying-code {
  304. }
  305. }
  306. .op-btn-wrap {
  307. margin-top: 30px;
  308. display: flex;
  309. justify-content: center;
  310. align-items: center;
  311. .h-btn {
  312. text-align: center;
  313. width: 343px;
  314. height: 42px;
  315. background: #FFE05C;
  316. border-radius: 27px;
  317. line-height: 42px;
  318. }
  319. }
  320. }
  321. .popup-content {
  322. width: 622rpx;
  323. background-color: #FFFFFF;
  324. border-radius: 20rpx;
  325. padding: 24rpx;
  326. .popupItem {
  327. width: 558rpx;
  328. height: 100rpx;
  329. background-color: #FAFAFA;
  330. border-radius: 16rpx;
  331. margin:24rpx ;
  332. display: flex;
  333. align-items: center;
  334. justify-content: space-around;
  335. }
  336. .popupItemSelect {
  337. width: 558rpx;
  338. height: 100rpx;
  339. background-color: #FAFAFA;
  340. border-radius: 16rpx;
  341. border: 4rpx solid #FFE05C;
  342. margin:24rpx ;
  343. display: flex;
  344. align-items: center;
  345. justify-content: space-around;
  346. box-sizing: border-box;
  347. }
  348. .popupItemSelect::after {
  349. content: '√';
  350. color: #fff;
  351. z-index: 1000;
  352. display: inline-block;
  353. width: 32rpx;
  354. height: 32rpx;
  355. transform: rotate(20deg);
  356. position: absolute;
  357. top: 0;
  358. right: 0;
  359. }
  360. }
  361. .button-popup {
  362. height: 60px;
  363. display: flex;
  364. justify-content: space-between;
  365. background: #fff;
  366. .h-btn {
  367. margin: 0 auto;
  368. margin-top: 8px;
  369. width: 240rpx;
  370. height: 84rpx;
  371. border-radius: 27px;
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. font-size: 14px;
  376. }
  377. }
  378. </style>