<style lang="scss">
    .preview{
        .el-form-item{
            margin-bottom:15px;
        }
        label,p{
            line-height: 25px !important;
        }
    }
</style>
<template>
    <section>
        <p>中科院全刊</p>
        <div class="content">
            <div class="filter">
                <el-form size="small" label-width="70px" :inline="true"  label-position="left">
                    <el-form-item label="">
                            <el-input clearable placeholder="请输入信息标题" v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button  type="primary">搜索</el-button>
                    </el-form-item>
                    <el-form-item style="float:right" >
                        <el-button @click="dialogVisible=true,edit=0" type="primary">发送消息</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table
                    class="table"
                    :data="list" height="50vh"
                    border  v-loading="loading"
                    default-expand-all row-key="id"
                    style="width: 100%">
                    <el-table-column
                    prop="name"  width="300"
                    label="标题">
                    </el-table-column>
                    <el-table-column
                    prop="username"  
                    label="发送者">
                    </el-table-column>
                    <el-table-column
                    prop="area" 
                    label="接收者">
                    </el-table-column>
                    <el-table-column
                    prop="area" 
                    label="发送时间">
                    </el-table-column>
                    <el-table-column  
                    prop="zip"  width="150"
                    label="操作">
                    <template slot-scope="">
                        <el-button type="text" @click="dialogVisible=true,edit=1">查看</el-button>
                        <el-button class="edit" type="text" @click="dialogVisible=true,edit=0">编辑</el-button>
                        <el-button class="del" @click="del" type="text">删除</el-button>
                    </template>
                    </el-table-column>
            </el-table>
            <Page  ref="pageButton" :current='form.page' :page_size='form.page_size' :total='total' @pageChange='gopage'/>
        </div>

        <el-dialog
        title="发送通知消息" :close-on-click-modal='false'
        :visible.sync="dialogVisible">
        <el-form size="small" class="preview" :inline='false' label-width="80px">
                <el-form-item label="标题">
                    <p v-if='edit'>关于集中使用期刊公众号的通知</p>
                    <el-input v-else v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="消息内容">
                    <p v-if='edit'>
                        关于集中使用期刊公众号的通知关于集中使用期刊公众号的通知
                        关于集中使用期刊公众号的通知关于集中使用期刊公众号的通知
                        关于集中使用期刊公众号的通知关于集中使用期刊公众号的通知
                    </p>
                    <el-input v-else v-model="form.name" type="textarea"></el-input>
                </el-form-item>
                <el-form-item label="文件">
                    <p v-if='edit'>
                        <el-link type="primary">关于集中使用期刊公众号的通知.docx</el-link><br>
                        <el-link type="primary">关于集中使用期刊公众号的通知.docx</el-link>
                    </p>
                    <el-button v-else class="upload_btn" plain type="primary">选择文件 <input type="file"></el-button>
                </el-form-item>
                <el-form-item label="接收人">
                    <el-input placeholder="请输入内容" v-model="input" class="input-with-select">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                    <el-tree
                    :data="data"
                    show-checkbox
                    node-key="id" default-expand-all
                    :props="defaultProps">
                    </el-tree>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" type="primary" @click="dialogVisible = false">确 定</el-button>
        </span>
        </el-dialog>
    </section>
</template>
<script>
import Page from '../../components/Page';
export default {
  components:{
        Page
  },
  data(){
    return{
      edit:0,
      form:{name:'',page:1,page_size:20},
      total:1,
      list:[{name:'2333'}],
      loading:false,
      input:'',
      dialogVisible:false,
      defaultProps:{},
      data: [{
          id: 1,
          label: '一级 1'
        }, {
          id: 2,
          label: '一级 2',
          children: [{
            id: 5,
            label: '二级 2-1'
          }, {
            id: 6,
            label: '二级 2-2'
          }]
        }],
    }
  },
  methods:{
        gopage(size){
            if(size){
                this.form.page_size=size
            }
            this.form.page=this.$refs.pageButton.page
            this.getData()
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        gopage1(size){
            if(size){
                this.form1.page_size=size
            }
            this.form1.page=this.$refs.pageButton1.page
            this.getJl()
        },
        open(data) {
            this.dialogFormVisible=true;
            this.message={...data}
        },
        download(){
            let array=this.multipleSelection,ids=[];
            for(let i=0;i<array.length;i++){
                ids.push(array[i].id)
            }
            ids=ids.join(',')
            this.$api.downloadMon({ids:ids}).then(res=>{
                        var elink = document.createElement('a');
                        let blob=new Blob([res.data], {type: 'application/vnd.ms-excel'});
                        let objUrl=URL.createObjectURL(blob);
                        console.log(res.headers['content-disposition'])
                        let file_name=res.headers['content-disposition'].split('=')[1];
                        elink.download = file_name;
                        elink.style.display = 'none';                
                        elink.href = objUrl;
                        document.body.appendChild(elink);
                        elink.click();
                        document.body.removeChild(elink);     
            })
        },
        prview(id){
            this.form1.enterprise_id=id;
            this.getJl();
            this.dialogFormVisible1=true
        },
        getJl(){
            var parm=this.form1;
            this.$api.getMonitjobList(parm).then(res=>{
                this.data=res.data.data.list
                this.total1=res.data.data.total
                
            })
        },
        detail(id){
            this.$router.push({ path: '/company/detail', query: {  id: id,page:this.form.page,page_size:this.form.page_size  } });
        },
        getData(){
            var parm=this.form;        
            this.loading=true
            this.$api.getEnterpriseList(parm).then(res=>{
                this.list=res.data.data.list;
                // list.forEach(item => {
                //     if(item.children.length>0){
                //         item.hasChildren=true
                //     }else{
                //         item.hasChildren=false
                //     }
                // });
                this.total=res.data.data.total
                this.loading=false
                this.area=this.store.area;
                this.category=this.store.categorys;
            })
        },
        del(id){
                this.$confirm('确定删除吗', '提示', {
                        type: 'warning'
                    }).then(() => {
                    this.$api.deleteEnterprise({id:id}).then((res)=>{
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            })
                            this.getData()
                    })
                })
        },
        permission(name){
			let permissions=this.info.permissions||[];
			let list=[];
			for(let i=0;i<permissions.length;i++){
				list.push(permissions[i].name)
			}
			if(list.indexOf(name)<0){
				return false;
			}else{
				return true;
			}	
		},
  },
  created(){
      
  }
}
</script>
