selected.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索区域 -->
  4. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  5. <div v-show="showSearch" class="mb-[10px]">
  6. <el-card shadow="hover">
  7. <el-form ref="queryFormRef" :model="queryParams" label-width="100px">
  8. <el-row :gutter="20">
  9. <el-col :span="6">
  10. <el-form-item label="商品编号" prop="productNo">
  11. <el-input v-model="queryParams.productNo" placeholder="请输入商品编号" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="6">
  15. <el-form-item label="商品名称" prop="itemName">
  16. <el-input v-model="queryParams.itemName" placeholder="请输入商品名称" clearable @keyup.enter="handleQuery" />
  17. </el-form-item>
  18. </el-col>
  19. <el-col :span="6">
  20. <el-form-item label="商品类别" prop="bottomCategoryId">
  21. <el-tree-select
  22. v-model="queryParams.bottomCategoryId"
  23. :data="categoryOptions"
  24. :props="{ value: 'id', label: 'label', children: 'children' } as any"
  25. value-key="id"
  26. placeholder="请选择商品类别"
  27. clearable
  28. check-strictly
  29. />
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="6">
  33. <el-form-item label="商品品牌" prop="brandName">
  34. <el-select-v2
  35. v-model="queryParams.brandName"
  36. :options="brandOptionsFormatted"
  37. placeholder="请选择商品品牌"
  38. clearable
  39. filterable
  40. :loading="brandLoading"
  41. @visible-change="handleBrandVisibleChange"
  42. />
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="6">
  46. <el-form-item label="审核状态" prop="auditStatus">
  47. <el-select
  48. v-model="queryParams.auditStatus"
  49. placeholder="请选择审核状态"
  50. clearable
  51. >
  52. <el-option label="待审核" :value="1" />
  53. <el-option label="审核通过" :value="2" />
  54. <el-option label="审核驳回" :value="3" />
  55. </el-select>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="6">
  59. <el-form-item>
  60. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  61. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  62. </el-form-item>
  63. </el-col>
  64. </el-row>
  65. </el-form>
  66. </el-card>
  67. </div>
  68. </transition>
  69. <!-- 审核商品信息列表 -->
  70. <el-card shadow="never" class="table-card">
  71. <template #header>
  72. <div class="flex items-center justify-between">
  73. <span class="font-semibold">审核商品信息列表</span>
  74. <div class="flex gap-2">
  75. <el-button circle icon="Refresh" @click="getList"></el-button>
  76. </div>
  77. </div>
  78. </template>
  79. <el-table v-loading="loading" border :data="baseList" :height="tableHeight" @selection-change="handleSelectionChange">
  80. <el-table-column type="selection" width="55" align="center" />
  81. <el-table-column label="商品图片" align="center" prop="productImage" width="100" >
  82. <template #default="scope">
  83. <image-preview :src="scope.row.productImage" :width="60" :height="60"/>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="商品编号" align="center" prop="productNo" width="120" >
  87. <template #default="scope">
  88. <el-link type="primary" @click="handleView(scope.row)">{{ scope.row.productNo }}</el-link>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="商品信息" align="center" min-width="250" show-overflow-tooltip>
  92. <template #default="scope">
  93. <div class="text-left">
  94. <div>{{ scope.row.itemName }}</div>
  95. <div class="text-gray-500" style="font-size: 12px;">品牌: {{ scope.row.brandName || '-' }}</div>
  96. </div>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="基本情况" align="center" width="180">
  100. <template #default="scope">
  101. <div class="text-left" style="font-size: 12px;">
  102. <div>
  103. <span class="text-gray-500">商品分类:</span>
  104. <span>{{ scope.row.categoryName || '-' }}</span>
  105. </div>
  106. <div>
  107. <span class="text-gray-500">单位:</span>
  108. <span>{{ scope.row.unitName || '-' }}</span>
  109. </div>
  110. </div>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="SKU价格" align="center" width="180">
  114. <template #default="scope">
  115. <div class="text-left" style="font-size: 12px">
  116. <div>
  117. <span class="text-gray-500">市场价:</span>
  118. <span class="text-red-500">¥{{ scope.row.marketPrice || '0.00' }}</span>
  119. </div>
  120. <div>
  121. <span class="text-gray-500">官网价:</span>
  122. <span class="text-red-500">¥{{ scope.row.memberPrice || '0.00' }}</span>
  123. </div>
  124. <div>
  125. <span class="text-gray-500">最低价:</span>
  126. <span class="text-red-500">¥{{ scope.row.minSellingPrice || '0.00' }}</span>
  127. </div>
  128. </div>
  129. </template>
  130. </el-table-column>
  131. <el-table-column label="成本预算" align="center" width="150">
  132. <template #default="scope">
  133. <div class="text-left" style="font-size: 12px;">
  134. <div>
  135. <span class="text-gray-500">采购价:</span>
  136. <span>¥{{ scope.row.purchasingPrice || '0.00' }}</span>
  137. </div>
  138. <div>
  139. <span class="text-gray-500">暂估毛利率:</span>
  140. <span>{{ scope.row.tempGrossMargin || '0.00' }}%</span>
  141. </div>
  142. </div>
  143. </template>
  144. </el-table-column>
  145. <el-table-column label="商品来源" align="center" width="100">
  146. <template #default="scope">
  147. <span>{{ scope.row.dataSource || '-' }}</span>
  148. </template>
  149. </el-table-column>
  150. <el-table-column label="商品状态" align="center" width="100">
  151. <template #default="scope">
  152. <el-tag v-if="scope.row.auditStatus === 1" type="warning">待审核</el-tag>
  153. <el-tag v-else-if="scope.row.auditStatus === 2" type="success">审核通过</el-tag>
  154. <el-tag v-else-if="scope.row.auditStatus === 3" type="danger">审核驳回</el-tag>
  155. <span v-else>-</span>
  156. </template>
  157. </el-table-column>
  158. <el-table-column label="审核意见" align="center" width="180" show-overflow-tooltip>
  159. <template #default="scope">
  160. <span>{{ scope.row.auditReason || '-' }}</span>
  161. </template>
  162. </el-table-column>
  163. <el-table-column label="操作" align="center" width="150" fixed="right" class-name="border-left">
  164. <template #default="scope">
  165. <div class="flex gap-1 justify-center">
  166. <el-link type="primary" :underline="false" @click="handleView(scope.row)">详情</el-link>
  167. <el-link type="primary" :underline="false" @click="handleUpdate(scope.row)">编辑</el-link>
  168. <el-link v-if="scope.row.auditStatus === 2" type="warning" :underline="false" @click="handleOffShelf(scope.row)">下架</el-link>
  169. </div>
  170. </template>
  171. </el-table-column>
  172. </el-table>
  173. <!-- 游标分页控制 -->
  174. <pagination
  175. v-show="baseList.length > 0"
  176. v-model:page="queryParams.pageNum"
  177. v-model:limit="queryParams.pageSize"
  178. v-model:way="queryParams.way"
  179. :cursor-mode="true"
  180. :has-more="hasMore"
  181. @pagination="getList"
  182. />
  183. </el-card>
  184. </div>
  185. </template>
  186. <script setup name="BaseReview" lang="ts">
  187. import { getGoodProductPage, brandList, categoryTree } from '@/api/product/base';
  188. import { BaseVO, BaseQuery } from '@/api/product/base/types';
  189. import { updateProductExquisite } from '@/api/product/productExquisite';
  190. import { BrandVO } from '@/api/product/brand/types';
  191. import { categoryTreeVO } from '@/api/product/category/types';
  192. import { useRouter, useRoute } from 'vue-router';
  193. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  194. const router = useRouter();
  195. const route = useRoute();
  196. const baseList = ref<BaseVO[]>([]);
  197. const loading = ref(true);
  198. const showSearch = ref(true);
  199. const ids = ref<Array<string | number>>([]);
  200. const single = ref(true);
  201. const multiple = ref(true);
  202. const total = ref(0);
  203. const brandOptions = ref<BrandVO[]>([]);
  204. const brandLoading = ref(false);
  205. const brandOptionsFormatted = computed(() => {
  206. return brandOptions.value.slice(0, 500).map((item) => ({
  207. label: item.brandName,
  208. value: item.brandName // review.vue使用brandName作为value
  209. }));
  210. });
  211. const categoryOptions = ref<categoryTreeVO[]>([]);
  212. const hasMore = ref(true); // 是否还有更多数据
  213. const pageHistory = ref([]);
  214. // 动态计算表格高度
  215. const tableHeight = computed(() => {
  216. // 基础高度 = 视口高度 - 顶部导航(84) - 容器padding(16) - 搜索区域 - 卡片header(60) - 分页器(60)
  217. const baseHeight = window.innerHeight - 84 - 16;
  218. const searchHeight = showSearch.value ? 150 : 10; // 搜索区域高度
  219. const cardHeaderHeight = 60; // 卡片header高度
  220. const paginationHeight = 60; // 分页器高度
  221. return baseHeight - searchHeight - cardHeaderHeight - paginationHeight;
  222. });
  223. const queryFormRef = ref<ElFormInstance>();
  224. const queryParams = ref<BaseQuery & { auditStatus?: number }>({
  225. pageNum: 1,
  226. pageSize: 10,
  227. way: undefined,
  228. productNo: undefined,
  229. itemName: undefined,
  230. brandName: undefined,
  231. purchaseNature: undefined,
  232. bottomCategoryId: undefined,
  233. isSelf: undefined,
  234. auditStatus: undefined,
  235. productStatus: undefined,
  236. lastSeenId: undefined // 游标分页的lastSeenId
  237. });
  238. /** 查询商品列表 */
  239. const getList = async () => {
  240. loading.value = true;
  241. try {
  242. const params = { ...queryParams.value };
  243. const currentPageNum = queryParams.value.pageNum;
  244. // 第一页不需要游标参数
  245. if (currentPageNum === 1) {
  246. delete params.lastSeenId;
  247. delete params.way;
  248. } else {
  249. // way参数:0=上一页,1=下一页
  250. if (queryParams.value.way === 0) {
  251. // 上一页:使用目标页(即当前显示页)的firstId
  252. const nextPageHistory = pageHistory.value[currentPageNum];
  253. if (nextPageHistory) {
  254. params.firstSeenId = nextPageHistory.firstId;
  255. params.way = 0;
  256. }
  257. } else {
  258. // 下一页:使用前一页的lastId作为lastSeenId
  259. const prevPageHistory = pageHistory.value[currentPageNum - 1];
  260. if (prevPageHistory) {
  261. params.lastSeenId = prevPageHistory.lastId;
  262. params.way = 1;
  263. }
  264. }
  265. }
  266. const res = await getGoodProductPage(params);
  267. baseList.value = res.rows || [];
  268. // 判断是否还有更多数据
  269. hasMore.value = baseList.value.length === queryParams.value.pageSize;
  270. // 记录当前页的第一个id和最后一个id
  271. if (baseList.value.length > 0) {
  272. const firstItem = baseList.value[0];
  273. const lastItem = baseList.value[baseList.value.length - 1];
  274. //如果长度小于currentPageNum则创建
  275. if (pageHistory.value.length <= currentPageNum) {
  276. pageHistory.value[currentPageNum] = {
  277. firstId: firstItem.id,
  278. lastId: lastItem.id
  279. };
  280. }
  281. }
  282. total.value = res.total || 0;
  283. } catch (error) {
  284. console.error('获取列表失败:', error);
  285. } finally {
  286. loading.value = false;
  287. }
  288. };
  289. /** 初始化路由参数 */
  290. const initRouteParams = () => {
  291. // 从路由参数中获取筛选条件
  292. if (route.query.auditStatus) {
  293. queryParams.value.auditStatus = Number(route.query.auditStatus);
  294. }
  295. if (route.query.brandName) {
  296. queryParams.value.brandName = route.query.brandName as string;
  297. }
  298. if (route.query.bottomCategoryId) {
  299. queryParams.value.bottomCategoryId = route.query.bottomCategoryId as string;
  300. }
  301. };
  302. /** 搜索按钮操作 */
  303. const handleQuery = () => {
  304. queryParams.value.pageNum = 1;
  305. queryParams.value.lastSeenId = undefined;
  306. pageHistory.value = [0]; // 重置页面历史
  307. getList();
  308. };
  309. /** 重置按钮操作 */
  310. const resetQuery = () => {
  311. queryFormRef.value?.resetFields();
  312. queryParams.value.lastSeenId = undefined;
  313. pageHistory.value = [0]; // 重置页面历史
  314. handleQuery();
  315. };
  316. /** 多选框选中数据 */
  317. const handleSelectionChange = (selection: BaseVO[]) => {
  318. ids.value = selection.map((item) => item.id);
  319. single.value = selection.length != 1;
  320. multiple.value = !selection.length;
  321. };
  322. /** 导出按钮操作 */
  323. const handleExport = () => {
  324. proxy?.download(
  325. 'product/base/export',
  326. {
  327. ...queryParams.value
  328. },
  329. `base_review_${new Date().getTime()}.xlsx`
  330. );
  331. };
  332. /** 查看商品详情 */
  333. const handleView = (row: BaseVO) => {
  334. const url = `https://item.xiaoluwebsite.xyz/item?id=${row.id}`;
  335. window.open(url, '_blank');
  336. };
  337. /** 编辑商品 */
  338. const handleUpdate = (row: BaseVO) => {
  339. router.push(`/product/base/edit/${row.id}`);
  340. };
  341. /** 下架操作 */
  342. const handleOffShelf = async (row: BaseVO) => {
  343. await proxy?.$modal.confirm('确认下架该精选商品吗?');
  344. try {
  345. await updateProductExquisite({
  346. id: row.exquisiteId,
  347. auditStatus: 3,
  348. auditReason: '下架操作'
  349. });
  350. proxy?.$modal.msgSuccess('下架成功');
  351. await getList();
  352. } catch (error) {
  353. console.error('下架失败:', error);
  354. proxy?.$modal.msgError('下架失败');
  355. }
  356. };
  357. /** 查询品牌列表(实时请求,每次只加载500条) */
  358. const getBrandList = async () => {
  359. try {
  360. brandLoading.value = true;
  361. const res = await brandList({ pageNum: 1, pageSize: 500 });
  362. brandOptions.value = res.data || [];
  363. } catch (error) {
  364. console.error('获取品牌列表失败:', error);
  365. } finally {
  366. brandLoading.value = false;
  367. }
  368. };
  369. /** 处理品牌下拉框显示/隐藏 */
  370. const handleBrandVisibleChange = (visible: boolean) => {
  371. if (visible && brandOptions.value.length === 0) {
  372. getBrandList();
  373. }
  374. };
  375. /** 查询分类树 */
  376. const getCategoryTree = async () => {
  377. const res = await categoryTree();
  378. categoryOptions.value = res.data || [];
  379. };
  380. onMounted(() => {
  381. getCategoryTree();
  382. initRouteParams();
  383. getList();
  384. });
  385. </script>
  386. <style scoped lang="scss">
  387. .app-container {
  388. padding: 8px;
  389. height: calc(100vh - 84px);
  390. display: flex;
  391. flex-direction: column;
  392. overflow: hidden;
  393. }
  394. .table-card {
  395. flex: 1;
  396. display: flex;
  397. flex-direction: column;
  398. overflow: hidden;
  399. :deep(.el-card__body) {
  400. flex: 1;
  401. display: flex;
  402. flex-direction: column;
  403. overflow: hidden;
  404. }
  405. :deep(.el-table) {
  406. flex: 1;
  407. }
  408. // 确保固定列左侧有边框
  409. :deep(.el-table__fixed-right) {
  410. box-shadow: -1px 0 0 var(--el-table-border-color) !important;
  411. }
  412. // 固定列的单元格左边框
  413. :deep(.el-table__fixed-right .el-table__cell) {
  414. border-left: 1px solid var(--el-table-border-color) !important;
  415. }
  416. }
  417. </style>