bindwechat.vue 10.0 KB

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