<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="服务单次卡T+30复购明细">
        <!-- 查询和其他操作 -->
        <div class="filter-container">
          <el-form :inline="true" size="small" v-model="listQuery1">
            <el-form-item label="服务月份">
              <el-date-picker v-model="listQuery1.month" type="month" value-format="yyyy-MM"
                :picker-options="{}"></el-date-picker>
            </el-form-item>
            <el-form-item label="城市">
              <el-select v-model="listQuery1.city" multiple clearable placeholder="请选择城市">
                <el-option v-for="(item, index) in cityList" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否复购">
              <el-select v-model="listQuery1.rebuyStatus" clearable placeholder="请选择复购状态">
                <el-option v-for="(item, index) in rebuyStatus" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item> 
            <el-form-item label="商家名称">
              <el-input v-model="listQuery1.workerName" clearable  placeholder="请输入商家名称"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button class="filter-item" type="primary" icon="el-icon-search"
                @click="querySearch1(false)">查找</el-button>
              <el-button :loading="listLoading" class="filter-item" type="primary" icon="el-icon-download"
                @click="querySearch1(true)">导出</el-button>
            </el-form-item>
          </el-form>
        </div>

        <div style="font-size: 9px;"> 服务单次保洁后T+30天（0-30），客服复购周期卡（2、4、24、48）情况。此报表数据延迟一天</div>
        <!-- 查询结果 -->
        <el-table :data="list1" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column prop="city" label="城市"></el-table-column>
          <el-table-column prop="stationName" label="服务站"></el-table-column>
          <el-table-column prop="workerManager" label="商家运营"></el-table-column>
          <el-table-column prop="workerNo" label="商家ID"></el-table-column>
          <el-table-column prop="servantName" label="商家"></el-table-column>
          <el-table-column prop="cusType" label="客户类型"></el-table-column>
          <el-table-column prop="bookTime" label="服务时间"></el-table-column>
          <el-table-column prop="bookTradeNo" label="服务单号"></el-table-column>
          <el-table-column prop="payId" label="服务订单号"></el-table-column>
          <el-table-column prop="orderChannel" label="订单渠道"></el-table-column>
          <el-table-column prop="isFirst" label="是否首次服务"></el-table-column>
          <el-table-column prop="goodsName" label="复购周期商品"></el-table-column>
          <el-table-column prop="rebuyChannel" label="复购周期渠道"></el-table-column>
          <el-table-column prop="rebuyOrderSn" label="复购周期订单号"></el-table-column>
          <el-table-column prop="payTime" label="复购周期时间"></el-table-column>
          <el-table-column prop="rebuyWorkerNo" label="复购周期商家Id"></el-table-column>
          <el-table-column prop="rebuyWorkerName" label="复购周期商家"></el-table-column>

          
          <el-table-column prop="singleGoodsName" label="复购单次商品"></el-table-column>
          <el-table-column prop="singleRebuyChannel" label="复购单次渠道"></el-table-column>
          <el-table-column prop="singleRebuyOrderSn" label="复购单次订单号"></el-table-column>
          <el-table-column prop="singlePayTime" label="复购单次时间"></el-table-column>
          <el-table-column prop="singleRebuyWorkerNo" label="复购单次商家Id"></el-table-column>
          <el-table-column prop="singleRebuyWorkerName" label="复购单次商家"></el-table-column>
        </el-table>
        <pagination :total="listQuery1.total" :page.sync="listQuery1.pageIndex" :limit.sync="listQuery1.pageSize"
          @pagination="querySearch1(false)" />
      </el-tab-pane>
      <el-tab-pane label="周期老客T+30续约明细">
        <!-- 查询和其他操作 -->
        <div class="filter-container">
          <el-form :inline="true" size="small" v-model="listQuery2">
            <el-form-item label="服务月份">
              <el-date-picker v-model="listQuery2.month" type="month" value-format="yyyy-MM"
                :picker-options="{}"></el-date-picker>
            </el-form-item>
            <el-form-item label="城市">
              <el-select v-model="listQuery2.city" clearable multiple placeholder="请选择城市">
                <el-option v-for="(item, index) in cityList" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item> 
            <el-form-item label="是否复购">
              <el-select v-model="listQuery2.rebuyStatus" clearable placeholder="请选择复购状态">
                <el-option v-for="(item, index) in rebuyStatus" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item> 
            <el-form-item label="商家名称">
              <el-input v-model="listQuery2.workerName" clearable  placeholder="请输入商家名称"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button class="filter-item" type="primary" icon="el-icon-search"
                @click="querySearch2(false)">查找</el-button>
              <el-button :loading="listLoading" class="filter-item" type="primary" icon="el-icon-download"
                @click="querySearch2(true)">导出</el-button>
            </el-form-item>
          </el-form>
        </div>

        <!-- 查询结果 -->
        <div style="font-size: 9px;">老客续约率：周期卡内最后一次服务完成后30天内（0-30），有未使用的、未预约的、履约中的周期订单。此报表数据延迟一天</div>

        <el-table :data="list2" border style="width: 100%" class="table">
          <el-table-column prop="city" label="城市"></el-table-column>
          <el-table-column prop="stationName" label="服务站"></el-table-column>
          <el-table-column prop="workerManager" label="商家运营"></el-table-column>
          <el-table-column prop="workerNo" label="商家ID"></el-table-column>
          <el-table-column prop="servantName" label="商家"></el-table-column>
          <el-table-column prop="serviceGoods" label="服务商品"></el-table-column>
          <el-table-column prop="bookTime" label="最后一次服务时间"></el-table-column>
          <el-table-column prop="bookTradeNo" label="服务单号"></el-table-column>
          <el-table-column prop="payId" label="服务订单号"></el-table-column>
          <el-table-column prop="orderChannel" label="订单渠道"></el-table-column>
          <el-table-column prop="goodsName" label="复购商品"></el-table-column>
          <el-table-column prop="rebuyChannel" label="复购渠道"></el-table-column>
          <el-table-column prop="rebuyOrderSn" label="复购订单号"></el-table-column>
          <el-table-column prop="payTime" label="复购时间"></el-table-column>
          <el-table-column prop="isRebuy" label="是否已计提此复购"></el-table-column>
          <el-table-column prop="isBefore" label="是否有T+0之前的复购"></el-table-column>
          <el-table-column prop="isRefund" label="是否已退款"></el-table-column>
        </el-table>
        <pagination :total="listQuery2.total" :page.sync="listQuery2.pageIndex" :limit.sync="listQuery2.pageSize"
          @pagination="querySearch2(false)" />
      </el-tab-pane>
      <el-tab-pane label="复购汇总表"> 
        <div class="filter-container">
          <el-form :inline="true" size="small" v-model="listQuery3">
            <el-form-item label="复购周期">
              <el-date-picker v-model="listQuery3.month"  type="month" value-format="yyyy-MM" :picker-options="{}"></el-date-picker>
            </el-form-item>
            <el-form-item label="城市">
              <el-select v-model="listQuery3.city" clearable multiple placeholder="请选择城市">
                <el-option v-for="(item, index) in cityList" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>  
            <el-form-item label="复购类型">
              <el-select v-model="listQuery3.type" clearable placeholder="复购类型">
                <el-option  label="单次复购" value="单次复购"></el-option>
                <el-option  label="周期续约" value="周期续约"></el-option>
              </el-select>
            </el-form-item>  
            <el-form-item label="复购汇总">
              <el-select  v-model="listQuery3.sumType">
                <el-option label="到服务站"  value="到服务站"></el-option>
                <el-option label="到商家"  value="到商家"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button class="filter-item" type="primary" icon="el-icon-search"
                @click="querySearch3(false)">查找</el-button>
              <el-button :loading="listLoading" class="filter-item" type="primary" icon="el-icon-download"
                @click="querySearch3(true)">导出</el-button>
            </el-form-item>
          </el-form>
        </div>  
        <div style="font-size: 9px;">应复购单量:服务单次卡客户没有待履约周期卡或周期卡客户最后一次服务切没有其他待履约订单</div>
        <el-table :data="list2" border style="width: 100%" class="table">
          <el-table-column prop="rebuyDate" label="复购周期"></el-table-column>
          <el-table-column prop="city" label="城市"></el-table-column>
          <el-table-column prop="stationName" label="服务站"></el-table-column>   
          <el-table-column prop="workerManager" label="商家运营" v-if="listQuery3.sumType=='到商家'"></el-table-column>
          <el-table-column prop="workerNo" label="商家ID" v-if="listQuery3.sumType=='到商家'"></el-table-column>
          <el-table-column prop="workerName" label="商家" v-if="listQuery3.sumType=='到商家'"></el-table-column>
          <el-table-column prop="bookOrders" label="服务单量"></el-table-column>
          <el-table-column prop="needRebuyOrders" label="应复购单量"></el-table-column>
          <el-table-column prop="rebuyOrders" label="复购单量"></el-table-column>
          <el-table-column prop="gmv" label="复购金额"></el-table-column>
          <el-table-column prop="rebuyRate" label="复购比例"></el-table-column>
          <el-table-column prop="rebuy2Orders" label="复购2次单量"></el-table-column>
          <el-table-column prop="rebuy2Gmv" label="复购2次金额"></el-table-column>
          <el-table-column prop="rebuy4Orders" label="复购4次单量"></el-table-column>
          <el-table-column prop="rebuy4Gmv" label="复购4次金额"></el-table-column>
          <el-table-column prop="rebuy24Orders" label="复购24次单量"></el-table-column>
          <el-table-column prop="rebuy24Gmv" label="复购24次金额"></el-table-column> 
        </el-table>
        <pagination :total="listQuery3.total" :page.sync="listQuery3.pageIndex" :limit.sync="listQuery3.pageSize"
          @pagination="querySearch3(false)" />
      </el-tab-pane>

    </el-tabs>

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

export default {
  name: "douyinRebuy",
  components: { Pagination },
  data() {
    return {
      listLoading: false,
      timeArray: '',
      cityList: [],
      list1: [],
      listQuery1: {
        total: 0,
        pageIndex: 1,
        pageSize: 50,
        rebuyStatus:'',
        month: moment().format("YYYY-MM"),
        city: ""
      },
      rebuyStatus:['已复购','未复购'],
      list2: [],
      listQuery2: {
        total: 0,
        pageIndex: 1,
        pageSize: 50,
        rebuyStatus:'',
        month: moment().format("YYYY-MM"),
        city: ""
      },
      list3: [],
      listQuery3: {
        city: "",
        total: 0,
        pageIndex: 1,
        pageSize: 50,
        type:'单次复购',
        month: moment().format("YYYY-MM"),
        sumType:'到服务站'
      },
    };
  },
  computed: {},
  created() {
    this.cityList = JSON.parse(window.localStorage.getItem("allHmCity"));
    let allCity={
      
    }
    this.cityList.splice(0,0,"全部");
  },
  methods: {
    querySearch1(isExport) {
      console.info(this.timeArray);
      if (this.listQuery1.month == '' || this.listQuery1.city == '') {
        this.$message.warning("请先选择日期或城市再进行查询");
        return false;
      }
      let data = JSON.parse(JSON.stringify(this.listQuery1));

      data.isExport = isExport;
      data.city = data.city.join(',');
      this.listLoading = true;

      if (isExport == false) {
        service
          .$axiosGetDYSinglelList(data)
          .then((response) => {
            this.list1 = response.data.data.dataList;
            this.listQuery1.total = response.data.data.total;
            this.listLoading = false;
          })
          .catch(() => {
            this.list1 = [];
            this.listQuery1.total = 0;
            this.listLoading = false;
          });
      }
      else {
        service.$axiosGetDYSingleExport(data);
      }

    },
    querySearch2(isExport) {
      console.info(this.timeArray);
      if (this.listQuery2.month == '' || this.listQuery2.city == '') {
        this.$message.warning("请先选择日期或城市再进行查询");
        return false;
      }
      let data = JSON.parse(JSON.stringify(this.listQuery2));

      data.isExport = isExport;
      data.city = data.city.join(',');
      this.listLoading = true;

      if (isExport == false) {
        service
          .$axiosGetDYCyclelList(data)
          .then((response) => {
            this.list2 = response.data.data.dataList;
            this.listQuery2.total = response.data.data.total;
            this.listLoading = false;
          })
          .catch(() => {
            this.list2 = [];
            this.listQuery2.total = 0;
            this.listLoading = false;
          });
      }
      else {
        service.$axiosGetDYCycleExport(data);
      }

    },
    querySearch3(isExport){

    }
  },
};
</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>
      