You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
6.4 KiB

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