sjs_setting.js 6.7 KB

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