shelfReview.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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>
  47. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  48. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  49. </el-form-item>
  50. </el-col>
  51. </el-row>
  52. </el-form>
  53. </el-card>
  54. </div>
  55. </transition>
  56. <!-- 上下架审核商品信息列表 -->
  57. <el-card shadow="never" class="table-card">
  58. <template #header>
  59. <div class="flex items-center justify-between">
  60. <span class="font-semibold">上下架审核商品信息列表</span>
  61. <div class="flex gap-2">
  62. <el-button type="primary" icon="Download" @click="handleExport">导出商品</el-button>
  63. <el-button type="success" icon="Upload">导入商品</el-button>
  64. <el-button circle icon="Refresh" @click="getList"></el-button>
  65. </div>
  66. </div>
  67. </template>
  68. <el-table v-loading="loading" border :data="baseList" :height="tableHeight" @selection-change="handleSelectionChange">
  69. <el-table-column type="selection" width="55" align="center" />
  70. <el-table-column label="商品图片" align="center" prop="productImage" width="100" >
  71. <template #default="scope">
  72. <image-preview :src="scope.row.productImage" :width="60" :height="60"/>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="商品编号" align="center" prop="productNo" width="120" >
  76. <template #default="scope">
  77. <el-link type="primary" @click="handleView(scope.row)">{{ scope.row.productNo }}</el-link>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="商品信息" align="center" min-width="250" show-overflow-tooltip>
  81. <template #default="scope">
  82. <div class="text-left">
  83. <div>{{ scope.row.itemName }}</div>
  84. <div class="text-gray-500" style="font-size: 12px;">品牌: {{ scope.row.brandName || '-' }}</div>
  85. </div>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="基本情况" align="center" width="180">
  89. <template #default="scope">
  90. <div class="text-left" style="font-size: 12px;">
  91. <div>
  92. <span class="text-gray-500">商品分类:</span>
  93. <span>{{ scope.row.categoryName || '-' }}</span>
  94. </div>
  95. <div>
  96. <span class="text-gray-500">单位:</span>
  97. <span>{{ scope.row.unitName || '-' }}</span>
  98. </div>
  99. </div>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="SKU价格" align="center" width="180">
  103. <template #default="scope">
  104. <div class="text-left" style="font-size: 12px;">
  105. <div>
  106. <span class="text-gray-500">市场价:</span>
  107. <span class="text-red-500">¥{{ scope.row.marketPrice || '0.00' }}</span>
  108. </div>
  109. <div>
  110. <span class="text-gray-500">会员价:</span>
  111. <span class="text-red-500">¥{{ scope.row.memberPrice || '0.00' }}</span>
  112. </div>
  113. <div>
  114. <span class="text-gray-500">最低价:</span>
  115. <span class="text-red-500">¥{{ scope.row.minSellingPrice || '0.00' }}</span>
  116. </div>
  117. </div>
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="成本预算" align="center" width="150">
  121. <template #default="scope">
  122. <div class="text-left" style="font-size: 12px;">
  123. <div>
  124. <span class="text-gray-500">采购价:</span>
  125. <span>¥{{ scope.row.purchasingPrice || '0.00' }}</span>
  126. </div>
  127. <div>
  128. <span class="text-gray-500">暂估毛利率:</span>
  129. <span>{{ scope.row.tempGrossMargin || '0.0000' }}%</span>
  130. </div>
  131. </div>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="商品来源" align="center" width="100">
  135. <template #default="scope">
  136. <span>{{ scope.row.dataSource || '-' }}</span>
  137. </template>
  138. </el-table-column>
  139. <el-table-column label="商品状态" align="center" width="100">
  140. <template #default="scope">
  141. <el-tag v-if="scope.row.productStatus === '2' || scope.row.productStatus === 2" type="warning">上架中</el-tag>
  142. <el-tag v-else-if="scope.row.productStatus === '1' || scope.row.productStatus === 1" type="success">已上架</el-tag>
  143. <el-tag v-else-if="scope.row.productStatus === '0' || scope.row.productStatus === 0" type="info">已下架</el-tag>
  144. <span v-else>-</span>
  145. </template>
  146. </el-table-column>
  147. <el-table-column label="审核意见" align="center" width="180" show-overflow-tooltip>
  148. <template #default="scope">
  149. <span>{{ scope.row.shelfComments || '-' }}</span>
  150. </template>
  151. </el-table-column>
  152. <el-table-column label="操作" align="center" width="200" fixed="right" class-name="border-left">
  153. <template #default="scope">
  154. <div class="flex flex-col gap-1">
  155. <!-- 根据商品状态显示不同按钮 -->
  156. <template v-if="scope.row.productStatus === '2' || scope.row.productStatus === 2">
  157. <!-- 上架中:显示上架审核按钮 -->
  158. <div class="flex gap-1 justify-center">
  159. <el-link type="primary" :underline="false" @click="handleEdit(scope.row)">编辑</el-link>
  160. <el-link type="success" :underline="false" @click="handleShelfReview(scope.row)">上架审核</el-link>
  161. </div>
  162. </template>
  163. <template v-else-if="scope.row.productStatus === '1' || scope.row.productStatus === 1">
  164. <!-- 已上架:显示下架按钮 -->
  165. <div class="flex gap-1 justify-center">
  166. <el-link type="primary" :underline="false" @click="handleEdit(scope.row)">编辑</el-link>
  167. <el-link type="danger" :underline="false" @click="handleOffShelf(scope.row)">下架</el-link>
  168. </div>
  169. </template>
  170. </div>
  171. </template>
  172. </el-table-column>
  173. </el-table>
  174. <!-- 游标分页控制 -->
  175. <pagination
  176. v-show="baseList.length > 0"
  177. v-model:page="queryParams.pageNum"
  178. v-model:limit="queryParams.pageSize"
  179. v-model:way="queryParams.way"
  180. :cursor-mode="true"
  181. :has-more="hasMore"
  182. @pagination="getList"
  183. />
  184. </el-card>
  185. <!-- 上架审核对话框 -->
  186. <el-dialog v-model="reviewDialog.visible" :title="reviewDialog.title" width="600px" append-to-body>
  187. <el-form ref="reviewFormRef" :model="reviewForm" :rules="reviewRules" label-width="100px">
  188. <el-form-item label="商品编号">
  189. <el-input v-model="reviewForm.productNo" disabled />
  190. </el-form-item>
  191. <el-form-item label="商品名称">
  192. <el-input v-model="reviewForm.itemName" disabled />
  193. </el-form-item>
  194. <el-form-item label="审核结果" prop="productStatus">
  195. <el-radio-group v-model="reviewForm.productStatus">
  196. <el-radio :label="1">通过上架</el-radio>
  197. <el-radio :label="0">驳回下架</el-radio>
  198. </el-radio-group>
  199. </el-form-item>
  200. <el-form-item label="审核意见" prop="shelfComments">
  201. <el-input v-model="reviewForm.shelfComments" type="textarea" :rows="4" placeholder="请输入审核意见" />
  202. </el-form-item>
  203. </el-form>
  204. <template #footer>
  205. <div class="dialog-footer">
  206. <el-button @click="reviewDialog.visible = false">取消</el-button>
  207. <el-button type="primary" @click="submitReview">确定</el-button>
  208. </div>
  209. </template>
  210. </el-dialog>
  211. </div>
  212. </template>
  213. <script setup name="ShelfReview" lang="ts">
  214. import { listBase, getBase, shelfReview, brandList, categoryTree } from '@/api/pmsProduct/base';
  215. import { BaseVO, BaseQuery, BaseForm } from '@/api/pmsProduct/base/types';
  216. import { BrandVO } from '@/api/pmsProduct/brand/types';
  217. import { categoryTreeVO } from '@/api/pmsProduct/category/types';
  218. import { useRouter, useRoute } from 'vue-router';
  219. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  220. const router = useRouter();
  221. const route = useRoute();
  222. const baseList = ref<BaseVO[]>([]);
  223. const loading = ref(true);
  224. const showSearch = ref(true);
  225. const ids = ref<Array<string | number>>([]);
  226. const single = ref(true);
  227. const multiple = ref(true);
  228. const total = ref(0);
  229. const brandOptions = ref<BrandVO[]>([]);
  230. const brandLoading = ref(false);
  231. const brandOptionsFormatted = computed(() => {
  232. return brandOptions.value.slice(0, 500).map((item) => ({
  233. label: item.brandName,
  234. value: item.brandName // review.vue使用brandName作为value
  235. }));
  236. });
  237. const categoryOptions = ref<categoryTreeVO[]>([]);
  238. const hasMore = ref(true); // 是否还有更多数据
  239. const pageHistory = ref([]);
  240. // 动态计算表格高度
  241. const tableHeight = computed(() => {
  242. // 基础高度 = 视口高度 - 顶部导航(84) - 容器padding(16) - 搜索区域 - 卡片header(60) - 分页器(60)
  243. const baseHeight = window.innerHeight - 84 - 16;
  244. const searchHeight = showSearch.value ? 150 : 10; // 搜索区域高度
  245. const cardHeaderHeight = 60; // 卡片header高度
  246. const paginationHeight = 60; // 分页器高度
  247. return baseHeight - searchHeight - cardHeaderHeight - paginationHeight;
  248. });
  249. const queryFormRef = ref<ElFormInstance>();
  250. const reviewFormRef = ref<ElFormInstance>();
  251. // 审核对话框
  252. const reviewDialog = reactive({
  253. visible: false,
  254. title: '上架审核'
  255. });
  256. // 审核表单
  257. const reviewForm = ref<any>({
  258. id: undefined,
  259. productNo: '',
  260. itemName: '',
  261. productStatus: 1,
  262. shelfComments: ''
  263. });
  264. // 审核表单验证规则
  265. const reviewRules = ref({
  266. productStatus: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
  267. shelfComments: [{ required: true, message: '请输入审核意见', trigger: 'blur' }]
  268. });
  269. const queryParams = ref<BaseQuery>({
  270. pageNum: 1,
  271. pageSize: 10,
  272. way: undefined,
  273. productNo: undefined,
  274. itemName: undefined,
  275. brandName: undefined,
  276. purchaseNature: undefined,
  277. bottomCategoryId: undefined,
  278. isSelf: undefined,
  279. productReviewStatus: 1, // 只查询审核通过的数据
  280. productStatus: 2, // 用于筛选商品状态
  281. lastSeenId: undefined // 游标分页的lastSeenId
  282. });
  283. /** 查询商品列表 */
  284. const getList = async () => {
  285. loading.value = true;
  286. try {
  287. const params = { ...queryParams.value };
  288. const currentPageNum = queryParams.value.pageNum;
  289. // 强制只查询审核通过的数据
  290. params.productReviewStatus = 1;
  291. // 如果没有选择商品状态,默认查询上架中和已上架的数据
  292. // 后端需要支持多状态查询,这里通过不传productStatus让后端返回所有状态,前端再过滤
  293. // 或者后端支持传入多个状态值
  294. // 第一页不需要游标参数
  295. if (currentPageNum === 1) {
  296. delete params.lastSeenId;
  297. delete params.way;
  298. } else {
  299. // way参数:0=上一页,1=下一页
  300. if (queryParams.value.way === 0) {
  301. // 上一页:使用目标页(即当前显示页)的firstId
  302. const nextPageHistory = pageHistory.value[currentPageNum];
  303. if (nextPageHistory) {
  304. params.firstSeenId = nextPageHistory.firstId;
  305. params.way = 0;
  306. }
  307. } else {
  308. // 下一页:使用前一页的lastId作为lastSeenId
  309. const prevPageHistory = pageHistory.value[currentPageNum - 1];
  310. if (prevPageHistory) {
  311. params.lastSeenId = prevPageHistory.lastId;
  312. params.way = 1;
  313. }
  314. }
  315. }
  316. const res = await listBase(params);
  317. baseList.value = res.rows || [];
  318. // 判断是否还有更多数据
  319. hasMore.value = baseList.value.length === queryParams.value.pageSize;
  320. // 记录当前页的第一个id和最后一个id
  321. if (baseList.value.length > 0) {
  322. const firstItem = baseList.value[0];
  323. const lastItem = baseList.value[baseList.value.length - 1];
  324. //如果长度小于currentPageNum则创建
  325. if (pageHistory.value.length <= currentPageNum) {
  326. pageHistory.value[currentPageNum] = {
  327. firstId: firstItem.id,
  328. lastId: lastItem.id
  329. };
  330. }
  331. }
  332. total.value = res.total || 0;
  333. } catch (error) {
  334. console.error('获取列表失败:', error);
  335. } finally {
  336. loading.value = false;
  337. }
  338. };
  339. /** 初始化路由参数 */
  340. const initRouteParams = () => {
  341. // 从路由参数中获取筛选条件
  342. if (route.query.productStatus) {
  343. queryParams.value.productStatus = Number(route.query.productStatus);
  344. }
  345. if (route.query.brandName) {
  346. queryParams.value.brandName = route.query.brandName as string;
  347. }
  348. if (route.query.bottomCategoryId) {
  349. queryParams.value.bottomCategoryId = route.query.bottomCategoryId as string;
  350. }
  351. };
  352. /** 搜索按钮操作 */
  353. const handleQuery = () => {
  354. queryParams.value.pageNum = 1;
  355. queryParams.value.lastSeenId = undefined;
  356. pageHistory.value = [0]; // 重置页面历史
  357. getList();
  358. };
  359. /** 重置按钮操作 */
  360. const resetQuery = () => {
  361. queryFormRef.value?.resetFields();
  362. queryParams.value.lastSeenId = undefined;
  363. pageHistory.value = [0]; // 重置页面历史
  364. handleQuery();
  365. };
  366. /** 多选框选中数据 */
  367. const handleSelectionChange = (selection: BaseVO[]) => {
  368. ids.value = selection.map((item) => item.id);
  369. single.value = selection.length != 1;
  370. multiple.value = !selection.length;
  371. };
  372. /** 导出按钮操作 */
  373. const handleExport = () => {
  374. proxy?.download(
  375. 'product/base/export',
  376. {
  377. ...queryParams.value
  378. },
  379. `base_shelf_review_${new Date().getTime()}.xlsx`
  380. );
  381. };
  382. /** 查看商品详情 */
  383. const handleView = (row: BaseVO) => {
  384. router.push(`/product/base/detail/${row.id}`);
  385. };
  386. /** 编辑商品 */
  387. const handleEdit = (row: BaseVO) => {
  388. router.push(`/product/base/edit/${row.id}`);
  389. };
  390. /** 上架审核 */
  391. const handleShelfReview = (row: BaseVO) => {
  392. reviewDialog.visible = true;
  393. reviewDialog.title = '上架审核';
  394. reviewForm.value = {
  395. id: row.id,
  396. productNo: row.productNo,
  397. itemName: row.itemName,
  398. productStatus: 1,
  399. shelfComments: ''
  400. };
  401. }
  402. /** 下架操作 */
  403. const handleOffShelf = async (row: BaseVO) => {
  404. await proxy?.$modal.confirm('确认下架该商品吗?');
  405. const data: BaseForm = {
  406. id: row.id,
  407. productStatus: '0' // 设置为下架状态
  408. };
  409. await shelfReview(data);
  410. proxy?.$modal.msgSuccess('下架成功');
  411. await getList();
  412. };
  413. /** 提交审核 */
  414. const submitReview = async () => {
  415. await reviewFormRef.value?.validate();
  416. const data: BaseForm = {
  417. id: reviewForm.value.id,
  418. productStatus: String(reviewForm.value.productStatus),
  419. shelfComments: reviewForm.value.shelfComments
  420. };
  421. await shelfReview(data);
  422. proxy?.$modal.msgSuccess(reviewForm.value.productStatus === 1 ? '上架成功' : '驳回成功');
  423. reviewDialog.visible = false;
  424. await getList();
  425. };
  426. /** 查询品牌列表(实时请求,每次只加载500条) */
  427. const getBrandList = async () => {
  428. try {
  429. brandLoading.value = true;
  430. const res = await brandList({ pageNum: 1, pageSize: 500 });
  431. brandOptions.value = res.data || [];
  432. } catch (error) {
  433. console.error('获取品牌列表失败:', error);
  434. } finally {
  435. brandLoading.value = false;
  436. }
  437. };
  438. /** 处理品牌下拉框显示/隐藏 */
  439. const handleBrandVisibleChange = (visible: boolean) => {
  440. if (visible && brandOptions.value.length === 0) {
  441. getBrandList();
  442. }
  443. };
  444. /** 查询分类树 */
  445. const getCategoryTree = async () => {
  446. const res = await categoryTree();
  447. categoryOptions.value = res.data || [];
  448. };
  449. onMounted(() => {
  450. getCategoryTree();
  451. initRouteParams();
  452. getList();
  453. });
  454. </script>
  455. <style scoped lang="scss">
  456. .app-container {
  457. padding: 8px;
  458. height: calc(100vh - 84px);
  459. display: flex;
  460. flex-direction: column;
  461. overflow: hidden;
  462. }
  463. .table-card {
  464. flex: 1;
  465. display: flex;
  466. flex-direction: column;
  467. overflow: hidden;
  468. :deep(.el-card__body) {
  469. flex: 1;
  470. display: flex;
  471. flex-direction: column;
  472. overflow: hidden;
  473. }
  474. :deep(.el-table) {
  475. flex: 1;
  476. }
  477. // 确保固定列左侧有边框
  478. :deep(.el-table__fixed-right) {
  479. box-shadow: -1px 0 0 var(--el-table-border-color) !important;
  480. }
  481. // 固定列的单元格左边框
  482. :deep(.el-table__fixed-right .el-table__cell) {
  483. border-left: 1px solid var(--el-table-border-color) !important;
  484. }
  485. }
  486. </style>