<template>
    <el-container class="base_info">
        <el-main style="padding:0 10px;">
            <!-- 类型：{{type}}
            工程ID：{{currentNodeId}} -->
            <!-- <h3 class="project_title">前期与设计专业稽察工作底稿</h3> -->
            <div class="content_wrapper">
                <!-- <h4>基本情况</h4> -->
                <el-form ref="form" :model="baseInfo" label-position="top">
                    <!-- <el-form-item label="项目名称：">
                        <span>{{projectName}}</span>
                    </el-form-item> -->
                    <el-form-item label="基本情况：" >
                        <Editor id="condition" v-model="baseInfo.itmeDesc" :init="editorInit" :disabled="disabled" v-if="showThisEd"></Editor>
                    </el-form-item>
                    <el-form-item label="评价：">
                        <Editor id="comment" v-model="baseInfo.itmeEval" :init="commentInit" :disabled="disabled" v-if="showThisEd"></Editor>
                    </el-form-item>
                    <el-form-item label="稽察组长复核意见：">
                        <Editor id="suggest" v-model="baseInfo.revOpin" :init="suggestInit" v-if="showThisEd"></Editor>
                    </el-form-item>
                    <el-form-item v-if="ownPriv('manage')">
                        <el-button style="font-size:large;" type="primary" @click="onSubmit">保存</el-button>
                        <el-button style="font-size:large;">取消</el-button>
                    </el-form-item>
                    <el-form-item label="查阅的资料目录：">
                        <p class="add_file_btn" @click="toAddFile" v-if="ownPriv('manage')">+ 添加资料</p>

                        <p class="add_file_btn" @click="showPlDialog" v-if="ownPriv('manage')">+ 批量添加</p>
                        <ZiLiaoTianBaoPl v-if="showTianBaoPl"
                            :listId="baseInfo.id"
                            @closePlDialog="closePlDialog"
                        >
                        </ZiLiaoTianBaoPl>

                        <el-table class="insTale"
                            :data="tableData"
                            border
                            style="width: 100%">
                            <el-table-column
                            prop="catalogName"
                            label="资料名称"
                            >
                            </el-table-column>
                            <el-table-column
                            prop="estUnit"
                            label="编制单位"
                            >
                            </el-table-column>
                            <el-table-column
                            prop="estTm"
                            label="编制时间"
                            width="200">
                            </el-table-column>
                            <el-table-column
                            fixed="right"
                            label="操作"
                            width="130"
                            v-if="ownPriv('manage')"
                            >
                            <template #default="scope">
                                <el-button @click="toEditFile(scope.row)"  type="text" size="small">编辑</el-button>
                                <el-button @click="deleteFile(scope.row)" type="text" size="small">删除</el-button>
                            </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination :pager-count="5" :current-page="pageIndex" background
                        :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
                        :page-sizes="[10, 20, 50, 100]"
                        @current-change="pageIndexChange" @size-change="handleSizeChange"
                        ></el-pagination>
                    </el-form-item>
                </el-form>
            </div>
            <add-file-com v-if="addFileVisiual" :listId="baseInfo.id" @dialogClose="dialogClose"></add-file-com>
            <file-modify-com v-if="modifyFileVisiual" :fileId="fileId" @dialogClose="dialogClose"></file-modify-com>
        </el-main>
    </el-container>
</template>
<script>
import request from '@/utils/gw_ajax_request.js'
import {getBaseInfoApi,submitBaseInfoApi,getFileListApi,deleteFileApi} from '@/api/InspectionReport.js'
import addFileCom from './dialogCom/addFileCom.vue'
import fileModifyCom from './dialogCom/fileModifyCom.vue'
import tinymce from 'tinymce/tinymce'
import 'tinymce/themes/silver/theme'
import Editor from '@tinymce/tinymce-vue'
import 'tinymce/plugins/image'
import 'tinymce/plugins/link'
import 'tinymce/plugins/code'
import 'tinymce/plugins/table'
import 'tinymce/plugins/lists'
import 'tinymce/plugins/wordcount'
import ZiLiaoTianBaoPl from './ziliao_tianbao_piliang.vue'
export default {
    props:['currentNodeId','type','projectName','pertype','backStatus'],
    data() {
        return {
            baseInfo:{
                itmeDesc:'',
                itmeEval: '',
                revOpin: '',
                persId: '',
                type: '',
                rgstrId: ''
            },
            editType: '', //是添加还是修改
            tableData: [],
            editorInit: {
                selector: 'condition',
                language_url: '/static/tinymce/zh_CN.js',
                language: 'zh_CN',
                skin_url: '/static/tinymce/skins/ui/oxide',
                plugins: 'wordcount',
                height: window.innerHeight - 250,
                toolbar:
                'bold italic underline strikethrough fontselect fontsizeselect forecolor backcolor | removeformat',
                branding: false
            },
            commentInit: {
                selector: 'comment',
                language_url: '/static/tinymce/zh_CN.js',
                language: 'zh_CN',
                skin_url: '/static/tinymce/skins/ui/oxide',
                plugins: 'wordcount',
                height: window.innerHeight - 250,
                toolbar:
                'bold italic underline strikethrough fontselect fontsizeselect forecolor backcolor | removeformat',
                branding: false
            },
            suggestInit: {
                selector: 'suggest',
                language_url: '/static/tinymce/zh_CN.js',
                language: 'zh_CN',
                skin_url: '/static/tinymce/skins/ui/oxide',
                plugins: 'wordcount',
                height: 300,
                toolbar:
                'bold italic underline strikethrough fontselect fontsizeselect forecolor backcolor | removeformat',
                branding: false
            },
            disabled: false,
            showThisEd: true,
            fileId: '', //资料id
            addFileVisiual: false,
            modifyFileVisiual: false,
            pageIndex: 1,
            pageSize: 10,
            total: 0,
            showTianBaoPl: false,
        }
    },
    computed: {
        persId() {
            return localStorage.getItem("userid") ? localStorage.getItem("userid") : "1098101939614724096";
        },
    },
    components:{
        addFileCom,
        fileModifyCom,
        Editor,
        ZiLiaoTianBaoPl
    },
    mounted(){
        this.getBaseInfo()
        //富文本初始化
        tinymce.init({})
        if(this.pertype == 20){
            this.disabled = true
        }
    },
    activated(){
        tinymce.init({})
        this.showThisEd = true
    },
    deactivated(){
        this.showThisEd = false
    },
    methods:{
        //获取单表基本信息
        getBaseInfo(){
            getBaseInfoApi(this.type,this.currentNodeId).then(res=>{
                if(res.data && Object.keys(res.data).length){
                    this.editType = '修改'
                    this.baseInfo = res.data
                    this.getFileList()
                }else{
                    this.editType = '添加'
                    this.baseInfo.persId = this.persId
                    this.baseInfo.type = this.type
                    this.baseInfo.rgstrId = this.currentNodeId
                    this.baseInfo.itmeDesc = ''
                    this.baseInfo.itmeEval = ''
                    this.baseInfo.revOpin = ''
                    if(this.baseInfo.id) delete this.baseInfo.id
                    this.getFileList();
                }
            }).catch(err=>{
                this.$message.error(err)
            })
        },
        //保存填写的基本信息
        onSubmit(){
            if(this.baseInfo.revOpin && this.baseInfo.revOpin.length>500){
                this.$message.error('稽察组长复核意见过长');
                return ;
            }
            submitBaseInfoApi(this.baseInfo).then(res=>{
                if(res.success){
                    this.$message.success(`${this.editType}成功`)
                    this.getBaseInfo()
                }
            }).catch(err=>{
                this.$message.error(err)
            })
        },
        //展示添加资料弹窗
        toAddFile(){
            if(!this.baseInfo.id){
                this.$message.warning('请先填写基本情况并保存')
                return
            }
            this.addFileVisiual = true
        },
        //展示修改资料弹窗
        toEditFile(row){
            this.fileId = row.id
            this.modifyFileVisiual = true
        },
        //获取查阅的资料目录
        getFileList(){
            if(!this.baseInfo.id){
                this.tableData = []
                return
            }
            let paramsObj = {
                listId: this.baseInfo.id,
                persId: this.persId,
                pageNum: this.pageIndex,
                pageSize: this.pageSize
            }
            getFileListApi(paramsObj).then(res=>{
                if(res.success){
                    this.tableData = res.data.list
                    this.total = res.data.total
                }
            }).catch(err=>{
                this.$message.error(err)
            })
        },
        deleteFile(row){
            this.$confirm('确认删除该问题吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteFileApi(row.id).then(res=>{
                    if(res.success){
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.getFileList()
                    }else{
                        this.$message({
                            type: 'error',
                            message: res.message
                        });
                    }
                })
            })
        },
        dialogClose(){
            this.getFileList()
            this.addFileVisiual = false
            this.modifyFileVisiual = false
        },
        pageIndexChange(val) {
            this.pageIndex = val;
            this.getFileList();
        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.getFileList();
        },
        showPlDialog() {
            if(!this.baseInfo.id){
                this.$message.warning('请先填写基本情况并保存')
                return
            }
            this.showTianBaoPl = true;
        },
        closePlDialog(val) {
            this.getFileList();
            this.showTianBaoPl = false;

        }
    },
    watch:{
        currentNodeId(){
            this.getBaseInfo()
        },
        type(){
            this.getBaseInfo()
        },
        pertype(val){
            if(val == 20){
                this.disabled = true
            }
        },
        backStatus(val){
            if(val){
                this.getBaseInfo()
            }
        }
    }
}
</script>
<style>
    .base_info{
        .project_title{
            line-height: 50px;
            text-align: center;
            color: #333;
            border-bottom: solid 1px #eee;
        }
        .content_wrapper{
            height: calc(100vh - 190px;);
            overflow-y: auto;
        }
        h4{
            line-height: 50px;
            color: #444;
        }
        .add_file_btn{
            line-height: 30px;
            text-align: center;
            color: #666;
            border: dashed 1px #ddd;
            border-radius: 5px;
            margin-bottom: 10px;
            cursor: pointer;
            font-size: large;
        }
        .el-form-item__label{
            font-size: large;
        }
        .insTale{
            .el-table th.gutter{
            display: table-cell!important;
            }
            /*滚动条样式*/
            ::-webkit-scrollbar {
            width: 8px;
            height: 8px;
            }
            /*正常情况下滑块的样式*/
            ::-webkit-scrollbar-thumb {
            background-color: #cdcdcd;
            border-radius: 10px;
            -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
            }
            /*鼠标悬浮在滑块上时滑块的样式*/
            ::-webkit-scrollbar-thumb:hover {
            background-color: rgba(0, 0, 0, .4);
            -webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
            }
            /*正常时候的主干部分*/
            ::-webkit-scrollbar-track {
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
            background-color: white;
            }
            /*鼠标悬浮在滚动条上的主干部分*/
            ::-webkit-scrollbar-track:hover {
            -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .4);
            background-color: rgba(0, 0, 0, .01);
            }
            /*el-table thead默认样式更改*/
            .el-table__header th,.el-table__header tr{
            background: rgba(235,243,251,1)!important;
            box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.1), -1px 0 0 0 rgba(0, 0, 0, 0.1), 0 1px 0 0 rgba(0, 0, 0, 0.1) !important;
            font-size: large !important;
            font-family: MicrosoftYaHei;
            font-weight: 400 !important;
            color: rgba(51,51,51,1);
            }
            tr.el-table__row {
            font-size:large;
            font-family:MicrosoftYaHei;
            font-weight:400;
            color:rgba(51,51,51,1);
            }
        }
    }
</style>
