<template>
  <!-- 仓储设备投资建设上报 -->
  <div class="content-main">
    <span class="spanStyle">仓储设施投资建设明细表</span>
    <span class="spanStyleRight">单位：万元、个、把、台</span>
    <el-table :data="tableData" :span-method="objectSpanMethod" stripe border fit highlight-current-row style="width: 100%">
	  <el-table-column v-if="orgCode != 'LS001'" align="center" type="index" label="序号" width="70">
	  </el-table-column>
	  <el-table-column v-else width="260px" align="center" prop="qyjt" label="区域/集团">
	  </el-table-column>
      <el-table-column width="260px" align="center" prop="sskdmc" label="库点名称"></el-table-column>
      <el-table-column align="center" prop="" label="项目状态">
        <el-table-column align="center" prop="xmztBddxkgxm" label="本年度新开工项目"></el-table-column>
        <el-table-column align="center" prop="xmztBndjgxm" label="本年度竣工项目"></el-table-column>
        <el-table-column align="center" prop="xmztNdmzjxm" label="年度末在建项目"></el-table-column>
      </el-table-column>
      <el-table-column align="center" prop="" label="年度完成投资">
        <el-table-column align="center" prop="" label="按项目类型分">
          <el-table-column align="center" prop="ndwctzXjgbzlc" label="新建高标准粮仓"></el-table-column>
          <el-table-column align="center" prop="" label="旧仓升级改造">
            <el-table-column align="center" prop="ndwctzGrxn" label="个人性能"></el-table-column>
            <el-table-column align="center" prop="ndwctzQmxn" label="气密性能"></el-table-column>
            <el-table-column align="center" prop="ndwctzTfjs" label="通风技术"></el-table-column>
            <el-table-column align="center" prop="ndwctzKwjs" label="控温技术"></el-table-column>
            <el-table-column align="center" prop="ndwctzLqck" label="粮情测控"></el-table-column>
            <el-table-column align="center" prop="ndwctzSccs" label="杀虫措施"></el-table-column>
            <el-table-column align="center" prop="ndwctzXswx" label="修缮维护"></el-table-column>
            <el-table-column align="center" prop="ndwctzQt" label="其它"></el-table-column>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center" prop="" label="按投资来源分">
          <el-table-column align="center" prop="ndwctzZycz" label="中央财政投资"></el-table-column>
          <el-table-column align="center" prop="ndwctzSjcz" label="市级财政投资"></el-table-column>
          <el-table-column align="center" prop="ndwctzQjcz" label="区级财政投资"></el-table-column>
          <el-table-column align="center" prop="ndwctzQyzc" label="企业自筹"></el-table-column>
          <el-table-column align="center" prop="ndwctzQt2" label="其它"></el-table-column>
        </el-table-column>
     </el-table-column>
      <el-table-column align="center" prop="bz" label="备注"></el-table-column>
      <el-table-column align="center" prop="sbzt" label="状态"></el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { queryMxForQlbOrGxgs,exportMxForQlbOrGxgs,queryMxForSj,exportMxForSj } from '@/api/zgsq/ccsstzjs'
  export default {
    data() {
      return {
        nf: '',
        tableData: [],
		orgCode:sessionStorage.getItem('orgCode'),
      }
    },
    created() {
      // this.getTableData();
    },
    methods: {
		getSpanArr(data){
			for (var i = 0; i < data.length; i++) {
				if(i == 0){
					this.spanArr.push(1)
					this.spanArrOne.push(1)
					this.pos = 0
					this.pos1=0
				}else{
					console.log(data[i-1].qyjt)
					if(data[i].qyjt == data[i-1].qyjt){
						 this.spanArr[this.pos] += 1;
						 this.spanArr.push(0); 
					}else{
						 this.spanArr.push(1);
						 this.pos = i;
					}
					if(data[i].sskdmc == data[i-1].sskdmc){
						 this.spanArrOne[this.pos1] += 1;
						 this.spanArrOne.push(0); 
					}else{
						 this.spanArrOne.push(1);
						 this.pos1 = i;
					}
				}
				
			}
		},
		//合并单元格
		objectSpanMethod({ row, column, rowIndex, columnIndex }){
			if(this.orgCode== 'LS001'){
				if (columnIndex === 0) {
					const _row = this.spanArr[rowIndex];
					const _col = _row > 0 ? 1 : 0; 
					return {
					  rowspan: _row, 
					  colspan: _col, 
					};
				}else if(columnIndex === 1){
					const _row = this.spanArrOne[rowIndex];
					const _col = _row > 0 ? 1 : 0; 
					return {
					  rowspan: _row, 
					  colspan: _col, 
					};
				}
			}
			
		},
      exportExcel(data){
		  if(this.orgCode == 'LS001'){
		  	exportMxForSj(data).then(res => {
		  		let blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
		  		const link = document.createElement('a');
		  		link.style.display = 'none';
		  		link.href = URL.createObjectURL(blob);
		  		link.setAttribute('download', '仓储设施投资建设明细表');
		  		document.body.appendChild(link);
		  		link.click();
		  		document.body.removeChild(link);
		  	}).catch((err) => {
		  	    this.$message.error(err);
		  	});
		  }else{
			exportMxForQlbOrGxgs(data).then(res => {
			  let blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
			  const link = document.createElement('a');
			  link.style.display = 'none';
			  link.href = URL.createObjectURL(blob);
			  link.setAttribute('download', '仓储设施投资建设明细表');
			  document.body.appendChild(link);
			  link.click();
			  document.body.removeChild(link);
			}).catch((err) => {
				this.$message.error(err);
			});
		}
      },
      // 报表数据
      init(data,type) {
		if(this.orgCode== 'LS001'){
			queryMxForSj(data).then(res =>{
			    if(res.infoCode == 200){
				 let arr=[]
				 Object.keys(res.data).forEach((item) =>{
					 console.log(res.data[item],'88343========')
					 res.data[item].forEach((val) =>{
						 val.qyjt=item
						 arr.push(val)
					 })
				 })
				 this.tableData=arr
				 console.log(this.tableData)
				 //清空合并坐标
				 this.spanArr = []; //每行合并数
				 this.pos = 0; //角标索引
				 this.spanArrOne=[];
				 this.pos1 =0
				 this.getSpanArr(this.tableData)
			    }
			}) 
		}else{
			queryMxForQlbOrGxgs(data).then(res =>{
			  if(res.infoCode == 200){
			    this.tableData=res.data
			    // this.ccsjList=res.data[3].ccsjList
			  }
			})  
		}
        
        // 模拟数据
        // this.tableData = [{"id":"1","lx":"按设备类型分","grsl":7,"hj":2.4,"children":[{"id":"11","lx":"粮食设备","grsl":3,"hj":1.4},{"id":"12","lx":"仓储器材","grsl":3,"hj":1}]},{"id":"2","lx":"按设备器材类别分","grsl":7,"hj":2.4,"children":[{"id":"22","lx":" 按粮食设备类别分","grsl":3,"hj":2.4,"children":[{"id":"222","lx":" 粮油通用机械设备","grsl":3,"hj":1.4,"children":[{"id":"2222","lx":" 网带出清筛","grsl":2,"hj":1},{"id":"2223","lx":" 圆筒出清筛","grsl":1,"hj":0.4}]}]}]},{"id":"3","lx":"合计","grsl":7,"hj":2.4}];
      },
    }
  }
</script>

<style scoped>
  .spanStyle {
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .spanStyleRight {
    display: flex;
    justify-content: right;
    align-items: right;
  }
</style>
