index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. // 实现深拷贝
  56. function deepCopy(target) {
  57. if (typeof target !== 'object') return
  58. // 判断目标类型,来创建返回值
  59. var newObj = target instanceof Array ? [] : {}
  60. for (var item in target) {
  61. // 只复制元素自身的属性,不复制原型链上的
  62. if (target.hasOwnProperty(item)) {
  63. newObj[item] = typeof target[item] === 'object' ? deepCopy(target[item]) : target[item]
  64. }
  65. }
  66. return newObj
  67. }
  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. }
  80. },
  81. mounted() {
  82. let info = localStorage.getItem('USOFTMALLWECHATINFO')
  83. if (this.$route.query.url) {
  84. localStorage.setItem('RETURNURL', this.$route.query.url || '')
  85. }
  86. if (!info && !this.$route.query.code) {
  87. 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`
  88. } else if (info) {
  89. this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', JSON.parse(info))
  90. } else {
  91. this.$store.dispatch('GerWechatInfo', {code: this.$route.query.code})
  92. }
  93. this.$nextTick(() => {
  94. if (this.BScroll) {
  95. this.BScroll.refresh()
  96. } else {
  97. this.BScroll = new BScroll(this.$refs.userContent, {
  98. click: true
  99. })
  100. }
  101. })
  102. },
  103. methods: {
  104. clickItem(item) {
  105. let userAccount = deepCopy(this.$store.state.option.wechatInfo.data.userAccount)
  106. userAccount.spaceUU = item.uu
  107. this.$http.get('/newLogin/other', {params: userAccount}).then(res => {
  108. this.$store.dispatch('loadUserInfo').then(() => {
  109. let _url = localStorage.getItem('RETURNURL')
  110. if (_url !== '') {
  111. localStorage.removeItem('RETURNURL')
  112. this.$router.replace(_url)
  113. } else if (this.$route.query.url && this.$route.query.url !== '') {
  114. this.$router.replace(this.$route.query.url)
  115. } else {
  116. this.goLastPage()
  117. }
  118. })
  119. })
  120. },
  121. telphoneBlur() {
  122. this.telerror = false
  123. if (!/^1[3|5|7|8]\d{9}$/.test(this.telphoneNum)) {
  124. this.telerror = true
  125. }
  126. },
  127. login() {
  128. if (this.telerror === true) {
  129. return false
  130. }
  131. if (!this.passwordNum || this.passwordNum === '') {
  132. this.collectResult = '密码不能为空'
  133. this.timeoutCount++
  134. return false
  135. }
  136. let openid = this.$store.state.option.wechatInfo.data.openid
  137. this.$http.post('/wx/bindUser', {userTel: this.telphoneNum, userPwd: this.passwordNum, openId: openid}).then(res => {
  138. if (res.data.success) {
  139. this.$store.commit('option/REQUEST_WECHATINFO_STATUS_SUCCESS', res.data)
  140. localStorage.setItem('USOFTMALLWECHATINFO', JSON.stringify(res.data))
  141. } else {
  142. this.collectResult = res.data.message
  143. this.timeoutCount++
  144. }
  145. }, err => {
  146. this.collectResult = err.response.data || '绑定失败'
  147. this.timeoutCount++
  148. })
  149. },
  150. resgiter() {
  151. this.$http.get('/register/page').then(response => {
  152. if (response.data) {
  153. window.location.href = response.data.content
  154. }
  155. })
  156. }
  157. },
  158. components: {
  159. RemindBox
  160. },
  161. computed: {
  162. userName() {
  163. // return ''
  164. return this.wechatInfo.nickname
  165. },
  166. headerImg() {
  167. // return ''
  168. return this.wechatInfo.headimgurl
  169. },
  170. wechatInfo() {
  171. return this.$store.state.option.wechatInfo.data
  172. }
  173. }
  174. }
  175. </script>
  176. <style scoped lang="scss">
  177. .wechat-view {
  178. position: fixed;
  179. z-index: 999;
  180. width: 100%;
  181. left: 0;
  182. right: 0;
  183. top: 0;
  184. bottom: 0;
  185. background: #fff;
  186. .header-view {
  187. background: #376ef3;
  188. height: 4.26rem;
  189. width: 100%;
  190. position: relative;
  191. padding-top: 0.56rem;
  192. .hearder-kuang {
  193. background: rgba(0, 0, 0, 0.18);
  194. width: 1.86rem;
  195. height: 1.86rem;
  196. border-radius: 50%;
  197. margin: 0 auto;
  198. overflow: hidden;
  199. position: relative;
  200. .header-img {
  201. background: #fff;
  202. width: 1.6rem;
  203. height: 1.6rem;
  204. border-radius: 50%;
  205. overflow: hidden;
  206. text-align: center;
  207. position: absolute;
  208. left: 50%;
  209. top: 50%;
  210. margin: -0.8rem 0 0 -0.8rem;
  211. img {
  212. width: 1.6rem;
  213. height: 1.6rem;
  214. border-radius: 50%;
  215. vertical-align: center;
  216. }
  217. }
  218. }
  219. .header-name {
  220. font-size: 0.3rem;
  221. color: #fff;
  222. text-align: center;
  223. margin-top: 0.24rem;
  224. }
  225. .headerbg {
  226. position: absolute;
  227. width: 100%;
  228. height: 0.88rem;
  229. bottom: 0px;
  230. left: 0px;
  231. }
  232. }
  233. .middle-view {
  234. padding: 0 0.71rem;
  235. margin-top: 0.56rem;
  236. ul li {
  237. padding-bottom: 0.1rem;
  238. min-height: 0.4rem;
  239. &.wechat-view-info {
  240. color: #3872f4;
  241. font-size: 0.24rem;
  242. margin-left: 0.64rem;
  243. margin-top: 0.2rem;
  244. margin-bottom: 0.2rem;
  245. }
  246. input {
  247. margin-left: 0.34rem;
  248. color: #aaa;
  249. font-size: 0.3rem;
  250. height: 0.5rem;
  251. line-height: 0.5rem;
  252. border: 0;
  253. display: inline-block;
  254. vertical-align: top;
  255. }
  256. &.telphone {
  257. border-bottom: 1px solid #eee;
  258. &::before {
  259. background: url('/images/mobile/@2x/wechat/tel_icon.png');
  260. content: ' ';
  261. width: 0.28rem;
  262. height: 0.5rem;
  263. display: inline-block;
  264. background-size: 100% 100%;
  265. vertical-align: top;
  266. }
  267. input {
  268. margin-left: 0.4rem;
  269. }
  270. }
  271. &.password {
  272. border-bottom: 1px solid #eee;
  273. &::before {
  274. background: url('/images/mobile/@2x/wechat/pass_icon.png');
  275. content: ' ';
  276. width: 0.34rem;
  277. height: 0.42rem;
  278. display: inline-block;
  279. background-size: 100% 100%;
  280. vertical-align: top;
  281. }
  282. }
  283. }
  284. .loginBtn {
  285. width: 5.8rem;
  286. height: 0.9rem;
  287. line-height: 0.9rem;
  288. text-align: center;
  289. font-size: 0.3rem;
  290. color: #fff;
  291. background: #376ef3;
  292. border-radius: 5px;
  293. margin: 1.29rem auto 0;
  294. }
  295. .register {
  296. width: 5.8rem;
  297. text-align: left;
  298. font-size: 0.24rem;
  299. color: #999;
  300. margin: 0.25rem auto 0;
  301. span {
  302. color: #0076ff;
  303. font-size: 0.24rem;
  304. text-align: center;
  305. border: 1px solid #0076ff;
  306. border-radius: 5px;
  307. height:0.44rem;
  308. width: 1.48rem;
  309. margin-left: 0.2rem;
  310. }
  311. }
  312. .company {
  313. margin-top: 1.51rem;
  314. position: relative;
  315. text-align: center;
  316. img {
  317. width: 1.78rem;
  318. height: 0.39rem;
  319. margin-top: 0.24rem;
  320. }
  321. p {
  322. font-size: 0.21rem;
  323. color: #aaa;
  324. margin: 0.13rem 0 0 0;
  325. }
  326. a {
  327. margin-top: 0.12rem;
  328. font-size: 0.18rem;
  329. color: #bbb;
  330. }
  331. .hr {
  332. width: 1.62rem;
  333. height: 0.02rem;
  334. background: #e3e3e3;
  335. position: absolute;
  336. left: 0.3rem;
  337. top: 0.45rem;
  338. &.right {
  339. right: 0.3rem;
  340. left: auto;
  341. }
  342. }
  343. }
  344. }
  345. .listAlert {
  346. position: fixed;
  347. top: 0;
  348. left: 0;
  349. right: 0;
  350. bottom: 0;
  351. background: #fff;
  352. padding: 0 0.2rem;
  353. overflow: hidden;
  354. z-index: 10000;
  355. li {
  356. line-height: 0.98rem;
  357. height: 0.98rem;
  358. border-bottom: 1px solid #dedede;
  359. }
  360. }
  361. }
  362. </style>