<style scoped lang="scss">
::v-deep a {
  color: #409eff;
  display: block;
}
</style>
<template>
  <div class="app-container">
    <div></div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="商品名称" prop="itemTitle">
        {{ $route.query ? $route.query.name : "-" }}
      </el-form-item>
      <el-form-item label="商品Id" prop="itemId">
        {{ $route.query ? $route.query.id : "-" }}
      </el-form-item>
      <br />
      <el-form-item label="达人名称" prop="promoterNickName">
        <el-input
          v-model="queryParams.promoterNickName"
          placeholder="请输入达人名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="达人Id" prop="promoterId">
        <el-input
          v-model.number="queryParams.promoterId"
          placeholder="请输入达人Id"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          :loading="downLoadLoading"
          >导出</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="typeList"
      @selection-change="handleSelectionChange"
      ref="multipleTable"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->

      <el-table-column label="达人名称" align="center" prop="promoterNickName">
        <template slot-scope="scope">
          <a @click="toIndexDetail(scope.row)">
            {{ scope.row.promoterNickName }}
          </a>
        </template>
      </el-table-column>
      <el-table-column label="达人Id" align="center" prop="promoterId" />
      <el-table-column label="订单数" align="center" prop="orderNum"> </el-table-column>
      <el-table-column label="有效订单数" align="center" prop="validOrderNUm" />
      <el-table-column label="有效率" align="center" prop="validRadio">
        <template slot-scope="scope">
          {{ scope.row.validRadio  }}
        </template>
      </el-table-column>
      <el-table-column label="付款金额" align="center" prop="payAmount">
        <template slot-scope="scope">
          {{ allMoney(scope.row.payAmount / 100) }}
        </template>
      </el-table-column>
      <el-table-column label="服务费率" align="center" prop="regimentalPromotionRate">
        <template slot-scope="scope">
          {{ scope.row.regimentalPromotionRate }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getItemDetail"
    />
  </div>
</template>

<script>
import {
  listType,
  getType,
  delType,
  addType,
  updateType,
  refreshCache,
} from "@/api/system/dict/type";
import { getOrderList, getItemDetail, downFile } from "@/api/bytedance/bytedance";
var echarts = require("echarts");
export default {
  name: "sale",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      downLoadLoading: false,
      dialogTableVisible: false,
      logPage: {
        pageNum: 1,
        pageSize: 10,
      },
      logData: [],
      logTotal: 0,
      logLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 分配销售
      openAllocation: false,
      // 选择的销售id
      saleId: undefined,
      // 获取用户id
      userId: undefined,
      // 销售列表
      saleList: [],
      // 分配销售确定loading
      confirmLoadingSale: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        promoterId: undefined,
        promoterNickName: undefined,
        orderStartDate: undefined,
        orderEndDate: undefined,
      },
      uploadDate: [new Date(), new Date()],
      //查询参数所用下拉数据
      queryParamsList: {},
    };
  },
  created() {
    if (
      this.$route &&
      this.$route.query.id &&
      this.$route.query.orderStartDate &&
      this.$route.query.orderEndDate
    ) {
      this.getItemDetail();
    }
  },
  mounted() {
    this.$nextTick(() => {
      //   this.getList();
      //   this.initEchart('echart', this.handlerEchartOption(res.result, 'cost'))
    });
  },
  methods: {
    /** 导出按钮操作 */
    handleExport() {
      this.downLoadLoading = true;
      downFile("/bytedance/order/exportBytedanceItemDetail", {
        ...this.queryParams,
        orderStartDate: this.$route.query.orderStartDate,
        orderEndDate: this.$route.query.orderEndDate,
        itemId: this.$route.query.id,
      }).then((res) => {
        let blob = new Blob([res], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        });
        let downloadElement = document.createElement("a");
        let href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = `商品_${this.$route.query.name}${this.$route.query.orderStartDate}-${this.$route.query.orderEndDate}详情.xlsx`; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
        this.downLoadLoading = false;
      });
    },
    toDetail(id) {},
    toIndexDetail(item) {
      this.$router.replace({
        path: "/supplyChain/bytedance/bytedancePromoterDetail",
        query: {
          id: item.promoterId,
          name: item.promoterNickName,
          orderStartDate: this.$route.query.orderStartDate,
          orderEndDate: this.$route.query.orderEndDate,
        },
      });
    },
    getItemDetail() {
      this.loading = true;
      getItemDetail({
        ...this.queryParams,
        orderStartDate: this.$route.query.orderStartDate,
        orderEndDate: this.$route.query.orderEndDate,
        itemId: this.$route.query.id,
      }).then((response) => {
        this.typeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      getOrderList(
        this.addDateRange(
          this.queryParams,
          this.uploadDate,
          "orderStartDate",
          "orderEndDate"
        )
      ).then((response) => {
        this.typeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.confirmLoading = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.dateFile = null;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getItemDetail();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      //   let date = new Date();
      //   let y = date.getFullYear();
      //   let MM = date.getMonth() + 1;
      //   MM = MM < 10 ? "0" + MM : MM;
      //   let dd = date.getDate();
      //   dd = dd < 10 ? "0" + dd : dd;
      //   this.uploadDate = [`${y}-${MM}-${dd}`, `${y}-${MM}-${dd}`];
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
    },
  },
};
</script>
