<template>
  <div>
    <div class="con-title">学术报告所在活动列表</div>
    <div class="con-box">
      <!-- <el-button type="primary" @click="goReportSubmit">申请报告</el-button> -->
      <el-button type="text" @click='gobackReportActiveList'>返回活动列表</el-button>
      <div style="width: 100%; height: 0.2rem;"></div>
      <m-page
        :tableHead="tableHead"
        :tableData="tableData"
        :params="params"
        :objFn="objFn"
        :tableConfig="tableConfig"
      />
    </div>
  </div>
</template>

<script>
import cAction from '@action'

import mPage from '../../components/comTable/mPage.vue'
export default {
  props: {
    rid: { type: String, required: true }
  },
  components: { mPage },
  data () {
    return {
      tableConfig: { border: '', size: '', selection: { has: false, sels: [], width: '50px', fix: 'left', align: '' } }, // 增加选择框，has设置为true
      tableHead: [
        { prop: 'index', label: '序号', minWidth: '80', fix: false },
        { prop: 'report_name', label: '报告名称', minWidth: '150', fix: false },
        { prop: 'report_description', label: '报告摘要', minWidth: '120', fix: false },
        { prop: 'submit_time', label: '提交时间', minWidth: '120', fix: false },
        { prop: 'approve_status', label: '审核状态', minWidth: '120', fix: false },
        { prop: 'file_url', label: '附件下载', minWidth: '120', fix: false },
        // { prop: '', label: '', minWidth: '', fix: false, goObj: { routerName: '', params: {} } }, // 点击跳转页面并传参数
        { prop: 'operate-x', label: '操作', width: '140px', fix: false, commandArr: "[ { command: 'reportlist-', name: '' }, { command: 'reportlist-edit', name: '编辑' }, { command: 'reportlist-delete', name: '删除' } ]" }
      ],
      tableData: [],
      params: { keywords: '', curPage: 1, pageSize: 100, total: '' },
      objFn: {
        paramsFn: (_this) => { return { rid: this.rid } },
        nameAPI: 'getReportListAll',
        actionClass: 'reportAction',
        // nameExcel: 'getStatSummaryExcel',
        nameExcel: 'getExportExcel3_4_14',
        callback: (_this, data) => {
          _this.params.total = 100
          data.forEach((elem, i) => {
            elem.approve_status = elem.is_checked === 1 ? '通过' : (elem.is_checked === 0 ? '未通过' : '未审核')
            elem.file_url = JSON.parse(elem.file_url)[0].url
            elem.index = i + 1 + (_this.params.curPage - 1) * _this.params.pageSize
            _this.tableData.push(elem)
          })
        }
      }
    }
  },
  mounted () {
    this.VueEvent.$on('command-tablelist-x', (_obj) => {
      if (_obj.command.command === 'reportlist-edit') {
        const reid = _obj.tableData[_obj.index - 1].id
        this.$router.push({ path: `/app/my-learn/report-submit/${this.rid}/${reid}` })
      }
      if (_obj.command.command === 'reportlist-delete') {
        const reid = _obj.tableData[_obj.index - 1].id
        /* 删除 */
        const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
        cAction.reportAction.deleteSubmitReport(this.rid, reid).then(data => {
          if (data.flag) {
            this.$message({ type: 'success', message: '删除成功' })
          }
          this.params.pageSize += 1
        }).catch(e => { this.$message.error(e.message) }).finally(() => { loading.close() })
      }
    })
  },
  methods: {
    goReportSubmit () {
      this.$router.push({ path: `/app/my-learn/report-submit/${this.rid}/-1` })
    },
    gobackReportActiveList () {
      this.$router.push({ path: '/app/service-hall/hall' })
    }
  }
}
</script>

<style lang="scss" scoped>
/* 申请 */
.el-date-editor.el-input {
  width: 100%;
}
.el-upload__tip {
  line-height: 1.5;
}
</style>
