index.vue 5.3 KB

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