Browse Source

添加状态过滤/页面中附件列表没更新bug

Renxy 2 years ago
parent
commit
9a8359ec00

+ 1 - 6
src/components/AttachmentTable/index.js

@@ -76,12 +76,7 @@ function AttachmentTable(props) {
   }, [excelFileList]);
   return (
     <>
-      <Table
-        rowKey="id"
-        loading={loading}
-        columns={columns}
-        dataSource={excelFileData}
-      />
+      <Table rowKey="id" loading={loading} columns={columns} dataSource={excelFileData} />
       <FileViewerModal
         data={exportData}
         visible={excelFileVisible}

+ 53 - 4
src/pages/Detail/FlowModal.js

@@ -46,6 +46,7 @@ function FlowModal(props) {
     NAME: '0',
     TYPE: '1',
     CREATOR: '2',
+    STATE: '3',
   };
   const {
     visible,
@@ -72,7 +73,7 @@ function FlowModal(props) {
   const [stepsData, setStepsData] = useState([]);
   const [versionVisible, setVersionVisible] = useState(false);
   const [selectType, setSelectType] = useState(SELECT_TYPE.NAME);
-  const [inputValue, setInputValue] = useState('');
+  const [inputValue, setInputValue] = useState();
 
   const [sealLoading, setSealLoading] = useState(false);
   // const [currentTempNodeId, setCurrentTempNodeId] = useState();
@@ -106,6 +107,8 @@ function FlowModal(props) {
     const id = args.nodeId || args.nodeIds[0];
     if (!id) return;
     let node = graphData.nodes.find(item => item.id == id);
+    //清除上次的筛选条件
+    clearSelected();
     initData(node.Id);
   };
 
@@ -374,8 +377,24 @@ function FlowModal(props) {
     updateSteps([]);
   };
 
+  const clearSelected = () => {
+    setSelectType(SELECT_TYPE.NAME);
+    setInputValue(null);
+  };
+
+  const filterState = () => {
+    const childrens = data
+      .map(item => (!item.flow_id && item.isParent ? item.children : item))
+      .flat(1);
+    if (inputValue !== STATE.FAILURE) {
+      return childrens.filter(item => item.status == 0 && item.audit_status == inputValue);
+    } else {
+      return childrens.filter(item => item.status == 1);
+    }
+  };
+
   useEffect(() => {
-    if (!inputValue) {
+    if (!inputValue && inputValue !== 0) {
       setShowData(data);
       return;
     }
@@ -390,10 +409,22 @@ function FlowModal(props) {
       case SELECT_TYPE.CREATOR:
         resultData = data.filter(item => item.AuthorInfo?.CName.includes(inputValue));
         break;
+      case SELECT_TYPE.STATE:
+        resultData = filterState();
+        break;
     }
     setShowData(resultData);
   }, [inputValue, data]);
 
+  //列表筛选状态
+  const STATE = {
+    NOSUBMIT: 0, //未提交
+    NOAPPROVE: 1, //待审批
+    REJECT: 2, //已拒绝
+    PASS: 3, //已通过
+    SUBMIT: 4, //已提交
+    FAILURE: 5, //已失效
+  };
   return (
     <>
       <Modal
@@ -419,7 +450,7 @@ function FlowModal(props) {
             <div style={{ display: 'flex', justifyContent: 'space-between' }}>
               <div style={{ width: '60%' }}>
                 <Select
-                  defaultValue={selectType}
+                  value={selectType}
                   style={{ width: '30%' }}
                   onChange={value => {
                     setSelectType(value);
@@ -429,8 +460,9 @@ function FlowModal(props) {
                   <Option value={SELECT_TYPE.NAME}>名称:</Option>
                   <Option value={SELECT_TYPE.TYPE}>分类:</Option>
                   <Option value={SELECT_TYPE.CREATOR}>创建人:</Option>
+                  <Option value={SELECT_TYPE.STATE}>状态:</Option>
                 </Select>
-                {selectType != SELECT_TYPE.TYPE && (
+                {(selectType == SELECT_TYPE.NAME || selectType == SELECT_TYPE.CREATOR) && (
                   <Input
                     style={{ width: '70%' }}
                     placeholder="请输入"
@@ -451,6 +483,23 @@ function FlowModal(props) {
                     }
                   />
                 )}
+                {selectType == SELECT_TYPE.STATE && (
+                  <Select
+                    showSearch
+                    allowClear
+                    style={{ width: '70%' }}
+                    placeholder="请选择状态"
+                    // options={typeOptions}
+                    onChange={id => setInputValue(id)}
+                  >
+                    <Option value={STATE.NOSUBMIT}>未提交</Option>
+                    <Option value={STATE.NOAPPROVE}>待审批</Option>
+                    <Option value={STATE.REJECT}>已拒绝</Option>
+                    <Option value={STATE.PASS}>已通过</Option>
+                    <Option value={STATE.SUBMIT}>已提交</Option>
+                    <Option value={STATE.FAILURE}>已失效</Option>
+                  </Select>
+                )}
               </div>
               {isOut && (
                 <Button type="primary" onClick={() => setVersionVisible(true)}>

+ 19 - 16
src/pages/Detail/FormAndFilesNode.js

@@ -16,24 +16,27 @@ const FormAndFilesNode = props => {
     return renderFrom(formData);
   }, [formData]);
 
-  if(formData) {
-    return  <Card title="审批信息">
-      <Row gutter={20}>
-        <Col span={12}>{FormContent}</Col>
-        
-        <Col span={12}>
-          <AttachmentTable version={version} canDelete={version.last_version == 0} />
-        </Col>
-      </Row>
-    </Card>
+  if (formData) {
+    return (
+      <Card title="审批信息">
+        <Row gutter={20}>
+          <Col span={12}>{FormContent}</Col>
+
+          <Col span={12}>
+            <AttachmentTable version={version} canDelete={version.last_version == 0} />
+          </Col>
+        </Row>
+      </Card>
+    );
+  } else if (excelFileList?.length > 0) {
+    return (
+      <Card title="附件信息">
+        <AttachmentTable version={version} canDelete={version.last_version == 0} />
+      </Card>
+    );
   } else {
-    return <Card title="附件信息">
-      
-      <AttachmentTable version={version} canDelete={version.last_version == 0} />
-    </Card>
+    return null;
   }
-
-
 };
 
 const renderFrom = data => {

+ 16 - 7
src/pages/Detail/Index.js

@@ -86,13 +86,22 @@ function Detail(props) {
   const cellPosition = useRef({});
 
   useEffect(() => {
-    if (!version.attachment_id) return;
-    dispatch({
-      type: 'detail/QueryExcelFiles',
-      payload: {
-        excel_id: version.attachment_id,
-      },
-    });
+    //不请求excelFileList 时清空excelFileList,否则会出现清单切换后如果attachment_id不存在,附件信息没有更新
+    if (!version.attachment_id) {
+      dispatch({
+        type: 'detail/save',
+        payload: {
+          excelFileList: [],
+        },
+      });
+    } else {
+      dispatch({
+        type: 'detail/QueryExcelFiles',
+        payload: {
+          excel_id: version.attachment_id,
+        },
+      });
+    }
   }, [version.id]);
 
   const projectId = parseInt(params.projectId);