bindOperator.vue 11 KB

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