setPwd.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view style="background-color: #FFFFFF;height: 100%;width: 100%;padding-top:80rpx">
  3. <view class="shopping-wrapper">
  4. <view>
  5. <u-icon name="close" bold color="#333333" size="20" @click="goBack()"></u-icon>
  6. </view>
  7. <view class="title">
  8. <view class="title-text mb8" v-if="type=='add'">请设置安全密码</view>
  9. <view class="title-text mb8" v-else-if="type=='set-2'">请输入原密码</view>
  10. <view class="title-text mb8" v-else>请输入新密码</view>
  11. <view class="title-prompt">6位数字</view>
  12. </view>
  13. <view class="mb12">
  14. <u-input
  15. :type="isPasswordVisible ? 'password' : 'text'"
  16. placeholder="确认安全密码"
  17. v-model="password"
  18. maxlength="6"
  19. :disabled="isSetPassword"
  20. shape="circle"
  21. placeholderStyle="color:#888888;"
  22. color="#333333"
  23. border="none"
  24. custom-style="background-color: #F3F6FC;padding-right: 20rpx;padding-left: 20rpx;opacity: 0.6;height: 94rpx;"
  25. >
  26. <template slot="suffix">
  27. <u-icon
  28. v-if="password.length>0&&!this.isSetPassword"
  29. :name="isPasswordVisible ? 'eye' : 'eye-off'"
  30. size="20"
  31. @click="togglePasswordVisibility"
  32. />
  33. </template>
  34. </u-input>
  35. </view>
  36. <view v-if="type=='add'">
  37. <u-input
  38. :type="isPasswordVisible2 ? 'password' : 'text'"
  39. placeholder="再次确认安全密码"
  40. v-model="password2"
  41. maxlength="6"
  42. :disabled="isSetPassword"
  43. shape="circle"
  44. placeholderStyle="color:#888888;"
  45. color="#333333"
  46. border="none"
  47. custom-style="background-color: #F3F6FC;padding-right: 20rpx;padding-left: 20rpx;opacity: 0.6;height: 94rpx;"
  48. >
  49. <template slot="suffix">
  50. <u-icon
  51. v-if="password2.length>0&&!this.isSetPassword"
  52. :name="isPasswordVisible2 ? 'eye' : 'eye-off'"
  53. size="20"
  54. @click="togglePasswordVisibility2"
  55. />
  56. </template>
  57. </u-input>
  58. </view>
  59. <view style="height: 108rpx; " class="btn-commnt" @click="setPassword()">
  60. <view class="btn-commnt-text" v-if="type=='add'||type=='set-3'">完成</view>
  61. <view class="btn-commnt-text" v-else>下一步</view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import {checkPayPswd, setPayPswd} from "@/common/api";
  68. import {getUserInfo} from "@/common/api/user";
  69. export default {
  70. data() {
  71. return {
  72. password: '',
  73. password2:'',
  74. userInfo: {},
  75. isSetPassword: false,
  76. isPasswordVisible: true,
  77. isPasswordVisible2: true,
  78. type: "add",
  79. verifyCode:"",
  80. };
  81. },
  82. onLoad(options) {
  83. // 保存查询参数到页面的数据对象中
  84. if (options.type) {
  85. this.type = options.type;
  86. }
  87. console.log("type", this.type)
  88. },
  89. onShow() {
  90. this.initUserInfo()
  91. },
  92. methods: {
  93. async getUserInfo() {
  94. const data = {}
  95. await getUserInfo(data)
  96. .then(res => {
  97. if (res.data) {
  98. uni.setStorageSync('token', res.data.token.token)
  99. uni.setStorageSync('userInfo', JSON.stringify(res.data))
  100. this.userInfo = res.data;
  101. }
  102. })
  103. .catch(() => {
  104. uni.hideLoading();
  105. });
  106. },
  107. async initUserInfo() {
  108. await this.getUserInfo();
  109. if (this.userInfo.pay_pswd && this.userInfo.pay_pswd.length > 0&& this.type == 'add' ) {
  110. this.isSetPassword = true;
  111. this.password = this.userInfo.pay_pswd;
  112. this.password2 = this.userInfo.pay_pswd;
  113. }
  114. },
  115. goBack() {
  116. uni.navigateBack({
  117. delta: 1 // 返回上一级页面
  118. });
  119. },
  120. change(e) {
  121. },
  122. togglePasswordVisibility() {
  123. this.isPasswordVisible = !this.isPasswordVisible;
  124. },
  125. togglePasswordVisibility2() {
  126. this.isPasswordVisible2 = !this.isPasswordVisible2;
  127. },
  128. savePad() {
  129. if (this.password.length < 6) {
  130. uni.showToast({
  131. title: '请输入6位数字',
  132. icon: 'none',
  133. duration: 2000
  134. });
  135. return
  136. }
  137. if (this.password!=this.password2 &&this.type=='add') {
  138. uni.showToast({
  139. title: '二次密码不一样,请重新确认',
  140. icon: 'none',
  141. duration: 2000
  142. });
  143. return
  144. }
  145. if (this.isSetPassword) {
  146. uni.showToast({
  147. title: '您已设置支付密码,无需重复设置',
  148. icon: 'none',
  149. duration: 2000
  150. });
  151. return
  152. }
  153. setPayPswd({pay_pswd: this.password}).then((res) => {
  154. if (this.type!="set-3"){
  155. uni.showToast({
  156. title: '保存成功'
  157. })
  158. }else{
  159. uni.showToast({
  160. title: '修改成功'
  161. })
  162. }
  163. this.isSetPassword = true
  164. setTimeout(() => {
  165. uni.navigateTo({
  166. url: '/subPages/setting/index',
  167. });
  168. }, 500);
  169. })
  170. },
  171. verifyPad() {
  172. if (this.password.length < 6) {
  173. uni.showToast({
  174. title: '请输入6位数字',
  175. icon: 'none',
  176. duration: 2000
  177. });
  178. return
  179. }
  180. checkPayPswd({pay_pswd: this.password}).then((res) => {
  181. uni.navigateTo({
  182. url: "/subPages/setting/setPwd?type=set-3",
  183. });
  184. })
  185. },
  186. setPassword() {
  187. switch (this.type) {
  188. case "add":
  189. this.savePad();
  190. break;
  191. case "set-1":
  192. break;
  193. case "set-2":
  194. this.verifyPad()
  195. break;
  196. case "set-3":
  197. this.savePad();
  198. break;
  199. default:
  200. break;
  201. }
  202. },
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .shopping-wrapper {
  208. width: 630rpx;
  209. margin: 0rpx auto 0rpx;
  210. padding: 30rpx 30rpx 178rpx;
  211. .title {
  212. display: flex;
  213. flex-direction: column;
  214. align-items: flex-start; /* 左对齐 */
  215. justify-content: flex-start; /* 左对齐 */
  216. margin-top: 112rpx;
  217. margin-bottom: 124rpx;
  218. .title-text {
  219. font-family: PingFang SC, PingFang SC;
  220. font-weight: 600;
  221. font-size: 48rpx;
  222. color: #262424;
  223. line-height: 68rpx;
  224. text-align: left;
  225. font-style: normal;
  226. text-transform: none;
  227. }
  228. .title-prompt {
  229. font-family: PingFang SC, PingFang SC;
  230. font-weight: 400;
  231. font-size: 24rpx;
  232. color: #888888;
  233. line-height: 36rpx;
  234. text-align: center;
  235. font-style: normal;
  236. text-transform: none;;
  237. }
  238. }
  239. .btn-commnt {
  240. margin-top: 40rpx;
  241. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  242. border-radius: 292rpx 292rpx 292rpx 292rpx;
  243. opacity: 0.6;
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. .btn-commnt-text {
  248. font-family: PingFang SC, PingFang SC;
  249. font-weight: 400;
  250. font-size: 32rpx;
  251. color: #FFFFFF;
  252. line-height: 42rpx;
  253. text-align: center;
  254. font-style: normal;
  255. text-transform: none;
  256. }
  257. }
  258. }
  259. </style>