<template>
  <div>
    <div class="con-title">{{ $t('pages.learn.reportListAll.title') }}</div>
    <div class="con-box">
      <!-- <el-button type="primary" @click="goReportSubmit">申请报告</el-button> -->
      <el-button type="text" @click='gobackReportActiveList'>{{ $t('pages.learn.reportListAll.backButtonText') }}</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: this.$t('pages.learn.reportListAll.index'), minWidth: '80', fix: false },
        { prop: 'report_name', label: this.$t('pages.learn.reportListAll.reportName'), minWidth: '150', fix: false },
        { prop: 'report_description', label: this.$t('pages.learn.reportListAll.reportDescription'), minWidth: '120', fix: false },
        { prop: 'submit_time', label: this.$t('pages.learn.reportListAll.submitTime'), minWidth: '120', fix: false },
        { prop: 'approve_status', label: this.$t('pages.learn.reportListAll.approveStatus'), minWidth: '120', fix: false },
        { prop: 'file_url', label: this.$t('pages.learn.reportListAll.file'), minWidth: '120', fix: false },
        // { prop: '', label: '', minWidth: '', fix: false, goObj: { routerName: '', params: {} } }, // 点击跳转页面并传参数
        { prop: 'operate-x', label: this.$t('pages.learn.reportListAll.operate'), width: '140px', fix: false, commandArr: [{ command: 'reportlist-', name: '' }, { command: 'reportlist-edit', name: this.$t('pages.learn.reportListAll.edit') }, { command: 'reportlist-delete', name: this.$t('pages.learn.reportListAll.delete') }] }
      ],
      tableData: [],
      params: { keywords: '', curPage: 1, pageSize: 100, total: '' },
      objFn: {
        paramsFn: (_this) => { return { rid: this.rid } },
        nameAPI: 'getReportListAll',
        actionClass: 'Report',
        // nameExcel: 'getStatSummaryExcel',
        nameExcel: 'getExportExcel3_4_14',
        callback: (_this, data) => {
          _this.params.total = 100
          data.forEach((elem, i) => {
            elem.approve_status = elem.is_checked === 1 ? this.$t('pages.learn.reportActiveList.passed') : (elem.is_checked === 0 ? this.$t('pages.learn.reportActiveList.failed') : this.$t('pages.learn.reportActiveList.unreviewed'))
            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/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.Report.deleteSubmitReport(this.rid, reid).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: {
    goReportSubmit () {
      this.$router.push({ path: `/app/learn/report-submit/${this.rid}/-1` })
    },
    gobackReportActiveList () {
      this.$router.push({ path: '/app/learn/report-Active-list' })
    }
  }
}
</script>

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