<template>
    <ap-container>
        <ap-aside margin="1111">
            <ap-aside-tree :options.sync="treeOptions">
                <el-form slot="form" ref="tSysTaskTimeType" :inline="true" label-width="80px"
                         :model="tSysTaskTimeTypeForm" :rules="tSysTaskTimeTypeRules">
                    <el-form-item label="父节点">
                        <el-select v-model="tSysTaskTimeTypeForm.fdParentId" filterable placeholder="请选择父节点">
                            <el-option label="无" value=""></el-option>
                            <el-option
                                v-for="item in typeList"
                                :key="item.fdId"
                                :label="item.fdName"
                                :value="item.fdId">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label='名称' prop='fdName'>
                        <el-input v-model='tSysTaskTimeTypeForm.fdName'></el-input>
                    </el-form-item>
                    <el-form-item label='备注' prop='fdComment'>
                        <el-input v-model='tSysTaskTimeTypeForm.fdComment'></el-input>
                    </el-form-item>
                    <el-form-item label='排序' prop='fdSort'>
                        <el-input v-model='tSysTaskTimeTypeForm.fdSort'></el-input>
                    </el-form-item>
                </el-form>
                <span slot="tree" slot-scope="scope">
                    {{ scope.data.fdName }}
                </span>
            </ap-aside-tree>
        </ap-aside>
        <ap-split-panel></ap-split-panel>
        <ap-container>
            <ap-main margin="1110">
                <ap-table ref="tSysTaskTimeTableRef" :options.sync="tSysTaskTimeTable"></ap-table>
            </ap-main>
        </ap-container>
    </ap-container>
</template>

<script>
    export default {
        name: 'TSysTaskTime',
        data() {
            let tSysTaskTimeCols = [
                {
                    prop: 'fdTypeId',
                    label: '类型',
                    type: 'select',
                    width: "150",
                    selectOptionsRemote: 'typeList',
                    selectOptionsKey: {label: "fdName", value: "fdId"},
                    addDefaultValue: () => {
                        return this.selectedId;
                    }
                }, {
                    prop: 'fdCode',
                    label: '编码',
                    minWidth: "150",
                    type: 'input'
                }, {
                    prop: 'fdName',
                    label: '名称',
                    minWidth: "180",
                    type: 'input'
                }, {
                    prop: 'fdTable',
                    label: '表',
                    minWidth: "120",
                    type: 'input'
                }, {
                    prop: 'fdDataSource',
                    label: '数据源',
                    minWidth: "100",
                    type: 'input'
                }, {
                    prop: 'fdLastTime',
                    label: '最后同步时间',
                    type: 'datePicker',
                    datePickerType:"datetime",
                    datePickerFormat: 'yyyy-MM-dd HH:mm:ss',
                    width: 200
                }, {
                    prop: 'fdComment',
                    label: '备注',
                    minWidth: "200",
                    type: 'input'
                },
            ];
            let tSysTaskTimeTable = {
                title: "同步时间戳信息",
                columns: tSysTaskTimeCols,
                dataUrl: "/apt/sys/TSysTaskTime/getTSysTaskTimeGridList",
                saveUrl: "/apt/sys/TSysTaskTime/saveTSysTaskTimeGridData",
                editPk: "fdId", //默认fdId
                deletePk: "fdId", // 默认fdId
                deleteUrl: "/apt/sys/TSysTaskTime/deleteTSysTaskTimeGridData",
                toolbarBtn: ["add", "edit", "del", "cancel", "refresh", "save"],
                params: () => {
                    return {
                        typeIds: this.treeSelectedValues
                    }
                }
            };

            return {
                // ----- 左侧树 -----
                treeOptions: this.getTreeOption(),
                tSysTaskTimeTypeForm: {},
                tSysTaskTimeTypeRules: {},
                treeSelectedValues: "",
                selectedId: "",
                typeList: [],
                // ----- 右侧 -----
                tSysTaskTimeTable: tSysTaskTimeTable,
            }
        },
        methods: {
            // 左侧树：配置
            getTreeOption() {
                let treeOptions = {
                    title: "同步类型",
                    toolbarBtn: ["add", "edit", "del", "sort"],
                    dialogTitle: "同步类型",
                    showCheckbox: true,
                    onCheck: (data, node, comp, halfCheckedKeys, checkedKeys) => {
                        this.selectedId = data.fdId;
                        this.treeSelectedValues = halfCheckedKeys.concat(checkedKeys).join(",");
                        if (this.treeSelectedValues == null || this.treeSelectedValues == "") {
                            return;
                        }
                        this.$refs.tSysTaskTimeTableRef.refresh();
                    },
                    loadOptions: {
                        url: "/apt/sys/TSysTaskTimeType/getTSysTaskTimeTypeList",
                        treeKey: {
                            idKey: "fdId",
                            parentKey: "fdParentId",
                            childrenKey: "children",
                            label: "fdName"
                        },
                        success: (response) => {
                            this.typeList = response.data;
                        },
                    },
                    editOptions: {
                        url: "/apt/sys/TSysTaskTimeType/getTSysTaskTimeTypeByFdId",
                        data: (node) => {
                            return {
                                fdId: node.fdId
                            }
                        },
                        success: (response) => {
                            this.tSysTaskTimeTypeForm= response.data;
                        },
                        error() {},
                    },
                    insertUrl: "/apt/sys/TSysTaskTimeType/insertTSysTaskTimeType",
                    insertData: () => {
                        return this.tSysTaskTimeTypeForm
                    },
                    updateUrl: "/apt/sys/TSysTaskTimeType/updateTSysTaskTimeType",
                    updateData: () => {
                        return this.tSysTaskTimeTypeForm
                    },
                    deleteUrl: "/apt/sys/TSysTaskTimeType/deleteTSysTaskTimeTypeByFdId",
                    deleteData: (node) => {
                        return {
                            fdId: node.fdId
                        }
                    },
                    updateSortUrl: '/apt/sys/TSysTaskTimeType/updateTSysTaskTimeTypeSort',
                    updateSortListUrl: '/apt/sys/TSysTaskTimeType/updateTSysTaskTimeTypeSortList',
                    resetForm: () => {
                        this.tSysTaskTimeTypeForm = {
                            fdId: '',
                            fdParentId: '',
                            fdName: '',
                            fdComment: '',
                            fdSort: '',
                        };
                    },
                    afterOpenAddDialog: (node) => {
                        this.tSysTaskTimeTypeForm.fdTypeId = this.selectedId;
                    },
                };

                return treeOptions;
            },
        }
    }
</script>

<style scoped>
</style>
