index.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import Header from '@/components/Header'
  2. import Slot from '@/components/Header/slot'
  3. import RuleModal from '@/components/RuleModal'
  4. import SvgIcon from '@/components/SvgIcon'
  5. import { apiSaveRule } from '@/pages/Safe/Content/List/api'
  6. import { contractReturnStore, tenderStore } from '@/store/mobx'
  7. import { ContractTree, iModalProps } from '@/types/contract'
  8. import { contractTreeBaseId } from '@/utils/common/constStatus'
  9. import consts from '@/utils/consts'
  10. import { Button, message, Tooltip } from 'antd'
  11. import React, { useState } from 'react'
  12. import { apiResfulContract, apiResfulContractTree } from './api'
  13. import ContractModal from './components/Modal'
  14. import TableContent from './components/TableContent'
  15. import Authorization from '@/components/Authorization'
  16. import { RouteComponentProps } from 'react-router'
  17. import { ContractType } from '@/store/mobx/contractReturn'
  18. interface iModal {
  19. visible: boolean
  20. loading: boolean
  21. }
  22. const Income: React.FC<RouteComponentProps> = (props) => {
  23. const { history } = props
  24. const [ modalObj, setModalObj ] = useState<iModalProps>({
  25. type: '',
  26. visible: false,
  27. confirmLoading: false,
  28. contractType: 'income'
  29. })
  30. const [ row, setRow ] = useState<ContractTree>({
  31. elderBrother: false,
  32. isEnd: false,
  33. attribsortution: 0,
  34. attribution: '',
  35. bidsectionId: '',
  36. children: [],
  37. code: '',
  38. contractCode: '',
  39. contractId: '',
  40. contractName: '',
  41. contractPrice: '',
  42. contractReturned: '',
  43. contractStatus: 0,
  44. contractsPaid: '',
  45. createTime: '',
  46. depth: 0,
  47. id: '',
  48. name: '',
  49. operation: '',
  50. parentId: '',
  51. projectId: '',
  52. serial: 0,
  53. templateNumber: 0
  54. })
  55. const [ ruleModal, setRuleModal ] = useState<iModal>({
  56. visible: false,
  57. loading: false
  58. })
  59. const onCreate = async (values: any, type: any) => {
  60. setModalObj({
  61. ...modalObj,
  62. confirmLoading: true
  63. })
  64. const { code = -1, contract = {} } = await apiResfulContract(type, values)
  65. if (code === consts.RET_CODE.SUCCESS) {
  66. contractReturnStore.updateContract(contract)
  67. contractReturnStore.resetTree(tenderStore.bid)
  68. if (type === 'return') {
  69. contractReturnStore.changeUpdate('2')
  70. }
  71. }
  72. setModalObj({
  73. ...modalObj,
  74. type: '',
  75. visible: false,
  76. confirmLoading: false
  77. })
  78. }
  79. const changeModalType = (type: string) => {
  80. setModalObj({
  81. ...modalObj,
  82. visible: true,
  83. type
  84. })
  85. }
  86. const treeResfulApiHandler = async (type: string, payload: any) => {
  87. const { code = -1, section = {} } = await apiResfulContractTree(type, payload, consts.CONTRACT_TREE.RETURN)
  88. if (code === consts.RET_CODE.SUCCESS) {
  89. contractReturnStore.resetTree(tenderStore.bid)
  90. if (type !== 'add' && type !== 'del') {
  91. setRow({ ...row, ...section })
  92. }
  93. }
  94. }
  95. const onRuleCreate = async (ruleValue: any) => {
  96. setRuleModal({ ...ruleModal, loading: true })
  97. const { code = -1 } = await apiSaveRule({ bidsectionId: tenderStore.bid, type: 'contract_return_rule', rule: ruleValue })
  98. if (code === consts.RET_CODE.SUCCESS) {
  99. message.success("规则更改成功")
  100. }
  101. setRuleModal({ ...ruleModal, loading: false, visible: false })
  102. }
  103. // 切换到删除合同弹窗
  104. const handleReload = (type: string) => {
  105. setModalObj({ ...modalObj, visible: false })
  106. setTimeout(() => {
  107. setModalObj({ ...modalObj, visible: true, type })
  108. }, 300)
  109. }
  110. const showCBtn = () => {
  111. return !row.children && !row.contractCode && row.id
  112. }
  113. return (
  114. <div className="wrap-contaniner">
  115. <Header title="维护项目节:">
  116. <Slot position="left">
  117. <div className="pi-flex-row">
  118. {
  119. row.id ?
  120. <>
  121. <Tooltip title="添加子项">
  122. <Button type="text" icon={<SvgIcon type="xxh-plus" style={{ color: '#007bff', fontSize: 12 }} />} onClick={() => treeResfulApiHandler('add', { id: row.id, bidsectionId: row.bidsectionId, name: '' })} />
  123. </Tooltip>
  124. {
  125. !row.children?.length ?
  126. <Tooltip title="删除">
  127. <Button type="text" icon={<SvgIcon type="xxh-times" style={{ color: '#007bff', fontSize: 12 }} />} onClick={() => treeResfulApiHandler('del', { id: row.id, bidsectionId: row.bidsectionId })} />
  128. </Tooltip>
  129. : <span className="pi-width-32 pi-height-32 pi-pd-tb-4 pi-flex-row-center"><SvgIcon type="xxh-times" style={{ color: '#9a9a9a', fontSize: 12 }} /></span>
  130. }
  131. {
  132. row.parentId && row.parentId !== contractTreeBaseId ?
  133. <Tooltip title="升级">
  134. <Button type="text" icon={<SvgIcon type="xxh-arrow-left" style={{ color: '#007bff', fontSize: 12 }} onClick={() => treeResfulApiHandler('depth', { id: row.id, bidsectionId: row.bidsectionId, operation: 'upDepth' })} />} />
  135. </Tooltip>
  136. :
  137. <span className="pi-width-32 pi-height-32 pi-pd-tb-4 pi-flex-row-center"><SvgIcon type="xxh-arrow-left" style={{ color: '#9a9a9a', fontSize: 12 }} /></span>
  138. }
  139. {
  140. row.elderBrother ?
  141. <Tooltip title="降级">
  142. <Button type="text" icon={<SvgIcon type="xxh-arrow-right" style={{ color: '#007bff', fontSize: 12 }} />} onClick={() => treeResfulApiHandler('depth', { id: row.id, bidsectionId: row.bidsectionId, operation: 'downDepth' })} />
  143. </Tooltip>
  144. :
  145. <span className="pi-width-32 pi-height-32 pi-pd-tb-4 pi-flex-row-center"><SvgIcon type="xxh-arrow-right" style={{ color: '#9a9a9a', fontSize: 12 }} /></span>
  146. }
  147. {
  148. row.elderBrother ?
  149. <Tooltip title="上移">
  150. <Button type="text" icon={<SvgIcon type="xxh-arrow-up" style={{ color: '#007bff', fontSize: 12 }} />} onClick={() => treeResfulApiHandler('serial', { id: row.id, bidsectionId: row.bidsectionId, operation: 'upSerial' })} disabled={!row.elderBrother} />
  151. </Tooltip>
  152. :
  153. <span className="pi-width-32 pi-height-32 pi-pd-tb-4 pi-flex-row-center"><SvgIcon type="xxh-arrow-up" style={{ color: '#9a9a9a', fontSize: 12 }} /></span>
  154. }
  155. {
  156. !row.isEnd ?
  157. <Tooltip title="下移">
  158. <Button type="text" icon={<SvgIcon type="xxh-arrow-down" style={{ color: '#007bff', fontSize: 12 }} />} onClick={() => treeResfulApiHandler('serial', { id: row.id, bidsectionId: row.bidsectionId, operation: 'downSerial' })} disabled={row.isEnd} />
  159. </Tooltip>
  160. :
  161. <span className="pi-width-32 pi-height-32 pi-pd-tb-4 pi-flex-row-center"><SvgIcon type="xxh-arrow-down" style={{ color: '#9a9a9a', fontSize: 12 }} /></span>
  162. }
  163. </>
  164. : ''
  165. }
  166. </div>
  167. </Slot>
  168. <Slot position="right">
  169. <Button type="ghost" size="small" icon={<SvgIcon type="xxh-cog" />} className="pi-mg-right-3" style={{ color: '#007bff' }} onClick={() => setRuleModal({ ...ruleModal, visible: true })}>设置</Button>
  170. {
  171. showCBtn ?
  172. <Authorization type="contract" auth="add">
  173. <Button type="primary" size="small" onClick={() => setModalObj({ ...modalObj, type: 'create', visible: true })}>新建收入合同</Button>
  174. </Authorization>
  175. : ""
  176. }
  177. </Slot>
  178. </Header>
  179. <TableContent
  180. changeModalType={changeModalType}
  181. row={row}
  182. setRow={(record: ContractTree) => setRow({ ...row, ...record })}
  183. history={history}
  184. type={ContractType.INCOME}
  185. />
  186. <RuleModal
  187. type={consts.RULE.CONTRACT_RETURN}
  188. title="合同管理编号设置"
  189. visible={ruleModal.visible}
  190. onCreate={onRuleCreate}
  191. loading={ruleModal.loading}
  192. onCancel={() => setRuleModal({ ...ruleModal, visible: false })}
  193. />
  194. <ContractModal row={row} modalObj={modalObj} onConfirm={onCreate} onCancel={() => setModalObj({ ...modalObj, visible: false })} reload={(type) => handleReload(type)} />
  195. </div>
  196. )
  197. }
  198. export default Income