<template>
  <div>

    <div>
      <div ref="lxHeader">
        <lx-header icon="md-apps" :text="$route.meta.title" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content">
            <div class="searchwrap" style="display: flex;align-items: center;">
              <div>
                <el-input v-model="select.username" placeholder="请输入姓名"></el-input>
              </div>
              <div>
                <el-select v-model="select.course" placeholder="请选择就读班级" clearable>
                  <el-option v-for="(item,index) in course_options" :key="index" :label="item.value" :value="item.value">
                  </el-option>
                </el-select>
              </div>
              <div>
                <el-button type="primary" size="small" @click="select.page=1,getList()">查询</el-button>
              </div>
              <div>
                <el-button type="primary" size="small" @click="editNotice('add')">新增</el-button>
              </div>
            </div>
          </div>

        </lx-header>
      </div>
    </div>

    <div>
      <xy-table :list="list" :total="total" @pageIndexChange="pageIndexChange" @pageSizeChange="pageSizeChange"
        :table-item="table_item">
        <template v-slot:btns>
          <el-table-column align='center' fixed="right" label="操作" width="180" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="editNotice('editor',scope.row.id)">编辑</el-button>
              <el-popconfirm style="margin:0 10px" @confirm="deleteList(scope.row.id)" title="确定删除吗？">
                <el-button type="danger" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

    <add-donate ref="addDonate" @refresh="getList"></add-donate>
  </div>
</template>

<script>
  import addDonate from './components/addDonate.vue';
  import {
    index,
    destroy
  } from "@/api/system/baseForm.js"
  export default {
    components: {
      addDonate
    },
    data() {
      return {
        select: {
          username:'',
          course:'',
          table_name: 'donates',
          page: 1,
          page_size: 10
        },
        course_options:[{
        	label: '高研班｜第一期高级科创人才研修班',
        	value: '高研班｜第一期高级科创人才研修班'
        }, {
        	label: '高研班｜第二期高级科创人才研修班',
        	value: '高研班｜第二期高级科创人才研修班'
        },{
        	label: '高研班｜第三期高级科创人才研修班',
        	value: '高研班｜第三期高级科创人才研修班'
        }, {
        	label: '高研班｜第四期高级科创人才研修班',
        	value: '高研班｜第四期高级科创人才研修班'
        },{
        	label: '高研班｜第五期高级科创人才研修班',
        	value: '高研班｜第五期高级科创人才研修班'
        }, {
        	label: '高研班｜第六期高级科创人才研修班',
        	value: '高研班｜第六期高级科创人才研修班'
        }, {
        	label: '其他',
        	value: '其他'
        }],
        list: [],
        total: 0,
        table_item: [{
          prop: 'username',
          label: '姓名',
          align: 'left',
          width: 160,
        }, {
          prop: 'course',
          label: '就读班级',
          align: 'left',
          // width:240
        }, {
          prop: 'mobile',
          label: '联系方式',
          align: 'center',
          width: 160,
        }, {
          prop: 'company_name',
          label: '公司名称',
          align: 'left',
          width: 240,
        }, {
          prop: 'company_position',
          label: '职务',
          align: 'center',
          width: 160,
        }, {
          prop: 'donate',
          label: '我希望捐赠',
          align: 'center',
          width: 240,
        }]

      }
    },
    created() {
      this.getList()
    },
    methods: {
      pageIndexChange(e) {
        this.select.page = e
        this.getList()
      },
      pageSizeChange(e) {
        this.select.page_size = e
        this.select.page = 1
        this.getList()
      },
      editNotice(type, id) {
        if (type == 'editor') {
          this.$refs.addDonate.id = id
        }
        this.$refs.addDonate.type = type
        this.$refs.addDonate.isShow = true
      },
      async getList() {
        const res = await index({
          page_size: this.select.page_size,
          page: this.select.page,
          table_name: this.select.table_name,
          filter:[{
            key:'username',
            op:'like',
            value:this.select.username
          },{
            key:'course',
            op:'like',
            value:this.select.course
          }]
        })
        this.list = res.data
        this.total = res.total
      },
      deleteList(id) {
        var that = this;
        destroy({
          id: id,
          table_name: this.select.table_name
        }).then(response => {
          this.$Message.success('操作成功');
          this.getList()
        }).catch(error => {
          console.log(error)
          reject(error)
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .searchwrap {
    display: flex;
    align-items: center;

    &>div {
      display: flex;
      align-items: center;
      margin-right: 10px;

      span {
        min-width: 70px;
      }
    }
  }
</style>
