index.tsx 8.1 KB

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