<script>
export default {
  name: "AppHourCount",
  label: "市场看板-全门店时段合计",
  data() {
    return {
      summary: {},
      tableData: []
    }
  },
  computed: {
    search: v => v.$marketBoard.search,
    columns: v => {
      let {currentDate, compareDate} = v.search
      const {compareSaleAmt = 0, compareHourTotalAmt = 0, currentHourTotalAmt = 0, saleGrowthRate = 0} = v.summary
      const {dayjs} = window
      currentDate = currentDate ? dayjs(currentDate).format("YYYY-MM-DD") : ""
      compareDate = compareDate ? dayjs(compareDate).format("YYYY-MM-DD") : ""
      return [
        {label: "日期", width: 100, children: [{label: '总计', children: [{label: '品类', prop: "categoryName"}]}]},
        {
          label: compareDate, width: 137, align: 'center', children: [
            {label: `${compareSaleAmt}`, align: 'right', children: [{label: "总销售额", prop: "compareSaleAmt", align: 'right'}]},
            {label: `${compareHourTotalAmt}`, align: 'right', children: [{label: "时段销售额", prop: "compareHourTotalAmt", align: 'right'}]},
          ]
        },
        {
          label: currentDate, width: 137, align: 'center', children: [
            {label: `${currentHourTotalAmt}`, align: 'right', children: [{label: "时段销售额", prop: "currentHourTotalAmt", align: 'right'}]},
            {label: `${saleGrowthRate}`, align: 'right', children: [{label: "销售增长率", prop: "saleGrowthRate", align: 'right'}]},
          ]
        }
      ]
    }
  },
  methods: {
    getTableData() {
      const {$http, $waitFor} = window
      $waitFor($http).then(() => $http.post("/data-boot/la/screen/marketBoard/hourCount", {
        ...this.search, limit: 999
      })).then(res => {
        if (res?.data) {
          this.tableData = res.data?.page?.records || []
          this.summary = res.data?.total
        }
      })
    },
    getHeaderClass({rowIndex}) {
      if (rowIndex === 1) {
        return "summaryHeader"
      }
    }
  },
  watch: {
    search: {
      immediate: true, deep: true, handler() {
        this.getTableData()
      }
    }
  }
}
</script>

<template>
  <section class="AppHourCount">
    <el-table :data="tableData" size="mini" header-cell-class-name="tableHeader" cell-class-name="tableCell" max-height="242px" stripe :header-row-class-name="getHeaderClass">
      <table-column v-for="(column,i) in columns" :key="i" :column="column"/>
    </el-table>
  </section>
</template>

<style>
.AppHourCount {
  color: #fff;
  box-sizing: border-box;
}

.AppHourCount .tableHeader {
  background: rgba(13, 48, 99, 0.6) !important;
  color: #fff;
  border-color: transparent !important;
}

.AppHourCount .el-table tr {
  background-color: transparent !important;
}

.AppHourCount .el-table {
  background: transparent;
  border-color: transparent;
}

.AppHourCount .el-table .el-table__footer-wrapper tr, .AppHourCount .el-table .summaryHeader {
  background: linear-gradient(90deg, rgba(1, 196, 236, 0.5) 0%, rgba(1, 196, 236, 0.01) 100%);
}

.AppHourCount .summaryHeader .tableHeader {
  background: transparent !important;
}

.AppHourCount .el-table .summaryHeader .cell {
  color: #66FFFF;
}

.AppHourCount .el-table .el-table__footer-wrapper .is-leaf {
  color: #66FFFF;
  background: transparent;
  border-color: transparent;
}

.AppHourCount .tableCell {
  color: #fff;
  border-color: transparent !important;
}

.AppHourCount .el-table tr.el-table__row--striped {
  --odd-bg: #09265B;
  background-color: #081F48;
  background-image: linear-gradient(
      -45deg, var(--odd-bg) 0, var(--odd-bg) 10%, transparent 10%, transparent 50%,
      var(--odd-bg) 50%, var(--odd-bg) 60%, transparent 60%, transparent);
  background-size: 10px 10px;
}

.AppHourCount .el-table tr.el-table__row--striped .tableCell {
  background-color: transparent !important;
}

.AppHourCount .el-table tr:hover > .tableCell {
  background-color: rgba(255, 255, 255, .1) !important;
}

.AppHourCount .subTitle {
  line-height: 20px;
  width: fit-content;
  margin: 24px auto 12px;
  background-image: url("http://10.0.97.209/img/kengee/kengee5.png");
  background-repeat: no-repeat;
  background-size: 100% 2px;
  background-position: center bottom;
}
</style>
