index.vue 15 KB

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