index.vue 6.0 KB

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