<template>
  <div>
    <div class="con-title">
      <div>办事大厅</div>
      <div @click="goMyApply">我的申请</div>
    </div>
    <Tap :tapParam='tapParam' @tapParam='tapIndexs'></Tap>
    <div class="con-box">
      <el-button type="primary" v-show="tapIndex==0" @click="golearningAdd(0)">申请新的活动</el-button>
      <el-button type="primary" v-show="tapIndex==1" @click="golearningAdd(1)">申请新乐分享</el-button>
      <el-button type="primary" v-show="tapIndex==2" @click="golearningAdd(2)">申请重修</el-button>
      <!-- <el-button style="float:right;" type="text" @click='gobackReportList'>返回报告列表</el-button> -->
      <div style="width: 100%; height: 0.2rem;"></div>
      <template v-if="ismPageFlag">
        <m-page
          :tableHead="tableHead"
          :tableData="tableData"
          :params="params"
          :objFn="objFn"
          :tableConfig="tableConfig"
        />
      </template>
    </div>
  </div>
</template>

<script>
import Tap from '../../components/module/tap.vue'
import mPage from '../../components/module/mPage.vue'
import cAction from '@actions'
export default {
  components: {
    Tap,
    mPage
  },
  data () {
    return {
      ismPageFlag: false,
      tapIndex: 0,
      // tap切换
      tapParam: [{
        name: '分类',
        isShow: false,
        selectIndex: 0,
        key: 'cc',
        arrItem: [
          // { val: '1', name: '学术活动' },
          // { val: '2', name: '乐分享' },
          // { val: '3', name: '重修' }
        ]
      }],
      // 学术活动
      tableConfig: { border: '', size: '', selection: { has: false, sels: [], width: '50px', fix: 'left', align: '' } }, // 增加选择框，has设置为true
      tableHead: [],
      tableData: [],
      dataParam: 1,
      params: {},
      // params: { keywords: '', curPage: 1, pageSize: 5, total: '' },
      objFn: {}
      // 音分享
    }
  },
  beforeDestroy () {
    this.VueEvent.$off('command-tablelist-x')
  },
  mounted () {
    this.getTapData()
    this.VueEvent.$on('command-tablelist-x', (_obj) => {
      if (_obj.command.command === 'activelist-show') {
        let rid = _obj.tableData[_obj.index - 1].id
        this.$router.push({ path: `/app/service-hall/view-report/${rid}` })
      }
      if (_obj.command.command === 'activereport-add') {
        let syid = _obj.tableData[_obj.index - 1].formId
        this.$router.push({ path: `/app/service-hall/upload-report/${syid}/-1` })
      }
      if (_obj.command.command === 'activelist-edit') {
        let rid = _obj.tableData[_obj.index - 1].id
        this.$router.push({ path: `/app/service-hall/learning-add/${rid}`, query: { id: this.tapParam[0].arrItem[this.tapIndex].val } })
      }
      if (_obj.command.command === 'activelist-delete') {
        let rid = _obj.tableData[_obj.index - 1].id
        /* 删除 */
        const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
        cAction.reportAction.deleteAffairs(rid).then(data => {
          if (data.success) {
            this.$message({ type: 'success', message: '删除成功' })
            this.setmPage()
          }
        }).catch(e => { this.$message.error(e.message) }).finally(() => { loading.close() })
      }
    })
  },
  methods: {
    setmPage () {
      this.objFn = {
        paramsFn: (_this) => { return { affair_id: this.dataParam } },
        nameAPI: 'getAffairsData',
        actionClass: 'reportAction',
        // nameExcel: 'getStatSummaryExcel',
        nameExcel: 'getExportExcel3_4_14',
        callback: (_this, data) => {
          // _this.params.total = data.length
          data.forEach((elem, i) => {
            let datas = {}
            datas.approve_status = '未通过'
            datas.approve_status = elem.status = elem.status === 1 || elem.status === 2 || elem.status === 4 ? '通过' : (elem.status === 0 || elem.status === 3 ? '未通过' : '未审核') // 0 未通过；1 通过；2 未审核
            // datas.index = elem.index = i + 1 + (_this.params.curPage - 1) * _this.params.pageSize
            datas.index = i + 1
            datas.approve_time = elem.apply_time
            datas.isPage = 0
            if (parseInt(this.tapIndex) === 0) {
              datas.symposium_attachments = elem.form.symposium_attachments
              // datas.approve_status = elem.approve_status = elem.approve_status === 1 ? '通过' : (elem.approve_status === 0 ? '未通过' : '未审核') // 0 未通过；1 通过；2 未审核
              // datas.index = elem.index = i + 1 + (_this.params.curPage - 1) * _this.params.pageSize
              // datas.reportscount = elem.reportscount = Number(elem.reportscount || '0')
              datas.symposium_name = elem.form.symposium_name
              datas.symposium_time = elem.form.symposium_time
              datas.symposium_lecturer = elem.form.symposium_lecturer
              datas.id = elem.id
              datas.formId = elem.form.id
            } else if (parseInt(this.tapIndex) === 1) {
              datas.personal_name = elem.form.personal_name
              datas.trade_name = elem.form.trade_name
              datas.age = elem.form.age
              datas.class_name = elem.form.class_name
              datas.telephone = elem.form.telephone
              datas.sharing_theme = elem.form.sharing_theme
              datas.remark1 = elem.remark1
            } else {
              datas.personal_name = elem.form.personal_name
              datas.payment_instrument = elem.form.payment_instrument
              datas.semester_name = elem.form.semester_name
              datas.class_name = elem.form.class_name
              datas.course_name = elem.form.course_name
              datas.remark1 = elem.remark1
            }
            _this.tableData.push(datas)
          })
        }
      }
      this.ismPageFlag = true
    },
    tapIndexs (data) {
      this.tapIndex = data.index
      this.getData(data)
    },
    getData (data) {
      let n = parseInt(data.index)
      this.dataParam = data.id
      switch (n) {
        case 0:
          this.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: '200px', fix: false, commandArr: [ { command: 'activelist-show', name: '查看报告' }, { command: 'activereport-add', name: '上传报告' }, { command: 'activelist-edit', name: '编辑' }, { command: 'activelist-delete', name: '删除' } ] }
          ]
          break
        case 1:
          this.tableHead = [
            { prop: 'index', label: '序号', minWidth: '80', fix: true },
            { prop: 'sharing_theme', label: '分享主题', minWidth: '150', fix: false },
            { prop: 'class_name', label: '班级', minWidth: '80', fix: false },
            { prop: 'personal_name', label: '申请人', minWidth: '80', fix: false },
            { prop: 'telephone', label: '电话', minWidth: '120', fix: false },
            { prop: 'approve_status', label: '审核状态', minWidth: '80', fix: false },
            { prop: 'approve_time', label: '审核时间', minWidth: '200', fix: false },
            { prop: 'remark1', label: '备注', minWidth: '120', fix: false }
          ]
          break
        case 2:
          this.tableHead = [
            { prop: 'index', label: '序号', minWidth: '80', fix: false },
            { prop: 'semester_name', label: '学期', minWidth: '150', fix: false },
            { prop: 'class_name', label: '班级', minWidth: '80', fix: false },
            { prop: 'course_name', label: '课程', minWidth: '80', fix: false },
            { prop: 'approve_status', label: '审核状态', minWidth: '80', fix: false },
            { prop: 'approve_time', label: '审核时间', minWidth: '120', fix: false },
            { prop: 'remark1', label: '备注', minWidth: '120', fix: false }
          ]
          break
      }
      this.setmPage()
    },
    getTapData () {
      // 获取事务类型   tap切换
      cAction.reportAction.getAffairsType().then(data => {
        for (let i = 0; i < data.length; i++) {
          this.tapParam[0].arrItem.push(
            { val: data[i].id, name: data[i].affair_name }
          )
        }
        let param = {
          id: this.tapParam[0].arrItem[0].val,
          index: 0
        }
        this.getData(param)
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    golearningAdd (n) {
      if (n === 0) {
        this.$router.push({ path: `/app/service-hall/learning-add/-1`, query: { id: this.tapParam[0].arrItem[this.tapIndex].val } })
      } else if (n === 1) {
        this.$router.push({ path: `/app/service-hall/share-add/-1`, query: { id: this.tapParam[0].arrItem[this.tapIndex].val } })
      } else {
        this.$router.push({ path: `/app/service-hall/again-add/-1`, query: { id: this.tapParam[0].arrItem[this.tapIndex].val } })
      }
    },
    goMyApply () {
      this.$router.push({ path: `/app/service-hall/my-apply`, query: { id1: this.tapParam[0].arrItem[0].val, id2: this.tapParam[0].arrItem[1].val, id3: this.tapParam[0].arrItem[2].val } })
    }
  }
}
</script>

<style lang="scss" scoped>
.con-title{
  display: flex;
  justify-content:space-between
}
</style>