<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="listQuery.timeRange" type="daterange" value-format="yyyy-MM-dd"
                              class="filter-item"
                              range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                              :picker-options="pickerOptions"/>
            </el-form-item>
            <el-form-item label="加盟商名称">
              <el-input v-model="listQuery.fraName" clearable placeholder="请输入加盟商名称"></el-input>
            </el-form-item>
            <el-form-item label="服务城市">
              <el-select v-model="listQuery.cityName" clearable placeholder="请输入城市名" filterable>
                <el-option v-for="item in cityList" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getList(false)">查找</el-button>
            <el-button :loading="listLoading" class="filter-item" type="primary" icon="el-icon-download"
                       @click="getList(true)">导出
            </el-button>
          </el-form>
        </div>
      </el-tab-pane>
    </el-tabs>

    <el-table :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>
      <el-table-column align="center" label="加盟商名称" prop="fraName"></el-table-column>
      <el-table-column align="center" label="城市名" prop="city"></el-table-column>
      <el-table-column align="center" label="分配类型" prop="assignType"></el-table-column>
      <el-table-column align="center" label="该分配类型下分配量" prop="num"></el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize"
                @pagination="getList(false)"/>
  </div>
</template>
<script>

import Pagination from "./../common/Pagination";
import service from "../../script/api/service";

export default {
  name: "douyinOrderAssign",
  components: {
    Pagination
  },
  data() {
    return {
      listLoading: false,
      cityList: [],
      total: 0,
      listQuery: {
        fraName: "",
        pageNo: 1,
        pageSize: 50,
        cityName: "",
        isExport: false,
        startDay: "",
        endDay: "",
        timeRange: [],
      },
      list: [],
      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]);
            },
          },
        ],
      },
    }
  },
  created() {
    let citys = JSON.parse(window.localStorage.getItem("allCity"));
    citys.forEach(item => {
      this.cityList.push(item.cityName);
    })
  },
  methods: {
    getList(isExport) {
      if (!this.listQuery.timeRange || this.listQuery.timeRange.length == 0) {
        this.$message.warning("请选择分配时间");
        return;
      }
      this.listQuery.startDay = this.listQuery.timeRange[0];
      this.listQuery.endDay = this.listQuery.timeRange[1];

      if (!isExport) {
        service.$axiosGetAssignList(this.listQuery).then(res => {
          if (res.data.errno === 0) {
            this.list = res.data.data.list;
            this.total = res.data.data.total;
          } else {
            this.list = [];
            this.total = 0;
          }
        }).catch(() => {
          this.list = [];
          this.total = 0;
        });
      } else {
        this.listQuery.isExport = true;
        service.$axiosGetAssignListExport(this.listQuery);
      }
    }

  }
}


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