<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="{}" />
            </el-form-item>

            <el-form-item label="下单时间">
              <el-date-picker v-model="salesTimeArray" type="datetimerange" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                class="filter-item" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                :picker-options="{}" />
            </el-form-item>
            <el-form-item label="是否分账">
              <el-select v-model="listQuery.isSettle" clearable placeholder="请选择是否分账">
                <el-option label="未分账" value="0"></el-option>
                <el-option label="已分账" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="订单号">
              <el-input v-model="listQuery.orderSn" clearable placeholder="请输入订单号" />
            </el-form-item>
            <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-item>
          </el-form>
        </div>

        <!-- 查询结果 -->
        <el-table :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" label="城市" prop="city" />
          <el-table-column align="center" label="下单渠道" prop="channel" />
          <el-table-column align="center" label="订单号" prop="orderSn" />
          <el-table-column align="center" label="订单状态" prop="orderStatus" />
          <el-table-column align="center" label="作业单号" prop="bookId" />
          <el-table-column align="center" label="服务时间" prop="bookTime" />
          <el-table-column align="center" label="作业单状态" prop="bookStatus" />
          <el-table-column align="center" label="服务商" prop="fraName" />
          <el-table-column align="center" label="经营模式" prop="fraType" />
          <el-table-column align="center" label="服务供应商" prop="provider" />
          <el-table-column align="center" label="带货达人号" prop="talentId" />
          <el-table-column align="center" label="带货达人昵称" prop="commissionUser" />
          <el-table-column align="center" label="实付金额" prop="actualPrice" />
          <el-table-column align="center" label="退款金额" prop="refundAmount" />
          <el-table-column align="center" label="核销状态" prop="verifyStatus" />
          <el-table-column align="center" label="分账状态" prop="sellteStatus" />
          <el-table-column align="center" label="分账金额" prop="settleAmount" />
          <el-table-column align="center" label="手续费" prop="rake" />
          <el-table-column align="center" label="佣金" prop="commission" />
          <el-table-column align="center" label="分账时间" prop="settleTime" />
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
          @pagination="getList(false)" />
      </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: "douyinFiance",
  components: { Pagination },
  data() {
    return {
      listLoading: false,
      timeArray: [
        this.formateDay(new Date(new Date() - 3600 * 1000 * 24 * 7)),
        this.formateDay(new Date()),
      ],
      salesTimeArray: [],
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 50,
        order: "desc",
      },
    };
  },
  computed: {},
  created() {
  },
  methods: {
    getList(isExport) {
      console.info(this.timeArray);
      if ((!this.timeArray || this.timeArray.length == 0) && (!this.salesTimeArray || this.salesTimeArray.length == 0)) {
        this.$message.warning("请至少选择一个日期范围再进行查询");
        return;
      }

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

      if (this.salesTimeArray && this.salesTimeArray.length === 2) {
        this.listQuery.salesStartDate = this.salesTimeArray[0];
        this.listQuery.salesEndDate = this.salesTimeArray[1];
      } else {
        this.listQuery.salesStartDate = null;
        this.listQuery.salesEndDate = null;
      }

      this.listQuery.isExport = isExport;
      this.listLoading = true;

      if (isExport == false) {
        service
          .$axiosGetDYFianceList(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.$axiosGetDYFianceExport(this.listQuery);
      }

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