classfiy.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. <script setup lang="ts">
  2. import type { LoadMoreState } from 'wot-design-uni/components/wd-loadmore/types'
  3. import selectSku from '../../components/select-sku/index.vue'
  4. import { StaticUrl } from '@/config'
  5. import router from '@/router'
  6. const props = defineProps<{ categoryList: Api.xsbCategories[], hotText: Api.xsbSearchTerm[] }>()
  7. const { statusBarHeight, MenuButtonHeight } = storeToRefs(useSysStore())
  8. const { topNavActive, leftActive, SelectShopInfo } = storeToRefs(useSysXsbStore())
  9. const { userInfo, token } = storeToRefs(useUserStore())
  10. const { getTotalNum } = storeToRefs(useSmqjhCartStore())
  11. const classfiylist = computed(() => props.categoryList)
  12. const sortClassBtn = ref(1)
  13. const show = ref(false)
  14. const cartList = ref<Api.xsbCategoriesCartList[]>([])
  15. const cartPopup = ref(false)
  16. const totalProduct = ref<Api.shoppingCartOrderConfirm>()
  17. const priceDetailPopup = ref(false)
  18. const cartIds = computed(() => cartList.value.filter(it => it.isDelete !== '1' && it.shopSkuStocks !== '0').map(it => it.id))
  19. // 勾选状态:只计算勾选商品的价格
  20. const selectedIds = ref<number[]>([])
  21. const isAllSelected = computed(() => cartIds.value.length > 0 && cartIds.value.every(id => selectedIds.value.includes(id)))
  22. const selectedCount = computed(() => selectedIds.value.length)
  23. function toggleSelectAll() {
  24. if (isAllSelected.value) {
  25. selectedIds.value = []
  26. }
  27. else {
  28. selectedIds.value = [...cartIds.value]
  29. }
  30. getGoodsPrice()
  31. }
  32. async function handleClearCart() {
  33. useGlobalMessage().confirm({
  34. title: '提示',
  35. msg: '确认清空购物车?',
  36. success: async () => {
  37. uni.showLoading({ mask: true })
  38. try {
  39. const ids = cartList.value.map(it => it.id).join(',')
  40. if (ids) {
  41. await Apis.common.deleteShoppingCart({ pathParams: { ids } })
  42. }
  43. cartPopup.value = false
  44. selectedIds.value = []
  45. totalProduct.value = undefined
  46. useSmqjhCartStore().getCartList('XSB')
  47. await getCartCategorList()
  48. setProductNum()
  49. }
  50. finally {
  51. uni.hideLoading()
  52. }
  53. },
  54. })
  55. }
  56. const showball = ref(false)
  57. const _this = getCurrentInstance()
  58. const selectGoods = ref(false)
  59. // 多规格商品skuid
  60. const selectSkuId = ref(0)
  61. const SelectGoodsNum = ref(1)
  62. const goodsInTo = ref()
  63. const goodsInfo = ref<Api.xsbCategoryProductList | Api.xsbProductDetail | undefined>()
  64. const isTopLoading = ref(false)
  65. const basllObj = ref({
  66. left: 0,
  67. top: 0,
  68. x: -402,
  69. y: 773,
  70. })
  71. const x = computed(() => `${basllObj.value.x}px`)
  72. const y = computed(() => `${basllObj.value.y}px`)
  73. const left = computed(() => `${basllObj.value.left}px`)
  74. const top = computed(() => `${basllObj.value.top}px`)
  75. const productList = ref<Api.xsbCategoryProductList[]>([])
  76. const topScrollView = ref()
  77. const scrollTop = ref<number | undefined>(0)
  78. const goodsLoading = ref<LoadMoreState>()
  79. const navHeight = computed(() => {
  80. return (`${Number(MenuButtonHeight.value) + Number(statusBarHeight.value)}px`)
  81. })
  82. function handleTopNavChange(item: Api.xsbCategoriesChildren) {
  83. topNavActive.value = item.code
  84. if (!item.children)
  85. return
  86. goodsLoading.value = 'loading'
  87. leftActive.value = item.children[0].code
  88. show.value = false
  89. topScrollView.value = null
  90. nextTick(() => {
  91. topScrollView.value = item.code
  92. })
  93. getProductList()
  94. }
  95. const categories = computed(() => {
  96. return classfiylist.value.find(it => it.code === topNavActive.value)?.children || []
  97. })
  98. const categoriesId = computed(() => {
  99. return categories.value.find(it => it.code === leftActive.value)?.id
  100. })
  101. async function getCartCategorList() {
  102. return new Promise((resolve, reject) => {
  103. Apis.xsb.myShoppingCartCategory({
  104. data: {
  105. businessType: 'XSB',
  106. channelId: unref(userInfo).channelId,
  107. shopId: unref(SelectShopInfo).shopId,
  108. },
  109. }).then((res) => {
  110. cartList.value = res.data
  111. console.log(cartList.value, '===================')
  112. resolve(res)
  113. }).catch((err) => {
  114. reject(err)
  115. })
  116. })
  117. }
  118. function handleChange({ value }: { value: string }) {
  119. leftActive.value = value
  120. getProductList()
  121. }
  122. function handleLeftChange(item: Api.xsbCategories) {
  123. goodsLoading.value = 'loading'
  124. handleChange({ value: item.code })
  125. }
  126. async function getProductList() {
  127. const res = await Apis.xsb.getCategoryProductList({
  128. data: {
  129. categoryId: Number(categoriesId.value),
  130. shopId: Number(SelectShopInfo.value?.shopId) || 1,
  131. channelId: unref(userInfo).channelId || 1,
  132. },
  133. })
  134. productList.value = res.data
  135. if (!res.data.length) {
  136. scrollTop.value = undefined
  137. nextTick(() => {
  138. scrollTop.value = 0
  139. })
  140. }
  141. if (!isTopLoading.value) {
  142. scrollTop.value = undefined
  143. nextTick(() => {
  144. scrollTop.value = 0
  145. })
  146. }
  147. else {
  148. goodsInTo.value = null
  149. nextTick(() => {
  150. goodsInTo.value = res.data.length > 4 ? res.data[res.data.length - 4].prodId : null
  151. })
  152. }
  153. goodsLoading.value = 'finished'
  154. isTopLoading.value = false
  155. setProductNum()
  156. }
  157. function handlScrollBottom() {
  158. goodsLoading.value = 'loading'
  159. const index = categories?.value.findIndex(it => it.code === leftActive.value)
  160. console.log(index, '-================')
  161. if (index + 1 === categories.value.length) {
  162. goodsLoading.value = 'finished'
  163. return
  164. }
  165. if (index !== -1) {
  166. handleChange({ value: categories.value[index + 1].code })
  167. }
  168. }
  169. function handleSrollTop() {
  170. isTopLoading.value = true
  171. const index = categories?.value.findIndex(it => it.code === leftActive.value)
  172. if (index !== -1) {
  173. if (index === 0) {
  174. nextTick(() => isTopLoading.value = false)
  175. }
  176. else {
  177. handleChange({ value: categories.value[index - 1].code })
  178. }
  179. }
  180. }
  181. async function handleAddCart(event: WechatMiniprogram.TouchEvent, item: Api.xsbCategoryProductList) {
  182. await useUserStore().checkLogin()
  183. if (item.skuList.length > 1) {
  184. goodsInfo.value = item
  185. selectGoods.value = true
  186. return
  187. }
  188. if (showball.value)
  189. return
  190. basllObj.value.left = event.detail.x
  191. basllObj.value.top = event.detail.y
  192. showball.value = true
  193. setTimeout(() => {
  194. showball.value = false
  195. }, 500)
  196. const skuId = item.skuList[0].skuId
  197. await useSmqjhCartStore().addCart(skuId, 1, Number(item.shopId), 'XSB')
  198. await getCartCategorList()
  199. setProductNum()
  200. // 自动选中刚加入的商品,并重新计算价格
  201. const cartItem = cartList.value.find(it => it.skuId === skuId && it.isDelete !== '1' && it.shopSkuStocks !== '0')
  202. if (cartItem && !selectedIds.value.includes(cartItem.id)) {
  203. selectedIds.value.push(cartItem.id)
  204. }
  205. await getGoodsPrice()
  206. }
  207. async function handleSubCart(event: WechatMiniprogram.TouchEvent, item: Api.xsbCategoryProductList) {
  208. const skuId = item.skuList[0].skuId
  209. if (item.num === 1) {
  210. useGlobalMessage().confirm({
  211. msg: '是否删除该商品?',
  212. success: async () => {
  213. // 删除前记录 cartId,用于从 selectedIds 中移除
  214. const cartItem = cartList.value.find(it => it.skuId === skuId)
  215. await useSmqjhCartStore().addCart(skuId, -1, Number(item.shopId), 'XSB')
  216. await getCartCategorList()
  217. setProductNum()
  218. if (cartItem) {
  219. selectedIds.value = selectedIds.value.filter(id => id !== cartItem.id)
  220. }
  221. await getGoodsPrice()
  222. },
  223. })
  224. }
  225. else {
  226. await useSmqjhCartStore().addCart(skuId, -1, Number(item.shopId), 'XSB')
  227. await getCartCategorList()
  228. setProductNum()
  229. await getGoodsPrice()
  230. }
  231. }
  232. onMounted(async () => {
  233. if (!topNavActive.value || !leftActive.value) {
  234. const firstWithChildren = props.categoryList?.find(it => it.children && it.children.length > 0)
  235. if (firstWithChildren) {
  236. topNavActive.value = firstWithChildren.code
  237. leftActive.value = firstWithChildren.children![0].code
  238. }
  239. }
  240. goodsLoading.value = 'loading'
  241. if (leftActive.value) {
  242. handleChange({ value: leftActive.value })
  243. }
  244. else {
  245. goodsLoading.value = 'finished'
  246. }
  247. if (topNavActive.value) {
  248. topScrollView.value = null
  249. nextTick(() => {
  250. topScrollView.value = topNavActive.value
  251. })
  252. }
  253. console.log(topNavActive.value, ' ==', props.categoryList)
  254. getCartBox()
  255. if (token.value) {
  256. await getCartCategorList()
  257. }
  258. })
  259. function getCartBox() {
  260. const query = uni.createSelectorQuery().in(_this)
  261. query.select('.cart-box').boundingClientRect()
  262. query.exec((res) => {
  263. basllObj.value.y = res[0].top
  264. uni.getSystemInfo().then((info) => {
  265. basllObj.value.x = -(info.screenWidth - res[0].left - 15)
  266. console.log(basllObj.value.x, basllObj.value.y)
  267. })
  268. })
  269. }
  270. function handleGo(item: Api.xsbCategoryProductList) {
  271. if (!item.prodId) {
  272. useGlobalToast().show('后端数据异常!')
  273. return
  274. }
  275. router.push({ name: 'xsb-goods', params: { id: String(item.prodId) } })
  276. }
  277. async function getGoodsPrice() {
  278. if (selectedIds.value.length) {
  279. const res = await useSmqjhCartStore().getCartAddGoodsPrice(selectedIds.value.join(','))
  280. totalProduct.value = res
  281. }
  282. else {
  283. totalProduct.value = undefined
  284. }
  285. }
  286. async function handleSub(item: Api.xsbCategoriesCartList) {
  287. if (item.num === 1) {
  288. useGlobalMessage().confirm({
  289. msg: '是否删除该商品?',
  290. success: async () => {
  291. cartPopup.value = false
  292. await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
  293. await getCartCategorList()
  294. setProductNum()
  295. totalProduct.value = undefined
  296. },
  297. })
  298. }
  299. else {
  300. await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
  301. getGoodsPrice()
  302. await getCartCategorList()
  303. setProductNum()
  304. }
  305. }
  306. async function handleAdd(item: Api.xsbCategoriesCartList) {
  307. await useSmqjhCartStore().addCart(item.skuId, 1, item.shopId, 'XSB')
  308. getGoodsPrice()
  309. await getCartCategorList()
  310. setProductNum()
  311. }
  312. onUnmounted(() => {
  313. console.log('组件卸载')
  314. topNavActive.value = ''
  315. leftActive.value = ''
  316. })
  317. async function handleDelCartGoods(item: Api.xsbCategoriesCartList) {
  318. const msg = item.isDelete ? '商品已被商家删除,是否确认删除该门店下的商品?' : '门店商品库存不足,是否删除该门店下的商品?'
  319. useGlobalMessage().confirm({
  320. title: '提示',
  321. msg,
  322. success: async () => {
  323. uni.showLoading({ mask: true })
  324. try {
  325. await Apis.common.deleteShoppingCart({
  326. pathParams: {
  327. ids: String(item.id),
  328. },
  329. })
  330. await getCartCategorList()
  331. uni.hideLoading()
  332. }
  333. catch {
  334. uni.hideLoading()
  335. }
  336. },
  337. })
  338. }
  339. function setProductNum() {
  340. if (!cartList.value.length) {
  341. productList.value = productList.value.map((goods) => {
  342. goods.num = undefined
  343. return goods
  344. })
  345. return
  346. }
  347. cartList.value.forEach((it) => {
  348. productList.value = productList.value.map((goods) => {
  349. if (goods.skuList.length && goods.skuList[0].skuId === it.skuId) {
  350. goods.num = it.num
  351. }
  352. return goods
  353. })
  354. })
  355. }
  356. async function handleSkuAddCart() {
  357. await useSmqjhCartStore().addCart(unref(selectSkuId), unref(SelectGoodsNum), Number(goodsInfo.value?.shopId), 'XSB')
  358. getGoodsPrice()
  359. await getCartCategorList()
  360. }
  361. function handlePay() {
  362. if (!totalProduct.value) {
  363. useGlobalToast().show('请选择商品')
  364. return
  365. }
  366. const shopSkuStock = totalProduct.value.skuList.filter(it => it.num > Number(it.shopSkuStocks))
  367. if (shopSkuStock.length) {
  368. useGlobalToast().show({ msg: `${shopSkuStock[0].skuName}库存不足` })
  369. return
  370. }
  371. router.push({ name: 'xsb-confirmOrder', params: { data: JSON.stringify(totalProduct.value) } })
  372. }
  373. </script>
  374. <script lang="ts">
  375. export default {
  376. options: {
  377. styleIsolation: 'shared',
  378. },
  379. }
  380. </script>
  381. <template>
  382. <view class="page-xsb">
  383. <wd-navbar
  384. title="" custom-style="background-color:#F4FFD1" :bordered="false" :z-index="9999" safe-area-inset-top
  385. fixed
  386. >
  387. <template #left>
  388. <view class="flex items-center" @click="router.push({ name: 'xsb-search' })">
  389. <view
  390. class="h60rpx w-474rpx flex items-center justify-between border-2rpx border-[var(--them-color)] rounded-40rpx border-solid bg-white pr6rpx"
  391. >
  392. <view class="flex items-center pb14rpx pl24rpx pt16rpx">
  393. <wd-icon name="search" size="14" color="#ccc" />
  394. <view class="search ml12rpx h-full w-full overflow-hidden">
  395. <wd-notice-bar
  396. :text="hotText.map((it) => it.searchName)" custom-class="notice-bar" color="#ccc"
  397. background-color="#fff" direction="vertical"
  398. />
  399. </view>
  400. </view>
  401. <view class="flex items-center pr28rpx">
  402. <wd-divider vertical />
  403. <view class="ml6rpx text-28rpx text-[var(--them-color)] font-semibold">
  404. 搜索
  405. </view>
  406. </view>
  407. </view>
  408. </view>
  409. </template>
  410. </wd-navbar>
  411. <view
  412. class="h162rpx flex items-center justify-between bg-#F4FFD1 pl24rpx"
  413. :style="{ paddingTop: `${(Number(statusBarHeight) || 44) + MenuButtonHeight + 12}px` }"
  414. >
  415. <scroll-view
  416. :scroll-into-view-offset="-150" scroll-x enable-passive scroll-with-animation
  417. class="scrollx w-90% flex-shrink-0 whitespace-nowrap" :scroll-into-view="`id${topScrollView}`"
  418. >
  419. <view class="flex items-end pb10rpx">
  420. <view
  421. v-for="item in classfiylist" :id="`id${item.code}`" :key="item.code"
  422. class="mr24rpx flex flex-col items-center justify-center" @click="handleTopNavChange(item)"
  423. >
  424. <view class="relative">
  425. <view
  426. class="box-border"
  427. :class="[topNavActive == item.code ? 'overflow-hidden border-solid border-[var(--them-color)] border-2rpx rounded-26rpx h84rpx w-84rpx' : 'h72rpx w-72rpx']"
  428. >
  429. <image :src="item.icon" class="h-full w-full" />
  430. </view>
  431. <view
  432. v-if="!item.children"
  433. class="absolute left-0 top-0 h-full w-full flex items-center justify-center rounded-26rpx bg-[rgba(0,0,0,0.6)] text-16rpx text-white"
  434. >
  435. 敬请期待
  436. </view>
  437. </view>
  438. <view
  439. class="mt16rpx text-22rpx"
  440. :class="[topNavActive == item.code ? 'bg-[var(--them-color)] rounded-18rpx px-8rpx py2rpx text-white text-24rpx' : '']"
  441. >
  442. {{ item.name }}
  443. </view>
  444. </view>
  445. </view>
  446. </scroll-view>
  447. <view
  448. class="right-nav box-border h144rpx w64rpx flex flex-shrink-0 flex-col items-center justify-center px20rpx text-24rpx font-semibold"
  449. @click="show = true"
  450. >
  451. 展开
  452. <image :src="`${StaticUrl}/xia.png`" class="mt20rpx h20rpx w20rpx" />
  453. </view>
  454. <wd-popup v-model="show" :z-index="9998" position="top" custom-style="border-radius:32rpx;">
  455. <view
  456. class="box-border bg-#F4FFD1 p24rpx"
  457. :style="{ paddingTop: `${(Number(statusBarHeight) || 44) + MenuButtonHeight + 12}px` }"
  458. >
  459. <view class="mb24rpx mt24rpx text-28rpx font-semibold">
  460. 全部一级分类
  461. </view>
  462. <view class="h400rpx overflow-y-scroll">
  463. <view class="grid grid-cols-5 box-border gap-x-24rpx gap-y-24rpx">
  464. <view
  465. v-for="item in classfiylist" :key="item.code"
  466. class="box-border h150rpx w114rpx flex flex-col items-center justify-center"
  467. @click="handleTopNavChange(item)"
  468. >
  469. <image
  470. :src="item.icon"
  471. :class="[topNavActive == item.code ? 'overflow-hidden border-solid border-[var(--them-color)] border-2rpx rounded-26rpx h88rpx w-88rpx' : 'h76rpx w-76rpx']"
  472. />
  473. <view
  474. class="mt16rpx whitespace-nowrap text-nowrap text-22rpx"
  475. :class="[topNavActive == item.code ? 'bg-[var(--them-color)] rounded-18rpx px-8rpx py2rpx text-white text-24rpx' : '']"
  476. >
  477. {{ item.name }}
  478. </view>
  479. </view>
  480. </view>
  481. </view>
  482. <view class="mt24rpx w-full flex items-center justify-center" @click="show = false">
  483. <view class="mr8rpx text-24rpx">
  484. 点击收起
  485. </view>
  486. <wd-icon name="arrow-down" size="18px" />
  487. </view>
  488. </view>
  489. </wd-popup>
  490. </view>
  491. <view class="wraper">
  492. <scroll-view
  493. class="w200rpx" :scroll-into-view-offset="-150" enable-passive scroll-with-animation scroll-y
  494. :scroll-into-view="`id${leftActive}`"
  495. >
  496. <view
  497. v-for="item in categories" :id="`id${item.code}`" :key="item.code"
  498. :class="[item.code == leftActive ? 'bg-white' : '']"
  499. class="relative h100rpx flex items-center justify-center whitespace-nowrap text-28rpx"
  500. @click="handleLeftChange(item)"
  501. >
  502. {{ item.name }}
  503. <view
  504. v-if="item.code == leftActive"
  505. class="absolute left-0 top-20rpx h60rpx w8rpx rounded-4rpx bg-[var(--them-color)]"
  506. />
  507. </view>
  508. </scroll-view>
  509. <view class="content">
  510. <view class="p20rpx">
  511. <image :src="`${StaticUrl}/class.png`" class="h144rpx w-full" @click="useGlobalToast().show('敬请期待 !')" />
  512. <view class="my20rpx flex items-center justify-end rounded-16rpx bg-#F6F6F6 px20rpx py8rpx">
  513. <view class="mr40rpx text-24rpx">
  514. 销量
  515. </view>
  516. <wd-sort-button v-model="sortClassBtn" :line="false" title="价格" />
  517. </view>
  518. </view>
  519. <view class="relative">
  520. <scroll-view
  521. :lower-threshold="100" :refresher-triggered="isTopLoading" :scroll-top="scrollTop"
  522. :style="{ height: `calc(100vh - ${navHeight} - 700rpx)` }" enable-passive scroll-y scroll-anchoring
  523. refresher-enabled :throttle="false" :scroll-into-view="`class${goodsInTo}`"
  524. @refresherrefresh="handleSrollTop" @scrolltolower="handlScrollBottom"
  525. >
  526. <view v-if="productList.length" class="p20rpx">
  527. <view v-for="item in productList" :id="`class${item.prodId}`" :key="item.id" class="relative">
  528. <view class="flex" @click="handleGo(item)">
  529. <view class="relative mr20rpx h172rpx w172rpx flex-shrink-0 overflow-hidden rounded-16rpx bg-#F6F6F6">
  530. <image :src="item.pic" lazy-load class="h-full w-full" />
  531. <image :src="`${StaticUrl}/xsb-shui-class.png`" class="absolute left-0 top-0 h-full w-full" />
  532. </view>
  533. <view class="flex-1">
  534. <view class="text-left text-28rpx font-semibold">
  535. <!-- <view v-for="i in 2" :key="i" class="mr5px inline-block">
  536. <wd-tag type="primary">
  537. 新品{{ i }}
  538. </wd-tag>
  539. </view> -->
  540. {{ item.prodName }}
  541. </view>
  542. <view class="text-22rpx text-#AAAAAA">
  543. <view class="mt10rpx flex items-center">
  544. <view>{{ item.spec }}</view>
  545. </view>
  546. <view class="mt6rpx">
  547. 已售 {{ item.soldNum }}+
  548. </view>
  549. </view>
  550. <view class="flex items-center justify-between">
  551. <view class="text-#FF4D3A font-semibold">
  552. <text class="text-24rpx">
  553. </text> <text class="text-36rpx">
  554. {{ item.channelProdPrice }}
  555. </text>
  556. </view>
  557. <view v-if="!item.num">
  558. <view v-if="item.spuStock" @click.stop="handleAddCart($event, item)">
  559. <image :src="`${StaticUrl}/cart-yes.png`" class="h52rpx w52rpx" />
  560. </view>
  561. <view v-else>
  562. <image :src="`${StaticUrl}/cart-no.png`" class="h52rpx w52rpx" />
  563. </view>
  564. </view>
  565. <view v-else>
  566. <view class="flex items-center">
  567. <image
  568. :src="` ${StaticUrl}/sub-cart.png`" class="h44rpx w44rpx"
  569. @click.stop="handleSubCart($event, item)"
  570. />
  571. <view
  572. class="box-border h44rpx w84rpx flex items-center justify-center border border-#F0F0F0 border-solid text-24rpx text-#AAAAAA"
  573. >
  574. {{ item.num }}
  575. </view>
  576. <image
  577. :src="` ${StaticUrl}/add-cart.png`" class="h44rpx w44rpx"
  578. @click.stop="handleAddCart($event, item)"
  579. />
  580. </view>
  581. </view>
  582. </view>
  583. </view>
  584. </view>
  585. <view class="line">
  586. <wd-divider color="#F0F0F0" />
  587. </view>
  588. <view
  589. v-if="!item.spuStock"
  590. class="absolute left-0 top-0 z-1 h-full w-full flex items-center bg-[rgba(255,255,255,.6)]"
  591. >
  592. <view class="h172rpx w172rpx flex items-center justify-center">
  593. <view
  594. class="h36rpx w112rpx flex items-center justify-center rounded-16rpx bg-[rgba(0,0,0,.6)] text-28rpx text-white"
  595. >
  596. 已售罄
  597. </view>
  598. </view>
  599. </view>
  600. <view
  601. v-if="!item.skuList.some((it) => it.saleStatus)"
  602. class="absolute left-0 top-0 z-1 h-full w-full flex items-center bg-[rgba(255,255,255,.6)]"
  603. >
  604. <view class="h172rpx w172rpx flex items-center justify-center">
  605. <view
  606. class="h36rpx w112rpx flex items-center justify-center rounded-16rpx bg-[rgba(0,0,0,.6)] text-28rpx text-white"
  607. >
  608. 不可售
  609. </view>
  610. </view>
  611. </view>
  612. </view>
  613. </view>
  614. <StatusTip v-else tip="暂无内容" />
  615. <view v-if="goodsLoading == 'finished' || isTopLoading" class="h-40vh" />
  616. </scroll-view>
  617. <view
  618. v-if="goodsLoading == 'loading' || isTopLoading"
  619. class="absolute left-0 top-0 z-10 h-full w-full flex items-center justify-center bg-white"
  620. >
  621. <wd-loading color="#9ED605" :size="20" />
  622. </view>
  623. </view>
  624. </view>
  625. </view>
  626. <view
  627. class="fixedShadow fixed bottom-60rpx left-0 z-100 box-border w-full flex items-center justify-between rounded-t-16rpx bg-white px24rpx pb60rpx pt10rpx"
  628. >
  629. <view class="ios w-full flex items-center justify-between">
  630. <view class="flex items-center">
  631. <view class="flex items-center" @click="cartPopup = true, priceDetailPopup = false">
  632. <wd-badge :model-value="getTotalNum" :top="20">
  633. <image v-if="getTotalNum" :src="`${StaticUrl}/cart-lanzi.png`" class="cart-box h100rpx w100rpx" />
  634. <image v-else :src="`${StaticUrl}/xsb-cart-disabled.png`" class="cart-box h100rpx w100rpx" />
  635. </wd-badge>
  636. </view>
  637. <view v-if="getTotalNum" class="ml40rpx">
  638. <view class="flex items-center">
  639. <view class="font-semibold">
  640. ¥ {{ totalProduct?.amount || 0 }}
  641. </view>
  642. <view v-if="totalProduct?.coupon" class="ml10rpx text-24rpx text-#FF4A39">
  643. 共减¥{{ totalProduct?.coupon }}
  644. </view>
  645. <view
  646. v-if="totalProduct?.amount" class="ml10rpx flex items-center text-24rpx text-gray"
  647. @click="priceDetailPopup = !priceDetailPopup, cartPopup = false"
  648. >
  649. 明细 <view :class="[priceDetailPopup ? 'rotate-180' : '']" class="flex items-center">
  650. <wd-icon name="arrow-up" size="24rpx" color="#aaa" />
  651. </view>
  652. </view>
  653. </view>
  654. <view class="mt10rpx text-24rpx text-gray">
  655. 配送费:¥{{ totalProduct?.transfee || 0 }}
  656. </view>
  657. </view>
  658. <view v-else class="ml40rpx text-24rpx text-#AAA">
  659. 您还没有添加商品
  660. </view>
  661. </view>
  662. <view class="flex items-center">
  663. <!-- <view class="flex items-center font-semibold">
  664. <view class="text-22rpx text-#222">
  665. 总计:
  666. </view>
  667. <view class="flex items-baseline text-24rpx text-#FF4A39">
  668. <text class="text-36rpx">
  669. {{ totalProduct?.price || '0.00' }}
  670. </text>
  671. </view>
  672. </view> -->
  673. <view class="ml20rpx w160rpx">
  674. <wd-button block size="large" :disabled="!getTotalNum" :type="getTotalNum ? 'primary' : 'info'" @click="handlePay">
  675. 结算
  676. </wd-button>
  677. </view>
  678. </view>
  679. </view>
  680. </view>
  681. <!-- 价格明细弹窗 -->
  682. <Zpopup v-model="priceDetailPopup" :zindex="10" bg="#fff">
  683. <view class="ios box-border w-full px-40rpx pb-60rpx pt-36rpx">
  684. <view class="mb-40rpx text-center text-32rpx font-semibold">
  685. 价格明细
  686. </view>
  687. <!-- 商品合计 -->
  688. <view class="flex items-center justify-between py-20rpx">
  689. <view class="text-30rpx font-semibold">
  690. 商品合计
  691. </view>
  692. <view class="text-30rpx font-semibold">
  693. ¥{{ totalProduct?.amount }}
  694. </view>
  695. </view>
  696. <!-- 商品总价 -->
  697. <view class="flex items-center justify-between py-20rpx">
  698. <view class="text-28rpx text-#333">
  699. 商品总价
  700. </view>
  701. <view class="text-28rpx text-#333">
  702. ¥{{ totalProduct?.price }}
  703. </view>
  704. </view>
  705. <!-- 下单用券共减 -->
  706. <template v-if="totalProduct?.coupon">
  707. <view class="flex items-center justify-between py-20rpx">
  708. <view class="text-28rpx text-#333">
  709. 下单用券共减
  710. </view>
  711. <view class="text-28rpx text-#FF4A39 font-semibold">
  712. -¥{{ totalProduct?.coupon }}
  713. </view>
  714. </view>
  715. <!-- 券名称子行 -->
  716. <view v-if="totalProduct?.activityName || totalProduct?.couponName" class="flex items-center justify-between pb-20rpx">
  717. <view class="text-24rpx text-#AAAAAA">
  718. {{ totalProduct?.activityName || totalProduct?.couponName }}
  719. </view>
  720. <view class="text-24rpx text-#AAAAAA">
  721. -¥{{ totalProduct?.coupon }}
  722. </view>
  723. </view>
  724. </template>
  725. <!-- 配送费 -->
  726. <view class="flex items-center justify-between py-20rpx">
  727. <view class="text-28rpx text-#333">
  728. 配送费
  729. </view>
  730. <view class="text-28rpx text-#333">
  731. ¥{{ totalProduct?.transfee }}
  732. </view>
  733. </view>
  734. </view>
  735. <view class="h200rpx" />
  736. </Zpopup>
  737. <Zpopup v-model="cartPopup" :zindex="99">
  738. <view class="ios overflow-hidden">
  739. <!-- 头部:全选 + 已选件数 + 清空购物车 -->
  740. <view class="flex items-center justify-between border-b border-[#F5F5F5] border-solid px-24rpx py-24rpx">
  741. <view class="flex items-center">
  742. <wd-checkbox :model-value="isAllSelected" size="large" @change="toggleSelectAll">
  743. 全选
  744. </wd-checkbox>
  745. <text class="ml-16rpx text-24rpx text-[#AAAAAA]">
  746. 已选{{ selectedCount }}件
  747. </text>
  748. </view>
  749. <view class="text-24rpx text-[#AAAAAA]" @click="handleClearCart">
  750. <wd-icon name="delete" size="24rpx" /> 清空购物车
  751. </view>
  752. </view>
  753. <!-- 商品列表 -->
  754. <view class="h-700rpx overflow-y-scroll">
  755. <view class="p-24rpx">
  756. <wd-checkbox-group v-model="selectedIds" custom-class="custom-checkbox-group" @change="getGoodsPrice">
  757. <view
  758. v-for="item in cartList" :key="item.id"
  759. class="relative mt-20rpx box-border flex items-center overflow-hidden rounded-16rpx bg-white p-24rpx"
  760. >
  761. <!-- 复选框 -->
  762. <wd-checkbox
  763. v-if="item.shopSkuStocks !== '0' && item.isDelete !== '1'" :model-value="item.id"
  764. size="large" class="mr-16rpx flex-shrink-0"
  765. />
  766. <view v-else class="mr-16rpx h-40rpx w-40rpx flex-shrink-0" />
  767. <view class="flex flex-1">
  768. <image
  769. :src="item.pic" class="h206rpx w200rpx flex-shrink-0"
  770. @click.stop="router.push({ name: 'xsb-goods', params: { id: String(item.prodId) } })"
  771. />
  772. <view class="ml20rpx flex-1">
  773. <view class="text-left text-28rpx font-semibold">
  774. {{ item.skuName }}
  775. </view>
  776. <view class="mt14rpx text-24rpx text-#AAAAAA">
  777. 规格:{{ item.spec }}
  778. </view>
  779. <view class="mt14rpx flex items-center justify-between">
  780. <view class="text-36rpx text-#FF4A39 font-semibold">
  781. ¥{{ item.price }}
  782. </view>
  783. <view v-if="item.shopSkuStocks !== '0' && item.isDelete !== '1'" class="flex items-center">
  784. <image
  785. :src="` ${StaticUrl}/sub-cart.png`" class="h44rpx w44rpx"
  786. @click.stop="handleSub(item)"
  787. />
  788. <view
  789. class="box-border h44rpx w84rpx flex items-center justify-center border border-#F0F0F0 border-solid text-24rpx text-#AAAAAA"
  790. >
  791. {{ item.num }}
  792. </view>
  793. <image
  794. :src="` ${StaticUrl}/add-cart.png`" class="h44rpx w44rpx"
  795. @click.stop="handleAdd(item)"
  796. />
  797. </view>
  798. </view>
  799. </view>
  800. </view>
  801. <view
  802. v-if="item.shopSkuStocks == '0' || item.isDelete == '1'"
  803. class="absolute left-0 top-0 z-1 h-full w-full bg-[rgba(255,255,255,.6)]"
  804. >
  805. <view class="relative w-full flex items-center justify-center">
  806. <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
  807. {{ item.shopSkuStocks == '0' ? '商品已售罄' : '商品已删除' }}
  808. </view>
  809. <view class="absolute bottom-20rpx right-20rpx">
  810. <wd-button @click="handleDelCartGoods(item)">
  811. 删除商品
  812. </wd-button>
  813. </view>
  814. </view>
  815. </view>
  816. </view>
  817. </wd-checkbox-group>
  818. </view>
  819. <StatusTip v-if="!cartList.length" tip="暂无内容" />
  820. <view class="h320rpx" />
  821. </view>
  822. </view>
  823. </Zpopup>
  824. <selectSku
  825. v-model:show="selectGoods" v-model:sku-id="selectSkuId" v-model:select-goods-num="SelectGoodsNum"
  826. :goods-info="goodsInfo!"
  827. >
  828. <template #footer>
  829. <view class="box-border w-full flex items-center justify-between py20rpx">
  830. <view class="w-48%">
  831. <wd-button plain hairline block @click="selectGoods = false">
  832. 取消
  833. </wd-button>
  834. </view>
  835. <view class="w-48%">
  836. <wd-button block @click="handleSkuAddCart">
  837. 加入购物车
  838. </wd-button>
  839. </view>
  840. </view>
  841. </template>
  842. </selectSku>
  843. <view v-if="showball" class="ball">
  844. <image :src="`${StaticUrl}/cart-yes.png`" class="cart-img h52rpx w52rpx" />
  845. </view>
  846. </view>
  847. </template>
  848. <style scoped lang="scss">
  849. .right-nav {
  850. background: linear-gradient(180deg, #FAFFEC 0%, #F6FFDE 11%, #E7FFA5 100%);
  851. box-shadow: -10rpx 0rpx 12rpx 2rpx rgba(0, 0, 0, 0.07);
  852. }
  853. .fixedShadow {
  854. box-shadow: 0rpx -6rpx 12rpx 2rpx rgba(0, 0, 0, 0.05);
  855. }
  856. .wraper {
  857. display: flex;
  858. height: calc(100vh - var(--window-top) - v-bind(navHeight) - 390rpx - var(--window-bottom));
  859. height: calc(100vh - var(--window-top) - constant(safe-area-inset-bottom) - v-bind(navHeight) - 390rpx - var(--window-bottom));
  860. height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom) - v-bind(navHeight) - 390rpx - var(--window-bottom));
  861. }
  862. .content {
  863. flex: 1;
  864. background: #fff;
  865. }
  866. @keyframes moveX {
  867. to {
  868. transform: translateX(v-bind(x));
  869. }
  870. }
  871. @keyframes moveY {
  872. to {
  873. transform: translateY(v-bind(y));
  874. }
  875. }
  876. .ball {
  877. position: fixed;
  878. z-index: 80;
  879. left: v-bind(left);
  880. top: v-bind(top);
  881. animation: moveX .5s linear forwards;
  882. }
  883. .cart-img {
  884. animation: moveY .5s cubic-bezier(1, -1.26, 1, 1) forwards;
  885. }
  886. :deep(.wd-checkbox-group){
  887. background-color: transparent !important;
  888. }
  889. </style>