details.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <!-- 商品详情 -->
  2. <template>
  3. <div>
  4. <!-- <Navbar /> -->
  5. <div class="default-width pb-5 mt-3 pt-3" v-if="state.goodsInfo && Object.keys(state.goodsInfo).length">
  6. <v-card class="carousel border-radius-8 white-bgc pa-5" style="width: 100%;">
  7. <v-btn variant="text" size="x-large" prepend-icon="mdi-chevron-triple-left" color="primary" @click.stop="router.go(-1)">返回</v-btn>
  8. <div class="mt-1 d-flex">
  9. <!-- 图片展示-轮播 -->
  10. <div style="width: 400px; height: 400px;">
  11. <div v-if="selectedSkuPicUrl" class="selectedSkuImgBox" @mouseover="showSelectedSkuImg = true" @mouseleave="showSelectedSkuImg = false">
  12. <v-img :src="selectedSkuPicUrl" :aspect-ratio="1" style="border-radius: 8px;"></v-img>
  13. <v-btn
  14. v-show="showSelectedSkuImg"
  15. size="x-small"
  16. class="close px-3"
  17. @click="selectedSkuPicUrl = ''"
  18. >关闭</v-btn>
  19. </div>
  20. <v-carousel v-else show-arrows="hover" cycle :model-value="0" :hide-delimiters="!carouselHover" @mouseover="carouselHover = true" @mouseleave="carouselHover = false">
  21. <v-carousel-item v-for="(imgUrl, i) in state.goodsInfo.sliderPicUrls" :key="'wareImg'+i" @click="null">
  22. <v-img :src="imgUrl" :aspect-ratio="1" style="border-radius: 8px;"></v-img>
  23. </v-carousel-item>
  24. </v-carousel>
  25. </div>
  26. <!-- s-select-sku 商品属性选择 -->
  27. <div style="flex: 1;" class="pl-10">
  28. <!-- 大标题 -->
  29. <div class="title-name">{{ state.goodsInfo?.name || '--' }}</div>
  30. <!-- 小标题 -->
  31. <div class="title-introduction">{{ state.goodsInfo?.introduction || '--' }}</div>
  32. <!-- 价格 -->
  33. <div class="prices py-4 my-3">
  34. <div class="left">
  35. <div class="price mr-5"><span>¥</span>{{ selectedSkuPrice}}</div>
  36. <div class="marketPrice" v-if="selectedSkuMarketPrice && selectedSkuMarketPrice !== selectedSkuPrice">优惠前¥{{ selectedSkuMarketPrice}}</div>
  37. </div>
  38. <div v-if="showActivePrices" :class="{'activePrices': showActivePrices}" class="right pa-3 mt-3">
  39. <div>优惠大赠送!</div>
  40. <div>购买一份人力资源薪酬报告,可获赠一张超值酒店住宿房券!!!先到先得,赠完为止。</div>
  41. <!-- <div class="cursor-pointer">
  42. <v-icon>mdi-help-circle-outline</v-icon>
  43. <span class="text-decoration-underline">查看赠送活动详情</span>
  44. </div> -->
  45. </div>
  46. </div>
  47. <!-- 销量 -->
  48. <div class="salesCount mb-5 parameterColor"><span class="l-s-10">已售</span>:{{ state.goodsInfo?.salesCount || 0 }}</div>
  49. <!-- 属性选择组件 -->
  50. <selectSku
  51. v-if="showSelectSku"
  52. class="mb-7"
  53. :goodsInfo="state.goodsInfo"
  54. @change="onSkuChange"
  55. @buy="onBuy"
  56. @addCart="onAddCart"
  57. ></selectSku>
  58. </div>
  59. </div>
  60. </v-card>
  61. <!-- 详情描述 detail-content-card -->
  62. <v-card class="carousel border-radius-8 white-bgc pa-5 mt-3" style="width: 100%;">
  63. <div>
  64. <!-- <div class="mb-3">
  65. <v-tabs v-model="describeTab" align-tabs="start" color="primary" bg-color="#f7f8fa" @update:model-value="null">
  66. <v-tab :value="0">商品介绍</v-tab>
  67. <v-tab :value="1">商品评价</v-tab>
  68. <v-tab :value="2" v-if="showPrize">房券抽奖活动</v-tab>
  69. </v-tabs>
  70. </div> -->
  71. <describe v-if="describeTab === 0 && state.goodsInfo?.description" :content="state.goodsInfo.description"></describe>
  72. <!-- <commentCard v-if="describeTab === 1 && state.goodsId" class="detail-comment-selector" :goodsId="state.goodsId" />
  73. <prizeDrawContent v-if="describeTab === 2 && lotteryId" :lotteryId="lotteryId" /> -->
  74. </div>
  75. </v-card>
  76. </div>
  77. <!-- 快速登录 -->
  78. <loginPage v-if="showLogin" @loginSuccess="loginSuccess" @close="loginClose"></loginPage>
  79. </div>
  80. </template>
  81. <script setup>
  82. defineOptions({name: 'goods-details'})
  83. // import Navbar from '@/views/mall/components/navbar.vue'
  84. import { getProductDetail } from '@/api/mall/product'
  85. import { addCart } from '@/api/mall/cart'
  86. import selectSku from './details/s-select-sku.vue'
  87. import describe from './details/describe.vue'
  88. // import commentCard from './details/detail-comment-card.vue'
  89. // import prizeDrawContent from './details/prizeDrawContent.vue'
  90. import { ref, reactive, nextTick } from 'vue'
  91. import { useRouter } from 'vue-router'
  92. import Snackbar from '@/plugins/snackbar'
  93. import { getToken } from '@/utils/auth'
  94. import loginPage from '@/views/common/loginDialog.vue'
  95. // import pay from '@/views/mall/components/details/order/pay.vue'
  96. import { getPrizeByGoodsId } from '@/api/mall/prize'
  97. const router = useRouter()
  98. const { id } = router.currentRoute.value.params
  99. const describeTab = ref(0)
  100. const selectedSkuPicUrl = ref('')
  101. const selectedSkuPrice = ref('')
  102. const selectedSkuMarketPrice = ref('')
  103. const showSelectSku = ref(false)
  104. const carouselHover = ref(false)
  105. const showSelectedSkuImg = ref(false)
  106. const showPrize = ref(false)
  107. const showActivePrices = ref(false) // 下单送房券
  108. const lotteryId = ref('')
  109. // 获取商品详情
  110. const getData = async () => {
  111. const obj = await getProductDetail({ id })
  112. if (!obj) return Snackbar.warning('未找到商品!')
  113. //
  114. // 加载到商品
  115. obj.sliderPicUrls = obj.sliderPicUrls || []
  116. state.skeletonLoading = false;
  117. state.goodsInfo = obj
  118. showSelectSku.value = true
  119. // 查询当前商品是否参与抽奖活动
  120. const data = await getPrizeByGoodsId(id)
  121. const bool = data && Object.keys(data).length
  122. showPrize.value = showActivePrices.value = bool
  123. lotteryId.value = data?.id || null
  124. }
  125. getData()
  126. const calcPrice = (price) => { return price && (price-0) ? (price-0)/100 : '--' }
  127. const state = reactive({
  128. goodsId: id || 0,
  129. skeletonLoading: true, // SPU 加载中
  130. goodsInfo: {}, // SPU 信息
  131. showSelectSku: false, // 是否展示 SKU 选择弹窗
  132. selectedSku: {}, // 选中的 SKU
  133. settlementSku: {}, // 结算的 SKU:由于 selectedSku 不进行默认选中,所以初始使用结算价格最低的 SKU 作为基础展示
  134. showModel: false, // 是否展示 Coupon 优惠劵的弹窗
  135. couponInfo: [], // 可领取的 Coupon 优惠劵的列表
  136. showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
  137. rewardActivity: {}, // 【满减送】活动
  138. activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
  139. });
  140. // 规格变更
  141. function onSkuChange(e) {
  142. state.selectedSku = e;
  143. state.settlementSku = e;
  144. // console.log('onSkuChange:', e)
  145. selectedSkuPicUrl.value = state.selectedSku?.picUrl || ''
  146. if (selectedSkuPicUrl.value) showSelectedSkuImg.value = true
  147. selectedSkuPrice.value = calcPrice(state.selectedSku?.price || state.goodsInfo.price)
  148. selectedSkuMarketPrice.value = calcPrice(state.selectedSku?.marketPrice || state.goodsInfo.marketPrice)
  149. }
  150. // const showSettlement = ref(false)
  151. // const skuInfo = ref(null) // 购买商品规格信息
  152. const onBuy = async (e) => {
  153. if (!getToken()) return handleLogin()
  154. if (!e?.id) return Snackbar.warning('请选择商品规格!')
  155. const data = JSON.stringify({
  156. items: [
  157. {
  158. skuId: e.id,
  159. count: e.goods_num,
  160. categoryId: state.goodsInfo.categoryId,
  161. },
  162. ],
  163. goodsType: state.goodsInfo?.type || 0,
  164. })
  165. localStorage.setItem('confirm_order_data', data)
  166. nextTick(() => {
  167. router.push({path: '/mall/confirm_order', query: { price: e.price, spuId: id }})
  168. })
  169. }
  170. // 添加购物车
  171. const onAddCart = async (e) => {
  172. if (!getToken()) return handleLogin()
  173. if (!e.id) {
  174. Snackbar.warning('请选择商品规格')
  175. return;
  176. }
  177. await addCart({ skuId: e.id, count: e.goods_num })
  178. Snackbar.success('已添加到购物车~')
  179. // 刷新购物车列表
  180. }
  181. const showLogin = ref(false)
  182. const handleLogin = () => {
  183. Snackbar.warning('您还未登录,请先登录后再试')
  184. showLogin.value = true // 打开快速登录弹窗
  185. }
  186. // 快速登录
  187. const loginSuccess = () => {
  188. showLogin.value = false
  189. Snackbar.success('登录成功')
  190. // router.go(0)
  191. }
  192. const loginClose = () => {
  193. showLogin.value = false
  194. Snackbar.warning('您已取消登录')
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .border-radius-8 {
  199. border-radius: 8px;
  200. }
  201. .title-name {
  202. font-size: 24px;
  203. line-height: 1.25;
  204. color: #000;
  205. margin-bottom: 12px;
  206. font-weight: bold;
  207. }
  208. .title-introduction {
  209. font-size: 18px;
  210. line-height: 1.5;
  211. color: #6b6b6b;
  212. }
  213. .parameterColor {
  214. color: #7a7a7a;
  215. }
  216. .prices {
  217. // display: flex;
  218. // justify-content: space-between;
  219. font-size: 28px;
  220. border-radius: 8px;
  221. width: 80%;
  222. color: #ff5000;
  223. .left {
  224. display: flex;
  225. align-items: flex-end;
  226. }
  227. .right {
  228. font-size: 18px;
  229. padding-top: 10px;
  230. font-weight: 400;
  231. }
  232. }
  233. .activePrices {
  234. color: #fff;
  235. background-color: #fb0037;
  236. border-radius: 10px;
  237. }
  238. .price {
  239. font-weight: 600;
  240. span {
  241. font-size: 16px;
  242. }
  243. }
  244. .marketPrice {
  245. color: #b7b7b7;
  246. font-size: 16px;
  247. line-height: 34px;
  248. // text-decoration: line-through;
  249. }
  250. .selectedSkuImgBox {
  251. position: relative;
  252. .close {
  253. position: absolute;
  254. bottom: 10px;
  255. right: 10px;
  256. }
  257. }
  258. </style>