<template>
  <ai-list class="list">
    <ai-title
      slot="title"
      title="积分审核"
      v-if="search.areaId"
      isShowBottomBorder
      :instance="instance"
      :disabledLevel="disabledLevel"
      isShowArea
      v-model="search.areaId"
      @change="changeArea">
    </ai-title>
    <template slot="content">
      <div class="content">
        <ai-search-bar>
          <template #left>
            <ai-select
              v-model="search.applyIntegralType"
              clearable
              placeholder="请选择积分类型"
              :selectList="dict.getDict('atWillReportType')"
              @change="search.current = 1, getList()">
            </ai-select>
            <ai-select
              v-model="search.auditStatus"
              clearable
              placeholder="请选择审核状态"
              :selectList="dict.getDict('auditStatus')"
              @change="search.current = 1, getList()">
            </ai-select>
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="search.createTimeStart"
              type="date"
              size="small"
              unlink-panels
              placeholder="选择开始日期"
              @change="search.current = 1, getList()" />
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="search.createTimeEnd"
              type="date"
              size="small"
              unlink-panels
              placeholder="选择结束日期"
              @change="search.current = 1, getList()" />
          </template>
          <template #right>
            <el-input
              v-model="search.residentName"
              size="small"
              placeholder="请输入姓名"
              clearable
              v-throttle="() => {search.current = 1, getList()}"
              @clear="search.current = 1, search.residentName = '', 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: 8px;"
          :current.sync="search.current"
          :size.sync="search.size"
          @getList="getList">
          <el-table-column slot="options" width="120px" fixed="right" label="操作" align="center">
            <template slot-scope="{ row }">
              <div class="table-options">
                <el-button type="text" @click="toDetail(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,
          residentName: '',
          applyIntegralType: '',
          areaId: '',
          auditStatus: '',
          createTimeStart: '',
          createTimeEnd: ''
        },
        dictList: [{
          dictName: '否',
          dictValue: '0'
        }, {
          dictName: '是',
          dictValue: '1'
        }],
        info: {},
        colConfigs: [
          { prop: 'residentName', label: '申请人' },
          { prop: 'residentPhone', align: 'center', label: '联系电话' },
          { prop: 'createTime', align: 'center', label: '申请时间' },
          { prop: 'applyIntegralType', align: 'center', label: '积分类型', formart: v => this.dict.getLabel('atWillReportType', v) }, 
          { prop: 'auditStatus', align: 'center', label: '状态', formart: v => v ? this.dict.getLabel('auditStatus', v) : '-' }, 
          { prop: 'auditUserName', align: 'center', label: '审批人' }, 
          { prop: 'auditTime', align: 'center', label: '审批时间' }
        ],
        tableData: [],
        total: 0,
        loading: false,
        disabledLevel: 0
      }
    },

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

      param () {
        return {

        }
      }
    },

    created () {
      this.disabledLevel = this.user.info.areaList.length - 1
      this.search.areaId = this.user.info.areaId
      this.loading = true
      this.dict.load(['atWillReportType', 'auditStatus']).then(() => {
        this.getList()
      })
    },

    methods: {
      getList () {
        this.instance.post(`/app/appvillagerintegraldeclare/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
        })
      },

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

      changeArea () {
        this.search.current = 1

        this.$nextTick(() => {
          this.getList()
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .list {
    ::v-deep .ai-list__content {
      padding: 0!important;

      .ai-list__content--right-wrapper {
        background: transparent!important;
        box-shadow: none!important;
        margin: 0!important;
        padding: 12px 16px 12px!important;
      }
    }
    .statistics-top {
      display: flex;
      align-items: center;
      margin-bottom: 20px;

      & > div {
        flex: 1;
        height: 96px;
        line-height: 1;
        margin-right: 20px;
        padding: 16px 24px;
        background: #FFFFFF;
        box-shadow: 0px 4px 6px -2px rgba(15, 15, 21, 0.15);
        border-radius: 4px;

        &:last-child {
          margin-right: 0;
        }

        h3 {
          font-size: 24px;
        }

        span {
          display: block;
          margin-bottom: 16px;
          color: #888888;
          font-size: 16px;
        }
      }
    }

    .content {
      padding: 16px;
      background: #FFFFFF;
      box-shadow: 0px 4px 6px -2px rgba(15, 15, 21, 0.15);
    }
  }
</style>
