index.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import FileModal from '@/components/FileModal'
  2. import Header from '@/components/Header'
  3. import Slot from '@/components/Header/slot'
  4. import RuleModal from '@/components/RuleModal'
  5. import SvgIcon from '@/components/SvgIcon'
  6. import { tenderStore } from '@/store/mobx'
  7. import { iCreateSafe } from '@/types/safe'
  8. import { safeStatus } from '@/utils/common/constStatus'
  9. import consts from '@/utils/consts'
  10. import { dayjsFomrat } from '@/utils/util'
  11. import { SettingOutlined } from '@ant-design/icons'
  12. import { Button, message, Table } from 'antd'
  13. import { ColumnsType } from 'antd/lib/table'
  14. import React, { useEffect, useState } from 'react'
  15. import { Link } from 'react-router-dom'
  16. import { apiCreateSafe, apiSafeList, apiSaveRule } from './api'
  17. import AddModel from './modal'
  18. interface iSafeList {
  19. id: string;
  20. code: string;
  21. createTime: string;
  22. position: string;
  23. inspection: string;
  24. inspectionDetail: string;
  25. demand: string;
  26. status: number;
  27. auditName: string;
  28. fileCounts: number;
  29. }
  30. interface iModal {
  31. visible: boolean
  32. loading: boolean
  33. }
  34. interface iFileModal {
  35. visible: boolean
  36. dataType: number
  37. dataId: string
  38. }
  39. const SafeList:React.FC<{}> =() => {
  40. const [ ruleModal, setRuleModal ] = useState<iModal>({
  41. visible: false,
  42. loading: false
  43. })
  44. const [ addModal, setAddModal ] = useState<iModal>({
  45. visible: false,
  46. loading: false
  47. })
  48. const [ fileModal, setFileModal ] = useState<iFileModal>({
  49. visible: false,
  50. dataType: consts.DATA_TYPE.SAFE,
  51. dataId: ''
  52. })
  53. useEffect(() => {
  54. initData()
  55. }, [])
  56. const columns:ColumnsType<iSafeList> = [
  57. {
  58. title: '序号',
  59. // eslint-disable-next-line react/display-name
  60. render: (_: string, record: any, i: number) => {
  61. return <span>{i + 1}</span>
  62. }
  63. },
  64. {
  65. title: '编号',
  66. dataIndex: 'code',
  67. // eslint-disable-next-line react/display-name
  68. render: (text: string, record) => {
  69. return <Link to={{ pathname: "/console/safe/content/detail/info", state: { saveId: record.id } }}>{text}</Link>
  70. }
  71. },
  72. {
  73. title: '检查项目',
  74. dataIndex: 'inspection'
  75. },
  76. {
  77. title: '现场检查情况',
  78. dataIndex: 'inspection_detail'
  79. },
  80. {
  81. title: '处理要求及措施',
  82. dataIndex: 'demand'
  83. },
  84. {
  85. title: '检查日期',
  86. dataIndex: 'create_time',
  87. // eslint-disable-next-line react/display-name
  88. render: (text: string) => {
  89. return <span>{dayjsFomrat(text, 'YYYY-MM-DD')}</span>
  90. }
  91. },
  92. {
  93. title: '检查人',
  94. dataIndex: 'auditName'
  95. },
  96. {
  97. title: '附件',
  98. dataIndex: 'fileCounts',
  99. // eslint-disable-next-line react/display-name
  100. render: (text: string, record) => {
  101. return <span className="pi-pointer" onClick={() => setFileModal({ ...fileModal, dataId: record.id, visible: true })}><SvgIcon type="xxh-paperclip1"></SvgIcon> {text}</span>
  102. }
  103. },
  104. {
  105. title: '状态',
  106. dataIndex: 'status',
  107. // eslint-disable-next-line react/display-name
  108. render: (statu: number) => {
  109. return <span className={safeStatus[statu].className}>{safeStatus[statu].text}</span>
  110. }
  111. }
  112. ]
  113. const [ list, setList ] = useState<iSafeList[]>([
  114. {
  115. id: '',
  116. code: '',
  117. createTime: '',
  118. position: '',
  119. inspection: '',
  120. inspectionDetail: '',
  121. demand: '',
  122. status: 0,
  123. auditName: '',
  124. fileCounts: 0
  125. }
  126. ])
  127. const [ total, setTotal ] = useState<number>(0)
  128. const initData = (pageNo: number = 1, pageSize: number = consts.PAGE_SIZE) => {
  129. apiSafeList(tenderStore.bid, pageNo, pageSize).then(({ code = -1, data = [], total = 0 }) => {
  130. if (code === consts.RET_CODE.SUCCESS) {
  131. setList(data)
  132. setTotal(total)
  133. }
  134. }).catch(err => {
  135. console.log(err)
  136. })
  137. }
  138. const onRuleCreate = async (ruleValue: any) => {
  139. setRuleModal({ ...ruleModal, loading: true })
  140. const { code = -1 } = await apiSaveRule({ bidsectionId: tenderStore.bid, type: 'safe_rule', rule: ruleValue })
  141. if (code === consts.RET_CODE.SUCCESS) {
  142. message.success("规则更改成功!")
  143. initData()
  144. }
  145. setRuleModal({ ...ruleModal, loading: false, visible: false })
  146. }
  147. const onAddCreate = async (payload: iCreateSafe) => {
  148. setAddModal({ ...addModal, loading: true })
  149. const createTime = dayjsFomrat(payload.createTime)
  150. const { code = -1 } = await apiCreateSafe({ ...payload, createTime })
  151. if (code === consts.RET_CODE.SUCCESS) {
  152. initData()
  153. }
  154. setAddModal({ ...addModal, loading: false, visible: false })
  155. }
  156. return (
  157. <div className="wrap-contaniner">
  158. <Header title="巡检概况">
  159. <Slot position="right">
  160. {
  161. !list.length ?
  162. <Button type="ghost" size="small" icon={<SettingOutlined />} className="pi-mg-right-3" style={{ color: '#007bff' }} onClick={() => setRuleModal({ ...ruleModal, visible: true })}>设置</Button>
  163. : ""
  164. }
  165. <Button type="primary" size="small" onClick={() => setAddModal({ ...addModal, visible: true })}>新建巡检</Button>
  166. </Slot>
  167. </Header>
  168. <Table
  169. dataSource={list}
  170. columns={columns}
  171. pagination={{
  172. hideOnSinglePage: true,
  173. size: "small",
  174. pageSize: consts.PAGE_SIZE,
  175. onChange: (page, pageSize) => initData(page, pageSize),
  176. total
  177. }}
  178. rowKey={record => record.id}
  179. bordered
  180. >
  181. </Table>
  182. <RuleModal
  183. type={consts.RULE.SAFE}
  184. title="安全巡检编号设置"
  185. visible={ruleModal.visible}
  186. onCreate={onRuleCreate}
  187. loading={ruleModal.loading}
  188. onCancel={() => setRuleModal({ ...ruleModal, visible: false })}
  189. >
  190. </RuleModal>
  191. <AddModel
  192. visible={addModal.visible}
  193. onCreate={onAddCreate}
  194. loading={addModal.loading}
  195. onCancel={() => setAddModal({ ...addModal, visible: false })}
  196. >
  197. </AddModel>
  198. <FileModal
  199. visible={fileModal.visible}
  200. dataType={fileModal.dataType}
  201. dataId={fileModal.dataId}
  202. onCancel={() => setFileModal({ ...fileModal, visible: false })}
  203. ></FileModal>
  204. </div>
  205. )
  206. }
  207. export default SafeList