<template>
  <div class="app-container">
    <div class="filter-container">
      <!-- <el-input
        v-model="listQuery.keyword"
        style="width:200px;margin-right:10px"
        class="filter-item"
        placeholder="请输入关键字"
        clearable
      /> -->
      <el-select v-model="listQuery.settlementStatus" clearable class="filter-item" style="width:200px;margin-right:10px" placeholder="请选择结算状态">
        <el-option v-for="item of statusOptions" :key="item.value" v-bind="item" />
      </el-select>
      <el-select v-model="listQuery.dealStatus" clearable class="filter-item" style="width:200px;margin-right:10px" placeholder="请选择已处理状态">
        <el-option v-for="item of dealStatusOptions" :key="item.value" v-bind="item" />
      </el-select>
      <el-button
        type="primary"
        style="margin-left:10px"
        @click="handleSearch"
      >搜索</el-button>
    </div>
    <el-table :data="list" border style="width: 100%">
      <el-table-column label="用户名" prop="residentInformation.name" />
      <el-table-column label="结算积分数" prop="num" />

      <el-table-column label="提交时间">
        <template slot-scope="scope">
          <span>{{
            scope.row.createDate | parseTime("{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算状态">
        <template slot-scope="scope">
          <span>{{
            scope.row.settlementStatus | optionsFilter(statusOptions)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已处理状态">
        <template slot-scope="scope">
          <span>{{
            scope.row.dealStatus | optionsFilter(dealStatusOptions)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理备注" prop="remark" />
      <el-table-column label="发票状态">
        <template slot-scope="scope">
          <span>{{
            scope.row.invoiceStatus | optionsFilter(invoiceStatusOptions)
          }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-if="total > 0"
      :total="total"
      :page.sync="listQuery.lastPageIndex"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { settlementList } from '@/api/fingertipIntegral'
export default {
  components: { Pagination },
  filters: {
    optionsFilter(value, options = []) {
      const findItem = options.find((option) => option.value === value)
      if (findItem) {
        return findItem.label
      }
      return ''
    }
  },
  data() {
    return {
      total: 0,
      listQuery: {
        lastPageIndex: 1,
        size: 10,
        category: undefined,
        dealStatus: undefined,
        endDate: undefined,
        id: undefined,
        innerCategory: undefined,
        keyword: undefined,
        settlementStatus: undefined,
        startDate: undefined,
        status: undefined
      },
      list: undefined,

      statusOptions: [
        {
          label: '待处理',
          value: '0'
        },
        {
          label: '已处理',
          value: '1'
        }
      ],
      dealStatusOptions: [
        {
          label: '兑换',
          value: '0'
        },
        {
          label: '不兑换',
          value: '1'
        }
      ],
      invoiceStatusOptions: [
        {
          label: '未收',
          value: '0'
        },
        {
          label: '已收',
          value: '1'
        }
      ]
    }
  },
  watch: {
    'listQuery.lastPageIndex': {
      handler(val) {
        this.getList()
      },
      deep: true // true 深度监听
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      settlementList(this.listQuery).then(res => {
        this.list = res.d.records
        this.total = res.d.total
        // this.pageSize = res.d.pageSize
      })
    },
    handleSearch() {
      const { listQuery } = this
      this.listQuery.lastPageIndex = 1
      Object.keys(listQuery).forEach(key => {
        if (listQuery[key] === '') listQuery[key] = undefined
      })
      this.getList()
    }
  }
}
</script>

<style></style>
