bind-operator.vue 11 KB

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