index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <div class="wechat-view">
  3. <div class="header-view">
  4. <div class="hearder-kuang">
  5. <div class="header-img">
  6. <img src="/images/mobile/@2x/wechat/header-img.png" :src="headerImg"/>
  7. </div>
  8. </div>
  9. <div class="header-name">
  10. {{userName}}
  11. </div>
  12. <img src="/images/mobile/@2x/wechat/headerbg.png" class="headerbg"/>
  13. </div>
  14. <div class="middle-view">
  15. <ul>
  16. <li class="telphone">
  17. <input placeholder="请输入手机号" type="tel" maxlength="11" @blur="telphoneBlur" v-model="telphoneNum"/>
  18. </li>
  19. <li class="wechat-view-info">
  20. <div v-show="telerror">
  21. 请输入正确的手机号码
  22. </div>
  23. </li>
  24. <li class="password" v-if="!bindShow">
  25. <input placeholder="请输入密码" type="password" v-model="passwordNum"/>
  26. </li>
  27. <li v-if="bindShow" class="code clearfix">
  28. <input placeholder="请输入验证码" type="tel" v-model="codeNum" style="margin-left: 0;"/>
  29. <span class="pull-right codeBtn" @click="getCode()">
  30. {{showExtraTime ? getExtraTime + 'S' : '获取验证码'}}
  31. </span>
  32. </li>
  33. <li class="wechat-view-info clearfix" v-if="bindShow">
  34. <div v-show="codeerror" class="pull-left">
  35. 验证码错误
  36. </div>
  37. <div class="pull-right" @click="bindShow = false">用户名密码登录</div>
  38. </li>
  39. <li class="toInfoBind" @click="toInfoBind()" v-if="!bindShow">通过短信绑定</li>
  40. </ul>
  41. <div class="loginBtn" @click="login">确定绑定已有账号登录</div>
  42. <div class="register">还没有优软账号,直接<span @click="resgiter">创建新账号</span></div>
  43. <nuxt-link :to="'/'" class="mobile_footer company" tag="div">
  44. <div class="hr"></div>
  45. <img src="/images/mobile/@2x/wechat/logo.png" alt="">
  46. <div class="hr right"></div>
  47. <!--<p>此页面由深圳优软商城科技有限公司提供</p>-->
  48. <!--<nuxt-link :to="'/'">www.usoftmall.com</nuxt-link>-->
  49. <!-- <a href="https://www.usoftmall.com">www.usoftmall.com</a> -->
  50. </nuxt-link>
  51. </div>
  52. <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
  53. <div class="listAlert" ref="userContent" v-show="wechatInfo.enterprises">
  54. <ul>
  55. <li v-for="(item, index) in wechatInfo.enterprises" @click="clickItem(item)">
  56. {{item.enName}}
  57. </li>
  58. <li @click="clickItem({uu: 0})">
  59. <a>个人账户</a>
  60. </li>
  61. </ul>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import { RemindBox } from '~components/mobile/common'
  67. import BScroll from 'better-scroll'
  68. export default {
  69. name: 'wechatView',
  70. layout: 'mobileNoHeader',
  71. // middleware: 'authenticated',
  72. data() {
  73. return {
  74. collectResult: '',
  75. timeoutCount: 0,
  76. telerror: false,
  77. telphoneNum: '',
  78. passwordNum: '',
  79. codeNum: '',
  80. bindShow: false, // 选择手机验证码绑定
  81. codeerror: false, // 显示验证码错误
  82. showExtraTime: false, // 倒计时
  83. getExtraTime: 60,
  84. enuu: ''
  85. }
  86. },
  87. mounted() {
  88. let info = localStorage.getItem('USOFTMALLWECHATINFO')
  89. let _url = this.$route.query.url ? this.$route.query.url.split('?') : []
  90. if (_url[0]) {
  91. localStorage.setItem('RETURNURL', _url[0] || '')
  92. }
  93. if (_url[1]) {
  94. this.enuu = _url[1].split('=')[1]
  95. localStorage.setItem('Userenuu', _url[1] || '')
  96. }
  97. let ua = this.$store.state.option.userAgent.toLowerCase()
  98. if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && !this.$route.query.code && !info) {
  99. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com/mobile/wechat&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  100. } else if (info) {
  101. // 绑定过的用户一定存在openid
  102. info = JSON.parse(info)
  103. if (info.openid) {
  104. this.$store.dispatch('GerWechatInfo', {code: '', openId: info.openid}).then(res => {
  105. // 存在enuu
  106. // this.enuu = localStorage.getItem('Userenuu')
  107. if (this.enuu) {
  108. this.loginFromEnuu()
  109. }
  110. })
  111. } else {
  112. localStorage.removeItem('USOFTMALLWECHATINFO')
  113. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://www.usoftmall.com/mobile/wechat&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  114. }
  115. } else {
  116. // 用户第一次进入公众号
  117. // this.$store.dispatch('GerWechatInfo', {code: '', openId: 'o2o8JwgMp9I8Es7yneC88JD7H2ts'}) // 测试用的数据
  118. this.$store.dispatch('GerWechatInfo', {code: this.$route.query.code})
  119. }
  120. this.$nextTick(() => {
  121. if (this.BScroll) {
  122. this.BScroll.refresh()
  123. } else {
  124. this.BScroll = new BScroll(this.$refs.userContent, {
  125. click: true
  126. })
  127. }
  128. })
  129. },
  130. methods: {
  131. // 路由带有enuu
  132. loginFromEnuu() {
  133. let _item = {}
  134. this.wechatInfo.enterprises.forEach((item) => {
  135. if (item.uu === parseInt(this.enuu)) {
  136. _item = item
  137. }
  138. })
  139. this.clickItem(_item)
  140. },
  141. // 选择账套登录
  142. clickItem(item) {
  143. let userAccount = this.baseUtils.deepCopy(this.$store.state.option.wechatInfo.data.userAccount)
  144. userAccount.spaceUU = item.uu
  145. this.$http.get('/newLogin/other', {params: userAccount}).then(res => {
  146. this.$store.dispatch('loadUserInfo').then(() => {
  147. let _url = localStorage.getItem('RETURNURL')
  148. let _uu = item.uu === 0 ? '' : item.uu
  149. this.$jsonp(`${process.env.ssoUrl}/sso/login/other?spaceUU=${_uu}&appId=mall&userUU=${userAccount.userUU}`, {timeout: 5000, name: 'successCallback'}, (err) => {
  150. console.log(err)
  151. })
  152. if (_url !== '') {
  153. localStorage.removeItem('RETURNURL')
  154. this.$router.replace('/' + _url)
  155. } else if (this.$route.query.url && this.$route.query.url !== '') {
  156. this.$router.replace(this.$route.query.url)
  157. } else {
  158. this.goLastPage()
  159. }
  160. localStorage.removeItem('Userenuu')
  161. })
  162. })
  163. },
  164. // 手机号码失去焦点
  165. telphoneBlur() {
  166. if (this.telphoneNum === '') { return }
  167. this.telerror = false
  168. if (!/^1[3|5|7|8]\d{9}$/.test(this.telphoneNum)) {
  169. this.telerror = true
  170. }
  171. },
  172. // 绑定操作
  173. login() {
  174. let openid = this.$store.state.option.wechatInfo.data.openid
  175. if (this.telerror === true) {
  176. return false
  177. }
  178. if (!this.telphoneNum || this.telphoneNum === '') {
  179. this.collectResult = '手机号码不能为空'
  180. this.timeoutCount++
  181. return false
  182. }
  183. // 'o2o8JwgMp9I8Es7yneC88JD7H2ts'
  184. let _item = {
  185. userTel: this.telphoneNum,
  186. openId: openid
  187. }
  188. if (this.bindShow === true) {
  189. if (!this.codeNum || this.codeNum === '') {
  190. this.collectResult = '验证码不能为空'
  191. this.timeoutCount++
  192. return false
  193. }
  194. _item.code = this.codeNum
  195. } else {
  196. if (!this.passwordNum || this.passwordNum === '') {
  197. this.collectResult = '密码不能为空'
  198. this.timeoutCount++
  199. return false
  200. }
  201. _item.userPwd = this.passwordNum
  202. }
  203. this.$http.post('/wx/bindUser', _item).then(res => {
  204. if (res.data.success) {
  205. this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', res.data)
  206. localStorage.setItem('USOFTMALLWECHATINFO', JSON.stringify(res.data))
  207. } else {
  208. localStorage.removeItem('USOFTMALLWECHATINFO')
  209. this.collectResult = res.data.message || res.data.errMsg
  210. this.timeoutCount++
  211. }
  212. }, err => {
  213. localStorage.removeItem('USOFTMALLWECHATINFO')
  214. this.collectResult = err.response.data || '绑定失败'
  215. this.timeoutCount++
  216. })
  217. },
  218. resgiter() {
  219. this.$http.get('/register/page').then(response => {
  220. if (response.data) {
  221. window.location.href = response.data.content
  222. }
  223. })
  224. },
  225. // 选择短信绑定操作
  226. toInfoBind() {
  227. this.bindShow = true
  228. },
  229. getCode() {
  230. if (this.telerror) {
  231. return false
  232. }
  233. if (!this.telphoneNum || this.telphoneNum === '') {
  234. this.collectResult = '手机号码不能为空'
  235. this.timeoutCount++
  236. return false
  237. }
  238. if (this.showExtraTime) {
  239. this.collectResult = '获取验证码已发送,请查收'
  240. this.timeoutCount++
  241. return
  242. }
  243. // todo 这里走请求验证码接口
  244. this.$http.get(`/wx/sendSmsCode?mobile=${this.telphoneNum}`).then((data) => {
  245. if (data.data.success) {
  246. this.showExtraTime = true
  247. this.$timer = setInterval(() => {
  248. this.getExtraTime--
  249. if (this.getExtraTime === 0) {
  250. this.getExtraTime = 60
  251. this.showExtraTime = false
  252. clearInterval(this.$timer)
  253. }
  254. }, 1000)
  255. } else {
  256. this.collectResult = data.data.errMsg
  257. this.timeoutCount++
  258. }
  259. }, err => {
  260. this.collectResult = err.response.data || '获取失败'
  261. this.timeoutCount++
  262. })
  263. }
  264. },
  265. components: {
  266. RemindBox
  267. },
  268. computed: {
  269. userName() {
  270. // return ''
  271. return this.wechatInfo.nickname
  272. },
  273. headerImg() {
  274. // return ''
  275. return this.wechatInfo.headimgurl || '/images/mobile/@2x/wechat/header-img.png'
  276. },
  277. wechatInfo() {
  278. return this.$store.state.option.wechatInfo.data
  279. }
  280. }
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. .wechat-view {
  285. position: fixed;
  286. z-index: 999;
  287. width: 100%;
  288. left: 0;
  289. right: 0;
  290. top: 0;
  291. bottom: 0;
  292. background: #fff;
  293. .header-view {
  294. background: #376ef3;
  295. height: 4.26rem;
  296. width: 100%;
  297. position: relative;
  298. padding-top: 0.56rem;
  299. .hearder-kuang {
  300. background: rgba(0, 0, 0, 0.18);
  301. width: 1.86rem;
  302. height: 1.86rem;
  303. border-radius: 50%;
  304. margin: 0 auto;
  305. overflow: hidden;
  306. position: relative;
  307. .header-img {
  308. background: #fff;
  309. width: 1.6rem;
  310. height: 1.6rem;
  311. border-radius: 50%;
  312. overflow: hidden;
  313. text-align: center;
  314. position: absolute;
  315. left: 50%;
  316. top: 50%;
  317. margin: -0.8rem 0 0 -0.8rem;
  318. img {
  319. width: 1.6rem;
  320. height: 1.6rem;
  321. border-radius: 50%;
  322. vertical-align: center;
  323. }
  324. }
  325. }
  326. .header-name {
  327. font-size: 0.3rem;
  328. color: #fff;
  329. text-align: center;
  330. margin-top: 0.24rem;
  331. }
  332. .headerbg {
  333. position: absolute;
  334. width: 100%;
  335. height: 0.88rem;
  336. bottom: 0px;
  337. left: 0px;
  338. }
  339. }
  340. .middle-view {
  341. padding: 0 0.71rem;
  342. margin-top: 0.56rem;
  343. ul li {
  344. padding-bottom: 0.1rem;
  345. min-height: 0.4rem;
  346. &.wechat-view-info {
  347. color: #3872f4;
  348. font-size: 0.24rem;
  349. margin-left: 0.64rem;
  350. margin-top: 0.2rem;
  351. margin-bottom: 0.2rem;
  352. }
  353. input {
  354. margin-left: 0.34rem;
  355. color: #aaa;
  356. font-size: 0.3rem;
  357. height: 0.5rem;
  358. line-height: 0.5rem;
  359. border: 0;
  360. display: inline-block;
  361. vertical-align: top;
  362. }
  363. &.telphone {
  364. border-bottom: 1px solid #eee;
  365. &::before {
  366. background: url('/images/mobile/@2x/wechat/tel_icon.png');
  367. content: ' ';
  368. width: 0.28rem;
  369. height: 0.5rem;
  370. display: inline-block;
  371. background-size: 100% 100%;
  372. vertical-align: top;
  373. }
  374. input {
  375. margin-left: 0.4rem;
  376. }
  377. }
  378. &.password {
  379. border-bottom: 1px solid #eee;
  380. &::before {
  381. background: url('/images/mobile/@2x/wechat/pass_icon.png');
  382. content: ' ';
  383. width: 0.34rem;
  384. height: 0.42rem;
  385. display: inline-block;
  386. background-size: 100% 100%;
  387. vertical-align: top;
  388. }
  389. }
  390. &.code {
  391. border-bottom: 1px solid #eee;
  392. }
  393. &.toInfoBind {
  394. color: #3872f4;
  395. font-size: 0.28rem;
  396. text-align: right;
  397. margin-top: 0.2rem;
  398. margin-bottom: 0.2rem;
  399. }
  400. .codeBtn {
  401. font-size: 0.28rem;
  402. color: #376ef3;
  403. width: 1.8rem;
  404. height: 0.5rem;
  405. line-height: 0.5rem;
  406. border-radius: 0.04rem;
  407. border: 1px solid #376ef3;
  408. text-align: center;
  409. }
  410. }
  411. .loginBtn {
  412. width: 5.8rem;
  413. height: 0.9rem;
  414. line-height: 0.9rem;
  415. text-align: center;
  416. font-size: 0.3rem;
  417. color: #fff;
  418. background: #376ef3;
  419. border-radius: 5px;
  420. margin: 1rem auto 0;
  421. }
  422. .register {
  423. width: 5.8rem;
  424. text-align: left;
  425. font-size: 0.24rem;
  426. color: #999;
  427. margin: 0.25rem auto 0;
  428. span {
  429. color: #0076ff;
  430. font-size: 0.24rem;
  431. text-align: center;
  432. border: 1px solid #0076ff;
  433. border-radius: 5px;
  434. height:0.44rem;
  435. width: 1.48rem;
  436. margin-left: 0.2rem;
  437. }
  438. }
  439. .company {
  440. margin-top: 1.51rem;
  441. position: relative;
  442. text-align: center;
  443. img {
  444. width: 1.78rem;
  445. height: 0.39rem;
  446. margin-top: 0.24rem;
  447. }
  448. p {
  449. font-size: 0.21rem;
  450. color: #aaa;
  451. margin: 0.13rem 0 0 0;
  452. }
  453. a {
  454. margin-top: 0.12rem;
  455. font-size: 0.18rem;
  456. color: #bbb;
  457. }
  458. .hr {
  459. width: 1.62rem;
  460. height: 0.02rem;
  461. background: #e3e3e3;
  462. position: absolute;
  463. left: 0.3rem;
  464. top: 0.45rem;
  465. &.right {
  466. right: 0.3rem;
  467. left: auto;
  468. }
  469. }
  470. }
  471. }
  472. .listAlert {
  473. position: fixed;
  474. top: 0;
  475. left: 0;
  476. right: 0;
  477. bottom: 0;
  478. background: #fff;
  479. padding: 0 0.2rem;
  480. overflow: hidden;
  481. z-index: 10000;
  482. li {
  483. line-height: 0.98rem;
  484. height: 0.98rem;
  485. border-bottom: 1px solid #dedede;
  486. }
  487. }
  488. }
  489. </style>