<template>
  <el-dialog :title="`${viewFeeDetailInfo.curYear}${$t('viewFeeDetail.yearFeeHistory')}(${viewFeeDetailInfo.roomName})`"
    :visible.sync="dialogVisible" width="80%" top="5vh">
    <el-table :data="viewFeeDetailInfo.feeDetails" border style="width: 100%" height="500">
      <el-table-column prop="cycles" :label="$t('viewFeeDetail.cycle')" align="center">
      </el-table-column>
      <el-table-column prop="receivableAmount" :label="$t('viewFeeDetail.receivableAmount')" align="center">
      </el-table-column>
      <el-table-column prop="receivedAmount" :label="$t('viewFeeDetail.receivedAmount')" align="center">
      </el-table-column>
      <el-table-column prop="createTime" :label="$t('viewFeeDetail.paymentTime')" align="center">
      </el-table-column>
      <el-table-column prop="startTime" :label="$t('viewFeeDetail.startTime')" align="center">
        <template slot-scope="scope">
          {{ $moment(scope.row.startTime).format('YYYY-MM-DD') }}
        </template>
      </el-table-column>
      <el-table-column prop="endTime" :label="$t('viewFeeDetail.endTime')" align="center">
        <template slot-scope="scope">
          {{ $moment(scope.row.endTime).format('YYYY-MM-DD') }}
        </template>
      </el-table-column>
      <el-table-column prop="stateName" :label="$t('viewFeeDetail.status')" align="center">
      </el-table-column>
      <el-table-column prop="remark" :label="$t('viewFeeDetail.remark')" align="center">
      </el-table-column>
    </el-table>

    <el-pagination :current-page.sync="pagination.current" :page-sizes="[10, 20, 30, 50]" :page-size="pagination.size"
      :total="pagination.total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
  </el-dialog>
</template>

<script>
import { queryFeeDetail } from '@/api/report/reportProficientApi'

export default {
  name: 'ViewFeeDetail',
  data() {
    return {
      dialogVisible: false,
      viewFeeDetailInfo: {
        feeDetails: [],
        curYear: '',
        roomName: '',
        feeId: '',
        configId: '',
        payerObjId: ''
      },
      pagination: {
        current: 1,
        size: 10,
        total: 0
      }
    }
  },
  methods: {
    open(params) {
      this.viewFeeDetailInfo = {
        ...this.viewFeeDetailInfo,
        ...params
      }
      this.dialogVisible = true
      this.listFeeDetail()
    },
    async listFeeDetail() {
      try {
        const params = {
          page: this.pagination.current,
          row: this.pagination.size,
          curYear: this.viewFeeDetailInfo.curYear,
          configId: this.viewFeeDetailInfo.configId,
          payerObjId: this.viewFeeDetailInfo.payerObjId
        }
        const { data, records } = await queryFeeDetail(params)

        this.viewFeeDetailInfo.feeDetails = data
        this.pagination.total = records
      } catch (error) {
        console.error('获取费用详情失败:', error)
      }
    },
    handleSizeChange(val) {
      this.pagination.size = val
      this.listFeeDetail()
    },
    handleCurrentChange(val) {
      this.pagination.current = val
      this.listFeeDetail()
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__body {
  padding: 20px;
}
</style>