index.tsx 8.7 KB

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