bindwechat.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. this.$util.msg(res.msg,2000)
  181. this.isMobileDisabled = false;
  182. })
  183. },
  184. bindingWechatLogin(){//获取用户基本信息登录
  185. wx.getUserInfo({
  186. success: res => {
  187. console.log('useInfo:',res.userInfo)
  188. this.isUserInfo = false;
  189. this.userInfo = res.userInfo;
  190. let params ={
  191. userID:this.userID,
  192. mobile:this.bindLinkPhone,
  193. linkName:this.bindLinkName,
  194. verificationCode:this.mobildeCode,
  195. nickName:res.userInfo.nickName,
  196. headimgurl:res.userInfo.avatarUrl,
  197. }
  198. bindingWechat(params).then(response =>{
  199. // this.login(response.data);
  200. uni.switchTab({
  201. url:'/pages/tabBar/user/user'
  202. })
  203. }).catch(response =>{
  204. this.$util.msg(response.msg,2000)
  205. })
  206. }
  207. })
  208. },
  209. goUserLogininit(){
  210. let url;
  211. if(this.loginType) {
  212. if(this.loginType=='detilType'){
  213. this.$api.redirectTo(`/pages/goods/product?id=${this.id}&page=2`);
  214. }else if(this.loginType=='search'){
  215. this.$api.redirectTo('/pages/search/search');
  216. }else if(this.loginType == 1){
  217. url ='/pages/tabBar/cart/cart'
  218. }else if(this.loginType == 4){
  219. url ='/pages/tabBar/user/user'
  220. }else {
  221. url ='/pages/tabBar/home/home'
  222. }
  223. } else if(this.listType) {
  224. this.$api.navToListPage({type:this.listType,value:this.listVal,lType:'4'});
  225. }
  226. },
  227. //关闭未授权用户授权提示弹窗
  228. hideModel(){
  229. this.isUserInfo = false;
  230. }
  231. },
  232. onShow() {
  233. this.$api.getStorage().then((resolve) => {
  234. this.userID = resolve.userID
  235. this.bindMobile = resolve.bindMobile
  236. })
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .login{
  242. width: 100%;
  243. height: auto;
  244. border-top: 1px solid #F7F7F7;
  245. .model-warp.none{
  246. display: none;
  247. }
  248. .model-warp.show{
  249. display: block;
  250. }
  251. .login-main{
  252. width: 702rpx;
  253. background: rgba(225, 86, 22, 0.1);
  254. display: flex;
  255. flex-direction: column;
  256. align-items: center;
  257. height: 68rpx;
  258. padding: 20rpx 24rpx;
  259. margin: 24rpx 0 118rpx 0;
  260. .logo-text{
  261. font-size: 24rpx;
  262. line-height: 34rpx;
  263. color: $color-system;
  264. }
  265. }
  266. .login-form{
  267. width: 702rpx;
  268. height: auto;
  269. padding: 0 24rpx;
  270. .login-input{
  271. width: 654rpx;
  272. height: 40rpx;
  273. padding: 24rpx;
  274. margin-bottom: 20rpx;
  275. background: #F7F7F7;
  276. border-radius: 14rpx;
  277. display: flex;
  278. flex-direction: column;
  279. align-items: center;
  280. &.code{
  281. width: 370rpx;
  282. float: left;
  283. margin-right: 20rpx;
  284. }
  285. &.btn{
  286. width: 258rpx;
  287. height: 88rpx;
  288. padding: 0;
  289. float: left;
  290. background: $btn-confirm;
  291. .input{
  292. width: 258rpx;
  293. height: 88rpx;
  294. line-height: 88rpx;
  295. padding: 0;
  296. border-radius: 14rpx;
  297. color: #FFFFFF;
  298. background: $btn-confirm;
  299. }
  300. &.disabled{
  301. background: #F7F7F7;
  302. .input{
  303. background: #F7F7F7;
  304. color: #999999;
  305. }
  306. }
  307. }
  308. &.img-btn{
  309. width: 250rpx;
  310. height: 88rpx;
  311. padding: 0;
  312. float: left;
  313. background: #FFFFFF;
  314. display: block;
  315. .vscodeimg{
  316. width: 180rpx;
  317. height: 88rpx;
  318. float: left;
  319. display: flex;
  320. flex-direction: column;
  321. align-items: center;
  322. border-radius: 14rpx;
  323. image{
  324. width: 180rpx;
  325. height: 88rpx;
  326. border-radius: 14rpx;
  327. }
  328. }
  329. .vscod-refresh{
  330. width: 70rpx;
  331. float: right;
  332. display: flex;
  333. flex-direction: column;
  334. align-items: center;
  335. .icon-shuaxin{
  336. font-size: 48rpx;
  337. color: #333333;
  338. }
  339. .ref-text{
  340. font-size: 24rpx;
  341. color: #333333;
  342. }
  343. }
  344. }
  345. .input{
  346. width: 100%;
  347. height: 100%;
  348. background: #F7F7F7;
  349. font-size: $font-size-28;
  350. line-height: 40rpx;
  351. color: #333333;
  352. border-radius: 14rpx;
  353. }
  354. }
  355. }
  356. .login-btn{
  357. width: 702rpx;
  358. height: 88rpx;
  359. border-radius: 14rpx;
  360. font-size: $font-size-28;
  361. line-height: 88rpx;
  362. color: #FFFFFF;
  363. margin: 0 auto;
  364. text-align: center;
  365. background: $btn-confirm;
  366. margin-top: 100rpx;
  367. }
  368. .model-authorization{
  369. width: 100%;
  370. height: 100%;
  371. position: fixed;
  372. top: 0;
  373. left: 0;
  374. z-index: 999;
  375. .authorization{
  376. width: 518rpx;
  377. height: 320rpx;
  378. position: absolute;
  379. background: rgba(255,255,255,.7);
  380. left: 0;
  381. right: 0;
  382. bottom: 0;
  383. top: 0;
  384. margin: auto;
  385. .to-btn{
  386. position: absolute;
  387. top: 0;
  388. left: 0;
  389. right: 0;
  390. bottom: 0;
  391. margin: auto;
  392. width: 70%;
  393. height: 88rpx;
  394. font-size: $font-size-28;
  395. line-height: 88rpx;
  396. color: #FFFFFF;
  397. text-align: center;
  398. border-radius: 44rpx;
  399. }
  400. }
  401. }
  402. }
  403. </style>