sjs_setting.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. const sjsSettingObj = (function () {
  2. const FxTreeStyle = {
  3. jz: 'jianzhu',
  4. };
  5. const setJzFxTreeStyle = function (setting) {
  6. setting.selectedBackColor = '#fffacd';
  7. setting.tree = {
  8. getFont: function (sheet, data, row, col, defaultFont) {
  9. if (sheet.zh_tree) {
  10. const levelField = sheet.zh_tree.setting.level;
  11. return data[levelField] === 1 ? 'bold ' + defaultFont : defaultFont;
  12. } else {
  13. return defaultFont;
  14. }
  15. },
  16. getColor: function (sheet, data, row, col, defaultColor) {
  17. if (sheet.zh_tree) {
  18. const levelField = sheet.zh_tree.setting.level;
  19. if (data[levelField] === 2) {
  20. return '#C4CAFB';
  21. } else if ((!data.b_code || data.b_code === '') && data[levelField] > 2) {
  22. return '#DFE8F9';
  23. } else {
  24. return defaultColor;
  25. }
  26. } else {
  27. return defaultColor;
  28. }
  29. }
  30. }
  31. };
  32. const setFxTreeStyle = function (setting, tag) {
  33. switch (tag) {
  34. case FxTreeStyle.jz:
  35. setJzFxTreeStyle(setting);
  36. break;
  37. }
  38. };
  39. const setGridSelectStyle = function (setting) {
  40. setting.selectedBackColor = '#fffacd';
  41. };
  42. const setTpThousandthFormat = function (setting, fields = []) {
  43. for (const col of setting.cols) {
  44. if (col.field === 'total_price' || col.field.indexOf('tp') >= 0 || fields.indexOf(col.field) >= 0)
  45. col.formatter = '#,##0.######';
  46. }
  47. };
  48. const setThousandthFormat = function (setting, fields) {
  49. for (const f of fields) {
  50. const col = setting.cols.find(function (x) {
  51. return x.field === f
  52. });
  53. if (col) col.formatter = '#,##0.######';
  54. }
  55. };
  56. const setTpColsThousandthFormat = function (cols, fields = []) {
  57. for (const col of cols) {
  58. if (col.field === 'total_price' || col.field.indexOf('tp') >= 0 || fields.indexOf(col.field) >= 0)
  59. col.formatter = '#,##0.######';
  60. }
  61. };
  62. const setPropValue = function (setting, fields, prop, value) {
  63. for (const f of fields) {
  64. const col = setting.cols.find(function (x) {
  65. return x.field === f
  66. });
  67. if (col) col[prop] = value;
  68. }
  69. };
  70. const setRelaCols = function(cols, rela, fun) {
  71. for (const r of rela) {
  72. const col = _.find(cols, {field: r.field});
  73. if (!col) continue;
  74. fun(col, r);
  75. }
  76. };
  77. const set3FCols = function (cols, rela) {
  78. setRelaCols(cols, rela, function(col, r) {
  79. col.getValue = r.getValue;
  80. col.cellType = 'imageBtn';
  81. col.normalImg = '#rela-file-icon';
  82. col.indent = 12;
  83. col.imgAlign = 2;
  84. col.showImage = function (data) { return data && data[r.url_field]; }
  85. });
  86. };
  87. const setQcCols = function (cols, rela){
  88. setRelaCols(cols, rela, function(col, r) {
  89. col.readOnly = true;
  90. col.cellType = 'activeImageBtn';
  91. col.normalImg = '#ellipsis-icon';
  92. col.indent = 5;
  93. col.showImage = r.showImage;
  94. });
  95. };
  96. const setOrgPriceCol = function (cols, rela) {
  97. setRelaCols(cols, rela, function(col, r) {
  98. col.getValue = function (data) { return data.contract_pc_tp || data.qc_pc_tp || data.pc_tp ? data.org_price : null; };
  99. });
  100. };
  101. const setNodeTypeCol = function (cols, rela) {
  102. setRelaCols(cols, rela, function(col, r) {
  103. col.comboItems = nodeType;
  104. col.cellType = 'specCombo';
  105. col.comboEdit = function (sheet, data) {
  106. if (!data) return false;
  107. const tree = sheet.zh_tree;
  108. if (!tree) return false;
  109. const parent = tree.getParent(data);
  110. if (!parent) return false;
  111. return true;
  112. // const topParent = tree.getTopParent(data);
  113. // return [1, 5].indexOf(topParent.node_type) >= 0;
  114. };
  115. });
  116. };
  117. const setIsTpCol = function(cols, rela) {
  118. setRelaCols(cols, rela, function(col, r) {
  119. col.headerCellType = 'tip';
  120. col.getHeaderTip = function() { return '可用单位:总额、元、台、个、处、月 、棵、套、组、辆、项、座、根、块、系统'; };
  121. });
  122. };
  123. return {
  124. setFxTreeStyle, FxTreeStyle, setGridSelectStyle,
  125. setTpThousandthFormat, setThousandthFormat, setTpColsThousandthFormat,
  126. setPropValue, set3FCols, setQcCols, setOrgPriceCol, setNodeTypeCol, setIsTpCol,
  127. };
  128. })();