index.vue 6.1 KB

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