<template>
    <ap-container>
        <ap-header margin="0111" style="border-bottom: 1px solid #e2e7ef;">
            <el-form ref="tSysJobStandardGroupSearchForm" :model="tSysJobStandardGroupSearchForm"
                     :rules="tSysJobStandardGroupSearchFormRules"
                     :inline="true" class="layout-header-form" @submit.native.prevent="searchEvent">
                <el-form-item label="搜索:" class="layout-header-form-item" prop="likeStr">
                    <el-input v-model="tSysJobStandardGroupSearchForm.likeStr" placeholder="名称/编码"></el-input>
                </el-form-item>
                <el-form-item label="是否有效:" class="layout-header-form-item" prop="fdDisabled">
                    <el-select v-model='tSysJobStandardGroupSearchForm.fdDisabled'>
                        <el-option key="" label="全部" value=""></el-option>
                        <el-option :key="0" label="有效" :value="0"></el-option>
                        <el-option :key="1" label="失效" :value="1"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <el-button type="primary" @click="searchEvent">查询</el-button>
        </ap-header>
        <ap-main margin="0101">
            <ap-table ref="tSysJobStandardGroupRef" :options.sync="tSysJobStandardGroupOpt"></ap-table>
        </ap-main>
    </ap-container>
</template>

<script>

    export default {
        name: 'SysJobStandardGroup',
        data() {
            let columns = [
                {
                    prop: 'fdName',
                    label: '名称',
                    type: 'input',
                    rules: [{required: true, message: "请输入群组名称"},
                        {min: 1, max: 20, message: '长度在 1 到 20 个字符'}]
                }, {
                    prop: 'fdParentName',
                    label: '父群组',
                    type: 'searchTree',
                    searchTreeUrl: "/apm/sys/sysJobStandardGroup/getTSysJobStandardGroupList",
                    searchTreeParams: {
                        fdDisabled: 0
                    },
                    searchTreeRenderKey: {idKey: "fdId"},
                    searchTreeLoadTime: "edit",
                    searchTreeConfirm: (row, checkedNodes) => {
                        row.fdParentId = checkedNodes[0].fdId;
                        row.fdParentName = checkedNodes[0].fdName;
                        return true;
                    },
                    searchTreeClear: (row) => {
                        row.fdParentId = "";
                        row.fdParentName = "";
                        return true;
                    },
                }, {
                    prop: 'fdCode',
                    label: '编码',
                    type: 'input',
                    width: 200
                }, {
                    prop: 'fdSort',
                    label: '排序',
                    type: 'input',
                    width: 100
                }, {
                    prop: 'fdDisabled',
                    label: '是否有效',
                    type: 'select',
                    align: "center",
                    width: 80,
                    addDefaultValue: 0,
                    selectOptions: [{label: "有效", value: 0}, {label: "失效", value: 1}],
                    html: function (value, row) {
                        if (value == 1) {
                            return '<div class="ap-tag-danger">禁用</div>'
                        } else if (value == 0) {
                            return '<div class="ap-tag-success">启用</el-tag>';
                        }
                    },
                },
            ];
            let tableOpt = {
                title: "基准岗位分组",
                columns: columns,
                dataUrl: "/apm/sys/sysJobStandardGroup/getTSysJobStandardGroupGridList",
                deletePk: "fdId", // 默认fdId
                saveUrl: "/apm/sys/sysJobStandardGroup/saveTSysJobStandardGroupGridData",
                deleteUrl: "/apm/sys/sysJobStandardGroup/deleteTSysJobStandardGroupGridData",
                toolbarBtn: ["add", "edit", "del", "cancel", "refresh", "save"],
                initData: true, // 默认false
                pagination: {pageSizes: [100, 1000, 3000], pageSize: 100},
                rowParentKey: "fdParentId",
                defaultExpandAll: true,
                indexWidth: 120,
                indexAlign: "left",
                params: () => {
                    return {
                        likeStr: this.tSysJobStandardGroupSearchForm.likeStr,
                        fdDisabled: this.tSysJobStandardGroupSearchForm.fdDisabled,
                    }
                }
            };

            return {
                tSysJobStandardGroupOpt: tableOpt,
                tSysJobStandardGroupSearchForm: {
                    likeStr: "",
                    fdDisabled: 0
                },
                tSysJobStandardGroupSearchFormRules: {

                    likeStr: [{min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur'}]
                }
            }
        },
        methods: {
            // 查询
            searchEvent() {
                // 表单rules认证
                this.$refs.tSysJobStandardGroupSearchForm.validate((valid) => {
                    if (!valid) {
                        this.$message.error('搜索条件格式不正确！');
                        return false;
                    }
                    this.$refs.tSysJobStandardGroupRef.refresh();
                });
            }
        }
    }
</script>

<style scoped>
</style>
