bind-operator.vue 11 KB

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