index.vue 5.4 KB

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