<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>
            <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>
          <Button style="margin-left: 10px" type="primary" @click="add">新增</Button>
        </div>
      </slot>
    </lx-header>


    <xy-table :list="list" :table-item="table" :total="total" @pageSizeChange="pageSizeChange" @pageIndexChange="pageChange">
      <template v-slot:btns>
        <el-table-column fixed="right" header-align="center" align="center" label="操作" width="360">
          <template slot-scope="scope">
            <div class="slot-btns">
              <Button type="primary" @click="edit(scope.row)">编辑</Button>
              <Button type="primary" @click="config(scope.row)" style="margin-left: 10px;">配置</Button>
              <Button type="primary" @click="white(scope.row)" style="margin-left: 10px;">白名单</Button>
              <Button type="error" @click="deleteitem(scope.row)" style="margin-left: 10px;">删除</Button>
            </div>
          </template>
        </el-table-column>
      </template>
    </xy-table>

    <addActivity ref="addActivity" @refresh="load()"></addActivity>
    <addActivityConfig ref="addActivityConfig" @refresh="load()"></addActivityConfig>
    <addActivityWhite ref="addActivityWhite" @refresh="load()"></addActivityWhite>


  </div>
</template>

<script>
  import {
    index,
    save,
    destroy,
    show
  } from "@/api/activity/index";

  import addActivity from '@/views/activity/components/addActivity'
  import addActivityConfig from '@/views/activity/components/addActivityConfig'
  import addActivityWhite from '@/views/activity/components/addWhite'

  export default {
    components: {
      addActivity,
      addActivityConfig,
      addActivityWhite
    },
    data() {
      return {
        select: {
          page: 1,
          page_size: 20,
          keyword: '',
        },
        total: 0,
        list: [],
        table: [{
            prop: 'name',
            label: '项目名称',
            align: 'left',
            width: 280,
            fixed: 'left',

          },{
            prop: 'domain',
            label: '访问地址',
            align: 'left',
            width: 280,
            fixed: 'left',

          }, {
            prop: 'tag',
            label: '项目标识',
            align: 'left',
            width: 120,
            fixed: 'left',

          }, {
            prop: 'start_time',
            label: '项目开始时间',
            width: 180,
            align: 'center'

          }, {
            prop: 'end_time',
            label: '项目结束时间',
            width: 180,
            align: 'center'
          },
          {
            prop: 'appid',
            label: '公众号的APPID',
            align: 'center',
            width: 180,
          }, , {
            prop: 'mch_id',
            label: '微信商户的ID',
            align: 'center',
            width: 180,
          },
          {
            prop: 'created_at',
            label: '创建信息',
            width: 180,
            formatter: (v1, v2, value) => {
              return value;
            }
          }
        ],
      }
    },
    methods: {
      doSearch() {
        this.select.page = 1;
        this.load();
      },
      add() {
        this.$refs['addActivity'].isShow = true
      },
      pageSizeChange(e) {
        this.select.page_size = e;
        this.select.page = 1;
        this.load();
      },
      async load() {
        const res = await index(this.select)
        this.total = res.total
        this.list = res.data
      },
      deleteitem(row) {
        destroy({
          id: row.id
        }).then(res => {
          this.load();
          this.$Message.success("操作成功");
        })
      },
      edit(row) {
        this.$refs['addActivity'].id = row.id;
        this.$refs['addActivity'].isShow = true;
        this.$refs['addActivity'].type = 'editor'
      },
      config(row){
        this.$refs['addActivityConfig'].id = row.id;
        this.$refs['addActivityConfig'].isShow = true;
        this.$refs['addActivityConfig'].type = 'editor'
      },
      white(row){
        this.$refs['addActivityWhite'].id = row.id;
        this.$refs['addActivityWhite'].isShow = true;
        this.$refs['addActivityWhite'].type = 'editor'
      },
      pageChange(e) {
        this.select.page = e
        this.load()
      },
    },
    mounted() {
      this.load()
    },
    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>
