index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <script setup lang="ts">
  2. import selectSku from '../components/select-sku/index.vue'
  3. import { StaticUrl } from '@/config'
  4. import router from '@/router'
  5. const { statusBarHeight, MenuButtonHeight } = useSysStore()
  6. definePage({
  7. name: 'xsb-goods',
  8. islogin: false,
  9. style: {
  10. navigationStyle: 'custom',
  11. navigationBarTitleText: '星闪豹商品详情',
  12. },
  13. })
  14. const selectGoods = ref(false)
  15. const SelectGoodsNum = ref(1)
  16. const specId = ref()
  17. const { userInfo, token } = storeToRefs(useUserStore())
  18. const { SelectShopInfo } = storeToRefs(useSysXsbStore())
  19. const { getTotalNum } = storeToRefs(useSmqjhCartStore())
  20. // const goodsTab = ref(0)
  21. const current = ref<number>(0)
  22. const currentDetaile = ref(0)
  23. // const goodsTabList = ref([
  24. // { title: '相似商品', id: 0 },
  25. // { title: '经常一起买', id: 1 },
  26. // ])
  27. const goodsDetaileTabList = ref([
  28. { title: '商品', id: 0 },
  29. { title: '评价', id: 1 },
  30. { title: '详情', id: 2 },
  31. { title: '推荐', id: 3 },
  32. ])
  33. const goodsTabData = ref([])
  34. const isShowTab = ref(false)
  35. // const currentTabGoods = ref(0)
  36. const goodsId = ref()
  37. onLoad((option: any) => {
  38. goodsId.value = option.id
  39. getGoodsDetaile()
  40. })
  41. const goodsInfo = ref<Api.xsbProductDetail>()
  42. const isLoging = ref(false)
  43. const swiperList = computed(() => {
  44. if (goodsInfo.value) {
  45. return goodsInfo.value.imgs?.split(',')
  46. }
  47. return []
  48. })
  49. const goodsContent = computed(() => {
  50. if (goodsInfo.value?.content) {
  51. return goodsInfo.value.content.replace(
  52. /<img/gi,
  53. '<img style="max-width:100%;height:auto" ',
  54. )
  55. }
  56. return '暂无数据'
  57. })
  58. onMounted(() => {
  59. // goodsTabData.value = splitArrayToPages([{ id: 1, name: '商品' }, { id: 2, name: '商品' }, { id: 3, name: '商品' }, { id: 4, name: '商品' }, { id: 8, name: '商品' }, { id: 5, name: '商品' }, { id: 10, name: '商品' }, { id: 6, name: '商品' }, { id: 9, name: '商品' }, { id: 7, name: '商品' }, { id: 11, name: '商品' }])
  60. console.log(goodsTabData.value, 'goodsTabData')
  61. })
  62. // function splitArrayToPages<T>(arr: T[]): T[][] {
  63. // const PAGE_SIZE = 6
  64. // const MAX_PAGES = 3
  65. // const result: T[][] = []
  66. // for (let i = 0; i < Math.min(MAX_PAGES, Math.ceil(arr.length / PAGE_SIZE)); i++) {
  67. // const start = i * PAGE_SIZE
  68. // const end = start + PAGE_SIZE
  69. // result.push(arr.slice(start, end))
  70. // }
  71. // return result
  72. // }
  73. onPageScroll((e) => {
  74. if (e.scrollTop >= 315) {
  75. isShowTab.value = true
  76. }
  77. else {
  78. isShowTab.value = false
  79. }
  80. })
  81. function handleGoCurren(id: number) {
  82. currentDetaile.value = id
  83. uni.pageScrollTo({ selector: `.view-${id}` })
  84. }
  85. async function getGoodsDetaile() {
  86. const res = await Apis.xsb.getProductDetail({ data: { id: goodsId.value, shopId: Number(SelectShopInfo.value?.shopId) || 2, channelId: userInfo.value.channelId || 1 } })
  87. console.log(res, '请求')
  88. if (!res.data) {
  89. useGlobalToast().show('暂无该商品查看权限!')
  90. return
  91. }
  92. goodsInfo.value = res.data
  93. specId.value = res.data.skuList?.[0].skuId
  94. }
  95. async function handleConfimOrder() {
  96. if (Number(unref(goodsInfo)?.spuStock) < unref(SelectGoodsNum)) {
  97. useGlobalToast().show('库存不足,请调整购买数量')
  98. return
  99. }
  100. if (!token.value) {
  101. useGlobalToast().show('请先登录!')
  102. return
  103. }
  104. isLoging.value = true
  105. const res = await Apis.xsb.skuOrderConfirm({
  106. data: {
  107. skuId: specId.value,
  108. num: SelectGoodsNum.value,
  109. channelId: unref(userInfo).channelId,
  110. shopId: unref(goodsInfo)?.shopId,
  111. },
  112. })
  113. if (Number(res.data.sku?.shopSkuStocks) < unref(SelectGoodsNum)) {
  114. useGlobalToast().show('库存不足,请调整购买数量')
  115. isLoging.value = false
  116. return
  117. }
  118. router.push({
  119. name: 'xsb-confirmOrder',
  120. params: { data: JSON.stringify({ ...res.data, skuList: [{ ...res.data.sku, num: SelectGoodsNum.value }] }) },
  121. })
  122. isLoging.value = false
  123. }
  124. async function handleAddCart() {
  125. if (Number(unref(goodsInfo)?.spuStock) < unref(SelectGoodsNum)) {
  126. useGlobalToast().show('库存不足,请调整购买数量')
  127. return
  128. }
  129. isLoging.value = true
  130. try {
  131. await useSmqjhCartStore().addCart(specId.value, unref(SelectGoodsNum), unref(SelectShopInfo.value.shopId), 'XSB')
  132. selectGoods.value = false
  133. useGlobalToast().show('添加成功')
  134. isLoging.value = false
  135. }
  136. catch (error) {
  137. console.log(error)
  138. useGlobalToast().show(String(error))
  139. }
  140. }
  141. </script>
  142. <template>
  143. <page-meta :page-style="selectGoods ? 'overflow: hidden;' : '' " />
  144. <view class="page-xsb">
  145. <wd-navbar
  146. title="商品详情" :custom-style="`background-color:${isShowTab ? '#FFF !important' : 'transparent !important'}`" :bordered="false" :z-index="99"
  147. safe-area-inset-top left-arrow fixed @click-left="router.back()"
  148. />
  149. <template v-if="goodsInfo">
  150. <wd-swiper v-model:current="current" :list="swiperList" :autoplay="false" :height="375">
  151. <template #indicator="{ current: currentIndex, total }">
  152. <view class="custom-indicator absolute bottom-60rpx right-20rpx px26rpx">
  153. {{ currentIndex + 1 }}/{{ total }}
  154. </view>
  155. </template>
  156. </wd-swiper>
  157. <view class="view-0 header relative z-3 rounded-t-32rpx px24rpx pt24rpx -mt30rpx">
  158. <view class="flex items-center justify-between">
  159. <view class="flex items-end text-#FF4D3A font-semibold">
  160. <view class="text-24rpx">
  161. </view>
  162. <view class="text-36rpx line-height-[36rpx]">
  163. {{ goodsInfo?.channelProdPrice }}
  164. </view>
  165. </view>
  166. <!-- <view>
  167. <image class="h40rpx w40rpx" :src="`${StaticUrl}/collect-yes.png`" />
  168. </view> -->
  169. </view>
  170. </view>
  171. <view class="sticky left-0 z-99 box-border h84rpx w-full flex items-center justify-between bg-white px24rpx" :style="{ top: `${statusBarHeight + MenuButtonHeight}px`, opacity: isShowTab ? 1 : 0 }" :class="[isShowTab ? '' : '']">
  172. <view v-for="item in goodsDetaileTabList" :key="item.id" class="relative flex items-center text-32rpx font-semibold" @click="handleGoCurren(item.id)">
  173. {{ item.title }}
  174. <view v-show="currentDetaile == item.id" class="line absolute left-50% h12rpx w40rpx rounded-8rpx bg-[var(--them-color)] -bottom-15rpx -translate-x-50%" />
  175. </view>
  176. </view>
  177. <view class="px24rpx">
  178. <view class="-mt64rpx">
  179. <view class="text-left text-28rpx font-semibold">
  180. <!-- <view v-for="i in 2" :key="i" class="mr5px inline-block">
  181. <wd-tag type="primary">
  182. 新品{{ i }}
  183. </wd-tag>
  184. </view> -->
  185. {{ goodsInfo.prodName }}
  186. </view>
  187. </view>
  188. <!-- <view class="mt16rpx text-24rpx text-#AAAAAA">
  189. 优选产地,皮薄核小,维c满满
  190. </view> -->
  191. <!-- <view class="mt20rpx flex items-center">
  192. <view
  193. v-for="item in 2" :key="item"
  194. class="mr16rpx flex items-center justify-center border-1rpx border-#BC9264 rounded-8rpx border-solid bg-[#FFF5E9] px16rpx py6rpx text-24rpx text-#BC9264 font-semibold"
  195. >
  196. 一口化渣{{ item }}
  197. </view>
  198. </view> -->
  199. <view class="mt20rpx flex items-center justify-between rounded-16rpx bg-white p24rpx">
  200. <view class="flex items-center">
  201. <view class="flex-shrink-0">
  202. <view class="text-28rpx font-semibold">
  203. {{ goodsInfo.brandName }}
  204. </view>
  205. <view class="mt16rpx text-24rpx text-#AAAAAA">
  206. 品牌
  207. </view>
  208. </view>
  209. </view>
  210. <view class="mx24rpx">
  211. <wd-divider vertical color="#F0F0F0" />
  212. </view>
  213. <view class="flex items-center">
  214. <view class="flex-shrink-0">
  215. <view class="text-28rpx font-semibold">
  216. {{ goodsInfo.skuList[0].weight }}g
  217. </view>
  218. <view class="mt16rpx text-24rpx text-#AAAAAA">
  219. 重量
  220. </view>
  221. </view>
  222. </view>
  223. <view class="mx24rpx">
  224. <wd-divider vertical color="#F0F0F0" />
  225. </view>
  226. <view class="flex items-center">
  227. <view class="flex-shrink-0">
  228. <view class="text-28rpx font-semibold">
  229. {{ goodsInfo.skuList[0].weightUnit }}
  230. </view>
  231. <view class="mt16rpx text-24rpx text-#AAAAAA">
  232. 单位
  233. </view>
  234. </view>
  235. </view>
  236. <wd-icon name="chevron-right" size="22px" color="#AAAAAA" />
  237. </view>
  238. <!-- <view class="view-1 mt20rpx flex items-center rounded-16rpx bg-white p24rpx">
  239. <view class="w-full flex items-center justify-between">
  240. <view class="text-32rpx font-semibold">
  241. 评价(10万+)
  242. </view>
  243. <view class="flex items-center">
  244. <view class="mr10rpx flex items-center text-28rpx text-#FF4D3A">
  245. <view>好评率</view>
  246. <view class="ml5rpx font-semibold">
  247. 99.8%
  248. </view>
  249. </view>
  250. <wd-icon name="chevron-right" size="22px" color="#AAAAAA" />
  251. </view>
  252. </view>
  253. </view> -->
  254. <!-- <view class="mt20rpx rounded-16rpx bg-white p24rpx">
  255. <wd-tabs v-model="goodsTab">
  256. <block v-for="item in goodsTabList" :key="item.id">
  257. <wd-tab :title="item.title" />
  258. </block>
  259. </wd-tabs>
  260. <swiper class="mt20rpx h900rpx" indicator-active-color="var(--them-color)" @change="(e) => currentTabGoods = e.detail.current">
  261. <swiper-item
  262. v-for="items in goodsTabData" :key="items"
  263. class="grid grid-cols-3 items-start gap-x-16rpx gap-y-16rpx pb20rpx"
  264. >
  265. <view
  266. v-for="goods in items" :key="goods"
  267. class="box-border w204rpx border border-2rpx border-#F0F0F0 rounded-16rpx border-solid px4rpx py8rpx"
  268. >
  269. <image lazy-load :src="`${StaticUrl}/shu.png`" class="h188rpx w198rpx" />
  270. <view class="mt20rpx px16rpx text-24rpx font-semibold">
  271. 新鲜现宰杀肋排200g
  272. </view>
  273. <view class="mt12rpx truncate px16rpx text-24rpx text-#AAAAAA">
  274. 维c满满,营养qweqwe
  275. </view>
  276. <view class="my20rpx flex items-center justify-between px16rpx">
  277. <view class="flex items-end text-#FF4D3A font-semibold">
  278. <view class="text-24rpx">
  279. </view>
  280. <view class="text-32rpx line-height-[32rpx]">
  281. 1.395
  282. </view>
  283. </view>
  284. <image :src="`${StaticUrl}/cart-yes.png`" class="h44rpx w44rpx" />
  285. </view>
  286. </view>
  287. </swiper-item>
  288. </swiper>
  289. <view class="mt24rpx flex items-center justify-center">
  290. <view v-for="item, idx in goodsTabData" :key="idx" class="mr14rpx transition-all transition-duration-400 ease-in" :class="[currentTabGoods == idx ? 'rounded-12rpx w-40rpx h12rpx bg-[var(--them-color)]' : 'w12rpx h12rpx rounded-50% bg-#F0F0F0']" />
  291. </view>
  292. </view> -->
  293. </view>
  294. <view class="view-2 mt20rpx bg-white">
  295. <view class="p24rpx text-32rpx font-semibold">
  296. 商品详情
  297. <rich-text :nodes="goodsContent" />
  298. </view>
  299. </view>
  300. <!-- <view class="view-3 mt28rpx flex items-center justify-center">
  301. <view class="flex items-center">
  302. <image
  303. :src="`${StaticUrl}/goods-recommend.png`"
  304. class="mr12rpx h25rpx w26rpx"
  305. />
  306. <view class="text-36rpx text-[var(--them-color)] font-semibold">
  307. 为你推荐
  308. </view>
  309. <image
  310. :src="`${StaticUrl}/goods-recommend.png`"
  311. class="ml12rpx h25rpx w26rpx"
  312. />
  313. </view>
  314. </view> -->
  315. <view class="h180rpx" />
  316. <view class="ios shadow-fixed fixed bottom-0 left-0 w-full rounded-t-32rpx bg-white">
  317. <view class="flex items-center justify-between px24rpx py20rpx">
  318. <view class="mr36rpx" @click="router.replace({ name: 'xsb-homeTabbar' })">
  319. <image
  320. :src="`${StaticUrl}/goods-home.png`"
  321. class="h44rpx w44rpx"
  322. />
  323. <view class="text-20rpx">
  324. 首页
  325. </view>
  326. </view>
  327. <view class="relative mr36rpx">
  328. <image
  329. :src="`${StaticUrl}/goods-kf.png`"
  330. class="h44rpx w44rpx"
  331. />
  332. <button class="zbutton" open-type="contact">
  333. <view class="text-20rpx">
  334. 客服
  335. </view>
  336. </button>
  337. </view>
  338. <wd-badge :model-value="getTotalNum">
  339. <view @click="router.replace({ name: 'xsb-homeTabbar', animationType: 'fade-out', params: { name: 'xsb-cart' } })">
  340. <image
  341. :src="`${StaticUrl}/goods-cart.png`"
  342. class="h44rpx w44rpx"
  343. />
  344. <view class="text-20rpx">
  345. 购物车
  346. </view>
  347. </view>
  348. </wd-badge>
  349. <view class="flex items-center">
  350. <view class="w220rpx">
  351. <wd-button hairline plain block @click="selectGoods = true">
  352. 加入购物车
  353. </wd-button>
  354. </view>
  355. <view class="ml20rpx w220rpx" @click="selectGoods = true">
  356. <wd-button block class="w-full">
  357. 立即购买
  358. </wd-button>
  359. </view>
  360. </view>
  361. </view>
  362. </view>
  363. <selectSku v-model:show="selectGoods" v-model:sku-id="specId" v-model:select-goods-num="SelectGoodsNum" :goods-info="goodsInfo">
  364. <template #footer>
  365. <view class="box-border w-full flex items-center justify-between py20rpx">
  366. <view class="w-48%">
  367. <wd-button plain hairline block :loading="isLoging" :disabled="isLoging" @click="handleAddCart">
  368. 加入购物车
  369. </wd-button>
  370. </view>
  371. <view class="w-48%">
  372. <wd-button block :loading="isLoging" :disabled="isLoging" @click="handleConfimOrder">
  373. 立即购买
  374. </wd-button>
  375. </view>
  376. </view>
  377. </template>
  378. </selectSku>
  379. </template>
  380. </view>
  381. </template>
  382. <style scoped lang="scss">
  383. .custom-indicator {
  384. border-radius: 16rpx;
  385. background: rgba(0, 0, 0, 0.5);
  386. color: #ffffff;
  387. font-size: 24rpx;
  388. }
  389. .shadow-fixed{
  390. box-shadow: 0rpx -6rpx 12rpx 2rpx rgba(0,0,0,0.09);
  391. }
  392. .header {
  393. background: linear-gradient(180deg, #FFFFFF 0%, #FFFFFF 62%, #F6F6F6 100%);
  394. }
  395. .page-xsb {
  396. :deep() {
  397. .wd-tabs__nav-container .wd-tabs__nav-item:nth-child(2){
  398. width: 220rpx !important ;
  399. }
  400. .wd-tabs__nav-item {
  401. flex:unset !important;
  402. .wd-tabs__nav-item-text {
  403. font-size: 32rpx !important;
  404. }
  405. }
  406. .ios .wd-button{
  407. min-width: unset !important;
  408. }
  409. .wd-radio-group.is-button{
  410. padding: 0!important;
  411. }
  412. }
  413. }
  414. </style>