index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="ChangePassword">
  4. <form @submit="editPwd">
  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. phoneRegisterReset,
  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. userInfo: {},
  57. phone: '',
  58. password: '',
  59. qr_password: '',
  60. isAuto: false, //没有授权的不会自动授权
  61. isShowAuth: false ,//是否隐藏授权
  62. key: '',
  63. };
  64. },
  65. computed: mapGetters(['isLogin']),
  66. watch:{
  67. isLogin:{
  68. handler:function(newV,oldV){
  69. if(newV){
  70. //#ifndef MP
  71. this.getUserInfo();
  72. this.getVerifyCode();
  73. //#endif
  74. }
  75. },
  76. deep:true
  77. }
  78. },
  79. onLoad() {
  80. if (this.isLogin) {
  81. this.getUserInfo();
  82. this.getVerifyCode();
  83. } else {
  84. toLogin()
  85. }
  86. },
  87. onShow() {
  88. uni.removeStorageSync('form_type_cart');
  89. },
  90. methods: {
  91. /**
  92. * 授权回调
  93. */
  94. onLoadFun: function(e) {
  95. this.getUserInfo();
  96. this.getVerifyCode();
  97. this.isShowAuth = false;
  98. },
  99. // 授权关闭
  100. authColse: function(e) {
  101. this.isShowAuth = e
  102. },
  103. getVerifyCode(){
  104. verifyCode().then(res=>{
  105. this.$set(this, 'key', res.data.key)
  106. });
  107. },
  108. /**
  109. * 获取个人用户信息
  110. */
  111. getUserInfo: function() {
  112. let that = this;
  113. getUserInfo().then(res => {
  114. let tel = res.data.phone;
  115. let phone = tel.substr(0, 3) + "****" + tel.substr(7);
  116. that.$set(that, 'userInfo', res.data);
  117. that.phone = phone;
  118. });
  119. },
  120. success(data) {
  121. console.log(data,'data');
  122. this.$refs.verify.hide()
  123. getCodeApi()
  124. .then(res => {
  125. this.keyCode = res.data.key;
  126. this.getCode(data);
  127. })
  128. .catch(res => {
  129. this.$util.Tips({
  130. title: res
  131. });
  132. });
  133. },
  134. /**
  135. * 发送验证码
  136. *
  137. */
  138. code(data) {
  139. let that = this;
  140. if (!that.userInfo.phone) return that.$util.Tips({
  141. title: '手机号码不存在,无法发送验证码!'
  142. });
  143. this.$refs.verify.show()
  144. },
  145. async getCode(data){
  146. console.log('data-------',data);
  147. let that = this;
  148. await registerVerify({
  149. phone: that.userInfo.phone,
  150. type: 'reset',
  151. key: that.key,
  152. captchaType: 'blockPuzzle',
  153. captchaVerification: data.captchaVerification,
  154. })
  155. .then(res => {
  156. that.$util.Tips({
  157. title: res.msg
  158. });
  159. that.sendCode();
  160. })
  161. .catch(res => {
  162. that.$util.Tips({
  163. title: res
  164. });
  165. });
  166. },
  167. /**
  168. * H5登录 修改密码
  169. *
  170. */
  171. editPwd: function(e) {
  172. let that = this,
  173. password = e.detail.value.password,
  174. qr_password = e.detail.value.qr_password,
  175. captcha = e.detail.value.captcha;
  176. if (!password) return that.$util.Tips({
  177. title: '请输入新密码'
  178. });
  179. if (qr_password != password) return that.$util.Tips({
  180. title: '两次输入的密码不一致!'
  181. });
  182. if (!captcha) return that.$util.Tips({
  183. title: '请输入验证码'
  184. });
  185. phoneRegisterReset({
  186. account: that.userInfo.phone,
  187. captcha: captcha,
  188. password: password
  189. }).then(res => {
  190. uni.reLaunch({
  191. url: '/pages/users/login/index'
  192. })
  193. // return that.$util.Tips({
  194. // title: res.msg
  195. // }, {
  196. // tab: 3,
  197. // url: 1
  198. // });
  199. }).catch(err => {
  200. return that.$util.Tips({
  201. title: err
  202. });
  203. });
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="scss">
  209. page {
  210. background-color: #fff !important;
  211. }
  212. .ChangePassword .phone {
  213. font-size: 32rpx;
  214. font-weight: bold;
  215. text-align: center;
  216. margin-top: 55rpx;
  217. }
  218. .ChangePassword .list {
  219. width: 580rpx;
  220. margin: 53rpx auto 0 auto;
  221. }
  222. .ChangePassword .list .item {
  223. width: 100%;
  224. height: 110rpx;
  225. border-bottom: 2rpx solid #f0f0f0;
  226. }
  227. .ChangePassword .list .item input {
  228. width: 100%;
  229. height: 100%;
  230. font-size: 32rpx;
  231. }
  232. .ChangePassword .list .item .placeholder {
  233. color: #b9b9bc;
  234. }
  235. .ChangePassword .list .item input.codeIput {
  236. width: 340rpx;
  237. }
  238. .ChangePassword .list .item .code {
  239. font-size: 32rpx;
  240. background-color: #fff;
  241. }
  242. .ChangePassword .list .item .code.on {
  243. color: #b9b9bc !important;
  244. }
  245. .ChangePassword .confirmBnt {
  246. font-size: 32rpx;
  247. width: 580rpx;
  248. height: 90rpx;
  249. border-radius: 45rpx;
  250. color: #fff;
  251. margin: 92rpx auto 0 auto;
  252. text-align: center;
  253. line-height: 90rpx;
  254. }
  255. </style>