bindwechat.vue 9.7 KB

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