index.vue 5.5 KB

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