index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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 } = 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. await useUserStore().checkLogin()
  101. isLoging.value = true
  102. const res = await Apis.xsb.skuOrderConfirm({
  103. data: {
  104. skuId: specId.value,
  105. num: SelectGoodsNum.value,
  106. channelId: unref(userInfo).channelId,
  107. shopId: unref(goodsInfo)?.shopId || 2,
  108. },
  109. })
  110. if (Number(res.data.sku?.shopSkuStocks) < unref(SelectGoodsNum)) {
  111. useGlobalToast().show('库存不足,请调整购买数量')
  112. isLoging.value = false
  113. return
  114. }
  115. router.push({
  116. name: 'xsb-confirmOrder',
  117. params: { data: JSON.stringify({ ...res.data, skuList: [{ ...res.data.sku, num: SelectGoodsNum.value }] }) },
  118. })
  119. isLoging.value = false
  120. }
  121. async function handleAddCart() {
  122. if (Number(unref(goodsInfo)?.spuStock) < unref(SelectGoodsNum)) {
  123. useGlobalToast().show('库存不足,请调整购买数量')
  124. return
  125. }
  126. isLoging.value = true
  127. try {
  128. await useSmqjhCartStore().addCart(specId.value, unref(SelectGoodsNum), unref(SelectShopInfo.value.shopId || 2), 'XSB')
  129. selectGoods.value = false
  130. useGlobalToast().show('添加成功')
  131. isLoging.value = false
  132. }
  133. catch (error) {
  134. isLoging.value = false
  135. console.log(error)
  136. }
  137. }
  138. </script>
  139. <template>
  140. <page-meta :page-style="selectGoods ? 'overflow: hidden;' : '' " />
  141. <view class="page-xsb">
  142. <wd-navbar
  143. title="商品详情" :custom-style="`background-color:${isShowTab ? '#FFF !important' : 'transparent !important'}`" :bordered="false" :z-index="99"
  144. safe-area-inset-top left-arrow fixed @click-left="router.back()"
  145. />
  146. <template v-if="goodsInfo">
  147. <wd-swiper v-model:current="current" :list="swiperList" :autoplay="false" :height="375">
  148. <template #indicator="{ current: currentIndex, total }">
  149. <view class="custom-indicator absolute bottom-60rpx right-20rpx px26rpx">
  150. {{ currentIndex + 1 }}/{{ total }}
  151. </view>
  152. </template>
  153. </wd-swiper>
  154. <view class="header view-0 relative z-3 rounded-t-32rpx px24rpx pt24rpx -mt30rpx">
  155. <view class="flex items-center justify-between">
  156. <view class="flex items-end text-#FF4D3A font-semibold">
  157. <view class="text-24rpx">
  158. </view>
  159. <view class="text-36rpx line-height-[36rpx]">
  160. {{ goodsInfo?.channelProdPrice }}
  161. </view>
  162. </view>
  163. <!-- <view>
  164. <image class="h40rpx w40rpx" :src="`${StaticUrl}/collect-yes.png`" />
  165. </view> -->
  166. </view>
  167. </view>
  168. <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 ? '' : '']">
  169. <view v-for="item in goodsDetaileTabList" :key="item.id" class="relative flex items-center text-32rpx font-semibold" @click="handleGoCurren(item.id)">
  170. {{ item.title }}
  171. <view v-show="currentDetaile == item.id" class="line absolute left-50% h12rpx w40rpx rounded-8rpx bg-[var(--them-color)] -bottom-15rpx -translate-x-50%" />
  172. </view>
  173. </view>
  174. <view class="px24rpx">
  175. <view class="-mt64rpx">
  176. <view class="text-left text-28rpx font-semibold">
  177. <!-- <view v-for="i in 2" :key="i" class="mr5px inline-block">
  178. <wd-tag type="primary">
  179. 新品{{ i }}
  180. </wd-tag>
  181. </view> -->
  182. {{ goodsInfo.prodName }}
  183. </view>
  184. </view>
  185. <!-- <view class="mt16rpx text-24rpx text-#AAAAAA">
  186. 优选产地,皮薄核小,维c满满
  187. </view> -->
  188. <!-- <view class="mt20rpx flex items-center">
  189. <view
  190. v-for="item in 2" :key="item"
  191. 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"
  192. >
  193. 一口化渣{{ item }}
  194. </view>
  195. </view> -->
  196. <view class="mt20rpx flex items-center justify-between rounded-16rpx bg-white p24rpx">
  197. <view class="flex items-center">
  198. <view class="flex-shrink-0">
  199. <view class="text-28rpx font-semibold">
  200. {{ goodsInfo.brandName }}
  201. </view>
  202. <view class="mt16rpx text-24rpx text-#AAAAAA">
  203. 品牌
  204. </view>
  205. </view>
  206. </view>
  207. <view class="mx24rpx">
  208. <wd-divider vertical color="#F0F0F0" />
  209. </view>
  210. <view class="flex items-center">
  211. <view class="flex-shrink-0">
  212. <view class="text-28rpx font-semibold">
  213. {{ goodsInfo.skuList[0].weight }}g
  214. </view>
  215. <view class="mt16rpx text-24rpx text-#AAAAAA">
  216. 重量
  217. </view>
  218. </view>
  219. </view>
  220. <view class="mx24rpx">
  221. <wd-divider vertical color="#F0F0F0" />
  222. </view>
  223. <view class="flex items-center">
  224. <view class="flex-shrink-0">
  225. <view class="text-28rpx font-semibold">
  226. {{ goodsInfo.skuList[0].weightUnit }}
  227. </view>
  228. <view class="mt16rpx text-24rpx text-#AAAAAA">
  229. 单位
  230. </view>
  231. </view>
  232. </view>
  233. <wd-icon name="chevron-right" size="22px" color="#AAAAAA" />
  234. </view>
  235. <!-- <view class="view-1 mt20rpx flex items-center rounded-16rpx bg-white p24rpx">
  236. <view class="w-full flex items-center justify-between">
  237. <view class="text-32rpx font-semibold">
  238. 评价(10万+)
  239. </view>
  240. <view class="flex items-center">
  241. <view class="mr10rpx flex items-center text-28rpx text-#FF4D3A">
  242. <view>好评率</view>
  243. <view class="ml5rpx font-semibold">
  244. 99.8%
  245. </view>
  246. </view>
  247. <wd-icon name="chevron-right" size="22px" color="#AAAAAA" />
  248. </view>
  249. </view>
  250. </view> -->
  251. <!-- <view class="mt20rpx rounded-16rpx bg-white p24rpx">
  252. <wd-tabs v-model="goodsTab">
  253. <block v-for="item in goodsTabList" :key="item.id">
  254. <wd-tab :title="item.title" />
  255. </block>
  256. </wd-tabs>
  257. <swiper class="mt20rpx h900rpx" indicator-active-color="var(--them-color)" @change="(e) => currentTabGoods = e.detail.current">
  258. <swiper-item
  259. v-for="items in goodsTabData" :key="items"
  260. class="grid grid-cols-3 items-start gap-x-16rpx gap-y-16rpx pb20rpx"
  261. >
  262. <view
  263. v-for="goods in items" :key="goods"
  264. class="box-border w204rpx border border-2rpx border-#F0F0F0 rounded-16rpx border-solid px4rpx py8rpx"
  265. >
  266. <image lazy-load :src="`${StaticUrl}/shu.png`" class="h188rpx w198rpx" />
  267. <view class="mt20rpx px16rpx text-24rpx font-semibold">
  268. 新鲜现宰杀肋排200g
  269. </view>
  270. <view class="mt12rpx truncate px16rpx text-24rpx text-#AAAAAA">
  271. 维c满满,营养qweqwe
  272. </view>
  273. <view class="my20rpx flex items-center justify-between px16rpx">
  274. <view class="flex items-end text-#FF4D3A font-semibold">
  275. <view class="text-24rpx">
  276. </view>
  277. <view class="text-32rpx line-height-[32rpx]">
  278. 1.395
  279. </view>
  280. </view>
  281. <image :src="`${StaticUrl}/cart-yes.png`" class="h44rpx w44rpx" />
  282. </view>
  283. </view>
  284. </swiper-item>
  285. </swiper>
  286. <view class="mt24rpx flex items-center justify-center">
  287. <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']" />
  288. </view>
  289. </view> -->
  290. </view>
  291. <view class="view-2 mt20rpx bg-white">
  292. <view class="p24rpx text-32rpx font-semibold">
  293. 商品详情
  294. <rich-text :nodes="goodsContent" />
  295. </view>
  296. </view>
  297. <!-- <view class="view-3 mt28rpx flex items-center justify-center">
  298. <view class="flex items-center">
  299. <image
  300. :src="`${StaticUrl}/goods-recommend.png`"
  301. class="mr12rpx h25rpx w26rpx"
  302. />
  303. <view class="text-36rpx text-[var(--them-color)] font-semibold">
  304. 为你推荐
  305. </view>
  306. <image
  307. :src="`${StaticUrl}/goods-recommend.png`"
  308. class="ml12rpx h25rpx w26rpx"
  309. />
  310. </view>
  311. </view> -->
  312. <view class="h180rpx" />
  313. <view class="ios shadow-fixed fixed bottom-0 left-0 w-full rounded-t-32rpx bg-white">
  314. <view class="flex items-center justify-between px24rpx py20rpx">
  315. <view class="mr36rpx" @click="router.replace({ name: 'xsb-homeTabbar' })">
  316. <image
  317. :src="`${StaticUrl}/goods-home.png`"
  318. class="h44rpx w44rpx"
  319. />
  320. <view class="text-20rpx">
  321. 首页
  322. </view>
  323. </view>
  324. <view class="relative mr36rpx">
  325. <image
  326. :src="`${StaticUrl}/goods-kf.png`"
  327. class="h44rpx w44rpx"
  328. />
  329. <Zcontact>
  330. <view class="text-20rpx">
  331. 客服
  332. </view>
  333. </Zcontact>
  334. </view>
  335. <wd-badge :model-value="getTotalNum">
  336. <view @click="router.replace({ name: 'xsb-homeTabbar', animationType: 'fade-out', params: { name: 'xsb-cart' } })">
  337. <image
  338. :src="`${StaticUrl}/goods-cart.png`"
  339. class="h44rpx w44rpx"
  340. />
  341. <view class="text-20rpx">
  342. 购物车
  343. </view>
  344. </view>
  345. </wd-badge>
  346. <view class="flex items-center">
  347. <view class="w220rpx">
  348. <wd-button plain hairline block @click="selectGoods = true">
  349. 加入购物车
  350. </wd-button>
  351. </view>
  352. <view class="ml20rpx w220rpx" @click="selectGoods = true">
  353. <wd-button block class="w-full">
  354. 立即购买
  355. </wd-button>
  356. </view>
  357. </view>
  358. </view>
  359. </view>
  360. <selectSku v-model:show="selectGoods" v-model:sku-id="specId" v-model:select-goods-num="SelectGoodsNum" :goods-info="goodsInfo">
  361. <template #footer>
  362. <view class="box-border w-full flex items-center justify-between py20rpx">
  363. <view class="w-48%">
  364. <wd-button plain hairline block :loading="isLoging" :disabled="isLoging" @click="handleAddCart">
  365. 加入购物车
  366. </wd-button>
  367. </view>
  368. <view class="w-48%">
  369. <wd-button block :loading="isLoging" :disabled="isLoging" @click="handleConfimOrder">
  370. 立即购买
  371. </wd-button>
  372. </view>
  373. </view>
  374. </template>
  375. </selectSku>
  376. </template>
  377. </view>
  378. </template>
  379. <style scoped lang="scss">
  380. .custom-indicator {
  381. border-radius: 16rpx;
  382. background: rgba(0, 0, 0, 0.5);
  383. color: #ffffff;
  384. font-size: 24rpx;
  385. }
  386. .shadow-fixed{
  387. box-shadow: 0rpx -6rpx 12rpx 2rpx rgba(0,0,0,0.09);
  388. }
  389. .header {
  390. background: linear-gradient(180deg, #FFFFFF 0%, #FFFFFF 62%, #F6F6F6 100%);
  391. }
  392. .page-xsb {
  393. :deep() {
  394. .wd-tabs__nav-container .wd-tabs__nav-item:nth-child(2){
  395. width: 220rpx !important ;
  396. }
  397. .wd-tabs__nav-item {
  398. flex:unset !important;
  399. .wd-tabs__nav-item-text {
  400. font-size: 32rpx !important;
  401. }
  402. }
  403. .ios .wd-button{
  404. min-width: unset !important;
  405. }
  406. .wd-radio-group.is-button{
  407. padding: 0!important;
  408. }
  409. }
  410. }
  411. </style>