<template>
  <ai-list class="list">
    <ai-title slot="title" title="健康上报" isShowBottomBorder></ai-title>
    <template slot="content">
      <div class="content">
        <ai-search-bar bottomBorder>
          <template #right>
            <el-input
              v-model="search.name"
              size="small"
              placeholder="请输入姓名"
              clearable
              v-throttle="() => {search.current = 1, getList()}"
              @clear="search.current = 1, search.name = '', getList()"
              suffix-icon="iconfont iconSearch">
            </el-input>
          </template>
        </ai-search-bar>
        <ai-table
          :tableData="tableData"
          :col-configs="colConfigs"
          :total="total"
          v-loading="loading"
          style="margin-top: 16px;"
          :current.sync="search.current"
          :size.sync="search.size"
          @getList="getList">
          <el-table-column slot="options" width="140px" fixed="right" label="操作" align="center">
            <template slot-scope="{ row }">
              <div class="table-options">
                <el-button type="text" @click="toDetail(row.id)">详情</el-button>
                <el-button type="text" @click="remove(row.id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </ai-table>
      </div>
    </template>
  </ai-list>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name: 'List',

    props: {
      instance: Function,
      dict: Object
    },

    data () {
      return {
        search: {
          current: 1,
          size: 10,
          name: ''
        },
        colConfigs: [
          { prop: 'id', label: '员工姓名', openType: 'userName' },
          { prop: 'girdNames', align: 'center', label: '网格' },
          { prop: 'clockCount', align: 'center', label: '打卡次数' },
          { prop: 'lastReportTime', align: 'center', label: '最近打卡时间' }, 
          {
            prop: 'status',
            label: '健康状态',
            align: 'center',
            render (h, {row}) {
              return h('span',{
                style: {
                  color: row.status === '0' ? '#F46' : '#2EA222'
                }
              }, row.status === '0' ? '异常' : '正常')
            }
          }
        ],
        tableData: [],
        total: 0,
        loading: false
      }
    },

    computed: {
      ...mapState(['user']),

      param () {
        return {

        }
      }
    },

    created () {
      this.loading = true
      this.dict.load(['epidemicTouchInFourteen']).then(() => {
        this.getList()
      })
    },

    methods: {
      getList () {
        this.instance.post(`/app/appepidemicreportmember/list`, null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
            this.loading = false
          } else {
            this.loading = false
          }
        }).catch(() => {
          this.loading = false
        })
      },

      remove(id) {
        this.$confirm('确定删除该数据？').then(() => {
          this.instance.post(`/app/appepidemicreportmember/delete?ids=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success('删除成功！')
              this.getTotalInfo()
              this.getList()
            }
          })
        })
      },

      toDetail (id) {
        this.$emit('change', {
          type: 'Detail',
          params: {
            id: id || ''
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
</style>
