<template>
  <div>
    <div ref="lxHeader">
      <lx-header icon="md-apps" text="防汛计划" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
        <slot>
          <div style="display: flex;justify-content: flex-start;flex-wrap: wrap;">
            <!-- <Input v-model="select.keyword" style="width: 200px;margin-right: 10px;" placeholder="经办人搜索" /> -->
            <Button type="primary" @click="getList">查询</Button>
            <Button type="primary" style="margin-left: 10px;" @click="$refs['addPlan'].type='add',$refs['addPlan'].isShow=true">添加</Button>
            <!-- <Button icon="ios-add" type="primary" style="margin-left: 10px;"
              @click="$refs['imports'].show()">导入</Button> -->

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

    <xy-table :list="list" :total="total" @pageSizeChange="pageSizeChange" @pageIndexChange="pageChange"
      :table-item="table">
      <template v-slot:btns>
        <el-table-column fixed="right" label="操作" width="260" header-align="center">
          <template slot-scope="scope">
            <div>
              <Button type="primary" size="small"
              @click="$refs['addPlan'].type='editor',
              $refs['addPlan'].id=scope.row.id,
              $refs['addPlan'].isShow=true">编辑</Button>
              <Button type="primary" size="small"
              @click="$refs['addTeam'].type='editor',
              $refs['addTeam'].id=scope.row.id,
              $refs['addTeam'].isShow=true">小组</Button>
              <Poptip transfer confirm title="确认要删除吗？" @on-ok="delRow(scope.row.id)">
                <Button type="primary" style="margin-left: 10px;" size="small" ghost>删除</Button>
              </Poptip>
            </div>
          </template>
        </el-table-column>
      </template>

    </xy-table>
      <addPlan ref="addPlan" @refresh="getList"></addPlan>
      <addTeam ref="addTeam"></addTeam>
  </div>

</template>

<script>
  import {
    index,
    destroy
  } from "@/api/system/baseForm.js"
  import addPlan from './components/addPlan.vue'
  import addTeam from './components/addTeam.vue'
  export default {
    components:{
      addPlan,
      addTeam
    },
    data() {
      return {
        select: {
          page: 1,
          page_size: 10,
          keyword: '',
          table_name:'flood_checks'
        },
        total: 0,
        list: [],
        table: [{
          label: '序号',
          type: 'index',
          fixed: 'left',
          width: 80,
        },{
          label: '年份',
          prop: 'nianfen',
          width: 120,
        },{
          label: '检查类型',
          prop: 'jianchaleixing'
        },{
          label: '开始日期',
          prop: 'kaishiriqi',
          width: 120,
        },{
          label: '结束日期',
          prop: 'jieshuriqi',
          width: 120,
        },{
          label: '创建人',
          prop: 'admin.name',
          width: 120,
        },{
          label: '创建日期',
          prop: 'created_at',
          width: 120,
          formatter:(cell,data,value)=>{
            return value?value.substring(0,10):''
          }
        }],
      }
    },
    created() {
      this.getList()
    },
    methods: {
      async getList() {
        const res = await index({
          ...this.select,
          filter: [],
        })
        this.list = res.data
        console.log("this.list",this.list)
        this.total = res.total
      },
      pageChange(e) {
        this.select.page = e
        this.getList()
      },
      pageSizeChange(e){
        this.select.page_size = e
        this.getList()
      },
      delRow(id){
        if(id){
          destroy({
            id: id,
            table_name: this.select.table_name,
          }).then(res => {
            this.$message({
              type: 'success',
              message: '删除成功'
            })
            this.getList()
          })
        }
      },
    }
  }
</script>

<style>
</style>
