<template>
  <div>
    <lx-header icon="md-apps" style="margin-bottom: 10px; border: 0px; margin-top: 15px" text="项目抽奖日志">
      <div slot="content"></div>
      <slot>
        <div class="selects">
          <div style="display: flex;align-items: center;">
            <span style="padding: 0 6px;word-break: keep-all;">
              项目
            </span>
            <Select v-model="select.activity_list_id" style="width: 180px;">
              <Option v-for="(item,index) of listActivity" :key="item.id" :value="item.id" :label="item.name">
              </Option>
            </Select>
          </div>
          <div>
            <span style="padding: 0 6px;word-break: keep-all;">
              关键字
            </span>
            <Input v-model="select.keyword" placeholder="请输入关键字" style="width: 180px"></Input>
          </div>

          <Button style="margin-left: 10px" type="primary" @click="select={page:1,keyword:''}">重置
          </Button>
          <Button style="margin-left: 10px" type="primary" @click="doSearch">查询</Button>
        </div>
      </slot>
    </lx-header>


    <xy-table :list="list" :table-item="table" :total="total" @delete="deleteitem">
      <template v-slot:btns v-if="type==0">

      </template>
    </xy-table>
  </div>
</template>

<script>
  import {
    drawLog,
    destroyDrawLog
  } from "@/api/activity/drawPrize";
  import {
    index as activityIndex
  } from "@/api/activity/index";

  export default {
    data() {
      return {
        select: {
          page: 1,
          page_size: 20,
          keyword: '',
          activity_list_id: ""
        },
        listActivity: [],
        total: 0,
        list: [],
        table: [{
            prop: 'activity_list.name',
            label: '项目名称',
            fixed: 'left',
            align: 'left'
          }, {
            prop: 'user.name',
            label: '用户名称',
            align: 'left',
          }, {
            prop: 'user.username',
            label: '登录名',
            align: 'center'
          }, {
            prop: 'draw_prize.name',
            label: '中奖信息',
            align: 'center'
          },

          {
            prop: 'created_at',
            label: '抽奖时间',
            width: 190,
            formatter: (v1, v2, value) => {
              return this.$moment(value).format("YYYY-MM-DD HH:mm:ss");
            }
          }
        ],
      }
    },
    methods: {

      async loadActivity() {
        const res = await activityIndex({
          page: 1,
          page_size: 999
        })
        this.listActivity = res.data;
      },
      doSearch() {
        this.select.page = 1;
        this.load();
      },
      add() {
        this.$refs['addActivityUser'].isShow = true
      },
      pageSizeChange(e) {
        this.select.page_size = e;
        this.select.page = 1;
        this.load();
      },
      async load() {
        const res = await drawLog(this.select)
        this.total = res.total
        this.list = res.data
      },
      deleteitem(row) {
        destroyDrawLog({
          id: row.id
        }).then(res => {
          this.load();
          this.$Message.success("操作成功");
        })
      },
      pageChange(e) {
        this.select.page = e
        this.load()
      },
    },
    mounted() {
      this.load();
      this.loadActivity()
    },
    created() {
      let type = parseInt(this.$route.path.split("_")[1]);
      this.type = this.select.is_auth = type;
    }
  }
</script>

<style lang="scss" scoped>
  .selects {
    display: flex;
    flex-wrap: wrap;

    &>div {
      margin-bottom: 6px;
    }
  }
</style>
