<template>
  <div>
    <list ref="list">
      <!-- 新增课程 -->
      <Header slot="add" v-if="tool.checkAuth($route.name, 'insert')">
        <save />
      </Header>
      <!-- 详情 -->
      <template v-slot:detail="scope">
        <div class="inline-16">
          <el-button type="text" size="mini" @click="openDetail(scope.data.data)">详情</el-button>
        </div>
      </template>
      <!-- 编辑 -->
      <template v-slot:edit="scope" v-if="tool.checkAuth($route.name, 'update')">
        <el-button slot="edit" type="text" size="small" class="inline-16" :disabled="scope.data.data.status == '审核'"
          @click="editData(scope.data.data)">编辑</el-button>
      </template>
      <!-- 发布 -->
      <template v-slot:release="scope" v-if="tool.checkAuth($route.name, 'release')">
        <release :data="scope.data.data" @onSuccess="onSuccess" />
      </template>
      <!-- 数据分析 -->
      <template v-slot:data_statistics="scope" v-if="tool.checkAuth($route.name, 'analysis')">
        <el-button type="text" size="small" @click="
                    $router.push({
                        path: '/archives_ad_analysis?id=' + scope.data.data.sat_sharematerialid
                    })
                ">数据统计</el-button>
      </template>
      <!-- 删除 -->
      <template v-slot:del="scope" v-if="tool.checkAuth($route.name, 'delete')">
        <on-del :data="scope.data.data" @onSuccess="onSuccess" />
      </template>
    </list>

    <detail ref="detail" v-if="currentFile && tool.checkAuth($route.name, 'read')" :currentSelectFile="currentFile">
    </detail>
  </div>
</template>

<script>
import Header from '@/SManagement/archives_upload/components/Header';//业务端上传
import save from '@/SManagement/archives_upload/components/save';

import list from './modules/list.vue';
import detail from '@/SManagement/archives_ad/components/detail'
import release from './modules/release.vue';
import onDel from './modules/delete.vue';
export default {
  name: "archives_adlist",
  components: { list, release, onDel, detail, Header, save },
  data () {
    return {
      currentFile: {}
    }
  },
  methods: {
    onSuccess () {
      this.$refs.list.getList();
    },
    /* 编辑素材 */
    editData (data) {
      window.sessionStorage.setItem('newMaterial', JSON.stringify(data));
      this.$router.push({
        path: '/upload_archives',
        query: {
          id: data.sat_sharematerialid
        }
      });
    },
    /* 打开详情 */
    openDetail (data) {
      let param = {
        "classname": "saletool.sharematerial.sharematerial",
        "method": "selectDetail",
        "content": {
          "sat_sharematerialid": data.sat_sharematerialid
        }
      }
      this.$api.requested(param).then(res => {
        res.data.attinfos = this.fileType.fileList(res.data.attinfos)
        this.currentFile = res.data
        this.$nextTick(() => {
          this.$refs.detail.isFileInfoPanlShow = true
        })
      })
    },

    async getAgentData () {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.courseware.statistics.agent",
        "method": "getAgentStudyData",
        "content": {
          "sat_coursewareid": this.$route.query.id
        }
      })
      this.pieStudyData = [{ type: '已学习', num: res.data.studyNum }, { type: '未学习', num: res.data.unStudyNum }]
      this.pieDownloadData = [{ type: '已下载', num: res.data.downloadNum }, { type: '未下载', num: res.data.unDownloadNum }]
      this.$refs.studyPie.piePlot.changeData(this.pieStudyData)
      this.$refs.downloadPie.piePlot.changeData(this.pieDownloadData)
    }
  }
}
</script>

<style scoped>
/deep/.header .left .el-button img {
  margin-left: -6px;
}
</style>