setting-telphone.vue 9.6 KB

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