initTemplate.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { cardCache } from 'nc-lightapp-front';
  2. import { CARD, CARD_BUTTON, STATUS, FIELD, CARD_CACHE, PRIMARY_KEY } from '../../constant';
  3. import { cardCreate, getCardData, copyClear } from './cardOperator';
  4. import { bodyButtonClick } from './bodyButtonClick';
  5. import { buttonVisibilityControl } from './buttonVisibilityControl';
  6. import { afterHeadEvent } from './afterHeadEvent';
  7. import { getBusinessInfo } from 'nc-lightapp-front';
  8. /**
  9. * @description: 卡片模板渲染
  10. */
  11. export function initTemplate(props) {
  12. props.createUIDom({},
  13. (data) => {
  14. if (data) {
  15. if (data.button) {
  16. let button = data.button;
  17. props.button.setButtons(button);
  18. buttonVisibilityControl(props);
  19. }
  20. if (data.template) {
  21. let meta = data.template;
  22. meta = modifierMeta.call(this, props, meta);
  23. props.meta.setMeta(meta, () => {
  24. let status = this.props.getUrlParam(STATUS.status);
  25. let id = this.props.getUrlParam(PRIMARY_KEY.id);
  26. if (status === STATUS.add) { //新增
  27. cardCreate(this.props);
  28. } else if (id) {
  29. getCardData(this.props, id, false, copyClear);
  30. }
  31. });
  32. }
  33. if (data.context && data.context.pk_org) {
  34. if (props.getUrlParam(STATUS.status) === STATUS.add) {
  35. //设置默认组织
  36. // let { pk_org, org_Name } = data.context;
  37. // props.form.setFormItemsValue(CARD.form_id, {
  38. // [FIELD.org]: { value: pk_org, display: org_Name }
  39. // });
  40. // afterHeadEvent(props, CARD.form_id, FIELD.org, { display: org_Name, value: pk_org }, { display: null, value: null });
  41. props.form.setFormItemsValue(CARD.form_id, {
  42. 'billdate':{value: getBusinessInfo().businessDate,display: getBusinessInfo().businessDate},
  43. 'maketime':{value: getBusinessInfo().businessDate,display: getBusinessInfo().businessDate},
  44. 'creationtime':{value: getBusinessInfo().businessDate,display:
  45. getBusinessInfo().businessDate},
  46. 'pk_group':{display:getBusinessInfo().groupName,value:getBusinessInfo().groupId},
  47. 'approvestatus':{value: STATUS.NOSTATE, display: '自由'},
  48. 'billmaker':{display:getBusinessInfo().userName,value:getBusinessInfo().userId},
  49. 'creator':{display:getBusinessInfo().userName,value:getBusinessInfo().userId}
  50. });
  51. }
  52. // 将组织信息缓存
  53. let { setDefData } = cardCache;
  54. setDefData(CARD_CACHE.key, CARD_CACHE.dataSource, data.context);
  55. }
  56. //表体统一参照过滤
  57. /*
  58. props.cardTable.setQueryCondition(CARD.table_code, {
  59. department: () => {
  60. return {
  61. pk_org: props.form.getFormItemsValue(CARD.form_id, FIELD.org).value
  62. };
  63. }
  64. });
  65. */
  66. }
  67. }
  68. )
  69. }
  70. function modifierMeta(props, meta) {
  71. //表头参照过滤
  72. meta[CARD.form_id].items.map(item => {
  73. if (item.attrcode === FIELD.org) { //财务组织
  74. item.queryCondition = () => {
  75. return {
  76. funcode: props.getSearchParam('c')//appcode获取
  77. };
  78. };
  79. }
  80. });
  81. for (let item of Object.keys(meta.gridrelation)) {
  82. meta[item].items.push({
  83. attrcode: 'opr',
  84. label: this.state.json['96H10119-000006'],/* 国际化处理: 操作*/
  85. itemtype: 'customer',
  86. fixed: 'right',
  87. className: 'table-opr',
  88. visible: true,
  89. width: 200,
  90. render: (text, record, index) => {
  91. let status = props.getUrlParam(STATUS.status);
  92. let buttonAry = [];
  93. if (status === STATUS.browse) { //浏览态
  94. buttonAry = [record.expandRowStatus ? CARD_BUTTON.fold : CARD_BUTTON.unfold];
  95. } else { //编辑态
  96. buttonAry = this.state.isPaste ? [CARD_BUTTON.pasteHere] : [CARD_BUTTON.expand, CARD_BUTTON.insertRow, CARD_BUTTON.delRow, CARD_BUTTON.copyRow];
  97. }
  98. return props.button.createOprationButton(buttonAry, {
  99. area: CARD.body_btn_code,
  100. buttonLimit: 4,
  101. onButtonClick: (props, key) => bodyButtonClick.call(this, props, key, text, record, index)
  102. });
  103. }
  104. })
  105. }
  106. return meta;
  107. }