bindOperator.vue 11 KB

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