project_property_indicativeInfo.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * Created by Zhong on 2018/3/7.
  3. */
  4. let indicativeInfoObj = {
  5. feeType: {common: 'common', labour: 'labour', material: 'material', machine: 'machine', mainMaterial: 'mainMaterial', equipment: 'equipment',
  6. labourDiff: 'labourDiff', materialDiff: 'materialDiff', machineDiff: 'machineDiff', manage: 'manage', profit: 'profit'},
  7. workBook: null,
  8. setting:{
  9. header: [
  10. {name: '名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left'},
  11. {name: '金额', dataCode: 'price', width: 120, vAlign: 'center', hAlign: 'right'},
  12. {name: '占造价比例(%)', dataCode: 'rate', width: 100, vAlign: 'center', hAlign: 'right'},
  13. {name: '单方造价', dataCode: 'perCentiare', width: 80, vAlign: 'center', hAlign: 'right'}
  14. ],
  15. options: {
  16. allowContextMenu: false,
  17. tabStripVisible: false,
  18. allowCopyPasteExcelStyle : false,
  19. allowExtendPasteRange: false,
  20. allowUserDragDrop : false,
  21. allowUserDragFill: false,
  22. scrollbarMaxAlign : true
  23. }
  24. },
  25. renderSheetFuc: function (sheet, fuc) {
  26. sheet.suspendPaint();
  27. sheet.suspendEvent();
  28. fuc();
  29. sheet.resumePaint();
  30. sheet.resumeEvent();
  31. },
  32. setOptions: function (workbook, opts) {
  33. for(let opt in opts){
  34. workbook.options[opt] = opts[opt];
  35. }
  36. },
  37. buildHeader: function (sheet, headers) {
  38. let me = projFeatureView;
  39. let fuc = function () {
  40. sheet.setColumnCount(headers.length);
  41. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  42. for(let i = 0, len = headers.length; i < len; i++){
  43. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  44. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  45. }
  46. };
  47. me.renderSheetFuc(sheet, fuc);
  48. },
  49. buildSheet: function () {
  50. if(!this.workBook){
  51. this.workBook = new GC.Spread.Sheets.Workbook($('#indicativeInfoSpread')[0], {sheetCount: 1});
  52. sheetCommonObj.spreadDefaultStyle(this.workBook);
  53. this.setOptions(this.workBook, this.setting.options);
  54. this.workBook.getSheet(0).options.isProtected = true;
  55. this.buildHeader(this.workBook.getActiveSheet(), this.setting.header);
  56. }
  57. },
  58. showData(datas){
  59. let sheet = this.workBook.getActiveSheet();
  60. let cols = this.setting.header;
  61. let fuc = function () {
  62. sheet.setRowCount(datas.length);
  63. for(let col = 0, cLen = cols.length; col < cLen; col++){
  64. //设置小数位数
  65. if(cols[col]['dataCode'] !== 'name'){
  66. sheet.setFormatter(-1, col, MainTreeCol.getNumberFormatter(decimalObj.bills.totalPrice, true));
  67. }
  68. sheet.getRange(-1, col, -1, 1, GC.Spread.Sheets.SheetArea.viewport).hAlign(GC.Spread.Sheets.HorizontalAlign[cols[col]['hAlign']]);
  69. sheet.getRange(-1, col, -1, 1, GC.Spread.Sheets.SheetArea.viewport).vAlign(GC.Spread.Sheets.VerticalAlign[cols[col]['vAlign']]);
  70. for(let row = 0, rLen = datas.length; row < rLen; row++){
  71. sheet.setValue(row, col, datas[row][cols[col]['dataCode']]);
  72. }
  73. }
  74. };
  75. this.renderSheetFuc(sheet, fuc);
  76. },
  77. //是清单
  78. isBills: function (node) {
  79. return node && node.sourceType === projectObj.project.Bills.getSourceType();
  80. },
  81. //是分部节点
  82. isFB:function (node) {
  83. return this.isBills(node) && node.data.type === billType.FB;
  84. },
  85. //是大项费用
  86. isDXFY: function (node) {
  87. return this.isBills(node) && node.data.type === billType.DXFY;
  88. },
  89. //是分部分项工程
  90. isFBFX: function (node) {
  91. return this.isDXFY(node) && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === fixedFlag.SUB_ENGINERRING;
  92. },
  93. //是措施项目
  94. isCSXM: function (node) {
  95. return this.isDXFY(node) && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === fixedFlag.MEASURE;
  96. },
  97. //是工程造价
  98. isEngieeringCost: function (node) {
  99. return this.isDXFY(node) && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === fixedFlag.ENGINEERINGCOST;
  100. },
  101. //存在某个费用
  102. fee: function (node, feeType) {
  103. return node && node.data.feesIndex && node.data.feesIndex[feeType] ? node.data.feesIndex[feeType].totalFee : 0;
  104. },
  105. //根据固定行ID获取固定行清单节点
  106. getFixedBill: function (flag) {
  107. for(let node of projectObj.project.mainTree.items){
  108. if(node && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === flag){
  109. return node;
  110. }
  111. }
  112. return null;
  113. },
  114. getDXFY: function (node) {
  115. if(!node) return null;
  116. let dxfy = Object.create(null);
  117. let engCostFee = this.fee(this.getFixedBill(fixedFlag.ENGINEERINGCOST), this.feeType.common);
  118. let commonFee = this.fee(node, this.feeType.common);
  119. let buildingArea = projFeatureView.getFeature('buildingArea');
  120. let areaNum = !buildingArea || buildingArea == '' || isNaN(buildingArea) ? 0 : buildingArea;
  121. dxfy.name = node.data.name;
  122. dxfy.price = commonFee ? parseFloat(commonFee).toDecimal(decimalObj.bills.totalPrice) : 0;
  123. dxfy.rate = engCostFee == 0 || this.isEngieeringCost(node) ? '' : parseFloat(dxfy.price/engCostFee*100).toDecimal(2);
  124. dxfy.perCentiare = areaNum == 0 ? '' : parseFloat(dxfy.price/areaNum).toDecimal(decimalObj.bills.totalPrice);
  125. return dxfy;
  126. },
  127. getIndicativeInfo: function () {
  128. let rst = [];
  129. for(let node of projectObj.project.mainTree.items){
  130. if(this.isDXFY(node)){
  131. let dxfy = this.getDXFY(node);
  132. if(!dxfy) continue;
  133. if(this.isFBFX(node)){
  134. rst.push(dxfy);
  135. rst.push({name: '其中:', price: '', rate: '', perCentiare: ''});
  136. rst.push({name: ' 人工费', price: parseFloat(this.fee(node, this.feeType.labour)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  137. rst.push({name: ' 材料费', price: parseFloat(this.fee(node, this.feeType.material)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  138. rst.push({name: ' 机械费', price: parseFloat(this.fee(node, this.feeType.machine)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  139. rst.push({name: ' 主材费', price: parseFloat(this.fee(node, this.feeType.mainMaterial)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  140. rst.push({name: ' 设备费', price: parseFloat(this.fee(node, this.feeType.equipment)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  141. let labourDiff = this.fee(node, this.feeType.labourDiff),
  142. materialDiff = this.fee(node, this.feeType.materialDiff),
  143. machineDiff = this.fee(node, this.feeType.machineDiff),
  144. rcjDiff = labourDiff + materialDiff + machineDiff;
  145. rst.push({name: ' 人材机价差', price: parseFloat(rcjDiff).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  146. rst.push({name: ' 企业管理费', price: parseFloat(this.fee(node, this.feeType.manage)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  147. rst.push({name: ' 利润', price: parseFloat(this.fee(node, this.feeType.profit)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  148. }
  149. else if(this.isCSXM(node)){
  150. rst.push(dxfy);
  151. rst.push({name: '其中:', price: '', rate: '', perCentiare: ''});
  152. let safeConst = this.getDXFY(this.getFixedBill(fixedFlag.SAFETY_CONSTRUCTION));
  153. if(safeConst){
  154. safeConst.name = ` ${safeConst.name}`;
  155. rst.push(safeConst);
  156. }
  157. }
  158. else{
  159. rst.push(dxfy);
  160. }
  161. }
  162. }
  163. return rst;
  164. }
  165. };
  166. $(document).ready(function () {
  167. $('#tab_poj-settings-indicativeInfo').on('shown.bs.tab', function(){
  168. if(indicativeInfoObj.workBook){
  169. indicativeInfoObj.workBook.destroy();
  170. indicativeInfoObj.workBook = null;
  171. }
  172. indicativeInfoObj.buildSheet();
  173. indicativeInfoObj.showData(indicativeInfoObj.getIndicativeInfo());
  174. });
  175. $('#poj-set').on('shown.bs.modal', function () {
  176. indicativeInfoObj.buildSheet();
  177. indicativeInfoObj.showData(indicativeInfoObj.getIndicativeInfo());
  178. });
  179. $('#poj-set').on('hidden.bs.modal', function () {
  180. if(indicativeInfoObj.workBook){
  181. indicativeInfoObj.workBook.destroy();
  182. indicativeInfoObj.workBook = null;
  183. }
  184. });
  185. $('#tab_poj-settings-indicativeInfo').on('shown.bs.tab', function () {
  186. indicativeInfoObj.workBook.refresh();
  187. });
  188. });