<div id="app" v-cloak>
    <el-card class="box-card search">
        <el-form :inline="true" :model="vm" ref="vm" label-position="left" label-width="90px">
            <el-form-item label="文件名称" prop="name">
                <el-input v-model="vm.name" clearable size="small" placeholder="请输入文件名称"></el-input>
            </el-form-item>
            <el-form-item label="文件类型" prop="fileType">
                <el-input-dict v-model="vm.fileType" clearable size="small" placeholder="请输入文件类型" dict-name="fileType" ></el-input-dict>
            </el-form-item>
            <el-form-item label="扩展属性1" prop="attribute1">
                <el-input v-model="vm.attribute1" clearable size="small" placeholder="请输入扩展属性1"></el-input>
            </el-form-item>
            <el-form-item label="扩展属性2" prop="attribute2">
                <el-input v-model="vm.attribute2" clearable size="small" placeholder="请输入扩展属性2"></el-input>
            </el-form-item>
            <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-position="left" label-width="90px">
                        <el-form-item label="文件名称" prop="name">
                            <el-input v-model="form.name" clearable size="small" placeholder="请输入文件名称"></el-input>
                        </el-form-item>
                        <el-form-item label="文件类型" prop="fileType">
                            <el-input-dict v-model="form.fileType" clearable size="small" placeholder="请输入文件类型" dict-name="fileType" ></el-input-dict>
                        </el-form-item>
                        <el-form-item label="扩展属性1" prop="attribute1">
                            <el-input v-model="form.attribute1" clearable size="small" placeholder="请输入扩展属性1"></el-input>
                        </el-form-item>
                        <el-form-item label="扩展属性2" prop="attribute2">
                            <el-input v-model="form.attribute2" clearable size="small" placeholder="请输入扩展属性2"></el-input>
                        </el-form-item>
                        <el-form-item label="存放地址" prop="location">
                            <el-input v-model="form.location" clearable size="small" placeholder="请输入存放地址"></el-input>
                        </el-form-item>
                        <el-form-item label="访问地址" prop="url">
                            <el-input v-model="form.url" clearable size="small" placeholder="请输入访问地址"></el-input>
                        </el-form-item>
                        <el-form-item label="下载地址" prop="urlDownload">
                            <el-input v-model="form.urlDownload" clearable size="small" placeholder="请输入下载地址"></el-input>
                        </el-form-item>
                    </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" icon="el-icon-upload2" @click="onImport"></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>
            <el-table-column
                    align="center"
                    prop="id"
                    label="主键"
                    width="140">
            </el-table-column>
            <el-table-column
                    align="center"
                    prop="name"
                    label="文件名称">
            </el-table-column>
            <el-table-column
                    align="center"
                    prop="fileType"
                    label="文件类型">
            </el-table-column>
            <el-table-column
                    align="center"
                    prop="location"
                    label="存放地址">
            </el-table-column>
            <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: 'system',
            target: 'file',
            vm: {//条件及分页参数
                name: "",
                fileType: "",
                attribute1: "",
                attribute2: "",
                pageNumber: 1,
                pageSize: 10,
                totalCount: 0,
                sortKey:'CREATE_TIME',
                sortType:'DESC'
            },
            form: {//待提交表单
                title: "",
                dialog: false,
                id: '',
                name: "",
                fileType: "",
                attribute1: "",
                attribute2: "",
                location: "",
                url: "",
                urlDownload: "",
                rowVersion: ""
            },
            formRules: {
                name: [
                    {required: true, message: '文件名称不能为空', trigger: 'blur'},
                    {min: 1, max: 255, message: '文件名称长度在 1 到 255 个字符', trigger: 'blur'}
                ],
                fileType: [
                ],
                attribute1: [
                    {min: 1, max: 50, message: '扩展属性1长度在 1 到 50 个字符', trigger: 'blur'}
                ],
                attribute2: [
                    {min: 1, max: 50, message: '扩展属性2长度在 1 到 50 个字符', trigger: 'blur'}
                ],
                location: [
                    {min: 1, max: 500, message: '存放地址长度在 1 到 500 个字符', trigger: 'blur'}
                ],
                url: [
                    {min: 1, max: 500, message: '访问地址长度在 1 到 500 个字符', trigger: 'blur'}
                ],
                urlDownload: [
                    {min: 1, max: 500, message: '下载地址长度在 1 到 500 个字符', trigger: 'blur'}
                ],
            }
        },
        methods: {
            onCreate: function () {
                this.form.title = "文件新增";
                this.form.dialog = true;
                this.form.id = "";
                this.form.name = "";
                this.form.fileType = "";
                this.form.attribute1 = "";
                this.form.attribute2 = "";
                this.form.location = "";
                this.form.url = "";
                this.form.urlDownload = "";
            },
            onCommand: function (arg) {
                const cmd = arg[0];
                const item = arg[1];
                switch (cmd) {
                    case "edit":
                        this.form.title = "文件编辑";
                        this.form.dialog = true;
                        this.form.id = item.id;
                        this.form.name = item.name;
                        this.form.fileType = item.fileType;
                        this.form.attribute1 = item.attribute1;
                        this.form.attribute2 = item.attribute2;
                        this.form.location = item.location;
                        this.form.url = item.url;
                        this.form.urlDownload = item.urlDownload;
                        this.form.rowVersion = item.rowVersion;
                        break;
                    case "delete":
                        this.onDelete(item);
                        break;
                    default:
                        this.w("未找到对应的命令");
                        break;
                }
            },
        },
        mounted: function () {
            this.onFind();
        },
    })
</script>
