setPaypass.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="page-wrap">
  3. <u-navbar
  4. v-if="fromPage=='reset'"
  5. :placeholder="true"
  6. title="密码设置"
  7. :autoBack="true"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="step-reset" v-if="step=='reset'&&noPaypass==false">
  12. <view class="title">请输入当前密码,以身份认证</view>
  13. <u-code-input v-model="paypass0"
  14. ref="paypass0"
  15. :space="codeInput.space"
  16. :size="codeInput.size"
  17. @finish="finish0"
  18. :maxlength="codeInput.maxlength"
  19. :adjustPosition="codeInput.adjustPosition"
  20. :dot="codeInput.dot"
  21. :focus="paypass0Focus"
  22. :disabled-keyboard="codeInput.disabledKeyboard" >
  23. </u-code-input>
  24. <view class="findpaypass" @click="$u.route('/center/findpaypass')">忘记密码?</view>
  25. </view>
  26. <view class="step-1" v-if="step==1">
  27. <view class="title">设置6位数数字支付密码</view>
  28. <u-code-input v-model="paypass1"
  29. ref="paypass1"
  30. :space="codeInput.space"
  31. :size="codeInput.size"
  32. @finish="finish1"
  33. :maxlength="codeInput.maxlength"
  34. :adjustPosition="codeInput.adjustPosition"
  35. :dot="codeInput.dot"
  36. :focus="paypass1Focus"
  37. :disabled-keyboard="codeInput.disabledKeyboard" >
  38. </u-code-input>
  39. <view class="tip">建议密码不重复,不连续,不同于登录密码</view>
  40. </view>
  41. <view class="step-2" v-if="step==2">
  42. <view class="title">请在再次输入</view>
  43. <u-code-input v-model="paypass2"
  44. ref="paypass2"
  45. :space="codeInput.space"
  46. :size="codeInput.size"
  47. @finish="finish2"
  48. :maxlength="codeInput.maxlength"
  49. :adjustPosition="codeInput.adjustPosition"
  50. :dot="codeInput.dot"
  51. :focus="paypass2Focus"
  52. :disabled-keyboard="codeInput.disabledKeyboard" >
  53. </u-code-input>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. return {
  61. noPaypass:true,
  62. fromPage:'',
  63. step:1,
  64. paypass0:'',
  65. paypass1:'',
  66. paypass2:'',
  67. paypass0Focus:false,
  68. paypass1Focus:false,
  69. paypass2Focus:false,
  70. codeInput:{
  71. space:10,
  72. size:45,
  73. maxlength:6,
  74. adjustPosition:false,
  75. dot:true,
  76. disabledKeyboard:false
  77. },
  78. code:'',
  79. }
  80. },
  81. onShow() {
  82. this.checkPaypass()
  83. },
  84. onLoad(page) {
  85. this.fromPage = page.fromPage;
  86. this.code = page.code;
  87. if(this.fromPage == 'reset'){
  88. this.$nextTick(()=>{
  89. this.paypass0Focus = true;
  90. })
  91. }else{
  92. this.$nextTick(()=>{
  93. this.paypass1Focus = true;
  94. })
  95. }
  96. },
  97. methods: {
  98. checkPaypass(){
  99. this.$u.api.balanceInfo().then(res=>{
  100. // console.log('res',res.data);
  101. if(res.data.isSetPayPassword==0){
  102. this.noPaypass = true
  103. }else{
  104. this.noPaypass = false;
  105. this.step = 1;
  106. if(this.fromPage=='reset'){
  107. this.step = 'reset'
  108. }
  109. if(this.fromPage=='reset'){
  110. this.step = 'reset'
  111. }
  112. }
  113. console.log('this.noPaypass',this.noPaypass);
  114. }).catch(err=>{
  115. console.log('checkPaypass',err);
  116. })
  117. },
  118. finish0(){
  119. this.$u.api.checkPayPassword({payPassword:this.paypass0}).then(res=>{
  120. console.log('res',res.data);
  121. if(res.msg=='操作成功'){//密码正确
  122. this.step = 1;
  123. this.$nextTick(()=>{
  124. this.paypass1Focus = true;
  125. })
  126. }else{
  127. this.paypass0 = ''
  128. }
  129. }).catch(err=>{
  130. if(err.msg=='密码错误!'){
  131. this.paypass0 = '';
  132. }
  133. console.log('checkPayPassword',err);
  134. })
  135. },
  136. finish1(){
  137. this.step = 2;
  138. this.$nextTick(()=>{
  139. this.paypass2Focus = true;
  140. console.log('this.paypass2Focus',this.paypass2Focus);
  141. })
  142. console.log('paypass',this.paypass1);
  143. console.log('paypass2',this.paypass2);
  144. },
  145. finish2(){
  146. console.log('paypass1',this.paypass1);
  147. console.log('paypass2',this.paypass2);
  148. let that = this;
  149. if(this.paypass1==this.paypass2){
  150. console.log('两次密码一样');
  151. if(this.fromPage == 'forget'){
  152. this.updatePayPassword();
  153. // this.resetPayPassword();
  154. }else{
  155. this.updatePayPassword();
  156. }
  157. }else{
  158. uni.showModal({
  159. showCancel:false,
  160. title: '提示',
  161. content: '两次密码不一样!',
  162. success: res => {
  163. if (res.confirm) {
  164. that.paypass1 = '';
  165. that.paypass2 = '';
  166. that.step = 1;
  167. } else if (res.cancel) {
  168. console.log('用户点击取消');
  169. }
  170. }
  171. });
  172. }
  173. },
  174. updatePayPassword(){
  175. this.$u.api.updatePayPassword({payPassword:this.paypass2}).then(res=>{
  176. uni.showToast({
  177. title:res.msg,
  178. icon:'success',
  179. complete() {
  180. setTimeout(()=>{
  181. uni.reLaunch({url: '/center/center'});
  182. },2000)
  183. }
  184. })
  185. console.log('res',res.data);
  186. }).catch(err=>{
  187. console.log('setPaypass',err);
  188. })
  189. },
  190. resetPayPassword(){
  191. let params = {
  192. payPassword:this.paypass2,
  193. code:this.code,
  194. mobile:this.vuex_member_info.mobile
  195. }
  196. this.$u.api.resetPayPassword(params).then(res=>{
  197. uni.showToast({
  198. title:res.msg,
  199. icon:'success',
  200. complete() {
  201. setTimeout(()=>{
  202. uni.reLaunch({url: '/center/center'});
  203. },2000)
  204. }
  205. })
  206. console.log('res',res.data);
  207. }).catch(err=>{
  208. setTimeout(()=>{
  209. uni.reLaunch({url: '/center/findpaypass'});
  210. },2000)
  211. console.log('setPaypass',err);
  212. })
  213. }
  214. }
  215. }
  216. </script>
  217. <style>
  218. page{
  219. padding-top: 100rpx;
  220. }
  221. </style>
  222. <style lang="scss" scoped>
  223. .page-wrap{
  224. text-align: center;
  225. /deep/ .u-code-input__item{
  226. flex-grow: 1!important;
  227. }
  228. }
  229. .title{
  230. font-size: 40rpx;
  231. font-weight: 600;
  232. margin-bottom: 40rpx;
  233. }
  234. .tip{
  235. margin: 24rpx auto 40rpx;
  236. color: #999;
  237. }
  238. .findpaypass{
  239. text-align: right;
  240. margin-top: 40rpx;
  241. color: #999;
  242. font-size: 24rpx;
  243. }
  244. </style>