From 60f24769048e3c36f8bdde0ac4649ee6f15df334 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期三, 06 八月 2025 14:59:57 +0800
Subject: [PATCH] '项目管理多选操作'

---
 src/views/system/dept/utils/hook.tsx |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 205 insertions(+), 27 deletions(-)

diff --git a/src/views/system/dept/utils/hook.tsx b/src/views/system/dept/utils/hook.tsx
index d11ee6f..a0c9b7b 100644
--- a/src/views/system/dept/utils/hook.tsx
+++ b/src/views/system/dept/utils/hook.tsx
@@ -11,32 +11,47 @@
   getRegionList,
   getDaimaleixingList,
   caigourenAdd,
-  caigourenDelete
+  caigourenUpdate,
+  caigourenDelete,
+  caigourenBatchDelete
 } from "@/api/item/index";
 import { usePublicHooks } from "../../hooks";
 import { addDialog } from "@/components/ReDialog";
-import { reactive, ref, onMounted, h } from "vue";
+import { type Ref, reactive, ref, onMounted, h, computed } from "vue";
 import type { FormItemProps } from "../utils/types";
-import { cloneDeep, isAllEmpty, deviceDetection } from "@pureadmin/utils";
+import {
+  cloneDeep,
+  isAllEmpty,
+  deviceDetection,
+  getKeyList
+} from "@pureadmin/utils";
+import { useUserStoreHook } from "@/store/modules/user";
+import type { PaginationProps } from "@pureadmin/table";
 
-export function useDept() {
+const nowRole = computed(() => {
+  return useUserStoreHook().nowRole;
+});
+const selectedNum = ref(0);
+
+export function useDept(tableRef: Ref) {
   const form = reactive({
     // 鏂板鏃ユ湡鑼冨洿锛屽彲涓� null锛岀被鍨嬩负鏁扮粍
     createDateRange: null,
     // 琛屾斂鍖哄煙锛屽彲涓� null锛岀被鍨嬩负瀛楃涓�
-    xingzhengquyu: "",
+    xingzhengquyu: [],
     // 琛屼笟鍝佺洰锛屽彲涓� null锛岀被鍨嬩负瀛楃涓�
     hangyepinmu: "",
     // 璁㈠崟鐘舵�侊紝鍙负 null锛岀被鍨嬩负 32 浣嶆暣鏁�
     orderStatus: "",
     // 璐ㄧ枒鏈夋棤锛屽彲涓� null锛岀被鍨嬩负甯冨皵鍊�
-    zhiyi: null,
+    zhiyi: [],
     // 鎶曡瘔鏈夋棤锛屽彲涓� null锛岀被鍨嬩负甯冨皵鍊�
-    tousu: null,
+    tousu: [],
     // 椤圭洰鍚嶇О锛屽彲涓� null锛岀被鍨嬩负瀛楃涓�
     projectName: null,
     // 浠g悊鏈烘瀯鍚嶇О锛屽彲涓� null锛岀被鍨嬩负瀛楃涓�
     dailijigoumingcheng: null,
+    caigourenmingcheng: null,
     // 涓爣渚涘簲鍟嗗鍚嶏紝鍙负 null锛岀被鍨嬩负瀛楃涓�
     zhongbiaoName: null,
     // 涓撳濮撳悕锛屽彲涓� null锛岀被鍨嬩负瀛楃涓�
@@ -48,6 +63,12 @@
     orderStatusList: [],
     regionList: [],
     daimaleixingList: []
+  });
+  const pagination = reactive<PaginationProps>({
+    total: 0,
+    pageSize: 10,
+    currentPage: 1,
+    background: true
   });
   //鑾峰彇閲囪喘鏂瑰紡
   const getCaigoufangshiListFun = async () => {
@@ -86,19 +107,25 @@
     const res = state.orderStatusList.find(item => {
       return row.orderStatus == item.status;
     });
-    return res.label;
+    return res?.label;
   };
   const columns: TableColumnList = [
+    {
+      label: "鍕鹃�夊垪", // 濡傛灉闇�瑕佽〃鏍煎閫夛紝姝ゅlabel蹇呴』璁剧疆
+      type: "selection",
+      fixed: "left",
+      reserveSelection: true // 鏁版嵁鍒锋柊鍚庝繚鐣欓�夐」
+    },
+    {
+      label: "閲囪喘浜�",
+      prop: "caigourenmingcheng",
+      minWidth: 70
+    },
     {
       label: "椤圭洰鍚嶇О",
       prop: "projectName",
       width: 180,
       align: "left"
-    },
-    {
-      label: "浠g悊鏈烘瀯",
-      prop: "dailijigoumingcheng",
-      minWidth: 70
     },
     {
       label: "椤圭洰杩涘害",
@@ -119,7 +146,7 @@
     {
       label: "涓爣渚涘簲鍟�",
       prop: "zhongbiaoName",
-      minWidth: 70
+      minWidth: 180
     },
     {
       label: "璇勫涓撳",
@@ -147,13 +174,124 @@
     {
       label: "鎿嶄綔",
       fixed: "right",
-      width: 210,
+      width: 80,
+      slot: "operation"
+    }
+  ];
+  const CGRcolumns: TableColumnList = [
+    {
+      label: "鍕鹃�夊垪", // 濡傛灉闇�瑕佽〃鏍煎閫夛紝姝ゅlabel蹇呴』璁剧疆
+      type: "selection",
+      fixed: "left",
+      reserveSelection: true // 鏁版嵁鍒锋柊鍚庝繚鐣欓�夐」
+    },
+    {
+      label: "浠g悊鏈烘瀯",
+      prop: "dailijigoumingcheng",
+      minWidth: 70
+    },
+    {
+      label: "椤圭洰鍚嶇О",
+      prop: "projectName",
+      width: 180,
+      align: "left"
+    },
+    {
+      label: "椤圭洰杩涘害",
+      prop: "orderStatus",
+      minWidth: 70,
+      cellRenderer: ({ row, props }) => getOrderStatus(row)
+    },
+    {
+      label: "鎶ュ悕璐�",
+      prop: "baomingfei",
+      minWidth: 70
+    },
+    {
+      label: "鎶曟爣淇濊瘉閲�",
+      prop: "toubiaobaozhengjin",
+      minWidth: 70
+    },
+    {
+      label: "涓爣渚涘簲鍟�",
+      prop: "zhongbiaoName",
+      minWidth: 180
+    },
+    {
+      label: "璇勫涓撳",
+      prop: "zhuanjiaName",
+      minWidth: 70
+    },
+    {
+      label: "璐ㄧ枒",
+      prop: "zhiyi",
+      minWidth: 100,
+      cellRenderer: ({ row, props }) => (
+        <span>{row.status === 1 ? "鏈�" : "鏃�"}</span>
+      )
+    },
+    {
+      label: "鎶曡瘔",
+      prop: "tousu",
+      minWidth: 100,
+      cellRenderer: ({ row, props }) => (
+        // <el-tag size={props.size} style={tagStyle.value(row.status)}>
+        <span>{row.status === 1 ? "鏈�" : "鏃�"}</span>
+        // </el-tag>
+      )
+    },
+    {
+      label: "鎿嶄綔",
+      fixed: "right",
+      width: 80,
       slot: "operation"
     }
   ];
 
+  /** 褰揅heckBox閫夋嫨椤瑰彂鐢熷彉鍖栨椂浼氳Е鍙戣浜嬩欢 */
   function handleSelectionChange(val) {
-    console.log("handleSelectionChange", val);
+    selectedNum.value = val.length;
+    // 閲嶇疆琛ㄦ牸楂樺害
+    tableRef.value.setAdaptive();
+  }
+  /** 鍙栨秷閫夋嫨 */
+  function onSelectionCancel() {
+    selectedNum.value = 0;
+    // 鐢ㄤ簬澶氶�夎〃鏍硷紝娓呯┖鐢ㄦ埛鐨勯�夋嫨
+    tableRef.value.getTableRef().clearSelection();
+  }
+  /** 鎵归噺鍒犻櫎 */
+  async function onbatchDel() {
+    // 杩斿洖褰撳墠閫変腑鐨勮
+    const curSelected = tableRef.value.getTableRef().getSelectionRows();
+    const data = [];
+    curSelected.forEach(item => {
+      data.push({ id: item.id });
+    });
+    const res = await caigourenBatchDelete(data);
+    if (res.code == "200") {
+      // 鎺ヤ笅鏉ユ牴鎹疄闄呬笟鍔★紝閫氳繃閫変腑琛岀殑鏌愰」鏁版嵁锛屾瘮濡備笅闈㈢殑id锛岃皟鐢ㄦ帴鍙h繘琛屾壒閲忓垹闄�
+      message(
+        `宸插垹闄ら」鐩悕绉颁负 ${getKeyList(curSelected, "projectName")} 鐨勬暟鎹甡,
+        {
+          type: "success"
+        }
+      );
+      onSearch();
+    } else {
+      message(res.message, {
+        type: "error"
+      });
+    }
+    tableRef.value.getTableRef().clearSelection();
+    onSearch();
+  }
+  function handleSizeChange(val: number) {
+    console.log(`${val} items per page`);
+  }
+
+  function handleCurrentChange(val: number) {
+    console.log(`current page: ${val}`);
   }
 
   function resetForm(formEl) {
@@ -161,12 +299,23 @@
     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锛宲arentId鍙栫埗鑺傜偣id
+    const { result } = await zhaobiaoPageOrder(obj); // 杩欓噷鏄繑鍥炰竴缁存暟缁勭粨鏋勶紝鍓嶇鑷澶勭悊鎴愭爲缁撴瀯锛岃繑鍥炴牸寮忚姹傦細鍞竴id鍔犵埗鑺傜偣parentId锛宲arentId鍙栫埗鑺傜偣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,11 +340,14 @@
   }
 
   function openDialog(title = "鏂板", row?: FormItemProps) {
+    console.log(row, "-");
+
     addDialog({
       title: `${title}椤圭洰`,
       props: {
         formInline: {
           higherDeptOptions: formatHigherDeptOptions(cloneDeep(dataList.value)),
+          id: row?.id ?? "",
           projectCode: row?.projectCode ?? "", // 椤圭洰缂栧彿锛堝繀濉級
           projectName: row?.projectName ?? "", // 椤圭洰鍚嶇О锛堝繀濉級
           hangyepinmu: row?.hangyepinmu ?? null, // 琛屼笟鍝佺洰锛堝彲閫夛級
@@ -206,10 +358,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, // 鏈烘瀯浠g爜锛堝彲閫夛級
           daimaleixing: row?.daimaleixing ?? null, // 浠g爜绫诲瀷锛堝彲閫夛級
@@ -233,28 +385,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 +423,16 @@
               // 瀹為檯寮�鍙戝厛璋冪敤淇敼鎺ュ彛锛屽啀杩涜涓嬮潰鎿嶄綔
               chores();
             }
+          } else {
+            closeLoading();
+            const fail = [];
+            for (const key in obj) {
+              fail.push(obj[key][0].message);
+            }
+            message(fail[0], {
+              type: "warning"
+            });
+            return false;
           }
         });
       }
@@ -297,7 +467,9 @@
     state,
     loading,
     columns,
+    CGRcolumns,
     dataList,
+    selectedNum,
     /** 鎼滅储 */
     onSearch,
     /** 閲嶇疆 */
@@ -306,6 +478,12 @@
     openDialog,
     /** 鍒犻櫎閮ㄩ棬 */
     handleDelete,
-    handleSelectionChange
+    handleSelectionChange,
+    handleSizeChange,
+    handleCurrentChange,
+    pagination,
+    checkboxAsRadio,
+    onSelectionCancel,
+    onbatchDel
   };
 }

--
Gitblit v1.9.1