bindOperator.vue 11 KB

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