bindOperator.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. this.getWxAuthorize()
  107. },
  108. methods:{
  109. ...mapMutations(['login','logout','wxLogin']),
  110. async getWxAuthorize(){
  111. const wechatCode = await authorize.getCode('weixin')// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  112. const getUserInfo = await authorize.getUserInfo('weixin')
  113. this.UserService.UserLoginAuthApplets({
  114. code:wechatCode,
  115. encryptedData:getUserInfo.encryptedData,
  116. iv:getUserInfo.iv ,
  117. })
  118. .then(response =>{
  119. this.login(response.data)
  120. this.$store.commit('updateStatus',response.data)
  121. uni.setStorageSync('token',response.data.token)
  122. uni.setStorageSync('unionId',response.data.unionId)
  123. uni.setStorageSync('spUserId', response.data.spUserId)
  124. setTimeout(()=>{
  125. if(response.data.userIdentity === 1){
  126. this.$api.navigateTo('/pages/seller/index/index')
  127. }else if(response.data.userIdentity === 2 || response.data.userIdentity === 4){
  128. this.$api.switchTabTo('/pages/tabBar/user/user')
  129. }else if(response.data.userIdentity === 3){
  130. this.$api.navigateTo('/pages/supplier/index/index')
  131. }else{
  132. this.isUserInfo= true
  133. }
  134. },1000)
  135. })
  136. .catch(error =>{
  137. this.logout()
  138. uni.setStorageSync('unionId',error.data.unionId)
  139. this.$store.commit('updateStatus',error.data)
  140. this.isUserInfo = true
  141. })
  142. },
  143. bindWechatInfo(){
  144. if( this.bindLinkName == ''){
  145. this.$util.msg('请输入姓名',2000)
  146. return
  147. }
  148. if( this.bindMobile == ''){
  149. this.$util.msg('请输入手机号',2000)
  150. return
  151. }
  152. if(!this.$reg.isMobile(this.bindMobile)){
  153. this.$util.msg('请输入正确的手机号',2000)
  154. return
  155. }
  156. if( this.mobildeCode == ''){
  157. this.$util.msg('请输入手机验证码',2000)
  158. return
  159. }
  160. if(!this.$reg.isMobileCode(this.mobildeCode)){
  161. this.$util.msg('验证码格式不正确',2000)
  162. return
  163. }
  164. this.GetUserProfile()
  165. },
  166. getVerificationCode(){//图形验证
  167. this.PublicService.GetImgVerifyCode().then(res => {
  168. this.imageCodeUrl = res.data.baseImage
  169. this.imageCodetoken = res.data.token
  170. })
  171. },
  172. getMobileCodeFn(){//获取手机验证码
  173. if( this.bindMobile == ''){
  174. this.$util.msg('请输入手机号',2000)
  175. return
  176. }
  177. if(!this.$reg.isMobile(this.bindMobile)){
  178. this.$util.msg('请输入正确的手机号',2000)
  179. return
  180. }
  181. if( this.imageCode == ''){
  182. this.$util.msg('请输入图形验证码',2000)
  183. return
  184. }
  185. let params = {
  186. mobile:this.bindMobile,
  187. userId:uni.getStorageSync('bind_id'),
  188. platformType:2,
  189. isCheckCaptcha:0,
  190. imgCode:this.imageCode,
  191. token:this.imageCodetoken,
  192. }
  193. this.isMobileDisabled = true
  194. this.PublicService.GetBindMobileCode(params)
  195. .then(res =>{
  196. const TIME_COUNT = 60
  197. this.$util.msg('验证短信已发送',2000)
  198. if (!this.codeTime) {
  199. this.count = TIME_COUNT
  200. this.isMobileDisabled = true
  201. this.codeTime = setInterval(() => {
  202. if (this.count > 1 && this.count <= TIME_COUNT) {
  203. this.count--
  204. this.mobileCodeText = this.count +'s重新发送'
  205. } else {
  206. this.isMobileDisabled = false
  207. clearInterval(this.codeTime)
  208. this.codeTime = null
  209. this.mobileCodeText = '获取验证码'
  210. }
  211. },1000)
  212. }
  213. })
  214. .catch( error =>{
  215. this.$util.msg(error.msg,2000)
  216. this.isMobileDisabled = false
  217. })
  218. },
  219. GetUserProfile(){//获取用户微信个人信息
  220. const self = this
  221. wx.getUserProfile({
  222. desc: '采美采购商城小程序获取您的信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  223. success(res) {
  224. console.log('微信获取用户信息新API',res)
  225. self.wxLogin(res.userInfo)
  226. self.wxUserInfo.nickName = res.userInfo.nickName
  227. self.wxUserInfo.avatarUrl = res.userInfo.avatarUrl
  228. self.BindingWechat()
  229. },
  230. fail() {
  231. self.$util.msg('授权失败', 2000)
  232. }
  233. })
  234. },
  235. BindingWechat(){//绑定微信并登录
  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. 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: #FF5B00;
  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>