多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
9.0 KiB

2 years ago
2 years ago
2 years ago
  1. <template>
  2. <!-- 登录 -->
  3. <view class="container flex-items-plus flex-column">
  4. <global-loading />
  5. <view class="login-logoBox">
  6. <image
  7. class="login-logo"
  8. src="https://wechat.hnthee.com/ceres-local-file/image/logo_wechat.png"
  9. ></image>
  10. </view>
  11. <view class="iphoneNum-box flex-row-plus flex-items">
  12. <view style="margin-right: 30rpx">
  13. <image
  14. class="loginIcon"
  15. src="https://ceres.zkthink.com/static/images/phone.png"
  16. ></image>
  17. </view>
  18. <view>
  19. <input
  20. v-model="loginQuery.account"
  21. placeholder-class="iphoneNum-input"
  22. type="number"
  23. maxlength='11'
  24. placeholder="请输入您的手机号"
  25. />
  26. </view>
  27. </view>
  28. <view class="flex-row-plus mar-top-20">
  29. <view class="code-box">
  30. <view style="margin-right: 30rpx">
  31. <image
  32. class="loginIcon"
  33. src="https://ceres.zkthink.com/static/images/code.png"
  34. ></image>
  35. </view>
  36. <view>
  37. <input
  38. v-model="loginQuery.code"
  39. :maxlength="4"
  40. placeholder-class="codeNum-input"
  41. placeholder="请输入验证码"
  42. />
  43. </view>
  44. </view>
  45. <view
  46. :class="disabled === true ? 'on' : ''"
  47. :disabled="disabled"
  48. class="getcode"
  49. @click="codede"
  50. >{{ text }}
  51. </view>
  52. </view>
  53. <view class="mar-top-60">
  54. <view
  55. class="registerBut mar-top-100"
  56. @click="login"
  57. >登录
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import sendVerifyCode from "@/mixins/SendVerifyCode";
  64. const NET = require('../../utils/request')
  65. const API = require('../../config/api')
  66. export default {
  67. data() {
  68. return {
  69. loginQuery: {
  70. account: '',
  71. code: '',
  72. salesId: '',
  73. },
  74. // 获取验证码
  75. VerifyQuery: {
  76. phone: ""
  77. },
  78. inviteSpell: {},
  79. inviteSpelltype: false,
  80. beforePage: undefined,
  81. doubleBeforePage: undefined
  82. }
  83. },
  84. mixins: [sendVerifyCode],
  85. onLoad(options) {
  86. if (options.inviteSpell == 1) {
  87. this.inviteSpelltype = true
  88. this.inviteSpell = uni.getStorageSync('inviteSpell');
  89. }
  90. this.loginQuery.salesId = uni.getStorageSync('salesId');
  91. var pages = getCurrentPages()
  92. if (pages.length >= 2) {
  93. this.beforePage = pages[pages.length - 2]
  94. }
  95. if (pages.length >= 3) {
  96. this.doubleBeforePage = pages[pages.length - 3]
  97. }
  98. },
  99. methods: {
  100. login() {
  101. let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  102. if (this.loginQuery.account == '') {
  103. uni.showToast({
  104. title: '请输入手机号!',
  105. duration: 2000,
  106. icon: 'none'
  107. });
  108. } else if (!phoneCodeVerification.test(this.loginQuery.account)) {
  109. uni.showToast({
  110. title: '请输入正确的手机号!',
  111. duration: 2000,
  112. icon: 'none'
  113. });
  114. } else {
  115. const that = this
  116. // uni.showLoading({
  117. // mask: true,
  118. // title: '正在登录...',
  119. // duration: 2000,
  120. // });
  121. NET.request(API.Login, {
  122. type: 2,
  123. phone: this.loginQuery.account,
  124. verificationCode: this.loginQuery.code
  125. }, 'POST').then(res => {
  126. uni.hideLoading()
  127. const item = res.data
  128. uni.setStorageSync('storage_key', item);
  129. if (uni.getStorageSync("salesId")) {
  130. let salesId = uni.getStorageSync("salesId")
  131. let shopId = uni.getStorageSync("shopId")
  132. this.bindSalesCustomer(salesId, shopId)
  133. uni.removeStorageSync('salesId');
  134. uni.removeStorageSync('shopId');
  135. }
  136. // 购物车右上角数量
  137. NET.request(API.ShoppingCart, {}, 'GET').then(resCart => {
  138. let cartNum = 0
  139. resCart.data.forEach(shopItem => {
  140. shopItem.skus.forEach(goodsItem => {
  141. cartNum += goodsItem.number
  142. })
  143. })
  144. if (cartNum > 0) {
  145. uni.setTabBarBadge({
  146. index: 2,
  147. text: cartNum.toString()
  148. })
  149. }
  150. uni.setStorageSync('allCartNum', cartNum)
  151. })
  152. if (this.inviteSpelltype == true) {
  153. setTimeout(function () {
  154. uni.reLaunch({
  155. url: '../../pages_category_page1/goodsModule/inviteSpell?collageId=' +
  156. this.inviteSpell.collageId + '&orderId=' + this.inviteSpell
  157. .orderId + '&type=0' + '&productId=' + this.inviteSpell
  158. .productId + '&skuId=' + this.inviteSpell.skuId
  159. })
  160. uni.removeStorageSync('inviteSpell');
  161. }, 2000)
  162. } else {
  163. if (that.beforePage && that.beforePage.route !==
  164. 'pages_category_page2/userModule/accountLogin' &&
  165. that.beforePage.route !== 'pages_category_page2/userModule/login' &&
  166. that.beforePage.route !== 'pages_category_page2/userModule/register') {
  167. uni.navigateBack({
  168. delta: 1
  169. })
  170. } else if (that.doubleBeforePage && that.doubleBeforePage.route !==
  171. 'pages_category_page2/userModule/accountLogin' &&
  172. that.doubleBeforePage.route !== 'pages_category_page2/userModule/login' &&
  173. that.doubleBeforePage.route !== 'pages_category_page2/userModule/register') {
  174. uni.navigateBack({
  175. delta: 2
  176. })
  177. } else {
  178. setTimeout(function () {
  179. uni.switchTab({
  180. url: '../../pages/tabbar/user/index'
  181. })
  182. }, 600)
  183. }
  184. }
  185. }).catch(res => {
  186. console.dir(res)
  187. uni.hideLoading()
  188. uni.showToast({
  189. title: res.data.message,
  190. duration: 2000,
  191. icon: 'none',
  192. });
  193. })
  194. }
  195. },
  196. // 获取验证码
  197. codede() {
  198. this.getVerify()
  199. },
  200. getVerify() {
  201. let phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  202. if (this.loginQuery.account == '') {
  203. uni.showToast({
  204. title: '请输入手机号!',
  205. duration: 2000,
  206. icon: 'none'
  207. });
  208. } else if (!phoneCodeVerification.test(this.loginQuery.account)) {
  209. uni.showToast({
  210. title: '请输入正确的手机号!',
  211. duration: 2000,
  212. icon: 'none'
  213. });
  214. } else {
  215. this.VerifyQuery.phone = this.loginQuery.account
  216. NET.request(API.Verify, {
  217. phone: this.VerifyQuery.phone,
  218. }, 'GET').then(res => {
  219. this.sendCode()
  220. }).catch(res => {
  221. uni.showToast({
  222. title: res.data.message,
  223. duration: 1000,
  224. icon: 'none'
  225. });
  226. })
  227. }
  228. },
  229. //绑定关系
  230. bindSalesCustomer(salesId, storeId) {
  231. if (salesId && storeId) {
  232. //如果已登录,静默绑定客户关系,否则跳转到登录页面
  233. NET.request(API.BindSalesCustomer, {
  234. shopId: storeId,
  235. distributorId: salesId
  236. }, 'POST').then(res => {
  237. uni.showToast({
  238. title: "绑定成功",
  239. icon: "none"
  240. })
  241. }).catch(res => {
  242. uni.showToast({
  243. title: res.data.message,
  244. icon: "none"
  245. })
  246. })
  247. }
  248. }
  249. }
  250. }
  251. </script>
  252. <style lang="scss">
  253. .container {
  254. background-color: #FFFFFF;
  255. height: 100vh;
  256. .login-logoBox {
  257. margin-top: -300rpx;
  258. .login-logo {
  259. width: 518rpx;
  260. height: 100rpx;
  261. }
  262. }
  263. .iphoneNum-box {
  264. margin-top: 100rpx;
  265. border-bottom: 1rpx solid #DDDDDD;
  266. height: 100rpx;
  267. width: 600rpx;
  268. .loginIcon {
  269. width: 40rpx;
  270. height: 53rpx;
  271. }
  272. .iphoneNum-input {
  273. color: #999999;
  274. font-size: 28rpx;
  275. font-weight: 400;
  276. }
  277. }
  278. .passwordNum-box {
  279. border-bottom: 1rpx solid #DDDDDD;
  280. height: 100rpx;
  281. width: 600rpx;
  282. .passwordNum-input {
  283. color: #999999;
  284. font-size: 28rpx;
  285. font-weight: 400;
  286. width: 346rpx;
  287. }
  288. }
  289. .code-box {
  290. border-bottom: 1rpx solid #DDDDDD;
  291. height: 100rpx;
  292. width: 360rpx;
  293. display: flex;
  294. flex-direction: row;
  295. justify-content: space-between;
  296. align-items: center;
  297. .loginIcon {
  298. width: 44rpx;
  299. height: 50rpx;
  300. }
  301. .code-lab {
  302. width: 200rpx;
  303. }
  304. .codeNum-input {
  305. color: #999999;
  306. font-size: 28rpx;
  307. font-weight: 400;
  308. }
  309. }
  310. .getcode {
  311. background-color: #C5AA7B;
  312. height: 100rpx;
  313. width: 230rpx;
  314. display: flex;
  315. flex-direction: row;
  316. justify-content: center;
  317. align-items: center;
  318. margin-left: 20rpx;
  319. color: #FFFFFF;
  320. }
  321. .registerBut {
  322. background: #333333;
  323. color: #FFEBC4;
  324. height: 100rpx;
  325. width: 600rpx;
  326. text-align: center;
  327. line-height: 100rpx;
  328. margin-top: 30rpx;
  329. }
  330. }
  331. </style>