change-password.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view>
  3. <headContent>
  4. <template #left>
  5. <reverse-back />
  6. </template>
  7. <template #content>
  8. <view class="haed-title">
  9. 修改登录密码
  10. </view>
  11. </template>
  12. </headContent>
  13. <view class="change-hint">
  14. <text class="iconfont">&#xe8ec;</text>
  15. <text>{{ changeHint }}</text>
  16. </view>
  17. <view class="form-box">
  18. <form class="form-content">
  19. <view class="form-item ">
  20. <view class="form-item-lable">原密码</view>
  21. <input class="form-item-input" v-model="formData.password" :maxlength="maxlength"
  22. placeholder-class="form-item-place" :type="showPwd ? 'text' : 'password'" placeholder="请输入原密码">
  23. <!-- <input class="form-item-input" v-model="formData.password" :maxlength="maxlength"
  24. placeholder-class="form-item-place" :type="showConfirmPsd ? 'text' : 'password'" placeholder="请输入原密码"> -->
  25. <view class="form-item-icon" @click.stop="showPwd = !showPwd">
  26. <text v-show="showPwd" class="iconfont">&#xe663;</text>
  27. <text v-show="!showPwd" class="iconfont">&#xe664;</text>
  28. </view>
  29. </view>
  30. <view class="err-hint">{{ formError.psdErr }}</view>
  31. <view class="form-item ">
  32. <view class="form-item-lable">新密码</view>
  33. <input class="form-item-input" v-model="formData.newPassword" :maxlength="maxlength"
  34. placeholder-class="form-item-place" :type="showNewPsd ? 'text' : 'password'"
  35. placeholder="请输入新密码">
  36. <view class="form-item-icon" @click.stop="showNewPsd = !showNewPsd">
  37. <text v-show="showNewPsd" class="iconfont">&#xe663;</text>
  38. <text v-show="!showNewPsd" class="iconfont">&#xe664;</text>
  39. </view>
  40. </view>
  41. <view class="err-hint">{{ formError.newPsdErr }}</view>
  42. <view class="form-item ">
  43. <view class="form-item-lable">确认密码</view>
  44. <input class="form-item-input" v-model="formData.confirmPassword" :maxlength="maxlength"
  45. placeholder-class="form-item-place" :type="showConfirmPsd ? 'text' : 'password'"
  46. placeholder="请再次输入新密码">
  47. <view class="form-item-icon" @click.stop="showConfirmPsd = !showConfirmPsd">
  48. <text v-show="showConfirmPsd" class="iconfont">&#xe663;</text>
  49. <text v-show="!showConfirmPsd" class="iconfont">&#xe664;</text>
  50. </view>
  51. </view>
  52. <view class="err-hint">{{ formError.confirmPsdErr }}</view>
  53. </form>
  54. <view :class="['form-btn' , deblockingSubmitBtn() ? 'active-form-btn' : '' ]"
  55. @click.stop="SubmitPassWord()">
  56. 确定
  57. </view>
  58. </view>
  59. <unopen ref="unopenRef" :content="changeHint" />
  60. </view>
  61. </template>
  62. <script>
  63. import {
  64. validPassword
  65. } from "@/utils/validate.js"
  66. import {
  67. Api_setPassword
  68. } from "@/api/index.js"
  69. import {
  70. Way_getUserInfo
  71. } from "@/utils/common-request.js"
  72. import {
  73. refreshAccount
  74. } from "@/utils/common.js"
  75. export default {
  76. name: 'change-password',
  77. data() {
  78. return {
  79. account: null,
  80. changeHint: "修改登录密码需24小时后才能操作提现",
  81. maxlength: 20,
  82. showPwd: false,
  83. showNewPsd: false,
  84. showConfirmPsd: false,
  85. formData: {
  86. password: '',
  87. newPassword: '',
  88. confirmPassword: ''
  89. },
  90. formError: {
  91. psdErr: '',
  92. newPsdErr: '',
  93. confirmPsdErr: ''
  94. }
  95. };
  96. },
  97. watch: {
  98. 'formData.password'(newPsd, oldPsd) {
  99. this.validateField('password')
  100. },
  101. 'formData.newPassword'(newPsd, oldPsd) {
  102. this.validateField('newPassword')
  103. },
  104. 'formData.confirmPassword'(newPsd, oldPsd) {
  105. this.validateField('confirmPassword')
  106. }
  107. },
  108. onShow() {
  109. this.getUserInfo();
  110. this.$refs.unopenRef.open();
  111. },
  112. methods: {
  113. getUserInfo() {
  114. Way_getUserInfo().then(res => {
  115. this.account = res;
  116. })
  117. },
  118. validateField(key) {
  119. let validateStatus = false
  120. switch (key) {
  121. case 'password':
  122. if (this.formData[key].trim()) {
  123. this.formError.psdErr = '';
  124. validateStatus = true;
  125. } else {
  126. this.formError.psdErr = '请输入原密码';
  127. validateStatus = false;
  128. };
  129. break;
  130. case 'newPassword':
  131. if (!this.formData[key].trim()) {
  132. this.formError.newPsdErr = '请输入新密码'
  133. validateStatus = false;
  134. } else if (!validPassword(this.formData[key])) {
  135. this.formError.newPsdErr = '密码长度为8-20位字符,必须同时包含大写字母、小写字母和数字';
  136. validateStatus = false;
  137. } else {
  138. this.formError.newPsdErr = '';
  139. validateStatus = true;
  140. };
  141. break;
  142. case 'confirmPassword':
  143. if (!this.formData[key].trim()) {
  144. this.formError.confirmPsdErr = '请再次输入新密码';
  145. validateStatus = false;
  146. } else if (this.formData[key] !== this.formData.newPassword) {
  147. this.formError.confirmPsdErr = '确认密码和新密码输入不一致';
  148. validateStatus = false;
  149. } else {
  150. this.formError.confirmPsdErr = '';
  151. validateStatus = true;
  152. }
  153. break;
  154. default:
  155. validateStatus = false
  156. };
  157. return validateStatus;
  158. },
  159. confirmValidateField() {
  160. return new Promise((resolve, reject) => {
  161. let validateStatus = true;
  162. for (let key in this.formData) {
  163. console.log('SubmitPassWord', key)
  164. if (validateStatus) {
  165. validateStatus = this.validateField(key)
  166. } else {
  167. this.validateField(key)
  168. }
  169. }
  170. if (validateStatus) {
  171. resolve()
  172. } else {
  173. reject()
  174. };
  175. })
  176. },
  177. deblockingSubmitBtn() {
  178. for (let key in this.formData) {
  179. if (this.formData[key] === '') {
  180. return false
  181. break;
  182. }
  183. };
  184. return true
  185. },
  186. SubmitPassWord() {
  187. this.confirmValidateField().then(res => {
  188. uni.showLoading({
  189. title: '修改中',
  190. mask: true
  191. })
  192. const obj = {
  193. account: this.account?.account_number,
  194. password: this.formData.newPassword,
  195. repassword: this.formData.newPassword
  196. }
  197. // formData: {
  198. // password: '',
  199. // newPassword: '',
  200. // confirmPassword: ''
  201. // },
  202. Api_setPassword(obj).then(res => {
  203. setTimeout(() => {
  204. refreshAccount()
  205. }, 501)
  206. }).catch(err => {}).finally(() => {
  207. setTimeout(() => {
  208. uni.hideLoading()
  209. }, 500)
  210. })
  211. })
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .change-hint {
  218. font-size: 26rpx;
  219. padding: 0 $pages-padding;
  220. display: flex;
  221. align-items: center;
  222. color: $Theme-Color;
  223. border-top: 1rpx solid $border-color;
  224. height: 80rpx;
  225. .iconfont {
  226. margin-right: 20rpx;
  227. }
  228. }
  229. .form-box {
  230. width: 100%;
  231. padding: 0 $pages-padding;
  232. .form-content {
  233. width: 100%;
  234. .form-item {
  235. width: 100%;
  236. height: 80rpx;
  237. display: flex;
  238. align-items: center;
  239. font-size: 28rpx;
  240. border-bottom: 1rpx solid $border-color;
  241. .form-item-lable {
  242. width: 180rpx;
  243. }
  244. .form-item-input {
  245. font-size: 28rpx;
  246. flex: 1;
  247. height: 100%;
  248. border: none;
  249. }
  250. .form-item-place {
  251. font-size: 28rpx;
  252. color: #ccc;
  253. }
  254. .form-item-icon {
  255. width: 50rpx;
  256. height: 100%;
  257. display: flex;
  258. justify-content: flex-end;
  259. align-items: center;
  260. .iconfont {
  261. font-size: 26rpx;
  262. }
  263. }
  264. }
  265. .err-hint {
  266. width: 100%;
  267. min-height: 50rpx;
  268. font-size: 26rpx;
  269. color: red;
  270. line-height: 1.2;
  271. padding-top: 10rpx;
  272. }
  273. }
  274. .form-btn {
  275. width: 100%;
  276. background-color: #ccc;
  277. height: 80rpx;
  278. margin-top: 20rpx;
  279. border-radius: 10rpx;
  280. text-align: center;
  281. line-height: 80rpx;
  282. color: #fff;
  283. letter-spacing: 1px;
  284. font-size: 28rpx;
  285. }
  286. .active-form-btn {
  287. background-color: $Theme-Color ;
  288. }
  289. }
  290. </style>