bindwechat.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. wx.getUserInfo({
  180. success: res => {
  181. this.isUserInfo = false;
  182. this.userInfo = res.userInfo;
  183. let params ={
  184. userId:this.userId,
  185. mobile:this.bindLinkPhone,
  186. linkName:this.bindLinkName,
  187. smsCode:this.smsCode,
  188. unionId:this.unionId,
  189. nickName:res.userInfo.nickName,
  190. avatarUrl:res.userInfo.avatarUrl,
  191. }
  192. this.UserService.BindingWechat(params)
  193. .then(response =>{
  194. if(this.userIdentity === 3){
  195. this.$api.navigateTo('/supplier/pages/index/index')
  196. }else{
  197. switch(this.isLoginType){
  198. case 9:
  199. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  200. break;
  201. case 8:
  202. this.$api.navigateTo(`/pages/goods/product?id=${this.isLoginProductId}`)
  203. break;
  204. case 7:
  205. this.$api.navigateTo(`/pages/user/order/order-details?type=share&orderID=${this.isLoginOrderId}`)
  206. break;
  207. default:
  208. this.$api.switchTabTo('/pages/tabBar/user/user')
  209. }
  210. }
  211. })
  212. .catch(error =>{
  213. this.$util.msg(error.msg,2000)
  214. })
  215. }
  216. })
  217. },
  218. //关闭未授权用户授权提示弹窗
  219. hideModel(){
  220. this.isUserInfo = false;
  221. }
  222. },
  223. onShow() {
  224. this.$api.getStorage().then((resolve) => {
  225. console.log(resolve)
  226. this.unionId = resolve.unionId
  227. console.log(this.unionId)
  228. this.userId = resolve.userId
  229. this.bindMobile = resolve.bindMobile
  230. this.userIdentity = resolve.userIdentity
  231. })
  232. }
  233. }
  234. </script>
  235. <style lang="scss">
  236. .login{
  237. width: 100%;
  238. height: auto;
  239. box-sizing: border-box;
  240. border-top: 1px solid #F7F7F7;
  241. .model-warp.none{
  242. display: none;
  243. }
  244. .model-warp.show{
  245. display: block;
  246. }
  247. .login-main{
  248. width: 100%;
  249. background: rgba(225, 86, 22, 0.1);
  250. display: flex;
  251. flex-direction: column;
  252. align-items: center;
  253. height: 68rpx;
  254. padding: 20rpx 24rpx;
  255. margin: 24rpx 0 118rpx 0;
  256. box-sizing: border-box;
  257. .logo-text{
  258. font-size: 24rpx;
  259. line-height: 34rpx;
  260. color: $color-system;
  261. }
  262. }
  263. .login-container{
  264. width: 100%;
  265. height: auto;
  266. padding: 0 24rpx;
  267. box-sizing: border-box;
  268. }
  269. .login-form{
  270. width: 100%;
  271. height: auto;
  272. box-sizing: border-box;
  273. border-bottom: 1px solid #E1E1E1;
  274. &.none{
  275. border-bottom: none;
  276. }
  277. .login-input{
  278. width: 100%;
  279. height: 60rpx;
  280. padding: 20rpx 0;
  281. background: #FFFFFF;
  282. display: flex;
  283. flex-direction: column;
  284. align-items: center;
  285. &.code{
  286. width: 370rpx;
  287. float: left;
  288. margin-right: 20rpx;
  289. }
  290. &.btn{
  291. width: 220rpx;
  292. height: 64rpx;
  293. padding: 0;
  294. float: left;
  295. background: $btn-confirm;
  296. border-radius: 32rpx;
  297. margin-top: 15rpx;
  298. .input{
  299. width: 220rpx;
  300. height: 64rpx;
  301. line-height: 64rpx;
  302. padding: 0;
  303. border-radius: 32rpx;
  304. color: #FFFFFF;
  305. background: $btn-confirm;
  306. }
  307. &.disabled{
  308. background: #F7F7F7;
  309. .input{
  310. background: #F7F7F7;
  311. color: #999999;
  312. }
  313. }
  314. }
  315. &.img-btn{
  316. width: 300rpx;
  317. height: 64rpx;
  318. padding: 0;
  319. float: left;
  320. background: #FFFFFF;
  321. display: block;
  322. border-bottom: none;
  323. margin-top: 16rpx;
  324. .vscodeimg{
  325. width: 160rpx;
  326. height: 64rpx;
  327. float: left;
  328. display: flex;
  329. flex-direction: column;
  330. align-items: center;
  331. border-radius: 6rpx;
  332. image{
  333. width: 180rpx;
  334. height: 88rpx;
  335. border-radius: 6rpx;
  336. }
  337. }
  338. .vscod-refresh{
  339. width: 100rpx;
  340. float: right;
  341. height: 64rpx;
  342. .icon-shuaxin{
  343. font-size: 40rpx;
  344. color: #999999;
  345. display: block;
  346. float: left;
  347. height: 64rpx;
  348. line-height: 64rpx;
  349. }
  350. .ref-text{
  351. display: block;
  352. float: right;
  353. height: 64rpx;
  354. line-height: 64rpx;
  355. font-size: 24rpx;
  356. color: #999999;
  357. }
  358. }
  359. }
  360. .input{
  361. width: 100%;
  362. height: 100%;
  363. background: #FFFFFF;
  364. font-size: $font-size-28;
  365. line-height: 40rpx;
  366. color: #333333;
  367. border-radius: 14rpx;
  368. }
  369. }
  370. }
  371. .login-btn{
  372. width: 600rpx;
  373. height: 88rpx;
  374. border-radius: 44rpx;
  375. font-size: $font-size-28;
  376. line-height: 88rpx;
  377. color: #FFFFFF;
  378. margin: 0 auto;
  379. text-align: center;
  380. background: $btn-confirm;
  381. margin-top: 100rpx;
  382. }
  383. .model-authorization{
  384. width: 100%;
  385. height: 100%;
  386. position: fixed;
  387. top: 0;
  388. left: 0;
  389. z-index: 999;
  390. .authorization{
  391. width: 518rpx;
  392. height: 320rpx;
  393. position: absolute;
  394. background: rgba(255,255,255,.7);
  395. left: 0;
  396. right: 0;
  397. bottom: 0;
  398. top: 0;
  399. margin: auto;
  400. .to-btn{
  401. position: absolute;
  402. top: 0;
  403. left: 0;
  404. right: 0;
  405. bottom: 0;
  406. margin: auto;
  407. width: 70%;
  408. height: 88rpx;
  409. font-size: $font-size-28;
  410. line-height: 88rpx;
  411. color: #FFFFFF;
  412. text-align: center;
  413. border-radius: 44rpx;
  414. }
  415. }
  416. }
  417. }
  418. </style>