ZhaoJun há 1 ano atrás
pai
commit
0b9304d400

+ 1 - 1
src/models/user.js

@@ -106,7 +106,7 @@ export default {
         }
         const resRole = yield call(queryUserRole, user.ID);
         let roleList = getRoleList(resRole.data.Dep);
-        console.log(roleList);
+        // console.log(roleList);
 
         yield put({
           type: 'saveCurrentUser',

+ 9 - 1
src/pages/PurchaseAdmin/PurchaseList/DailyRecord/components/RecordDetail.js

@@ -3,7 +3,15 @@ import styles from './index.less';
 import { useEffect, useState } from 'react';
 import { DeleteOutlined } from '@ant-design/icons';
 
-const RecordDetailModal = ({ visible, user, projects, loading = false, onOk, onCancel }) => {
+const RecordDetailModal = ({
+  detail,
+  visible,
+  user,
+  projects,
+  loading = false,
+  onOk,
+  onCancel,
+}) => {
   const RenderItem = item => {
     return (
       <div className={styles.itemCon}>

+ 16 - 5
src/pages/PurchaseAdmin/PurchaseList/DailyRecord/components/WriteRecordModal.js

@@ -8,7 +8,7 @@ const WriteRecordModal = ({ visible, user, projects, loading = false, onOk, onCa
   const [form] = Form.useForm();
   const defaultData = { code_id: '', title: '', content: '' };
   const [list, setList] = useState([defaultData]);
-  console.log(user, list);
+  // console.log(user, list);
 
   useEffect(() => {
     if (!visible) setList([defaultData]);
@@ -30,7 +30,7 @@ const WriteRecordModal = ({ visible, user, projects, loading = false, onOk, onCa
     newList.splice(idx, 1);
     setList(newList);
   };
-  console.log('00000000000---------', list);
+  // console.log('00000000000---------', list);
 
   const handleOk = () => {
     onOk(list);
@@ -41,6 +41,7 @@ const WriteRecordModal = ({ visible, user, projects, loading = false, onOk, onCa
       <Form
         labelCol={{ span: 4 }}
         wrapperCol={{ span: 18 }}
+        labelAlign="left"
         width="100%"
         style={{ marginBottom: 20 }}
         form={form}
@@ -90,7 +91,13 @@ const RenderItem = ({ idx, data, projects, onChange, onDelete }) => {
   }, [data.code_id]);
   return (
     <div className={styles.itemContent}>
-      <Form labelCol={{ span: 7 }} wrapperCol={{ span: 17 }} width="100%" form={form}>
+      <Form
+        labelCol={{ span: 8 }}
+        wrapperCol={{ span: 16 }}
+        labelAlign="left"
+        width="100%"
+        form={form}
+      >
         <Row>
           <Col span={12}>
             <Form.Item
@@ -105,6 +112,10 @@ const RenderItem = ({ idx, data, projects, onChange, onDelete }) => {
                   return { label: item.Name, value: item.ID };
                 })}
                 onChange={id => onChange(idx, { ...data, code_id: id })}
+                filterOption={(input, option) => {
+                  return option.label.includes(input);
+                }}
+                showSearch
               />
             </Form.Item>
           </Col>
@@ -124,8 +135,8 @@ const RenderItem = ({ idx, data, projects, onChange, onDelete }) => {
         </Row>
         <Form.Item
           style={{ marginBottom: 0 }}
-          labelCol={{ span: 3 }}
-          wrapperCol={{ span: 21 }}
+          labelCol={{ span: 4 }}
+          wrapperCol={{ span: 20 }}
           label="日志详情"
           initialValue={data.content}
           name="content"

+ 72 - 38
src/pages/PurchaseAdmin/PurchaseList/DailyRecord/index.js

@@ -5,19 +5,47 @@ import { connect } from 'dva';
 import RecordDetailModal from './components/RecordDetail';
 import styles from './index.less';
 import { useRequest } from 'ahooks';
-import { approvalAddLog, approvalEditLog, approvalLogOwnList } from '@/services/record';
+import {
+  approvalAddLog,
+  approvalDeleteLog,
+  approvalEditLog,
+  approvalLogDetail,
+  approvalLogOwnList,
+} from '@/services/record';
+import record from './models/record';
+import { log } from 'lodash-decorators/utils';
+import moment from 'moment';
 
 const DailyRecord = props => {
   const { currentUser, projects, dispatch } = props;
+
   const [date, setDate] = useState('');
-  const [visible, setVisible] = useState(false);
-  const [detailOpen, setDetailOpen] = useState(false);
+  const [writeVisible, setWriteVisible] = useState(false);
+  const [detailVisible, setDetailVisible] = useState(false);
+  const [selectedLogID, setselectedLogID] = useState('');
 
-  //请求列表
-  const { data, run, loading } = useRequest(date => approvalLogOwnList(date), {});
+  // 请求列表
+  const { data, run, loading } = useRequest(date => approvalLogOwnList(date));
 
-  //添加日志
+  // 查询日志详情
+  const { data: logDetail, run: runDetail, loading: detailLoading } = useRequest(
+    logID => approvalLogDetail(logID),
+    {
+      manual: true,
+    }
+  );
+
+  // 删除日志
   const { run: runAdd } = useRequest(approvalAddLog, {
+    manual: true,
+    onSuccess: () => {
+      message('删除日志成功');
+      run();
+    },
+  });
+
+  // 添加日志
+  const { run: runDelete } = useRequest(approvalDeleteLog, {
     manual: true,
     onSuccess: () => {
       message('添加日志成功');
@@ -25,7 +53,7 @@ const DailyRecord = props => {
     },
   });
 
-  //添加日志
+  // 编辑日志
   const { run: runEdit } = useRequest(approvalEditLog, {
     manual: true,
     onSuccess: () => {
@@ -34,56 +62,58 @@ const DailyRecord = props => {
     },
   });
 
+  const toDetail = record => {
+    console.log(record);
+    runDetail(record.log_id);
+  };
+
   const columns = [
     {
       title: '日志标题',
-      dataIndex: 'title',
+      key: 'log_title',
       width: '20%',
-    },
-    {
-      title: '日志概述',
-      dataIndex: 'doc',
-      render: doc => <div className={styles.doc}>{doc}</div>,
+      render: record => {
+        return `${record.author_name}的金科环境项目日志`;
+      },
     },
     {
       title: '提交人',
-      dataIndex: 'name',
+      dataIndex: 'author_name',
       width: '16%',
     },
     {
       title: '提交时间',
-      dataIndex: 'time',
+      dataIndex: 'c_time',
       width: '20%',
+      render: time => {
+        if (!time) {
+          return '--';
+        }
+        return moment(time).format('YYYY-DD-MM HH:mm');
+      },
     },
     {
       title: '操作',
       width: '20%',
-      render: () => (
-        <Space>
-          <a>编辑</a>
-          <a onClick={() => setDetailOpen(true)}>详情</a>
-          <a>删除</a>
-        </Space>
-      ),
-    },
-  ];
-
-  const dataSource = [
-    {
-      name: '管理员',
-      title: '管理员的金科环境项目日志',
-      time: '1993-49-49 22:23:99',
-      doc:
-        '十八大不愧是你打卡是你打八大不愧是你打卡是你打卡机阿萨你打看那看手八大不愧是你打卡是你打卡机阿萨你打看那看手八大不愧是你打卡是你打卡机阿萨你打看那看手八大不愧是你打卡是你打卡机阿萨你打看那看手卡机阿萨你打看那看手打',
+      render: record => {
+        return (
+          <Space>
+            <a>编辑</a>
+            <a onClick={() => toDetail(record)}>详情</a>
+            <a>删除</a>
+          </Space>
+        );
+      },
     },
   ];
 
   useEffect(() => {
-    dispatch({ type: 'record/queryProject' });
+    if (!projects?.length) {
+      dispatch({ type: 'record/queryProject' });
+    }
   }, []);
 
   const onChange = (date, dateString) => {
-    console.log(date, dateString);
     run({ s_time: `${dateString} 00:00:00`, e_time: `${dateString} 23:59:59` });
   };
   return (
@@ -95,19 +125,23 @@ const DailyRecord = props => {
             查询
           </Button>
         </Space>
-        <Button type="primary" onClick={() => setVisible(true)}>
+        <Button type="primary" onClick={() => setWriteVisible(true)}>
           写日志
         </Button>
       </div>
       <Table columns={columns} dataSource={data?.list} pagination={data?.pagination} />
       <WriteRecordModal
-        visible={visible}
+        visible={writeVisible}
         user={currentUser}
         projects={projects}
         onOk={runAdd}
-        onCancel={() => setVisible(false)}
+        onCancel={() => setWriteVisible(false)}
+      />
+      <RecordDetailModal
+        visible={detailVisible}
+        onCancel={() => setDetailVisible(false)}
+        detail={logDetail}
       />
-      <RecordDetailModal visible={detailOpen} onCancel={() => setDetailOpen(false)} />
     </div>
   );
 };

+ 24 - 4
src/services/record.js

@@ -1,20 +1,40 @@
 import request from '@/utils/request';
 import { stringify } from 'qs';
-//新增日志接口
+// 新增日志
 export async function approvalAddLog(params) {
   return request(`/api/v2/approval/log`, {
     method: 'POST',
     body: params,
   });
 }
-//编辑日志接口
+
+// 删除日志
+export async function approvalDeleteLog(params) {
+  return request(`/api/v2/approval/log/${params.id}`, {
+    method: 'DELETE',
+    body: params,
+  });
+}
+
+// 编辑日志
 export async function approvalEditLog(params) {
   return request(`/api/v2/approval/log/${params.id}`, {
     method: 'PUT',
     body: params,
   });
 }
-//请求个人日志列表
+// 请求个人日志列表
 export async function approvalLogOwnList(params) {
-  return request(`/api/v2/approval/log-own/list?${stringify(params)}`);
+  const res = await request(`/api/v2/approval/log-own/list?${stringify(params)}`);
+  return res?.data || { list: [], pagination: {} };
+}
+
+/**
+ * 查询日志详情
+ * @param {string} log_id
+ * @returns Promise<logDetail[]>
+ */
+export async function approvalLogDetail(logID) {
+  const res = await request(`/api/v2/approval/log/${logID}`);
+  return res?.data || [];
 }