<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="clipId">
        <el-select
          filterable
          v-model="queryParams.promoterId"
          placeholder="选择行业"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in queryParamsList.clipUserIds"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </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-form-item>
    </el-form>

    <el-table v-loading="loading" :data="typeList" ref="multipleTable"    @sort-change="sortChange">


      <el-table-column
        label="商品信息"
        align="center"
        prop="itemName"
        width="350"
      >
        <template slot-scope="scope">
          <div style="display: flex; width: 100%">
            <div style="width: 40%">
              <img
                :src="scope.row.itemImgUrl"
                alt=""
                style="width: 70px; height: auto"
              />
              <img
                v-if="scope.row.isNew == 1 "
                src="./new.jpg"
                alt=""
                style="
                  width: 70px;
                  height: auto;
                  position: absolute;
                  left: 40px;
                  top: 10px;
                "
              />
            </div>
            <div style="width: 60%" class="item-name-calss">
              <p>商品Id： {{ scope.row.itemId }}</p>
              <p>售价： {{ scope.row.itemPrice }}</p>
              <p>
                名称：{{ scope.row.itemName }}
              </p>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column width="150" label="团长信息" align="center" prop="clipName" ></el-table-column>
      <el-table-column label="出单达人数" align="center" prop="promotionPromoterCount" sortable="custom"> </el-table-column>
      <el-table-column label="今日出单数" align="center" prop="promotionVolume"  sortable="custom"></el-table-column>
      <el-table-column label="昨日出单数" align="center" prop="yesPromotionVolume"  sortable="custom"></el-table-column>
      <el-table-column label="出单增量" align="center" prop="difference"  sortable="custom"></el-table-column>
      <el-table-column label="涨幅" align="center" prop="increaseInPrice"  sortable="custom">
        <template slot-scope="scope">
          {{ scope.row.increaseInPrice ? scope.row.increaseInPrice + "%" : "-" }}
        </template>
      </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,100,200]"
    />
  </div>
</template>

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

  export default {
    name: "JyTopItem",
    dicts: ["sys_normal_disable"],

    components: {},
    data() {
      return {
        prop: "difference",
        sort: "desc",
        // 遮罩层
        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,
        },
        uploadDate: new Date(),
        //页面所有的下拉数据
        queryParamsList: {
          clipUserIds: []
        },
        // 表单参数
        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();
      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();
      this.getClipIds();
    },
    filters: {},
    methods: {
      getClipIds() {
        getItemClipIds().then((res) => {
          this.queryParamsList.clipUserIds = res.map((item) => {
            return {
              label: item.name,
              value: item.id,
            };
          });
        });
      },
      /** 导出按钮操作 */
      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;
        });
      },
      sortChange(col, prop, order) {
        this.prop = col.prop;
        this.sort = !!col.order
          ? col.order == "descending"
            ? "desc"
            : "asc"
          : "desc";
        this.handleQuery();
      },
      /** 查询字典类型列表 */
      getList() {
        this.loading = true;
        this.typeList = [];
        getTopItem({statDate: this.uploadDate,fieId: this.prop, sort: this.sort, ...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();
        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.queryParams.promoterId = undefined;
        this.prop = 'difference';
        this.sort = 'desc';
        this.handleQuery();
      },


      /** 修改按钮操作 */
      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>
