<!--
新增功能
@Author: linqian
@Date: 2021-05-17 16:47
-->
<template>
    <dg-row>
        <el-form ref="form" :model="form" :rules="rules" label-width="150px">
            <dg-col :span="12">
                <el-form-item label="功能编号：" prop="code">
                    <el-input v-model="form.code" placeholder="" v-if="!isDetail"></el-input>
                    <span v-else>{{ form.code }}</span>
                </el-form-item>
                <el-form-item label="上级功能编号：" prop="parentId">
                    <el-input v-model="form.parentId" placeholder="" v-if="!isDetail"></el-input>
                    <span v-else>{{ form.parentId }}</span>
                </el-form-item>
                <el-form-item label="所属应用：" prop="appName">
                    <el-input v-model="form.appName" placeholder="" v-if="!isDetail" disabled></el-input>
                    <span v-else>{{ form.appName }}</span>
                </el-form-item>
                <el-form-item label="设计安全隐私类别：" prop="designSecureType">
                    <dg-select v-model="form.designSecureType" placeholder="" enum="SecurityPrivacyEnum" v-if="!isDetail"></dg-select>
                    <span v-else>{{ form.designSecureType }}</span>
                </el-form-item>
            </dg-col>
            <dg-col :span="12">
                <el-form-item label="功能名称：" prop="name">
                    <el-input v-model="form.name" placeholder="" v-if="!isDetail"></el-input>
                    <span v-else>{{ form.name }}</span>
                </el-form-item>
                <el-form-item label="在用状态：" prop="isActive">
                    <dg-select code="DM_APPLY_STATUS" v-model="form.isActive" v-if="!isDetail"></dg-select>
                    <span v-else>{{ form.isActive == "0" ? "禁用" : "启用" }}</span>
                </el-form-item>
                <el-form-item label="功能使用场景代码：" prop="functionUsageScenarios">
                    <el-input v-model="form.functionUsageScenarios" placeholder="" v-if="!isDetail"></el-input>
                    <span v-else>{{ form.functionUsageScenarios }}</span>
                </el-form-item>
            </dg-col>
            <dg-col :span="24">
                <el-form-item label="功能说明：" prop="remark">
                    <el-input
                        v-model="form.remark"
                        placeholder=""
                        type="textarea"
                        :rows="3"
                        v-if="!isDetail"
                    ></el-input>
                    <span v-else>{{ form.remark }}</span>
                </el-form-item>
            </dg-col>
        </el-form>
    </dg-row>
</template>
S
<script>
// import { funcRestApi } from "@/api/application";
export default {
    props: {
        id: String,
        isDetail: {
            type: Boolean,
            default: false
        },
        app: Object
    },
    components: {},
    data() {
        return {
            form: {
                appId: "",
                appName: "",
                code: "",
                designSecureType: "",
                functionUsageScenarios: "",
                isActive: "",
                name: "",
                parentId: "",
                remark: ""
            },
            rules: {
                code: [{ required: true, message: "请输入功能编号", trigger: "change" }],
                name: [{ required: true, message: "请输入功能名称", trigger: "change" }],
                parentId: [{ required: true, message: "请输入上级功能编号", trigger: "change" }],
                isActive: [{ required: true, message: "请选择在用状态", trigger: "change" }],
                appName: [{ required: true, message: "请选择应用", trigger: "change" }]
            }
        };
    },
    computed: {},
    methods: {
        /**
         * 保存
         */
        saveForm() {
            return new Promise((resolve) => {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        const api = this.id ? "update" : "save";
                        // funcRestApi[api](this.form)
                        //     .then((res) => {
                        //         this.$message.success("保存成功!");
                        //         resolve("成功");
                        //     })
                        //     .catch((error) => {
                        //         this.$message.error(error);
                        //     });
                    }
                });
            });
        },
        /**
         * 获取详情
         */
        getDetail() {
            // funcRestApi.detail(this.id).then((res) => {
            //     this.form = res;
            // });
        }
    },
    created() {
        if (this.id) {
            if (this.isDetail) {
                this.rules = {};
            }
            this.getDetail();
        } else {
            this.form.appName = this.app.applyName;
            this.form.appId = this.app.id;
        }
    },
    mounted() {}
};
</script>

<style lang='scss'>
</style>