shelfReview.vue 19 KB

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