<template>
  <div>
    <div class="con-title">{{ $t('pages.learn.reportActiveList.title') }}</div>
    <div class="con-box">
      <el-button type="primary" @click="goReportAdd">{{ $t('pages.learn.reportActiveList.newEvent') }}</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: this.$t('pages.learn.reportActiveList.serialNumber'), minWidth: '80', fix: false },
        { prop: 'symposium_name', label: this.$t('pages.learn.reportActiveList.activityName'), minWidth: '150', fix: false },
        { prop: 'symposium_time', label: this.$t('pages.learn.reportActiveList.activitytime'), minWidth: '120', fix: false },
        { prop: 'symposium_lecturer', label: this.$t('pages.learn.reportActiveList.lecturer'), minWidth: '120', fix: false },
        { prop: 'approve_status', label: this.$t('pages.learn.reportActiveList.approvalStatus'), minWidth: '80', fix: false },
        { prop: 'approve_time', label: this.$t('pages.learn.reportActiveList.approvalTime'), minWidth: '120', fix: false },
        // { prop: '', label: '', minWidth: '', fix: false, goObj: { routerName: '', params: {} } }, // 点击跳转页面并传参数
        { prop: 'operate-x', label: this.$t('pages.learn.reportActiveList.operate'), width: '240px', fix: false, commandArr: [{ command: 'activelist-show', name: this.$t('pages.learn.reportActiveList.viewReport') }, { command: 'activereport-add', name: this.$t('pages.learn.reportActiveList.uploadReport') }, { command: 'activelist-edit', name: this.$t('pages.learn.reportActiveList.edit') }, { command: 'activelist-delete', name: this.$t('pages.learn.reportActiveList.delete') }] }
      ],
      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 ? this.$t('pages.learn.reportActiveList.passed') : (elem.approve_status === 0 ? this.$t('pages.learn.reportActiveList.failed') : this.$t('pages.learn.reportActiveList.unreviewed')) // 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.$t('pages.learn.reportActiveList.deleteSuccessTips') })
          }
          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>
