form.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. import React from "react";
  2. import {promptBox, toast} from 'nc-lightapp-front';
  3. import handlePks from './handleAllpks';
  4. import {saveValidate} from "../../../../hrpub/common/utils/utils";
  5. export default class FormAction {
  6. constructor(comp) {
  7. this.comp = comp;
  8. this.dispatch = this.comp.props.dispatch;
  9. }
  10. tabBtnClick = (btnCode, record) => {
  11. switch (btnCode) {
  12. case 'commit':
  13. this.submit(record);
  14. break;
  15. case 'recover':
  16. this.takeBack(record);
  17. break;
  18. case 'edit':
  19. this.edit(record);
  20. break;
  21. case 'del':
  22. this.delete(record);
  23. break;
  24. case 'check_flow':
  25. this.checkWorkflow(record);
  26. break;
  27. default:
  28. break;
  29. }
  30. };
  31. add = async () => {
  32. const {props, action} = this.comp;
  33. const {dispatch, form, meta} = props;
  34. let res = await dispatch({
  35. type: 'main/addNew',
  36. payload: {}
  37. });
  38. if (res.success) {
  39. const template = meta.getMeta();
  40. let allArea = ['card'];
  41. if (template.formrelation) {
  42. allArea = allArea.concat(template.formrelation['card'] || [])
  43. }
  44. allArea.forEach(area => {
  45. if (res.data[area]) template[area] = res.data[area];
  46. });
  47. meta.setMeta(template);
  48. form.setFormStatus('card', 'add');
  49. await dispatch({
  50. type: 'main/update',
  51. payload: {
  52. page: 'detail',
  53. isEdit: true,
  54. handleData: null
  55. }
  56. });
  57. action.btnAct.updateBtnStatus();
  58. // 是否禁用编码
  59. form.setFormItemsDisabled('card', {bill_code: !res.data.isBillCodeEditable, pk_psnjob: true});
  60. form.openArea('psninfo');
  61. form.openArea('oldinfo');
  62. form.openArea('newinfo');
  63. /*form.openArea('execinfo');
  64. form.openArea('audit_info');
  65. form.openArea('table_end_info');*/
  66. if (res.data.formData) {
  67. form.setAllFormValue({card: res.data.formData.card})
  68. }
  69. if(res.data.formBodyData){
  70. props.editTable.setTableData('card_body', { rows: res.data.formBodyData.card_body.rows });
  71. }else{
  72. props.editTable.setTableData('card_body',{rows:[]})
  73. }
  74. props.editTable.setStatus('card_body', 'edit');
  75. }
  76. };
  77. edit = async (record) => {
  78. const {props, action} = this.comp;
  79. const {dispatch, form, meta} = props;
  80. let res = await dispatch({
  81. type: 'main/editData',
  82. payload: {
  83. "area_code": "card",
  84. "billid": record.pk_hi_regapply.value,
  85. "page_code": "60092040nccloud",
  86. "isapprove": false
  87. }
  88. });
  89. if (res.success) {
  90. const template = meta.getMeta();
  91. let allArea = ['card'];
  92. if (template.formrelation) {
  93. allArea = allArea.concat(template.formrelation['card'] || [])
  94. }
  95. allArea.forEach(area => {
  96. if (res.data[area]) template[area] = res.data[area];
  97. });
  98. meta.setMeta(template);
  99. form.setFormStatus('card', 'edit');
  100. await dispatch({
  101. type: 'main/update',
  102. payload: {
  103. page: 'detail',
  104. isEdit: true
  105. }
  106. });
  107. action.btnAct.updateBtnStatus();
  108. // 是否禁用编码
  109. form.setFormItemsDisabled('card', {bill_code: !res.data.isBillCodeEditable, pk_psnjob: true});
  110. form.openArea('psninfo');
  111. form.openArea('oldinfo');
  112. form.openArea('newinfo');
  113. /*form.openArea('execinfo');
  114. form.openArea('audit_info');
  115. form.openArea('table_end_info');*/
  116. if (res.data.formData) {
  117. form.setAllFormValue({card: res.data.formData.card})
  118. }
  119. if(res.data.formBodyData){
  120. props.editTable.setTableData('card_body', { rows: res.data.formBodyData.card_body.rows });
  121. }else{
  122. props.editTable.setTableData('card_body',{rows:[]})
  123. }
  124. props.editTable.setStatus('card_body', 'edit');
  125. }
  126. };
  127. save = async () => {
  128. const {props, action} = this.comp;
  129. const {dispatch, form, main, cardPagination} = props;
  130. const {language} = main;
  131. if (!form.isCheckNow('card')) return;
  132. await saveValidate(
  133. props,
  134. '60651050p',
  135. 'card',
  136. ['psninfo', 'oldinfo', 'newinfo'],
  137. 'extcard',
  138. null,
  139. null
  140. );
  141. let formData = form.getAllFormValue('card');
  142. let formBodyData = props.editTable.getAllData('card_body');
  143. let status = form.getFormStatus('card');
  144. let postData = {
  145. formData: formData,
  146. formBodyData: formBodyData,
  147. area_code: 'card',
  148. page_code: '60092040nccloud',
  149. probationType: '1',
  150. opera_code: status === 'add' ? '1' : '2'
  151. };
  152. let res = await dispatch({
  153. type: 'main/saveData',
  154. payload: postData
  155. });
  156. if (res.success) {
  157. toast({color: 'success', content: language['hrzzpc-000080']});
  158. await dispatch({
  159. type: 'main/update',
  160. payload: {
  161. isEdit: false,
  162. handleData: res.data.formData.card.rows[0].values
  163. }
  164. });
  165. form.setFormStatus('card', 'browse');
  166. form.setAllFormValue({card: res.data.formData.card});
  167. if(res.data.formBodyData){
  168. props.editTable.setTableData('card_body', { rows: res.data.formBodyData.card_body.rows });
  169. props.editTable.setStatus('card_body', 'browse');
  170. }
  171. const billId = res.data.formData.card.rows[0].values.pk_hi_regapply.value;
  172. handlePks.add(billId);
  173. cardPagination.setCardPaginationId({
  174. id: billId,
  175. status: 2
  176. });
  177. //action.tableAct.getData();
  178. action.btnAct.updateBtnStatus();
  179. }
  180. };
  181. submit = (record) => {
  182. const {props, action} = this.comp;
  183. const {dispatch, main} = props;
  184. const {language, page} = main;
  185. promptBox({
  186. color: "warning",
  187. title: language['hrzzpc-000074'],
  188. content: language['hrzzpc-000097'],
  189. beSureBtnClick: async () => {
  190. let postData = {
  191. billids: [record.pk_hi_regapply.value]
  192. };
  193. let res = await dispatch({
  194. type: 'main/submit',
  195. payload: postData
  196. });
  197. if (res.success) {
  198. if (res.data && res.data.errorMsg) {
  199. toast({color: 'error', content: res.data.errorMsg});
  200. } else {
  201. if (res.data && res.data.content) {
  202. this.dispatch({
  203. type: 'main/update',
  204. payload: {
  205. assignAppVisible: true,
  206. assignContent: res.data.content,
  207. assignRecord: record
  208. }
  209. });
  210. } else {
  211. toast({color: 'success', content: language['hrzzpc-000080']});
  212. if (page === 'main') {
  213. action.tableAct.getData();
  214. } else {
  215. this.checkOneBill(record);
  216. }
  217. }
  218. }
  219. }
  220. }
  221. });
  222. };
  223. assignApp = async (assignInfo, callback) => {
  224. const {props, action} = this.comp;
  225. const {dispatch, main} = props;
  226. const {page, language, assignRecord} = main;
  227. let postData = {
  228. billids: [assignRecord.pk_hi_regapply.value],
  229. content: assignInfo
  230. };
  231. let res = await dispatch({
  232. type: 'main/submit',
  233. payload: postData
  234. });
  235. if (res.success) {
  236. if (res.data && res.data.errorMsg) {
  237. toast({color: 'error', content: res.data.errorMsg});
  238. } else {
  239. toast({color: 'success', content: language['hrzzpc-000080']});
  240. if (page === 'main') {
  241. action.tableAct.getData();
  242. } else {
  243. this.checkOneBill(assignRecord);
  244. }
  245. callback && callback();
  246. }
  247. }
  248. };
  249. takeBack = (record) => {
  250. const {props, action} = this.comp;
  251. const {dispatch, main} = props;
  252. const {language, page} = main;
  253. promptBox({
  254. color: "warning",
  255. title: language['hrzzpc-000074'],
  256. content: language['hrzzpc-000096'],
  257. beSureBtnClick: async () => {
  258. let postData = {
  259. billids: [record.pk_hi_regapply.value]
  260. };
  261. let res = await dispatch({
  262. type: 'main/takeBack',
  263. payload: postData
  264. });
  265. if (res.success) {
  266. if (res.data && res.data.errorMsg) {
  267. toast({color: 'error', content: res.data.errorMsg});
  268. } else {
  269. toast({color: 'success', content: language['hrzzpc-000080']});
  270. if (page === 'main') {
  271. action.tableAct.getData();
  272. } else {
  273. this.checkOneBill(record);
  274. }
  275. }
  276. }
  277. }
  278. });
  279. };
  280. delete = (record) => {
  281. const {props, action} = this.comp;
  282. const {dispatch, main, cardPagination} = props;
  283. const {page, language} = main;
  284. promptBox({
  285. color: "warning",
  286. title: language['hrzzpc-000074'],
  287. content: language['hrzzpc-000095'],
  288. beSureBtnClick: async () => {
  289. let postData = {
  290. billids: [record.pk_hi_regapply.value]
  291. };
  292. let res = await dispatch({
  293. type: 'main/delete',
  294. payload: postData
  295. });
  296. if (res.success) {
  297. toast({color: 'success', content: language['hrzzpc-000080']});
  298. if (page === 'main') {
  299. action.tableAct.getData();
  300. } else {
  301. const nextPk = cardPagination.getNextCardPaginationId({
  302. id: record.pk_hi_regapply.value,
  303. status: 1
  304. });
  305. handlePks.remove(record.pk_hi_regapply.value);
  306. this.pageQueryClick(null, nextPk);
  307. }
  308. }
  309. }
  310. });
  311. };
  312. cancel = () => {
  313. const {props: {main: {language, handleData}, form}} = this.comp;
  314. promptBox({
  315. color: "warning",
  316. title: language['hrzzpc-000074'],
  317. content: language['hrzzpc-000081'],
  318. beSureBtnClick: async () => {
  319. const {action} = this.comp;
  320. let formData = form.getAllFormValue('card');
  321. let res = await this.dispatch({
  322. type: 'main/cancel',
  323. payload: {formData}
  324. });
  325. if (res.success) {
  326. await this.dispatch({
  327. type: 'main/update',
  328. payload: {
  329. isEdit: false
  330. }
  331. });
  332. form.setFormStatus('card', 'browse');
  333. if (handleData) {
  334. this.checkOneBill(handleData);
  335. } else {
  336. await this.dispatch({
  337. type: 'main/update',
  338. payload: {
  339. page: 'main',
  340. handleData: null
  341. }
  342. });
  343. action.btnAct.updateBtnStatus();
  344. }
  345. }
  346. }
  347. });
  348. };
  349. // 表单编辑前
  350. formBeforeEdit = async (platFormProps, formId, key, value, data) => {
  351. const {props} = this.comp;
  352. const {dispatch, form, meta} = props;
  353. const template = meta.getMeta();
  354. let allArea = ['card'], targetItem = null;
  355. if (template.formrelation) {
  356. allArea = allArea.concat(template.formrelation['card'] || [])
  357. }
  358. allArea.some(area => {
  359. targetItem = template[area].items.find(item => item.attrcode === key);
  360. if (targetItem) {
  361. return true;
  362. }
  363. });
  364. if (!targetItem || targetItem.itemtype !== 'refer') return true;
  365. let formData = form.getAllFormValue('card');
  366. let postData = {
  367. key: key,
  368. formData
  369. };
  370. let res = await dispatch({
  371. type: 'main/formBeforeEdit',
  372. payload: postData
  373. });
  374. if (res.success) {
  375. if (res.data && res.data.refParam) {
  376. if (targetItem) {
  377. targetItem.queryCondition = {
  378. ...targetItem.queryCondition,
  379. ...res.data.refParam
  380. };
  381. meta.setMeta(template);
  382. }
  383. }
  384. return true;
  385. }
  386. };
  387. // 表单编辑后
  388. formAfterEdit = async (platFormProps, formId, key, value, preVal) => {
  389. const {props} = this.comp;
  390. const {dispatch, form} = props;
  391. let area_code = 'card';
  392. let formData = form.getAllFormValue('card');
  393. let postData = {
  394. key: key,
  395. formData: formData,
  396. area_code: 'card',
  397. page_code: '60092040nccloud',
  398. probationType: '1'
  399. };
  400. let res = await dispatch({
  401. type: 'main/formAfterEdit',
  402. payload: postData
  403. });
  404. if (res.success) {
  405. if (res.data && res.data.formData) {
  406. res.data.visible && form.setFormItemsVisible(area_code, res.data.visible);
  407. res.data.disable && form.setFormItemsDisabled(area_code, res.data.disable);
  408. res.data.required && form.setFormItemsRequired(area_code, res.data.required);
  409. form.setAllFormValue({card: res.data.formData.card});
  410. }
  411. }
  412. };
  413. fileManage = (record) => {
  414. this.dispatch({
  415. type: 'main/update',
  416. payload: {
  417. showUploader: true,
  418. psndoc: record.pk_hi_regapply.value,
  419. isDisableUpload: !(record.approve_state && record.approve_state.value === '-1')
  420. }
  421. });
  422. };
  423. closeFileManage = () => {
  424. this.dispatch({
  425. type: 'main/update',
  426. payload: {
  427. showUploader: false,
  428. psndoc: ''
  429. }
  430. });
  431. };
  432. checkWorkflow = (record) => {
  433. this.dispatch({
  434. type: 'main/update',
  435. payload: {
  436. showFlow: true,
  437. billid: record.pk_hi_regapply.value,
  438. billtype: record.transtype.value || record.pk_billtype.value
  439. }
  440. });
  441. };
  442. closeFlow = () => {
  443. this.dispatch({
  444. type: 'main/update',
  445. payload: {
  446. showFlow: false
  447. }
  448. });
  449. };
  450. checkOneBill = async (record) => {
  451. const {props, action} = this.comp;
  452. const {dispatch, cardPagination, form} = props;
  453. let res = await dispatch({
  454. type: 'main/checkOneBill',
  455. payload: {
  456. billid: record.pk_hi_regapply.value
  457. }
  458. });
  459. if (res.success) {
  460. await dispatch({
  461. type: 'main/update',
  462. payload: {
  463. page: 'detail',
  464. isEdit: false,
  465. handleData: res.data.formData.card.rows[0].values
  466. }
  467. });
  468. cardPagination.setCardPaginationId({
  469. id: res.data.formData.card.rows[0].values.pk_hi_regapply.value,
  470. status: 1
  471. });
  472. form.setFormStatus('card', 'browse');
  473. form.openArea('psninfo');
  474. form.openArea('oldinfo');
  475. form.openArea('newinfo');
  476. /*form.openArea('execinfo');
  477. form.openArea('audit_info');
  478. form.openArea('table_end_info');*/
  479. form.setAllFormValue({card: res.data.formData.card});
  480. if(res.data.formBodyData){
  481. props.editTable.setTableData('card_body', { rows: res.data.formBodyData.card_body.rows });
  482. props.editTable.setStatus('card_body', 'browse');
  483. }
  484. action.btnAct.updateBtnStatus();
  485. }
  486. };
  487. refresh = async () => {
  488. const {props, action} = this.comp;
  489. const {dispatch, main, form} = props;
  490. const {handleData} = main;
  491. if (handleData && handleData.pk_hi_regapply && handleData.pk_hi_regapply.value) {
  492. let res = await dispatch({
  493. type: 'main/checkOneBill',
  494. payload: {
  495. billid: handleData.pk_hi_regapply.value
  496. }
  497. });
  498. if (res.success) {
  499. await dispatch({
  500. type: 'main/update',
  501. payload: {
  502. handleData: res.data.formData.card.rows[0].values
  503. }
  504. });
  505. form.setAllFormValue({card: res.data.formData.card});
  506. action.btnAct.updateBtnStatus();
  507. }
  508. }
  509. };
  510. pageQueryClick = async (lastProps, billId) => {
  511. const {props, action} = this.comp;
  512. const {dispatch, form} = props;
  513. if (billId) {
  514. let res = await dispatch({
  515. type: 'main/checkOneBill',
  516. payload: {
  517. billid: billId
  518. }
  519. });
  520. if (res.success) {
  521. await dispatch({
  522. type: 'main/update',
  523. payload: {
  524. handleData: res.data.formData.card.rows[0].values
  525. }
  526. });
  527. form.setAllFormValue({card: res.data.formData.card});
  528. action.btnAct.updateBtnStatus();
  529. }
  530. } else {
  531. /*await dispatch({
  532. type: 'main/update',
  533. payload: {
  534. handleData: null
  535. }
  536. });
  537. form.EmptyAllFormValue('card');
  538. action.btnAct.updateBtnStatus();*/
  539. await this.dispatch({
  540. type: 'main/update',
  541. payload: {
  542. page: 'main',
  543. handleData: null
  544. }
  545. });
  546. action.btnAct.updateBtnStatus();
  547. action.tableAct.getData();
  548. }
  549. }
  550. }