123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import {
- listFileByBasisIdMulType,
- getToolDetailById,
- queryToolDict,
- toolDelete,
- } from "@/api/bussiness";
- import { useRouter } from "vue-router";
- import { groupByKey } from "@/utils";
- // 数据表格的 hooks
- const useTable = (
- open,
- title,
- form,
- formLoading,
- submitFormLevelTwoDict,
- getTableData,
- updateTypeOneDict,
- reset
- ) => {
- const { proxy } = getCurrentInstance();
- const router = useRouter();
- // 表格数据
- const toolList = ref([]);
- // 表格的 loading 状态
- const loading = ref(true);
- // 表格勾选框选中的 id 列表
- const ids = ref([]);
- // 多个勾选时为 true 其他为 false
- const single = ref(true);
- // 只要有勾选项就为 true
- const multiple = ref(true);
- // 多选框选中数据
- const handleSelectionChange = (selection) => {
- ids.value = selection.map((item) => item.id);
- single.value = selection.length != 1;
- multiple.value = !selection.length;
- };
- // 新增按钮操作
- const handleAdd = () => {
- reset();
- // 重新更新一下大类下拉列表
- updateTypeOneDict();
- open.value = true;
- title.value = "添加工具";
- };
- // 获取类型id
- const getTypeId = (ancestors, level) => {
- return ancestors.split(",")[level];
- };
- // 获取二级分类字典
- const updateTypeTwoDict = (parentId) => {
- queryToolDict("2", parentId).then((data) => {
- submitFormLevelTwoDict.value = data || [];
- });
- };
- // 点击表格上的修改按钮
- const handleSelecterUpdate = () => {
- const targetId = ids.value[0];
- formLoading.value = true;
- getToolDetailById(targetId).then((res) => {
- handleUpdate(res.data);
- });
- };
- // 修改按钮操作
- const handleUpdate = (row) => {
- reset();
- updateTypeOneDict();
- open.value = true;
- formLoading.value = true;
- // 获取工具对应的附件
- listFileByBasisIdMulType({
- basisId: row.id,
- delFlag: "0",
- informationType: 'sc,zl,syt'
- })
- .then((res) => {
- // 重新修改一下字段
- const allFiles = (res.data || []).map((item) => ({
- id: item.id,
- name: item.fileName,
- url: item.filePath,
- informationType: item.informationType,
- }));
- // 附件分组
- const fileMap = groupByKey(allFiles, "informationType");
- // 根据祖级列表获取二类的下拉列表
- const typeOneId = +getTypeId(row.ancestors, 1);
- updateTypeTwoDict(typeOneId);
- // 表单赋值
- form.value = {
- id: row.id,
- toolName: row.toolName,
- aliasName: row.aliasName,
- levelOneId: typeOneId,
- levelTwoId: row.parentId,
- describe: row.describe,
- toolNum: row.toolNum || 0,
- specifications: row.specifications,
- example: row.example,
- // 手册附件
- manualFileList: fileMap["sc"] || [],
- // 资料附件
- resourceFileList: fileMap["zl"] || [],
- // 示意图
- imageList: fileMap["syt"] || [],
- };
- title.value = "修改工具";
- })
- .finally(() => {
- formLoading.value = false;
- });
- };
- // 删除按钮操作
- const handleDelete = (row) => {
- const toolIds = row.id || ids.value;
- proxy.$modal
- .confirm("是否确认删除该工具?")
- .then(function () {
- return toolDelete(toolIds);
- })
- .then(() => {
- getTableData();
- proxy.$modal.msgSuccess("删除成功");
- })
- .catch(() => {});
- };
- // 跳转到物料管理页面
- const handlePageToToolsMaterial = (row) => {
- router.push({
- path: "/toolsMaterial",
- query: {
- toolId: row.id,
- },
- });
- };
- return {
- toolList,
- loading,
- single,
- multiple,
- handleSelectionChange,
- handleAdd,
- handleUpdate,
- handleDelete,
- handleSelecterUpdate,
- handlePageToToolsMaterial,
- };
- };
- export default useTable;
|