index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view>
  3. <view class="ChangePassword">
  4. <view class="list">
  5. <view class="item" v-if="isNew">
  6. <input type='number' disabled='true' placeholder='填写手机号码1' placeholder-class='placeholder' v-model="userInfo.phone"></input>
  7. </view>
  8. <view class="item" v-if="!isNew">
  9. <input type='number' placeholder='填写手机号码' placeholder-class='placeholder' v-model="phone"></input>
  10. </view>
  11. <view class="item acea-row row-between-wrapper">
  12. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha"></input>
  13. <button class="code font-color" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  14. {{ text }}
  15. </button>
  16. </view>
  17. </view>
  18. <button form-type="submit" v-if="isNew" class="confirmBnt bg-color" @click="next">下一步</button>
  19. <button form-type="submit" v-if="!isNew" class="confirmBnt bg-color" @click="editPwd">保存</button>
  20. </view>
  21. <!-- #ifdef MP -->
  22. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  23. <!-- #endif -->
  24. </view>
  25. </template>
  26. <script>
  27. import sendVerifyCode from "@/mixins/SendVerifyCode";
  28. import {
  29. registerVerify,
  30. bindingPhone,
  31. verifyCode,
  32. bindingVerify
  33. } from '@/api/api.js';
  34. import {
  35. toLogin
  36. } from '@/libs/login.js';
  37. import {
  38. mapGetters
  39. } from "vuex";
  40. // #ifdef MP
  41. import authorize from '@/components/Authorize';
  42. // #endif
  43. export default {
  44. mixins: [sendVerifyCode],
  45. components: {
  46. // #ifdef MP
  47. authorize
  48. // #endif
  49. },
  50. data() {
  51. return {
  52. phone:'',
  53. captcha:'',
  54. isAuto: false, //没有授权的不会自动授权
  55. isShowAuth: false, //是否隐藏授权
  56. key: '',
  57. isNew: true,
  58. timer: '',
  59. text: '获取验证码',
  60. nums: 60
  61. };
  62. },
  63. mounted() {
  64. // this.timer = setInterval(this.getTimes, 1000);
  65. },
  66. computed: mapGetters(['isLogin','userInfo']),
  67. onLoad() {
  68. if (this.isLogin) {
  69. // verifyCode().then(res=>{
  70. // this.$set(this, 'key', res.data.key)
  71. // });
  72. } else {
  73. toLogin();
  74. }
  75. },
  76. methods: {
  77. getTimes(){
  78. this.nums = this.nums - 1;
  79. this.text = "剩余 " + this.nums + "s";
  80. if (this.nums < 0) {
  81. clearInterval(this.timer);
  82. }
  83. this.text = "剩余 " + this.nums + "s";
  84. if (this.text < "剩余 " + 0 + "s") {
  85. this.disabled = false;
  86. this.text = "重新获取";
  87. }
  88. },
  89. onLoadFun:function(){},
  90. // 授权关闭
  91. authColse: function(e) {
  92. this.isShowAuth = e
  93. },
  94. next() {
  95. uni.hideLoading();
  96. this.isNew = false;
  97. this.captcha = '';
  98. clearInterval(this.timer);
  99. this.disabled = false;
  100. this.text = "获取验证码";
  101. uni.showLoading({
  102. title: '加载中',
  103. mask: true
  104. });
  105. if (!this.captcha) return this.$util.Tips({
  106. title: '请填写验证码'
  107. });
  108. bindingVerify({
  109. phone: this.userInfo.phone,
  110. captcha: this.captcha
  111. }).then(res => {
  112. uni.hideLoading();
  113. this.isNew = false;
  114. this.captcha = '';
  115. clearInterval(this.timer);
  116. this.disabled = false;
  117. this.text = "获取验证码";
  118. }).catch(err => {
  119. return this.$util.Tips({
  120. title: err
  121. });
  122. uni.hideLoading();
  123. })
  124. },
  125. editPwd: function() {
  126. let that = this;
  127. if (!that.phone) return that.$util.Tips({
  128. title: '请填写手机号码!'
  129. });
  130. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  131. title: '请输入正确的手机号码!'
  132. });
  133. if (!that.captcha) return that.$util.Tips({
  134. title: '请填写验证码'
  135. });
  136. uni.showModal({
  137. title: '是否更换绑定账号',
  138. confirmText: '绑定',
  139. success(res) {
  140. if (res.confirm) {
  141. bindingPhone({
  142. phone: that.phone,
  143. captcha: that.captcha
  144. }).then(res => {
  145. return that.$util.Tips({
  146. title: res.message,
  147. icon: 'success'
  148. }, {
  149. tab: 5,
  150. url: '/pages/users/user_info/index'
  151. });
  152. }).catch(err => {
  153. return that.$util.Tips({
  154. title: err
  155. });
  156. })
  157. } else if (res.cancel) {
  158. return that.$util.Tips({
  159. title: '您已取消更换绑定!'
  160. }, {
  161. tab: 5,
  162. url: '/pages/users/user_info/index'
  163. });
  164. }
  165. }
  166. });
  167. },
  168. /**
  169. * 发送验证码
  170. *
  171. */
  172. async code() {
  173. this.nums = 60;
  174. uni.showLoading({
  175. title: '加载中',
  176. mask: true
  177. });
  178. let that = this;
  179. if(!that.isNew){
  180. if (!that.phone) return that.$util.Tips({
  181. title: '请填写手机号码!'
  182. });
  183. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  184. title: '请输入正确的手机号码!'
  185. });
  186. }
  187. await registerVerify(that.isNew?that.userInfo.phone:that.phone).then(res => {
  188. that.$util.Tips({
  189. title: res.message
  190. });
  191. that.timer = setInterval(that.getTimes, 1000);
  192. that.disabled = true;
  193. uni.hideLoading();
  194. }).catch(err => {
  195. return that.$util.Tips({
  196. title: err
  197. });
  198. uni.hideLoading();
  199. });
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .shading {
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. width: 100%;
  210. /* #ifdef APP-VUE */
  211. margin-top: 50rpx;
  212. /* #endif */
  213. /* #ifndef APP-VUE */
  214. margin-top: 200rpx;
  215. /* #endif */
  216. image {
  217. width: 180rpx;
  218. height: 180rpx;
  219. }
  220. }
  221. page {
  222. background-color: #fff !important;
  223. }
  224. .ChangePassword .phone {
  225. font-size: 32rpx;
  226. font-weight: bold;
  227. text-align: center;
  228. margin-top: 55rpx;
  229. }
  230. .ChangePassword .list {
  231. width: 580rpx;
  232. margin: 53rpx auto 0 auto;
  233. }
  234. .ChangePassword .list .item {
  235. width: 100%;
  236. height: 110rpx;
  237. border-bottom: 2rpx solid #f0f0f0;
  238. }
  239. .ChangePassword .list .item input {
  240. width: 100%;
  241. height: 100%;
  242. font-size: 32rpx;
  243. }
  244. .ChangePassword .list .item .placeholder {
  245. color: #b9b9bc;
  246. }
  247. .ChangePassword .list .item input.codeIput {
  248. width: 340rpx;
  249. }
  250. .ChangePassword .list .item .code {
  251. font-size: 32rpx;
  252. // background-color: #fff;
  253. }
  254. .ChangePassword .list .item .code.on {
  255. color: #b9b9bc !important;
  256. }
  257. .ChangePassword .confirmBnt {
  258. font-size: 32rpx;
  259. width: 580rpx;
  260. height: 90rpx;
  261. border-radius: 45rpx;
  262. color: #fff;
  263. margin: 92rpx auto 0 auto;
  264. text-align: center;
  265. line-height: 90rpx;
  266. }
  267. </style>