bindwechat.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. switch(this.isLoginType){
  188. case 9:
  189. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  190. break;
  191. case 8:
  192. this.$api.navigateTo(`/pages/goods/product?id=${this.isLoginProductId}`)
  193. break;
  194. case 7:
  195. this.$api.navigateTo(`/pages/user/order/order-details?type=share&orderID=${this.isLoginOrderId}`)
  196. break;
  197. default:
  198. this.$api.switchTabTo('/pages/tabBar/user/user')
  199. }
  200. }).catch(error =>{
  201. this.$util.msg(error.msg,2000)
  202. })
  203. }
  204. })
  205. },
  206. //关闭未授权用户授权提示弹窗
  207. hideModel(){
  208. this.isUserInfo = false;
  209. }
  210. },
  211. onShow() {
  212. this.$api.getStorage().then((resolve) => {
  213. this.userID = resolve.userID
  214. this.bindMobile = resolve.bindMobile
  215. })
  216. }
  217. }
  218. </script>
  219. <style lang="scss">
  220. .login{
  221. width: 100%;
  222. height: auto;
  223. border-top: 1px solid #F7F7F7;
  224. .model-warp.none{
  225. display: none;
  226. }
  227. .model-warp.show{
  228. display: block;
  229. }
  230. .login-main{
  231. width: 702rpx;
  232. background: rgba(225, 86, 22, 0.1);
  233. display: flex;
  234. flex-direction: column;
  235. align-items: center;
  236. height: 68rpx;
  237. padding: 20rpx 24rpx;
  238. margin: 24rpx 0 118rpx 0;
  239. .logo-text{
  240. font-size: 24rpx;
  241. line-height: 34rpx;
  242. color: $color-system;
  243. }
  244. }
  245. .login-form{
  246. width: 702rpx;
  247. height: auto;
  248. padding: 0 24rpx;
  249. .login-input{
  250. width: 654rpx;
  251. height: 40rpx;
  252. padding: 24rpx;
  253. margin-bottom: 20rpx;
  254. background: #F7F7F7;
  255. border-radius: 14rpx;
  256. display: flex;
  257. flex-direction: column;
  258. align-items: center;
  259. &.code{
  260. width: 370rpx;
  261. float: left;
  262. margin-right: 20rpx;
  263. }
  264. &.btn{
  265. width: 258rpx;
  266. height: 88rpx;
  267. padding: 0;
  268. float: left;
  269. background: $btn-confirm;
  270. .input{
  271. width: 258rpx;
  272. height: 88rpx;
  273. line-height: 88rpx;
  274. padding: 0;
  275. border-radius: 14rpx;
  276. color: #FFFFFF;
  277. background: $btn-confirm;
  278. }
  279. &.disabled{
  280. background: #F7F7F7;
  281. .input{
  282. background: #F7F7F7;
  283. color: #999999;
  284. }
  285. }
  286. }
  287. &.img-btn{
  288. width: 250rpx;
  289. height: 88rpx;
  290. padding: 0;
  291. float: left;
  292. background: #FFFFFF;
  293. display: block;
  294. .vscodeimg{
  295. width: 180rpx;
  296. height: 88rpx;
  297. float: left;
  298. display: flex;
  299. flex-direction: column;
  300. align-items: center;
  301. border-radius: 14rpx;
  302. image{
  303. width: 180rpx;
  304. height: 88rpx;
  305. border-radius: 14rpx;
  306. }
  307. }
  308. .vscod-refresh{
  309. width: 70rpx;
  310. float: right;
  311. display: flex;
  312. flex-direction: column;
  313. align-items: center;
  314. .icon-shuaxin{
  315. font-size: 48rpx;
  316. color: #333333;
  317. }
  318. .ref-text{
  319. font-size: 24rpx;
  320. color: #333333;
  321. }
  322. }
  323. }
  324. .input{
  325. width: 100%;
  326. height: 100%;
  327. background: #F7F7F7;
  328. font-size: $font-size-28;
  329. line-height: 40rpx;
  330. color: #333333;
  331. border-radius: 14rpx;
  332. }
  333. }
  334. }
  335. .login-btn{
  336. width: 702rpx;
  337. height: 88rpx;
  338. border-radius: 14rpx;
  339. font-size: $font-size-28;
  340. line-height: 88rpx;
  341. color: #FFFFFF;
  342. margin: 0 auto;
  343. text-align: center;
  344. background: $btn-confirm;
  345. margin-top: 100rpx;
  346. }
  347. .model-authorization{
  348. width: 100%;
  349. height: 100%;
  350. position: fixed;
  351. top: 0;
  352. left: 0;
  353. z-index: 999;
  354. .authorization{
  355. width: 518rpx;
  356. height: 320rpx;
  357. position: absolute;
  358. background: rgba(255,255,255,.7);
  359. left: 0;
  360. right: 0;
  361. bottom: 0;
  362. top: 0;
  363. margin: auto;
  364. .to-btn{
  365. position: absolute;
  366. top: 0;
  367. left: 0;
  368. right: 0;
  369. bottom: 0;
  370. margin: auto;
  371. width: 70%;
  372. height: 88rpx;
  373. font-size: $font-size-28;
  374. line-height: 88rpx;
  375. color: #FFFFFF;
  376. text-align: center;
  377. border-radius: 44rpx;
  378. }
  379. }
  380. }
  381. }
  382. </style>