Browse Source

页面更新

XuZinan 2 years ago
parent
commit
417fa8d241
3 changed files with 154 additions and 26 deletions
  1. 65 20
      src/pages/Auth/Auth.js
  2. 87 4
      src/pages/Auth/models/auth.js
  3. 2 2
      src/services/bomAuth.js

+ 65 - 20
src/pages/Auth/Auth.js

@@ -1,52 +1,97 @@
-import React, { useState } from 'react';
+import React, { useEffect } from 'react';
 import { Table, Collapse } from 'antd';
-import { connect } from 'umi';
+import { connect } from 'dva';
+import router from 'umi/router';
 
 const { Panel } = Collapse;
 
 function Auth(props) {
-  const { dispatch } = props;
+  const {
+    dispatch,
+    authList,
+    checkedList,
+    checkedPagination,
+    typeOptions,
+    currentUser,
+    loading,
+  } = props;
+
+  useEffect(() => {
+    if (!currentUser.ID) return;
+    dispatch({
+      type: 'auth/queryAuthList',
+      payload: { user_id: currentUser.ID },
+    });
+    dispatch({
+      type: 'auth/queryCheckedList',
+      payload: { user_id: currentUser.ID, params: {} },
+    });
+  }, [currentUser]);
+
+  useEffect(() => {
+    dispatch({
+      type: 'auth/queryClassify',
+    });
+  }, []);
 
   const columns = [
     { title: '流程名称', dataIndex: 'name' },
-    { title: '所属项目', dataIndex: 'project' },
+    { title: '所属项目', dataIndex: 'project_name' },
   ];
 
   const flowColumns = [
-    { title: '名称', dataIndex: 'name' },
-    { title: '节点', dataIndex: 'node' },
+    { title: '名称', dataIndex: 'version_name' },
+    { title: '节点', dataIndex: 'node_name' },
     { title: '创建人', dataIndex: 'author' },
-    { title: '分类', dataIndex: 'type' },
-    { title: '状态', dataIndex: 'status' },
-    { title: '印章申请', render: () => '-' },
-    { title: '操作', render: () => <a>加载</a> },
+    {
+      title: '分类',
+      render: (_, record) => typeOptions.find(cur => cur.id == record.classify_id)?.name,
+    },
+    { title: '操作', render: (_, record) => <a onClick={() => loadNode(record)}>加载</a> },
   ];
 
-  const temp = [{ name: '测试', project: '测试' }];
+  const loadNode = item => {
+    localStorage.excelItem = JSON.stringify({ version_id: item.version_id });
+    router.push(`/home/detail/${item.project_id}/${item.template_id}`);
+  };
 
-  const flowTemp = [{ name: '测试', node: '测试', author: '测试', type: '测试', status: '测试' }];
-
-  const renderUnauth = () => (
-    <Table columns={flowColumns} dataSource={flowTemp} pagination={false} />
+  const renderUnauth = data => (
+    <Table columns={flowColumns} dataSource={data} pagination={false} rowKey="id" />
   );
 
-  const renderAuth = () => <Table columns={flowColumns} dataSource={flowTemp} pagination={false} />;
+  const renderAuth = data => (
+    <Table columns={flowColumns} dataSource={data} pagination={false} rowKey="id" />
+  );
 
   return (
     <Collapse defaultActiveKey={['0']}>
       <Panel header="未审批" key="0">
         <Table
           columns={columns}
-          dataSource={temp}
-          expandable={{ expandedRowRender: renderUnauth }}
+          dataSource={authList}
+          expandable={{ expandedRowRender: record => renderUnauth(record.nodes) }}
           pagination={false}
+          rowKey="key"
         />
       </Panel>
       <Panel header="已审批" key="1">
-        <Table columns={columns} dataSource={temp} expandable={{ expandedRowRender: renderAuth }} />
+        <Table
+          columns={columns}
+          dataSource={checkedList}
+          expandable={{ expandedRowRender: record => renderAuth(record.nodes) }}
+          pagination={false}
+          rowKey="key"
+        />
       </Panel>
     </Collapse>
   );
 }
 
-export default Auth;
+export default connect(({ auth, loading, user }) => ({
+  authList: auth.authList,
+  checkedList: auth.checkedList.list,
+  checkedPagination: auth.checkedList.pagination,
+  typeOptions: auth.typeOptions,
+  loading: loading.models.auth,
+  currentUser: user.currentUser,
+}))(Auth);

+ 87 - 4
src/pages/Auth/models/auth.js

@@ -1,11 +1,94 @@
-import { queryAuthList, queryCheckedList } from '@/services/BomAuth';
+import { queryAuthList, queryCheckedList } from '@/services/bomAuth';
+import { queryClassify } from '@/services/boom';
 export default {
-  namespace: 'detail',
+  namespace: 'auth',
   state: {
     authList: [],
-    checkedList: [],
+    checkedList: { list: [], pagination: {} },
+  },
+  effects: {
+    *queryAuthList({ payload }, { call, put }) {
+      const responce = yield call(queryAuthList, payload);
+      if (responce) {
+        let data = responce.data;
+        let ret = [];
+        data.forEach(e => {
+          let item = ret.find(item => item.key == `${e.template_id}_${e.project_id}`);
+          if (!item) {
+            item = {
+              key: `${e.template_id}_${e.project_id}`,
+              name: e.name,
+              project_name: e.ding_schema,
+              nodes: [],
+            };
+            ret.push(item);
+          }
+          item.nodes.push({
+            template_id: e.template_id,
+            project_id: e.project_id,
+            version_name: e.version_name,
+            node_name: e.TemplateNodeInfo?.label,
+            author: e.AuthorInfo?.CName,
+            classify_id: e.classify_id,
+            version_id: e.version_id,
+            id: e.id,
+          });
+        });
+        yield put({
+          type: 'save',
+          payload: { authList: ret },
+        });
+      }
+    },
+
+    *queryCheckedList({ payload }, { call, put }) {
+      const responce = yield call(queryCheckedList, payload);
+      if (responce) {
+        let data = responce.data.list;
+        let ret = [];
+        data.forEach(e => {
+          let item = ret.find(item => item.key == `${e.template_id}_${e.project_id}`);
+          if (!item) {
+            item = {
+              key: `${e.template_id}_${e.project_id}`,
+              name: e.name,
+              project_name: e.ding_schema,
+              nodes: [],
+            };
+            ret.push(item);
+          }
+          item.nodes.push({
+            template_id: e.template_id,
+            project_id: e.project_id,
+            version_name: e.version_name,
+            node_name: e.TemplateNodeInfo?.label,
+            author: e.AuthorInfo?.CName,
+            classify_id: e.classify_id,
+            version_id: e.version_id,
+            id: e.id,
+          });
+        });
+        yield put({
+          type: 'save',
+          payload: { checkedList: { list: ret, pagination: responce.data.pagination } },
+        });
+      }
+    },
+
+    *queryClassify({ payload, callback }, { call, put }) {
+      const data = yield call(queryClassify, payload);
+      if (data) {
+        yield put({
+          type: 'save',
+          payload: {
+            typeOptions: data?.map(item => {
+              return { ...item, label: item.name, value: item.id };
+            }),
+          },
+        });
+      }
+    },
   },
-  effects: {},
   reducers: {
     save(state, action) {
       return {

+ 2 - 2
src/services/bomAuth.js

@@ -3,12 +3,12 @@ import { stringify } from 'qs';
 
 //获取未审核列表
 //params: user_id
-export async function queryAuthList(user_id) {
+export async function queryAuthList({ user_id }) {
   return request(`/purchase/bom/get-audit-list/${user_id}`);
 }
 
 //获取已审核列表
 //params: user_id, page_size, current_page
-export async function queryCheckedList(user_id, params) {
+export async function queryCheckedList({ user_id, params }) {
   return request(`/purchase/bom/get-checked-list/${user_id}?${stringify(params)}`);
 }