<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item :label="'会员编号'" prop="memberCode">
              <el-input clearable v-model="queryParams.memberCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'" prop="memberName">
              <el-input clearable v-model="queryParams.memberName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'联系方式'" prop="phone">
              <el-input clearable v-model="queryParams.phone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'奖品名称'" prop="giftName">
              <el-input clearable v-model="queryParams.giftName"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item :label="'活动名称'" prop="actName">
              <el-input clearable v-model="queryParams.actName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'获奖日期'" prop="teamCode">
              <el-date-picker
                v-model="queryParams.theDate"
                @change="changeTime"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
                
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="getSearch"> {{ '搜索' }}</el-button>
              <el-button class="my_reset" @click="reChongzhi"> {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="mini" class="thebtn1" 
          v-hasButtons="['winExport']"
          @click="handleExport"
            > {{ '导出' }}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="680px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column prop="colsele" type="selection" width="55">
          </el-table-column>

          <el-table-column :label="'奖品图片'" align="center" prop="gradeName" :placeholder="'赠送类型'">
            <template slot-scope="scope">
              <img
                style="width: 44px; height: 44px; border-radius: 8px"
                :src="scope.row.giftCover"
                alt=""
              />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="giftName" :label="'奖品名称'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="productName"
            :label="'产品名称(规格)'"
          >
          </el-table-column>
          <el-table-column align="center" prop="quantity" :label="'产品数量'">
          </el-table-column>
          <el-table-column align="center" prop="memberCode" :label="'会员编号'">
          </el-table-column>
          <el-table-column align="center" prop="memberName" :label="'会员姓名'">
          </el-table-column>

          <el-table-column align="center" prop="phone" :label="'联系方式'">
          </el-table-column>

          <el-table-column align="center" prop="giftNumber" :label="'获奖数量'">
          </el-table-column>
          <el-table-column
            min-width="120px"
            align="center"
            prop="actName"
            :label="'活动名称'"
          >
          </el-table-column>
          <el-table-column
            min-width="120px"
            align="center"
            prop="creationTime"
            :label="'获奖日期'"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as gif from "@/api/newgift";
export default {
  name: "WinningRecordList",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "winningRecordList",
      topList: [
        {
          name: '中奖记录',
          path: "winningRecordList",
        },
      ],
      tableData: [],
      loading:false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        theDate: [],
      },

      total: 0,
      multipleSelection: [],
    };
  },
  created() {
    this.getSearch();
  },
  methods: {
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        this.download(
          "/activity/manage/draw/export-record",
          {
            ...this.queryParams,
          },
          `${'中奖记录'}_${new Date().getTime()}.xlsx`
        );
      });
    },

    changeTime(val) {
      this.queryParams.startDate = val[0];
      this.queryParams.endDate = val[1];
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        theDate: [],
      };
      this.getSearch();
    },
    getSearch() {
      this.loading = true
      gif.getActiveDrawDetailList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false
      });
    },
  },
};
</script>

  <style lang="scss" scoped>
::v-deep .dizhi .el-cascader {
  width: 100%;
}
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #f3a900;
          border-radius: 4px 4px 4px 4px;
        }
        .thebtn2 {
          color: #ffffff;
          border-radius: 4px 4px 4px 4px;
          background: #48b2fd;
          height: 32px;
        }
      }
    }
  }
}
</style>
