<div id="app" v-cloak>
    <el-card class="box-card search">
        <el-form :inline="true" :model="vm" ref="vm" label-width="90px">
<#list fields as item>
<#if item.isQuery>
<#if item.fieldType.javaType() =="Boolean">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-radio-group v-model="vm.${item.getFName()}" clearable>
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
<#elseif item.fieldType.javaType() =="String" &&  item.fieldType != "Dict">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="vm.${item.getFName()}" clearable size="small" placeholder="请输入${item.fieldComment?default("")}"></el-input>
            </el-form-item>
<#elseif item.fieldType.javaType() =="String" &&  item.fieldType == "Dict">

<#elseif item.fieldType.javaType() =="Byte">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :min="-128" :max="127" :step="1" step-strictly></el-input-number>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Short">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :min="-32768" :max="32767" :step="1" step-strictly></el-input-number>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Integer">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :min="-2147483648" :max="2147483647" :step="1" step-strictly></el-input-number>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Long">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="1" step-strictly></el-input-number>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Float">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="0.01" step-strictly :precision="2"></el-input-number>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Double">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="0.01" step-strictly :precision="2"></el-input-number>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Character">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="vm.${item.getFName()}" clearable size="small" placeholder="请输入${item.fieldComment?default("")}" minlength="0" maxlength="1"></el-input>
            </el-form-item>
<#elseif item.fieldType.javaType() =="Date">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-date-picker
                        size="small"
                        v-model="vm.${item.getFName()}"
                        type="datetime"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
<#elseif item.fieldType.javaType() =="BigDecimal">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="1" step-strictly :precision="2" :step="0.01"></el-input-number>
            </el-form-item>
</#if>
</#if>
</#list>
            <el-form-item>
                <el-button type="primary" size="small" icon="el-icon-search" @click="onSearch">搜索</el-button>
                <el-button type="warning" size="small" icon="el-icon-refresh-left" @click="onReset('vm')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>

    <el-card class="box-card">
        <el-row>
            <el-col :span="12">
                <el-button type="success" size="small" icon="el-icon-plus" @click="onCreate">新增</el-button>

                <el-button type="warning" size="small" icon="el-icon-download" @click="onExport">导出</el-button>

                <el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
                    <el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px">
        <#list fields as item>
            <#if !item.isSystem>
                <#if item.fieldType.javaType() =="Boolean">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-radio-group v-model="vm.${item.getFName()}" clearable>
                                <el-radio :label="true">是</el-radio>
                                <el-radio :label="false">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="String" &&  item.fieldType != "Dict">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input v-model="vm.${item.getFName()}" clearable size="small" placeholder="请输入${item.fieldComment?default("")}"></el-input>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="String" &&  item.fieldType == "Dict">

                <#elseif item.fieldType.javaType() =="Byte">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :min="-128" :max="127" :step="1" step-strictly></el-input-number>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Short">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :min="-32768" :max="32767" :step="1" step-strictly></el-input-number>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Integer">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :min="-2147483648" :max="2147483647" :step="1" step-strictly></el-input-number>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Long">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="1" step-strictly></el-input-number>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Float">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="0.01" step-strictly :precision="2"></el-input-number>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Double">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="0.01" step-strictly :precision="2"></el-input-number>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Character">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input v-model="vm.${item.getFName()}" clearable size="small" placeholder="请输入${item.fieldComment?default("")}" minlength="0" maxlength="1"></el-input>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="Date">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-date-picker
                                    size="small"
                                    v-model="vm.${item.getFName()}"
                                    type="datetime"
                                    placeholder="选择日期时间">
                            </el-date-picker>
                        </el-form-item>
                <#elseif item.fieldType.javaType() =="BigDecimal">
                        <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                            <el-input-number v-model="vm.${item.getFName()}"clearable size="small" placeholder="请输入${item.fieldComment?default("")}" :step="1" step-strictly :precision="2" :step="0.01"></el-input-number>
                        </el-form-item>
                </#if>
            </#if>
        </#list>
                    </el-form>
                    <span slot="footer" class="dialog-footer">
                        <el-button size="small" @click="form.dialog = false">取 消</el-button>
                        <el-button size="small" type="primary" @click="onSave">保存</el-button>
                    </span>
                </el-dialog>
            </el-col>

            <el-col :span="12">
                <el-button-group style="float: right;">
                    <el-tooltip effect="dark" content="Excel模板下载" placement="bottom">
                        <el-button size="small" icon="el-icon-date" @click="onTemplate"></el-button>
                    </el-tooltip>

                    <el-tooltip effect="dark" content="Excel导入" placement="bottom">
                        <el-button size="small" @click="selectExcel">
                            <i class="el-icon-upload2">
                                <input type="file" style="display: none" @change="onImport($event)" ref="excel">
                            </i>
                        </el-button>
                    </el-tooltip>

                    <el-tooltip effect="dark" content="批量删除" placement="bottom">
                        <el-button size="small" icon="el-icon-delete" @click="onBitchDelete"></el-button>
                    </el-tooltip>

                    <el-tooltip effect="dark" content="刷新" placement="bottom">
                        <el-button size="small" icon="el-icon-refresh" @click="onFind"></el-button>
                    </el-tooltip>
                </el-button-group>
            </el-col>
        </el-row>

        <el-table
                style="margin-top: 10px"
                @selection-change="onSelectionChange"
                empty-text="无数据"
                :data="result"
                size="mini"
                style="width: 100%">
            <el-table-column
                    align="center"
                    type="selection"
                    width="40">
            </el-table-column>
<#list fields as item>
<#if item.isQuery && !item.isSystem>
            <el-table-column
                    align="center"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
</#if>
</#list>
            <el-table-column
                    align="center"
                    prop="createTime"
                    width="140"
                    label="创建时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    fixed="right"
                    width="120"
                    label="操作">
                <template slot-scope="scope">
                    <el-dropdown size="mini" split-button type="primary" @click="onCommand(['edit',scope.row])"
                                 @command="onCommand">
                        <i class="el-icon-edit"></i>编辑
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item :command="['delete',scope.row]" icon="el-icon-delete">删除
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                background
                v-if="vm.totalCount > vm.pageSize"
                style="margin-top: 10px"
                @current-change="onPage"
                :current-page="vm.pageNumber"
                :page-size="vm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="vm.totalCount">
        </el-pagination>
    </el-card>
</div>
<script>
    var app = new Vue({
        mixins: [mixin],
        el: "#app",
        data: {
            module: '${module}',
            target: '${table.getFName()}',
            vm: {//条件及分页参数
<#list fields as item>
<#if item.isQuery>
                ${item.getFName()}: "",
</#if>
</#list>
                pageNumber: 1,
                pageSize: 10,
                totalCount: 0,
                sortKey:'CREATE_TIME',
                sortType:'DESC'
            },
            form: {//待提交表单
                title: "",
                dialog: false,
                id: '',
<#list fields as item>
<#if !item.isSystem>
                ${item.getFName()}: "",
</#if>
</#list>
                rowVersion: ""
            },
            formRules: {
<#list fields as field>
<#if !field.isSystem>
                ${field.getFName()}: [
<#if field.isMust>
                    {required: true, message: '${field.fieldComment?default("")}不能为空', trigger: 'blur'},
</#if>
<#if field.fieldType?contains("String_") && field.fieldType != 'String_super'>
                    {min: 1, max: ${field.fieldLength}, message: '${field.fieldComment?default("")}长度在 1 到 ${field.fieldLength} 个字符', trigger: 'blur'}
</#if>
                ],
</#if>
</#list>
            }
        },
        methods: {
            onCreate: function () {
                this.form.title = "${table.tableComment?default("")}新增";
                this.form.dialog = true;
                this.form.id = "";
<#list fields as item>
<#if !item.isSystem>
                this.form.${item.getFName()} = "";
</#if>
</#list>
            },
            onCommand: function (arg) {
                const action = arg[0];
                const item = arg[1];
                switch (action) {
                    case "edit":
                        this.form.title = "${table.tableComment?default("")}编辑";
                        this.form.dialog = true;
                        this.form.id = item.id;
<#list fields as item>
<#if !item.isSystem>
                        this.form.${item.getFName()} = item.${item.getFName()};
</#if>
</#list>
                        this.form.rowVersion = item.rowVersion;
                        break;
                    case "delete":
                        this.onDelete(item);
                        break;
                    default:
                        this.w("未找到对应的命令");
                        break;
                }
            },
        },
        mounted: function () {
            this.onFind();
        },
    })
</script>
