<template>
  <div>
    <el-dialog
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      title="查看回答"
      :fullscreen="false"
      width="700px"
      custom-class="xl-dialog"
      center
    >
      <table-list
        :list-loading="listLoading"
        :data="aList"
        :columns="listConfig"
        :current-page="currentPage"
        :page-size="pageSize"
        :total-records="totalRecords"
        @currentChange="pageHandle"
      />
      <div class="xl-form">
        <div class="xl-form-footer">
          <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import baseTable from '_m/baseTable.js'
export default {
  components: {},
  mixins: [...mixins, baseTable],
  props: {
    isShow: Boolean,
    curObj: Object
  },
  inject: ['parentData'],
  data() {
    return {
      apiStr: 'user.admanswerlist',
      noCreated: true,
      searchForm: {},
      aList: [],
    }
  },
  mounted() {
    this.listConfig = {
      rows: [
        { label: '回答内容', prop: 'answer_cont', fullShow: true, minWidth: 200, align: 'left' },
        { label: '昵称', prop: 'nickname' },
        { label: '头像', prop: 'avatar', type: 'img' },
        { label: '回答时间', prop: 'create_at' },
        { label: '操作', width: 80, type: 'handle2', operations:
          [
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        this.searchForm = {question_id: this.curObj.id}
        this.fetchData()
      }
    },
  },
  methods: {
    getMoreData (res) {
      const data = res.answer_list || {}
      this.aList = data.list || []
      if (this.currentPage === 1) this.pageSize = data.page_size || 1
      this.totalRecords = data.total ? Number(data.total) : 0
    },
    delHandle(row) {
      this.$msg(`您确定要删除该问题吗？`, 'confirm', () => {
        this.$api.user.admanswerdel({
          answer_id: row.answer_id
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    close(str) {
      this.$emit('close')
    },
  }
}
</script>
<style lang="scss" scoped>
</style>
