<template>
    <el-dialog :title="'编辑法规'" @close="closeDialog" v-model="dialogFormVisible">
        <el-form :model="form" :rules="rules" ref="form" label-width="100px">
            <el-form-item label="法规名称" prop="lawKeyword">
                <el-input v-model="form.lawKeyword" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="法规文号" prop="lawModify">
                <el-input v-model="form.lawModify" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="专业" prop="docId">
                <el-select style="width:180px;" v-model="form.docId" 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.lawType" placeholder="请选择问题大类">
                    <el-option
                    v-for="item in lawTypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item> -->
            <el-form-item label="法规内容" prop="bookContent">
              <el-input
                type="textarea"
                :autosize="{ minRows: 5, maxRows: 10}"
                placeholder="请输入法规内容"
                v-model="form.bookContent">
              </el-input>
            </el-form-item>
<!--            <el-form-item label="附件">-->
<!--                <upload-->
<!--                    ref="uploadFile"-->
<!--                    :url="`/pdcApi/file/insert?bizId=`"-->
<!--                    @uploadOver="removeNewSupervision"-->
<!--                ></upload>-->
<!--            </el-form-item>-->
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="closeDialog">取 消</el-button>
            <el-button type="primary" @click="addLaw">保 存</el-button>
        </div>
    </el-dialog>
</template>
<script>
import request from '@/utils/gw_ajax_request.js'
export default {
    props:['rowData'],
    data(){
        return{
            form: {
                lawKeyword: '',
                lawModify: '',
                docId: '',
                lawType: '',
                bookContent:'',
                gwComFile: []
            },
            dialogFormVisible: true,
            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'}
            ],
            lawTypeList:[
                {label: '法律',value: '1'},
                {label: '部门规章',value: '2'},
                {label: '规范性文件',value: '3'},
                {label: '规程规范',value: '4'}
            ],
            gwComFileList: [],
            rules: {
                lawKeyword: [
                    { required: true, message: '请输入法规名称', trigger: 'blur' }
                ],
                lawModify: [
                    { required: true, message: '请输入法规文号', trigger: 'blur' }
                ],
                docId: [
                    { required: true, message: '请选择专业', trigger: 'change' }
                ],
                bookContent: [
                    { required: true, message: '请输入法规内容', trigger: 'change' }
                ]
            }
        }
    },
    components:{
        upload: resolve => {
            require(["@widget/uploadFile.vue"], resolve);
        }
    },
    mounted(){
        const obj = JSON.stringify(this.rowData);
        this.form = JSON.parse(obj);
    },
    methods:{
        closeDialog(){
            this.$emit('dialogClose')
        },
        addLaw(){
            this.$refs['form'].validate((valid) => {
                if(valid){
                    request.post(`/tac/slb/law/index`,this.form).then(res=>{
                        if(res.success){
                            this.$message.success('编辑成功')
                            this.gwComFileList = [];
                            this.$emit('dialogClose')
                            // if (this.$refs.uploadFile.submitUpload(res.data.fileId)) {
                            //     this.removeNewSupervision();
                            // }
                        }else{
                            this.$message.error(res.message)
                        }
                    }).catch(err=>{
                        this.$message.error(err)
                    })
                } else {
                    return false;
                }
            })
        },
        removeNewSupervision(arg) {
            if (arg) {
                var args = this.gwComFileList.concat(arg);
            }
            this.gwComFileList = [];
            this.$emit('dialogClose')
        },
    }
}
</script>
<style >
    body .el-table th.gutter{display: table-cell!important;}
</style>
