bindOperator.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view class="container login" >
  3. <!-- v-if="isUserInfo" -->
  4. <view class="login-form title">
  5. <view class="text">
  6. <label class="iconfont icon-tishi"></label>请填写如下信息成为机构运营人员后才能操作订单
  7. </view>
  8. </view>
  9. <view class="login-form clearfix">
  10. <view class="login-input">
  11. <input type="text"
  12. v-model="bindLinkName"
  13. maxlength="30"
  14. class="input"
  15. placeholder="请输入姓名"
  16. placeholder-class="placeholder"
  17. />
  18. </view>
  19. </view>
  20. <view class="login-form clearfix">
  21. <view class="login-input">
  22. <input type="number"
  23. v-model="bindMobile"
  24. maxlength="11"
  25. class="input"
  26. placeholder="请输入手机号"
  27. placeholder-class="placeholder"
  28. />
  29. </view>
  30. </view>
  31. <view class="login-form clearfix">
  32. <view class="login-input code">
  33. <input type="text"
  34. v-model="imageCode"
  35. maxlength="4"
  36. class="input"
  37. placeholder="请输入右侧图形验证码"
  38. placeholder-class="placeholder"
  39. />
  40. </view>
  41. <view class="login-input img-btn">
  42. <view class="vscodeimg">
  43. <image :src="imageCodeUrl" mode=""></image>
  44. </view>
  45. <view class="vscod-refresh" @click.stop="getVerificationCode">
  46. <text class="iconfont icon-shuaxin"></text>
  47. <text class="ref-text">刷新</text>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="login-form clearfix">
  52. <view class="login-input code">
  53. <input type="number"
  54. v-model="mobildeCode"
  55. maxlength="6"
  56. class="input"
  57. placeholder="请输入短信验证码"
  58. placeholder-class="placeholder"
  59. />
  60. </view>
  61. <view class="login-input btn" :class="[isMobileDisabled ? 'disabled' : '']" >
  62. <button type="button"
  63. @click.stop="getMobileCodeFn"
  64. :disabled="isMobileDisabled"
  65. class="input">
  66. {{ mobileCodeText }}
  67. </button>
  68. </view>
  69. </view>
  70. <view class="login-form clearfix">
  71. <view class="login-btn" @click="bindWechatInfo">绑定</view>
  72. </view>
  73. <view class="login-foot">
  74. <text class="foot-text">本操作会绑定您的微信,绑定后您可使用微信直接登录【采美采购商城】小程序。</text>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. import { mapState,mapMutations } from 'vuex'
  80. import authorize from '@/common/config/authorize.js'
  81. import wxLogin from "@/common/config/wxLogin.js"
  82. import { getbindOperatorCode } from "@/api/utils.js"
  83. export default{
  84. data() {
  85. return{
  86. wxUserInfo:'', //储存用户微信信息
  87. bindLinkName:'', //用户姓名
  88. bindMobile:'', //用户手机号
  89. mobildeCode:'', //手机验证码
  90. imageCode:'', //图形验证码
  91. imageCodeUrl:'', //图形验证码地址
  92. imageCodetoken:'', //图形校验token
  93. isMobileDisabled:false, //获取手机短信按钮
  94. count: '', //倒计时
  95. mobileCodeText: '获取验证码',
  96. codeTime: null,
  97. isUserInfo:false
  98. }
  99. },
  100. onLoad(option) {
  101. console.log(option)
  102. uni.setStorageSync('bind_id', option.userID);
  103. this.getVerificationCode()
  104. authorize.checkLogin().then(res => {
  105. this.getWxAuthorize()
  106. })
  107. .catch(err => {
  108. this.$api.navigateTo('/pages/authorization/authorization')
  109. this.isUserInfo = true
  110. })
  111. },
  112. computed: {
  113. ...mapState(['isWxAuthorize'])
  114. },
  115. methods:{
  116. ...mapMutations(['login','logout']),
  117. async getWxAuthorize(){
  118. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  119. const getUserInfo = await authorize.getUserInfo('weixin');
  120. this.UserService.UserLoginAuthApplets({
  121. code:wechatCode,
  122. encryptedData:getUserInfo.encryptedData,
  123. iv:getUserInfo.iv ,
  124. })
  125. .then(response =>{
  126. this.login(response.data);
  127. this.$store.commit('updateStatus',response.data)
  128. uni.setStorageSync('token',response.data.token)
  129. uni.setStorageSync('unionId',response.data.unionId)
  130. setTimeout(()=>{
  131. if(response.data.userIdentity === 1){
  132. this.$api.navigateTo('/seller/pages/index/index')
  133. }else if(response.data.userIdentity === 2 || response.data.userIdentity === 4){
  134. this.$api.switchTabTo('/pages/tabBar/user/user')
  135. }else if(response.data.userIdentity === 3){
  136. this.$api.navigateTo('/supplier/pages/index/index')
  137. }else{
  138. this.isUserInfo= true
  139. }
  140. },1000)
  141. })
  142. .catch(error =>{
  143. this.logout()
  144. uni.setStorageSync('unionId',error.data.unionId)
  145. this.$store.commit('updateStatus',error.data)
  146. this.isUserInfo = true
  147. })
  148. },
  149. bindWechatInfo(){
  150. if( this.bindLinkName == ''){
  151. this.$util.msg('请输入姓名',2000)
  152. return
  153. }
  154. if( this.bindMobile == ''){
  155. this.$util.msg('请输入手机号',2000)
  156. return
  157. }
  158. if(!this.$reg.isMobile(this.bindMobile)){
  159. this.$util.msg('请输入正确的手机号',2000)
  160. return
  161. }
  162. if( this.mobildeCode == ''){
  163. this.$util.msg('请输入手机验证码',2000)
  164. return
  165. }
  166. if(!this.$reg.isMobileCode(this.mobildeCode)){
  167. this.$util.msg('验证码格式不正确',2000)
  168. return
  169. }
  170. authorize.checkLogin().then(res => {
  171. this.bindingWechatLogin()
  172. })
  173. .catch(err => {
  174. this.$api.navigateTo('/pages/authorization/authorization')
  175. })
  176. },
  177. getVerificationCode(){//图形验证
  178. this.PublicService.GetImgVerifyCode().then(res => {
  179. this.imageCodeUrl = res.data.baseImage
  180. this.imageCodetoken = res.data.token
  181. })
  182. },
  183. getMobileCodeFn(){//获取手机验证码
  184. if( this.bindMobile == ''){
  185. this.$util.msg('请输入手机号',2000);
  186. return
  187. }
  188. if(!this.$reg.isMobile(this.bindMobile)){
  189. this.$util.msg('请输入正确的手机号',2000);
  190. return
  191. }
  192. if( this.imageCode == ''){
  193. this.$util.msg('请输入图形验证码',2000);
  194. return
  195. }
  196. let params = {
  197. mobile:this.bindMobile,
  198. userId:uni.getStorageSync('bind_id'),
  199. platformType:2,
  200. isCheckCaptcha:0,
  201. imgCode:this.imageCode,
  202. token:this.imageCodetoken,
  203. }
  204. this.isMobileDisabled = true;
  205. this.PublicService.GetBindMobileCode(params)
  206. .then(res =>{
  207. const TIME_COUNT = 60;
  208. this.$util.msg('验证短信已发送',2000)
  209.       if (!this.codeTime) {
  210.         this.count = TIME_COUNT;
  211. this.isMobileDisabled = true;
  212.         this.codeTime = setInterval(() => {
  213.         if (this.count > 1 && this.count <= TIME_COUNT) {
  214.           this.count--
  215.           this.mobileCodeText = this.count +'s重新发送'
  216.          } else {
  217.           this.isMobileDisabled = false;
  218.           clearInterval(this.codeTime)
  219.           this.codeTime = null
  220. this.mobileCodeText = '获取验证码'
  221.          }
  222.         },1000)
  223.        }
  224. })
  225. .catch( error =>{
  226. this.$util.msg(error.msg,2000)
  227. this.isMobileDisabled = false;
  228. })
  229. },
  230. bindingWechatLogin(){//获取用户基本信息登录
  231. wx.getUserInfo({
  232. success: res => {
  233. this.wxUserInfo = res.userInfo;
  234. let params ={
  235. userId:uni.getStorageSync('bind_id'),
  236. mobile:this.bindMobile,
  237. linkName:this.bindLinkName,
  238. smsCode:this.mobildeCode,
  239. unionId:uni.getStorageSync('unionId'),
  240. nickName:this.wxUserInfo.nickName,
  241. avatarUrl:this.wxUserInfo.avatarUrl,
  242. }
  243. this.UserService.BindingWechat(params).then(response =>{
  244. this.login(response.data)
  245. this.$api.switchTabTo('/pages/tabBar/home/index')
  246. }).catch(error =>{
  247. this.$util.msg(error.msg,2000)
  248. this.isUserInfo = true
  249. })
  250. }
  251. })
  252. }
  253. },
  254. onShow() {
  255. }
  256. }
  257. </script>
  258. <style lang="scss">
  259. .login{
  260. width: 100%;
  261. height: auto;
  262. border-top: 1px solid #F7F7F7;
  263. padding-top: 30rpx;
  264. .login-foot{
  265. width: 528rpx;
  266. height: 88rpx;
  267. padding: 0 24rpx;
  268. margin: 30rpx auto;
  269. text-align: center;
  270. .foot-text{
  271. font-size: 24rpx;
  272. line-height: 44rpx;
  273. color:#999999;
  274. }
  275. }
  276. .login-form{
  277. width: 702rpx;
  278. height: auto;
  279. padding: 0 24rpx;
  280. &.title{
  281. color: #e15616;
  282. font-size: 24rpx;
  283. text-align: center;
  284. margin-bottom: 20rpx;
  285. .text{
  286. padding: 20rpx 24rpx;
  287. background: #fff0e9;
  288. border-radius: 16rpx;
  289. .iconfont{
  290. margin-right: 20rpx;
  291. position: relative;
  292. top: 5rpx;
  293. }
  294. }
  295. }
  296. .login-input{
  297. width: 654rpx;
  298. height: 40rpx;
  299. padding: 24rpx;
  300. margin-bottom: 20rpx;
  301. display: flex;
  302. flex-direction: column;
  303. align-items: center;
  304. border-bottom: 1rpx solid #e1e1e1;
  305. &.code{
  306. width: 370rpx;
  307. float: left;
  308. margin-right: 10rpx;
  309. }
  310. &.btn{
  311. width: 258rpx;
  312. height: 88rpx;
  313. padding: 0;
  314. float: left;
  315. border: 0;
  316. .input{
  317. width: 280rpx;
  318. height: 88rpx;
  319. line-height: 88rpx;
  320. padding: 0;
  321. border-radius: 45rpx;
  322. color: #FFFFFF;
  323. background: $btn-confirm;
  324. }
  325. &.disabled{
  326. background: #F7F7F7;
  327. .input{
  328. color: #999999;
  329. }
  330. }
  331. }
  332. &.img-btn{
  333. width: 270rpx;
  334. height: 88rpx;
  335. padding: 0;
  336. float: left;
  337. background: #FFFFFF;
  338. display: block;
  339. border: 0;
  340. .vscodeimg{
  341. width: 160rpx;
  342. height: 64rpx;
  343. float: left;
  344. display: flex;
  345. flex-direction: column;
  346. align-items: center;
  347. border-radius: 6rpx;
  348. image{
  349. width: 180rpx;
  350. height: 88rpx;
  351. border-radius: 14rpx;
  352. }
  353. }
  354. .vscod-refresh{
  355. width: 95rpx;
  356. float: right;
  357. // display: flex;
  358. flex-direction: column;
  359. align-items: center;
  360. margin-top: 10rpx;
  361. .icon-shuaxin{
  362. font-size: 36rpx;
  363. color: #999999;
  364. display: inline-block;
  365. }
  366. .ref-text{
  367. font-size: 24rpx;
  368. color: #999999;
  369. display: inline-block;
  370. margin-left: 10rpx;
  371. }
  372. }
  373. }
  374. .input{
  375. width: 100%;
  376. height: 100%;
  377. // background: #F7F7F7;
  378. font-size: $font-size-28;
  379. line-height: 40rpx;
  380. color: #333333;
  381. border-radius: 14rpx;
  382. }
  383. }
  384. }
  385. .login-btn{
  386. width: 600rpx;
  387. height: 88rpx;
  388. border-radius: 44rpx;
  389. font-size: $font-size-28;
  390. line-height: 88rpx;
  391. color: #FFFFFF;
  392. margin: 0 auto;
  393. text-align: center;
  394. background: $btn-confirm;
  395. margin-top: 100rpx;
  396. }
  397. .model-authorization{
  398. width: 100%;
  399. height: 100%;
  400. position: fixed;
  401. top: 0;
  402. left: 0;
  403. z-index: 999;
  404. .authorization{
  405. width: 518rpx;
  406. height: 320rpx;
  407. position: absolute;
  408. background: rgba(255,255,255,.7);
  409. left: 0;
  410. right: 0;
  411. bottom: 0;
  412. top: 0;
  413. margin: auto;
  414. .to-btn{
  415. position: absolute;
  416. top: 0;
  417. left: 0;
  418. right: 0;
  419. bottom: 0;
  420. margin: auto;
  421. width: 70%;
  422. height: 88rpx;
  423. font-size: $font-size-28;
  424. line-height: 88rpx;
  425. color: #FFFFFF;
  426. text-align: center;
  427. border-radius: 44rpx;
  428. }
  429. }
  430. }
  431. }
  432. .placeholder{
  433. color:#b2b2b2 ;
  434. }
  435. </style>