project_property_indicativeInfo.js 9.1 KB

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