index.tsx 6.3 KB

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