
<template>
  <div>
    <basicLayout 
      ref="basicLayout" 
      :oldFormPath="{
        add:'HManagement/archives_ad/modules',
      }"
      tableName="listTable" 
      idName="sat_sharematerialid" 
      :apiId="{query:20221102143102,del:20221102143602}" 
      :options="options"
      @listData="listData"
    >
      <div slot="custom">
      </div>
      <div slot="titleRight" style="display:flex;margin-left:10px">
      </div>
      <template v-slot:tbList="scope">
        <div v-if="scope.data.column.columnname === 'status'">
            <span :style="scope.data.column.data.status === '审核' ? 'color:#52C41A' : ''">{{
                scope.data.column.data.status == '审核' ? '发布' : scope.data.column.data.status
            }}</span>
          </div>
          <p v-else-if="scope.data.column.columnname === 'title'">
            【{{ getType(scope.data.column.data.type) }}】{{ scope.data.column.data.title }}
          </p>
        <div v-else>
          {{scope.data.column.data[[scope.data.column.columnname]]}}
        </div>
      </template>
      <template v-slot:tbOpreation="scope">
        <el-button class="inline-16" type="text" size="mini" @click="openDetail(scope.data.data)">详 情</el-button>
        <release :data="scope.data.data" @onSuccess="$refs.basicLayout.listData()" />
        <el-button v-if="tool.checkAuth($route.name,'update')" type="text" size="mini" :disabled="scope.data.data.status == '发布' || scope.data.data.status == '审核'" @click="EditBtn(scope.data.data)">编 辑</el-button>
        <el-button v-if="tool.checkAuth($route.name,'data_analysis')" type="text" class="inline-16" size="mini" @click="dataCalc(scope.data.data)">数 据 统 计</el-button>
        <on-del v-if="tool.checkAuth($route.name,'delete')" :disabled="scope.data.data.status == '发布' || scope.data.data.status == '审核'" :data="scope.data.data" @onSuccess="$refs.basicLayout.listData()" />
      </template>
    </basicLayout>
    <detail ref="detail" v-if="currentFile && tool.checkAuth($route.name, 'read')" :currentSelectFile="currentFile">
    </detail>
    <!--抽屉面板-->
    <el-drawer
      title="我是标题"
      :visible.sync="drawer"
      :with-header="false"
      direction="rtl"
      size="90%"
      append-to-body
      @close="closeDrawer">
      <div class="detail__panel">
        <router-view/>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import detail from '@/SManagement/archives_ad/components/detail'
import onDel from './modules/delete.vue'
import release from './modules/release.vue'

import {mapGetters} from 'vuex'
import { log } from '@antv/g2plot/lib/utils'


export default {
  components:{
    detail,
    onDel,
    release
  },
  data () {
    return {
      options:[
      ],
      currentFile: {},
      drawer:false
    }
  },
  watch: {
    $route (val) {
      if (val.path == '/archives_adlist') {
        this.$refs.basicLayout.listData()
      }
    },
    DrawerShow (val) {
      val ? this.drawer = true : this.drawer = false
    }
  },
  computed: {
    ...mapGetters({
      DrawerShow:'DrawerShow'
    })
  },
  methods:{
    closeDrawer () {
      this.$router.push('/archives_adlist')
      this.$store.dispatch('DrawerShowChange',false)
    },
    /* 新建的数据批量删除 */
    listData (data) {
      console.log(data);
      
      let initID = '9999' + JSON.parse(window.sessionStorage.getItem("active_account")).userid;
      let deleteList = [];
      data.forEach(v => (initID == v.sat_sharematerial_classid && v.title == '') ? deleteList.push(v.sat_sharematerialid) : '');
      if (deleteList.length != 0) this.handleDelete(deleteList);
    },
    /* 处理批量删除 */
    handleDelete(list) {
      this.$api.requested({
        "id": 20221102143602,
        "content": {
          "sat_sharematerialids": list
        }
      }).then(res => {
        console.log("处理删除", res);
        if (res.msg == '成功') this.$refs.basicLayout.listData()
      })
    },
    getType(type) {
      if (type == 1) {
        return '图片'
      } else if (type == 2) {
        return '视频'
      } else if (type == 3) {
        return '图文'
      }
    },
    /* 打开详情 */
    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
        })
      })
    },
    EditBtn (data) {
      this.$store.dispatch('pageOnlyRead',false)
      window.sessionStorage.setItem('newMaterial', JSON.stringify(data))
      this.$store.dispatch('DrawerShowChange',true)
      this.$router.push({path:'/upload_archives',query:{id:data.sat_sharematerialid}})
    },
    dataCalc (data) {
      window.sessionStorage.setItem('newMaterial', JSON.stringify(data))
      this.$store.dispatch('DrawerShowChange',true)
      this.$router.push({path:'/archives_ad_analysis',query:{id:data.sat_sharematerialid}})
    }
  }
}

</script>
<style>
</style>