accountLogin.vue 7.6 KB

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