index.vue 5.8 KB

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