index - 副本.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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 } from '@/EaseIM/emApis';
  62. import wxPrivacy from '@/uni_modules/ws-wx-privacy/components/ws-wx-privacy/ws-wx-privacy.vue'
  63. export default {
  64. data() {
  65. return {
  66. show: true,
  67. count: '',
  68. timer: null,
  69. is_wei: true,
  70. is_yes: false,
  71. form: {
  72. phone: uni.getStorageSync("user_phone").length == 0?'':uni.getStorageSync("user_phone"),
  73. sms_code: '',
  74. type: '1'
  75. },
  76. type: ''
  77. }
  78. },
  79. onLoad(options) {
  80. //#ifdef MP-WEIXIN
  81. wx.requirePrivacyAuthorize({
  82. success: () => {
  83. console.log('点击同意');
  84. },
  85. fail: () => {
  86. console.log('点击拒绝');
  87. },
  88. complete: () => {
  89. console.log('用户已点击');
  90. }
  91. })
  92. //#endif
  93. this.type = options.type
  94. console.log(options.type)
  95. console.log(this.type)
  96. },
  97. components: {
  98. wxPrivacy
  99. },
  100. methods: {
  101. handleDisagree() {
  102. // 处理用户不同意隐私协议的逻辑
  103. },
  104. handleAgree() {
  105. // 处理用户同意隐私协议的逻辑
  106. },
  107. getCode() {
  108. var mobileReg = /^1[3456789]\d{9}$/;
  109. if (this.form.phone == "") {
  110. uni.showToast({
  111. title: "手机号不能为空",
  112. icon: "none"
  113. })
  114. } else if (!mobileReg.test(this.form.phone)) {
  115. uni.showToast({
  116. title: "手机号格式有误",
  117. icon: "none"
  118. })
  119. } else {
  120. // 点击获取验证码后 保存手机号
  121. uni.setStorageSync('user_phone',this.form.phone);
  122. const TIME_COUNT = 60;
  123. if (!this.timer) {
  124. this.count = TIME_COUNT;
  125. this.show = false;
  126. if (this.show == false) {
  127. // 获取验证码
  128. userPhoneLogOnCode({
  129. phone: this.form.phone
  130. }).then(res => {
  131. if (res.data.status == 200) {
  132. uni.showToast({
  133. title: res.data.data.message,
  134. icon: "none"
  135. })
  136. }
  137. }, fail => {
  138. uni.showToast({
  139. title: fail,
  140. icon: "error"
  141. })
  142. }).catch(err => {
  143. console.log(err)
  144. })
  145. }
  146. this.timer = setInterval(() => {
  147. if (this.count > 0 && this.count <= TIME_COUNT) {
  148. this.count--;
  149. } else {
  150. this.show = true;
  151. clearInterval(this.timer);
  152. this.timer = null;
  153. }
  154. }, 1000)
  155. }
  156. }
  157. },
  158. inputphone(e) {
  159. const o = e.target;
  160. const inputRule = /[^\d]/g
  161. this.$nextTick(function() {
  162. this.form.phone = o.value.replace(inputRule, '');
  163. if (this.form.phone.length < 11) {
  164. if(this.show==false){
  165. this.show = true;
  166. clearInterval(this.timer);
  167. this.timer = null;
  168. }
  169. }
  170. })
  171. },
  172. inputcode(e) {
  173. const o = e.target;
  174. const inputRule = /[^\d]/g
  175. this.$nextTick(function() {
  176. this.form.sms_code = o.value.replace(inputRule, '');
  177. })
  178. },
  179. xieyi() {
  180. uni.setStorageSync('agreementType','2')
  181. uni.navigateTo({
  182. url: "/pages/index/bottombat?type=2"
  183. })
  184. },
  185. yincang() {
  186. uni.setStorageSync('agreementType','1')
  187. uni.navigateTo({
  188. url: "/pages/index/bottombat?type=1"
  189. })
  190. },
  191. ruzhuxieyi() {
  192. uni.setStorageSync('agreementType','6')
  193. uni.navigateTo({
  194. url: "/pages/index/bottombat?type=6"
  195. })
  196. },
  197. gou() {
  198. if (this.is_wei == true) {
  199. this.is_wei = false;
  200. this.is_yes = true;
  201. } else {
  202. this.is_wei = true;
  203. this.is_yes = false;
  204. }
  205. },
  206. // 暂不登录
  207. unLogin() {
  208. setTimeout(function() {
  209. uni.switchTab({
  210. url: '../../my/index'
  211. });
  212. }, 300);
  213. },
  214. loginWithUserId (){
  215. try {
  216. uni.setStorage({
  217. key: 'myUsername',
  218. data: loginState.name.toLowerCase(),
  219. });
  220. console.log('22222');
  221. loginStore.setLoginUserBaseInfos({ loginUserId: loginState.name });
  222. setUserTokenToStorage(loginState.name.toLowerCase(), res.accessToken);
  223. } catch (error) {
  224. console.log('>>>>>>', error);
  225. uni.showToast({
  226. title: '登录失败',
  227. icon: 'none',
  228. });
  229. console.log('33333');
  230. } finally {
  231. loginState.name = '';
  232. loginState.psd = '';
  233. }
  234. },
  235. login() {
  236. const { actionEMReconnect } = emHandleReconnect();
  237. var mobileReg = /^1[3456789]\d{9}$/;
  238. if (this.form.phone == "") {
  239. uni.showToast({
  240. title: "手机号不能为空",
  241. icon: "none"
  242. })
  243. } else if (!mobileReg.test(this.form.phone)) {
  244. uni.showToast({
  245. title: "手机号格式有误",
  246. icon: "none"
  247. })
  248. } else if (this.form.sms_code == "") {
  249. uni.showToast({
  250. title: "请输入验证码",
  251. icon: "none"
  252. })
  253. } else if (this.is_wei == true) {
  254. uni.showToast({
  255. title: "请勾选协议",
  256. icon: "none"
  257. })
  258. return;
  259. } else {
  260. // 登录注册
  261. userPhoneLogOn(this.form).then(res => {
  262. console.log(res)
  263. if (res.data.status == 200 && JSON.stringify(res.data.data) != "{}") {
  264. uni.setStorageSync('userinfo', res.data.data.user);
  265. uni.setStorageSync('authorization', res.data.data.x_token);
  266. uni.setStorageSync('storeStaff', res.data.data.storeStaff);
  267. // 用户状态判断
  268. selectMerchant({
  269. uid: res.data.data.user.uid
  270. }).then(data => {
  271. uni.setStorage({
  272. key: 'myUsername',
  273. data: JSON.stringify(uni.getStorageSync('userinfo').uid),
  274. });
  275. getImUser({
  276. mer_id: data.data.data.merId
  277. }).then(data=>{
  278. console.log('getImUser======',data.data.data);
  279. actionEMReconnect();
  280. // this.loginWithUserId()
  281. const { loginWithPassword } = emConnect();
  282. uni.setStorage({
  283. key: 'im_userid',
  284. data:data.data.data.im_userid
  285. })
  286. uni.setStorage({
  287. key: 'im_pass',
  288. data:data.data.data.im_pass
  289. })
  290. // loginWithPassword( data.data.data.im_userid,data.data.data.im_pass);
  291. // getApp().globalData.conn.open({
  292. // apiUrl: WebIM.config.apiURL,
  293. // appKey: "1154240320150538#cxb-yhc",
  294. // pwd: "123456",
  295. // user: JSON.stringify(uni.getStorageSync('userinfo').uid),
  296. // success: (res) => {
  297. // console.log('1111');
  298. // console.log('uni.WebIM.conn.open-----',res);
  299. // const {
  300. // access_token
  301. // } = res
  302. // uni.setStorageSync('imToken', access_token)
  303. // },
  304. // error:(err)=>{
  305. // console.log('2222');
  306. // console.log(err);
  307. // }
  308. // });
  309. })
  310. if (data.data.status == 200) {
  311. uni.setStorageSync('selectmerchant', data.data.data);
  312. let storeStaff = uni.getStorageSync('storeStaff')
  313. if (storeStaff != null) {
  314. queryStoreBranch({
  315. id: storeStaff.department
  316. }).then(res => {
  317. if (res.data.status == 200) {
  318. uni.setStorageSync('jurisdiction', res.data.data.jurisdiction);
  319. }
  320. })
  321. } else {
  322. uni.setStorageSync('jurisdiction', [7, 9, 5, 3]);
  323. }
  324. uni.showToast({
  325. title: res.data.message,
  326. icon: "none"
  327. })
  328. console.log(this.type)
  329. if (this.type == 1) {
  330. console.log('返回上一页')
  331. uni.navigateBack({
  332. delta: 1
  333. })
  334. } else {
  335. setTimeout(function() {
  336. uni.switchTab({
  337. url: '../../cashier/index'
  338. });
  339. }, 700);
  340. }
  341. }
  342. }, fail => {
  343. uni.showToast({
  344. title: fail,
  345. icon: "none"
  346. })
  347. }).catch(err => {
  348. console.log(err)
  349. })
  350. } else {
  351. uni.showToast({
  352. title: res.data.message,
  353. icon: "none"
  354. })
  355. }
  356. }, fail => {
  357. uni.showToast({
  358. title: fail,
  359. icon: "none"
  360. })
  361. }).catch(data => {
  362. console.log(data)
  363. })
  364. }
  365. },
  366. }
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. .login {
  371. width: 100%;
  372. height: 100%;
  373. display: flex;
  374. flex-direction: column;
  375. align-items: center;
  376. .login_header {
  377. height: 211rpx;
  378. margin-top: 74rpx;
  379. display: flex;
  380. flex-direction: column;
  381. justify-content: space-between;
  382. align-items: center;
  383. .login_header_top {
  384. width: 216rpx;
  385. height: 242rpx;
  386. image {
  387. width: 100%;
  388. height: 100%;
  389. }
  390. }
  391. .login_header_botom {
  392. width: 156rpx;
  393. height: 48rpx;
  394. image {
  395. width: 100%;
  396. height: 100%;
  397. }
  398. }
  399. }
  400. .input-home {
  401. width: 658rpx;
  402. height: 238rpx;
  403. margin-top: 67rpx;
  404. display: flex;
  405. flex-direction: column;
  406. align-items: center;
  407. justify-content: space-between;
  408. .input {
  409. width: 100%;
  410. height: 118rpx;
  411. border-bottom: 1rpx solid #E5E5E5;
  412. position: relative;
  413. input {
  414. width: 485rpx;
  415. height: 100rpx;
  416. margin: 20rpx 0 0 10rpx;
  417. color: #333333;
  418. }
  419. .input_code {
  420. position: absolute;
  421. top: 55rpx;
  422. right: 15rpx;
  423. font-size: 30rpx;
  424. font-weight: 400;
  425. }
  426. }
  427. }
  428. .login-singn {
  429. width: 658rpx;
  430. height: 88rpx;
  431. background-color: rgba(31, 124, 255, 0.3);
  432. border-radius: 10rpx;
  433. margin-top: 70rpx;
  434. font-size: 30rpx;
  435. font-weight: 400;
  436. display: flex;
  437. justify-content: center;
  438. align-items: center;
  439. color: #333333;
  440. }
  441. .unLogin-singn {
  442. margin-top: 88rpx;
  443. }
  444. .bottom-index {
  445. width: 658rpx;
  446. height: 33rpx;
  447. display: flex;
  448. justify-content: space-between;
  449. align-items: center;
  450. margin-top: 60rpx;
  451. .bottom-index-in {
  452. width: 32rpx;
  453. height: 32rpx;
  454. line-height: 33rpx;
  455. transform: sale(2);
  456. image {
  457. width: 100%;
  458. height: 100%;
  459. }
  460. margin-right: 20rpx;
  461. // position: relative;
  462. }
  463. .bottom-index-ri {
  464. height: 100%;
  465. font-size: 24rpx;
  466. }
  467. }
  468. }
  469. </style>