index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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">
  25. <input placeholder="请输入密码" type="password" v-model="passwordNum"/>
  26. </li>
  27. </ul>
  28. <div class="loginBtn" @click="login">确定绑定已有账号登录</div>
  29. <div class="register">还没有优软账号,直接<span @click="resgiter">创建新账号</span></div>
  30. <nuxt-link :to="'/'" class="mobile_footer company" tag="div">
  31. <div class="hr"></div>
  32. <img src="/images/mobile/@2x/wechat/logo.png" alt="">
  33. <div class="hr right"></div>
  34. <!--<p>此页面由深圳市优软商城科技有限公司提供</p>-->
  35. <!--<nuxt-link :to="'/'">www.usoftmall.com</nuxt-link>-->
  36. <!-- <a href="https://www.usoftmall.com">www.usoftmall.com</a> -->
  37. </nuxt-link>
  38. </div>
  39. <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
  40. <div class="listAlert" ref="userContent" v-show="wechatInfo.enterprises">
  41. <ul>
  42. <li v-for="(item, index) in wechatInfo.enterprises" @click="clickItem(item)">
  43. {{item.enName}}
  44. </li>
  45. <li @click="clickItem({uu: 0})">
  46. <a>个人账户</a>
  47. </li>
  48. </ul>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { RemindBox } from '~components/mobile/common'
  54. import BScroll from 'better-scroll'
  55. export default {
  56. name: 'wechatView',
  57. layout: 'mobileNoHeader',
  58. // middleware: 'authenticated',
  59. data() {
  60. return {
  61. collectResult: '',
  62. timeoutCount: 0,
  63. telerror: false,
  64. telphoneNum: '',
  65. passwordNum: ''
  66. }
  67. },
  68. mounted() {
  69. let info = localStorage.getItem('USOFTMALLWECHATINFO')
  70. if (this.$route.query.url) {
  71. localStorage.setItem('RETURNURL', this.$route.query.url || '')
  72. }
  73. if (!info && !this.$route.query.code) {
  74. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://pre.usoftmall.com/mobile/wechat&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  75. } else if (info) {
  76. info = JSON.parse(info)
  77. if (info.openid) {
  78. this.$store.dispatch('GerWechatInfo', {code: '', openId: info.openid})
  79. } else {
  80. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb3274b676737a319&redirect_uri=https://pre.usoftmall.com/mobile/wechat&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  81. }
  82. } else {
  83. this.$store.dispatch('GerWechatInfo', {code: this.$route.query.code})
  84. }
  85. this.$nextTick(() => {
  86. if (this.BScroll) {
  87. this.BScroll.refresh()
  88. } else {
  89. this.BScroll = new BScroll(this.$refs.userContent, {
  90. click: true
  91. })
  92. }
  93. })
  94. },
  95. methods: {
  96. clickItem(item) {
  97. let userAccount = this.baseUtils.deepCopy(this.$store.state.option.wechatInfo.data.userAccount)
  98. userAccount.spaceUU = item.uu
  99. this.$http.get('/newLogin/other', {params: userAccount}).then(res => {
  100. this.$store.dispatch('loadUserInfo').then(() => {
  101. let _url = localStorage.getItem('RETURNURL')
  102. if (_url !== '') {
  103. localStorage.removeItem('RETURNURL')
  104. this.$router.replace(_url)
  105. } else if (this.$route.query.url && this.$route.query.url !== '') {
  106. this.$router.replace(this.$route.query.url)
  107. } else {
  108. this.goLastPage()
  109. }
  110. })
  111. })
  112. },
  113. telphoneBlur() {
  114. this.telerror = false
  115. if (!/^1[3|5|7|8]\d{9}$/.test(this.telphoneNum)) {
  116. this.telerror = true
  117. }
  118. },
  119. login() {
  120. if (this.telerror === true) {
  121. return false
  122. }
  123. if (!this.passwordNum || this.passwordNum === '') {
  124. this.collectResult = '密码不能为空'
  125. this.timeoutCount++
  126. return false
  127. }
  128. let openid = this.$store.state.option.wechatInfo.data.openid
  129. this.$http.post('/wx/bindUser', {userTel: this.telphoneNum, userPwd: this.passwordNum, openId: openid}).then(res => {
  130. if (res.data.success) {
  131. this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', res.data)
  132. localStorage.setItem('USOFTMALLWECHATINFO', JSON.stringify(res.data))
  133. } else {
  134. localStorage.removeItem('USOFTMALLWECHATINFO')
  135. this.collectResult = res.data.message
  136. this.timeoutCount++
  137. }
  138. }, err => {
  139. localStorage.removeItem('USOFTMALLWECHATINFO')
  140. this.collectResult = err.response.data || '绑定失败'
  141. this.timeoutCount++
  142. })
  143. },
  144. resgiter() {
  145. this.$http.get('/register/page').then(response => {
  146. if (response.data) {
  147. window.location.href = response.data.content
  148. }
  149. })
  150. }
  151. },
  152. components: {
  153. RemindBox
  154. },
  155. computed: {
  156. userName() {
  157. // return ''
  158. return this.wechatInfo.nickname
  159. },
  160. headerImg() {
  161. // return ''
  162. return this.wechatInfo.headimgurl
  163. },
  164. wechatInfo() {
  165. return this.$store.state.option.wechatInfo.data
  166. }
  167. }
  168. }
  169. </script>
  170. <style scoped lang="scss">
  171. .wechat-view {
  172. position: fixed;
  173. z-index: 999;
  174. width: 100%;
  175. left: 0;
  176. right: 0;
  177. top: 0;
  178. bottom: 0;
  179. background: #fff;
  180. .header-view {
  181. background: #376ef3;
  182. height: 4.26rem;
  183. width: 100%;
  184. position: relative;
  185. padding-top: 0.56rem;
  186. .hearder-kuang {
  187. background: rgba(0, 0, 0, 0.18);
  188. width: 1.86rem;
  189. height: 1.86rem;
  190. border-radius: 50%;
  191. margin: 0 auto;
  192. overflow: hidden;
  193. position: relative;
  194. .header-img {
  195. background: #fff;
  196. width: 1.6rem;
  197. height: 1.6rem;
  198. border-radius: 50%;
  199. overflow: hidden;
  200. text-align: center;
  201. position: absolute;
  202. left: 50%;
  203. top: 50%;
  204. margin: -0.8rem 0 0 -0.8rem;
  205. img {
  206. width: 1.6rem;
  207. height: 1.6rem;
  208. border-radius: 50%;
  209. vertical-align: center;
  210. }
  211. }
  212. }
  213. .header-name {
  214. font-size: 0.3rem;
  215. color: #fff;
  216. text-align: center;
  217. margin-top: 0.24rem;
  218. }
  219. .headerbg {
  220. position: absolute;
  221. width: 100%;
  222. height: 0.88rem;
  223. bottom: 0px;
  224. left: 0px;
  225. }
  226. }
  227. .middle-view {
  228. padding: 0 0.71rem;
  229. margin-top: 0.56rem;
  230. ul li {
  231. padding-bottom: 0.1rem;
  232. min-height: 0.4rem;
  233. &.wechat-view-info {
  234. color: #3872f4;
  235. font-size: 0.24rem;
  236. margin-left: 0.64rem;
  237. margin-top: 0.2rem;
  238. margin-bottom: 0.2rem;
  239. }
  240. input {
  241. margin-left: 0.34rem;
  242. color: #aaa;
  243. font-size: 0.3rem;
  244. height: 0.5rem;
  245. line-height: 0.5rem;
  246. border: 0;
  247. display: inline-block;
  248. vertical-align: top;
  249. }
  250. &.telphone {
  251. border-bottom: 1px solid #eee;
  252. &::before {
  253. background: url('/images/mobile/@2x/wechat/tel_icon.png');
  254. content: ' ';
  255. width: 0.28rem;
  256. height: 0.5rem;
  257. display: inline-block;
  258. background-size: 100% 100%;
  259. vertical-align: top;
  260. }
  261. input {
  262. margin-left: 0.4rem;
  263. }
  264. }
  265. &.password {
  266. border-bottom: 1px solid #eee;
  267. &::before {
  268. background: url('/images/mobile/@2x/wechat/pass_icon.png');
  269. content: ' ';
  270. width: 0.34rem;
  271. height: 0.42rem;
  272. display: inline-block;
  273. background-size: 100% 100%;
  274. vertical-align: top;
  275. }
  276. }
  277. }
  278. .loginBtn {
  279. width: 5.8rem;
  280. height: 0.9rem;
  281. line-height: 0.9rem;
  282. text-align: center;
  283. font-size: 0.3rem;
  284. color: #fff;
  285. background: #376ef3;
  286. border-radius: 5px;
  287. margin: 1.29rem auto 0;
  288. }
  289. .register {
  290. width: 5.8rem;
  291. text-align: left;
  292. font-size: 0.24rem;
  293. color: #999;
  294. margin: 0.25rem auto 0;
  295. span {
  296. color: #0076ff;
  297. font-size: 0.24rem;
  298. text-align: center;
  299. border: 1px solid #0076ff;
  300. border-radius: 5px;
  301. height:0.44rem;
  302. width: 1.48rem;
  303. margin-left: 0.2rem;
  304. }
  305. }
  306. .company {
  307. margin-top: 1.51rem;
  308. position: relative;
  309. text-align: center;
  310. img {
  311. width: 1.78rem;
  312. height: 0.39rem;
  313. margin-top: 0.24rem;
  314. }
  315. p {
  316. font-size: 0.21rem;
  317. color: #aaa;
  318. margin: 0.13rem 0 0 0;
  319. }
  320. a {
  321. margin-top: 0.12rem;
  322. font-size: 0.18rem;
  323. color: #bbb;
  324. }
  325. .hr {
  326. width: 1.62rem;
  327. height: 0.02rem;
  328. background: #e3e3e3;
  329. position: absolute;
  330. left: 0.3rem;
  331. top: 0.45rem;
  332. &.right {
  333. right: 0.3rem;
  334. left: auto;
  335. }
  336. }
  337. }
  338. }
  339. .listAlert {
  340. position: fixed;
  341. top: 0;
  342. left: 0;
  343. right: 0;
  344. bottom: 0;
  345. background: #fff;
  346. padding: 0 0.2rem;
  347. overflow: hidden;
  348. z-index: 10000;
  349. li {
  350. line-height: 0.98rem;
  351. height: 0.98rem;
  352. border-bottom: 1px solid #dedede;
  353. }
  354. }
  355. }
  356. </style>