setting-account-password.vue 7.5 KB

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