<#-- since ${.now?string["yyyy-MM-dd"]}-->
<div id="app" v-cloak>
    <el-card class="box-card">
        <el-form class="search" :inline="true" :model="vm" ref="vm" label-position="right" label-width="90px">
<#list fields as item>
    <#if item.isQuery>
        <#if item.getFieldTypeJava() =="Boolean">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-radio-group v-model="vm.${item.getFName()}" clearable size="mini">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Byte">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" controls-position="right" :min="-128" :max="127" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Short">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" controls-position="right" :min="-32768" :max="32767" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Integer">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" controls-position="right" :min="-2147483648" :max="2147483647" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Long">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" controls-position="right" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Float">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" controls-position="right" :step="0.01" step-strictly :precision="2"></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Double">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" controls-position="right" :step="0.01" step-strictly :precision="2"></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Character">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" minlength="0" maxlength="1"></el-input>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="String" &&  item.fieldType != "Dict">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}"></el-input>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="String" &&  item.fieldType == "Dict">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-dict v-model="vm.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" dict-name="${item.getFieldName()}" ></el-input-dict>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Date">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-date-picker
                        size="mini"
                        v-model="vm.${item.getFName()}"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetime"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="BigDecimal">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="vm.${item.getFName()}"clearable size="mini" 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 label="开始日期" prop="startDate">
                <el-date-picker v-model="vm.startDate" clearable size="mini" placeholder="请输入开始日期" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
            <el-form-item label="结束日期" prop="endDate">
                <el-date-picker v-model="vm.endDate" clearable size="mini" placeholder="请输入结束日期" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" size="mini" icon="el-icon-search" @click="onSearch">搜索</el-button>
                <el-button type="warning" size="mini" 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="mini" icon="el-icon-plus" @click="onCreate">新增</el-button>

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

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

                    <el-tooltip effect="dark" content="Excel导入" placement="bottom">
                        <el-button size="mini" icon="el-icon-upload2" @click="onImport"></el-button>
                    </el-tooltip>

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

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

        <el-table
                class="data"
                @selection-change="onSelectionChange"
                empty-text="无数据"
                :stripe="true"
                :data="result"
                size="mini">
            <el-table-column
                    align="center"
                    width="45"
                    type="selection">
            </el-table-column>
            <el-table-column
                    align="center"
                    width="140"
                    prop="id"
                    label="主键">
            </el-table-column>
<#list fields as item>
<#if !item.isSystem>
<#if item.fieldType == 'Boolean'>
            <el-table-column
                    align="center"
                    width="80"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
                <template slot-scope="scope">
                    <el-tag size="mini" effect="dark" type="success" v-if="scope.row.${item.getFName()}">是</el-tag>
                    <el-tag size="mini" effect="dark" type="danger" v-if="!scope.row.${item.getFName()}">否</el-tag>
                </template>
            </el-table-column>
<#elseif  item.fieldType == 'Date'>
            <el-table-column
                    align="center"
                    width="140"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'Dict'>
            <el-table-column
                    align="center"
                    width="100"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
                <template slot-scope="scope">
                    <el-view-dict v-model="scope.row.${item.getFName()}" dict-name="${item.fieldName}"></el-view-dict>
                </template>
            </el-table-column>
<#elseif item.fieldType == 'String_1' || item.fieldType == 'String_10'>
            <el-table-column
                    align="center"
                    width="100"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'String_var' && item.getFieldLength() lt 15>
            <el-table-column
                    align="center"
                    width="100"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'String_var' && item.getFieldLength() lt 50>
            <el-table-column
                    align="center"
                    width="150"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'String_var' && item.getFieldLength() gte 50>
            <el-table-column
                    align="center"
                    width="180"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'String_var50' || item.fieldType == 'String_var100'>
            <el-table-column
                    align="center"
                    width="180"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'String_var255' || item.fieldType == 'String_var500' || item.fieldType == 'String_var2500'|| item.fieldType == 'String_var4000'|| item.fieldType == 'String_super'>
            <el-table-column
                    align="center"
                    width="180"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#elseif item.fieldType == 'Long'>
            <el-table-column
                    align="center"
                    width="140"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
<#else>
            <el-table-column
                    align="center"
                    width="100"
                    prop="${item.getFName()}"
                    label="${item.fieldComment?default("")}">
            </el-table-column>
</#if>
</#if>
</#list>
            <el-table-column
                    align="center"
                    width="140"
                    prop="createTime"
                    label="创建时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    width="120"
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <wb-dropdown :arg="scope.row">
                        <wb-dropdown-item value="编辑" icon="el-icon-edit" @click="onEdit"></wb-dropdown-item>
                        <wb-dropdown-item value="删除" icon="el-icon-delete" @click="onDelete"></wb-dropdown-item>
                    </wb-dropdown>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination
                background
                v-if="vm.totalCount > vm.pageSize"
                style="margin-top: 10px"
                @current-change="onPageChange"
                @size-change="onPageSizeChange"
                :current-page="vm.pageNumber"
                :page-size="vm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="vm.totalCount">
        </el-pagination>
    </el-card>

	<el-dialog
            :custom-class="'dialog'"
            :title="form.formTitle"
            :close-on-click-modal="false"
            :visible.sync="form.formShow">
		<el-form class="form" :model="form" :inline="true" :rules="formRules" ref="form" label-position="right" label-width="90px">
<#list fields as item>
    <#if !item.isSystem>
        <#if item.getFieldTypeJava() =="Boolean">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-radio-group v-model="form.${item.getFName()}" clearable size="mini">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="String" && item.getFieldLength() lte 50 &&  item.fieldType != "Dict">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" maxlength="${item.getFieldLength()}"></el-input>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="String" && item.getFieldLength() gt 50 &&  item.fieldType != "Dict">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="form.${item.getFName()}"
                          clearable
                          size="mini"
                          placeholder="请输入${item.fieldComment?default("")}"
                          type="textarea"
                          maxlength="${item.getFieldLength()}"
                          show-word-limit></el-input>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="String" &&  item.fieldType == "Dict">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-dict v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" dict-name="${item.getFieldName()}" ></el-input-dict>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Byte">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}"clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" :min="-128" :max="127" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Short">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" :min="-32768" :max="32767" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Integer">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" :min="-2147483648" :max="2147483647" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Long">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" :step="1" step-strictly></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Float">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" :step="0.01" step-strictly :precision="2"></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Double">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" :step="0.01" step-strictly :precision="2"></el-input-number>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Character">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input v-model="form.${item.getFName()}" clearable size="mini" placeholder="请输入${item.fieldComment?default("")}" minlength="0" maxlength="1"></el-input>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="Date">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-date-picker
                        size="mini"
                        v-model="form.${item.getFName()}"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetime"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
        <#elseif item.getFieldTypeJava() =="BigDecimal">
            <el-form-item label="${item.fieldComment?default("")}" prop="${item.getFName()}">
                <el-input-number v-model="form.${item.getFName()}"clearable size="mini" 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="mini" @click="form.formShow = false">取 消</el-button>
			<el-button size="mini" type="primary" @click="onSave">保存</el-button>
		</span>
    </el-dialog>
</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()}: null,
</#if>
</#list>
                startDate: null,
                endDate: null,
                pageNumber: 1,
                pageSize: 10,
                totalCount: 0,
                sortKey:'CREATE_TIME',
                sortType:'DESC'
            },
            form: {//待提交表单
                formTitle: "",
                formShow: false,
                id: null,
<#list fields as item>
<#if !item.isSystem>
                ${item.getFName()}: null,
</#if>
</#list>
                rowVersion: null
            },
            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.formTitle = "${table.tableComment?default("")}新增";
                this.form.formShow = true;
                this.form.id = "";
<#list fields as item>
<#if !item.isSystem>
                this.form.${item.getFName()} = "";
</#if>
</#list>
            },
            onEdit: function (item) {
                this.form.formTitle = "${table.tableComment?default("")}编辑";
                this.form.formShow = 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;
            },
            onDelete: function (item) {
                this.$confirm('将删除该项, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    new Ajax("${module}", "${table.getFName()}").delete({id: item.id}, function (response) {
                        if (response.errors.length > 0) {
                            nav.e(response.errors[0].message);
                        } else {
                            nav.s("删除成功.");
                            this.onFind();
                        }
                    }.bind(this))
                }.bind(this)).catch(function (action) {

                });
            }
        },
        mounted: function () {
            this.onFind();
        },
    })
</script>
