accountLogin.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <!-- 登录 -->
  3. <!-- flex-items-plus 去除了这个类名 相当于flex的两个居中操作 alignItems justifyContent -->
  4. <view class="container flex-column">
  5. <global-loading />
  6. <view style="padding: 30upx 20upx 0;color: #000000;">
  7. <JHeader width="50" height="50" title=""></JHeader>
  8. </view>
  9. <view class="register" @click="$jump('/pages_category_page2/userModule/register', '', 0, 'reLaunch')">
  10. 注册
  11. </view>
  12. <view class="PhoneAuthentication">
  13. <text class="textRL">手机号快捷登录</text>
  14. <text class="textTips">请先注册账号再登录</text>
  15. </view>
  16. <view class="LoginForm">
  17. <view class="iphoneNum-box">
  18. <text class="labels">手机号</text>
  19. <input v-model="loginQuery.account" type="texts" placeholder="请输入手机号">
  20. </view>
  21. <view v-if="loginType === 'password'" class="iphoneNum-box">
  22. <text class="labels">密码</text>
  23. <input v-model="loginQuery.password" type="texts" placeholder="请输入密码">
  24. </view>
  25. <view v-else-if="loginType === 'verificationCode'" class="iphoneNum-box">
  26. <text class="labels">验证码</text>
  27. <input v-model="loginQuery.verificationCode" type="texts" placeholder="请输入验证码">
  28. <view v-if="!disabled" class="getcode" @click="codede">
  29. {{ text }}
  30. </view>
  31. <view v-else class="awaitCode">
  32. {{ text }}
  33. </view>
  34. </view>
  35. <view class="ReadingAgreement">
  36. <radio
  37. style="transform:scale(0.8)" color="#CE2601" :checked="isReadAgreement"
  38. @click="isReadAgreement = !isReadAgreement"
  39. />
  40. <view class="Agreement">
  41. 我已阅读并同意<text class="redText">《巨蜂商城用户服务协议》</text>以及<text class="redText">《隐私政策》</text>
  42. </view>
  43. </view>
  44. </view>
  45. <tui-button
  46. :disabled="!isReadAgreement" type="danger" width="650rpx" margin="0 auto"
  47. height="82rpx"
  48. style="margin-top: 60rpx;" @click="login"
  49. >
  50. 立即登录
  51. </tui-button>
  52. <view class="problem">
  53. <text @click="$jump('/pages_category_page2/userModule/register', '', 0, 'reLaunch')">没有账号?<text class="redText">去注册</text></text>
  54. <text>无法接收验证码?</text>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import sendVerifyCode from '@/mixins/SendVerifyCode'
  60. import { J_STORAGE_KEY } from '../../config/constant'
  61. const NET = require('../../utils/request')
  62. const API = require('../../config/api')
  63. import { getVerifyCodeApi } from '../../api/user'
  64. export default {
  65. name: 'AccountLogin',
  66. mixins: [ sendVerifyCode ],
  67. data() {
  68. return {
  69. loginType: '', // password,verificationCode
  70. loginQuery: {
  71. account: '',
  72. verificationCode: '',
  73. salesId: '',
  74. password: ''
  75. },
  76. isReadAgreement: false
  77. }
  78. },
  79. onLoad(options) {
  80. this.loginType = options.type || ''
  81. this.loginQuery.salesId = uni.getStorageSync('salesId')
  82. },
  83. methods: {
  84. login() {
  85. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  86. if (this.loginQuery.account == '') {
  87. this.$showToast('请输入手机号!')
  88. } else if (!phoneCodeVerification.test(this.loginQuery.account)) {
  89. this.$showToast('请输入正确的手机号!')
  90. } else {
  91. // uni.showLoading({
  92. // mask: true,
  93. // title: '正在登录...',
  94. // duration: 2000,
  95. // });
  96. NET.request(API.Login, {
  97. type: 2,
  98. phone: this.loginQuery.account,
  99. verificationCode: this.loginQuery.verificationCode,
  100. password: this.loginQuery.password
  101. }, 'POST').then((res) => {
  102. uni.hideLoading()
  103. const item = res.data
  104. uni.setStorageSync(J_STORAGE_KEY, item)
  105. if (uni.getStorageSync('salesId')) {
  106. const salesId = uni.getStorageSync('salesId')
  107. const shopId = uni.getStorageSync('shopId')
  108. this.bindSalesCustomer(salesId, shopId)
  109. uni.removeStorageSync('salesId')
  110. uni.removeStorageSync('shopId')
  111. }
  112. // 购物车右上角数量
  113. NET.request(API.ShoppingCart, {}, 'GET').then((resCart) => {
  114. let cartNum = 0
  115. resCart.data.forEach((shopItem) => {
  116. shopItem.skus.forEach((goodsItem) => {
  117. cartNum += goodsItem.number
  118. })
  119. })
  120. if (cartNum > 0) {
  121. uni.setTabBarBadge({
  122. index: 3,
  123. text: cartNum.toString()
  124. })
  125. }
  126. uni.setStorageSync('allCartNum', cartNum)
  127. })
  128. setTimeout(() => {
  129. this.$switchTab('/pages/tabbar/user/index')
  130. }, 600)
  131. })
  132. .catch((res) => {
  133. console.dir(res)
  134. uni.hideLoading()
  135. this.$showToast(res.data.message)
  136. })
  137. }
  138. },
  139. // 获取验证码
  140. codede() {
  141. this.getVerify()
  142. },
  143. getVerify() {
  144. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  145. if (this.loginQuery.account == '') {
  146. this.$showToast('请输入手机号!')
  147. } else if (!phoneCodeVerification.test(this.loginQuery.account)) {
  148. this.$showToast('请输入正确的手机号!')
  149. } else {
  150. getVerifyCodeApi({
  151. phone: this.loginQuery.account
  152. }).then((res) => {
  153. this.sendCode()
  154. })
  155. .catch((res) => {
  156. this.$showToast(res.data.message)
  157. })
  158. }
  159. },
  160. // 绑定关系
  161. bindSalesCustomer(salesId, storeId) {
  162. if (salesId && storeId) {
  163. // 如果已登录,静默绑定客户关系,否则跳转到登录页面
  164. NET.request(API.BindSalesCustomer, {
  165. shopId: storeId,
  166. distributorId: salesId
  167. }, 'POST').then((res) => {
  168. this.$showToast('绑定成功')
  169. })
  170. .catch((res) => {
  171. this.$showToast(res.data.message)
  172. })
  173. }
  174. }
  175. }
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. .container {
  180. box-sizing: border-box;
  181. background-color: #FFFFFF;
  182. .redText {
  183. color: #CE2601;
  184. }
  185. .register {
  186. margin-top: 30rpx;
  187. position: relative;
  188. text-align: right;
  189. padding-right: 40rpx;
  190. }
  191. .PhoneAuthentication {
  192. margin-top: 15rpx;
  193. font-family: Source Han Sans CN;
  194. width: 466rpx;
  195. height: 100rpx;
  196. display: flex;
  197. flex-direction: column;
  198. padding: 0px 30rpx;
  199. gap: 8rpx;
  200. .textRL {
  201. font-size: 44rpx;
  202. font-weight: 600;
  203. line-height: 60rpx;
  204. color: #222229;
  205. }
  206. .textTips {
  207. font-size: 24rpx;
  208. font-weight: 350;
  209. line-height: 32rpx;
  210. color: #888889;
  211. }
  212. }
  213. .LoginForm {
  214. margin-top: 50rpx;
  215. width: 750rpx;
  216. .iphoneNum-box {
  217. /* 自动布局 */
  218. margin: 0 auto;
  219. height: 114rpx;
  220. display: flex;
  221. flex-direction: row;
  222. align-items: center;
  223. gap: 32rpx;
  224. border-bottom: 2rpx solid #E6E6E8;
  225. width: 690rpx;
  226. color: #222229;
  227. .labels {
  228. font-size: 32rpx;
  229. font-weight: normal;
  230. line-height: 48rpx;
  231. }
  232. }
  233. .ReadingAgreement {
  234. width: 710rpx;
  235. margin: 0 auto;
  236. margin-top: 33rpx;
  237. gap: 32rpx;
  238. display: flex;
  239. align-items: center;
  240. font-size: 24rpx;
  241. .Agreement {
  242. margin-left: -15rpx;
  243. }
  244. }
  245. }
  246. .problem {
  247. margin: 0 auto;
  248. margin-top: 30rpx;
  249. width: 654rpx;
  250. display: flex;
  251. justify-content: space-between;
  252. font-size: 24rpx;
  253. font-weight: 350;
  254. line-height: 32rpx;
  255. color: #878788;
  256. }
  257. .getcode {
  258. position: absolute;
  259. right: 30rpx;
  260. font-size: 32rpx;
  261. font-weight: normal;
  262. line-height: 48rpx;
  263. text-align: right;
  264. color: #CE2601;
  265. }
  266. .awaitCode {
  267. position: absolute;
  268. right: 30rpx;
  269. font-size: 32rpx;
  270. font-weight: normal;
  271. line-height: 48rpx;
  272. text-align: right;
  273. color: #888889;
  274. }
  275. }
  276. </style>