bindwechat.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="container login">
  3. <view class="login-main">
  4. <text class="logo-text">您的微信尚未绑定公司账号,填写以下资料进行绑定后,您能通过微信快速登录。</text>
  5. </view>
  6. <view class="login-container">
  7. <view class="login-form clearfix">
  8. <view class="login-input">
  9. <input type="text"
  10. v-model="bindLinkName"
  11. maxlength="30"
  12. class="input"
  13. placeholder="请输入姓名"
  14. />
  15. </view>
  16. </view>
  17. <view class="login-form clearfix">
  18. <view class="login-input">
  19. <input type="number"
  20. v-model="bindLinkPhone"
  21. maxlength="11"
  22. class="input"
  23. placeholder="请输入手机号"
  24. />
  25. </view>
  26. </view>
  27. <view class="login-form clearfix">
  28. <view class="login-input code">
  29. <input type="text"
  30. v-model="imageCode"
  31. maxlength="4"
  32. class="input"
  33. placeholder="请输入右侧图形验证码"
  34. />
  35. </view>
  36. <view class="login-input img-btn">
  37. <view class="vscodeimg">
  38. <image :src="imageCodeUrl" mode=""></image>
  39. </view>
  40. <view class="vscod-refresh" @click.stop="getVerificationCode">
  41. <text class="iconfont icon-shuaxin"></text>
  42. <text class="ref-text">刷新</text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="login-form clearfix">
  47. <view class="login-input code">
  48. <input type="number"
  49. v-model="smsCode"
  50. maxlength="6"
  51. class="input"
  52. placeholder="请输入短信验证码"
  53. />
  54. </view>
  55. <view class="login-input btn" :class="[isMobileDisabled ? 'disabled' : '']" >
  56. <button type="button"
  57. @click.stop="getMobileCodeFn"
  58. :disabled="isMobileDisabled"
  59. class="input">
  60. {{ mobileCodeText }}
  61. </button>
  62. </view>
  63. </view>
  64. <view class="login-form none clearfix">
  65. <view class="login-btn" @click="bindWechatInfo">绑定并登录</view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import { mapState,mapMutations } from 'vuex'
  72. import authorize from '@/common/config/authorize.js'
  73. import wxLogin from "@/common/config/wxLogin.js"
  74. import { getbindWechatCode } from "@/api/utils.js"
  75. export default{
  76. data() {
  77. return{
  78. userIdentity:'',
  79. userId:'',
  80. unionId:'',
  81. bindMobile:'',
  82. bindLinkName:'', //用户姓名
  83. bindLinkPhone:'', //用户手机号
  84. smsCode:'', //手机验证码
  85. imageCode:'', //图形验证码
  86. imageCodeUrl:'', //图形验证码地址
  87. imageCodetoken:'', //图形校验token
  88. isMobileDisabled:false, //获取手机短信按钮
  89. count: '', //倒计时
  90. mobileCodeText: '获取验证码',
  91. codeTime: null,
  92. }
  93. },
  94. onLoad(option) {
  95. this.getVerificationCode()
  96. },
  97. computed: {
  98. ...mapState(['isWxAuthorize','isLoginType','isLoginProductId','isLoginOrderId'])
  99. },
  100. methods:{
  101. ...mapMutations(['login']),
  102. bindWechatInfo(){
  103. if( this.bindLinkName == ''){
  104. this.$util.msg('请输入姓名',2000)
  105. return
  106. }
  107. if( this.bindLinkPhone == ''){
  108. this.$util.msg('请输入手机号',2000)
  109. return
  110. }
  111. if(!this.$reg.isMobile(this.bindLinkPhone)){
  112. this.$util.msg('请输入正确的手机号',2000)
  113. return
  114. }
  115. if( this.smsCode == ''){
  116. this.$util.msg('请输入手机验证码',2000)
  117. return
  118. }
  119. if(!this.$reg.isMobileCode(this.smsCode)){
  120. this.$util.msg('验证码格式不正确',2000)
  121. return
  122. }
  123. this.bindingWechatLogin()
  124. },
  125. getVerificationCode(){//图形验证
  126. this.PublicService.GetImgVerifyCode().then(res => {
  127. this.imageCodeUrl = res.data.baseImage
  128. this.imageCodetoken = res.data.token
  129. })
  130. },
  131. getMobileCodeFn(){//获取手机验证码
  132. if( this.bindLinkPhone == ''){
  133. this.$util.msg('请输入手机号',2000);
  134. return
  135. }
  136. if(!this.$reg.isMobile(this.bindLinkPhone)){
  137. this.$util.msg('请输入正确的手机号',2000);
  138. return
  139. }
  140. if( this.imageCode == ''){
  141. this.$util.msg('请输入图形验证码',2000);
  142. return
  143. }
  144. let params = {
  145. mobile:this.bindLinkPhone,
  146. bindMobile:this.bindMobile,
  147. platformType:2,
  148. isCheckCaptcha:0,
  149. imgCode:this.imageCode,
  150. token:this.imageCodetoken,
  151. }
  152. this.isMobileDisabled = true;
  153. this.PublicService.GetBindMobileCode(params)
  154. .then(res =>{
  155. const TIME_COUNT = 60;
  156. this.$util.msg('验证短信已发送',2000)
  157.       if (!this.codeTime) {
  158.         this.count = TIME_COUNT;
  159. this.isMobileDisabled = true;
  160.         this.codeTime = setInterval(() => {
  161.         if (this.count > 1 && this.count <= TIME_COUNT) {
  162.           this.count--
  163.           this.mobileCodeText = this.count +'s重新发送'
  164.          } else {
  165.           this.isMobileDisabled = false;
  166.           clearInterval(this.codeTime)
  167.           this.codeTime = null
  168. this.mobileCodeText = '获取验证码'
  169.          }
  170.         },1000)
  171.        }
  172. })
  173. .catch( error =>{
  174. this.$util.msg(error.msg,2000)
  175. this.isMobileDisabled = false;
  176. })
  177. },
  178. bindingWechatLogin(){//获取用户基本信息登录
  179. const userInfo = uni.getStorageSync('wechatUserInfo')
  180. this.isUserInfo = false;
  181. let params ={
  182. userId:this.userId,
  183. mobile:this.bindLinkPhone,
  184. linkName:this.bindLinkName,
  185. smsCode:this.smsCode,
  186. unionId:this.unionId,
  187. nickName:userInfo.nickName,
  188. avatarUrl:userInfo.avatarUrl,
  189. }
  190. this.UserService.BindingWechat(params)
  191. .then(response =>{
  192. if(this.userIdentity === 3){
  193. this.$api.navigateTo('/supplier/pages/index/index')
  194. }else{
  195. switch(this.isLoginType){
  196. case 9:
  197. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  198. break;
  199. case 8:
  200. this.$api.navigateTo(`/pages/goods/product?id=${this.isLoginProductId}`)
  201. break;
  202. case 7:
  203. this.$api.navigateTo(`/pages/user/order/order-details?type=share&orderID=${this.isLoginOrderId}`)
  204. break;
  205. default:
  206. this.$api.switchTabTo('/pages/tabBar/user/user')
  207. }
  208. }
  209. })
  210. .catch(error =>{
  211. this.$util.msg(error.msg,2000)
  212. })
  213. },
  214. //关闭未授权用户授权提示弹窗
  215. hideModel(){
  216. this.isUserInfo = false;
  217. }
  218. },
  219. onShow() {
  220. this.$api.getStorage().then((resolve) => {
  221. console.log(resolve)
  222. this.unionId = resolve.unionId
  223. console.log(this.unionId)
  224. this.userId = resolve.userId
  225. this.bindMobile = resolve.bindMobile
  226. this.userIdentity = resolve.userIdentity
  227. })
  228. }
  229. }
  230. </script>
  231. <style lang="scss">
  232. .login{
  233. width: 100%;
  234. height: auto;
  235. box-sizing: border-box;
  236. border-top: 1px solid #F7F7F7;
  237. .model-warp.none{
  238. display: none;
  239. }
  240. .model-warp.show{
  241. display: block;
  242. }
  243. .login-main{
  244. width: 100%;
  245. background: rgba(225, 86, 22, 0.1);
  246. display: flex;
  247. flex-direction: column;
  248. align-items: center;
  249. height: 68rpx;
  250. padding: 20rpx 24rpx;
  251. margin: 24rpx 0 118rpx 0;
  252. box-sizing: border-box;
  253. .logo-text{
  254. font-size: 24rpx;
  255. line-height: 34rpx;
  256. color: $color-system;
  257. }
  258. }
  259. .login-container{
  260. width: 100%;
  261. height: auto;
  262. padding: 0 24rpx;
  263. box-sizing: border-box;
  264. }
  265. .login-form{
  266. width: 100%;
  267. height: auto;
  268. box-sizing: border-box;
  269. border-bottom: 1px solid #E1E1E1;
  270. &.none{
  271. border-bottom: none;
  272. }
  273. .login-input{
  274. width: 100%;
  275. height: 60rpx;
  276. padding: 20rpx 0;
  277. background: #FFFFFF;
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. &.code{
  282. width: 370rpx;
  283. float: left;
  284. margin-right: 20rpx;
  285. }
  286. &.btn{
  287. width: 220rpx;
  288. height: 64rpx;
  289. padding: 0;
  290. float: left;
  291. background: $btn-confirm;
  292. border-radius: 32rpx;
  293. margin-top: 15rpx;
  294. .input{
  295. width: 220rpx;
  296. height: 64rpx;
  297. line-height: 64rpx;
  298. padding: 0;
  299. border-radius: 32rpx;
  300. color: #FFFFFF;
  301. background: $btn-confirm;
  302. }
  303. &.disabled{
  304. background: #F7F7F7;
  305. .input{
  306. background: #F7F7F7;
  307. color: #999999;
  308. }
  309. }
  310. }
  311. &.img-btn{
  312. width: 300rpx;
  313. height: 64rpx;
  314. padding: 0;
  315. float: left;
  316. background: #FFFFFF;
  317. display: block;
  318. border-bottom: none;
  319. margin-top: 16rpx;
  320. .vscodeimg{
  321. width: 160rpx;
  322. height: 64rpx;
  323. float: left;
  324. display: flex;
  325. flex-direction: column;
  326. align-items: center;
  327. border-radius: 6rpx;
  328. image{
  329. width: 180rpx;
  330. height: 88rpx;
  331. border-radius: 6rpx;
  332. }
  333. }
  334. .vscod-refresh{
  335. width: 100rpx;
  336. float: right;
  337. height: 64rpx;
  338. .icon-shuaxin{
  339. font-size: 40rpx;
  340. color: #999999;
  341. display: block;
  342. float: left;
  343. height: 64rpx;
  344. line-height: 64rpx;
  345. }
  346. .ref-text{
  347. display: block;
  348. float: right;
  349. height: 64rpx;
  350. line-height: 64rpx;
  351. font-size: 24rpx;
  352. color: #999999;
  353. }
  354. }
  355. }
  356. .input{
  357. width: 100%;
  358. height: 100%;
  359. background: #FFFFFF;
  360. font-size: $font-size-28;
  361. line-height: 40rpx;
  362. color: #333333;
  363. border-radius: 14rpx;
  364. }
  365. }
  366. }
  367. .login-btn{
  368. width: 600rpx;
  369. height: 88rpx;
  370. border-radius: 44rpx;
  371. font-size: $font-size-28;
  372. line-height: 88rpx;
  373. color: #FFFFFF;
  374. margin: 0 auto;
  375. text-align: center;
  376. background: $btn-confirm;
  377. margin-top: 100rpx;
  378. }
  379. .model-authorization{
  380. width: 100%;
  381. height: 100%;
  382. position: fixed;
  383. top: 0;
  384. left: 0;
  385. z-index: 999;
  386. .authorization{
  387. width: 518rpx;
  388. height: 320rpx;
  389. position: absolute;
  390. background: rgba(255,255,255,.7);
  391. left: 0;
  392. right: 0;
  393. bottom: 0;
  394. top: 0;
  395. margin: auto;
  396. .to-btn{
  397. position: absolute;
  398. top: 0;
  399. left: 0;
  400. right: 0;
  401. bottom: 0;
  402. margin: auto;
  403. width: 70%;
  404. height: 88rpx;
  405. font-size: $font-size-28;
  406. line-height: 88rpx;
  407. color: #FFFFFF;
  408. text-align: center;
  409. border-radius: 44rpx;
  410. }
  411. }
  412. }
  413. }
  414. </style>