src/views/basicInformation/index.vue
@@ -56,9 +56,6 @@
          @edit="handleEdit"
          @viewRow="handleView"
          @selection-change="handleSelectionChange"
          :showOperations="true"
          :showIndex="true"
          :showPagination="false"
          :operations="['edit', 'viewRow']"
          :operationsWidth="200"
        >
@@ -146,21 +143,6 @@
        :title="title"
        @submit="handleSubmit"
      />
      <Descriptions
        v-model:descriptionsVisible="showDialog"
        title="供应商详情"
        :formData="supplierData"
        :fieldLabels="supplierFieldLabels"
        :column="2"
        :isViewOnly="false"
        :border="true"
        :showOperations="true"
        descriptionsTitle="基本信息"
        :fieldConfig="fieldConfig"
        :excludeFields="excludeFields"
        @edit="descriptionsHandleEdit"
        @close="handleClose"
      />
    </el-card>
  </div>
</template>
@@ -185,7 +167,6 @@
import Coal from "./mould/coal.vue";
import coalQualityMaintenance from "./mould/coalQualityMaintenance.vue";
import coalMeiZhiZiDuanWeiHu from "./mould/coalMeiZhiZiDuanWeiHu.vue";
import Descriptions from "@/components/dialog/Descriptions.vue";
// ===== API 服务导入 =====
import { delSupply, getSupply } from "@/api/basicInformation/supplier.js";
@@ -203,77 +184,17 @@
import {
  getCoalFieldList,
  getCoalPlanList,
  delCoalPlan,
} from "@/api/basicInformation/coalQualityMaintenance";
import { useDelete } from "@/hooks/useDelete.js";
const { proxy } = getCurrentInstance();
import router from "@/router";
// ===== 响应式状态管理 =====
// 弹窗控制状态
const showDialog = ref(false)
const supplierFieldLabels = {
  supplierName: '供应商名称',
  taxpayerId: '统一社会信用代码',
}
// 数据对象
const supplierData = ref({
  supplierName: "测试供应商",
  taxpayerId: "91320000MA1N2P3Q4R",
  contactPerson: "张三",
  contactPhone: "13800138000",
  bankAccount: "6222024200019999999",
  bankName: "中国工商银行",
  businessAddress: "江苏省苏州市工业园区星湖街328号",
  contactAddress: "江苏省苏州市姑苏区观前街100号",
  createTime: "2024-01-15T10:30:00",
  updateTime: "2024-06-25T14:20:00",
  id: 123,
})
// 字段配置
const fieldConfig = ref({
  supplierName: {
    label: '供应商名称',
    span: 2  // 跨2列显示
  },
  taxpayerId: {
    label: '统一社会信用代码'
  },
  contactPhone: {
    label: '联系电话',
    formatter: (value) => value || '暂无联系方式'
  },
  createTime: {
    label: '创建时间',
    formatter: (value) => new Date(value).toLocaleDateString('zh-CN')
  },
  businessAddress: {
    label: '详细经营地址',
    span: 2
  },
  contactAddress: {
    label: '详细联系地址',
    span: 2
  }
})
// 排除不显示的字段
const excludeFields = ref(["id", "updateTime", "deleted"]);
// 事件处理
const descriptionsHandleEdit = (data) => {
  console.log("编辑数据:", data);
  // 跳转到编辑页面或打开编辑弹窗
};
const handleClose = () => {
  console.log("弹窗关闭");
};
const dialogFormVisible = ref(false);
const form = ref({});
const title = ref("");
const copyForm = ref({});
const addOrEdit = ref("add");
const descriptionsVisible = ref(false);
// 数据缓存映射
const userList = ref([]);
@@ -389,10 +310,12 @@
const getUserList = async () => {
  try {
    const res = await testUserList();
    console.log("获取用户列表数据:", res);
    console.log("userMap:", userMap.value);
    if (res && res.data) {
      userList.value = res.data;
      userList.value.forEach((user) => {
        userMap.value[user.userId] = user.username;
        userMap.value[user.userId] = user.nickName;
      });
    }
  } catch (error) {
@@ -430,8 +353,6 @@
  return matchedField ? matchedField.fieldName : numId;
};
// ===== 计算属性 =====
/**
 * 当前标签页是否支持导出功能
 */
@@ -444,11 +365,11 @@
 */
const searchPlaceholder = computed(() => {
  const placeholderMap = {
    supplier: "供应商/识别码/详细地址",
    customer: "供应商/识别码/详细地址",
    coal: "请输入搜索信息",
    coalQualityMaintenance: "请输入搜索信息",
    coalMeiZhiZiDuanWeiHu: "请输入搜索信息",
    supplier: "供应商/统一识别码/详细地址",
    customer: "供应商/统一识别码/详细地址",
    coal: "请输入煤种信息",
    coalQualityMaintenance: "请输入煤质方案信息",
    coalMeiZhiZiDuanWeiHu: "请输入煤质字段信息",
  };
  return placeholderMap[tabName.value] || "请输入搜索信息";
});
@@ -470,11 +391,6 @@
 * 当前选中行数量
 */
const selectedCount = computed(() => selectedRows.value.length);
/**
 * 是否有选中的行
 */
const hasSelectedRows = computed(() => selectedCount.value > 0);
// ===== 表格列配置 =====
@@ -796,104 +712,27 @@
  handleAddEdit(tabName.value);
};
/**
 * 查看按钮点击处理
 * @param {Object} row - 行数据
 * @description 处理查看操作,构建地址数组并打开查看弹窗
 */
const handleView = (row) => {
  console.log("查看行数据:", row);
  // 拿到所有的keys
  const keys = Object.keys(row);
  console.log("所有keys:", keys);
  showDialog.value = true;
  // form.value = JSON.parse(JSON.stringify(row));
  // console.log("查看行数据:", form.value);
  // // 构建供应商业务地址数组
  // if (form.value.bprovinceId && form.value.bdistrictId && form.value.bcityId) {
  //   form.value.bids = [row.bprovinceId, row.bcityId, row.bdistrictId];
  // }
  // // 构建供应商联系地址数组
  // if (form.value.cprovinceId && form.value.cdistrictId && form.value.ccityId) {
  //   form.value.cids = [row.cprovinceId, row.ccityId, row.cdistrictId];
  // }
  // // 构建客户业务地址数组
  // if (
  //   form.value.businessCityId &&
  //   form.value.businessDistrictId &&
  //   form.value.businessProvinceId
  // ) {
  //   form.value.bids = [
  //     row.businessProvinceId,
  //     row.businessCityId,
  //     row.businessDistrictId,
  //   ];
  // }
  // // 构建客户联系地址数组
  // if (form.value.cityId && form.value.districtId && form.value.provinceId) {
  //   form.value.cids = [row.provinceId, row.cityId, row.districtId];
  // }
  // addOrEdit.value = "viewRow";
  // handleAddEdit(tabName.value);
};
/**
 * 批量删除处理
 * @description 批量删除选中的记录
 */
const handleDelete = async () => {
  if (selectedRows.value.length === 0) {
    ElMessage.warning("请选择要删除的数据");
    return;
  }
  const deleteIds = selectedRows.value.map((item) => item.id);
  try {
    await ElMessageBox.confirm("确定删除选中的数据吗?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    });
    const deleteApiMap = {
  const deleteApiMap = {
      supplier: delSupply,
      coal: delCoalInfo,
      coalQualityMaintenance: () => {
        throw new Error("delCoalQuality API not imported");
      },
      coalQualityMaintenance: delCoalPlan,
      customer: delCustomer,
      coalMeiZhiZiDuanWeiHu: deleteCoalField,
    };
    const deleteApi = deleteApiMap[tabName.value];
    if (!deleteApi) {
      ElMessage.error("删除接口未配置");
      return;
    }
    console.log(deleteIds);
    const res = await deleteApi(deleteIds);
    if (res.code !== 200 && res.msg !== "操作成功") {
      ElMessage.error("删除失败:" + res.msg);
      return;
    }
    ElMessage.success("删除成功");
    await getList();
  } catch (error) {
    if (error.message !== "cancel") {
      console.error("删除操作失败:", error);
      ElMessage.error("删除失败,请稍后再试");
    } else {
      ElMessage.info("已取消删除操作");
    }
  } finally {
    selectedRows.value = [];
  }
};
const {handleDeleteBatch :handleDelete} = useDelete({
  deleteApi: () => deleteApiMap[tabName.value],
  selectedRows: selectedRows,
  getList: () => getList,
  tableData: tableData,
  total: total,
  confirmText: "确认删除选中的数据吗?",
  successText: "删除成功",
})
/**
 * 关闭弹窗处理
@@ -985,6 +824,40 @@
  }
};
const handleView = (row) => {
  form.value = JSON.parse(JSON.stringify(row));
  // 构建供应商业务地址数组
  if (form.value.bprovinceId && form.value.bdistrictId && form.value.bcityId) {
    form.value.bids = [row.bprovinceId, row.bcityId, row.bdistrictId];
  }
  // 构建供应商联系地址数组
  if (form.value.cprovinceId && form.value.cdistrictId && form.value.ccityId) {
    form.value.cids = [row.cprovinceId, row.ccityId, row.cdistrictId];
  }
  // 构建客户业务地址数组
  if (
    form.value.businessCityId &&
    form.value.businessDistrictId &&
    form.value.businessProvinceId
  ) {
    form.value.bids = [
      row.businessProvinceId,
      row.businessCityId,
      row.businessDistrictId,
    ];
  }
  // 构建客户联系地址数组
  if (form.value.cityId && form.value.districtId && form.value.provinceId) {
    form.value.cids = [row.provinceId, row.cityId, row.districtId];
  }
  addOrEdit.value = "viewRow";
  handleAddEdit(tabName.value);
};
// ===== 生命周期钩子 =====
/**