index.vue 15 KB

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