index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="solve-page">
  3. <div class="solve-bos">
  4. <el-image class="solve-img" :src="dataInfo.coverImage" fit="cover" />
  5. <div v-for="(item, index) in dataList" :key="index">
  6. <!-- 标题 -->
  7. <div class="solve-title">
  8. <div class="title1">{{ item.title }}</div>
  9. <div class="title2">{{ item.subtitle }}</div>
  10. </div>
  11. <!-- 数据 -->
  12. <div class="data-bos">
  13. <div class="data-box">
  14. <div
  15. v-for="(item1, index1) in item.list"
  16. :key="index1"
  17. class="data-list"
  18. @click="onPath('/item?id=' + item1.id + '&productNo=' + item1.productNo)"
  19. >
  20. <el-image class="data-img" :src="item1.productImage" fit="cover" />
  21. <div class="data-title ellipsis">{{ item1.itemName }}</div>
  22. <div class="money">
  23. <span class="money1">¥{{ item1.memberPrice }}</span>
  24. <span class="money2">¥{{ item1.marketPrice }}</span>
  25. </div>
  26. <div class="data-cat" @click.stop="onCart(item1)">加入购物车</div>
  27. </div>
  28. </div>
  29. <div class="flex-row-center w100%" v-if="item.list.length === 0">
  30. <el-empty description="暂无数据" />
  31. </div>
  32. <!-- 游标分页控制 -->
  33. <TablePagination v-model:page="item.pageNum" v-model:page-size="item.pageSize" :total="item.total" @change="getList(item)" />
  34. </div>
  35. </div>
  36. <div class="flex-row-center w100%" v-if="dataList.length === 0">
  37. <el-empty description="暂无数据" />
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script setup lang="ts">
  43. import { onPath } from '@/utils/siteConfig';
  44. import { getProcurementProgramDetail, getProcurementProgramGroupList, getProcurementProgramGroupProductList } from '@/api/plan/index';
  45. import { addProductShoppingCart } from '@/api/goods/index';
  46. const id = ref<any>(null);
  47. const dataInfo = ref<any>({});
  48. const dataList = ref<any>({});
  49. const route = useRoute();
  50. onMounted(() => {
  51. id.value = route.query.id;
  52. getInfo();
  53. });
  54. const getInfo = async () => {
  55. try {
  56. // 获取采购计划详情
  57. const detailRes = await getProcurementProgramDetail(id.value);
  58. if (detailRes.code === 200) {
  59. dataInfo.value = detailRes.data;
  60. }
  61. // 获取采购计划分组列表
  62. const groupRes = await getProcurementProgramGroupList(id.value);
  63. if (groupRes.code === 200) {
  64. // 使用 Promise.all 等待所有 onGoods 异步操作完成
  65. const updatedData = await Promise.all(
  66. groupRes.data.map(async (item: any) => {
  67. item.pageSize = 10;
  68. item.pageNum = 1;
  69. item.hasMore = false;
  70. const productList: any = await onGoods(item); // 等待每个分组的商品列表加载完成
  71. item.total = productList.total;
  72. return {
  73. ...item,
  74. list: productList.rows // 将商品列表赋值给 item.List
  75. };
  76. })
  77. );
  78. dataList.value = updatedData; // 更新 dataList
  79. }
  80. } catch (error) {
  81. console.error('获取数据失败:', error);
  82. }
  83. };
  84. // 修改 onGoods 返回 Promise
  85. const onGoods = async (item: any) => {
  86. try {
  87. const res = await getProcurementProgramGroupProductList({ groupId: item.id, pageSize: item.pageSize, pageNum: item.pageNum });
  88. if (res.code === 200) {
  89. return res; // 返回商品列表
  90. }
  91. return []; // 如果请求失败,返回空数组
  92. } catch (error) {
  93. console.error('获取商品列表失败:', error);
  94. return []; // 异常情况下也返回空数组
  95. }
  96. };
  97. const getList = (row: any) => {
  98. getProcurementProgramGroupProductList({ groupId: row.id, pageSize: row.pageSize, pageNum: row.pageNum }).then((res) => {
  99. if (res.code == 200) {
  100. row.list = res.rows;
  101. row.total = res.total;
  102. }
  103. });
  104. };
  105. import { cartStore } from '@/store/modules/cart';
  106. const cart = cartStore();
  107. //加入购物车
  108. const onCart = (row: any) => {
  109. addProductShoppingCart({
  110. productId: row.id,
  111. productNum: 1
  112. }).then((res) => {
  113. if (res.code == 200) {
  114. cart.onCartCount();
  115. ElMessage.success('加入购物车成功');
  116. }
  117. });
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .solve-page {
  122. width: 100%;
  123. background-color: #ffffff;
  124. .solve-bos {
  125. width: 100%;
  126. min-width: 1200px;
  127. max-width: 1500px;
  128. margin: 0 auto;
  129. padding-bottom: 30px;
  130. .solve-img {
  131. width: 100%;
  132. aspect-ratio: 1200 / 360;
  133. // height: 380px;
  134. border-radius: 5px;
  135. }
  136. .solve-title {
  137. width: 100%;
  138. margin-top: 10px;
  139. .title1 {
  140. font-size: 20px;
  141. font-weight: bold;
  142. margin-bottom: 5px;
  143. }
  144. .title2 {
  145. font-size: 14px;
  146. color: #666666;
  147. border-bottom: 1px solid #e5e7eb;
  148. padding-bottom: 10px;
  149. }
  150. }
  151. //数据
  152. .data-bos {
  153. margin-top: 15px;
  154. .data-box {
  155. width: 100%;
  156. display: flex;
  157. flex-wrap: wrap;
  158. gap: 20px;
  159. .data-list {
  160. flex: 0 0 calc((100% - 80px) / 5);
  161. width: 0;
  162. background: #f4f4f4;
  163. border-radius: 5px;
  164. padding: 20px 20px 22px 20px;
  165. cursor: pointer;
  166. transition:
  167. transform 0.2s ease,
  168. box-shadow 0.2s ease;
  169. display: flex;
  170. flex-direction: column;
  171. &:hover {
  172. transform: translateY(-2px);
  173. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  174. .data-title {
  175. color: #e7000b !important;
  176. }
  177. }
  178. .data-img {
  179. width: 100%;
  180. aspect-ratio: 1;
  181. // height: 184px;
  182. border-radius: 5px;
  183. margin-bottom: 10px;
  184. }
  185. .data-title {
  186. margin-top: 4px;
  187. font-size: 14px;
  188. color: #101828;
  189. height: 40px;
  190. }
  191. .money {
  192. margin-top: 4px;
  193. .money1 {
  194. font-size: 16px;
  195. color: #e7000b;
  196. }
  197. .money2 {
  198. font-size: 12px;
  199. color: #99a1af;
  200. text-decoration: line-through;
  201. padding-left: 6px;
  202. }
  203. }
  204. .data-cat {
  205. width: 86px;
  206. height: 26px;
  207. background: #e7000b;
  208. border-radius: 2px;
  209. font-size: 14px;
  210. color: #ffffff;
  211. line-height: 26px;
  212. text-align: center;
  213. margin-top: 16px;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. </style>