<template>
    <el-container class="problem_list">
        <el-main style="padding: 10px 10px;">
            <div class="content_wrapper">
                <el-form ref="form" :inline="true" label-width="84px">
                    <el-form-item label="专业">
                        <el-select style="width:180px;" v-model="form.docId" clearable placeholder="请选择">
                            <el-option
                            v-for="item in professionList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item label="法规类别">
                        <el-select style="width:180px;" v-model="form.lawClass" clearable placeholder="请选择">
                            <el-option
                            v-for="item in lawClassList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item> -->
                    <el-form-item label="法规名称">
                        <el-input v-model="form.lawKeyword" clearable></el-input>
                    </el-form-item>
                    <el-form-item label="文号">
                        <el-input v-model="form.lawModify" clearable></el-input>
                    </el-form-item>
                    <div class="operate_btn">
                        <el-button style="margin-left:0;padding:7px 10px;" type="primary" @click="getlawsList()">查询</el-button>
                        <el-button style="margin-left:0;padding:7px 10px;" type="primary" @click="toAddLaws">添加</el-button>
                        <!-- <el-button style="margin-left:0;padding:7px 10px;" type="success" @click="exportExcel()">导出excel</el-button>
                        <el-button style="margin-left:0;padding:7px 10px;" type="success" @click="exportWord()">导出word</el-button> -->
                    </div>
                </el-form>
                <el-table
                    :data="tableData"
                    border
                    stripe
                    v-loading='loading'
                    :height="tableHeight"
                    style="width: 100%">
                    <el-table-column
                    prop="id"
                    label="序号"
                    min-width="40">
                        <template #default="scope">
                            {{(pageIndex - 1) * pageSize + (scope.$index + 1)}}
                        </template>
                    </el-table-column>
                    <el-table-column
                    prop="lawTitle"
                    label="类别"
                    show-overflow-tooltip
                    min-width="120">
                    </el-table-column>
                    <el-table-column
                    prop="lawKeyword"
                    label="名称"
                    show-overflow-tooltip
                    min-width="180">
                    </el-table-column>
                    <el-table-column
                    prop="lawModify"
                    label="文号"
                    show-overflow-tooltip
                    min-width="180">
                    </el-table-column>
                    <el-table-column
                    label="操作"
                    width="180">
                    <template #default="scope">
                        <el-button type="text" size="small" @click="editProvision(scope.row)">编辑</el-button>
                        <el-button type="text" size="small" @click="toShowProvision(scope.row)">查看条款</el-button>
<!--                        <el-button @click="downloadlaw(scope.row)" type="text" size="small">下载</el-button>-->
                        <el-button @click="deleteLaw(scope.row)" type="text" size="small">删除</el-button>
<!--                        <el-button  type="text" size="small">替换</el-button>-->
                    </template>
                    </el-table-column>
                </el-table>
                <el-pagination style="margin-left: 30px;" :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>
            </div>
            <add-law-com v-if="addFileVisiual" :currentNodeId="currentNodeId" :objId="objId" :listType="type" :pertype="pertype" @dialogClose="dialogClose"></add-law-com>
            <edit-law-com v-if="editFileVisiual" :rowData="rowData"  @dialogClose="dialogCloseEdit"></edit-law-com>
            <provision-view v-if="showProvision" :rowData="rowData" @dialogClose="dialogClose"></provision-view>
            <export-excel v-if="exportEvent" @dialogClose="dialogClose" :currentNodeId="currentNodeId" :listType="type"></export-excel>
            <export-word v-if="exportWordDialog" @dialogClose="dialogClose" :problemId="problemId" :professionType="type"></export-word>
        </el-main>
    </el-container>
</template>
<script>
import request from '@/utils/gw_ajax_request.js'
import { hostUrl } from "@/utils/global_variable.js";
import addLawCom from './dialogCom/addInspectionLaw.vue'
import editLawCom from './dialogCom/editInspectionLaw.vue'
import provisionView from './dialogCom/provisionView.vue'
import ProblemModifyCom from './dialogCom/addInspectionProblem.vue'
import editProblemClass from './dialogCom/editProblemClass.vue'
import ExportExcel from './dialogCom/ExportExcel.vue'
import ExportWord from './dialogCom/ExportWord.vue'
export default {
    props:[],
    data(){
        return{
            currentNodeId:"",
            pertype:"",
            problemId:"",
            form:{
                docId: '',
                lawKeyword: '',
                lawModify: ''
            },
            professionList:[
                {label: '综合法规',value: '0'},
                {label: '前期与设计',value: '1'},
                {label: '建设管理',value: '2'},
                {label: '计划下达与执行',value: '3'},
                {label: '资金使用与管理',value: '4'},
                {label: '工程质量',value: '5'},
                {label: '工程安全',value: '6'},
                {label: '新增法规',value: '7'}
            ],
            lawClassList:[
                {label: '全部',value: '1'},
                {label: '法律',value: '2'},
                {label: '部门规章',value: '3'},
                {label: '规范性文件',value: '4'},
                {label: '规程规范',value: '5'}
            ],
            tableData: [],
            pageIndex: 1,
            pageSize: 20,
            total: 0,
            loading: false,
            addFileVisiual: false,
            editFileVisiual: false,
            modifyFileVisiual: false,
            exportEvent: false,//导出对话框v-if
            exportWordDialog: false,
            name: '',
            tableHeight: window.innerHeight - 200,
            dialogFormVisible: false,
            showProblemClass: false,
            showProvision: false,
            rowData: {}
        }
    },
    components:{
        addLawCom,
        editLawCom,
        provisionView,
        ProblemModifyCom,
        ExportExcel,
        ExportWord,
        editProblemClass
    },
    computed: {
        persId() {
            return localStorage.getItem("userid") ? localStorage.getItem("userid") : "1098101939614724096";
        },
        hostUrl(){
            return hostUrl
        }
    },
    mounted(){
        this.getlawsList()
    },
    activated(){
    },
    methods:{
        getlawsList(){
            this.loading = true
            let paramsObj = {
                pageSize: this.pageSize,
                pageNum: this.pageIndex,
                lawKeyword: this.form.lawKeyword,
                lawModify: this.form.lawModify,
                docId: this.form.docId
            }
            request.post(`/tac/slb/law/index/page`,paramsObj).then(res=>{
                if(res.success){
                    this.loading = false
                    this.tableData = res.data.list
                    this.total = res.data.total
                }else{
                    this.loading = false
                    this.$message.error(res.message)
                }
            }).catch(err=>{
                this.$message.error(err)
            })
        },
        toAddLaws(){
            this.addFileVisiual = true
        },
        //导出Excel
        exportExcel(){
            this.exportEvent = true
        },
        //导出Word
        exportWord(){
            this.exportWordDialog = true
        },
        toEditProblem(row){
            this.problemId = row.id
            this.modifyFileVisiual = true
        },
        deleteLaw(row){
            this.$confirm('确认删除该法规吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                request.get(`/tac/slb/law/index/del/${row.id}`).then(res=>{
                    if(res.success){
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.getlawsList()
                    }else{
                        this.$message({
                            type: 'error',
                            message: res.message
                        });
                    }
                })
            })
        },
        downloadlaw(row){
            this.$confirm('确认下载该法规吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                request.get(`/tac/slb/law/index/doc/${row.id}`).then(res=>{
                    if(res.success){
                        window.open(`${this.hostUrl}${res.data.downloadPath}`)
                    }else{
                        this.$message({
                            type: 'error',
                            message: res.message
                        });
                    }
                })
            })
        },
        pageIndexChange(val) {
            this.pageIndex = val;
            this.getlawsList();
        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.getlawsList();
        },
        dialogClose(){
            this.addFileVisiual = false
            this.modifyFileVisiual = false
            this.exportEvent = false
            this.exportWordDialog = false
            this.showProvision = false
            this.getlawsList()
        },
        dialogCloseEdit(){
            this.editFileVisiual = false
            this.modifyFileVisiual = false
            this.exportEvent = false
            this.exportWordDialog = false
            this.showProvision = false
            this.getlawsList()
        },
        handleSelectionChange(val){
            let problemArr = []
            val.forEach(ele=>{
                problemArr.push(ele.id)
            })
            this.problemId = problemArr.join(',')
        },
        toShowProvision(row){
            Object.assign(this.rowData,row)
            this.showProvision = true
        },
        editProvision(row){
            Object.assign(this.rowData,row)
            this.editFileVisiual = true
        }
    },
    watch:{
    }
}
</script>
<style >
    .problem_list{
        .project_title{
            line-height: 50px;
            text-align: center;
            color: #333;
            border-bottom: solid 1px #eee;
        }
        h4{
            line-height: 50px;
            color: #444;
        }
        .operate_btn{
            float: right;
            margin-bottom: 10px;
        }
        .el-form-item__label{
            font-size: large;
            color: #333;
        }
        .el-form--inline .el-form-item{
            margin-right: 6px;
        }
        .el-table__header th{
            font-size: large !important;
        }
        tr.el-table__row{
            font-size: large;
        }
    }
</style>


