<template>
  <ai-list class="notice">
    <template slot="title">
      <ai-title title="走访排查情况统计" isShowBottomBorder isShowBack @onBackClick="back"></ai-title>
    </template>
    <template slot="content">
      <ai-search-bar>
        <template #left>
          <el-date-picker
            value-format="yyyy-MM"
            v-model="search.startDate"
            type="month"
            size="small"
            unlink-panels
            placeholder="请选择考核开始月份"
            @change="search.current = 1, getList()" />
          <el-date-picker
            value-format="yyyy-MM"
            v-model="search.endDate"
            type="month"
            size="small"
            unlink-panels
            placeholder="请选择考核结束月份"
            @change="search.current = 1, getList()" />
        </template>
        <template #right>
          <el-input
            v-model="search.createUserName"
            size="small"
            placeholder="网格员姓名"
            clearable
            v-throttle="() => {search.current = 1, getList()}"
            @clear="search.current = 1, search.createUserName = '', getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        style="margin-top: 12px;"
        :current.sync="search.current"
        :size.sync="search.size"
        @selection-change="(v) => (ids = v.map((e) => e.id))"
        @getList="getList">
      </ai-table>
    </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,
          createUserName: '',
          endDate: '',
          startDate: ''
        },
        total: 10,
        tableData: []
      }
    },

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

      colConfigs () {
        return [
          { prop: 'month', label: '考核月份', align: 'left' },
          { prop: 'createUserName', label: '网格员姓名', align: 'center' },
          { prop: 'phone', label: '网格员联系方式', align: 'center' },
          { prop: 'povertyNumber', label: '监测家庭数量', align: 'center' },
          { prop: 'logNumber', label: '开展走访次数', align: 'center' },
          { prop: 'povertyHouseholdNumber', label: '已走访家庭数量', align: 'center' },
          { prop: 'finishRate', label: '走访进度', align: 'center', formart: v => (v * 100).toFixed(1) + '%' }
        ]
      }
    },

    created () {
      this.getList()
    },

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

      back () {
        this.$emit('change', {
          type: 'Statistics'
        })
      }
    }
  }
</script>

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