zhangwei
2025-08-05 b94b71d44d62802bb8093f64a202d0176fdade50
src/views/system/dept/utils/hook.tsx
@@ -11,6 +11,7 @@
  getRegionList,
  getDaimaleixingList,
  caigourenAdd,
  caigourenUpdate,
  caigourenDelete
} from "@/api/item/index";
import { usePublicHooks } from "../../hooks";
@@ -24,15 +25,15 @@
    // 新增日期范围,可为 null,类型为数组
    createDateRange: null,
    // 行政区域,可为 null,类型为字符串
    xingzhengquyu: "",
    xingzhengquyu: [],
    // 行业品目,可为 null,类型为字符串
    hangyepinmu: "",
    // 订单状态,可为 null,类型为 32 位整数
    orderStatus: "",
    // 质疑有无,可为 null,类型为布尔值
    zhiyi: null,
    zhiyi: [],
    // 投诉有无,可为 null,类型为布尔值
    tousu: null,
    tousu: [],
    // 项目名称,可为 null,类型为字符串
    projectName: null,
    // 代理机构名称,可为 null,类型为字符串
@@ -48,6 +49,12 @@
    orderStatusList: [],
    regionList: [],
    daimaleixingList: []
  });
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 10,
    currentPage: 1,
    background: true
  });
  //获取采购方式
  const getCaigoufangshiListFun = async () => {
@@ -86,7 +93,7 @@
    const res = state.orderStatusList.find(item => {
      return row.orderStatus == item.status;
    });
    return res.label;
    return res?.label;
  };
  const columns: TableColumnList = [
    {
@@ -155,18 +162,36 @@
  function handleSelectionChange(val) {
    console.log("handleSelectionChange", val);
  }
  function handleSizeChange(val: number) {
    console.log(`${val} items per page`);
  }
  function handleCurrentChange(val: number) {
    console.log(`current page: ${val}`);
  }
  function resetForm(formEl) {
    if (!formEl) return;
    formEl.resetFields();
    onSearch();
  }
  const checkboxAsRadio = data => {
    if (data.length > 1) {
      data.shift();
    }
  };
  async function onSearch() {
    const obj = cloneDeep(form);
    obj.tousu = obj.tousu.join("");
    obj.zhiyi = obj.zhiyi.join("");
    obj.xingzhengquyu = obj.xingzhengquyu ? obj.xingzhengquyu.join("") : "";
    loading.value = true;
    const { result } = await zhaobiaoPageOrder(form); // 这里是返回一维数组结构,前端自行处理成树结构,返回格式要求:唯一id加父节点parentId,parentId取父节点id
    const { result } = await zhaobiaoPageOrder(obj); // 这里是返回一维数组结构,前端自行处理成树结构,返回格式要求:唯一id加父节点parentId,parentId取父节点id
    const newData = result.items;
    loading.value = false;
    pagination.total = result.total;
    pagination.pageSize = result.pageSize;
    pagination.currentPage = result.page;
    // if (!isAllEmpty(form.name)) {
    //   // 前端搜索部门名称
    //   newData = newData.filter(item => item.name.includes(form.name));
@@ -191,6 +216,8 @@
  }
  function openDialog(title = "新增", row?: FormItemProps) {
    console.log(row,'-');
    addDialog({
      title: `${title}项目`,
      props: {
@@ -206,10 +233,10 @@
          toubiaobaozhengjin: row?.toubiaobaozhengjin ?? null, // 投标保证金(可选)
          lianhetitoubiao: row?.lianhetitoubiao ?? null, // 联合体投标(可选)
          kaibiaofangshi: row?.kaibiaofangshi ?? null, // 开标方式(可选)
          shifoufenbao: row?.shifoufenbao ?? false, // 是否分包(可选)
          shifoutuisongxuanchuan: row?.shifoutuisongxuanchuan ?? true, // 是否推送宣传(可选)
          shifoufenbao: row?.shifoufenbao ?? "false", // 是否分包(可选)
          shifoutuisongxuanchuan: row?.shifoutuisongxuanchuan ?? "true", // 是否推送宣传(可选)
          caigourenmingcheng: row?.caigourenmingcheng ?? null, // 采购人名称(可选)
          xingzhengquyu: row?.xingzhengquyu ?? null, // 行政区域(可选)
          xingzhengquyu: row?.xingzhengquyu.split(",") ?? [], // 行政区域(可选)
          xingzhengquyuName: row?.xingzhengquyuName ?? null, // 行政区域名称(可选)
          jigoudaima: row?.jigoudaima ?? null, // 机构代码(可选)
          daimaleixing: row?.daimaleixing ?? null, // 代码类型(可选)
@@ -233,28 +260,36 @@
      draggable: true,
      fullscreen: deviceDetection(),
      fullscreenIcon: true,
      sureBtnLoading: true,
      closeOnClickModal: false,
      contentRenderer: () => h(editForm, { ref: formRef, formInline: null }),
      beforeSure: (done, { options }) => {
      beforeSure: (done, { options, closeLoading }) => {
        const FormRef = formRef.value.getRef();
        const curData = options.props.formInline as FormItemProps;
        const curData = cloneDeep(options.props.formInline as FormItemProps);
        async function chores() {
          message(`您${title}了项目名称为${curData.projectName}的这条数据`, {
            type: "success"
          });
          const res = await caigourenAdd(curData);
          // curData.dingbiaoguize = curData.dingbiaoguize.join("");
          curData.xingzhengquyu = curData.xingzhengquyu.join(",");
          let res;
          if (title == "新增") {
            res = await caigourenAdd(curData);
          } else {
            res = await caigourenUpdate(curData);
          }
          if (res.code == "200") {
            done(); // 关闭弹框
            onSearch(); // 刷新表格数据
          } else {
            closeLoading();
            message(res.message, {
              type: "error"
            });
          }
        }
        FormRef.validate(valid => {
        FormRef.validate((valid, obj) => {
          if (valid) {
            console.log("curData", curData);
            // 表单规则校验通过
            if (title === "新增") {
              // 实际开发先调用新增接口,再进行下面操作
@@ -263,6 +298,18 @@
              // 实际开发先调用修改接口,再进行下面操作
              chores();
            }
          } else {
            closeLoading();
            const fail = [];
            console.log(obj);
            for (const key in obj) {
              fail.push(obj[key][0].message);
            }
            message(fail[0], {
              type: "warning"
            });
            return false;
          }
        });
      }
@@ -306,6 +353,10 @@
    openDialog,
    /** 删除部门 */
    handleDelete,
    handleSelectionChange
    handleSelectionChange,
    handleSizeChange,
    handleCurrentChange,
    pagination,
    checkboxAsRadio
  };
}