pay-password.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view>
  3. <navbar :config="config" backColor="#666666"></navbar>
  4. <view class="password-box">
  5. <text class="password-title">密码设置</text>
  6. <u-form :model="form" ref="uForm" label-width="156">
  7. <u-form-item label="支付密码">
  8. <u-input v-model.trim="form.payPass" type="number" maxlength="6" @input="changePass" placeholder="请输入6位支付密码" />
  9. </u-form-item>
  10. <u-form-item label="验证码">
  11. <u-input v-model="form.captcha" placeholder="本账户手机验证码" />
  12. <view class="get-code" @click.stop="getCode()">{{ captchaText }}</view>
  13. </u-form-item>
  14. </u-form>
  15. <view class="password-btn" @click.stop="setPayPassword()">
  16. 确认提交
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. setUpPaymentPassword,
  24. getVerifyCodeByParam
  25. } from "@/api/personal-center.js"
  26. export default {
  27. data() {
  28. return {
  29. config: {
  30. back: true, //false是tolbar页面 是则不写
  31. title: '设置支付密码',
  32. color: '#1A1A1A',
  33. // autoBack:true,
  34. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  35. backgroundColor: [1, "#fff"],
  36. statusBarFontColor: '#1A1A1A'
  37. },
  38. mobile: '',
  39. captchaText: '获取验证码',
  40. captchaInterval: null,
  41. payPasswordLoading: false,
  42. form: {
  43. payPass: '',
  44. captcha: ''
  45. }
  46. };
  47. },
  48. onShow() {
  49. this.getUserInfo()
  50. },
  51. onUnload() {
  52. if (uni.getStorageSync('toUrl')) {
  53. uni.removeStorageSync('toUrl')
  54. }
  55. },
  56. methods: {
  57. changePass(e) {
  58. console.log(e, 111)
  59. if (e) {
  60. if (e.indexOf('.') != -1) {
  61. this.form.payPass = e.replace(/\./g, '')
  62. }
  63. }
  64. },
  65. //获取个人信息
  66. getUserInfo() {
  67. let personal = uni.getStorageSync('personal')
  68. this.mobile = personal ? personal.mobile : '';
  69. },
  70. setPayPassword() {
  71. if (this.payPasswordLoading) {
  72. return false
  73. };
  74. this.payPasswordLoading = true;
  75. try {
  76. if (!this.form.payPass) {
  77. uni.showToast({
  78. title: '请填写支付密码',
  79. icon: 'none'
  80. });
  81. throw new Error()
  82. }
  83. if (this.form.payPass.length < 6) {
  84. uni.showToast({
  85. title: '请填写6位支付密码',
  86. icon: 'none'
  87. });
  88. throw new Error()
  89. }
  90. if (!this.form.captcha) {
  91. uni.showToast({
  92. title: '请填写验证码',
  93. icon: 'none'
  94. });
  95. throw new Error()
  96. };
  97. this.$http.put(setUpPaymentPassword, this.form).then(res => {
  98. uni.showToast({
  99. title: '支付密码设置成功',
  100. icon: 'none'
  101. });
  102. this.payPasswordLoading = false;
  103. if (uni.getStorageSync('toUrl')) {
  104. this.$mUtil.removeCurrenPage()
  105. }
  106. }).catch(err => {
  107. this.payPasswordLoading = false;
  108. })
  109. } catch (err) {
  110. this.payPasswordLoading = false;
  111. }
  112. },
  113. getCode() {
  114. this.getUserInfo()
  115. if (!this.mobile) {
  116. uni.showToast({
  117. title: '当前账号暂未绑定手机号',
  118. icon: 'none'
  119. });
  120. return false
  121. }
  122. if (this.captchaText !== '获取验证码') {
  123. return false
  124. }
  125. this.captchaText = '获取中...'
  126. try {
  127. clearInterval(this.captchaInterval)
  128. } catch {}
  129. try {
  130. this.$http.post(getVerifyCodeByParam, {
  131. mobile: this.mobile,
  132. verifyCodeType: 2
  133. }).then(res => {
  134. let num = 60
  135. this.captchaInterval = setInterval(() => {
  136. this.captchaText = `${num}s`;
  137. num--;
  138. if (num < 0) {
  139. clearInterval(this.captchaInterval)
  140. this.captchaText = '获取验证码'
  141. }
  142. }, 1000)
  143. }).catch(err => {
  144. this.captchaText = '获取验证码'
  145. })
  146. } catch (err) {
  147. this.captchaText = '获取验证码'
  148. }
  149. },
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .password-box {
  155. padding: 70rpx 50rpx 0;
  156. .password-title {
  157. font-size: 38rpx;
  158. font-family: PingFang SC, PingFang SC-Bold;
  159. font-weight: 700;
  160. color: #333333;
  161. }
  162. .u-form {
  163. /deep/.u-form-item--left__content__label {
  164. font-size: 28rpx;
  165. font-family: PingFang SC, PingFang SC-Regular;
  166. font-weight: 400;
  167. color: #333333;
  168. }
  169. }
  170. }
  171. .password-btn {
  172. width: 100%;
  173. height: 90rpx;
  174. background: #3d93fc;
  175. border-radius: 45rpx;
  176. text-align: center;
  177. line-height: 90rpx;
  178. font-size: 32rpx;
  179. font-family: PingFang SC, PingFang SC-Regular;
  180. font-weight: 400;
  181. color: #ffffff;
  182. margin-top: 98rpx;
  183. }
  184. .get-code {
  185. // flex-shrink: 0;
  186. height: 100%;
  187. padding: 0 30rpx;
  188. color: #FA6138;
  189. font-size: 28rpx;
  190. border: 1rpx solid #3775f6;
  191. background: #e7eefc;
  192. border-radius: 4rpx;
  193. }
  194. </style>