<template>
  <div class="JCDetails" style="padding:0 50px 0 50px;">

    <h1>客源分析</h1>
    <!-- <div class="topbox">
      <div class="selec">
        <el-select v-model="value" clearable placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>
      <div class="timeselec">

      </div>
    </div> -->
    <div class="topbox" style="display: flex;justify-content: space-between;">
      <div style="flex: 1;"></div>
      <div class="selec ershi">
        <el-select v-model="value" filterable multiple collapse-tags clearable placeholder="请选择">
          <el-option v-for="(item, index) in options" :key="index" :label="item.text" :value="item.value">
          </el-option>
        </el-select>
      </div>
      <div class="timeselec ershi">
        <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <button class="ershi" style="width: 100px;height: 40px;background-color: aqua;"
        @click="chaxun2(value, value1)">查询</button>
    </div>
    <div> <el-table ref="table" :height="taheight" show-summary :summary-method="getSummaries" :header-cell-style="{
      background: 'rgba(30, 111, 200,0.8)',
      color: 'white',
      textAlign: 'center',
      border: '1px rgb(70, 91, 117) solid',
    }" :data="tableData" style="width: 100%">
        <el-table-column prop="company" fixed label="门店" width="100">
        </el-table-column>
        <el-table-column label="展厅">
          <el-table-column prop="ztjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="ztzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="ztcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="ztcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="转介绍">
          <el-table-column prop="zjsjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="zjszs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="zjscjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="zjscjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="网络直销">
          <el-table-column prop="wlzxjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="wlzxzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="wlzxcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="wlzxcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="车展外拓">
          <el-table-column prop="czwtjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="czwtzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="czwtcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="czwtcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="二网大客">
          <el-table-column prop="ewdkjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="czwtzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="czwtcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="czwtcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="厂家">
          <el-table-column prop="cjjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="cjzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="cjcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="cjcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="懂车帝">
          <el-table-column prop="dcdjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="dcdzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="dcdcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="dcdcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="抖音">
          <el-table-column prop="dyjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="dyzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="dycjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="dycjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="易车网">
          <el-table-column prop="ycwjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="ycwzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="ycwcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="ycwcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="汽车之家">
          <el-table-column prop="qczjjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="qczjzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="qczjcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="qczjcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="电台广告">
          <el-table-column prop="dtggjc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="dtggzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="dtggcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="dtggcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>
        <el-table-column label="其他网络平台">
          <el-table-column prop="qtwljc" sortable width="100" label="交车数">
          </el-table-column>
          <el-table-column prop="qtwlzs" sortable width="110" label="客户总数">
          </el-table-column>
          <el-table-column prop="qtwlcjl" sortable width="100" label="成交率">
          </el-table-column>
          <el-table-column prop="qtwlcjl" sortable width="110" label="成交占比">
          </el-table-column>
        </el-table-column>

      </el-table></div>


  </div>
</template>
<script>
import { column } from "./tuozhuai";
import { kyfxtabledataInfo } from "../../../servuces/prove";
import { nowdaterange } from "../../../servuces/getnowtime";
export default {
  data () {
    return {
      tableData: [],
      taheight: window.innerHeight - (window.innerHeight * 0.15),
      tableDatahj: [],
      options: [],
      value: '',
      value1: '',
      activeName: 'second'
    }
  },
  created () {
    const data = sessionStorage.getItem('data')
    console.log(data);
    if (data) {
      this.options = JSON.parse(data)
    }
  },
  mounted () {
    column(this)
    this.kyfxtabledataapi()
  },
  updated () {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    getSummaries () {
      const keyindex = {
        'company': 0,
        'ztjc': 1,
        'ztzs': 2,
        'ztcjl': 3,
        'zjsjc': 5,
        'zjszs': 6,
        'zjscjl': 7,
        'wlzxjc': 9,
        'wlzxzs': 10,
        'wlzxcjl': 11,
        'czwtjc': 13,
        'czwtzs': 14,
        'czwtcjl': 15,
        'ewdkjc': 17,
        'ewdkzs': 18,
        'ewdkcjl': 19,
        'cjjc': 21,
        'cjzs': 22,
        'cjcjl': 23,
        'dcdjc': 25,
        'dcdzs': 26,
        'dcdcjl': 27,
        'dyjc': 29,
        'dyzs': 30,
        'dycjl': 31,
        'ycwjc': 33,
        'ycwzs': 34,
        'ycwcjl': 35,
        'qczjjc': 37,
        'qczjzs': 38,
        'qczjcjl': 39,
        'dtggjc': 41,
        'dtggzs': 42,
        'dtggcjl': 43,
        'qtwljc': 45,
        'qtwlzs': 46,
        'qtwlcjl': 47,
      }
      const item_value = []
      for (let key in this.tableDatahj) {
        let index = keyindex[key]
        item_value[index] = this.tableDatahj[key] + ''
      }
      // console.log(item_value);
      item_value[0] = '合计'
      return item_value
    },
    chaxun2 (value, value1) {
      const strvalue = value.join(',')
      if (value1) {
        const strvaluezh = value1.map(item => {
          const date = new Date(item)
          // 获取年份和月份
          const year = date.getFullYear();
          const month = date.getMonth() + 1; // 月份从0开始，需要加1
          const day = date.getDate()
          // 将年份和月份拼接成所需形式的字符串
          return `${year}-${month}-${day}`;
        });
        kyfxtabledataInfo({ "company_ids": strvalue, "date_begin": strvaluezh[0], 'date_end': strvaluezh[1] }).then(res => {
          // console.log('查询分期业务', res);
          this.tableData = res.data
          this.tableDatahj = res.footer
          console.log(res);
        }
        )
      } else {
        kyfxtabledataInfo({ "company_ids": strvalue, "date_begin": '', 'date_end': '' }).then(res => {
          // console.log('查询分期业务', res);
          this.tableData = res.data
          this.tableDatahj = res.footer
          console.log(res);
        }
        )
      }


      // const strvalue1 = strvaluezh.join(',')
      // console.log(strvaluezh[0], strvaluezh[1]);
      // const date = new Date(value1)
      // // 获取年份和月份
      // const year = date.getFullYear();
      // const month = String(date.getMonth() + 1); // 月份从0开始，需要加1
      // const day = String(date.getDate())
      // // 将年份和月份拼接成所需形式的字符串
      // const strvalue1 = `${year}-${month}-${day}`;
      // const strvalue3=
      // console.log(strvalue, strvaluezh[0], strvaluezh[1]);

      // console.log(strvalue, strvalue1);
      // console.log(value, value1);
    },
    kyfxtabledataapi () {
      this.value1 = nowdaterange
      kyfxtabledataInfo({ "company_ids": '', "date_begin": nowdaterange[0], 'date_end': nowdaterange[1] }).then(res => {
        console.log('客源分析', res);
        this.tableData = res.data
        this.tableDatahj = res.footer

      })
    }
  }
}
</script>
<style>
/* .el-table tr {
  background-color: none;
  color: white;
} */
.el-table .warning-row {
  background-color: rgba(15, 78, 146, 0.827);

}

.el-table .success-row {
  background-color: rgb(15, 78, 146, 0.5);
}

.has-gutter tr th:last-child {
  background-color: rgba(30, 111, 200, 0.8);
}

.el-table tr {
  background-color: rgb(15, 78, 146, 0.5);
}
</style>
<style scoped lang="scss">
.JCDetails {
  .selec {
    margin: 0 0 20px 0;
  }
}

::v-deep .el-table__footer {

  tr {

    td {
      color: white;
      background-color: rgba(30, 111, 200, 0.8);
    }

    td:hover {
      color: white;
    }
  }

}

::v-deep .el-table {
  background-color: transparent;
  border-color: rgb(70, 91, 117);
}

::v-deep .el-table td,
.building-top .el-table th.is-leaf {
  border-color: rgb(70, 91, 117);
  color: white;
}

::v-deep .el-table__body tr.hover-row>td.el-table__cell {
  background-color: rgb(58, 147, 189) !important;
}

::v-deep .gutter {
  background-color: rgba(30, 111, 200, 0.8) !important;
  border: 0 !important;
}

::v-deep .el-table td:hover {
  color: rgb(5, 51, 159);
}

::v-deep .has-gutter th {
  border-color: rgb(70, 91, 117);
}

::v-deep .el-table--enable-row-hover .el-table__body tr:hover>td {
  background-color: rgb(58, 147, 189);
}

::v-deep #tab-first,
::v-deep #tab-second,
::v-deep #tab-third,
::v-deep #tab-fourth {
  color: #fff; //设置修改默认蚊子颜色，背景颜色，等
}

::v-deep .el-tabs__item.is-active {
  color: rgb(37, 99, 214) !important;
}
</style>



