Przeglądaj źródła

添加psr 4个tab显示权限 4个导出权限 两个另存权限

Renxy 1 rok temu
rodzic
commit
cb91091895
2 zmienionych plików z 204 dodań i 223 usunięć
  1. 201 221
      src/pages/PSRManage/detail.js
  2. 3 2
      src/pages/PSRManage/index.js

+ 201 - 221
src/pages/PSRManage/detail.js

@@ -238,7 +238,7 @@ const PSRDetail = () => {
   const [excelData, setExcelData] = useState();
   const [historyOpen, setHistoryOpen] = useState();
   const [open, setOpen] = useState(false);
-  const [key, setKey] = useState('1');
+  const [key, setKey] = useState();
   const [compareOpen, setCompareOpen] = useState(false);
   const [compareValues, setCompareValues] = useState([]);
   const [isOriginVer, setIsOriginVer] = useState(false); //是否原始版本 是的话只能另存不能编辑
@@ -415,15 +415,6 @@ const PSRDetail = () => {
     },
   );
 
-  // useEffect(() => {
-  //   let url = '/psrData.json';
-  //   axios.get(url).then((res) => {
-  //     if (res.status == 200) {
-  //       renderSheet(res.data);
-  //     }
-  //   });
-  // }, [key]);
-
   const data_type = useMemo(() => {
     if (key == '3') return 1;
     if (key == '4') return 2;
@@ -445,12 +436,20 @@ const PSRDetail = () => {
     }
     titleRef.current = str;
     setCompareValues([]);
-    if (key) {
-      onChange(key);
-    } else {
+    onChange(key);
+  }, [key]);
+
+  const onChange = (key) => {
+    if (!key) return;
+    if (key == '1') {
       queryPsrExcel({ gridKey: node_id });
+    } else if (key == '2') {
+      queryPsrExcel({ gridKey: flow_id });
+    } else {
+      initPsrActrual(key);
     }
-  }, [key]);
+  };
+
   //请求投标版、签字版psr excel
   const queryPsrExcel = (data) => {
     axios({
@@ -468,16 +467,7 @@ const PSRDetail = () => {
     });
   };
 
-  const onChange = (key) => {
-    if (key == '1') {
-      queryPsrExcel({ gridKey: node_id });
-    } else if (key == '2') {
-      queryPsrExcel({ gridKey: flow_id });
-    } else {
-      initPsrActrual(key);
-    }
-  };
-  //请求 过程/终版PSR 现金流的数据
+  //请求 过程/终版PSR 现金流最近一条数据
   const initPsrActrual = async (key) => {
     const data_type = key == '3' ? 1 : 2;
     const res = await queryPsrMonthLast({ project_id: projectId, data_type });
@@ -646,6 +636,7 @@ const PSRDetail = () => {
     luckysheetRef.current = contentWindow.luckysheet;
   };
 
+  //计算现金流表设备没数据的行隐藏
   const setActHideRow = (data) => {
     const rowHide = {};
     const rang = [6, 246];
@@ -675,6 +666,160 @@ const PSRDetail = () => {
     return rowHide;
   };
 
+  const fillWorkLoadData = async (day) => {
+    const param = { project_id: projectId };
+    param.code = workConfig.map((item) => item.code).join(',');
+    param.s_time = dayjs(day).add(-1, 'month').format('YYYY-MM') + '-26';
+    param.e_time = dayjs(day).format('YYYY-MM') + '-25';
+    const res = await queryPsrWorkLoad(param);
+    if (res?.data) {
+      const data = res?.data; //{ '02-010': [800, 100] };
+      Object.keys(data).forEach((code) => {
+        const list = data[code]; //第一个是当月的,第二个是累计的
+        const fill = workConfig.find((item) => item.code == code)?.fill;
+        if (list?.length > 0 && fill) {
+          luckysheetRef.current.setCellValue(fill.r, fill.curC, list[0]);
+          luckysheetRef.current.setCellValue(fill.r, fill.actC, list[1]);
+        }
+      });
+      console.log('--------------------', res.data);
+    }
+  };
+  const renderTitle = (data_type, name) => {
+    if (compareValues?.length == 2) {
+      return (
+        <div className={styles.exportDiv}>
+          <Button
+            type="primary"
+            onClick={() => {
+              setCompareValues([]);
+              setTimeout(() => {
+                initPsrActrual(key);
+              }, 500);
+            }}
+          >
+            退出比对
+          </Button>
+        </div>
+      );
+    }
+    let content;
+    switch (data_type) {
+      case 0:
+        //投标版psr
+        if (user?.Permission['func-psr-export-01'])
+          content = (
+            <div className={styles.exportDiv}>
+              <Button
+                type="primary"
+                onClick={() => exportExcl(name)}
+                disabled={noData}
+              >
+                导出
+              </Button>
+            </div>
+          );
+        break;
+      case 3:
+        //签字版psr
+        if (user?.Permission['func-psr-export-02'])
+          content = (
+            <div className={styles.excelTitle}>
+              <div style={{ minWidth: '10px' }}>
+                {/* 当前PSR表单:
+              <span style={{ color: 'blue' }}>{excelData?.name}</span> */}
+              </div>
+              <Space>
+                <Button
+                  type="primary"
+                  onClick={() => {
+                    run(init_flow_id);
+                    setHistoryOpen(true);
+                  }}
+                  disabled={noData}
+                >
+                  历史版本
+                </Button>
+                <Button
+                  type="primary"
+                  onClick={() => exportExcl(name)}
+                  disabled={noData}
+                >
+                  导出
+                </Button>
+              </Space>
+            </div>
+          );
+        break;
+      default:
+        let text, canExport, canSaveAs;
+        if (data_type == 1) {
+          text = 'PSR';
+          canExport = user?.Permission['func-psr-export-03'];
+          canSaveAs = user.Permission['func-psr-saveas-03'];
+        } else {
+          text = '现金流';
+          canExport = user?.Permission['func-psr-export-04'];
+          canSaveAs = user.Permission['func-actual-saveas-04'];
+        }
+        //过程/终版psr  现金流
+        content = (
+          <div className={styles.excelTitle}>
+            <div>
+              当前{text}表单:
+              <span style={{ color: 'blue' }}>{excelData?.name}</span>
+            </div>
+            <Space>
+              <Button
+                type="primary"
+                onClick={() => {
+                  runList();
+                  setHistoryOpen(true);
+                }}
+                disabled={noData}
+              >
+                历史版本
+              </Button>
+              {canSaveAs && (
+                <Button
+                  type="primary"
+                  onClick={() => setOpen(true)}
+                  disabled={!excelData?.is_edit}
+                >
+                  另存为
+                </Button>
+              )}
+              <Button
+                type="primary"
+                onClick={handlerSave}
+                loading={saveLoading}
+                disabled={!excelData?.is_edit || isOriginVer}
+              >
+                保存
+              </Button>
+              <Button
+                type="primary"
+                onClick={() => setCompareOpen(true)}
+                disabled={noData}
+              >
+                比对
+              </Button>
+              {canExport && (
+                <Button
+                  type="primary"
+                  onClick={() => exportExcl(excelData?.name)}
+                  disabled={noData}
+                >
+                  导出
+                </Button>
+              )}
+            </Space>
+          </div>
+        );
+    }
+    return content;
+  };
+
   const renderSheet = (currentData, is_edit = false, day = '') => {
     if (!currentData || !currentData[0]?.celldata) {
       setNoData(true);
@@ -758,137 +903,6 @@ const PSRDetail = () => {
     luckysheetRef.current.create(option);
   };
 
-  const fillWorkLoadData = async (day) => {
-    const param = { project_id: projectId };
-    param.code = workConfig.map((item) => item.code).join(',');
-    param.s_time = dayjs(day).add(-1, 'month').format('YYYY-MM') + '-26';
-    param.e_time = dayjs(day).format('YYYY-MM') + '-25';
-    const res = await queryPsrWorkLoad(param);
-    if (res?.data) {
-      const data = res?.data; //{ '02-010': [800, 100] };
-      Object.keys(data).forEach((code) => {
-        const list = data[code]; //第一个是当月的,第二个是累计的
-        const fill = workConfig.find((item) => item.code == code)?.fill;
-        if (list?.length > 0 && fill) {
-          luckysheetRef.current.setCellValue(fill.r, fill.curC, list[0]);
-          luckysheetRef.current.setCellValue(fill.r, fill.actC, list[1]);
-        }
-      });
-      console.log('--------------------', res.data);
-    }
-  };
-  const renderTitle = (data_type, name) => {
-    if (compareValues?.length == 2) {
-      return (
-        <div className={styles.exportDiv}>
-          <Button
-            type="primary"
-            onClick={() => {
-              setCompareValues([]);
-              setTimeout(() => {
-                initPsrActrual(key);
-              }, 500);
-            }}
-          >
-            退出比对
-          </Button>
-        </div>
-      );
-    }
-    if (data_type == 0)
-      //投标版psr
-      return (
-        <div className={styles.exportDiv}>
-          <Button
-            type="primary"
-            onClick={() => exportExcl(name)}
-            disabled={noData}
-          >
-            导出
-          </Button>
-        </div>
-      );
-    if (data_type == 3)
-      //签字版psr
-      return (
-        <div className={styles.excelTitle}>
-          <div style={{ minWidth: '10px' }}>
-            {/* 当前PSR表单:
-            <span style={{ color: 'blue' }}>{excelData?.name}</span> */}
-          </div>
-          <Space>
-            <Button
-              type="primary"
-              onClick={() => {
-                run(init_flow_id);
-                setHistoryOpen(true);
-              }}
-              disabled={noData}
-            >
-              历史版本
-            </Button>
-            <Button
-              type="primary"
-              onClick={() => exportExcl(name)}
-              disabled={noData}
-            >
-              导出
-            </Button>
-          </Space>
-        </div>
-      );
-    //过程/终版psr  现金流
-    return (
-      <div className={styles.excelTitle}>
-        <div>
-          当前{key == '4' ? '现金流' : 'PSR'}表单:
-          <span style={{ color: 'blue' }}>{excelData?.name}</span>
-        </div>
-        <Space>
-          <Button
-            type="primary"
-            onClick={() => {
-              runList();
-              setHistoryOpen(true);
-            }}
-            disabled={noData}
-          >
-            历史版本
-          </Button>
-          <Button
-            type="primary"
-            onClick={() => setOpen(true)}
-            disabled={!excelData?.is_edit}
-          >
-            另存为
-          </Button>
-          <Button
-            type="primary"
-            onClick={handlerSave}
-            loading={saveLoading}
-            disabled={!excelData?.is_edit || isOriginVer}
-          >
-            保存
-          </Button>
-          <Button
-            type="primary"
-            onClick={() => setCompareOpen(true)}
-            disabled={noData}
-          >
-            比对
-          </Button>
-          <Button
-            type="primary"
-            onClick={() => exportExcl(excelData?.name)}
-            disabled={noData}
-          >
-            导出
-          </Button>
-        </Space>
-      </div>
-    );
-  };
-
   const changeDate = (date) => {
     date = dayjs(date);
     const startDate = dayjs('1900-01-01');
@@ -896,71 +910,38 @@ const PSRDetail = () => {
     return daysDifference;
   };
 
-  const items = [
-    {
-      key: '1',
-      label: '投标版PSR',
-      children: renderTitle(0, '投标版PSR'),
-    },
-    {
-      key: '2',
-      label: '签字版PSR',
-      children: renderTitle(3, '签字版PSR'),
-    },
-    {
-      key: '3',
-      label: '过程/终版PSR',
-      children: renderTitle(1, '过程/终版PSR'),
-    },
-    {
-      key: '4',
-      label: '现金流',
-      children: renderTitle(2, '现金流'),
-    },
-  ];
-
-  // const handlerOnChange = (event) => {
-  //   console.log(event);
-  //   console.log('----------------', luckysheetRef.current);
-  //   var file = event.target.files[0];
-  //   var fileName = file.name;
-  //   fileName = fileName + '';
-  //   //將文件加載到頁面上
-  //   LuckyExcel.transformExcelToLucky(
-  //     file,
-  //     function (exportJson, luckysheetfile) {
-  //       if (exportJson.sheets == null || exportJson.sheets.length == 0) {
-  //         alert(
-  //           'Failed to read the content of the excel file, currently does not support xls files!',
-  //         );
-  //         return;
-  //       }
-  //       console.log(exportJson, luckysheetfile);
-  //       renderSheet(exportJson?.sheets);
-  //       // window.luckysheet.destroy();
-
-  //       // window.luckysheet.create({
-  //       //     container: 'luckysheet', //luckysheet is the container id
-  //       //     showinfobar:false,
-  //       //     lang: 'zh', // 设定表格语言
-  //       //     allowEdit: true,//作用:是否允许前台编辑
-  //       //     // allowUpdate: true,
-  //       //     allowCopy: true, //是否允许拷贝
-  //       //     showtoolbar: true, //是否第二列显示工具栏
-  //       //     showinfobar: true, //是否显示顶部名称栏
-  //       //     showsheetbar: true, //是否显示底部表格名称区域
-  //       //     showstatisticBar: true, //是否显示底部计数栏
-  //       //     pointEdit: false, //是否是编辑器插入表格模式
-  //       //     pointEditUpdate: null, //编辑器表格更新函数
-  //       //     data:exportJson.sheets,
-  //       //     title:exportJson.info.name,
-  //       //     userInfo:exportJson.info.name.creator,
-  //       //     functionButton: '<button id="" class="btn btn-primary" style=" padding:3px 6px; font-size: 16px;width: 100px;height: 27px; margin-right: 85px;" οnclick="downExcelData()">導出</button>',
+  const items = useMemo(() => {
+    const { Permission } = user;
+    console.log('-00000000000000----------Permission-----', Permission);
+    const list = [];
+    if (Permission['func-psr-tab-01'])
+      list.push({
+        key: '1',
+        label: '投标版PSR',
+        children: renderTitle(0, '投标版PSR'),
+      });
+    if (Permission['func-psr-tab-02'])
+      list.push({
+        key: '2',
+        label: '签字版PSR',
+        children: renderTitle(3, '签字版PSR'),
+      });
+    if (Permission['func-psr-tab-03'])
+      list.push({
+        key: '3',
+        label: '过程/终版PSR',
+        children: renderTitle(1, '过程/终版PSR'),
+      });
+    if (Permission['func-psr-tab-04'])
+      list.push({
+        key: '4',
+        label: '现金流',
+        children: renderTitle(2, '现金流'),
+      });
 
-  //       // });
-  //     },
-  //   );
-  // };
+    list.length > 0 ? setKey(list[0].key) : setNoData(true);
+    return list;
+  }, [user]);
 
   const handlerDetailClick = (id) => {
     if (key == '2') {
@@ -977,11 +958,10 @@ const PSRDetail = () => {
         <Button type="primary" onClick={() => navigate(-1)}>
           返回
         </Button>
-        {/* <input type="file" onChange={handlerOnChange} /> */}
         <span className={styles.title}>{project_name}</span>
       </div>
       <Tabs
-        defaultActiveKey="1"
+        // defaultActiveKey={items?.length > 0 ? items[0]?.key : ''}
         type="card"
         items={items}
         onChange={(key) => {

+ 3 - 2
src/pages/PSRManage/index.js

@@ -25,14 +25,15 @@ const PSRManage = () => {
       setSearchData({ ...searchData, current_page: 1, page_size });
     },
   });
-  // console.log(data?.list);
   const columns = [
     {
       title: '项目编号',
+      key: 'project_full_code',
       dataIndex: 'project_full_code',
     },
     {
       title: '项目名称',
+      key: 'project_name',
       dataIndex: 'project_name',
     },
     {
@@ -60,7 +61,6 @@ const PSRManage = () => {
       ),
     },
   ];
-  const projectData = [];
 
   const handleSearch = () => {
     run({ ...searchData });
@@ -109,6 +109,7 @@ const PSRManage = () => {
         </Button>
       </div>
       <Table
+        rowKey="id"
         columns={columns}
         dataSource={data?.list}
         onChange={onTableChange}