project_property_indicativeInfo.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. isFB:function (node) {
  82. return this.isBills(node) && node.data.type === billType.FB;
  83. },
  84. //是大项费用
  85. isDXFY: function (node) {
  86. return this.isBills(node) && node.data.type === billType.DXFY;
  87. },
  88. //是分部分项工程
  89. isFBFX: function (node) {
  90. return this.isDXFY(node) && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === fixedFlag.SUB_ENGINERRING;
  91. },
  92. //是措施项目
  93. isCSXM: function (node) {
  94. return this.isDXFY(node) && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === fixedFlag.MEASURE;
  95. },
  96. //是工程造价
  97. isEngieeringCost: function (node) {
  98. return this.isDXFY(node) && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === fixedFlag.ENGINEERINGCOST;
  99. },
  100. //存在某个费用
  101. fee: function (node, feeType) {
  102. return node && node.data.feesIndex && node.data.feesIndex[feeType] ? node.data.feesIndex[feeType].totalFee : 0;
  103. },
  104. //根据固定行ID获取固定行清单节点
  105. getFixedBill: function (flag) {
  106. for(let node of projectObj.project.mainTree.items){
  107. if(node && node.data.flagsIndex && node.data.flagsIndex.fixed && node.data.flagsIndex.fixed.flag === flag){
  108. return node;
  109. }
  110. }
  111. return null;
  112. },
  113. getDXFY: function (node) {
  114. if(!node) return null;
  115. let dxfy = Object.create(null);
  116. let engCostFee = this.fee(this.getFixedBill(fixedFlag.ENGINEERINGCOST), this.feeType.common);
  117. let commonFee = this.fee(node, this.feeType.common);
  118. let buildingArea = projFeatureView.getFeature('buildingArea');
  119. let areaNum = !buildingArea || buildingArea == '' || isNaN(buildingArea) ? 0 : buildingArea;
  120. dxfy.name = node.data.name;
  121. dxfy.price = commonFee ? parseFloat(commonFee).toDecimal(decimalObj.bills.totalPrice) : 0;
  122. dxfy.rate = engCostFee == 0 || this.isEngieeringCost(node) ? '' : parseFloat(dxfy.price/engCostFee*100).toDecimal(2);
  123. dxfy.perCentiare = areaNum == 0 ? '' : parseFloat(dxfy.price/areaNum).toDecimal(decimalObj.bills.totalPrice);
  124. return dxfy;
  125. },
  126. getIndicativeInfo: function () {
  127. let rst = [];
  128. for(let node of projectObj.project.mainTree.items){
  129. if(this.isDXFY(node)){
  130. let dxfy = this.getDXFY(node);
  131. if(!dxfy) continue;
  132. if(this.isFBFX(node)){
  133. rst.push(dxfy);
  134. rst.push({name: '其中:', price: '', rate: '', perCentiare: ''});
  135. rst.push({name: ' 人工费', price: parseFloat(this.fee(node, this.feeType.labour)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  136. rst.push({name: ' 材料费', price: parseFloat(this.fee(node, this.feeType.material)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  137. rst.push({name: ' 机械费', price: parseFloat(this.fee(node, this.feeType.machine)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  138. rst.push({name: ' 主材费', price: parseFloat(this.fee(node, this.feeType.mainMaterial)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  139. rst.push({name: ' 设备费', price: parseFloat(this.fee(node, this.feeType.equipment)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  140. let labourDiff = this.fee(node, this.feeType.labourDiff),
  141. materialDiff = this.fee(node, this.feeType.materialDiff),
  142. machineDiff = this.fee(node, this.feeType.machineDiff),
  143. rcjDiff = labourDiff + materialDiff + machineDiff;
  144. rst.push({name: ' 人材机价差', price: parseFloat(rcjDiff).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  145. rst.push({name: ' 企业管理费', price: parseFloat(this.fee(node, this.feeType.manage)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  146. rst.push({name: ' 利润', price: parseFloat(this.fee(node, this.feeType.profit)).toDecimal(decimalObj.bills.totalPrice), rate: '', perCentiare: ''});
  147. }
  148. else if(this.isCSXM(node)){
  149. rst.push(dxfy);
  150. rst.push({name: '其中:', price: '', rate: '', perCentiare: ''});
  151. let safeConst = this.getDXFY(this.getFixedBill(fixedFlag.SAFETY_CONSTRUCTION));
  152. if(safeConst){
  153. safeConst.name = ` ${safeConst.name}`;
  154. rst.push(safeConst);
  155. }
  156. }
  157. else{
  158. rst.push(dxfy);
  159. }
  160. }
  161. }
  162. return rst;
  163. }
  164. };
  165. $(document).ready(function () {
  166. $('#tab_poj-settings-indicativeInfo').on('shown.bs.tab', function(){
  167. if(indicativeInfoObj.workBook){
  168. indicativeInfoObj.workBook.destroy();
  169. indicativeInfoObj.workBook = null;
  170. }
  171. indicativeInfoObj.buildSheet();
  172. indicativeInfoObj.showData(indicativeInfoObj.getIndicativeInfo());
  173. });
  174. $('#poj-set').on('shown.bs.modal', function () {
  175. indicativeInfoObj.buildSheet();
  176. indicativeInfoObj.showData(indicativeInfoObj.getIndicativeInfo());
  177. });
  178. $('#poj-set').on('hidden.bs.modal', function () {
  179. if(indicativeInfoObj.workBook){
  180. indicativeInfoObj.workBook.destroy();
  181. indicativeInfoObj.workBook = null;
  182. }
  183. });
  184. $('#tab_poj-settings-indicativeInfo').on('shown.bs.tab', function () {
  185. indicativeInfoObj.workBook.refresh();
  186. });
  187. });