<template>
  <normalLayout @onRefresh="closeDrawer">
    <div slot="titleRight">
      <el-button type="primary" plain size="small" @click="export1" v-if="tool.checkAuth($route.name,'export')">导出</el-button>
    </div>
    <div slot="refresh">
      <i class="el-icon-refresh" @click="refresh"></i>
<!--      <el-button  icon="el-icon-refresh" @click="refresh"></el-button>-->
    </div>
    <div slot="content">
      <div class="personal-target">
        <div class="container normal-panel">
          <table1 ref="table" :data="hrid">
            <template v-slot:detail="scope">
              <el-button v-if="tool.checkAuth($route.name,'read')  && scope.data.data.hrid != hrid" type="text" size="small" @click="$store.dispatch('changeDetailDrawer',true),$router.push({path:'/projectDetail',query:{id:scope.data.data.sa_salestargetbillid,hrid:scope.data.data.hrid,year:scope.data.year,ownerHrid:hrid}})">详 情</el-button>
              <el-button v-if="tool.checkAuth($route.name,'read') && scope.data.data.status !== '新建' && scope.data.data.hrid == hrid" type="text" size="small" @click="$store.dispatch('changeDetailDrawer',true),$router.push({path:'/projectDetail',query:{id:scope.data.data.sa_salestargetbillid,hrid:scope.data.data.hrid,year:scope.data.year,ownerHrid:hrid}})">详 情</el-button>
              <el-button v-if="tool.checkAuth($route.name,'read') && scope.data.data.status === '新建' && scope.data.data.hrid == hrid" type="text" size="small" @click="$store.dispatch('changeDetailDrawer',true),$router.push({path:'/projectDetail',query:{id:scope.data.data.sa_salestargetbillid,hrid:scope.data.data.hrid,year:scope.data.year,ownerHrid:hrid}})">编 辑</el-button>
<!--              <el-button v-if="tool.checkAuth($route.name,'update') && scope.data.data.status === '新建' " type="text" size="small" @click="$store.dispatch('DrawerShowChange',true),$router.push({path:'/editProjectInfo',query:{id:scope.data.data.hrid,year:scope.data.year}})">编辑</el-button>-->
            </template>
          </table1>
        </div>
        <!--抽屉面板-->
<!--        <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>
    </div>
  </normalLayout>

</template>

<script>
import {mapGetters} from 'vuex'

import Header from '@/SManagement/archives_upload/components/Header';
import table1 from './components/table'
export default {
  name: '',
  data() {
    return {
      drawer:false,
      session:[],
      hrid:''
    };
  },
  components: { Header , table1},
  watch: {
    $route (val) {
      if (val.path == '/sm_projectTarget') {
        this.$refs.table.queryData()
      }
    },
    DrawerShow (val) {
      val ? this.drawer = true : this.drawer = false
    }
  },
  computed: {
    ...mapGetters({
      DrawerShow:'DrawerShow'
    })
  },
  created() {
    console.log('执行')
    this.session = sessionStorage.getItem('active_account')
    /*var  r = "{'msg':'你好'}" ;*/
    const map = eval("("+this.session+")"); //r为String类型的数据
   /* const xx = map.msg;  //此时 xx 的值为 你好*/
    console.log(map.hrid)
    this.hrid = map.hrid
  },
  methods: {
    closeDrawer () {
      this.$router.push('/sm_projectTarget')
      this.$store.dispatch('DrawerShowChange',false)
    },
    async export1() {
      if(!Object.keys(this.$refs.table.tableData).length > 0) return
      let res = await this.$api.requested({
        "id": 20220916160002,
        "content": {
            "row": this.$refs.table.tableData
        }
      })
      this.tool.showMessage(res,() => {
        console.log(res)
        window.open(res.data,'_self')
      })
    },
    refresh(){
     this.$refs.table.queryData()
    }
  },
};
</script>

<style scoped>

</style>
