index.vue 15 KB

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