<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="searchDate"
        :picker-options="pickerOptions"
        class="filter-item"
        type="daterange"
        format="yyyy年MM月dd日"
        value-format="yyyy-MM-dd"
        align="left"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
      <span>投放媒体:</span>
       <el-select v-model="mediaSourcesId" placeholder="请选择投放媒体">
          <el-option
          v-for="item in mediaSources"
          :key="item.id"
          :label="item.name"
          :value="item.id">
          </el-option>
      </el-select>
      <span>投放产品:</span>
       <el-select v-model="launchProductsId" placeholder="请选择投放产品">
          <el-option
          v-for="item in launchProducts"
          :key="item.id"
          :label="item.name"
          :value="item.id">
          </el-option>
      </el-select>
      <span>组别：</span>
      <el-cascader
      v-model="group"
      :options="groupItem"
      @change="handleChange"></el-cascader>
    </div>
    <el-table v-loading="loading" :data="listData" 
        :span-method="objectSpanMethod" border stripe  style="width: 100%" >
      <el-table-column label="鞋品"  prop="sheetType" align="center"  width="80" />
      <el-table-column type="index" label="各媒体成交" align="center" width='100%'>
        <el-table-column  align="center" prop="taskKey" label="媒体" width="120"> </el-table-column>
        <el-table-column  align="center" prop="templateUrl" label="广告费" width="120"> </el-table-column>
        <el-table-column  align="center" prop="name" label="进线/回访数量" width="120"> </el-table-column>
        <el-table-column  align="center" prop="name" label="鞋" width="120">
            <el-table-column align="center" prop="name" label="单数" width="120"> </el-table-column>
            <el-table-column align="center" prop="name" label="双数" width="120"> </el-table-column>
            <el-table-column align="center" prop="name" label="销售金额" width="120"> </el-table-column>
        </el-table-column>
        <el-table-column align="center" prop="name" label="足部按摩器" width="120"> 
          <el-table-column align="center" prop="name" label="单数" width="120"> </el-table-column>
          <el-table-column align="center" prop="name" label="台数" width="120"> </el-table-column>
          <el-table-column align="center" prop="name" label="销售金额" width="120"> </el-table-column>
        </el-table-column>
        <el-table-column align="center" prop="name" label="成交率" width="120"> </el-table-column>
        <el-table-column align="center" prop="name" label="单线成本" width="120"> </el-table-column>
        <el-table-column align="center" prop="name" label="单线产出" width="120"> </el-table-column>
        <el-table-column align="center" prop="name" label="投产比" width="120"> </el-table-column>
      </el-table-column>
    </el-table>
    <!-- <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList"
    /> -->
  </div>
</template>

<script>
import { getOrderLists } from "@/api/mediaCenter/mediaInformation";
import { pickerOptions, formatterContent } from "@/utils";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装

export default {
  components: {
    Pagination
  },
  data() {
    return {
      loading: false,
      searchDate: "", // 日期
      pickerOptions, // 日期数据
      mediaSourcesId:'',// 投放媒体id
      mediaSources:[
        {
          name:'腾讯',
          id:0
        },
        {
          name:'百度',
          id:1
        }
      ],//投放媒体
      launchProductsId:'',//投放产品id
      launchProducts:[
        {
          name:'秦时',
          id:0
        },
        {
          name:'天九',
          id:1
        },
        {
          name:'玄机',
          id:2
        }
      ],//投放产品
      group:[],//组别
       groupItem: [{
          value: 'zhinan',
          label: '指南',
          children: [{
            value: 'shejiyuanze',
            label: '设计原则',
            children: [{
              value: 'yizhi',
              label: '一致'
            }, {
              value: 'fankui',
              label: '反馈'
            }, {
              value: 'xiaolv',
              label: '效率'
            }, {
              value: 'kekong',
              label: '可控'
            }]
          }]
       }],
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      //列数据处理
      rowList: [],
      spanArr: [],
      position: 0,
      listData: [],
      //行数据处理
      colArr:[],
      colArrPosition:0,
    };
  },
  created() {
    this.getList();
    document.onkeyup = e => {
      if (e.keyCode === 13) {
        this.getList();
      }
    };
  },
  methods: {
    getList() {
      this.loading = true;
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize, // int 每页几条信息
          stime: this.searchDate && this.searchDate[0], // 开始时间
          etime: this.searchDate && this.searchDate[1], // 结束时间
        };
        getOrderLists(params).then(response => {
          this.loading = false;
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.data.total;
            this.dataLists = response.data.rows;
          }
        });
        resolve();
      });
    },
    btn_search() {
      this.pageParams.pageindex = 1;
      this.getList();
    },
    handleChange(value) {
      console.log(value);
    },
    //表格数据处理开始
    queryData(){//查询操作
  		this.listData = [
  			{
        	id:1,
          type:1,
          sheetType: "青年鞋",
          taskKey: "shijian_01",
          templateUrl: "/shijian_01"
        },
        {
        	id:2,
          type:1,
          sheetType: "青年鞋",
          taskKey: "shijian_02",
          templateUrl: "/shijian_02"
        },
        {
        	id:3,
          type:1,
          sheetType: "青年鞋",
          taskKey: "shijian_03",
          templateUrl: "/shijian_04"
        },
        {
        	id:4,
          type:2,
          sheetType: "中年鞋",
          taskKey: "wenti_01",
          templateUrl: "/wenti_01"
        },
        {
        	id:5,
          type:2,
          sheetType: "中年鞋",
          taskKey: "wenti_02",
          templateUrl: "/wenti_02"
        },
        {
        	id:6,
          type:2,
          sheetType: "中年鞋",
          taskKey: "wenti_03",
          templateUrl: "/wenti_03"
        },
        {
        	id:7,
          type:3,
          sheetType: "接线合计",
          taskKey: "接线合计",
          templateUrl: "/wenti_04"
        },
  		];
		  this.rowspan()
  	},
  	rowspan() {
  		this.listData.forEach((item,index) => {
	    	if( index === 0){
	    		this.spanArr.push(1);
	    		this.position = 0;//合并列的数据
          this.colArr.push(1);
          this.colArrPosition = 0;//合并行的数据
	    	}else{
            if(this.listData[index].sheetType === this.listData[index].taskKey){
            this.colArr[this.colArrPosition] += 1;
            this.colArr.push(0)
          }else{
            this.colArr.push(1)
            this.colArrPosition = index;
          }
	    		if(this.listData[index].type === this.listData[index-1].type ){
	    			this.spanArr[this.position] += 1;
	    			this.spanArr.push(0);
	    		}else{
	    			this.spanArr.push(1);
	    			this.position = index;
	    		}
	    	}
	    })
  	},
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {  //表格合并行
      if(rowIndex === 6){
        if(columnIndex==0){
          const hanghao = this.colArr[rowIndex]
          const hanghao1 = hanghao>0 ? 1:0;
          return {
            rowspan:hanghao,
            colspan:hanghao1
          }
        }else{
            return{
              rowspan:0,
              colspan:0
            }
          }
      }
    	if (columnIndex === 0) {
    		const _row = this.spanArr[rowIndex];
    		const _col = _row>0 ? 1 : 0;
    		return {
    			rowspan: _row,
    			colspan: _col
    		}
    	}
    	if(columnIndex === 1){
    		const _row = this.spanArr[rowIndex];
    		const _col = _row>0 ? 1 : 0;
    		return {
    			rowspan: _row,
    			colspan: _col
    		}
    	}
    },
    //表格数据处理结束
  },
  mounted() {
     this.queryData();
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
span{
  font-size: 14px;
}

</style>
