index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="wrap">
  3. <div class="nav">
  4. <div
  5. class="back"
  6. @click="router.push({ name: routerName.h5Shop })"
  7. >
  8. <i class="arrow"></i>
  9. </div>
  10. </div>
  11. <div class="cover-wrap">
  12. <img
  13. class="cover"
  14. :src="goodsInfo?.cover"
  15. alt=""
  16. />
  17. </div>
  18. <div class="info-wrap">
  19. <div class="price-wrap">
  20. <span class="rmb">¥</span>
  21. <span class="price">{{ formatMoney(goodsInfo?.price!, true) }}</span>
  22. <span
  23. class="original-price"
  24. v-if="goodsInfo?.original_price !== goodsInfo?.price"
  25. >
  26. <del>¥{{ formatMoney(goodsInfo?.original_price!, true) }}</del>
  27. </span>
  28. </div>
  29. <div class="name-wrap">{{ goodsInfo?.name }}</div>
  30. <div class="other-wrap">
  31. <div>库存:{{ goodsInfo?.inventory }}</div>
  32. <div>销量:{{ goodsInfo?.pay_nums }}</div>
  33. </div>
  34. </div>
  35. <div class="detail-title">商品详情</div>
  36. <RenderMarkdown :md="goodsInfo?.desc"></RenderMarkdown>
  37. <div class="buy">
  38. <div
  39. class="btn"
  40. @click="handleBuy"
  41. >
  42. 立即购买
  43. </div>
  44. </div>
  45. <QrPay
  46. v-if="showQrPay"
  47. :money="qrcodeInfo.money"
  48. :goods-id="qrcodeInfo.goodsId"
  49. :live-room-id="qrcodeInfo.liveRoomId"
  50. ></QrPay>
  51. </div>
  52. </template>
  53. <script lang="ts" setup>
  54. import { nextTick, onMounted, reactive, ref } from 'vue';
  55. import { useRoute } from 'vue-router';
  56. import { fetchGoodsFind } from '@/api/goods';
  57. import { IGoods } from '@/interface';
  58. import router, { routerName } from '@/router';
  59. import { formatMoney } from '@/utils';
  60. const route = useRoute();
  61. const goodsId = ref(-1);
  62. const goodsInfo = ref<IGoods>();
  63. const showQrPay = ref(false);
  64. const qrcodeInfo = reactive({
  65. money: 0,
  66. goodsId: -1,
  67. liveRoomId: -1,
  68. });
  69. onMounted(async () => {
  70. goodsId.value = +route.params.id;
  71. if (goodsId.value) {
  72. const res = await fetchGoodsFind(goodsId.value);
  73. if (res.code === 200) {
  74. goodsInfo.value = res.data;
  75. }
  76. }
  77. });
  78. function handleBuy() {
  79. if (goodsInfo.value?.price! <= 0) {
  80. window.$message.info('该商品是免费的,不需要购买!');
  81. return;
  82. }
  83. showQrPay.value = false;
  84. nextTick(() => {
  85. qrcodeInfo.money = goodsInfo.value?.price!;
  86. qrcodeInfo.goodsId = goodsInfo.value?.id!;
  87. showQrPay.value = true;
  88. });
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .wrap {
  93. height: 100vh;
  94. background-color: #f9f9f9;
  95. .nav {
  96. position: fixed;
  97. left: 0;
  98. z-index: 10;
  99. display: flex;
  100. align-items: center;
  101. box-sizing: border-box;
  102. padding-left: 20px;
  103. width: 100%;
  104. height: 60px;
  105. .back {
  106. display: flex;
  107. align-items: center;
  108. justify-content: center;
  109. box-sizing: border-box;
  110. width: 26px;
  111. height: 26px;
  112. border-radius: 4px;
  113. background-color: rgba($color: #000000, $alpha: 0.5);
  114. cursor: pointer;
  115. .arrow {
  116. border-color: white;
  117. @include arrow(left, 8px, 2px);
  118. }
  119. }
  120. }
  121. .cover-wrap {
  122. display: flex;
  123. align-items: center;
  124. justify-content: center;
  125. background-color: #fff;
  126. .cover {
  127. min-height: 300px;
  128. max-width: 100%;
  129. max-height: 300px;
  130. }
  131. }
  132. .info-wrap {
  133. box-sizing: border-box;
  134. margin: 14px auto;
  135. padding: 14px 10px;
  136. width: 95%;
  137. border-radius: 10px;
  138. background-color: #fff;
  139. .price-wrap {
  140. display: flex;
  141. align-items: baseline;
  142. color: #ff5000;
  143. .rmb {
  144. font-size: 16px;
  145. }
  146. .price {
  147. font-weight: 500;
  148. font-size: 28px;
  149. }
  150. .original-price {
  151. margin-left: 5px;
  152. color: #999;
  153. font-size: 14px;
  154. }
  155. }
  156. .name-wrap {
  157. margin-top: 10px;
  158. font-size: 20px;
  159. }
  160. .other-wrap {
  161. display: flex;
  162. display: flex;
  163. align-items: center;
  164. justify-content: space-between;
  165. margin-top: 10px;
  166. color: #999;
  167. font-size: 14px;
  168. }
  169. }
  170. .detail-title {
  171. display: flex;
  172. align-items: center;
  173. justify-content: center;
  174. margin: 30px 0;
  175. color: #333;
  176. text-align: center;
  177. font-weight: bold;
  178. &::before {
  179. display: inline-block;
  180. margin: 0 0.625rem;
  181. width: 3.0625rem;
  182. height: 1px;
  183. background: #dcdfe6;
  184. content: '';
  185. }
  186. &::after {
  187. display: inline-block;
  188. margin: 0 0.625rem;
  189. width: 3.0625rem;
  190. height: 1px;
  191. background: #dcdfe6;
  192. content: '';
  193. }
  194. }
  195. .buy {
  196. position: fixed;
  197. right: 0;
  198. bottom: 0;
  199. left: 0;
  200. display: flex;
  201. align-items: center;
  202. justify-content: center;
  203. height: 54px;
  204. background-color: #fff;
  205. &::before {
  206. position: absolute;
  207. top: 0;
  208. right: 0;
  209. left: 0;
  210. z-index: 2;
  211. display: block;
  212. height: 0;
  213. border-top: 1px solid #ddd;
  214. content: '';
  215. transform: scaleY(0.5);
  216. transform-origin: 50% 0;
  217. }
  218. .btn {
  219. display: flex;
  220. align-items: center;
  221. justify-content: center;
  222. width: 95%;
  223. height: 36px;
  224. border-radius: 10px;
  225. background-color: $theme-color-gold;
  226. color: white;
  227. font-size: 15px;
  228. }
  229. }
  230. }
  231. </style>