<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>抖音小程序数据</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-tabs type="border-card">
      <el-tab-pane label="页面分析">
        <!-- 查询和其他操作 -->
        <div class="filter-container">
          <el-form :inline="true" size="small" v-model="listQuery">
            <el-form-item label="访问时间">
              <el-date-picker v-model="timeArray" type="datetimerange" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                class="filter-item" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                :picker-options="pickerOptions" />
            </el-form-item>
            <el-form-item>
              <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getPageList(false)">查找</el-button>
              <el-button :loading="listLoading" class="filter-item" type="primary" icon="el-icon-download"
                @click="getPageList(true)">导出</el-button>
            </el-form-item>
          </el-form>
        </div>

        <!-- 查询结果 -->
        <el-table :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" label="访问日期" prop="pageDate" />
          <el-table-column align="center" label="页面名称" prop="pageName" />
          <el-table-column align="center" label="页面路径" prop="page" />
          <el-table-column align="center" label="访问人数" prop="pageUv" />
          <el-table-column align="center" label="平均停留时长" prop="pageAvgStayTime" />
          <el-table-column align="center" label="分享次数" prop="pageShareTime" />
          <!-- <el-table-column align="center" label="数据抓取时间" prop="etlTime" /> -->
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getPageList(false)" />
      </el-tab-pane>
      
      <!-- <el-tab-pane label="行为分析"> 
        <div class="filter-container">
          <el-form :inline="true" size="small" v-model="listQueryIB">
            <el-form-item label="访问时间">
              <el-date-picker v-model="timeIBArray" type="datetimerange" value-format="yyyy-MM-dd" class="filter-item"
                range-separator="至" start-placeholder="访问开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" />
            </el-form-item>
            <el-form-item>
              <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getIBList">查找</el-button>
            </el-form-item>
          </el-form>
        </div>
 
        <el-table :data="listIB" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" label="访问日期" min-width="150" prop="agentName" />
          <el-table-column align="center" label="活跃用户数" prop="createTime" />
          <el-table-column align="center" label="新增用户数" prop="ibTotal" />
          <el-table-column align="center" label="累计用户数" prop="connected" />
          <el-table-column align="center" label="分享次数" prop="noSaveResult" />
          <el-table-column align="center" label="打开次数" prop="less20s" />
          <el-table-column align="center" label="人均打开次数" prop="talkTotal" />
          <el-table-column align="center" label="人均停留时长" prop="avgTalk" />
          <el-table-column align="center" label="次均停留时长" prop="ringTotal" />
          <el-table-column align="center" label="数据抓取时间" prop="etlTime" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="来源分析"> 
        <div class="filter-container">
          <el-form :inline="true" size="small" v-model="listQueryIB">
            <el-form-item label="访问时间">
              <el-date-picker v-model="timeIBArray" type="datetimerange" value-format="yyyy-MM-dd" class="filter-item"
                range-separator="至" start-placeholder="访问开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" />
            </el-form-item>
            <el-form-item>
              <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getIBList">查找</el-button>
            </el-form-item>
          </el-form>
        </div>
 
        <el-table :data="listIB" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" label="访问日期" prop="agentName" />
          <el-table-column align="center" label="场景名称" prop="createTime" />
          <el-table-column align="center" label="活跃用户数" prop="ibTotal" />
          <el-table-column align="center" label="新增用户数" prop="connected" />
          <el-table-column align="center" label="场景访问次数" prop="noSaveResult" />
          <el-table-column align="center" label="次均停留时长" prop="less20s" />
          <el-table-column align="center" label="数据抓取时间" prop="etlTime" />
        </el-table>

          <pagination v-show="totalIB>0" :total="totalIB" :page.sync="listQueryIB.page" :limit.sync="listQueryIB.limit" @pagination="getIBList" /> 
      </el-tab-pane> -->

    </el-tabs>

  </div>
</template>
  
<script>
import Pagination from "./../common/Pagination";
import service from "../../script/api/service";
import "@/script/table2excel";

export default {
  name: "callTask",
  components: { Pagination },
  data() {
    return {
      listLoading: false,
      timeArray: [
        this.formateDay(new Date(new Date() - 3600 * 1000 * 24 * 7)),
        this.formateDay(new Date()),
      ],
      timeTArray: [
        this.formateDay(new Date(new Date() - 3600 * 1000 * 24 * 7)),
        this.formateDay(new Date()),
      ],
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 50,
        campaignId: "",
        order: "desc",
      },
      timeIBArray: [
        this.formateDay(new Date(new Date() - 3600 * 1000 * 24 * 7)),
        this.formateDay(new Date()),
      ],
      listIB: [],
      totalIB: 0,
      listQueryIB: {
        //ib进电的结果
        page: 1,
        limit: 50,
        campaignId: "",
        order: "desc",
      }, 
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  computed: {},
  created() {
  },
  methods: {
    getPageList(isExport) {
      console.info(this.timeArray);
      if (this.timeArray && this.timeArray.length === 2) {
        this.listQuery.startDate = this.timeArray[0];
        this.listQuery.endDate = this.timeArray[1];
      } else {
        this.listQuery.startDate = null;
        this.listQuery.endDate = null;
        this.$message.warning("请先选择日期范围再进行查询");
        return false;
      }
      this.listQuery.isExport=isExport;
      this.listLoading = true;

      if(isExport==false){
        service
        .$axiosGetDYPageList(this.listQuery)
        .then((response) => {
          this.list = response.data.data.list; 
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading = false;
        });
      }
      else{
        service.$axiosGetDYPageExport(this.listQuery);
      }
      
    }, 
    getIBList() {
      if (this.timeIBArray && this.timeIBArray.length === 2) {
        this.listQueryIB.startTime = this.timeIBArray[0];
        this.listQueryIB.endTime = this.timeIBArray[1];
      } else {
        this.listQueryIB.startTime = null;
        this.listQueryIB.endTime = null;
        this.$message.warning("请先选择日期范围再进行查询");
        return false;
      }
      this.listLoading = true;

      service
        .$axiosGetCallIB(this.listQueryIB)
        .then((response) => {
          this.listIB = response.data.data;
          this.totalIB = 1;
          this.listLoading = false;
        })
        .catch(() => {
          this.listIB = [];
          this.totalIB = 0;
          this.listLoading = false;
        });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
  },
};
</script>
  
<style>
.detail-container {
  width: 80%;
  padding: 20px 20px 20px 20px;
  margin: 20px auto;
}

.panel-group {
  display: flex;
  flex-flow: wrap;
}

.panel-group .card-panel {
  min-height: 130px;
  border-radius: 6px;
  padding: 10px 10px 0px;
  cursor: pointer;
  font-size: 12px;
  position: relative;
  overflow: hidden;
  color: #666;
  background: #fff;
  -webkit-box-shadow: 2px 2px 10px rgb(0 0 0 / 10%);
  box-shadow: 2px 2px 10px rgb(0 0 0 / 10%);
  border-color: rgba(0, 0, 0, .05);
  margin: 10px
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid #ccc;
  /*dashed*/
  padding: 10px 0;
}

.card-data {
  display: flex;
  flex-direction: column;
  padding-top: 10px;
}

.card-item {
  display: flex;
  line-height: 20px;
  font-size: 13px;
}

.card-sub-item {
  margin-right: 20px;
  border-right: 1px dashed #ccc;
  width: 150px;
}

.card-sub-item .title {
  font-weight: 600;
}

.card-footer {
  height: 40px;
  line-height: 40px;
  border-top: 1px dashed #ccc;
  text-align: center;
  margin-top: 10px;
  color: #36a3f7;
}
</style>
  