<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.source" clearable class="filter-item" placeholder="请选择积分来源">
        <el-option v-for="item of sourceOptions" :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="source">
        <template slot-scope="scope">
          <span>{{
            scope.row.source | optionsFilter(sourceOptions)
          }}</span>
        </template>
      </el-table-column>

      <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>

    <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 { recordList } 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,
        // params: {},
        size: 10,
        category: undefined,
        id: undefined,
        innerCategory: undefined,
        keyword: undefined,
        source: undefined,
        status: undefined,
        userId: undefined
      },
      list: undefined,

      sourceOptions: [
        {
          value: 'REAL_NAME_AUTHENTICATION',
          label: '实名认证'
        },
        {
          value: 'HANDLING',
          label: '处理办件'
        },
        {
          value: 'APPLY',
          label: '申请办件'
        },
        {
          value: 'TIMEOUT',
          label: '超期办件扣分'
        },
        {
          value: 'VERY_SATISFIED',
          label: '非常满意得分'
        },
        {
          value: 'NEGATIVE_COMMENT',
          label: '差评扣分'
        },
        {
          value: 'READ',
          label: '阅读'
        },
        {
          value: 'SEND_A_CIRCLE_OF_FRIENDS',
          label: '发朋友圈'
        },
        {
          value: 'CONSUMPTION',
          label: '消费'
        },
        {
          value: 'MERCHANT_SETTLEMENT',
          label: '商户结算'
        },
        {
          value: 'POINT_REFUND',
          label: '积分回退'
        },
        {
          value: 'REGULATORY_PUNISHMENT_AND_REWARD',
          label: '监管惩罚'
        },
        {
          value: 'SPECIAL_WORK_TYPE',
          label: '特殊工单类型奖励积分(医保卫生)'
        }
      ]
    }
  },
  watch: {
    'listQuery.lastPageIndex': {
      handler(val) {
        this.getList()
      },
      deep: true // true 深度监听
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      recordList(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>
