inventory.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div class="safety-platform-container">
  3. <header class="safety-platform-container__header">
  4. <div class="breadcrumb-title"> 物品库存管理 </div>
  5. </header>
  6. <main class="safety-platform-container__main">
  7. <div class="search-table-container">
  8. <header>
  9. <div style="position: relative">
  10. <el-button type="primary" class="search-table-container--button" @click="handleCreate">
  11. 添加
  12. </el-button>
  13. <el-button plain class="search-table-container--button" @click="handleImport">
  14. 导入
  15. </el-button>
  16. <el-button plain class="search-table-container--button" @click="handleDownload">
  17. 导出
  18. </el-button>
  19. </div>
  20. <div class="act-search">
  21. <section class="select-box">
  22. <div class="select-box--item">
  23. <span>物品名称:</span>
  24. <el-input
  25. v-model="tableQuery.queryParam.stuffName"
  26. placeholder="搜索物品名称"
  27. class="act-search-input"
  28. />
  29. </div>
  30. <div class="select-box--item">
  31. <span>状态:</span>
  32. <el-select
  33. v-model="tableQuery.queryParam.status"
  34. placeholder="请选择状态"
  35. clearable
  36. >
  37. <el-option label="启用" :value="true" />
  38. <el-option label="禁用" :value="false" />
  39. </el-select>
  40. </div>
  41. </section>
  42. <section class="search-btn">
  43. <el-button type="primary" @click="handleSearch">查询</el-button>
  44. <el-button @click="handleReset">重置</el-button>
  45. </section>
  46. </div>
  47. </header>
  48. <div class="batch-table">
  49. <BasicTable
  50. ref="basicTableRef"
  51. :tableData="tableData"
  52. :tableConfig="tableConfig"
  53. @update:pageSize="handleSizeChange"
  54. @update:pageNumber="handleCurrentChange"
  55. >
  56. <template #status="scope">
  57. <span>
  58. {{ scope.row.statusName || (scope.row.status === true || scope.row.status === 'true' ? '启用' : scope.row.status === false || scope.row.status === 'false' ? '禁用' : '-') }}
  59. </span>
  60. </template>
  61. <template #action="scope">
  62. <div class="action-container--div" style="justify-content: left">
  63. <ActionButton text="编辑" @click="handleEdit(scope.row.id)" />
  64. <ActionButton
  65. text="删除"
  66. :popconfirm="{
  67. title: '确定要删除?',
  68. }"
  69. @confirm="handleDelete(scope.row.id)"
  70. />
  71. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  72. </div>
  73. </template>
  74. </BasicTable>
  75. </div>
  76. </div>
  77. </main>
  78. <BatchImport
  79. v-if="batchImportVisible"
  80. :visible="batchImportVisible"
  81. :import-api-url="importApiUrl"
  82. :template-url="templateUrl"
  83. template-name="下载模板"
  84. :show-template="false"
  85. @close="batchImportVisible = false"
  86. @update="handleUpdate"
  87. />
  88. </div>
  89. </template>
  90. <script setup lang="ts">
  91. import { onMounted, reactive, ref } from 'vue';
  92. import { ElMessage } from 'element-plus';
  93. import BasicTable from '@/components/BasicTable.vue';
  94. import useTableConfig from '@/hooks/useTableConfigHook';
  95. import ActionButton from '@/components/ActionButton.vue';
  96. import { TABLE_OPTIONS, INVENTORY_TABLE_COLUMNS } from './configs/tables';
  97. import { useRouter } from 'vue-router';
  98. import type { QueryPageRequest } from '@/types/basic-query';
  99. import { queryInventoryManage, deleteInventory, exportInventory } from '@/api/inventory';
  100. import { downloadByData } from '@/utils/file/download';
  101. import BatchImport from '@/components/batch-import/BatchImport.vue';
  102. import { useGlobSetting } from '@/hooks/setting';
  103. import urlJoin from 'url-join';
  104. const router = useRouter();
  105. // 表格
  106. const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  107. const { tableConfig, pagination } = useTableConfig(INVENTORY_TABLE_COLUMNS, TABLE_OPTIONS);
  108. const tableData = ref<any[]>([]);
  109. const tableQuery = reactive<QueryPageRequest<any>>({
  110. pageNumber: pagination.pageNumber,
  111. pageSize: pagination.pageSize,
  112. queryParam: {
  113. stuffName: '', // 物品名称
  114. status: true, // 状态,默认启用
  115. ids: [], // 选择数据的ID
  116. },
  117. });
  118. const handleSizeChange = (value: number) => {
  119. pagination.pageSize = value;
  120. tableQuery.pageSize = value;
  121. getTableData();
  122. };
  123. const handleCurrentChange = (value: number) => {
  124. pagination.pageNumber = value;
  125. tableQuery.pageNumber = value;
  126. getTableData();
  127. };
  128. async function getTableData() {
  129. tableConfig.loading = true;
  130. try {
  131. const res = await queryInventoryManage(tableQuery);
  132. if (res) {
  133. // 映射返回数据字段到表格字段
  134. tableData.value = res.records.map((item) => ({
  135. id: item.id,
  136. itemName: item.stuffName, // 物品名称
  137. warehouseDate: item.inStoreTime, // 入库日期
  138. itemQuantity: item.stuffQty, // 物品数量
  139. handler: item.createdUserName, // 经办人
  140. remarks: item.remark, // 备注
  141. status: item.status, // 状态:true-启用,false-禁用
  142. statusName: item.statusName, // 状态名称
  143. }));
  144. pagination.total = res.totalRow;
  145. }
  146. } catch (e) {
  147. console.error('获取物品库存列表失败:', e);
  148. tableData.value = [];
  149. pagination.total = 0;
  150. } finally {
  151. tableConfig.loading = false;
  152. }
  153. }
  154. const handleSearch = () => {
  155. pagination.pageNumber = 1;
  156. tableQuery.pageNumber = 1;
  157. getTableData();
  158. };
  159. const handleReset = () => {
  160. tableQuery.queryParam.stuffName = '';
  161. tableQuery.queryParam.status = true; // 重置为默认启用状态
  162. tableQuery.queryParam.ids = [];
  163. handleSearch();
  164. };
  165. // 批量导入
  166. const batchImportVisible = ref(false);
  167. const { urlPrefix } = useGlobSetting();
  168. const importApiUrl = ref(urlJoin(urlPrefix, '/inventory/importInventory'));
  169. const templateUrl = ref('./skyeye-file-upload/sfysecurity/TEMPLATE/import-inventory-template.xlsx');
  170. const handleImport = () => {
  171. batchImportVisible.value = true;
  172. };
  173. const handleUpdate = () => {
  174. batchImportVisible.value = false;
  175. getTableData();
  176. };
  177. const handleDownload = async () => {
  178. try {
  179. const exportParams = {
  180. stuffName: tableQuery.queryParam.stuffName || undefined,
  181. status: tableQuery.queryParam.status,
  182. ids: tableQuery.queryParam.ids.length > 0 ? tableQuery.queryParam.ids : undefined,
  183. };
  184. const response = await exportInventory(exportParams);
  185. if (response) {
  186. const fileName = `物品库存管理_${new Date().toISOString().split('T')[0]}.xlsx`;
  187. downloadByData(response, fileName);
  188. ElMessage.success('导出成功');
  189. }
  190. } catch (e) {
  191. console.error('导出物品库存失败:', e);
  192. ElMessage.error('导出失败,请重试');
  193. }
  194. };
  195. const handleCreate = () => {
  196. router.push({
  197. name: 'InventoryItem',
  198. query: {
  199. operate: 'inventory-create',
  200. },
  201. });
  202. };
  203. const handleEdit = (id: number) => {
  204. router.push({
  205. name: 'InventoryItem',
  206. query: {
  207. id,
  208. operate: 'inventory-edit',
  209. },
  210. });
  211. };
  212. const handleDelete = async (id: number) => {
  213. try {
  214. await deleteInventory(id);
  215. ElMessage.success('删除成功');
  216. getTableData();
  217. } catch (e) {
  218. console.error('删除物品库存失败:', e);
  219. ElMessage.error('删除失败,请重试');
  220. }
  221. };
  222. const handleView = (id: number) => {
  223. router.push({
  224. name: 'InventoryItem',
  225. query: {
  226. id,
  227. operate: 'inventory-view',
  228. },
  229. });
  230. };
  231. onMounted(() => {
  232. getTableData();
  233. });
  234. </script>
  235. <style scoped lang="scss">
  236. @use '@/styles/page-details-layout.scss' as *;
  237. @use '@/styles/page-main-layout.scss' as *;
  238. @use '@/styles/basic-table-action.scss' as *;
  239. @use '@/views/traffic/violation/style/act-search-table.scss' as *;
  240. </style>