bindwechat.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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="number"
  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' : '']" @click.stop="getMobileCodeFn">
  55. <button type="button"
  56. :disabled="isMobileDisabled"
  57. class="input"
  58. >{{ mobileCodeText }}</button>
  59. </view>
  60. </view>
  61. <view class="login-form clearfix">
  62. <view class="login-btn" @click="bindWechatInfo">绑定</view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import { mapMutations } from 'vuex';
  68. import authorize from '@/common/config/authorize.js'
  69. import { bindingWechat } from "@/api/use.js"
  70. import { getImageCode, getbindWechatCode } from "@/api/utils.js"
  71. var self;
  72. export default{
  73. data() {
  74. return{
  75. userID:'',
  76. bindMobile:'',
  77. bindLinkName:'', //用户姓名
  78. bindLinkPhone:'', //用户手机号
  79. mobildeCode:'', //手机验证码
  80. imageCode:'', //图形验证码
  81. imageCodeUrl:'', //图形验证码地址
  82. imageCodetoken:'', //图形校验token
  83. isMobileDisabled:false, //获取手机短信按钮
  84. count: '', //倒计时
  85. mobileCodeText: '获取验证码',
  86. codeTime: null,
  87. loginType:'', //跳转类型
  88. alertText:'',
  89. listType: '',
  90. listVal: '',
  91. detilType:'',
  92. id:'',//商品ID
  93. getOption:''
  94. }
  95. },
  96. onLoad(option) {
  97. let data = JSON.parse(option.data);
  98. this.codeType = option.codeType
  99. this.option = option
  100. this.loginType = data.type;
  101. this.id = data.id
  102. if(data.listType) {
  103. this.listType = data.listType;
  104. this.listVal = data.listVal;
  105. }
  106. this.getVerificationCode()
  107. },
  108. methods:{
  109. ...mapMutations(['login']),
  110. bindWechatInfo(){
  111. let params ={
  112. userID:this.userID,
  113. mobile:this.bindLinkPhone,
  114. linkName:this.bindLinkName,
  115. verificationCode:this.mobildeCode,
  116. }
  117. bindingWechat(params).then(res =>{
  118. this.goUserLogininit()
  119. }).catch(res =>{
  120. this.$util.msg(res.msg,2000)
  121. })
  122. },
  123. getVerificationCode(){//图形验证
  124. getImageCode().then(res => {
  125. this.imageCodeUrl = res.data.baseImage
  126. this.imageCodetoken = res.data.token
  127. })
  128. },
  129. getMobileCodeFn(){//获取手机验证码
  130. let params = {
  131. mobile:this.bindLinkPhone,
  132. mobileOrEmail:this.bindMobile,
  133. platformType:2,
  134. imgCode:this.imageCode,
  135. token:this.imageCodetoken,
  136. }
  137. getbindWechatCode(params).then(res =>{
  138. const TIME_COUNT = 60;
  139. this.isMobileDisabled = true;
  140. this.$util.msg('验证短信已发送',2000)
  141.       if (!this.codeTime) {
  142.         this.count = TIME_COUNT;
  143.         this.codeTime = setInterval(() => {
  144.         if (this.count > 1 && this.count <= TIME_COUNT) {
  145.           this.count--
  146.           this.mobileCodeText = this.count +'s重新发送'
  147.          } else {
  148.           this.isMobileDisabled = false;
  149.           clearInterval(this.codeTime)
  150.           this.codeTime = null
  151. this.mobileCodeText = '获取验证码'
  152.          }
  153.         },1000)
  154.        }
  155. }).catch( res =>{
  156. this.$util.msg(res.msg,2000)
  157. })
  158. },
  159. goUserLogininit(){
  160. let url;
  161. if(this.loginType) {
  162. if(this.loginType=='detilType'){
  163. this.$api.redirectTo(`/pages/goods/product?id=${this.id}&page=2`);
  164. }else if(this.loginType=='search'){
  165. this.$api.redirectTo('/pages/search/search');
  166. }else if(this.loginType == 1){
  167. url ='/pages/tabBar/cart/cart'
  168. }else if(this.loginType == 4){
  169. url ='/pages/tabBar/user/user'
  170. }else {
  171. url ='/pages/tabBar/home/home'
  172. }
  173. uni.switchTab({
  174. url
  175. })
  176. } else if(this.listType) {
  177. this.$api.navToListPage({type:this.listType,value:this.listVal,lType:'4'});
  178. }
  179. }
  180. },
  181. onShow() {
  182. this.$api.getStorage().then((resolve) => {
  183. this.userID = resolve.userID
  184. this.bindMobile = resolve.bindMobile
  185. })
  186. }
  187. }
  188. </script>
  189. <style lang="scss">
  190. .login{
  191. width: 100%;
  192. height: auto;
  193. border-top: 1px solid #F7F7F7;
  194. .model-warp.none{
  195. display: none;
  196. }
  197. .model-warp.show{
  198. display: block;
  199. }
  200. .login-main{
  201. width: 702rpx;
  202. background: rgba(225, 86, 22, 0.1);
  203. display: flex;
  204. flex-direction: column;
  205. align-items: center;
  206. height: 68rpx;
  207. padding: 20rpx 24rpx;
  208. margin: 24rpx 0 118rpx 0;
  209. .logo-text{
  210. font-size: 24rpx;
  211. line-height: 34rpx;
  212. color: $color-system;
  213. }
  214. }
  215. .login-form{
  216. width: 702rpx;
  217. height: auto;
  218. padding: 0 24rpx;
  219. .login-input{
  220. width: 654rpx;
  221. height: 40rpx;
  222. padding: 24rpx;
  223. margin-bottom: 20rpx;
  224. background: #F7F7F7;
  225. border-radius: 14rpx;
  226. display: flex;
  227. flex-direction: column;
  228. align-items: center;
  229. &.code{
  230. width: 370rpx;
  231. float: left;
  232. margin-right: 20rpx;
  233. }
  234. &.btn{
  235. width: 210rpx;
  236. float: left;
  237. background: $btn-confirm;
  238. .input{
  239. color: #FFFFFF;
  240. background: $btn-confirm;
  241. }
  242. &.disabled{
  243. background: #F7F7F7;
  244. .input{
  245. background: #F7F7F7;
  246. color: #999999;
  247. }
  248. }
  249. }
  250. &.img-btn{
  251. width: 250rpx;
  252. height: 88rpx;
  253. padding: 0;
  254. float: left;
  255. background: #FFFFFF;
  256. display: block;
  257. .vscodeimg{
  258. width: 180rpx;
  259. height: 88rpx;
  260. float: left;
  261. display: flex;
  262. flex-direction: column;
  263. align-items: center;
  264. border-radius: 14rpx;
  265. image{
  266. width: 180rpx;
  267. height: 88rpx;
  268. border-radius: 14rpx;
  269. }
  270. }
  271. .vscod-refresh{
  272. width: 70rpx;
  273. float: right;
  274. display: flex;
  275. flex-direction: column;
  276. align-items: center;
  277. .icon-shuaxin{
  278. font-size: 48rpx;
  279. color: #333333;
  280. }
  281. .ref-text{
  282. font-size: 24rpx;
  283. color: #333333;
  284. }
  285. }
  286. }
  287. .input{
  288. width: 100%;
  289. height: 100%;
  290. background: #F7F7F7;
  291. font-size: $font-size-28;
  292. line-height: 40rpx;
  293. color: #333333;
  294. border-radius: 14rpx;
  295. }
  296. }
  297. }
  298. .login-btn{
  299. width: 702rpx;
  300. height: 88rpx;
  301. border-radius: 14rpx;
  302. font-size: $font-size-28;
  303. line-height: 88rpx;
  304. color: #FFFFFF;
  305. margin: 0 auto;
  306. text-align: center;
  307. background: $btn-confirm;
  308. margin-top: 100rpx;
  309. }
  310. .model-authorization{
  311. width: 100%;
  312. height: 100%;
  313. position: fixed;
  314. top: 0;
  315. left: 0;
  316. z-index: 999;
  317. .authorization{
  318. width: 518rpx;
  319. height: 320rpx;
  320. position: absolute;
  321. background: rgba(255,255,255,.7);
  322. left: 0;
  323. right: 0;
  324. bottom: 0;
  325. top: 0;
  326. margin: auto;
  327. .to-btn{
  328. position: absolute;
  329. top: 0;
  330. left: 0;
  331. right: 0;
  332. bottom: 0;
  333. margin: auto;
  334. width: 70%;
  335. height: 88rpx;
  336. font-size: $font-size-28;
  337. line-height: 88rpx;
  338. color: #FFFFFF;
  339. text-align: center;
  340. border-radius: 44rpx;
  341. }
  342. }
  343. }
  344. }
  345. </style>