bindwechat.vue 9.9 KB

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