bindwechat.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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="4"
  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 wxLogin from "@/common/config/wxLogin.js"
  72. import { bindingWechat } from "@/api/use.js"
  73. import { getImageCode, getbindWechatCode } from "@/api/utils.js"
  74. export default{
  75. data() {
  76. return{
  77. userID:'',
  78. bindMobile:'',
  79. bindLinkName:'', //用户姓名
  80. bindLinkPhone:'', //用户手机号
  81. mobildeCode:'', //手机验证码
  82. imageCode:'', //图形验证码
  83. imageCodeUrl:'', //图形验证码地址
  84. imageCodetoken:'', //图形校验token
  85. isMobileDisabled:false, //获取手机短信按钮
  86. count: '', //倒计时
  87. mobileCodeText: '获取验证码',
  88. codeTime: null,
  89. }
  90. },
  91. onLoad(option) {
  92. this.getVerificationCode()
  93. },
  94. computed: {
  95. ...mapState(['isWxAuthorize','isLoginType','isLoginProductId','isLoginOrderId'])
  96. },
  97. methods:{
  98. ...mapMutations(['login']),
  99. bindWechatInfo(){
  100. if( this.bindLinkName == ''){
  101. this.$util.msg('请输入姓名',2000)
  102. return
  103. }
  104. if( this.bindLinkPhone == ''){
  105. this.$util.msg('请输入手机号',2000)
  106. return
  107. }
  108. if(!this.$reg.isMobile(this.bindLinkPhone)){
  109. this.$util.msg('请输入正确的手机号',2000)
  110. return
  111. }
  112. if( this.mobildeCode == ''){
  113. this.$util.msg('请输入手机验证码',2000)
  114. return
  115. }
  116. if(!this.$reg.isMobileCode(this.mobildeCode)){
  117. this.$util.msg('验证码格式不正确',2000)
  118. return
  119. }
  120. this.bindingWechatLogin()
  121. },
  122. getVerificationCode(){//图形验证
  123. getImageCode().then(res => {
  124. this.imageCodeUrl = res.data.baseImage
  125. this.imageCodetoken = res.data.token
  126. })
  127. },
  128. getMobileCodeFn(){//获取手机验证码
  129. if( this.bindLinkPhone == ''){
  130. this.$util.msg('请输入手机号',2000);
  131. return
  132. }
  133. if(!this.$reg.isMobile(this.bindLinkPhone)){
  134. this.$util.msg('请输入正确的手机号',2000);
  135. return
  136. }
  137. if( this.imageCode == ''){
  138. this.$util.msg('请输入图形验证码',2000);
  139. return
  140. }
  141. let params = {
  142. mobile:this.bindLinkPhone,
  143. mobileOrEmail:this.bindMobile,
  144. platformType:2,
  145. imgCode:this.imageCode,
  146. token:this.imageCodetoken,
  147. }
  148. this.isMobileDisabled = true;
  149. getbindWechatCode(params).then(res =>{
  150. const TIME_COUNT = 60;
  151. this.$util.msg('验证短信已发送',2000)
  152.       if (!this.codeTime) {
  153.         this.count = TIME_COUNT;
  154. this.isMobileDisabled = true;
  155.         this.codeTime = setInterval(() => {
  156.         if (this.count > 1 && this.count <= TIME_COUNT) {
  157.           this.count--
  158.           this.mobileCodeText = this.count +'s重新发送'
  159.          } else {
  160.           this.isMobileDisabled = false;
  161.           clearInterval(this.codeTime)
  162.           this.codeTime = null
  163. this.mobileCodeText = '获取验证码'
  164.          }
  165.         },1000)
  166.        }
  167. }).catch( error =>{
  168. this.$util.msg(error.msg,2000)
  169. this.isMobileDisabled = false;
  170. })
  171. },
  172. bindingWechatLogin(){//获取用户基本信息登录
  173. wx.getUserInfo({
  174. success: res => {
  175. this.isUserInfo = false;
  176. this.userInfo = res.userInfo;
  177. let params ={
  178. userID:this.userID,
  179. mobile:this.bindLinkPhone,
  180. linkName:this.bindLinkName,
  181. verificationCode:this.mobildeCode,
  182. nickName:res.userInfo.nickName,
  183. headimgurl:res.userInfo.avatarUrl,
  184. }
  185. // console.log(params)
  186. bindingWechat(params).then(response =>{
  187. console.log(this.isLoginType)
  188. console.log(this.isLoginProductId)
  189. console.log(this.isLoginOrderId)
  190. switch(this.isLoginType){
  191. case 9:
  192. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  193. break;
  194. case 8:
  195. this.$api.navigateTo(`/pages/goods/product?id=${this.isLoginProductId}`)
  196. break;
  197. case 7:
  198. this.$api.navigateTo(`/pages/user/order/order-details?type=share&orderID=${this.isLoginOrderId}`)
  199. break;
  200. default:
  201. this.$api.switchTabTo('/pages/tabBar/user/user')
  202. }
  203. }).catch(error =>{
  204. this.$util.msg(error.msg,2000)
  205. })
  206. }
  207. })
  208. },
  209. //关闭未授权用户授权提示弹窗
  210. hideModel(){
  211. this.isUserInfo = false;
  212. }
  213. },
  214. onShow() {
  215. this.$api.getStorage().then((resolve) => {
  216. this.userID = resolve.userID
  217. this.bindMobile = resolve.bindMobile
  218. })
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. .login{
  224. width: 100%;
  225. height: auto;
  226. border-top: 1px solid #F7F7F7;
  227. .model-warp.none{
  228. display: none;
  229. }
  230. .model-warp.show{
  231. display: block;
  232. }
  233. .login-main{
  234. width: 702rpx;
  235. background: rgba(225, 86, 22, 0.1);
  236. display: flex;
  237. flex-direction: column;
  238. align-items: center;
  239. height: 68rpx;
  240. padding: 20rpx 24rpx;
  241. margin: 24rpx 0 118rpx 0;
  242. .logo-text{
  243. font-size: 24rpx;
  244. line-height: 34rpx;
  245. color: $color-system;
  246. }
  247. }
  248. .login-form{
  249. width: 702rpx;
  250. height: auto;
  251. padding: 0 24rpx;
  252. .login-input{
  253. width: 654rpx;
  254. height: 40rpx;
  255. padding: 24rpx;
  256. margin-bottom: 20rpx;
  257. background: #F7F7F7;
  258. border-radius: 14rpx;
  259. display: flex;
  260. flex-direction: column;
  261. align-items: center;
  262. &.code{
  263. width: 370rpx;
  264. float: left;
  265. margin-right: 20rpx;
  266. }
  267. &.btn{
  268. width: 258rpx;
  269. height: 88rpx;
  270. padding: 0;
  271. float: left;
  272. background: $btn-confirm;
  273. .input{
  274. width: 258rpx;
  275. height: 88rpx;
  276. line-height: 88rpx;
  277. padding: 0;
  278. border-radius: 14rpx;
  279. color: #FFFFFF;
  280. background: $btn-confirm;
  281. }
  282. &.disabled{
  283. background: #F7F7F7;
  284. .input{
  285. background: #F7F7F7;
  286. color: #999999;
  287. }
  288. }
  289. }
  290. &.img-btn{
  291. width: 250rpx;
  292. height: 88rpx;
  293. padding: 0;
  294. float: left;
  295. background: #FFFFFF;
  296. display: block;
  297. .vscodeimg{
  298. width: 180rpx;
  299. height: 88rpx;
  300. float: left;
  301. display: flex;
  302. flex-direction: column;
  303. align-items: center;
  304. border-radius: 14rpx;
  305. image{
  306. width: 180rpx;
  307. height: 88rpx;
  308. border-radius: 14rpx;
  309. }
  310. }
  311. .vscod-refresh{
  312. width: 70rpx;
  313. float: right;
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. .icon-shuaxin{
  318. font-size: 48rpx;
  319. color: #333333;
  320. }
  321. .ref-text{
  322. font-size: 24rpx;
  323. color: #333333;
  324. }
  325. }
  326. }
  327. .input{
  328. width: 100%;
  329. height: 100%;
  330. background: #F7F7F7;
  331. font-size: $font-size-28;
  332. line-height: 40rpx;
  333. color: #333333;
  334. border-radius: 14rpx;
  335. }
  336. }
  337. }
  338. .login-btn{
  339. width: 702rpx;
  340. height: 88rpx;
  341. border-radius: 14rpx;
  342. font-size: $font-size-28;
  343. line-height: 88rpx;
  344. color: #FFFFFF;
  345. margin: 0 auto;
  346. text-align: center;
  347. background: $btn-confirm;
  348. margin-top: 100rpx;
  349. }
  350. .model-authorization{
  351. width: 100%;
  352. height: 100%;
  353. position: fixed;
  354. top: 0;
  355. left: 0;
  356. z-index: 999;
  357. .authorization{
  358. width: 518rpx;
  359. height: 320rpx;
  360. position: absolute;
  361. background: rgba(255,255,255,.7);
  362. left: 0;
  363. right: 0;
  364. bottom: 0;
  365. top: 0;
  366. margin: auto;
  367. .to-btn{
  368. position: absolute;
  369. top: 0;
  370. left: 0;
  371. right: 0;
  372. bottom: 0;
  373. margin: auto;
  374. width: 70%;
  375. height: 88rpx;
  376. font-size: $font-size-28;
  377. line-height: 88rpx;
  378. color: #FFFFFF;
  379. text-align: center;
  380. border-radius: 44rpx;
  381. }
  382. }
  383. }
  384. }
  385. </style>