|
@@ -6,8 +6,9 @@ import RuleModal from '@/components/RuleModal'
|
|
import SvgIcon from '@/components/SvgIcon'
|
|
import SvgIcon from '@/components/SvgIcon'
|
|
import { tenderStore } from '@/store/mobx'
|
|
import { tenderStore } from '@/store/mobx'
|
|
import { iFileModal } from '@/types/file'
|
|
import { iFileModal } from '@/types/file'
|
|
-import { iCreateSafe } from '@/types/safe'
|
|
|
|
|
|
+import { iCreateSafe, iSafeList } from '@/types/safe'
|
|
import { safeStatus } from '@/utils/common/constStatus'
|
|
import { safeStatus } from '@/utils/common/constStatus'
|
|
|
|
+import { useListModal } from '@/utils/common/customHooks'
|
|
import consts from '@/utils/consts'
|
|
import consts from '@/utils/consts'
|
|
import { dayjsFormat } from '@/utils/util'
|
|
import { dayjsFormat } from '@/utils/util'
|
|
import { Button, message, Table } from 'antd'
|
|
import { Button, message, Table } from 'antd'
|
|
@@ -16,39 +17,29 @@ import React, { useEffect, useState } from 'react'
|
|
import { Link } from 'react-router-dom'
|
|
import { Link } from 'react-router-dom'
|
|
import { apiCreateSafe, apiSafeList, apiSaveRule } from './api'
|
|
import { apiCreateSafe, apiSafeList, apiSaveRule } from './api'
|
|
import AddModel from './modal'
|
|
import AddModel from './modal'
|
|
-interface iSafeList {
|
|
|
|
- id: string
|
|
|
|
- code: string
|
|
|
|
- createTime: string
|
|
|
|
- position: string
|
|
|
|
- inspection: string
|
|
|
|
- inspectionDetail: string
|
|
|
|
- demand: string
|
|
|
|
- status: number
|
|
|
|
- auditName: string
|
|
|
|
- fileCounts: number
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
interface iModal {
|
|
interface iModal {
|
|
visible: boolean
|
|
visible: boolean
|
|
loading: boolean
|
|
loading: boolean
|
|
}
|
|
}
|
|
|
|
|
|
const SafeList: React.FC<{}> = () => {
|
|
const SafeList: React.FC<{}> = () => {
|
|
- const [ ruleModal, setRuleModal ] = useState<iModal>({
|
|
|
|
- visible: false,
|
|
|
|
- loading: false
|
|
|
|
- })
|
|
|
|
- const [ addModal, setAddModal ] = useState<iModal>({
|
|
|
|
- visible: false,
|
|
|
|
- loading: false
|
|
|
|
- })
|
|
|
|
- const [ fileModal, setFileModal ] = useState<iFileModal>({
|
|
|
|
- visible: false,
|
|
|
|
- dataType: consts.DATA_TYPE.SAFE,
|
|
|
|
- dataId: ''
|
|
|
|
- })
|
|
|
|
- const [ safeList, setSafeList ] = useState<iSafeList[]>([])
|
|
|
|
- const [ total, setTotal ] = useState<number>(0)
|
|
|
|
|
|
+ const [ state, setState ] = useListModal(consts.DATA_TYPE.SAFE)
|
|
|
|
+ // const [ ruleModal, setRuleModal ] = useState<iModal>({
|
|
|
|
+ // visible: false,
|
|
|
|
+ // loading: false
|
|
|
|
+ // })
|
|
|
|
+ // const [ addModal, setAddModal ] = useState<iModal>({
|
|
|
|
+ // visible: false,
|
|
|
|
+ // loading: false
|
|
|
|
+ // })
|
|
|
|
+ // const [ fileModal, setFileModal ] = useState<iFileModal>({
|
|
|
|
+ // visible: false,
|
|
|
|
+ // dataType: consts.DATA_TYPE.SAFE,
|
|
|
|
+ // dataId: ''
|
|
|
|
+ // })
|
|
|
|
+ // const [ safeList, setSafeList ] = useState<iSafeList[]>([])
|
|
|
|
+ // const [ total, setTotal ] = useState<number>(0)
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
initData()
|
|
initData()
|
|
}, [])
|
|
}, [])
|
|
@@ -98,8 +89,8 @@ const SafeList: React.FC<{}> = () => {
|
|
// eslint-disable-next-line react/display-name
|
|
// eslint-disable-next-line react/display-name
|
|
render: (text: string, record) => {
|
|
render: (text: string, record) => {
|
|
return (
|
|
return (
|
|
- <span className="pi-pointer" onClick={() => setFileModal({ ...fileModal, dataId: record.id, visible: true })}>
|
|
|
|
- <SvgIcon type="xxh-paperclip1"></SvgIcon> {text}
|
|
|
|
|
|
+ <span className="pi-pointer" onClick={() => setState({ ...state, fileModal: { ...state.fileModal, dataId: record.id, visible: true } })}>
|
|
|
|
+ <SvgIcon type="xxh-paperclip1" /> {text}
|
|
</span>
|
|
</span>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
@@ -115,11 +106,14 @@ const SafeList: React.FC<{}> = () => {
|
|
]
|
|
]
|
|
|
|
|
|
const initData = (pageNo: number = 1, pageSize: number = consts.PAGE_SIZE) => {
|
|
const initData = (pageNo: number = 1, pageSize: number = consts.PAGE_SIZE) => {
|
|
|
|
+ const initModal = {
|
|
|
|
+ ruleModal: { loading: false, visible: false },
|
|
|
|
+ addModal: { loading: false, visible: false }
|
|
|
|
+ }
|
|
apiSafeList(tenderStore.bid, pageNo, pageSize)
|
|
apiSafeList(tenderStore.bid, pageNo, pageSize)
|
|
.then(({ code = -1, data = [], total = 0 }) => {
|
|
.then(({ code = -1, data = [], total = 0 }) => {
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
- setSafeList(data)
|
|
|
|
- setTotal(total)
|
|
|
|
|
|
+ setState({ ...state, dataList: data, total, ...initModal })
|
|
}
|
|
}
|
|
})
|
|
})
|
|
.catch(err => {
|
|
.catch(err => {
|
|
@@ -128,70 +122,71 @@ const SafeList: React.FC<{}> = () => {
|
|
}
|
|
}
|
|
|
|
|
|
const onRuleCreate = async (ruleValue: any) => {
|
|
const onRuleCreate = async (ruleValue: any) => {
|
|
- setRuleModal({ ...ruleModal, loading: true })
|
|
|
|
|
|
+ setState({ ...state, ruleModal: { ...state.ruleModal, loading: true } })
|
|
const { code = -1 } = await apiSaveRule({ bidsectionId: tenderStore.bid, type: 'safe_rule', rule: ruleValue })
|
|
const { code = -1 } = await apiSaveRule({ bidsectionId: tenderStore.bid, type: 'safe_rule', rule: ruleValue })
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
- message.success('规则更改成功!')
|
|
|
|
initData()
|
|
initData()
|
|
|
|
+ return message.success('规则更改成功!')
|
|
|
|
+ } else {
|
|
|
|
+ setState({ ...state, ruleModal: { ...state.ruleModal, loading: false } })
|
|
}
|
|
}
|
|
- setRuleModal({ ...ruleModal, loading: false, visible: false })
|
|
|
|
}
|
|
}
|
|
const onAddCreate = async (payload: iCreateSafe) => {
|
|
const onAddCreate = async (payload: iCreateSafe) => {
|
|
- setAddModal({ ...addModal, loading: true })
|
|
|
|
|
|
+ setState({ ...state, addModal: { ...state.addModal, loading: true } })
|
|
const createTime = dayjsFormat(payload.createTime)
|
|
const createTime = dayjsFormat(payload.createTime)
|
|
const { code = -1 } = await apiCreateSafe({ ...payload, createTime })
|
|
const { code = -1 } = await apiCreateSafe({ ...payload, createTime })
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
initData()
|
|
initData()
|
|
|
|
+ return message.success('添加新的巡检记录成功!')
|
|
|
|
+ }else {
|
|
|
|
+ setState({ ...state, addModal: { ...state.addModal, loading: false } })
|
|
}
|
|
}
|
|
- setAddModal({ ...addModal, loading: false, visible: false })
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return (
|
|
return (
|
|
<div className="wrap-contaniner">
|
|
<div className="wrap-contaniner">
|
|
<Header title="安全巡检">
|
|
<Header title="安全巡检">
|
|
<Slot position="right">
|
|
<Slot position="right">
|
|
- {!safeList.length ? (
|
|
|
|
|
|
+ {!state.dataList.length ? (
|
|
<Button
|
|
<Button
|
|
type="ghost"
|
|
type="ghost"
|
|
size="small"
|
|
size="small"
|
|
icon={<SvgIcon type="xxh-cog" />}
|
|
icon={<SvgIcon type="xxh-cog" />}
|
|
className="pi-mg-right-3"
|
|
className="pi-mg-right-3"
|
|
style={{ color: '#007bff' }}
|
|
style={{ color: '#007bff' }}
|
|
- onClick={() => setRuleModal({ ...ruleModal, visible: true })}>
|
|
|
|
|
|
+ onClick={() => setState({ ...state, ruleModal: { ...state.ruleModal, visible: true } })}>
|
|
设置
|
|
设置
|
|
</Button>
|
|
</Button>
|
|
- ) : (
|
|
|
|
- ''
|
|
|
|
- )}
|
|
|
|
|
|
+ ) : null}
|
|
|
|
|
|
<Authorization type="safe" auth="add">
|
|
<Authorization type="safe" auth="add">
|
|
- <Button type="primary" size="small" onClick={() => setAddModal({ ...addModal, visible: true })}>
|
|
|
|
|
|
+ <Button type="primary" size="small" onClick={() => setState({ ...state, addModal: { ...state.addModal, visible: true } })}>
|
|
新建巡检
|
|
新建巡检
|
|
</Button>
|
|
</Button>
|
|
</Authorization>
|
|
</Authorization>
|
|
</Slot>
|
|
</Slot>
|
|
</Header>
|
|
</Header>
|
|
<Table
|
|
<Table
|
|
- dataSource={safeList}
|
|
|
|
|
|
+ dataSource={state.dataList}
|
|
columns={columns}
|
|
columns={columns}
|
|
pagination={{
|
|
pagination={{
|
|
hideOnSinglePage: true,
|
|
hideOnSinglePage: true,
|
|
size: 'small',
|
|
size: 'small',
|
|
pageSize: consts.PAGE_SIZE,
|
|
pageSize: consts.PAGE_SIZE,
|
|
onChange: (page, pageSize) => initData(page, pageSize),
|
|
onChange: (page, pageSize) => initData(page, pageSize),
|
|
- total
|
|
|
|
|
|
+ total: state.total
|
|
}}
|
|
}}
|
|
rowKey={record => record.id}
|
|
rowKey={record => record.id}
|
|
- bordered></Table>
|
|
|
|
|
|
+ bordered />
|
|
<RuleModal
|
|
<RuleModal
|
|
type={consts.RULE.SAFE}
|
|
type={consts.RULE.SAFE}
|
|
title="安全巡检编号设置"
|
|
title="安全巡检编号设置"
|
|
- visible={ruleModal.visible}
|
|
|
|
|
|
+ visible={state.ruleModal.visible}
|
|
onCreate={onRuleCreate}
|
|
onCreate={onRuleCreate}
|
|
- loading={ruleModal.loading}
|
|
|
|
- onCancel={() => setRuleModal({ ...ruleModal, visible: false })}></RuleModal>
|
|
|
|
- <AddModel visible={addModal.visible} onCreate={onAddCreate} loading={addModal.loading} onCancel={() => setAddModal({ ...addModal, visible: false })}></AddModel>
|
|
|
|
- <FileModal visible={fileModal.visible} dataType={fileModal.dataType} dataId={fileModal.dataId} onCancel={() => setFileModal({ ...fileModal, visible: false })}></FileModal>
|
|
|
|
|
|
+ loading={state.ruleModal.loading}
|
|
|
|
+ onCancel={() => setState({ ...state, ruleModal: { ...state.ruleModal, visible: false } })} />
|
|
|
|
+ <AddModel visible={state.addModal.visible} onCreate={onAddCreate} loading={state.addModal.loading} onCancel={() => setState({ ...state, addModal: { ...state.addModal, visible: false } })} />
|
|
|
|
+ <FileModal visible={state.fileModal.visible} dataType={state.fileModal.dataType} dataId={state.fileModal.dataId} onCancel={() => setState({ ...state, fileModal: { ...state.fileModal, visible: false } })} />
|
|
</div>
|
|
</div>
|
|
)
|
|
)
|
|
}
|
|
}
|