details.vue 9.7 KB

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