bindwechat.vue 10 KB

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