index.vue 5.6 KB

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