<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="systemName+'号'" prop="usercode">
        <el-input
            v-model="queryParams.usercode"
            :placeholder="'请输入'+systemName+'号'"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
            v-model="queryParams.mobile"
            placeholder="请输入手机号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="奖品名称" prop="prizeName">
        <el-input
            v-model="queryParams.prizeName"
            placeholder="请输入奖品名称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="自动兑奖" prop="autoGive">
        <el-select v-model="queryParams.autoGive" size="small">
          <el-option
              v-for="dict in prizeAutoGiveList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="giveStatus">
        <el-select v-model="queryParams.giveStatus" size="small">
          <el-option
              v-for="dict in winningRecordGiveStatusList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </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="prizeWinningRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="抽奖时间" align="center" prop="createTime" width="140"/>
      <el-table-column :label="systemName+'号'" align="center" prop="usercode"/>
      <el-table-column label="手机号" align="center" prop="mobile"/>
      <el-table-column label="昵称" align="center" prop="nickname"/>
      <el-table-column label="奖品类型" align="center" prop="prizeType" >
        <template v-slot="scope">
          <cai-dict-tag :options="prizeTypeList" :value="scope.row.prizeType" />
        </template>
      </el-table-column>
      <el-table-column label="奖品名称" align="center" prop="prizeName" />
      <el-table-column label="奖品描述" align="center" prop="prizeDesc" />
      <el-table-column label="奖品图片" align="center" prop="prizeImg" >
        <template v-slot="scope">
          <image-avatar :src="scope.row.prizeImg"/>
        </template>
      </el-table-column>
      <el-table-column label="奖品价值" align="center" prop="prizePrice" />
      <el-table-column label="自动兑奖" align="center" prop="autoGive" >
        <template v-slot="scope">
          <cai-dict-tag :options="prizeAutoGiveList" :value="scope.row.autoGive" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="giveStatus" >
        <template v-slot="scope">
          <cai-dict-tag :options="winningRecordGiveStatusList" :value="scope.row.giveStatus" />
        </template>
      </el-table-column>
      <el-table-column label="兑奖备注" align="center" prop="giveRemark" />
      <el-table-column label="中奖率" align="center" prop="winProbability" />
      <el-table-column label="保底抽数" align="center" prop="guaranteeDraws" />
      <el-table-column label="最低抽数" align="center" prop="minWinDraws" />
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['cai:prizeWinningRecord:edit']"
          >已领奖</el-button>
        </template>
      </el-table-column>
    </el-table>

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

  </div>
</template>

<script>
import {givePrizeWinningRecord, listPrizeWinningRecord} from "@/api/cai/prizeWinningRecord";
import {prizeAutoGiveList, prizeTypeList, winningRecordGiveStatusList} from "@/constant/statusMap";

export default {
  name: "PrizeWinningRecord",
  data() {
    return {
      winningRecordGiveStatusList,prizeTypeList, prizeAutoGiveList,
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 中奖记录表格数据
      prizeWinningRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        usercode: undefined,
        mobile: undefined,
        prizeName: undefined,
        autoGive: undefined,
        giveStatus: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询中奖记录列表 */
    getList() {
      this.loading = true;
      listPrizeWinningRecord(this.queryParams).then(response => {
        this.prizeWinningRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$prompt('可输入的备注', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
      }).then(({ value }) => {
        givePrizeWinningRecord({
          id: row.id,
          giveRemark: value,
        }).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.getList();
        });
      }).catch(() => {});
    },
  }
};
</script>
