index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <div class="detail-box">
  3. <div class="main-info__box">
  4. <div class="main-info__content">
  5. <div class="goods-info">
  6. <div class="image-box">
  7. <img :src="mainForm.detail.imgUrl" />
  8. </div>
  9. <div class="info-content">
  10. <div class="title">{{ mainForm.detail.goodsName || '' }}</div>
  11. <div class="stock-info__box">
  12. <div class="stock-content">
  13. <a-flex v-if="!isLogin" align="center">
  14. <a-button type="link" @click="toLogin">登录</a-button>
  15. <span>查看商品实时库存</span>
  16. </a-flex>
  17. <div v-else>库存: {{ mainForm.detail.stock }}</div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="goods-handle">
  23. <div>
  24. <a-flex v-if="!isLogin" align="center">
  25. <a-button type="link" @click="toLogin">登录</a-button>
  26. <span>查看商品实时价格</span>
  27. </a-flex>
  28. <div v-else>价格: ¥ {{ mainForm.detail.goodsPrice }}</div>
  29. </div>
  30. <div>
  31. <a-form
  32. :model="mainForm"
  33. name="mainForm"
  34. :label-col="{ span: 24 }"
  35. :wrapper-col="{ span: 24 }"
  36. autocomplete="off"
  37. @finish="onFinish"
  38. @finishFailed="onFailed"
  39. >
  40. <a-form-item
  41. label="数量"
  42. name="quantity"
  43. :rules="[{ required: true, message: '数量不能为空' }]"
  44. >
  45. <a-input-number v-model:value="mainForm.quantity" :min="1" style="width: 100%;">
  46. <template #upIcon>
  47. <ArrowUpOutlined />
  48. </template>
  49. <template #downIcon>
  50. <ArrowDownOutlined />
  51. </template>
  52. </a-input-number>
  53. </a-form-item>
  54. <a-form-item label="" name="addToCard">
  55. <a-button :disabled="!isLogin" type="primary" block @click="handleAddToCart">添加到购物车</a-button>
  56. </a-form-item>
  57. <a-form-item label="" name="saveToList">
  58. <a-button :disabled="!isLogin" type="primary" block>保存到列表</a-button>
  59. </a-form-item>
  60. </a-form>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="main-desc__box">
  66. <a-tabs v-model:activeKey="mainForm.tabIndex" type="card" :tabBarStyle="{background: '#f3f3f7', marginBottom: 0}">
  67. <a-tab-pane
  68. v-for="(tabName, index) in tabs"
  69. :key="index"
  70. :tab="tabName"
  71. />
  72. </a-tabs>
  73. <div class="desc-content">
  74. <div v-show="mainForm.tabIndex == 0">
  75. <div v-html="mainForm.detail.content"></div>
  76. </div>
  77. <div v-show="mainForm.tabIndex == 1">
  78. <div :style="{marginBottom: '20px'}">
  79. <a-input
  80. v-model:value="mainForm.searchFileName"
  81. placeholder="点击输入文档名称搜索"
  82. size="large"
  83. allowClear
  84. >
  85. <template #prefix>
  86. <SearchOutlined />
  87. </template>
  88. </a-input>
  89. </div>
  90. <a-collapse
  91. v-for="(item, index) in goodsDocumentsRelaList"
  92. :key="index"
  93. collapsible="header"
  94. :style="{marginBottom: '20px'}"
  95. >
  96. <a-collapse-panel key="1" :header="item.children && item.children.length > 0 ? `${item.folderName} (${item.children.length})` : item.parentCategoryName">
  97. <div v-if="item.children && item.children.length > 0">
  98. <ViewFile
  99. v-for="(child, cIndex) in item.children"
  100. :key="cIndex"
  101. :url="child.url"
  102. :name="child.fileName"
  103. :show-delete="false"
  104. :style="{
  105. marginBottom: cIndex === item.children.length - 1 ? 0 : '12px'
  106. }"
  107. />
  108. </div>
  109. </a-collapse-panel>
  110. </a-collapse>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </template>
  116. <script setup lang="js">
  117. import ViewFile from '@/components/viewFile/index.vue';
  118. import { ArrowUpOutlined, ArrowDownOutlined, SearchOutlined } from '@ant-design/icons-vue';
  119. import { reactive, computed, onMounted, watch } from 'vue';
  120. import { useRoute, useRouter } from 'vue-router';
  121. import { getDetail, getFileList } from '@/api/goods';
  122. import { useUserStore } from '@/store/user';
  123. import { useHomeStore } from '@/store/home';
  124. import { useGoodsStore } from '@/store/goods';
  125. import { goodsDetailData, fileList } from '@/utils/mock';
  126. const route = useRoute();
  127. const router = useRouter();
  128. const userStore = useUserStore();
  129. const homeStore = useHomeStore();
  130. const goodsStore = useGoodsStore();
  131. const mainForm = reactive({
  132. quantity: 1,
  133. tabIndex: 0,
  134. detail: {},
  135. searchFileName: ''
  136. })
  137. const isLogin = computed(() => userStore.isLogin);
  138. const goodsDocumentsRelaList = computed(() => {
  139. if (!mainForm.detail.goodsDocumentsRelaList || mainForm.detail.goodsDocumentsRelaList.length === 0) return [];
  140. const validList = mainForm.detail.goodsDocumentsRelaList.filter(item => item.goodsDocumentsId.indexOf(mainForm.searchFileName) > -1 || item.fileName.indexOf(mainForm.searchFileName) > -1);
  141. return validList.reduce((prev, curItem) => {
  142. const target = prev.find(item => item.goodsDocumentsId === curItem.goodsDocumentsId);
  143. if (target) {
  144. target.children.push(curItem);
  145. } else {
  146. prev.push({
  147. ...curItem,
  148. children: [curItem]
  149. })
  150. };
  151. return prev;
  152. }, []);
  153. });
  154. const tabs = computed(() => {
  155. if (!mainForm.detail.goodsDocumentsRelaList || mainForm.detail.goodsDocumentsRelaList.length === 0) return ['商品详情'];
  156. return ['商品详情', '文档'];
  157. });
  158. const onFinish = () => {}
  159. const onFailed = () => {}
  160. const fetchDetail = async () => {
  161. // const res = await getDetail(route.query.id);
  162. // mainForm.detail = res.data || {};
  163. mainForm.detail = goodsDetailData;
  164. }
  165. const fetchFileData = async () => {
  166. // const res = await getFileList(route.query.id);
  167. // mainForm.detail.goodsDocumentsRelaList = res.data || [];
  168. mainForm.detail.goodsDocumentsRelaList = fileList;
  169. }
  170. const handleAddToCart = () => {
  171. if (!mainForm.detail.goodsId) return;
  172. const buyGoods = [
  173. {
  174. goodsId: route.query.id,
  175. goodsSpecId: mainForm.detail.goodsSpecs ? mainForm.detail.goodsSpecs[0]?.goodsSpecId : '',
  176. secKillId: mainForm.detail.secKillId || '',
  177. promotionGroupId: mainForm.detail.promotionGroupId || ''
  178. }
  179. ]
  180. const params = {
  181. storageId: homeStore.storageId,
  182. buyGoods: buyGoods
  183. }
  184. goodsStore.addToCard(params)
  185. }
  186. const toLogin = () => {
  187. router.push({
  188. path: '/login'
  189. })
  190. }
  191. onMounted(() => {
  192. fetchDetail();
  193. fetchFileData();
  194. })
  195. watch(() => route.query.id, newVal => {
  196. fetchDetail();
  197. fetchFileData();
  198. })
  199. </script>
  200. <style lang="less" scoped>
  201. .detail-box {
  202. .main-info__box {
  203. margin-bottom: 24px;
  204. border: 1px solid @border-color;
  205. border-radius: 2px;
  206. .main-info__content {
  207. width: 100%;
  208. display: flex;
  209. .goods-info {
  210. flex: 1;
  211. display: flex;
  212. min-width: 1px;
  213. background: #fff;
  214. .image-box {
  215. width: 360px;
  216. height: 360px;
  217. flex-shrink: 0;
  218. img {
  219. display: block;
  220. width: 100%;
  221. height: 100%;
  222. }
  223. }
  224. .info-content {
  225. flex: 1;
  226. min-width: 1px;
  227. padding: 20px;
  228. word-break: break-all;
  229. .title {
  230. color: #000;
  231. font-size: 24px;
  232. font-weight: 600;
  233. line-height: 1.5;
  234. text-align: center;
  235. margin-bottom: 24px;
  236. }
  237. .stock-info__box {
  238. padding: 0 40px;
  239. .stock-content {
  240. padding: 20px 24px;
  241. border: 1px solid @border-color;
  242. border-radius: 2px;
  243. }
  244. }
  245. }
  246. }
  247. .goods-handle {
  248. width: 240px;
  249. padding: 20px;
  250. flex-shrink: 0;
  251. background: #fff9db;
  252. }
  253. }
  254. }
  255. .main-desc__box {
  256. .desc-content {
  257. padding: 20px;
  258. background: #fff;
  259. }
  260. }
  261. }
  262. ::v-deep img {
  263. max-width: 100% !important;
  264. }
  265. </style>