index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. height: 380px;
  133. border-radius: 5px;
  134. }
  135. .solve-title {
  136. width: 100%;
  137. margin-top: 10px;
  138. .title1 {
  139. font-size: 20px;
  140. font-weight: bold;
  141. margin-bottom: 5px;
  142. }
  143. .title2 {
  144. font-size: 14px;
  145. color: #666666;
  146. border-bottom: 1px solid #e5e7eb;
  147. padding-bottom: 10px;
  148. }
  149. }
  150. //数据
  151. .data-bos {
  152. margin-top: 15px;
  153. .data-box {
  154. width: 100%;
  155. display: flex;
  156. flex-wrap: wrap;
  157. gap: 20px;
  158. .data-list {
  159. flex: 0 0 calc((100% - 80px) / 5);
  160. width: 0;
  161. background: #f4f4f4;
  162. border-radius: 5px;
  163. padding: 20px 20px 22px 20px;
  164. cursor: pointer;
  165. transition:
  166. transform 0.2s ease,
  167. box-shadow 0.2s ease;
  168. display: flex;
  169. flex-direction: column;
  170. &:hover {
  171. transform: translateY(-2px);
  172. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  173. .data-title {
  174. color: #e7000b !important;
  175. }
  176. }
  177. .data-img {
  178. width: 100%;
  179. height: 184px;
  180. border-radius: 5px;
  181. }
  182. .data-title {
  183. margin-top: 4px;
  184. font-size: 14px;
  185. color: #101828;
  186. height: 40px;
  187. }
  188. .money {
  189. margin-top: 4px;
  190. .money1 {
  191. font-size: 16px;
  192. color: #e7000b;
  193. }
  194. .money2 {
  195. font-size: 12px;
  196. color: #99a1af;
  197. text-decoration: line-through;
  198. padding-left: 6px;
  199. }
  200. }
  201. .data-cat {
  202. width: 86px;
  203. height: 26px;
  204. background: #e7000b;
  205. border-radius: 2px;
  206. font-size: 14px;
  207. color: #ffffff;
  208. line-height: 26px;
  209. text-align: center;
  210. margin-top: 16px;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. }
  217. </style>