<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                            <Field label="所属种类,来源种类" prop="categoryId" v-model="form.categoryId" placeholder="请输入所属种类,来源种类"/>
                            <Field label="产品id" prop="productId" v-model="form.productId" placeholder="请输入产品id"/>
                            <Field label="产品名称" prop="productName" v-model="form.productName" type="textarea" placeholder="请输入产品名称"/>
                            <Field label="css模板合成后文件地址"><fileUpload v-model="form.cssFilePath"  prePath="/file/fileupload"/></Field>
                            <Field label="产品皮肤名称，唯一且不为空" prop="name" v-model="form.name" type="textarea" placeholder="请输入产品皮肤名称，唯一且不为空"/>
                            <Field label="分辨率 " prop="imageResolution" v-model="form.imageResolution" type="select" :enumData="dict.imageResolution" placeholder="请选择分辨率 "/>
                            <Field label="预览图片"><imageUpload v-model="form.previewImagePath" prePath="/file/preview"/></Field>
                            <Field label="排序编号" prop="sortNum" v-model="form.sortNum" placeholder="请输入排序编号"/>
                            <Field label="是否使用" prop="used" v-model="form.used" type="select" :enumData="dict.used" placeholder="请选择是否使用"/>

            </el-row>

            <form-buttons @submit='submitForm' v-if="pageInfo.type!='view'" noCancelBtn />
        </el-form>

    </el-drawer>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    export default {
        name: "SkinDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("skin")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "皮肤",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "used",
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    productName: [
                        {required: true,message: "请输入产品名称", trigger: "blur" },
                        {max: 256,message: "最多只能录入256个字符",trigger: "blur",},
                    ],
                    name: [
                        {required: true,message: "请输入产品皮肤名称，唯一且不为空", trigger: "blur" },
                        {max: 256,message: "最多只能录入256个字符",trigger: "blur",},
                    ],
                    imageResolution: [
                        {required: true,message: "请输入分辨率 ", trigger: "blur" },
                        {max: 256,message: "最多只能录入256个字符",trigger: "blur",},
                    ],
                    previewImagePath: [
                        {required: true,message: "请输入预览图片", trigger: "blur" },
                        {max: 256,message: "最多只能录入256个字符",trigger: "blur",},
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="skin/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改皮肤";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "skin/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增皮肤";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="skin/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "皮肤详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    categoryId : null,
                    productId : null,
                    productName : null,
                    cssFilePath : null,
                    name : null,
                    imageResolution : null,
                    previewImagePath : null,
                    sortNum : null,
                    used : 0,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
