index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <view class="login">
  3. <view class="login_header">
  4. <view class="login_header_top">
  5. <image src="https://cdn.bjtdba.com/vod/image/2024-04-12/20240412151953641.png" mode="widthFix"></image>
  6. </view>
  7. <!-- <view class="login_header_botom">
  8. <image src="https://cdn.bjtdba.com/vod/image/2022-08-09/20220809135451815.png" mode="widthFix"></image>
  9. </view> -->
  10. </view>
  11. <view class="input-home">
  12. <view class="input">
  13. <input placeholder="请输入手机号" type="number" maxlength="11" focus="true"
  14. placeholder-style="color:#9E9E9E;font-size:30rpx" v-model="form.phone" @input="inputphone">
  15. <view class="input_code">
  16. <span v-show="show" @click="getCode"
  17.  :style="form.phone.length==11?'color:#1F7CFF':'color:#9E9E9E'">获取验证码</span>
  18. <span v-show="!show" class="count" style="color:#9E9E9E">重新发送({{count}}S)</span>
  19. </view>
  20. </view>
  21. <view class="input">
  22. <input type="number" placeholder="请输入验证码" maxlength="4"
  23. placeholder-style="color:#9E9E9E;font-size:30rpx;" v-model="form.sms_code" @input="inputcode">
  24. </view>
  25. </view>
  26. <view class="login-singn" @click="login" :style="form.sms_code.length == 4 ? 'background-color:#1F7CFF':'background-color:rgba(31, 124, 255, 0.3)'">
  27. <view class="login-singn-text" :style="form.sms_code.length == 4 ? 'color:#FFF':'color: #333'">
  28. 登录
  29. </view>
  30. </view>
  31. <view class="bottom-index">
  32. <view class="bottom-index-in">
  33. <image src="https://cdn.bjtdba.com/vod/image/2022-08-09/20220809155152572.png" v-if="is_wei"
  34. @click="gou" mode="widthFix"></image>
  35. <image src="https://cdn.bjtdba.com/vod/image/2022-08-09/20220809155125568.png" v-if="is_yes"
  36. @click="gou" mode="widthFix"></image>
  37. </view>
  38. <view class="bottom-index-ri">
  39. 我已经阅读并同意<span style="color: #1f7cff" @click="xieyi()">《注册协议》</span >、<span style="color: #1f7cff" @click="yincang()">《隐私协议》</span>、<span style="color: #1f7cff" @click="ruzhuxieyi()">《商家入驻协议》</span>
  40. </view>
  41. </view>
  42. <view class="unLogin-singn" @click="unLogin">
  43. <view class="login-singn-text">
  44. 暂不登录
  45. </view>
  46. </view>
  47. <!-- #ifdef MP-WEIXIN -->
  48. <ws-wx-privacy id="privacy-popup"></ws-wx-privacy>
  49. <!-- #endif -->
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. userPhoneLogOnCode,
  55. userPhoneLogOn,
  56. selectMerchant,
  57. queryStoreBranch,
  58. getImUser
  59. } from '@/commit/api.js'
  60. import emHandleReconnect from '@/EaseIM/utils/emHandleReconnect';
  61. import { emConnect,emUserInfos } from '@/EaseIM/emApis';
  62. const { updateUserInfosFromServer } = emUserInfos();
  63. const { loginWithPassword } = emConnect();
  64. import wxPrivacy from '@/uni_modules/ws-wx-privacy/components/ws-wx-privacy/ws-wx-privacy.vue'
  65. export default {
  66. data() {
  67. return {
  68. show: true,
  69. count: '',
  70. timer: null,
  71. is_wei: true,
  72. is_yes: false,
  73. form: {
  74. phone: uni.getStorageSync("user_phone").length == 0?'':uni.getStorageSync("user_phone"),
  75. sms_code: '',
  76. type: '1'
  77. },
  78. type: ''
  79. }
  80. },
  81. onLoad(options) {
  82. //#ifdef MP-WEIXIN
  83. wx.requirePrivacyAuthorize({
  84. success: () => {
  85. console.log('点击同意');
  86. },
  87. fail: () => {
  88. console.log('点击拒绝');
  89. },
  90. complete: () => {
  91. console.log('用户已点击');
  92. }
  93. })
  94. //#endif
  95. this.type = options.type
  96. console.log(options.type)
  97. console.log(this.type)
  98. },
  99. components: {
  100. wxPrivacy
  101. },
  102. methods: {
  103. handleDisagree() {
  104. // 处理用户不同意隐私协议的逻辑
  105. },
  106. handleAgree() {
  107. // 处理用户同意隐私协议的逻辑
  108. },
  109. getCode() {
  110. var mobileReg = /^1[3456789]\d{9}$/;
  111. if (this.form.phone == "") {
  112. uni.showToast({
  113. title: "手机号不能为空",
  114. icon: "none"
  115. })
  116. } else if (!mobileReg.test(this.form.phone)) {
  117. uni.showToast({
  118. title: "手机号格式有误",
  119. icon: "none"
  120. })
  121. } else {
  122. // 点击获取验证码后 保存手机号
  123. uni.setStorageSync('user_phone',this.form.phone);
  124. const TIME_COUNT = 60;
  125. if (!this.timer) {
  126. this.count = TIME_COUNT;
  127. this.show = false;
  128. if (this.show == false) {
  129. // 获取验证码
  130. userPhoneLogOnCode({
  131. phone: this.form.phone
  132. }).then(res => {
  133. if (res.data.status == 200) {
  134. uni.showToast({
  135. title: res.data.data.message,
  136. icon: "none"
  137. })
  138. }
  139. }, fail => {
  140. uni.showToast({
  141. title: fail,
  142. icon: "error"
  143. })
  144. }).catch(err => {
  145. console.log(err)
  146. })
  147. }
  148. this.timer = setInterval(() => {
  149. if (this.count > 0 && this.count <= TIME_COUNT) {
  150. this.count--;
  151. } else {
  152. this.show = true;
  153. clearInterval(this.timer);
  154. this.timer = null;
  155. }
  156. }, 1000)
  157. }
  158. }
  159. },
  160. inputphone(e) {
  161. const o = e.target;
  162. const inputRule = /[^\d]/g
  163. this.$nextTick(function() {
  164. this.form.phone = o.value.replace(inputRule, '');
  165. if (this.form.phone.length < 11) {
  166. if(this.show==false){
  167. this.show = true;
  168. clearInterval(this.timer);
  169. this.timer = null;
  170. }
  171. }
  172. })
  173. },
  174. inputcode(e) {
  175. const o = e.target;
  176. const inputRule = /[^\d]/g
  177. this.$nextTick(function() {
  178. this.form.sms_code = o.value.replace(inputRule, '');
  179. })
  180. },
  181. xieyi() {
  182. uni.setStorageSync('agreementType','2')
  183. uni.navigateTo({
  184. url: "/pages/index/bottombat?type=2"
  185. })
  186. },
  187. yincang() {
  188. uni.setStorageSync('agreementType','1')
  189. uni.navigateTo({
  190. url: "/pages/index/bottombat?type=1"
  191. })
  192. },
  193. ruzhuxieyi() {
  194. uni.setStorageSync('agreementType','6')
  195. uni.navigateTo({
  196. url: "/pages/index/bottombat?type=6"
  197. })
  198. },
  199. gou() {
  200. if (this.is_wei == true) {
  201. this.is_wei = false;
  202. this.is_yes = true;
  203. } else {
  204. this.is_wei = true;
  205. this.is_yes = false;
  206. }
  207. },
  208. // 暂不登录
  209. unLogin() {
  210. setTimeout(function() {
  211. uni.switchTab({
  212. url: '../../my/index'
  213. });
  214. }, 300);
  215. },
  216. //lww
  217. // loginWithUserId (){
  218. // try {
  219. // uni.setStorage({
  220. // key: 'myUsername',
  221. // data: loginState.name.toLowerCase(),
  222. // });
  223. // console.log('22222');
  224. // loginStore.setLoginUserBaseInfos({ loginUserId: loginState.name });
  225. // setUserTokenToStorage(loginState.name.toLowerCase(), res.accessToken);
  226. // } catch (error) {
  227. // console.log('>>>>>>', error);
  228. // uni.showToast({
  229. // title: '登录失败',
  230. // icon: 'none',
  231. // });
  232. // console.log('33333');
  233. // } finally {
  234. // loginState.name = '';
  235. // loginState.psd = '';
  236. // }
  237. // },
  238. //lww
  239. async loginWithUserId() {
  240. this.loginEaseIMId =uni.getStorageSync('im_userid')
  241. try {
  242. const res = await loginWithPassword(
  243. this.loginEaseIMId,
  244. uni.getStorageSync('im_pass')
  245. );
  246. this.$store.commit('SET_LOGIN_USER_BASE_INFOS', {
  247. loginUserId: this.loginEaseIMId,
  248. });
  249. this.setEMUserLoginInfosToStorage(
  250. this.loginEaseIMId.toLowerCase(),
  251. res.accessToken
  252. //注意:res.accessToken
  253. );
  254. // this.updateHXUser();
  255. } catch (error) {
  256. console.log('>>>>>>', error);
  257. uni.showToast({
  258. title: '登录失败',
  259. icon: 'none',
  260. });
  261. } finally {
  262. this.loginEaseIMId = '';
  263. }
  264. },
  265. setEMUserLoginInfosToStorage(userId, token) {
  266. const params = {
  267. key: `EM_LOGIN_INFOS`,
  268. data: { userId: userId, token: token },
  269. };
  270. uni.setStorage({ ...params });
  271. },
  272. updateHXUser(){
  273. console.log('修改环信的昵称');
  274. updateUserInfosFromServer({nickname: JSON.stringify(uni.getStorageSync('userinfo')).nickname,avatarurl:JSON.stringify(uni.getStorageSync('userinfo')).avatar});
  275. // {nickname: JSON.stringify(uni.getStorageSync('userinfo')).nickname,avatar:JSON.stringify(uni.getStorageSync('userinfo')).avatar}
  276. },
  277. //lww结束
  278. login() {
  279. const { actionEMReconnect } = emHandleReconnect();
  280. var mobileReg = /^1[3456789]\d{9}$/;
  281. if (this.form.phone == "") {
  282. uni.showToast({
  283. title: "手机号不能为空",
  284. icon: "none"
  285. })
  286. } else if (!mobileReg.test(this.form.phone)) {
  287. uni.showToast({
  288. title: "手机号格式有误",
  289. icon: "none"
  290. })
  291. } else if (this.form.sms_code == "") {
  292. uni.showToast({
  293. title: "请输入验证码",
  294. icon: "none"
  295. })
  296. } else if (this.is_wei == true) {
  297. uni.showToast({
  298. title: "请勾选协议",
  299. icon: "none"
  300. })
  301. return;
  302. } else {
  303. // 登录注册
  304. userPhoneLogOn(this.form).then(res => {
  305. console.log(res)
  306. if (res.data.status == 200 && JSON.stringify(res.data.data) != "{}") {
  307. uni.setStorageSync('userinfo', res.data.data.user);
  308. uni.setStorageSync('authorization', res.data.data.x_token);
  309. uni.setStorageSync('storeStaff', res.data.data.storeStaff);
  310. // 用户状态判断
  311. selectMerchant({
  312. uid: res.data.data.user.uid
  313. }).then(data => {
  314. uni.setStorage({
  315. key: 'myUsername',
  316. data: JSON.stringify(uni.getStorageSync('userinfo').uid),
  317. });
  318. uni.setStorage({
  319. key: 'mer_id',
  320. data: data.data.data.merchantIntention.mer_id,
  321. });
  322. if (data.data.status == 200) {
  323. uni.setStorageSync('selectmerchant', data.data.data);
  324. //lww
  325. getImUser({
  326. mer_id: uni.getStorageSync('mer_id'),
  327. }).then(data=>{
  328. console.log('getImUser======',data.data.data);
  329. // actionEMReconnect();
  330. // this.loginWithUserId()
  331. const { loginWithPassword } = emConnect();
  332. uni.setStorage({
  333. key: 'im_userid',
  334. data:data.data.data.im_userid
  335. })
  336. uni.setStorage({
  337. key: 'im_pass',
  338. data:data.data.data.im_pass
  339. })
  340. uni.setStorage({
  341. key: 'im_uuid',
  342. data:data.data.data.im_uuid
  343. })
  344. //环信注册成功 登录
  345. if(data.data.status==200){
  346. console.log('>>>>>>>>环信注册成功 登录')
  347. this.loginWithUserId()
  348. //更新环信的用户信息 头像,昵称
  349. }
  350. })
  351. //lww
  352. let storeStaff = uni.getStorageSync('storeStaff')
  353. if (storeStaff != null) {
  354. queryStoreBranch({
  355. id: storeStaff.department
  356. }).then(res => {
  357. if (res.data.status == 200) {
  358. uni.setStorageSync('jurisdiction', res.data.data.jurisdiction);
  359. }
  360. })
  361. } else {
  362. uni.setStorageSync('jurisdiction', [7, 9, 5, 3]);
  363. }
  364. uni.showToast({
  365. title: res.data.message,
  366. icon: "none"
  367. })
  368. console.log(this.type, 'this.type')
  369. if (this.type == 1) {
  370. console.log('返回上一页')
  371. uni.navigateBack({
  372. delta: 1
  373. })
  374. } else {
  375. setTimeout(function() {
  376. uni.switchTab({
  377. url: '../../cashier/index'
  378. });
  379. }, 700);
  380. }
  381. }
  382. }, fail => {
  383. uni.showToast({
  384. title: fail,
  385. icon: "none"
  386. })
  387. }).catch(err => {
  388. console.log(err)
  389. })
  390. } else {
  391. uni.showToast({
  392. title: res.data.message,
  393. icon: "none"
  394. })
  395. }
  396. }, fail => {
  397. uni.showToast({
  398. title: fail,
  399. icon: "none"
  400. })
  401. }).catch(data => {
  402. console.log(data)
  403. })
  404. }
  405. },
  406. }
  407. }
  408. </script>
  409. <style lang="scss" scoped>
  410. .login {
  411. width: 100%;
  412. height: 100%;
  413. display: flex;
  414. flex-direction: column;
  415. align-items: center;
  416. .login_header {
  417. height: 211rpx;
  418. margin-top: 74rpx;
  419. display: flex;
  420. flex-direction: column;
  421. justify-content: space-between;
  422. align-items: center;
  423. .login_header_top {
  424. width: 216rpx;
  425. height: 242rpx;
  426. image {
  427. width: 100%;
  428. height: 100%;
  429. }
  430. }
  431. .login_header_botom {
  432. width: 156rpx;
  433. height: 48rpx;
  434. image {
  435. width: 100%;
  436. height: 100%;
  437. }
  438. }
  439. }
  440. .input-home {
  441. width: 658rpx;
  442. height: 238rpx;
  443. margin-top: 67rpx;
  444. display: flex;
  445. flex-direction: column;
  446. align-items: center;
  447. justify-content: space-between;
  448. .input {
  449. width: 100%;
  450. height: 118rpx;
  451. border-bottom: 1rpx solid #E5E5E5;
  452. position: relative;
  453. input {
  454. width: 485rpx;
  455. height: 100rpx;
  456. margin: 20rpx 0 0 10rpx;
  457. color: #333333;
  458. }
  459. .input_code {
  460. position: absolute;
  461. top: 55rpx;
  462. right: 15rpx;
  463. font-size: 30rpx;
  464. font-weight: 400;
  465. }
  466. }
  467. }
  468. .login-singn {
  469. width: 658rpx;
  470. height: 88rpx;
  471. background-color: rgba(31, 124, 255, 0.3);
  472. border-radius: 10rpx;
  473. margin-top: 70rpx;
  474. font-size: 30rpx;
  475. font-weight: 400;
  476. display: flex;
  477. justify-content: center;
  478. align-items: center;
  479. color: #333333;
  480. }
  481. .unLogin-singn {
  482. margin-top: 88rpx;
  483. }
  484. .bottom-index {
  485. width: 658rpx;
  486. height: 33rpx;
  487. display: flex;
  488. justify-content: space-between;
  489. align-items: center;
  490. margin-top: 60rpx;
  491. .bottom-index-in {
  492. width: 32rpx;
  493. height: 32rpx;
  494. line-height: 33rpx;
  495. transform: sale(2);
  496. image {
  497. width: 100%;
  498. height: 100%;
  499. }
  500. margin-right: 20rpx;
  501. // position: relative;
  502. }
  503. .bottom-index-ri {
  504. height: 100%;
  505. font-size: 24rpx;
  506. }
  507. }
  508. }
  509. </style>