<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="达人名称" prop="promoterName">
        <el-input
          placeholder="请输入达人名称"
          style="width: 240px"
          v-model="queryParams.promoterName"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="达人ID" prop="promoterId">
        <el-input
          placeholder="请输入达人ID"
          style="width: 240px"
          v-model="queryParams.promoterId"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="选择日期">
        <el-date-picker
          v-model="uploadDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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="primary"
          plain
          size="mini"
          @click="handleExport"
          style="margin-bottom: 15px"
        >导出
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="typeList" ref="multipleTable">

      <el-table-column
        label="达人信息"
        align="center"
        prop="itemTitle"
        width="300"
      >
        <template slot-scope="scope">
          <div style="display: flex; width: 100%">
            <div style="width: 40%">
              <img
                :src="scope.row.headImg"
                alt=""
                style="width: 70px; height: auto"
              />
            </div>
            <div style="width: 60%" class="item-name-calss">
              <p>
                {{ scope.row.clipName }}
              </p>
              <p>达人Id： {{ scope.row.clipId }}</p>
              <p>佣金率： {{ scope.row.commissionRateView }}</p>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="粉丝数" align="center" prop="fansNum"></el-table-column>
      <!-- <el-table-column label="创作者GMV" align="center" prop="gmv30d"></el-table-column>-->
      <el-table-column label="状态" align="center" prop="status"></el-table-column>
      <el-table-column label="口碑评分" align="center" prop="shopScore"></el-table-column>
      <el-table-column label="二创GMV" align="center" prop="clipGmv30d"></el-table-column>
      <el-table-column label="授权商品GMV" align="center" prop="authItemGmv30d"></el-table-column>
      <el-table-column label="二创作者挂车短视频发布量" align="center" prop="videoCount"></el-table-column>
      <el-table-column label="二创作者挂车短视频曝光量" align="center" prop="videoShow"></el-table-column>
      <el-table-column label="状态备注" align="center" prop="terminationReason"></el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :pageSizes="[10, 20, 30, 50]"
    />


  </div>
</template>

<script>
  import {refreshCache} from "@/api/system/dict/type";
  import {getClipCooperation, downFile} from "@/api/jiaoyang/report";

  export default {
    name: "JyClipCooperation",
    dicts: ["sys_normal_disable"],
    components: {},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: null,
        okIds: null,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 字典表格数据
        typeList: [],
        //上传文件类型
        fileType: [".doc", ".xls", ".xlsx", ".ppt", ".pdf", ".csv"],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openFp: false,
        formFp: {},
        // 是否可编辑
        edit: false,
        // 分配销售
        openAllocation: false,
        // 选择的销售id
        saleId: undefined,
        // 销售列表
        saleList: [],
        // 分配销售确定loading
        confirmLoadingSale: false,
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          promoterId: undefined,
          promoterName: undefined,
        },
        uploadDate: new Date(),
        //页面所有的下拉数据
        queryParamsList: {},
        // 表单参数
        form: {},
        formBroadcast: {
          ruleDetails: [],
        },
        //上传报表下拉数据
        formList: {},
        fileList: [],
        accept: "",
        //获取销售线索文件流
        dateFile: new FormData(),
        //销售线索上传loading
        confirmLoading: false,
        // 表单校验
        // 分配销售展示列表
        ksInfo: null,
        userId: null,
      };
    },
    created() {
      this.userId = this.$store.getters.userId;
      let start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
      let date = new Date(start);
      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}`;

      this.getList();
    },
    filters: {},
    methods: {

      /** 导出按钮操作 */
      handleExport() {
        this.downLoadLoading = true;
        downFile("/jy/report/exportClipCooperation",
          this.addDateRange(
            {statDate: this.uploadDate},
            this.queryParams
          )
        ).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.uploadDate[0]}-${this.uploadDate[1]}.xlsx`; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
          this.downLoadLoading = false;
        });
      },

      /** 查询字典类型列表 */
      getList() {
        this.loading = true;
        this.typeList = [];
        getClipCooperation({statDate: this.uploadDate, ...this.queryParams})
          .then((response) => {
            this.loading = false;
            this.typeList = response.rows;
            this.total = response.total;
          })
          .catch((err) => {
            console.log(err);
          });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.confirmLoading = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {};
        this.dateFile = null;
        this.resetForm("formBroadcast");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        let start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
        let date = new Date(start);
        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}`;
        this.resetForm("queryForm");
        this.handleQuery();
      },

      addNew() {
        this.openAllocation = true;
        this.edit = false;
        this.ids = null;
        this.confirmLoading = false;
        this.formBroadcast = {};
        setTimeout(() => {
          this.$refs.formBroadcast.clearValidate();
        }, 0);
        this.$set(this.formBroadcast, "ruleDetails", []);
      },
      /** 编辑地址 新增达人*/
      handleAddbroadcast(item) {
        this.ids = item.id;
        this.edit = true;
        this.openAllocation = true;
        this.$set(this.formBroadcast, "consignee", item.consignee);
        this.$set(this.formBroadcast, "phone", item.phone);
        this.$set(this.formBroadcast, "promoterAddress", item.promoterAddress);
        this.$set(this.formBroadcast, "ruleName", item.ruleName);
        this.$set(this.formBroadcast, "promoterId", item.promoterId);
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
      },
      /** 新增直播确定按钮 */

    },
  };
</script>
<style lang="scss" scoped>
  .entire-line {
    width: 100%;
  }

  ::v-deep .entire-line .el-form-item__content {
    width: 60%;
  }

  ::v-deep .el-form-item__label {
    white-space: nowrap;
  }
</style>
<style scoped lang="scss">
  ::v-deep a {
    color: #409eff;
    display: block;
    text-align: left;
  }

  .item-name-calss p {
    margin: 0;
    text-align: left;
  }

  .tableBox {
    width: 100%;
  }
</style>
