<template>
    <layout-form>
        <el-form :model="form" :loading="loading" :rules="rules" size='small' style="width:100%" label-width='120px' ref="form">
            <el-row>
            <#list columns as column>
                <#if column.isPrimaryKey != 1 && !column.isSuperColumn(column.javaField)&& column.isEdit==1>
                    <#assign javaField=column.javaField />
                    <#assign comment=column.subComment(column.columnComment) />
                    <#if column.htmlType == 1 && !column.columnType?contains("tinyint")>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" placeholder="请输入${comment}"/>
                    <#elseif column.htmlType == 2>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="textarea" placeholder="请输入${comment}"/>
                    <#elseif column.htmlType == 3 ||column.columnType?contains("tinyint")>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="select" :enumData="dict.${column.javaField}" placeholder="请选择${comment}"/>
                    <#elseif column.htmlType == 4>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="checkbox" :enumData="dict.${column.javaField}" />
                    <#elseif column.htmlType == 5>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="radio" :enumData="dict.${column.javaField}" />
                    <#elseif column.htmlType == 6>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" type="date" />
                    <#elseif column.htmlType == 7>
                        <Field label="${comment}"><imageUpload v-model="form.${column.javaField}" prePath="/file/preview"/></Field>
                    <#elseif column.htmlType == 8>
                        <Field label="${comment}"><fileUpload v-model="form.${column.javaField}"  prePath="/file/fileupload"/></Field>
                    <#elseif column.htmlType == 9>
                        <Field label="${comment}"><editor v-model="form.${column.javaField}" :min-height="256"/></Field>
                    <#else >
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${column.javaField}" placeholder="请输入${comment}"/>
                    </#if>
                </#if>
            </#list>
            </el-row>
        <#if table.tplCategory=="sub">
            <el-divider content-position="center">${subTable.functionName}信息</el-divider>
            <br/>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button>
                </el-col>
            </el-row>

            <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
                <el-table-column type="selection" width="50" align="center" />
                <el-table-column label="序号" align="center" prop="index" width="50"/>
                <#list subTable.columns as column >
                    <#if column.isPrimaryKey != 1 &&column.javaField!= subTableFkclassName && !column.isSuperColumn(column.javaField)&& column.isEdit==1>
                <el-table-column label="${comment}" prop="${column.javaField}">
                    <template slot-scope="scope">

                        <el-input v-model="scope.row.${column.javaField}" placeholder="请输入${comment}" />
                    </template>
                </el-table-column>
                    </#if>
                </#list>
            </el-table>
        </#if>

        <#if table.tplCategory=="subone">
            <el-divider content-position="center">${subTable.functionName}信息</el-divider>
            <br/>
            <el-row>
            <#list subTable.columns as column >
                <#if column.isPrimaryKey != 1 && !column.isSuperColumn(column.javaField)&& column.isEdit==1>
                    <#assign javaField=column.javaField />
                    <#assign comment=column.subComment(column.columnComment) />
                    <#if column.htmlType == 1 && !column.columnType?contains("tinyint")>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" placeholder="请输入${comment}"/>
                    <#elseif column.htmlType == 2>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" type="textarea" placeholder="请输入${comment}"/>
                    <#elseif column.htmlType == 3 ||column.columnType?contains("tinyint")>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" type="select" :enumData="dict.${column.javaField}" placeholder="请选择${comment}"/>
                    <#elseif column.htmlType == 4>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" type="checkbox" :enumData="dict.${column.javaField}" />
                    <#elseif column.htmlType == 5>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" type="radio" :enumData="dict.${column.javaField}" />
                    <#elseif column.htmlType == 6>
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" type="date" />
                    <#elseif column.htmlType == 7>
                        <Field label="${comment}"><imageUpload v-model="form.${subclassName}Entity.${column.javaField}" prePath="/file/preview"/></Field>
                    <#elseif column.htmlType == 8>
                        <Field label="${comment}"><fileUpload v-model="form.${subclassName}Entity.${column.javaField}"  prePath="/file/fileupload"/></Field>
                    <#elseif column.htmlType == 9>
                        <Field label="${comment}"><editor v-model="form.${subclassName}Entity.${column.javaField}" :min-height="256"/></Field>
                    <#else >
                        <Field label="${comment}" prop="${column.javaField}" v-model="form.${subclassName}Entity.${column.javaField}" placeholder="请输入${comment}"/>
                    </#if>
                </#if>
            </#list>
            </el-row>
        </#if>
            <form-buttons @submit='submitForm' :noSaveBtn="pageInfo.type === 'view'"/>
        </el-form>
    </layout-form>
</template>

<script>
    import form from "@/assets/mixins/form";
    <#list columns as column>
    <#if column.isInsert==1 && !column.isSuperColumn(column.javaField) && column.isPrimaryKey!=1 && column.htmlType == 7>
    import ImageUpload from '@/components/ImageUpload';
    <#break>
    </#if>
    </#list>
    <#list columns as column>
    <#if column.isInsert==1 && !column.isSuperColumn(column.javaField) && column.isPrimaryKey!=1 && column.htmlType == 8>
    import FileUpload from '@/components/FileUpload';
        <#break>
        </#if>
        </#list>
    <#list columns as column>
        <#if column.isInsert==1 && !column.isSuperColumn(column.javaField) && column.isPrimaryKey!=1 && column.htmlType == 9>
    import Editor from '@/components/Editor';
        <#break>
    </#if>
    </#list>
    export default {
        mixins: [form],
        components: {
        <#list columns as column>
            <#if column.isInsert==1 && !column.isSuperColumn(column.javaField) && column.isPrimaryKey!=1 && column.htmlType == 7>
            ImageUpload,
            <#break>
            </#if>
        </#list>
        <#list columns as column>
            <#if column.isInsert==1 && !column.isSuperColumn(column.javaField) && column.isPrimaryKey!=1 && column.htmlType == 8>
            FileUpload,
            <#break>
            </#if>
        </#list>
        <#list columns as column>
            <#if column.isInsert==1 && !column.isSuperColumn(column.javaField) && column.isPrimaryKey!=1 && column.htmlType == 9>
            Editor,
            <#break>
            </#if>
        </#list>
        },
        methods: {

    <#if table.tplCategory=="sub">
        /** ${subTable.functionName}序号 */
        row${subClassName}Index({ row, rowIndex }) {
            row.index = rowIndex + 1;
        },
        /** ${subTable.functionName}添加按钮操作 */
        handleAdd${subClassName}() {
            let obj = {};
            <#list subTable.columns as column>
                <#if column.isPrimaryKey==1 || column.javaField == subTableFkclassName>
                <#elseif "" != javaField>
            obj.${column.javaField} = "";
                </#if>
            </#list>
            this.${subclassName}List.push(obj);
        },
        /** ${subTable.functionName}删除按钮操作 */
        handleDelete${subClassName}() {
            if (this.checked${subClassName}.length == 0) {
                this.$alert("请先选择要删除的${subTable.functionName}数据", "提示", { confirmButtonText: "确定", });
            } else {
                this.${subclassName}List.splice(this.checked${subClassName}[0].index - 1, 1);
            }
        },
        /** 单选框选中数据 */
        handle${subClassName}SelectionChange(selection) {
            if (selection.length > 1) {
                this.$refs.${subclassName}.clearSelection();
                this.$refs.${subclassName}.toggleRowSelection(selection.pop());
            } else {
                this.checked${subClassName} = selection;
            }
        },
        // 渲染前置处理
        beforeRender(data) {
            if(data.entity.${subclassName}List) {
                this.${subclassName}List = data.entity.${subclassName}List;
            }
            return data
        },
        <#elseif table.tplCategory=="subone" >
    </#if>

        },
        data() {
            return {
                toString:[
                    <#list columns as column>
                    <#if column.columnType?contains("tinyint")>
                    "${column.javaField}",
                    </#if>
                    </#list>
                ],
                <#if table.tplCategory=="sub">
                // 子表选中数据
                checked${subClassName}: [],
                // ${subTable.functionName}表格数据
                ${subclassName}List: [],
                </#if>
                rules: {
                    <#list columns as column>
                    <#assign comment=column.subComment(column.columnComment) />
                    <#if column.javaType == "String" && column.isRequired==1>
                    ${column.javaField}: [
                        {<#if column.isRequired==1>required: true,message: "请输入${comment}",</#if> trigger: "blur" },
                        <#assign max=column.subBetween(column.columnType) />
                        {max: ${max},message: "最多只能录入${max}个字符",trigger: "blur",},
                    ],
                    </#if>
                    <#if column.javaType == "Integer" && column.isRequired==1>
                    ${column.javaField}: [
                        {<#if column.isRequired==1>required: true,message: "请输入${comment}",</#if> trigger: "blur" },
                    ],
                    </#if>
                    <#if column.javaType == "BigDecimal" && column.isRequired==1>
                    ${column.javaField}: [
                        {<#if column.isRequired==1>required: true,message: "请输入${comment}",</#if> trigger: "blur" },
                    ],
                    </#if>
                    <#if column.javaType == "Date" &&column.htmlType ==6 && column.isRequired==1>
                    ${column.javaField}: [
                        {<#if column.isRequired==1>required: true,message: "请选择${comment}"</#if> },
                    ],
                    </#if>
                    </#list>
                }
            };
        }
    };
</script>