<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">
            <el-form-item label="应用名称" prop="appName">
                <el-input v-model="vm.appName" clearable size="mini" placeholder="请输入应用名称"></el-input>
            </el-form-item>
            <el-form-item label="应用码" prop="appKey">
                <el-input v-model="vm.appKey" clearable size="mini" placeholder="请输入应用码"></el-input>
            </el-form-item>
            <el-form-item label="安全码" prop="appSecret">
                <el-input v-model="vm.appSecret" clearable size="mini" placeholder="请输入安全码"></el-input>
            </el-form-item>
            <el-form-item label="是否有效" prop="valid">
                <el-radio-group v-model="vm.valid" clearable size="mini">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <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>
            <el-table-column
                    align="center"
                    prop="appName"
                    label="应用名称">
            </el-table-column>
            <el-table-column
                    align="center"
                    prop="appNote"
                    label="应用简介">
            </el-table-column>
            <el-table-column
                    align="center"
                    prop="appKey"
                    label="应用码">
            </el-table-column>
            <el-table-column
                    align="center"
                    prop="appSecret"
                    label="安全码">
            </el-table-column>
            <el-table-column
                    align="center"
                    width="80"
                    prop="valid"
                    label="是否有效">
                <template slot-scope="scope">
                    <el-tag size="mini" effect="dark" type="success" v-if="scope.row.valid">是</el-tag>
                    <el-tag size="mini" effect="dark" type="danger" v-if="!scope.row.valid">否</el-tag>
                </template>
            </el-table-column>
            <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">
            <el-form-item label="应用名称" prop="appName">
                <el-input v-model="form.appName" clearable size="mini" placeholder="请输入应用名称" maxlength="50"></el-input>
            </el-form-item>
            <el-form-item label="应用简介" prop="appNote">
                <el-input v-model="form.appNote"
                          clearable
                          size="mini"
                          placeholder="请输入应用简介"
                          type="textarea"
                          maxlength="255"
                          show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="应用码" prop="appKey">
                <el-input v-model="form.appKey" clearable size="mini" placeholder="请输入应用码" maxlength="50"></el-input>
            </el-form-item>
            <el-form-item label="安全码" prop="appSecret">
                <el-input v-model="form.appSecret" clearable size="mini" placeholder="请输入安全码" maxlength="16"></el-input>
            </el-form-item>
            <el-form-item label="是否有效" prop="valid">
                <el-radio-group v-model="form.valid" clearable size="mini">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
		</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: 'wsys',
            target: 'visitor',
            vm: {//条件及分页参数
                appName: null,
                appKey: null,
                appSecret: null,
                valid: null,
                startDate: null,
                endDate: null,
                pageNumber: 1,
                pageSize: 10,
                totalCount: 0,
                sortKey:'CREATE_TIME',
                sortType:'DESC'
            },
            form: {//待提交表单
                formTitle: null,
                formShow: false,
                id: null,
                appName: null,
                appNote: null,
                appKey: null,
                appSecret: null,
                valid: null,
                rowVersion: null
            },
            formRules: {
                appName: [
                    {required: true, message: '应用名称不能为空', trigger: 'blur'},
                    {min: 1, max: 50, message: '应用名称长度在 1 到 50 个字符', trigger: 'blur'}
                ],
                appNote: [
                    {min: 1, max: 255, message: '应用简介长度在 1 到 255 个字符', trigger: 'blur'}
                ],
                appKey: [
                    {required: true, message: '应用码不能为空', trigger: 'blur'},
                    {min: 1, max: 50, message: '应用码长度在 1 到 50 个字符', trigger: 'blur'}
                ],
                appSecret: [
                    {required: true, message: '安全码不能为空', trigger: 'blur'},
                    {min: 1, max: 16, message: '安全码长度在 1 到 16 个字符', trigger: 'blur'}
                ],
                valid: [
                    {required: true, message: '是否有效不能为空', trigger: 'blur'},
                ],
            }
        },
        methods: {
            onCreate: function () {
                this.form.formTitle = "应用接入新增";
                this.form.formShow = true;
                this.form.id = "";
                this.form.appName = "";
                this.form.appNote = "";
                this.form.appKey = "";
                this.form.appSecret = "";
                this.form.valid = "";
            },
            onEdit: function (item) {
                this.form.formTitle = "应用接入编辑";
                this.form.formShow = true;
                this.form.id = item.id;
                this.form.appName = item.appName;
                this.form.appNote = item.appNote;
                this.form.appKey = item.appKey;
                this.form.appSecret = item.appSecret;
                this.form.valid = item.valid;
                this.form.rowVersion = item.rowVersion;
            },
            onDelete: function (item) {
                this.$confirm('将删除该项, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    new Ajax("wsys", "visitor").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>
