setting-account-password.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. disabled="disabled"
  23. maxlength="11"
  24. ></u--input>
  25. </u-form-item>
  26. <u-form-item
  27. labelWidth="auto"
  28. labelAlign="right"
  29. label="验证码"
  30. prop="smsCode"
  31. width="120"
  32. >
  33. <u--input
  34. v-model="userInfo.smsCode"
  35. disabledColor="#ffffff"
  36. placeholder="请输入验证码"
  37. border="bottom"
  38. maxlength="4"
  39. ></u--input>
  40. <template #right>
  41. <view class="identifying-code">
  42. <u-code
  43. ref="uCode2"
  44. @change="codeChange2"
  45. keep-running
  46. start-text="获取验证码"
  47. ></u-code>
  48. <text
  49. @tap="getCode2"
  50. :text="tips2"
  51. class="u-page__code-text"
  52. >{{tips2}}</text>
  53. </view>
  54. </template>
  55. </u-form-item>
  56. <u-form-item
  57. label="新账号支付密码"
  58. prop="password"
  59. labelWidth="auto"
  60. labelAlign="right"
  61. >
  62. <u--input
  63. v-model="userInfo.password"
  64. placeholder="请输入6位新密码"
  65. border="bottom"
  66. maxlength="6"
  67. type="password"
  68. ></u--input>
  69. </u-form-item>
  70. <u-form-item
  71. labelWidth="auto"
  72. labelAlign="right"
  73. label="确认密码"
  74. prop="password1"
  75. width="120"
  76. >
  77. <u--input
  78. maxlength="6"
  79. v-model="userInfo.password1"
  80. placeholder="请再次输入密码"
  81. border="bottom"
  82. type="password"
  83. ></u--input>
  84. </u-form-item>
  85. </u--form>
  86. </view>
  87. </view>
  88. <view @click="submitData()" class="op-btn-wrap">
  89. <view class="h-btn">
  90. <text>确定</text>
  91. </view>
  92. </view>
  93. <!-- 提示 -->
  94. <view class="h-mark-desc">
  95. <view class="h-text">
  96. <text>*账号密码建议输入不连续的6位数</text>
  97. </view>
  98. </view>
  99. <!-- 密码找回 -->
  100. <u-popup :show="show" :round="10" mode="center" @close="close" @open="open">
  101. <view class="h-popo-content">
  102. <view class="h-img">
  103. <u-icon name="checkbox-mark" color="green" size="40"></u-icon>
  104. </view>
  105. <view class="text">
  106. <text>密码找回成功</text>
  107. </view>
  108. <view class="h-btn-wrap">
  109. <view @click="passwordSucessSure()" class="h-right-btn">
  110. <text>确定</text>
  111. </view>
  112. </view>
  113. </view>
  114. </u-popup>
  115. </view>
  116. </template>
  117. <script>
  118. export default {
  119. data() {
  120. return {
  121. show: false,
  122. userInfo: {
  123. auth: true,
  124. password: '',
  125. password1: '',
  126. phone: '',
  127. phonenumber: '',
  128. smsCode: '',
  129. code: ''
  130. },
  131. tips2: '',
  132. rules: {
  133. phonenumber: [
  134. {
  135. required: true,
  136. min: 10,
  137. max: 12,
  138. message: '请输入11位电话号码',
  139. trigger: ['blur', 'change'],
  140. },
  141. {
  142. // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
  143. validator: (rule, value, callback) => {
  144. // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
  145. return !this.$isDataEmpty(value);
  146. },
  147. message: "请认真填写电话号码",
  148. trigger: ['blur', 'change'],
  149. }
  150. ],
  151. smsCode: {
  152. required: true,
  153. min: 4,
  154. max: 6,
  155. message: '请输入4位验证码',
  156. trigger: ['blur', 'change'],
  157. },
  158. password: {
  159. required: true,
  160. min: 6,
  161. max: 18,
  162. message: '请输入6位密账号交易密码',
  163. trigger: ['blur', 'change'],
  164. },
  165. password1: [
  166. {
  167. required: true,
  168. min: 6,
  169. max: 18,
  170. message: '请再次输入',
  171. trigger: ['blur', 'change'],
  172. },
  173. {
  174. validator: (rule, value, callback) => {
  175. if(this.userInfo.password === value){
  176. return true;
  177. }
  178. return false;
  179. },
  180. message: "两次输入密码不一致",
  181. trigger: ['blur', 'change'],
  182. }
  183. ],
  184. },
  185. }
  186. },
  187. onLoad() {
  188. // 用户信息
  189. let user = uni.getStorageSync('userInfo');
  190. this.userInfo.phonenumber = user.phone;
  191. },
  192. onReady() {
  193. this.$refs.form1.setRules(this.rules)
  194. },
  195. methods: {
  196. // 提交交易密码
  197. submitData(){
  198. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  199. this.$refs.form1.validate().then(res => {
  200. // 设置新密码
  201. this.updateUserAccountPassword();
  202. }).catch(errors => {
  203. uni.$u.toast('校验失败,请认真填写')
  204. })
  205. },
  206. // 设置交易密码
  207. updateUserAccountPassword(){
  208. this.userInfo.phone = this.userInfo.phonenumber;
  209. this.userInfo.code = this.userInfo.smsCode;
  210. // 保存数据
  211. this.$api.passwordByPhone(this.userInfo).then((res)=>{
  212. this.show = true;
  213. }).catch(() =>{
  214. uni.showToast({
  215. title: "操作失败"
  216. })
  217. });
  218. },
  219. passwordSucessSure(){
  220. uni.switchTab({
  221. url: '/pages/my/index'
  222. });
  223. },
  224. codeChange2(text) {
  225. this.tips2 = text;
  226. },
  227. getCode2() {
  228. let that = this;
  229. if (this.$refs.uCode2.canGetCode) {
  230. that.getSmsCode();
  231. } else {
  232. uni.$u.toast('倒计时结束后再发送');
  233. }
  234. },
  235. // 获取手机验证码
  236. getSmsCode(){
  237. let that = this;
  238. if(!this.userInfo.phonenumber){
  239. uni.$u.toast('请认真填写手机号');
  240. return;
  241. }
  242. that.getPhoneCode();
  243. },
  244. // 获取验证码
  245. getPhoneCode(){
  246. let that = this;
  247. // 模拟向后端请求验证码
  248. uni.showLoading({
  249. title: '正在获取验证码'
  250. })
  251. this.$api.getSmsCode({phonenumber:this.userInfo.phonenumber,auth: true}).then((res)=>{
  252. uni.hideLoading();
  253. // 这里此提示会被this.start()方法中的提示覆盖
  254. uni.$u.toast('验证码已发送');
  255. // 通知验证码组件内部开始倒计时
  256. that.$refs.uCode2.start();
  257. }).catch(() =>{
  258. uni.showToast({
  259. title: "操作失败"
  260. })
  261. });
  262. },
  263. }
  264. }
  265. </script>
  266. <style lang="scss">
  267. page,body{
  268. background: #fff;
  269. }
  270. .container{
  271. background: #fff;
  272. height: 300px;
  273. .login-wrap {
  274. display: flex;
  275. justify-content: center;
  276. .login-form{
  277. width: 90%;
  278. }
  279. .account{
  280. display: flex;
  281. }
  282. .identifying-code{
  283. }
  284. }
  285. .op-btn-wrap{
  286. margin-top: 30px;
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. .h-btn{
  291. text-align: center;
  292. width: 343px;
  293. height: 42px;
  294. background: #FFE05C;
  295. border-radius: 27px;
  296. line-height: 42px;
  297. }
  298. }
  299. }
  300. .h-popo-content{
  301. height: 160px;
  302. padding: 12px;
  303. width: 300px;
  304. text-align: center;
  305. font-size: 14px;
  306. font-family: PingFangSC-Semibold, PingFang SC;
  307. .h-img{
  308. display: flex;
  309. justify-content: center;
  310. }
  311. .h-text{
  312. margin-top: 12px;
  313. font-weight: 400;
  314. color: #666666;
  315. }
  316. .text{
  317. margin-top: 6px;
  318. font-weight: 400;
  319. color: #666666;
  320. }
  321. .h-btn-wrap{
  322. display: flex;
  323. justify-content: space-between;
  324. color: #333333;
  325. text-align: center;
  326. margin-top: 14px;
  327. .h-left-btn{
  328. height: 32px;
  329. line-height: 30px;
  330. background: #EEEEEE;
  331. width: 100px;
  332. text-align: center;
  333. border-radius: 16px;
  334. margin: 0 auto;
  335. }
  336. .h-right-btn{
  337. height: 32px;
  338. line-height: 30px;
  339. background: #FFE05C;
  340. width: 100px;
  341. border-radius: 16px;
  342. margin: 0 auto;
  343. }
  344. }
  345. }
  346. </style>