You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
7.8 KiB
170 lines
7.8 KiB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
|
return new (P || (P = Promise))(function (resolve, reject) { |
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
|
}); |
|
}; |
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; |
|
import { ProCard, ProTable } from '@ant-design/pro-components'; |
|
import { useRef } from 'react'; |
|
import { Space, Button, Popconfirm, message } from 'antd'; |
|
import { getHiddenList, onAdd, onEdit, onDelete } from './action'; |
|
import Form from './form'; |
|
import { useServiceContext } from '../../context'; |
|
import { PlusCircleOutlined } from '@ant-design/icons'; |
|
import { hiddenDangerStatus, getHiddenTroubleGrade } from '../../CONST'; |
|
import { useRequest, useToggle } from 'ahooks'; |
|
import { Link } from 'react-router-dom'; |
|
import { dateFormatter, urlEncodeParams, themeMessage } from '@component/utils'; |
|
import { CardForm, CardDetail } from '@component/ui'; |
|
export default ({ readonly, title, required, serviceid, hiddenurl, setHiddenIds, }) => { |
|
var _a, _b, _c, _d; |
|
const actionRef = useRef(); |
|
const [value, { set }] = useToggle({ |
|
visible: false, |
|
}); |
|
/** |
|
* @auth: fengkai |
|
* @description: 专家端使用当前组件serviceId使用props中的 |
|
* @date: 2023/04/14 11:13 |
|
*/ |
|
// const { serviceId, hiddenUrl } = useServiceContext(); |
|
const serviceId = (_b = (_a = useServiceContext()) === null || _a === void 0 ? void 0 : _a.serviceId) !== null && _b !== void 0 ? _b : serviceid; |
|
const hiddenUrl = (_d = (_c = useServiceContext()) === null || _c === void 0 ? void 0 : _c.hiddenUrl) !== null && _d !== void 0 ? _d : hiddenurl; |
|
const { runAsync, confirmLoading } = useRequest(onDelete, { |
|
manual: true, |
|
onSuccess(result) { |
|
themeMessage(result); |
|
if (result.type === 'success') { |
|
init && init(); |
|
} |
|
}, |
|
onError(result) { |
|
message.error(result.message); |
|
}, |
|
}); |
|
const columns = [ |
|
{ |
|
title: '隐患编号', |
|
dataIndex: 'hiddenNumber', |
|
ellipsis: true, |
|
}, |
|
{ |
|
title: '隐患描述', |
|
dataIndex: 'description', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '隐患类型', |
|
dataIndex: 'classifyName', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '隐患分类', |
|
dataIndex: 'dangerTypeName', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '隐患等级', |
|
dataIndex: 'hiddenTroubleGrade', |
|
ellipsis: true, |
|
search: false, |
|
render: (_, item) => { |
|
return getHiddenTroubleGrade(item.hiddenTroubleGrade); |
|
}, |
|
}, |
|
{ |
|
title: '隐患所在场所/部位', |
|
dataIndex: 'discoveredAddress', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '整改状态', |
|
dataIndex: 'hiddenDangerStatus', |
|
ellipsis: true, |
|
search: false, |
|
render: (_, item) => { |
|
return hiddenDangerStatus[item.hiddenDangerStatus]; |
|
}, |
|
}, |
|
{ |
|
title: '更新时间', |
|
dataIndex: 'changedAt', |
|
ellipsis: true, |
|
search: false, |
|
renderText: dateFormatter, |
|
}, |
|
{ |
|
title: '操作', |
|
dataIndex: 'policyNumber', |
|
ellipsis: true, |
|
search: false, |
|
fixed: 'right', |
|
render(_, item) { |
|
if (readonly) { |
|
return (_jsx(Button, Object.assign({ type: "link", size: "small" }, { children: _jsx(Link, Object.assign({ to: `${hiddenUrl}${urlEncodeParams({ |
|
hiddenDangerId: item.hiddenDangerId, |
|
})}` }, { children: "\u8BE6\u60C5" })) }))); |
|
} |
|
return (_jsxs(Space, { children: [_jsx(Button, Object.assign({ type: "link", size: "small", onClick: () => set({ |
|
visible: true, |
|
item: item, |
|
title: '企业现场隐患编辑', |
|
service: onEdit, |
|
}) }, { children: "\u7F16\u8F91" })), _jsx(Popconfirm, Object.assign({ placement: "top", title: "\u786E\u8BA4\u5220\u9664\u5417\uFF1F", onConfirm: () => handleDelete(item), okText: "\u786E\u8BA4", cancelText: "\u53D6\u6D88", getPopupContainer: (node) => { |
|
return document.body; |
|
}, okButtonProps: { loading: confirmLoading } }, { children: _jsx(Button, Object.assign({ type: "link", danger: true, size: "small" }, { children: "\u5220\u9664" })) }))] })); |
|
}, |
|
}, |
|
]; |
|
function init() { |
|
var _a; |
|
(_a = actionRef.current) === null || _a === void 0 ? void 0 : _a.reload(); |
|
} |
|
function handleDelete(item) { |
|
return runAsync({ |
|
hiddenDangerId: item.hiddenDangerId, |
|
}); |
|
} |
|
function onCancel() { |
|
set({ |
|
visible: false, |
|
}); |
|
} |
|
if (readonly) { |
|
return (_jsx(CardDetail, Object.assign({ title: title }, { children: _jsx(ProTable, { cardProps: { |
|
bodyStyle: { |
|
padding: 0, |
|
}, |
|
}, rowKey: "hiddenDangerId", actionRef: actionRef, params: { serviceId }, options: false, search: false, pagination: false, columns: columns, request: (params) => __awaiter(void 0, void 0, void 0, function* () { |
|
var _e; |
|
const res = yield getHiddenList(params); |
|
// 外部使用当前组件,把隐患列表传递出去 |
|
setHiddenIds && setHiddenIds((_e = res === null || res === void 0 ? void 0 : res.data) !== null && _e !== void 0 ? _e : []); |
|
return res; |
|
}) }) }))); |
|
} |
|
return (_jsxs(CardForm, Object.assign({ gutter: [10, 10], title: _jsxs(_Fragment, { children: [required && _jsx("i", Object.assign({ style: { color: 'red' } }, { children: "*" })), title] }), extra: !readonly && (_jsx(Button, Object.assign({ type: "link", size: "small", icon: _jsx(PlusCircleOutlined, {}), onClick: () => set({ |
|
item: null, |
|
title: '企业现场隐患添加', |
|
service: onAdd, |
|
visible: true, |
|
}) }, { children: "\u6DFB\u52A0" }))) }, { children: [value.visible && (_jsx(Form, { item: value.item, title: value.title, service: value.service, init: init, onCancel: onCancel, serviceid: serviceId })), _jsx(ProTable, { cardProps: { |
|
bodyStyle: { |
|
padding: 0, |
|
}, |
|
}, rowKey: "hiddenDangerId", actionRef: actionRef, params: { serviceId }, options: false, search: false, pagination: false, columns: columns, request: (params) => __awaiter(void 0, void 0, void 0, function* () { |
|
var _f; |
|
const res = yield getHiddenList(params); |
|
// 外部使用当前组件,把隐患列表传递出去 |
|
setHiddenIds && setHiddenIds((_f = res === null || res === void 0 ? void 0 : res.data) !== null && _f !== void 0 ? _f : []); |
|
return res; |
|
}) })] }))); |
|
};
|
|
|