bindOperator.vue 11 KB

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