bindOperator.vue 11 KB

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