<template>
  <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
    <van-list v-model="loading" :finished="finished" @load="loadData">
      <van-cell
        v-for="(item,index) in listData"
        :key="item.id+index"
        :title="item.content"
        :label="item.reply"
        size="large"
      >
        <span>{{ item.replyTime }}</span>
      </van-cell>
      <ibps-list-result-page
        :result-type="resultType"
        :error-type="errorType"
        :result-message="resultMessage"
      />
    </van-list>
  </van-pull-refresh>
</template>
<script>
import ActionUtils from '@/utils/action'
import { getReplyPageList } from '@/api/platform/message/innerMessage'
import IbpsListResultPage from '@/components/ibps-list-result-page'
export default {
  components: {
    IbpsListResultPage
  },
  props: {
    id: String
  },
  data() {
    return {
      pkKey: 'id', // 主键  如果主键不是pk需要传主键

      listData: [],
      pagination: {},
      sorts: {},

      loading: false,
      finished: false,
      refreshing: false,
      resultType: 'init',
      errorType: null,
      resultMessage: null
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    // 加载已回复数据
    loadData() {
      this.loading = true
      getReplyPageList(this.getSearcFormData()).then(response => {
        ActionUtils.handleListData(this, response.data)
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    /**
     * 获取格式化参数
     */
    getSearcFormData() {
      return ActionUtils.formatParams({
        'Q^MSG_ID_^S': this.id
      }, this.pagination, this.sorts)
    },
    /**
     * 处理已回复分页事件
     */
    handlePaginationChange(page) {
      ActionUtils.setPagination(this.pagination, page)
      this.loadData()
    },
    /**
     * 处理排序
     */
    handleSortChange(sort) {
      ActionUtils.setSorts(this.sorts, sort)
      this.loadData()
    },
    /**
     * 下拉刷新
     */
    onRefresh() {
      this.refreshing = true
      this.finished = false
      this.loading = true
      this.onSearch()
    },
    /**
     * 查询
     */
    onSearch() {
      ActionUtils.initListData(this)
      this.loadData()
    }
  }
}
</script>
