bindmobile.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view :style="viewColor">
  3. <view class="container">
  4. <view class="header">
  5. <text class="title">绑定手机号</text>
  6. <text class="iconfont icon-guanbi5" @tap="closePopup"></text>
  7. </view>
  8. <view class="main_counts">
  9. <form report-submit='true'>
  10. <view class="ChangePassword">
  11. <view class="list">
  12. <view class="item">
  13. <input type='number' placeholder='输入手机号码' placeholder-class='placeholder' v-model="phone"></input>
  14. </view>
  15. <view class="item acea-row row-between-wrapper">
  16. <input type='number' placeholder='输入验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha"></input>
  17. <button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="handleVerify">
  18. {{ text }}
  19. </button>
  20. </view>
  21. </view>
  22. <button form-type="submit" @click="editPwd" class="confirmBnt">确认绑定</button>
  23. <!-- #ifdef MP -->
  24. <button v-if="!isCommuity && wechat_phone_switch == 1" form-type="submit" class="getPhoneBtn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"><text class="iconfont icon-weixin2"></text>使用微信绑定号码</button>
  25. <!-- #endif -->
  26. </view>
  27. </form>
  28. </view>
  29. </view>
  30. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
  31. <view class='mask' catchtouchmove="true" :hidden='popup.show==false' @tap="closePopup"></view>
  32. </view>
  33. </template>
  34. <script>
  35. // +----------------------------------------------------------------------
  36. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  37. // +----------------------------------------------------------------------
  38. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  39. // +----------------------------------------------------------------------
  40. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  41. // +----------------------------------------------------------------------
  42. // | Author: CRMEB Team <admin@crmeb.com>
  43. // +----------------------------------------------------------------------
  44. import sendVerifyCode from "@/mixins/SendVerifyCode";
  45. import { bindingPhone, verifyCode, appletsDecrypt } from '@/api/api.js';
  46. import { registerVerify } from '@/api/user.js'
  47. import { mapGetters } from "vuex";
  48. import { configMap } from '@/utils/index';
  49. import Verify from '@/components/verify/verify.vue';
  50. export default {
  51. props:{
  52. isCommuity: {
  53. type: Boolean,
  54. default: false
  55. }
  56. },
  57. mixins: [sendVerifyCode],
  58. components: {
  59. Verify
  60. },
  61. data() {
  62. return {
  63. phone:'',
  64. captcha:'',
  65. key: '',
  66. codeVal: '',
  67. popup: {
  68. show: false
  69. },
  70. };
  71. },
  72. computed: {
  73. ...mapGetters(['isLogin', 'viewColor']),
  74. ...configMap(['wechat_phone_switch'])
  75. },
  76. onLoad() {},
  77. methods: {
  78. // 点击关闭按钮
  79. closePopup() {
  80. this.$emit('close');
  81. },
  82. // #ifdef MP
  83. getPhoneNumber(e) {
  84. let that = this;
  85. appletsDecrypt({
  86. iv:e.detail.iv,
  87. encryptedData:e.detail.encryptedData,
  88. code:that.codeVal
  89. }).then(res => {
  90. that.$util.Tips({
  91. title: '绑定成功!',
  92. icon: 'success'
  93. })
  94. setTimeout(()=>{
  95. uni.switchTab({
  96. url: '/pages/user/index',
  97. });
  98. },2000)
  99. })
  100. },
  101. // #endif
  102. editPwd: function() {
  103. let that = this;
  104. if (!that.phone) return that.$util.Tips({
  105. title: '请输入手机号码!'
  106. });
  107. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  108. title: '请输入正确的手机号码!'
  109. });
  110. if (!that.captcha) return that.$util.Tips({
  111. title: '请填写验证码'
  112. });
  113. bindingPhone({
  114. phone: that.phone,
  115. sms_code: that.captcha
  116. }).then(res => {
  117. if (res.data !== undefined && res.data.is_bind) {
  118. uni.showModal({
  119. title: '是否绑定手机号',
  120. content: res.message,
  121. confirmText: '绑定',
  122. success(res) {
  123. if (res.confirm) {
  124. bindingPhone({
  125. phone: that.phone,
  126. captcha: that.captcha,
  127. step: 1
  128. }).then(res => {
  129. that.$emit('close');
  130. return that.$util.Tips({
  131. title: res.message,
  132. icon: 'success'
  133. });
  134. }).catch(err => {
  135. return that.$util.Tips({
  136. title: err
  137. });
  138. })
  139. } else if (res.cancel) {
  140. return that.$util.Tips({
  141. title: '您已取消绑定!'
  142. }, {
  143. tab: 5,
  144. url: '/pages/users/user_info/index'
  145. });
  146. }
  147. }
  148. });
  149. } else
  150. that.$emit('close');
  151. return that.$util.Tips({
  152. title: '绑定成功!',
  153. icon: 'success'
  154. });
  155. }).catch(err => {
  156. return that.$util.Tips({
  157. title: err
  158. });
  159. })
  160. },
  161. /**
  162. * 发送验证码
  163. *
  164. */
  165. async code(data) {
  166. let that = this;
  167. if (!that.phone) return that.$util.Tips({
  168. title: '请填写手机号码!'
  169. });
  170. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  171. title: '请输入正确的手机号码!'
  172. });
  173. this.disabled = true
  174. await registerVerify({
  175. phone:that.phone,
  176. key:that.key,
  177. code:that.captcha,
  178. type: 'binding',
  179. captchaType: 'blockPuzzle',
  180. captchaVerification: data.captchaVerification
  181. }).then(res => {
  182. this.disabled = false
  183. that.$util.Tips({
  184. title: res.message
  185. });
  186. that.sendCode();
  187. }).catch(err => {
  188. this.disabled = false
  189. return that.$util.Tips({
  190. title: err
  191. });
  192. });
  193. },
  194. success(data) {
  195. this.$refs.verify.hide();
  196. this.code(data);
  197. },
  198. handleVerify() {
  199. let that = this;
  200. if (!that.phone) return that.$util.Tips({
  201. title: '请填写手机号码!'
  202. });
  203. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  204. title: '请输入正确的手机号码!'
  205. });
  206. this.$refs.verify.show();
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .container{
  213. background-color: #ffffff;
  214. border-radius: 16rpx 16rpx 0 0;
  215. position: relative;
  216. padding-bottom: 30rpx;
  217. .header{
  218. position: relative;
  219. padding: 40rpx 30rpx;
  220. text-align: center;
  221. .title{
  222. color: #282828;
  223. font-size: 32rpx;
  224. }
  225. .iconfont{
  226. color: #8A8A8A;
  227. font-size: 28rpx;
  228. position: absolute;
  229. top: 0;
  230. right: 0;
  231. }
  232. .icon-guanbi5 {
  233. right: 20rpx;
  234. color: #8a8a8a;
  235. font-size: 30rpx;
  236. line-height: 30rpx;
  237. top: 20rpx;
  238. background-color: transparent;
  239. font-weight: normal;
  240. }
  241. }
  242. }
  243. .ChangePassword{
  244. padding: 0 30rpx 100rpx;
  245. }
  246. .ChangePassword .phone {
  247. font-size: 32rpx;
  248. font-weight: bold;
  249. text-align: center;
  250. margin-top: 55rpx;
  251. }
  252. .ChangePassword .list .item {
  253. height: 86rpx;
  254. margin-bottom: 30rpx;
  255. flex-direction: row;
  256. }
  257. .ChangePassword .list .item input {
  258. height: 100%;
  259. font-size: 32rpx;
  260. border: 1px solid #DCDCDC;
  261. border-radius: 43rpx;
  262. padding: 0 40rpx;
  263. }
  264. .ChangePassword .list .item .placeholder {
  265. color: #b9b9bc;
  266. }
  267. .ChangePassword .list .item input.codeIput {
  268. max-width: 400rpx;
  269. }
  270. .ChangePassword .list .item .code {
  271. font-size: 28rpx;
  272. background-color: var(--view-minorColor);
  273. color: var(--view-theme);
  274. width: 230rpx;
  275. height: 86rpx;
  276. border-radius: 43rpx;
  277. display: flex;
  278. align-items: center;
  279. justify-content: center;
  280. }
  281. .ChangePassword .list .item .code.on {
  282. color: #b9b9bc;
  283. }
  284. .ChangePassword .confirmBnt {
  285. font-size: 32rpx;
  286. width: 580rpx;
  287. height: 90rpx;
  288. border-radius: 45rpx;
  289. color: #fff;
  290. margin: 60rpx auto 0 auto;
  291. text-align: center;
  292. line-height: 90rpx;
  293. background-color: var(--view-theme);
  294. }
  295. .getPhoneBtn{
  296. font-size: 32rpx;
  297. width: 580rpx;
  298. height: 90rpx;
  299. border-radius: 45rpx;
  300. border: 1px solid #3CB625;
  301. color: #3CB625;
  302. margin: 40rpx auto 0 auto;
  303. text-align: center;
  304. line-height: 90rpx;
  305. .iconfont{
  306. font-size: 32rpx;
  307. margin-right: 12rpx;
  308. }
  309. }
  310. /deep/.verifybox{
  311. top: auto!important;
  312. }
  313. </style>