<template>
<div class="p20">
  <div class="d-flex border-bottom-1 pb15">
    <div class="flex-1 w-80">
      <h3 class="font-size-24">{{detailInfo.wwj_title}}</h3>
      <div class="font-size-16 color-6" v-html="detailInfo.wwj_content">
      </div>
    </div>
    <div class="flex-1">
      <div id="boxChart" style="height: 400px"></div>
      <div class="text-center">
        <el-button type="primary" size="small" @click="toRemind">
          <span class="d-in-block v-mid icon-info-message mr5"></span>
          <span class="d-in-block v-mid font-size-14">提醒</span>
        </el-button>
      </div>

    </div>
  </div>
  <el-table :data="tableData" class="mt15" style="width: 100%">
<!--    <el-table-column-->
<!--        type="selection"-->
<!--        align="center"-->
<!--        width="55">-->
<!--    </el-table-column>-->
    <el-table-column
        label="文件"
        show-overflow-tooltip
        width="auto">
      <template slot-scope="scope">
        <span class="el-icon-document font-size-18"></span>
        <span class="ml5">{{ scope.row.wwj_title }}</span>
      </template>
    </el-table-column>
    <el-table-column
        label="上传者"
        width="100"
        prop="wwj_scr"
    ></el-table-column>
    <el-table-column
        label="时间"
        width="150"
        prop="www_scsj"
        align="center"
    ></el-table-column>
    <el-table-column label="操作" width="80">
      <template slot-scope="scope" >
        <el-button
            type="text"
            @click="toDetail(scope.row)"
        >查看</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-button class="mt15" type="primary" @click="exportData">批量下载</el-button>
  <el-dialog title="超期提醒" :visible.sync="remindFormVisible" width="750px">
    <el-form :model="remindForm" label-width="100px">
      <el-form-item label="收集对象" prop="sjdx">
        <el-cascader style="width: 100%;" v-model="remindForm.sjdx"
                     :options="defaultData"
                     :props="props" :show-all-levels="false"
                     clearable></el-cascader>
      </el-form-item>
      <el-form-item label="附加消息" prop="content">
        <Tinymce v-if="remindFormVisible" v-model="remindForm.fjxx" :key="timestamp" :height="300"></Tinymce>
      </el-form-item>


    </el-form>
    <div slot="footer">
      <el-button @click="remindFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="remindSubmit">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
import {wfqd_detail,org_list_tree,wfqd_list_detail} from "./api";
import * as echarts from 'echarts';
import Tinymce from "@/components/TinymceVue/index.vue";
import FileUpload from "@/components/FileUpload/index.vue";
import { useUserStore } from "@/stores/user";
const { token,real_name } = useUserStore();
export default {
  name: "index",
  components:{
    Tinymce,
    FileUpload
  },
  data() {
    return {
      wwj_id:'',
      tableData:[{
        id:'1',
        wjm:'党委办公室申请材料',
        scz:'上传者',
        sj:'2022/01/20',
      },{
        id:'2',
        wjm:'后勤处申请材料',
        scz:'上传者',
        sj:'2022/01/20',
      },{
        id:'1',
        wjm:'党委办公室申请材料',
        scz:'上传者',
        sj:'2022/01/20',
      },{
        id:'3',
        wjm:'安保处申请材料',
        scz:'上传者',
        sj:'2022/01/20',
      }],
      multipleSelection: [],
      detailInfo:{},
      remindFormVisible:false,
      remindForm:{
        sjdx:[],
        fjxx:''
      },
      timestamp: Date.now(),
      props: {
        multiple: true,
        value:'id',
        label:'label',
        checkStrictly: true,
        expandTrigger: 'hover'
      },
      defaultData:[],
    }
  },
  methods:{
    getOrgTree() {
      let data = {}
      org_list_tree(data).then(res => {
        if (res.code == 1) {
          this.defaultData = res.data.one_info;
        }
      })
    },
    getDetail() {
      let data = {
        wwj_id: this.wwj_id
      }
      wfqd_detail(data).then(res =>{
        if(res.code == 1) {
          this.detailInfo = res.data.one_info;
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    boxChart() {
      var chartDom = document.getElementById('boxChart');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: 'item',
          formatter: '{b} '
        },
        series: [{
            type: 'pie',

            label: {
              position: 'outside',
              fontSize: 14
            },
            data: [
              { value: 40, name: '未提交单位' },
              { value: 60, name: '已提交单位'}
            ],
            color:['#c2c2c2',{
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                offset: 0, color: '#0036FF' // 0% 处的颜色
              }, {
                offset: 1, color: '#76CDFB' // 100% 处的颜色
              }],
              global: false // 缺省为 false
            }],
          },
          {
            type: 'pie',
            label: {
              show: true,
              position: 'inside',
              formatter:`{d}%`,
              fontSize: 14,
              color:'#fff'
            },
            data: [
              { value: 40, name: '财务部 办公室 安全科'},
              { value: 60, name: '党委办公室 后勤部 安保处 教育课 基建管理科'}
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            color:['#c2c2c2',{
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                offset: 0, color: '#0036FF' // 0% 处的颜色
              }, {
                offset: 1, color: '#76CDFB' // 100% 处的颜色
              }],
              global: false // 缺省为 false
            }],
          }
        ]
      };

      option && myChart.setOption(option);
    },
    toRemind() {
      this.remindFormVisible = true;
      this.remindForm.sjdx = '';
      this.remindForm.fjxx = '';
    },
    remindSubmit() {
      let data = {
        jsdx:this.remindForm.sjdx,
        content:this.remindForm.fjxx
      }
      remind_add(data).then(res =>{
        if(res.code == 1) {
          this.$message({
            message: "提醒发送成功！",
            type: "success",
          });
          this.remindFormVisible = false;
        }
      })
    },
    getListDetail() {
      let data = {
        wwj_id_pid: this.wwj_id
      }
      wfqd_list_detail(data).then(res =>{
        if(res.code == 1) {
          this.tableData = res.data.page_data;
        }
      })
    },
    toDetail(item) {
      window.open(item.wwj_wjlj,'_self');
    },
    exportData() {
      let link =
          window.globalVariables.api +
          "/jdbg/wjsj_wjgzt_detail/index?api=xls&page=1&limit=10000&token=" +
          token;
      window.open(link, "_self");
    }
  },
  mounted() {
    this.getOrgTree();
    if(this.$route.params.id != '') {
      this.wwj_id = this.$route.params.id;
      this.getDetail();
      this.getListDetail();
    }
    this.boxChart();
  }
}
</script>

<style lang="scss" scoped>
.el-button--text{
  color:#4351FF;
}
.icon-info-message{
  width: 13px;
  height: 16px;
  background: url("@/assets/icon-message.png") center no-repeat;
  background-size: 13px 16px;
}
</style>
