import React, { useState, useEffect, useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { Form, Input, Button, Table, Row, Col, Select, Modal, DatePicker, Space, message, Spin } from 'antd';
import '@common/common.less';
import moment from "moment";
import "moment/locale/zh-cn"
import './index.less'
import apiObj from '@api/index';
import EditProblem from './editProblem';
import ProblemContext from './problem-context';
import { getValueFromEvent, disabledDate, getDaysBetween } from '@utils/index'
const { post, api, xPost } = apiObj;
const { Option } = Select;
function FieldProblem() {
const [logList, setLogList] = useState([]);
const [total, setTotal] = useState(0);
const [type, setType] = useState(0);//1新增 2修改
const [visible, setVisible] = useState(false);
const [size, setSize] = useState(15);
const [current, setCurrent] = useState(1);
const [loading, setLoading] = useState(false);
const [probleData, setProbleData] = useState({});
const [problemDetail, setProblemDetail] = useState(null);//详情数据
const [title, setTitle] = useState();//正则式数据
const [modeList, setModeList] = useState([]);//质控模块
const [params, setParams] = useState({
pages: 1,
current: 1,
size: 15,
asc: ['isSolved'],
desc: ['solveTime', 'behospitalCode'],
behospitalStartDate: getCurrentDataFront().split('/').join('-') + ' 00:00:00',
behospitalEndDate: getCurrentData().split('/').join('-') + ' 23:59:59'
});
const [form] = Form.useForm();
let data = {
pages: 1,
current: 1,
size: 15,
asc: ['isSolved'],
desc: ['solveTime', 'behospitalCode'],
behospitalStartDate: getCurrentDataFront().split('/').join('-') + ' 00:00:00',
behospitalEndDate: getCurrentData().split('/').join('-') + ' 23:59:59'
}
let date = {
behospitalStartDate: getCurrentDataFront().split('/').join('-') + ' 00:00:00',
behospitalEndDate: getCurrentData().split('/').join('-') + ' 23:59:59'
}
const { problemNum } = useSelector((state) => {
return state.userInfo;
});
useEffect(() => {
setCurrent(1)
setSize(15)
setParams(data)
form.resetFields();
getColumnResultPage(data);
getColumnResultNumber(date)
getModeName()
}, [problemNum]);
//表格数据
function getColumnResultPage(param) {
const hide = message.loading('加载中...', 0);
post(api.getColumnResultPage, param || params).then((res) => {
hide()
if (res.data.code === 200) {
const data = res.data.data;
setLogList(data.records);
setTotal(data.total)
setLoading(false)
}
}).catch((err) => {
hide()
})
}
function getColumnResultNumber(param) {
post(api.getColumnResultNumber, {
hospitalId: localStorage.getItem('hospitalId'),
...param
}).then((res) => {
if (res.data.code === 200) {
const data = res.data.data || [];
setProbleData(data)
}
})
}
function getModeName(name) {
post(api.getModeName, {
modeName: name
}).then((res) => {
if (res.data.code === 200) {
const data = res.data.data || [];
setModeList(data)
}
})
}
function onSearch(val) {
getModeName(val)
}
function showModal(title, row, type) {
setVisible(true)
setProblemDetail(row)
setTitle(title)
setType(type)
}
//返回
function cancel() {
setVisible(false)
setProblemDetail(null)
}
function userChange() {
params.current = 1
setParams(params)
setCurrent(1)
setVisible(false)
getColumnResultPage();
getColumnResultNumber({ behospitalStartDate: params.behospitalStartDate, behospitalEndDate: params.behospitalEndDate })
setProblemDetail(null)
}
function onSizeChange(current, pageSize) {
params.current = current
params.size = pageSize
setSize(pageSize)
setCurrent(current)
setParams(params)
}
function changePage(page, pageSize) {
params.current = page
params.size = pageSize
setParams(params)
setCurrent(page)
getColumnResultPage()
}
const onFinish = (value) => {
value.behospitalStartDate = moment(value.behospitalStartDate).format('YYYY-MM-DD 00:00:00');
value.behospitalEndDate = moment(value.behospitalEndDate).format('YYYY-MM-DD 23:59:59');
if (value.behospitalStartDate > value.behospitalEndDate) {
message.warning('开始时间不能大于结束时间');
return
} else if (getDaysBetween(value.behospitalStartDate, value.behospitalEndDate) > 364) {
message.warning('开始时间与结束时间相差不能超过一年');
return
}
const param = {
...data,
...value,
}
setCurrent(1)
setParams(param)
getColumnResultPage(param);
getColumnResultNumber({ behospitalStartDate: value.behospitalStartDate, behospitalEndDate: value.behospitalEndDate })
};
const onReset = () => {
setCurrent(1)
setSize(15)
setParams(data)
form.resetFields();
getColumnResultPage(data);
getColumnResultNumber(date)
};
function getCurrentDataFront() {
let time = new Date((new Date() - 30 * 24 * 3600 * 1000)).toLocaleDateString()
return time
}
// 结束时间
function getCurrentData() {
let time = new Date().toLocaleDateString()
return time
}
const columns = [
{ title: '序号', dataIndex: 'index', render: (text, record, index) => (current - 1) * params.size + index + 1 },
{ title: '住院序号', dataIndex: 'behospitalCode', key: 'behospitalCode' },
{
title: '文书编号', dataIndex: 'hosptialDatatmpCode', key: 'hosptialDatatmpCode', render: (text, record) => {
return record.hosptialDatatmpCode || '-';
}
},
{
title: '文书标题', dataIndex: 'hosptialDatatmpName', key: 'hosptialDatatmpName', render: (text, record) => {
return record.hosptialDatatmpName || '-';
}
},
{ title: '质控模块名称', dataIndex: 'modeName', key: 'modeName' },
{ title: '表名称(中文)', dataIndex: 'tableCname', key: 'tableCname' },
{ title: '表名称(英文)', dataIndex: 'tableEname', key: 'tableEname' },
{ title: '字段名称(中文)', dataIndex: 'columnCname', key: 'columnCname' },
{ title: '字段名称(英文)', dataIndex: 'columnEname', key: 'columnEname' },
{
title: '上传字段值', dataIndex: 'tableVal', key: 'tableVal', render: (text, record) => {
return record.tableVal ? record.tableVal.length > 8 ? {record.tableVal.substring(0, 8) + '...'} : record.tableVal : '-';
}
},
{
title: '备注', dataIndex: 'description', key: 'description', render: (text, record) => {
return record.description ? record.description.length > 20 ? {record.description.substring(0, 20) + '...'} : record.description : '-';
}
},
{
title: '问题类型', dataIndex: 'type', render: (text, record) => {
return record.type == 1 ? "数据缺失" : record.type == 2 ? "非标准值" : "正则校验失败";
}
},
{
title: '更新时间', dataIndex: 'gmtModified', key: 'gmtModified', render: (text, record) => {
return record.gmtModified || '-';
}
},
{
title: '状态', dataIndex: 'isRequired', key: 'isRequired', render: (text, record) => {
return record.isSolved == 1 ? "已处理" : record.isSolved == 0 ? "未处理" : "-";
}
},
{
title: '操作', dataIndex: 'key', render: (text, record) => (
{probleData.notSolvedNonnull || probleData.notSolvedNonnull == 0 ? probleData.notSolvedNonnull : '-'}
数据缺失
{probleData.notSolvedStandardvalue || probleData.notSolvedStandardvalue == 0 ? probleData.notSolvedStandardvalue : '-'}
非标准值
{probleData.notSolvedRegular || probleData.notSolvedRegular == 0 ? probleData.notSolvedRegular : '-'}
正则校验失败
{probleData.notSolved || probleData.notSolved == 0 ? probleData.notSolved : '-'}
未处理
{probleData.resolvedNonnull || probleData.resolvedNonnull == 0 ? probleData.resolvedNonnull : '-'}
数据缺失
{probleData.resolvedStandardvalue || probleData.resolvedStandardvalue == 0 ? probleData.resolvedStandardvalue : '-'}
非标准值
{probleData.resolvedRegular || probleData.resolvedRegular == 0 ? probleData.resolvedRegular : '-'}
正则校验失败
{probleData.resolved || probleData.resolved == 0 ? probleData.resolved : '-'}
已处理