govFinancialAssetComp.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import React, { useEffect, useRef, useState } from 'react';
  2. import { Button, Form, FormInstance, Input, Space, Table, Tooltip, Upload } from 'antd';
  3. import { EditType, SDForm, SDFormDict, SDFormText, SDModal, SDModalForm, SDOperate, SDPage, SDSubmitButton, SDTable, baseFun, SDButton, validateFun, SDFormItem } from '@sundata/ui-frame';
  4. import { ActionType, ProColumns } from '@ant-design/pro-table';
  5. import { WomanOutlined } from '@ant-design/icons';
  6. import { result } from 'lodash';
  7. import { deleteGovFinancialAssetComp, exportExcelModel, getGovFinancialAssetComp, GovFinancialAssetCompModel, inserteGovFinancialAssetComp, selectGovFinancialAssetComp, templateUpload, uploadAction } from '@/services/rwa/govFinancialAssetComp';
  8. import { countChineseChars } from '@/services/rwa/product/rwacheckutils';
  9. type bbb ={
  10. }//中央政府投资的金融资产管理公司清单表
  11. const govFinancialAssetCompts: React.FC<bbb>= (prop : bbb) => {
  12. const [editType, setEditType] = useState<EditType>('update');
  13. const formRef = useRef<FormInstance<any>>();
  14. /** 当前行对象,查看详情、修改时,作为详细信息表单的查询条件 */
  15. const [currentRow,setCurrentRow] = useState<GovFinancialAssetCompModel>();
  16. const [dataSource, setDataSource] = useState<any>() ;
  17. const [detailVisible, setDetailVisible] = useState<boolean>(false);
  18. const [visible,setVisible] = useState<boolean>(false);//弹窗是否显示
  19. const [deadline,setdeadline] = useState<boolean>(false);//弹窗是否显示
  20. const [secName,setSecName] = useState<boolean>(false);//弹窗是否显示
  21. const [importVisible, setImportVisible] = useState<boolean>(false);
  22. const tableActionRef = useRef<ActionType>();
  23. const actionRef = useRef<ActionType>();
  24. /**上传文件 */
  25. const [fileData, setFileData] = useState<File>();
  26. const closeAndRefresh = ()=>{
  27. setVisible(false);
  28. actionRef.current?.reloadAndRest?.();
  29. }
  30. var formDataList = new Array<GovFinancialAssetCompModel>;
  31. const selectdata = async (record:any)=>{
  32. const sd =await selectGovFinancialAssetComp(record.name);
  33. // if (sd.deadline ==='' || sd.deadline ===null){
  34. // setSecName(true);
  35. // setdeadline(false);
  36. // console.log('1');
  37. // }else {
  38. // console.log('3');
  39. // setdeadline(true);
  40. // setSecName(false)
  41. // }
  42. console.log(sd);
  43. formRef.current?.setFieldsValue(sd);
  44. }
  45. const inst = async(formData : GovFinancialAssetCompModel) => {
  46. setEditType('create')
  47. console.log(formData);
  48. formRef.current?.getFieldValue(formData);
  49. const insSovere =await inserteGovFinancialAssetComp(formData)
  50. closeAndRefresh();
  51. console.log(insSovere);
  52. if(insSovere){
  53. baseFun.info ("保存成功");
  54. }else{
  55. baseFun.error(insSovere);
  56. }
  57. ;
  58. }
  59. const del = async(record:any)=>{
  60. baseFun.confirm("请确认是否继续操作。",async()=>{
  61. await deleteGovFinancialAssetComp(record.name)
  62. closeAndRefresh();
  63. baseFun.info("删除成功");
  64. })
  65. }
  66. const disdata = async (record:any)=>{
  67. const sd =await selectGovFinancialAssetComp(record.name);
  68. (record.qualfiedCreditToolType,record.secClassificationCd);
  69. formRef.current?.setFieldsValue(sd);
  70. // return {data :sd};
  71. }
  72. const columns: ProColumns<GovFinancialAssetCompModel>[] = [
  73. {
  74. title : '计算实例号',
  75. dataIndex : 'calcindex',
  76. width:150,
  77. search: false,
  78. hideInTable: true,
  79. },
  80. {
  81. title : '缓释分类',
  82. dataIndex : 'crmClass',
  83. search: false,
  84. hideInTable: true,
  85. width:150
  86. },
  87. {
  88. title : '数据日期',
  89. dataIndex : 'dataDate',
  90. width:150,
  91. search: false,
  92. hideInTable: true,
  93. },
  94. {
  95. title : '截止数据日期',
  96. dataIndex : 'edate',
  97. width:150,
  98. search: false,
  99. hideInTable: true,
  100. },
  101. {
  102. title : '交易对手名称',
  103. dataIndex : 'name',
  104. width:150
  105. },
  106. {
  107. title : '缓释工具类型',
  108. dataIndex : 'qualfiedCreditToolTypeName',
  109. search: false,
  110. hideInTable:true,
  111. width:150
  112. },
  113. {
  114. title : '缓释工具类型',
  115. dataIndex : 'qualfiedCreditToolName',
  116. search: false,
  117. width:150
  118. },
  119. {
  120. title : '起始数据日期',
  121. dataIndex : 'sdate',
  122. width:150,
  123. search: false,
  124. hideInTable: true,
  125. },
  126. {
  127. title : '年月',
  128. dataIndex : 'term',
  129. width:150,
  130. search: false,
  131. hideInTable: true,
  132. },
  133. {
  134. title : '缓释权重',
  135. dataIndex : 'weight',
  136. search: false,
  137. hideInTable: true,
  138. width:150
  139. },
  140. {
  141. title : '备注',
  142. dataIndex : 'notes',
  143. search: false,
  144. hideInTable: true,
  145. width:150
  146. },
  147. {
  148. title: '操作',
  149. dataIndex: 'operate',
  150. valueType: 'option',
  151. render: (_, record) => [
  152. <SDOperate
  153. key="roleCfg"
  154. icon={<WomanOutlined />}
  155. successMessage=""
  156. onClick={()=>{
  157. selectdata(record);
  158. setVisible(true);
  159. setEditType('update')
  160. } }
  161. >
  162. 修改
  163. </SDOperate>,
  164. <SDOperate
  165. key="roleCfg"
  166. icon={<WomanOutlined />}
  167. successMessage=""
  168. onClick={()=>{
  169. del(record);
  170. } }
  171. >
  172. 删除
  173. </SDOperate>,
  174. ],
  175. },
  176. ]
  177. /**上传提交 */
  178. const uploadSubmit = async () => {
  179. if (!fileData) {
  180. baseFun.warning('未上传文件');
  181. return;
  182. }
  183. const res = await uploadAction(fileData);
  184. if ('导入成功'===res) {
  185. baseFun.info("处理完成");
  186. } else {
  187. baseFun.error(res);
  188. }
  189. setEditType('update');
  190. setDetailVisible(false);
  191. };
  192. // 模板下载
  193. const templateUploadAction = async() => {
  194. await templateUpload("govFinancialAssetComp");
  195. // baseFun.info("处理完成");
  196. }
  197. /**上传属性 */
  198. const fileProps = {
  199. onRemove: () => {
  200. setFileData(undefined);
  201. },
  202. beforeUpload(info: any) {
  203. setFileData(info);
  204. },
  205. };
  206. return(
  207. <SDPage>
  208. <SDTable
  209. title="查询表格"
  210. rowKey="secClassificationCd"
  211. request={async(formData : GovFinancialAssetCompModel)=>{
  212. const sd = await getGovFinancialAssetComp(formData);
  213. formDataList =[...sd];
  214. return {data :sd };
  215. }}
  216. columns={columns}
  217. actionRef={actionRef}
  218. formRef={formRef}
  219. // operations={["create"]}
  220. //handleRemove={deletedata}
  221. setCurrentRow={setCurrentRow}
  222. setEditType={setEditType}
  223. setDetailVisible={setVisible}
  224. toolBarRender={(_, { selectedRows }) => [
  225. <SDButton
  226. key="export"
  227. successMessage=''
  228. onClick={async () => {
  229. exportExcelModel("govFinancialAssetComp",formDataList);
  230. baseFun.info('处理完成');
  231. }}
  232. >
  233. 全部导出
  234. </SDButton>,
  235. <SDButton
  236. key="import"
  237. successMessage=''
  238. onClick={() => {
  239. baseFun.confirm("请注意本功能意在覆盖本表所有数据,请谨慎使用!",()=>{ setImportVisible(true);})
  240. }}
  241. >
  242. 覆盖导入
  243. </SDButton>,
  244. ]}
  245. ></SDTable>
  246. {importVisible && (
  247. <SDModalForm
  248. title={'上传文件窗口'}
  249. visible={importVisible}
  250. editType={editType}
  251. onVisibleChange={() => {setImportVisible(false)}}
  252. tableRef={actionRef}
  253. footer={[
  254. <SDSubmitButton editType={'update'} formRef={formRef} successMessage=""
  255. doSubmit={async() => {await uploadSubmit()}} >提交</SDSubmitButton>,
  256. <SDButton
  257. key="template"
  258. onClick={() => {
  259. templateUploadAction();
  260. }}
  261. >
  262. 模板下载
  263. </SDButton>
  264. ]
  265. }
  266. >
  267. <SDFormItem nestType="form">
  268. <Upload maxCount={1} {...fileProps} name="rfile">
  269. <div style={{ paddingLeft: '5.5vw' }}>
  270. 选择上传文件: &nbsp;&nbsp;<SDOperate>上传</SDOperate>
  271. </div>
  272. </Upload>
  273. </SDFormItem>
  274. </SDModalForm>
  275. )}
  276. { visible &&(
  277. <SDModalForm
  278. visible={visible}
  279. //rowKey="cust_NAME"
  280. editType={editType}
  281. //request={selectdata}
  282. //params={setDataSource}
  283. onVisibleChange={() => { setVisible(false) }}
  284. initialValues={{crmClass :'保证'}}
  285. footer={[<SDSubmitButton editType={editType} successMessage="" formRef={formRef} doSubmit={inst} >保存</SDSubmitButton>,
  286. <SDButton successMessage="" onClick={()=>closeAndRefresh()}>关闭</SDButton>]}
  287. formRef={formRef}
  288. >
  289. <SDFormText name="crmClass" label="缓释分类" />
  290. <SDFormText name="name" label="交易对手名称" />
  291. <SDFormDict name="qualfiedCreditToolTypeName" label="合格信用风险缓释工具类型" dictKey='qualfiedCreditToolTypeName' />
  292. <SDFormText name="weight" label="缓释权重" rules={ [{validator: validateFun.double,message:"请输入数字类型" }
  293. ,{pattern :RegExp(`^\\d+\\.{${0},${1}}\\d{${0},${4}}$`),message:"小数位超位" }]}
  294. oldValue="%" />
  295. <SDFormText name="notes" label="备注" rules={[{validator:(rules,value,callback)=>{
  296. let chineseCount = countChineseChars(value);
  297. if (chineseCount > 500) {
  298. callback('最多500个汉字');
  299. } else if (chineseCount<=0) {
  300. callback('请输入汉字');
  301. } else{
  302. callback();
  303. }
  304. }}]} />
  305. <div style={{display:"none"}}>
  306. <SDFormText name="calcindex" label="计算实例号" />
  307. <SDFormText name="dataDate" label="数据日期" />
  308. <SDFormText name="edate" label="截止数据日期" />
  309. <SDFormText name="sdate" label="起始数据日期" />
  310. <SDFormText name="term" label="年月" />
  311. </div>
  312. </SDModalForm>
  313. )
  314. }
  315. </SDPage>
  316. )
  317. };export default govFinancialAssetCompts