project_property_indicativeInfo.js 9.1 KB

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