<template>
  <div class="JCDetails" style="padding: 0 50px 0 50px;height: 100%;">
    <h1>客流分析</h1>
    <div class="topbox" style="display: flex;justify-content: space-between;">
      <div style="flex: 1;"></div>
      <div class="selec">
        <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" style="margin: 0 20px;">
        <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <button 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',
      }" row-key="id" :data="tableData" style="width: 100%;">
        <el-table-column prop="company" width="150" fixed label="店面">
          <!-- <template slot-scope="scope">
            <div class="handle" style="color: red;position: absolute;left: 0;top: 500px;">{{ scope.row.company }}</div>
          </template> -->
        </el-table-column>
        <el-table-column prop="scjdl" sortable width="120" label="首次接待量">
        </el-table-column>
        <el-table-column prop="scldl" sortable width="120" label="首次留档量">
        </el-table-column>
        <el-table-column prop="ldv" sortable width="120" label="留档率">
        </el-table-column>
        <el-table-column prop="sccjl" sortable width="120" label="首次成交量">
        </el-table-column>
        <el-table-column prop="skcjl" sortable width="120" label="首客成交率">
        </el-table-column>
        <el-table-column prop="ecddl" sortable width="120" label="二次到店量">
        </el-table-column>
        <el-table-column prop="eccjl" sortable width="120" label="二次成交量">
        </el-table-column>
        <el-table-column prop="ecddbl" sortable width="120" label="二次到店率">
        </el-table-column>
        <el-table-column prop="eccjbl" sortable width="120" label="二次成交率">
        </el-table-column>
        <el-table-column prop="hjcjl" sortable width="120" label="合计成交量">
        </el-table-column>
        <el-table-column prop="lcddl" sortable width="120" label="留存订单量">
        </el-table-column>
        <el-table-column prop="ddcjl" sortable width="120" label="到店成交率">
        </el-table-column>
        <el-table-column prop="ssfz" sortable width="180" label="接待时长大于30分钟">
        </el-table-column>
        <el-table-column prop="wxldl" sortable width="120" label="微信留档量">
        </el-table-column>
        <el-table-column prop="wxldbzb" sortable width="140" label="微信留档占比">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { column } from "./tuozhuai";
import { klfxtabledataInfo } from "../../../servuces/prove";
import { nowdaterange } from "../../../servuces/getnowtime";
export default {
  data () {
    return {
      taheight: window.innerHeight - (window.innerHeight * 0.15),
      tableData: [],
      options: [],
      tableDatahj: [],
      value: '',
      value1: '',
      activeName: 'second'
    }
  },
  created () {
    const data = sessionStorage.getItem('data')
    console.log(data);
    if (data) {
      this.options = JSON.parse(data)
    }
  },
  mounted () {
    column(this)
    this.klfxtabledataapi()
  },
  updated () {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },

  methods: {
    getSummaries () {
      const keyindex = {
        'company': 0,
        'scjdl': 1,
        'scldl': 2,
        'ldv': 3,
        'sccjl': 4,
        'skcjl': 5,
        'ecddl': 6,
        'eccjl': 7,
        'ecddbl': 8,
        'eccjbl': 9,
        'hjcjl': 10,
        'lcddl': 11,
        'ddcjl': 12,
        'ssfz': 13,
        'wxldl': 14,
        'wxldbzb': 15,
      }
      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}`;
        });
        klfxtabledataInfo({ "company_ids": strvalue, "date_begin": strvaluezh[0], 'date_end': strvaluezh[1] }).then(res => {
          // console.log('查询分期业务', res);
          this.tableData = res.data
          console.log(this.tableData, 1111);
          this.tableDatahj = res.footer

        }
        )
      } else {
        klfxtabledataInfo({ "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);
    },
    klfxtabledataapi () {
      this.value1 = nowdaterange
      klfxtabledataInfo({ "company_ids": '', "date_begin": nowdaterange[0], 'date_end': nowdaterange[1] }).then(res => {
        this.tableData = res.data
        this.tableDatahj = res.footer
        // this.$nextTick(() => {
        //   column(this.tableData)
        // })
        // console.log(this.tableDatahj);
        // console.log(this.tableData);

      })
    },
  }
}
</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 .el-table__row {
  height: 6vh !important;
}

::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 td:hover {
  color: rgb(5, 51, 159);
}

// ::v-deep .el-table__body .el-table__cell {
//   background-color: red !important;
// }

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

::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>



