bindOperator.vue 12 KB

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