<template>
  <div>
    <div class="con-title">学术活动列表</div>
    <div class="con-box">
      <el-button type="primary" @click="goReportAdd">申请新的活动</el-button>
      <!-- <el-button style="float:right;" type="text" @click='gobackReportList'>返回报告列表</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 {
  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: 'symposium_name', label: '活动名称', minWidth: '150', fix: false },
        { prop: 'symposium_time', label: '活动时间', minWidth: '120', fix: false },
        { prop: 'symposium_lecturer', label: '主讲人', minWidth: '120', fix: false },
        { prop: 'approve_status', label: '审核状态', minWidth: '80', fix: false },
        { prop: 'approve_time', label: '审核时间', minWidth: '120', fix: false },
        // { prop: '', label: '', minWidth: '', fix: false, goObj: { routerName: '', params: {} } }, // 点击跳转页面并传参数
        { prop: 'operate-x', label: '操作', width: '240px', fix: false, commandArr: [{ command: 'activelist-show', name: '查看报告' }, { command: 'activereport-add', name: '上传报告' }, { command: 'activelist-edit', name: '编辑' }, { command: 'activelist-delete', name: '删除' }] }
      ],
      tableData: [],
      params: { keywords: '', curPage: 1, pageSize: 100, total: '' },
      objFn: {
        paramsFn: (_this) => { return {} },
        nameAPI: 'getReportActiveList',
        actionClass: 'Report',
        // nameExcel: 'getStatSummaryExcel',
        nameExcel: 'getExportExcel3_4_14',
        callback: (_this, data) => {
          _this.params.total = 100
          data.forEach((elem, i) => {
            elem.approve_status = elem.approve_status === 1 ? '通过' : (elem.approve_status === 0 ? '未通过' : '未审核') // 0 未通过；1 通过；2 未审核
            elem.index = i + 1 + (_this.params.curPage - 1) * _this.params.pageSize
            elem.reportscount = Number(elem.reportscount || '0')
            _this.tableData.push(elem)
          })
        }
      }
    }
  },
  mounted () {
    this.VueEvent.$on('command-tablelist-x', (_obj) => {
      if (_obj.command.command === 'activelist-show') {
        const rid = _obj.tableData[_obj.index - 1].id
        this.$router.push({ path: `/app/learn/report-list-all/${rid}` })
      }
      if (_obj.command.command === 'activereport-add') {
        const syid = _obj.tableData[_obj.index - 1].id
        this.$router.push({ path: `/app/learn/report-submit/${syid}/-1` })
      }
      if (_obj.command.command === 'activelist-edit') {
        const rid = _obj.tableData[_obj.index - 1].id
        this.$router.push({ path: `/app/learn/report-add/${rid}` })
      }
      if (_obj.command.command === 'activelist-delete') {
        const rid = _obj.tableData[_obj.index - 1].id
        /* 删除 */
        const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
        cAction.Report.deleteReportActive(rid).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: {
    goReportAdd () {
      this.$router.push({ path: '/app/learn/report-add/-1' })
    }
    // gobackReportList () {
    //   this.$router.push({ path: `/app/learn/report-list` })
    // }
  }
}
</script>

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