index.vue 9.8 KB

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