<template>
  <div>
    <!-- 标题 -->
    <div class="title" style="margin-top: 10px">
      <div style="display: flex; justify-content: space-between">
        <h1 style="color: azure" @click="goOff">漯河亿通集团数据看板</h1>

        <div class="time">
          <span class="iconfont icon-riqi"></span>&nbsp;&nbsp;{{ currentTime }}
        </div>
      </div>
      <img src="../../assets/bargound/图层 6.png" width="100%" />
    </div>
    <div class="content">
      <!-- 库存车辆 -->

      <el-tabs type="border-card" class="theme">
        <div style="display: flex; justify-content: space-between">
          <!-- 图标 -->
          <div>
            <p>
              <img src="../../assets/bargound/data.png" alt="" /><span
                class="kccl"
                >客源分析</span
              >
            </p>
          </div>
          <div style="display: flex">
            <!-- 下拉框 -->
            <div style="margin-right: 20px">
              <el-select
                class="select"
                v-model="company_ids"
                multiple
                placeholder="请选择"
                style="width: 200px"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.text"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <!-- 日期表 -->
            <div class="dataForm" style="margin-right: 20px">
              <el-date-picker v-model="search_date" type="daterange" range-separator="——" start-placeholder="开始日期"
                end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
              </el-date-picker>
            </div>
            <!-- 按钮 -->
            <el-button @click="searchBtn(company_ids, search_date)" style="background-color: rgb(40, 155, 209); color: black">查询</el-button>
          </div>
        </div>
        <!-- 表格 -->
        <el-table
          border
          class="exporttable"
          :data="tableData"

          stripe
          :header-cell-style="{ 'text-align': 'center', background: '#03111c' }"
          :cell-style="{ 'text-align': 'center' }"
          show-summary
          style="width: 100%; margin: 1px"
          :max-height="taheight"
        >
          <el-table-column prop="company" label="品牌"> </el-table-column>
          <el-table-column prop="name" label="展厅">
            <el-table-column prop="ztjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="ztzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="ztcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="转介绍">
            <el-table-column prop="zjsjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="zjszs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="zjscjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="网络直销">
            <el-table-column prop="wlzxjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="wlzxzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="wlzxcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="车展外拓">
            <el-table-column prop="czwtjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="czwtzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="czwtcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="二网大客">
            <el-table-column prop="ewdkjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="ewdkzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="ewdkcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="厂家">
            <el-table-column prop="cjjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="cjzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="cjcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="懂车帝">
            <el-table-column prop="dcdjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="dcdzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="dcdcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="抖音">
            <el-table-column prop="dyjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="dyzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="dycjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="易车网">
            <el-table-column prop="ycwjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="ycwzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="ycwcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="汽车之家">
            <el-table-column prop="qczjjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="qczjzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="qczjcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="电台广告">
            <el-table-column prop="dtggjc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="dtggzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="dtggcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
          <el-table-column prop="name" label="其他网络平台">
            <el-table-column prop="qtwljc" label="交车数" width="120" sortable> </el-table-column>
            <el-table-column prop="qtwlzs" label="客户总数" width="120" sortable> </el-table-column>
            <el-table-column prop="qtwlcjl" label="成交率" width="120" sortable> </el-table-column>
          </el-table-column>
        </el-table>

        <!-- <el-tab-pane label=" 分渠道销量统计分析">配置管理</el-tab-pane> -->
      </el-tabs>
    </div>
  </div>
</template>

<script>
import { kyfxtabledataInfo } from "../../servuces/prove";
import { nowdaterange } from "../../servuces/getnowtime";
import { column } from "../../store/tuozhuai";
export default {
  data() {
    return {
      taheight: window.innerHeight - (window.innerHeight * 0.15),
      currentTime: "",
      company_ids: [],
      //表格各类属性
      tableData: [],
      tableDatahj: [],
      //下拉框内属性
      options: [],
      search_date: '',
    };
  },
  created () {
    const data = sessionStorage.getItem('company_data');
    if (data) {
      this.options = JSON.parse(data)
    }
  },
  mounted() {
    column(this);
    this.updateTime();
    this.getTableData();//开始获取表格
  },
  beforeDestroy() {
    // 在组件销毁前清除定时器，避免内存泄漏
    clearInterval(this.timer);
  },
  methods: {
    //表格接口数据
    getTableData () {
      this.search_date = nowdaterange;
      kyfxtabledataInfo({ "company_ids": '', "date_begin": nowdaterange[0], 'date_end': nowdaterange[1] }).then(res => {
        this.tableData = res.data;
        this.tableDatahj = res.footer
      })
    },
    //查询
    searchBtn(value, value1) {
      const company_ids = 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": company_ids, "date_begin": strvaluezh[0], 'date_end': strvaluezh[1] }).then(res => {
          this.tableData = res.data;
          this.tableDatahj = res.footer

        })
      } else {
        kyfxtabledataInfo({"company_ids": company_ids, "date_begin": '', 'date_end': ''}).then(res => {
          this.tableData = res.data;
          this.tableDatahj = res.footer;
        });
      }
    },
    goOff(){
      history.go(-1);
    },
    //更新时间
    updateTime() {
      // 在组件挂载结束时启动定时器，每秒更新一次时间
      this.currentTime = this.getCurrentTime();
      //每秒更新一次
      this.timer = setInterval(() => {
        this.currentTime = this.getCurrentTime();
      }, 1000);
    },
    getCurrentTime() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      const hours = String(now.getHours()).padStart(2, "0");
      const minutes = String(now.getMinutes()).padStart(2, "0");
      const seconds = String(now.getSeconds()).padStart(2, "0");
      return `${year}.${month}.${day} ${hours}:${minutes}:${seconds}`;
    },
  },
};
</script>

<style scoped="less">
.content {
  padding: 10px;
}

.title {
  width: 100%;
  /* background: url('../../assets/bargound/'); */
  height: 64px;

  p {
    height: 100px;
  }
}

.kccl {
  color: #697c91;
  font-size: 24px;
  margin-left: 10px;
}
.el-input__inner {
  background-color: #133654;
}

.el-input__inner {
  border: 0;
}
::v-deep .el-date-editor .el-range-input {
  display: inline-block;
  height: 100%;
  width: 39%;
  text-align: center;
  font-size: 14px;
  color: #ffffffba;
  background-color: #133654;
}
::v-deep .el-table {
  border: none;
}
::v-deep .el-table::before {
  background-color: black;
}
::v-deep .el-table__footer-wrapper tbody td.el-table__cell,
.el-table__header-wrapper tbody td.el-table__cell {
  background-color: rgb(2, 62, 2);
  color: #93acbf;
}
::v-deep .el-table--border::after,
.el-table--group::after,
.el-table::before {
  content: "";
  position: absolute;
  background-color: black;
  z-index: 1;
}
::v-deep
  .el-tabs.theme.el-tabs--top.theme.el-tabs--border-card
  .el-tabs__nav-scroll {
  border-bottom: 1px solid;
}
::v-deep .el-table td,
.building-top .el-table th.is-leaf {
  color: #93acbf;
}
::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: #133654;
}
/* 日期表 */
:deep(.el-input__inner) {
  background-color: #133654;
  border: none;
  color: #ffffffc1;
}

::v-deep .el-table tr {
  background: #133654;
}
::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td {
  background: #081b2b;
}
/**
改变边框颜色
 */
.el-table {
  border-bottom: 1px solid #102b47;
  border-right: 1px solid #102b47;
  margin: 0 auto;
}
::v-deep.el-table th {
  border: 1px solid #102b47 !important;
  border-right: none !important;
  border-bottom: none !important;
}

::v-deep.el-table td {
  border: 1px solid #102b47;
  border-right: none !important;
  text-align: center !important;
}
.time {
  color: rgb(174, 201, 222);
  margin-right: 2%;
  font-size: 16px;
  overflow: hidden;
  max-width: 15%;
  white-space: nowrap;
}
</style>
