sjs_setting.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 setContractFxTreeStyle = function (setting) {
  33. setting.selectedBackColor = '#fffacd';
  34. setting.tree = {
  35. getFont: function (sheet, data, row, col, defaultFont) {
  36. if (sheet.zh_tree) {
  37. const levelField = sheet.zh_tree.setting.level;
  38. return data[levelField] === 1 ? 'bold ' + defaultFont : defaultFont;
  39. } else {
  40. return defaultFont;
  41. }
  42. },
  43. getColor: function (sheet, data, row, col, defaultColor) {
  44. if (sheet.zh_tree) {
  45. const levelField = sheet.zh_tree.setting.level;
  46. if (data[levelField] === 2) {
  47. return '#C4CAFB';
  48. } else if (!data.c_code && data[levelField] > 2) {
  49. return '#DFE8F9';
  50. } else {
  51. return defaultColor;
  52. }
  53. } else {
  54. return defaultColor;
  55. }
  56. }
  57. }
  58. };
  59. const setFxTreeStyle = function (setting, tag) {
  60. switch (tag) {
  61. case FxTreeStyle.jz:
  62. setJzFxTreeStyle(setting);
  63. break;
  64. case FxTreeStyle.contract:
  65. setContractFxTreeStyle(setting);
  66. break;
  67. }
  68. };
  69. const setGridSelectStyle = function (setting) {
  70. setting.selectedBackColor = '#fffacd';
  71. };
  72. const setTpThousandthFormat = function (setting, fields = []) {
  73. for (const col of setting.cols) {
  74. if (col.field === 'total_price' || col.field.indexOf('tp') >= 0 || fields.indexOf(col.field) >= 0)
  75. col.formatter = '#,##0.######';
  76. }
  77. };
  78. const setThousandthFormat = function (setting, fields) {
  79. for (const f of fields) {
  80. const col = setting.cols.find(function (x) {
  81. return x.field === f
  82. });
  83. if (col) col.formatter = '#,##0.######';
  84. }
  85. };
  86. const setTpColsThousandthFormat = function (cols, fields = []) {
  87. for (const col of cols) {
  88. if (col.field === 'total_price' || col.field.indexOf('tp') >= 0 || fields.indexOf(col.field) >= 0)
  89. col.formatter = '#,##0.######';
  90. }
  91. };
  92. const setPropValue = function (setting, fields, prop, value) {
  93. for (const f of fields) {
  94. const col = setting.cols.find(function (x) {
  95. return x.field === f
  96. });
  97. if (col) col[prop] = value;
  98. }
  99. };
  100. const setRelaCols = function(cols, rela, fun) {
  101. for (const r of rela) {
  102. const col = _.find(cols, {field: r.field});
  103. if (!col) continue;
  104. fun(col, r);
  105. }
  106. };
  107. const set3FCols = function (cols, rela) {
  108. setRelaCols(cols, rela, function(col, r) {
  109. col.getValue = r.getValue;
  110. col.cellType = 'imageBtn';
  111. col.normalImg = '#rela-file-icon';
  112. col.indent = 12;
  113. col.imgAlign = 2;
  114. col.showImage = function (data) { return data && data[r.url_field]; }
  115. });
  116. };
  117. const setQcCols = function (cols, rela){
  118. setRelaCols(cols, rela, function(col, r) {
  119. col.readOnly = true;
  120. col.cellType = 'activeImageBtn';
  121. col.normalImg = '#ellipsis-icon';
  122. col.indent = 5;
  123. col.showImage = r.showImage;
  124. });
  125. };
  126. const setOrgPriceCol = function (cols, rela) {
  127. setRelaCols(cols, rela, function(col, r) {
  128. col.getValue = function (data) { return data.contract_pc_tp || data.qc_pc_tp || data.pc_tp ? data.org_price : null; };
  129. });
  130. };
  131. const setNodeTypeCol = function (cols, rela) {
  132. setRelaCols(cols, rela, function(col, r) {
  133. col.comboItems = nodeType;
  134. col.cellType = 'specCombo';
  135. col.comboEdit = function (sheet, data) {
  136. if (!data) return false;
  137. const tree = sheet.zh_tree;
  138. if (!tree) return false;
  139. const parent = tree.getParent(data);
  140. if (!parent) return false;
  141. return true;
  142. // const topParent = tree.getTopParent(data);
  143. // return [1, 5].indexOf(topParent.node_type) >= 0;
  144. };
  145. });
  146. };
  147. const setIsTpCol = function(cols, rela) {
  148. setRelaCols(cols, rela, function(col, r) {
  149. col.headerCellType = 'tip';
  150. col.getHeaderTip = function() { return '可用单位:总额、元、台、个、处、月 、棵、套、组、辆、项、座、根、块、系统'; };
  151. });
  152. };
  153. return {
  154. setFxTreeStyle, FxTreeStyle, setGridSelectStyle,
  155. setTpThousandthFormat, setThousandthFormat, setTpColsThousandthFormat,
  156. setPropValue, set3FCols, setQcCols, setOrgPriceCol, setNodeTypeCol, setIsTpCol,
  157. };
  158. })();