<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['addFlood'].type='add',
            $refs['addFlood'].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['addFlood'].type='editor',
              $refs['addFlood'].id=scope.row.id,
              $refs['addFlood'].isShow=true">编辑</Button>
              <template v-for="(item,key) of statusLabel">
                <span v-if="key===scope.row.zhuangtai">
                  <Button type="primary" size="small" style="margin-left: 10px;"
                  @click="$refs['showFlood'].type=item['type'],
                  $refs['showFlood'].id=scope.row.id,
                  $refs['showFlood'].isShow=true">{{item['name']}}</Button>
                </span>
              </template>
              <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>
      <addFlood ref="addFlood" @refresh="getList"></addFlood>
      <showFlood ref="showFlood" @refresh="getList"></showFlood>
  </div>

</template>

<script>
  import {
    index,
    destroy
  } from "@/api/system/baseForm.js"
  import addFlood from './components/addFlood.vue'
  import showFlood from './components/showFlood.vue'
  export default {
    components:{
      addFlood,
      showFlood
    },
    data() {
      //  待确认check  无需整改end  待整改need  已整改complete 重新整改need 已完成end

      return {
        select: {
          page: 1,
          page_size: 10,
          keyword: '',
          table_name:'flood_infos'
        },
        total: 0,
        list: [],
        statusLabel:{
          "待确认":{
            type:"check",
            name:'确认'
          },
          "无需整改":{
            type:"end",
            name:'查看'
          },
           "待整改":{
             type:"need",
             name:'提交'
           },
           "已整改":{
             type:"complete",
             name:'审核'
           },
           "重新整改":{
             type:'need',
             name:'提交'
           },
           "已完成":{
             type:"end",
             name:'查看'
           }
        },
        table: [{
          label: '序号',
          type: 'index',
          fixed: 'left',
          width: 80,
        },{
          label: '状态',
          prop: 'zhuangtai',
          width: 120,
        },{
          label: '问题类型',
          prop: 'wentileixing'
        },{
          label: '检查日期',
          prop: 'jianchariqi',
          width: 120,
        },{
          label: '上报人',
          prop: 'shangbaoren',
          width: 120,
        },{
          label: '建议整改科室',
          prop: 'jianyizhenggaikeshi',
          width: 120,
        },{
          label: '检查地点',
          prop: 'jianchadidian',
          width: 120,
        },{
          label: '问题照片',
          prop: 'wentizhaopian',
          width: 120,
        },{
          label: '整改建议',
          prop: 'wentimiaoshu',
          width: 120,
        },{
          label: '问题描述',
          prop: 'zhenggaijianyi',
          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
        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>
