shelfReview.vue 20 KB

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