index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="ChangePassword">
  4. <form @submit="editBus">
  5. <view class="phone">当前手机号:{{phone}}</view>
  6. <view class="list">
  7. <view class="item">
  8. <input type='password' placeholder='设置新支付密码' placeholder-class='placeholder' name="password" :value="password"></input>
  9. </view>
  10. <view class="item">
  11. <input type='password' placeholder='确认新密码' placeholder-class='placeholder' name="qr_password" :value="qr_password"></input>
  12. </view>
  13. <view class="item acea-row row-between-wrapper">
  14. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" name="captcha" :value="captcha"></input>
  15. <button class="code font-num" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  16. {{ text }}
  17. </button>
  18. </view>
  19. </view>
  20. <button form-type="submit" class="confirmBnt bg-color">确认修改</button>
  21. </form>
  22. </view>
  23. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }"
  24. ref="verify"></Verify>
  25. <!-- #ifdef MP -->
  26. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  27. <!-- #endif -->
  28. </view>
  29. </template>
  30. <script>
  31. import sendVerifyCode from "@/mixins/SendVerifyCode";
  32. import {
  33. tradePassword,
  34. registerVerify,
  35. verifyCode
  36. } from '@/api/api.js';
  37. import {
  38. getUserInfo,
  39. getCodeApi
  40. } from '@/api/user.js';
  41. import {
  42. toLogin
  43. } from '@/libs/login.js';
  44. import {
  45. mapGetters
  46. } from "vuex";
  47. import colors from '@/mixins/color.js';
  48. import Verify from '@/components/verify/verify.vue';
  49. export default {
  50. mixins: [sendVerifyCode,colors],
  51. components: {
  52. Verify
  53. },
  54. data() {
  55. return {
  56. captcha: '',
  57. userInfo: {},
  58. phone: '',
  59. password: '',
  60. qr_password: '',
  61. isAuto: false, //没有授权的不会自动授权
  62. isShowAuth: false ,//是否隐藏授权
  63. key: '',
  64. };
  65. },
  66. computed: mapGetters(['isLogin']),
  67. watch:{
  68. isLogin:{
  69. handler:function(newV,oldV){
  70. if(newV){
  71. //#ifndef MP
  72. this.getUserInfo();
  73. this.getVerifyCode();
  74. //#endif
  75. }
  76. },
  77. deep:true
  78. }
  79. },
  80. onLoad() {
  81. if (this.isLogin) {
  82. this.getUserInfo();
  83. this.getVerifyCode();
  84. } else {
  85. //#ifndef MP
  86. toLogin();
  87. //#endif
  88. //#ifdef MP
  89. this.isShowAuth = true;
  90. //#endif
  91. }
  92. },
  93. onShow() {
  94. uni.removeStorageSync('form_type_cart');
  95. },
  96. methods: {
  97. /**
  98. * 授权回调
  99. */
  100. onLoadFun: function(e) {
  101. this.getUserInfo();
  102. this.getVerifyCode();
  103. this.isShowAuth = false;
  104. },
  105. // 授权关闭
  106. authColse: function(e) {
  107. this.isShowAuth = e
  108. },
  109. getVerifyCode(){
  110. verifyCode().then(res=>{
  111. this.$set(this, 'key', res.data.key)
  112. });
  113. },
  114. /**
  115. * 获取个人用户信息
  116. */
  117. getUserInfo: function() {
  118. let that = this;
  119. getUserInfo().then(res => {
  120. let tel = res.data.phone;
  121. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  122. that.$set(that, 'userInfo', res.data);
  123. that.phone = phone;
  124. });
  125. },
  126. success(data) {
  127. console.log(data,'data');
  128. this.$refs.verify.hide()
  129. getCodeApi()
  130. .then(res => {
  131. this.keyCode = res.data.key;
  132. this.getCode(data);
  133. })
  134. .catch(res => {
  135. this.$util.Tips({
  136. title: res
  137. });
  138. });
  139. },
  140. /**
  141. * 发送验证码
  142. *
  143. */
  144. code(data) {
  145. let that = this;
  146. if (!that.userInfo.phone) return that.$util.Tips({
  147. title: '手机号码不存在,无法发送验证码!'
  148. });
  149. this.$refs.verify.show()
  150. },
  151. async getCode(data){
  152. console.log('data-------',data);
  153. let that = this;
  154. await registerVerify({
  155. phone: that.userInfo.phone,
  156. type: 'reset',
  157. key: that.key,
  158. captchaType: 'blockPuzzle',
  159. captchaVerification: data.captchaVerification,
  160. })
  161. .then(res => {
  162. that.$util.Tips({
  163. title: res.msg
  164. });
  165. that.sendCode();
  166. })
  167. .catch(res => {
  168. that.$util.Tips({
  169. title: res
  170. });
  171. });
  172. },
  173. /**
  174. * H5登录 修改密码
  175. *
  176. */
  177. editBus: function(e) {
  178. let that = this,
  179. password = e.detail.value.password,
  180. qr_password = e.detail.value.qr_password,
  181. captcha = e.detail.value.captcha;
  182. if (!password) return that.$util.Tips({
  183. title: '请输入新支付密码'
  184. });
  185. if (qr_password != password) return that.$util.Tips({
  186. title: '两次输入的密码不一致!'
  187. });
  188. if (!captcha) return that.$util.Tips({
  189. title: '请输入验证码'
  190. });
  191. tradePassword({
  192. // account: that.userInfo.phone,
  193. captcha: captcha,
  194. password: password
  195. }).then(res => {
  196. return that.$util.Tips({
  197. title: res.msg
  198. }, {
  199. tab: 3,
  200. url: 1
  201. });
  202. }).catch(err => {
  203. return that.$util.Tips({
  204. title: err
  205. });
  206. });
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss">
  212. page {
  213. background-color: #fff !important;
  214. }
  215. .ChangePassword .phone {
  216. font-size: 32rpx;
  217. font-weight: bold;
  218. text-align: center;
  219. margin-top: 55rpx;
  220. }
  221. .ChangePassword .list {
  222. width: 580rpx;
  223. margin: 53rpx auto 0 auto;
  224. }
  225. .ChangePassword .list .item {
  226. width: 100%;
  227. height: 110rpx;
  228. border-bottom: 2rpx solid #f0f0f0;
  229. }
  230. .ChangePassword .list .item input {
  231. width: 100%;
  232. height: 100%;
  233. font-size: 32rpx;
  234. }
  235. .ChangePassword .list .item .placeholder {
  236. color: #b9b9bc;
  237. }
  238. .ChangePassword .list .item input.codeIput {
  239. width: 340rpx;
  240. }
  241. .ChangePassword .list .item .code {
  242. font-size: 32rpx;
  243. background-color: #fff;
  244. }
  245. .ChangePassword .list .item .code.on {
  246. color: #b9b9bc !important;
  247. }
  248. .ChangePassword .confirmBnt {
  249. font-size: 32rpx;
  250. width: 580rpx;
  251. height: 90rpx;
  252. border-radius: 45rpx;
  253. color: #fff;
  254. margin: 92rpx auto 0 auto;
  255. text-align: center;
  256. line-height: 90rpx;
  257. }
  258. </style>