bindwechat.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view class="container login">
  3. <view class="login-main">
  4. <text class="logo-text">您的微信尚未绑定机构账号,填写以下资料进行绑定后,您能通过微信快速登录。</text>
  5. </view>
  6. <view class="login-form clearfix">
  7. <view class="login-input">
  8. <input type="text"
  9. v-model="bindLinkName"
  10. maxlength="30"
  11. class="input"
  12. placeholder="请输入姓名"
  13. />
  14. </view>
  15. </view>
  16. <view class="login-form clearfix">
  17. <view class="login-input">
  18. <input type="number"
  19. v-model="bindLinkPhone"
  20. maxlength="11"
  21. class="input"
  22. placeholder="请输入手机号"
  23. />
  24. </view>
  25. </view>
  26. <view class="login-form clearfix">
  27. <view class="login-input code">
  28. <input type="text"
  29. v-model="imageCode"
  30. maxlength="6"
  31. class="input"
  32. placeholder="请输入右侧图形验证码"
  33. />
  34. </view>
  35. <view class="login-input img-btn">
  36. <view class="vscodeimg">
  37. <image :src="imageCodeUrl" mode=""></image>
  38. </view>
  39. <view class="vscod-refresh" @click.stop="getVerificationCode">
  40. <text class="iconfont icon-shuaxin"></text>
  41. <text class="ref-text">刷新</text>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="login-form clearfix">
  46. <view class="login-input code">
  47. <input type="number"
  48. v-model="mobildeCode"
  49. maxlength="6"
  50. class="input"
  51. placeholder="请输入短信验证码"
  52. />
  53. </view>
  54. <view class="login-input btn" :class="[isMobileDisabled ? 'disabled' : '']" >
  55. <button type="button"
  56. @click.stop="getMobileCodeFn"
  57. :disabled="isMobileDisabled"
  58. class="input">
  59. {{ mobileCodeText }}
  60. </button>
  61. </view>
  62. </view>
  63. <view class="login-form clearfix">
  64. <view class="login-btn" @click="bindWechatInfo">绑定并登录</view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import { mapState,mapMutations } from 'vuex'
  70. import authorize from '@/common/config/authorize.js'
  71. import { bindingWechat } from "@/api/use.js"
  72. import { getImageCode, getbindWechatCode } from "@/api/utils.js"
  73. export default{
  74. data() {
  75. return{
  76. userID:'',
  77. bindMobile:'',
  78. bindLinkName:'', //用户姓名
  79. bindLinkPhone:'', //用户手机号
  80. mobildeCode:'', //手机验证码
  81. imageCode:'', //图形验证码
  82. imageCodeUrl:'', //图形验证码地址
  83. imageCodetoken:'', //图形校验token
  84. isMobileDisabled:false, //获取手机短信按钮
  85. count: '', //倒计时
  86. mobileCodeText: '获取验证码',
  87. codeTime: null,
  88. loginType:'', //跳转类型
  89. alertText:'',
  90. listType: '',
  91. listVal: '',
  92. detilType:'',
  93. id:'',//商品ID
  94. getOption:''
  95. }
  96. },
  97. onLoad(option) {
  98. let data = JSON.parse(option.data);
  99. this.codeType = option.codeType
  100. this.option = option
  101. this.loginType = data.type;
  102. this.id = data.id
  103. if(data.listType) {
  104. this.listType = data.listType;
  105. this.listVal = data.listVal;
  106. }
  107. this.getVerificationCode()
  108. },
  109. methods:{
  110. ...mapMutations(['login']),
  111. bindWechatInfo(){
  112. if( this.bindLinkName == ''){
  113. this.$util.msg('请输入姓名',2000)
  114. return
  115. }
  116. if( this.bindLinkPhone == ''){
  117. this.$util.msg('请输入手机号',2000)
  118. return
  119. }
  120. if(!this.$reg.isMobile(this.bindLinkPhone)){
  121. this.$util.msg('请输入正确的手机号',2000)
  122. return
  123. }
  124. if( this.mobildeCode == ''){
  125. this.$util.msg('请输入手机验证码',2000)
  126. return
  127. }
  128. if(!this.$reg.isMobileCode(this.mobildeCode)){
  129. this.$util.msg('验证码格式不正确',2000)
  130. return
  131. }
  132. this.bindingWechatLogin()
  133. },
  134. getVerificationCode(){//图形验证
  135. getImageCode().then(res => {
  136. this.imageCodeUrl = res.data.baseImage
  137. this.imageCodetoken = res.data.token
  138. })
  139. },
  140. getMobileCodeFn(){//获取手机验证码
  141. if( this.bindLinkPhone == ''){
  142. this.$util.msg('请输入手机号',2000);
  143. return
  144. }
  145. if(!this.$reg.isMobile(this.bindLinkPhone)){
  146. this.$util.msg('请输入正确的手机号',2000);
  147. return
  148. }
  149. if( this.imageCode == ''){
  150. this.$util.msg('请输入图形验证码',2000);
  151. return
  152. }
  153. let params = {
  154. mobile:this.bindLinkPhone,
  155. mobileOrEmail:this.bindMobile,
  156. platformType:2,
  157. imgCode:this.imageCode,
  158. token:this.imageCodetoken,
  159. }
  160. this.isMobileDisabled = true;
  161. getbindWechatCode(params).then(res =>{
  162. const TIME_COUNT = 60;
  163. this.$util.msg('验证短信已发送',2000)
  164.       if (!this.codeTime) {
  165.         this.count = TIME_COUNT;
  166. this.isMobileDisabled = true;
  167.         this.codeTime = setInterval(() => {
  168.         if (this.count > 1 && this.count <= TIME_COUNT) {
  169.           this.count--
  170.           this.mobileCodeText = this.count +'s重新发送'
  171.          } else {
  172.           this.isMobileDisabled = false;
  173.           clearInterval(this.codeTime)
  174.           this.codeTime = null
  175. this.mobileCodeText = '获取验证码'
  176.          }
  177.         },1000)
  178.        }
  179. }).catch( res =>{
  180. console.log(res)
  181. this.$util.msg(res.msg,2000)
  182. this.isMobileDisabled = false
  183. console.log(this.isMobileDisabled)
  184. })
  185. },
  186. bindingWechatLogin(){//获取用户基本信息登录
  187. wx.getUserInfo({
  188. success: res => {
  189. console.log('useInfo:',res.userInfo)
  190. this.isUserInfo = false;
  191. this.userInfo = res.userInfo;
  192. let params ={
  193. userID:this.userID,
  194. mobile:this.bindLinkPhone,
  195. linkName:this.bindLinkName,
  196. verificationCode:this.mobildeCode,
  197. nickName:res.userInfo.nickName,
  198. headimgurl:res.userInfo.avatarUrl,
  199. }
  200. bindingWechat(params).then(response =>{
  201. // this.login(response.data);
  202. uni.switchTab({
  203. url:'/pages/tabBar/user/user'
  204. })
  205. }).catch(response =>{
  206. this.$util.msg(response.msg,2000)
  207. })
  208. }
  209. })
  210. },
  211. goUserLogininit(){
  212. let url;
  213. if(this.loginType) {
  214. if(this.loginType=='detilType'){
  215. this.$api.redirectTo(`/pages/goods/product?id=${this.id}&page=2`);
  216. }else if(this.loginType=='search'){
  217. this.$api.redirectTo('/pages/search/search');
  218. }else if(this.loginType == 1){
  219. url ='/pages/tabBar/cart/cart'
  220. }else if(this.loginType == 4){
  221. url ='/pages/tabBar/user/user'
  222. }else {
  223. url ='/pages/tabBar/home/home'
  224. }
  225. } else if(this.listType) {
  226. this.$api.navToListPage({type:this.listType,value:this.listVal,lType:'4'});
  227. }
  228. },
  229. //关闭未授权用户授权提示弹窗
  230. hideModel(){
  231. this.isUserInfo = false;
  232. }
  233. },
  234. onShow() {
  235. this.$api.getStorage().then((resolve) => {
  236. this.userID = resolve.userID
  237. this.bindMobile = resolve.bindMobile
  238. })
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. .login{
  244. width: 100%;
  245. height: auto;
  246. border-top: 1px solid #F7F7F7;
  247. .model-warp.none{
  248. display: none;
  249. }
  250. .model-warp.show{
  251. display: block;
  252. }
  253. .login-main{
  254. width: 702rpx;
  255. background: rgba(225, 86, 22, 0.1);
  256. display: flex;
  257. flex-direction: column;
  258. align-items: center;
  259. height: 68rpx;
  260. padding: 20rpx 24rpx;
  261. margin: 24rpx 0 118rpx 0;
  262. .logo-text{
  263. font-size: 24rpx;
  264. line-height: 34rpx;
  265. color: $color-system;
  266. }
  267. }
  268. .login-form{
  269. width: 702rpx;
  270. height: auto;
  271. padding: 0 24rpx;
  272. .login-input{
  273. width: 654rpx;
  274. height: 40rpx;
  275. padding: 24rpx;
  276. margin-bottom: 20rpx;
  277. background: #F7F7F7;
  278. border-radius: 14rpx;
  279. display: flex;
  280. flex-direction: column;
  281. align-items: center;
  282. &.code{
  283. width: 370rpx;
  284. float: left;
  285. margin-right: 20rpx;
  286. }
  287. &.btn{
  288. width: 258rpx;
  289. height: 88rpx;
  290. padding: 0;
  291. float: left;
  292. background: $btn-confirm;
  293. .input{
  294. width: 258rpx;
  295. height: 88rpx;
  296. line-height: 88rpx;
  297. padding: 0;
  298. border-radius: 14rpx;
  299. color: #FFFFFF;
  300. background: $btn-confirm;
  301. }
  302. &.disabled{
  303. background: #F7F7F7;
  304. .input{
  305. background: #F7F7F7;
  306. color: #999999;
  307. }
  308. }
  309. }
  310. &.img-btn{
  311. width: 250rpx;
  312. height: 88rpx;
  313. padding: 0;
  314. float: left;
  315. background: #FFFFFF;
  316. display: block;
  317. .vscodeimg{
  318. width: 180rpx;
  319. height: 88rpx;
  320. float: left;
  321. display: flex;
  322. flex-direction: column;
  323. align-items: center;
  324. border-radius: 14rpx;
  325. image{
  326. width: 180rpx;
  327. height: 88rpx;
  328. border-radius: 14rpx;
  329. }
  330. }
  331. .vscod-refresh{
  332. width: 70rpx;
  333. float: right;
  334. display: flex;
  335. flex-direction: column;
  336. align-items: center;
  337. .icon-shuaxin{
  338. font-size: 48rpx;
  339. color: #333333;
  340. }
  341. .ref-text{
  342. font-size: 24rpx;
  343. color: #333333;
  344. }
  345. }
  346. }
  347. .input{
  348. width: 100%;
  349. height: 100%;
  350. background: #F7F7F7;
  351. font-size: $font-size-28;
  352. line-height: 40rpx;
  353. color: #333333;
  354. border-radius: 14rpx;
  355. }
  356. }
  357. }
  358. .login-btn{
  359. width: 702rpx;
  360. height: 88rpx;
  361. border-radius: 14rpx;
  362. font-size: $font-size-28;
  363. line-height: 88rpx;
  364. color: #FFFFFF;
  365. margin: 0 auto;
  366. text-align: center;
  367. background: $btn-confirm;
  368. margin-top: 100rpx;
  369. }
  370. .model-authorization{
  371. width: 100%;
  372. height: 100%;
  373. position: fixed;
  374. top: 0;
  375. left: 0;
  376. z-index: 999;
  377. .authorization{
  378. width: 518rpx;
  379. height: 320rpx;
  380. position: absolute;
  381. background: rgba(255,255,255,.7);
  382. left: 0;
  383. right: 0;
  384. bottom: 0;
  385. top: 0;
  386. margin: auto;
  387. .to-btn{
  388. position: absolute;
  389. top: 0;
  390. left: 0;
  391. right: 0;
  392. bottom: 0;
  393. margin: auto;
  394. width: 70%;
  395. height: 88rpx;
  396. font-size: $font-size-28;
  397. line-height: 88rpx;
  398. color: #FFFFFF;
  399. text-align: center;
  400. border-radius: 44rpx;
  401. }
  402. }
  403. }
  404. }
  405. </style>