index.vue 15 KB

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