details.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. <!-- 结算 -->
  80. <CtDialog :visible="showSettlement" titleClass="text-h6" :widthType="3" title="订单提交" submitText="提交支付" @submit="handleSubmit" @close="handleClose">
  81. <confirm ref="confirmRef" :data="skuInfo" @orderCreated="orderCreated"></confirm>
  82. </CtDialog>
  83. <!-- 支付 -->
  84. <CtDialog :visible="showPay" titleClass="text-h6" :widthType="3" title="收银台" :footer="false" @close="payCancel">
  85. <pay ref="payRef" :id="payOrderId" @paySuccess="paySuccess"></pay>
  86. </CtDialog>
  87. </div>
  88. </template>
  89. <script setup>
  90. defineOptions({name: 'goods-details'})
  91. import Navbar from '@/views/mall/components/navbar.vue'
  92. import { getProductDetail } from '@/api/mall/product'
  93. import { addCart } from '@/api/mall/cart'
  94. import selectSku from './details/s-select-sku.vue'
  95. import describe from './details/describe.vue'
  96. // import commentCard from './details/detail-comment-card.vue'
  97. // import prizeDrawContent from './details/prizeDrawContent.vue'
  98. import confirm from './details/order/confirm.vue'
  99. import { ref, reactive } from 'vue'
  100. import { useRouter } from 'vue-router'
  101. import Snackbar from '@/plugins/snackbar'
  102. import { getToken } from '@/utils/auth'
  103. import loginPage from '@/views/common/loginDialog.vue'
  104. import pay from '@/views/mall/components/details/order/pay.vue'
  105. import { getPrizeByGoodsId } from '@/api/mall/prize'
  106. const router = useRouter()
  107. const { id } = router.currentRoute.value.params
  108. const describeTab = ref(0)
  109. const selectedSkuPicUrl = ref('')
  110. const selectedSkuPrice = ref('')
  111. const selectedSkuMarketPrice = ref('')
  112. const showSelectSku = ref(false)
  113. const carouselHover = ref(false)
  114. const showSelectedSkuImg = ref(false)
  115. const showPrize = ref(false)
  116. const showActivePrices = ref(false) // 下单送房券
  117. const lotteryId = ref('')
  118. // 获取商品详情
  119. const getData = async () => {
  120. const obj = await getProductDetail({ id })
  121. if (!obj) return Snackbar.warning('未找到商品!')
  122. //
  123. // 加载到商品
  124. obj.sliderPicUrls = obj.sliderPicUrls || []
  125. state.skeletonLoading = false;
  126. state.goodsInfo = obj
  127. showSelectSku.value = true
  128. // 查询当前商品是否参与抽奖活动
  129. const data = await getPrizeByGoodsId(id)
  130. showPrize.value = data && Object.keys(data).length > 0
  131. showActivePrices.value = data && Object.keys(data).length > 0
  132. lotteryId.value = data.id
  133. }
  134. getData()
  135. const calcPrice = (price) => { return price && (price-0) ? (price-0)/100 : '--' }
  136. const state = reactive({
  137. goodsId: id || 0,
  138. skeletonLoading: true, // SPU 加载中
  139. goodsInfo: {}, // SPU 信息
  140. showSelectSku: false, // 是否展示 SKU 选择弹窗
  141. selectedSku: {}, // 选中的 SKU
  142. settlementSku: {}, // 结算的 SKU:由于 selectedSku 不进行默认选中,所以初始使用结算价格最低的 SKU 作为基础展示
  143. showModel: false, // 是否展示 Coupon 优惠劵的弹窗
  144. couponInfo: [], // 可领取的 Coupon 优惠劵的列表
  145. showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
  146. rewardActivity: {}, // 【满减送】活动
  147. activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
  148. });
  149. // 规格变更
  150. function onSkuChange(e) {
  151. state.selectedSku = e;
  152. state.settlementSku = e;
  153. // console.log('onSkuChange:', e)
  154. selectedSkuPicUrl.value = state.selectedSku?.picUrl || ''
  155. if (selectedSkuPicUrl.value) showSelectedSkuImg.value = true
  156. selectedSkuPrice.value = calcPrice(state.selectedSku?.price || state.goodsInfo.price)
  157. selectedSkuMarketPrice.value = calcPrice(state.selectedSku?.marketPrice || state.goodsInfo.marketPrice)
  158. }
  159. const showSettlement = ref(false)
  160. const skuInfo = ref(null) // 购买商品规格信息
  161. const onBuy = async (e) => {
  162. if (!getToken()) return handleLogin()
  163. if (!e?.id) return Snackbar.warning('请选择商品规格!')
  164. skuInfo.value = JSON.stringify({
  165. items: [{ skuId: e.id, count: e.goods_num, categoryId: state.goodsInfo.categoryId }]
  166. })
  167. showSettlement.value = true
  168. // router.push(`/mall/order/settlement/${e.id}?count=${e.goods_num}`)
  169. }
  170. // 创建订单完成
  171. const payRef = ref()
  172. const showPay = ref(false)
  173. const payOrderId = ref('')
  174. const orderId = ref('')
  175. const orderCreated = (id, order) => {
  176. showSettlement.value = false
  177. payOrderId.value = id
  178. orderId.value = order
  179. showPay.value = true
  180. }
  181. //
  182. const payCancel = () => {
  183. Snackbar.warning('您已取消支付!')
  184. showPay.value = false
  185. setTimeout(() => { router.push({ path: '/mall/user/order', query: { tab: 0 } }) }, 500);
  186. }
  187. const paySuccess = (e) => {
  188. // Snackbar.success('支付成功,请前往我的订单查看!')
  189. // showPay.value = false
  190. router.push({ path: '/mall/payOver', query: { price: e.price, spuId: id, orderId: orderId.value } })
  191. }
  192. // 添加购物车
  193. const onAddCart = async (e) => {
  194. if (!getToken()) return handleLogin()
  195. if (!e.id) {
  196. Snackbar.warning('请选择商品规格')
  197. return;
  198. }
  199. await addCart({ skuId: e.id, count: e.goods_num })
  200. Snackbar.success('已添加到购物车~')
  201. // 刷新购物车列表
  202. }
  203. const confirmRef = ref()
  204. const handleSubmit = () => {
  205. if (confirmRef.value) confirmRef.value.onConfirm()
  206. }
  207. const handleClose = () => {
  208. showSettlement.value = false
  209. }
  210. const showLogin = ref(false)
  211. const handleLogin = () => {
  212. Snackbar.warning('您还未登录,请先登录后再试')
  213. showLogin.value = true // 打开快速登录弹窗
  214. }
  215. // 快速登录
  216. const loginSuccess = () => {
  217. showLogin.value = false
  218. Snackbar.success('登录成功')
  219. // router.go(0)
  220. }
  221. const loginClose = () => {
  222. showLogin.value = false
  223. Snackbar.warning('您已取消登录')
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .border-radius-8 {
  228. border-radius: 8px;
  229. }
  230. .title-name {
  231. font-size: 24px;
  232. line-height: 1.25;
  233. color: #000;
  234. margin-bottom: 12px;
  235. font-weight: bold;
  236. }
  237. .title-introduction {
  238. font-size: 18px;
  239. line-height: 1.5;
  240. color: #6b6b6b;
  241. }
  242. .parameterColor {
  243. color: #7a7a7a;
  244. }
  245. .prices {
  246. // display: flex;
  247. // justify-content: space-between;
  248. font-size: 28px;
  249. border-radius: 8px;
  250. width: 80%;
  251. color: #ff5000;
  252. .left {
  253. display: flex;
  254. align-items: flex-end;
  255. }
  256. .right {
  257. font-size: 18px;
  258. padding-top: 10px;
  259. font-weight: 400;
  260. }
  261. }
  262. .activePrices {
  263. color: #fff;
  264. background-color: #fb0037;
  265. border-radius: 10px;
  266. }
  267. .price {
  268. font-weight: 600;
  269. span {
  270. font-size: 16px;
  271. }
  272. }
  273. .marketPrice {
  274. color: #b7b7b7;
  275. font-size: 16px;
  276. line-height: 34px;
  277. // text-decoration: line-through;
  278. }
  279. .selectedSkuImgBox {
  280. position: relative;
  281. .close {
  282. position: absolute;
  283. bottom: 10px;
  284. right: 10px;
  285. }
  286. }
  287. </style>