index.vue 5.8 KB

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