<template>
    <!-- 时间序列维护 -->
    <div class="timeSeries">
        <div class="box">
            <div class="box-top">
                <el-form
                    style="overflow: hidden;"
                    :style="filterForm.show ? null : { height: '0px' }"
                    size="mini"
                    label-width="70px"
                >
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="序列编号">
                                <el-input
                                    clearable
                                    v-model="filterForm.data.id"
                                    placeholder="序列编号"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="序列名称">
                                <el-input
                                    clearable
                                    v-model="filterForm.data.name"
                                    placeholder="序列名称"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="时间粒度">
                                <el-select
                                    filterable
                                    clearable
                                    v-model="filterForm.data.timegranid"
                                    placeholder="时间粒度"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.timegranid.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="box-top-gjl">
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-plus"
                        v-privilege="activeMenu + 'ADD'"
                        @click="but_add"
                    >新增</el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-edit-outline"
                        v-privilege="activeMenu + 'PUT'"
                        @click="but_edit_plural()"
                        :loading="loading"
                    >修改</el-button>
                    <el-button
                        class="button"
                        type="danger"
                        size="mini"
                        icon="el-icon-delete"
                        v-privilege="activeMenu + 'DELETE'"
                        @click="but_del_plural()"
                        :loading="loading"
                    >删除</el-button>
                    <div style="float:right; text-align: right;">
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-search"
                            v-privilege="activeMenu + 'QUERY'"
                            @click="getTableData(1)"
                        >查询</el-button>
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-refresh"
                            v-privilege="activeMenu + 'QUERY'"
                            @click="tableDataCancel();"
                        >重置</el-button>
                        <el-button
                            size="mini"
                            :icon="filterForm.show ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"
                            :title="filterForm.show ? '收起搜索区' : '展开搜索区'"
                            @click="filterForm.show = !filterForm.show;
                                $nextTick(() => {
                                    singleTableHeight = getRoleHeight($refs['singleTable'].$el) - 45;
                                }
                            );"
                        >{{ filterForm.show ? '收起' : '展开' }}</el-button>
                    </div>
                </div>
            </div>
            <div class="box-bottom">
                <el-form
                    size="mini"
                    ref="dialog_form_arr"
                    label-width="0px"
                    :model="tableFormDataObj"
                >
                    <el-table
                        stripe
                        id="singleTable"
                        ref="singleTable"
                        :data="tableData"
                        v-loading="tableLoading"
                        style="width: 100%;"
                        :height="singleTableHeight"
                        border
                        size="mini"
                        highlight-current-row
                        @selection-change="handleSelectionChange"
                    >
                        <el-table-column
                            type="selection"
                            width="40"
                            align="center"
                            fixed="left"
                        ></el-table-column>
                        <el-table-column
                            sortable
                            prop="id"
                            label="序列编号"
                            width="80px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            sortable
                            prop="name"
                            label="序列名称"
                            width="110px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.name'"
                                    :rules="dialog.editorBox.form.rules.name"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].name"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.name}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="timegranid"
                            label="时间粒度"
                            width="100px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.timegranid'"
                                    :rules="dialog.editorBox.form.rules.timegranid"
                                >
                                    <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].timegranid"
                                    >
                                        <el-option
                                            v-for="item of nameObj.timegranid.arr"
                                            :key="item.id"
                                            :value="item.id"
                                            :label="item.name"
                                        ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{ nameObj.timegranid.obj[scope.row.timegranid] ? nameObj.timegranid.obj[scope.row.timegranid] : scope.row.timegranid }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="grandefault"
                            label="粒度默认序列"
                            width="100px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.grandefault'"
                                    :rules="dialog.editorBox.form.rules.grandefault"
                                >
                                    <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].grandefault"
                                    >
                                        <el-option
                                            label="是"
                                            value="1"
                                        ></el-option>
                                        <el-option
                                            label="否"
                                            value="0"
                                        ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span
                                    v-else
                                    :class="{color_yes:  scope.row.grandefault === '1', color_no:  scope.row.grandefault === '0'}"
                                >{{ scope.row.grandefault === '0' ? '否' : scope.row.grandefault === '1' ? '是' : '' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="standunit"
                            label="所属粒度"
                            width="100px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.standunit'"
                                    :rules="dialog.editorBox.form.rules.standunit"
                                >
                                    <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].standunit"
                                    >
                                        <el-option
                                            v-for="item of nameObj.unit.arr"
                                            :key="item.id"
                                            :value="item.id"
                                            :label="item.name"
                                        ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{ nameObj.unit.obj[scope.row.standunit] ? nameObj.unit.obj[scope.row.standunit] : scope.row.standunit }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="baseunit"
                            label="间隔粒度"
                            width="100px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.baseunit'"
                                    :rules="dialog.editorBox.form.rules.baseunit"
                                >
                                    <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].baseunit"
                                    >
                                        <el-option
                                            v-for="item of nameObj.unit.arr"
                                            :key="item.id"
                                            :value="item.id"
                                            :label="item.name"
                                        ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{ nameObj.unit.obj[scope.row.baseunit] ? nameObj.unit.obj[scope.row.baseunit] : scope.row.baseunit }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="calctype"
                            label="时间间隔方式"
                            width="110px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.calctype'"
                                    :rules="dialog.editorBox.form.rules.calctype"
                                >
                                    <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].calctype"
                                    >
                                        <el-option
                                            v-for="item of nameObj.calctype.arr"
                                            :key="item.id"
                                            :value="item.id"
                                            :label="item.name"
                                        ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{ nameObj.calctype.obj[scope.row.calctype] ? nameObj.calctype.obj[scope.row.calctype] : scope.row.calctype }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="interval"
                            label="间隔"
                            width="75px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.interval'"
                                    :rules="dialog.editorBox.form.rules.interval"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].interval"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.interval}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="startformat"
                            label="起始格式"
                            width="160px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.startformat'"
                                    :rules="dialog.editorBox.form.rules.startformat"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].startformat"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.startformat}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="endformat"
                            label="结束格式"
                            width="160px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.endformat'"
                                    :rules="dialog.editorBox.form.rules.endformat"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].endformat"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.endformat}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="timeformat"
                            label="内容格式"
                            width="160px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.timeformat'"
                                    :rules="dialog.editorBox.form.rules.timeformat"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].timeformat"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.timeformat}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="extrainfo"
                            label="附加序列"
                            width="100px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.extrainfo'"
                                    :rules="dialog.editorBox.form.rules.extrainfo"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].extrainfo"
                                    ></el-input>
                                </el-form-item>
                                <span v-else>{{scope.row.extrainfo}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="offsetinfo"
                            label="偏移量说明"
                            width="100px"
                            :show-overflow-tooltip="true"
                        > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.id + '.offsetinfo'"
                                    :rules="dialog.editorBox.form.rules.offsetinfo"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.id].offsetinfo"
                                    ></el-input>
                                </el-form-item>
                                <span v-else>{{scope.row.offsetinfo}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            sortable
                            prop="createman"
                            label="创建人"
                            min-width="60px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            sortable
                            prop="createtime"
                            label="创建时间"
                            min-width="125px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            sortable
                            prop="updateman"
                            label="修改人"
                            min-width="60px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            sortable
                            prop="updatetime"
                            label="修改时间"
                            width="125px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            class-name="gn-TableDownloadExcel-none"
                            label="操作"
                            align="center"
                            width="85px"
                            fixed="right"
                        > <template slot-scope="scope">
                                <div>
                                    <el-button
                                        type="primary"
                                        size="mini"
                                        @click="but_timeList(scope.row)"
                                    >序列列表</el-button>
                                    <!-- <el-button
                                    type="primary"
                                    size="mini"
                                    v-privilege="activeMenu + 'PUT'"
                                    @click="but_edit(scope.row)"
                                >修改</el-button>
                                <el-button
                                    type="danger"
                                    size="mini"
                                    v-privilege="activeMenu + 'DELETE'"
                                    @click="but_del(scope.row)"
                                >删除</el-button> -->
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form>
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    :page-sizes="[10, 20, 50, 100, 500, 1000]"
                    :page-size="pageSize"
                    :current-page.sync="pageNum"
                    @size-change="tableSizeChange"
                    @current-change="getTableData()"
                    style="text-align: right;margin-top: 10px;"
                ></el-pagination>
            </div>
        </div>
        <el-dialog
            :title="'时间序列 - ' + (dialog.editorBox.type === 'add' ? '新增' : '修改')"
            :visible.sync="dialog.editorBox.show"
            width="600px"
            :close-on-click-modal="false"
            :show-close="!loading"
        >
            <div>
                <el-form
                    ref="dialog_form"
                    :model="dialog.editorBox.form.data"
                    :rules="dialog.editorBox.form.rules"
                    size="mini"
                    label-width="85px"
                >
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="序列编号"
                                prop="id"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.id"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="序列名称"
                                prop="name"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.name"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="时间粒度"
                                prop="timegranid"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.timegranid"
                                >
                                    <el-option
                                        v-for="item of nameObj.timegranid.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="粒度默认序列"
                                prop="grandefault"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.grandefault"
                                >
                                    <el-option
                                        label="是"
                                        value="1"
                                    ></el-option>
                                    <el-option
                                        label="否"
                                        value="0"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="所属粒度"
                                prop="standunit"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.standunit"
                                >
                                    <el-option
                                        v-for="item of nameObj.unit.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="间隔粒度"
                                prop="baseunit"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.baseunit"
                                >
                                    <el-option
                                        v-for="item of nameObj.unit.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="时间间隔方式"
                                prop="calctype"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.calctype"
                                >
                                    <el-option
                                        v-for="item of nameObj.calctype.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="间隔"
                                prop="interval"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.interval"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="起始格式"
                                prop="startformat"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.startformat"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="结束格式"
                                prop="endformat"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.endformat"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="内容格式"
                                prop="timeformat"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.timeformat"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="附加序列"
                                prop="extrainfo"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.extrainfo"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="偏移量说明"
                                prop="offsetinfo"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.offsetinfo"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialog.editorBox.show = false"
                    :loading="loading"
                >取 消</el-button>
                <el-button
                    type="primary"
                    @click="dataSave"
                    :loading="loading"
                >保 存</el-button>
            </span>
        </el-dialog>
        <el-dialog
            title="时间序列列表"
            :visible.sync="dialog.timeList.show"
            width="600px"
            :close-on-click-modal="false"
            :show-close="!loading"
        >
            <div>
                <el-form
                    ref="timeList_form"
                    :model="dialog.timeList.form.data"
                    :rules="dialog.timeList.form.rules"
                    size="mini"
                    label-width="70px"
                >
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="起始时间"
                                prop="starttime"
                            >
                                <el-date-picker
                                    type="date"
                                    placeholder="起始时间"
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd"
                                    v-model="dialog.timeList.form.data.starttime"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="结束时间"
                                prop="endtime"
                            >
                                <el-date-picker
                                    type="date"
                                    placeholder="结束时间"
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd"
                                    v-model="dialog.timeList.form.data.endtime"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div style="padding-bottom: 7px;">
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-search"
                        @click="getTimeListTableData(1)"
                    >查询序列</el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-plus"
                        @click="addTimeListTableData()"
                    >生成序列</el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-delete"
                        @click="delTimeListTableData()"
                    >清空已生成序列</el-button>
                </div>
                <el-table
                    stripe
                    ref="singleTable"
                    :data="dialog.timeList.tableData"
                    v-loading="dialog.timeList.tableLoading"
                    style="width: 100%;"
                    height="200px"
                    border
                    size="mini"
                    highlight-current-row
                >
                    <el-table-column
                        sortable
                        prop="desttime"
                        label="目标时间"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="starttime"
                        label="起始时间"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="endtime"
                        label="截至时间"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                </el-table>
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="dialog.timeList.total"
                    :page-sizes="[10, 20, 50, 100, 500, 1000]"
                    :page-size="dialog.timeList.pageSize"
                    :current-page.sync="dialog.timeList.pageNum"
                    @size-change="timeListTableSizeChange"
                    @current-change="getTimeListTableData()"
                    style="text-align: right;margin-top: 10px;"
                ></el-pagination>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialog.timeList.show = false"
                    :loading="loading"
                >关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { zCheckNumber1 } from '@/utils/validator.js'
export default {
    name: 'timeSeries',
    data () {
        return {
            multipleSelection: [],
            tableFormDataObj: {},
            activeMenu: '',
            filterForm: {
                show: true,
                data: {
                    id: '',
                    name: '',
                    timegranid: ''
                },
                rules: {

                }
            },
            pageNum: 1,
            pageSize: 20,
            total: 0,
            singleTableHeight: 100,
            tableData: [
                // {
                //     id: 'day01',
                //     name: '日',
                //     timegranid: '日',
                //     grandefault: '0',
                //     standunit: '日',
                //     baseunit: '日',
                //     calctype: '固定时间',
                //     interval: '1',
                //     startformat: 'yyyyMMdd200000',
                //     endformat: 'yyyyMMdd195959',
                //     timeformat: 'yyyy-MM-dd',
                //     extrainfo: '',
                //     offsetinfo: 'dd-1,dd-1,'
                // }
            ],
            nameObj: {
                timegranid: {
                    obj: {},
                    arr: []
                },
                calctype: {
                    obj: {
                        'FixedSpan': '固定间隔',
                        'FixedCircle': '固定循环',
                        'FixedTime': '固定时间'
                    },
                    arr: [
                        {
                            id: 'FixedSpan',
                            name: '固定间隔'
                        },
                        {
                            id: 'FixedCircle',
                            name: '固定循环'
                        },
                        {
                            id: 'FixedTime',
                            name: '固定时间'
                        }
                    ]
                },
                unit: {
                    obj: {
                        'YEAR': '年',
                        'MONTH': '月',
                        'DAY': '日',
                        'HOUR': '小时',
                        'MINUTE': '分钟'
                    },
                    arr: [
                        {
                            id: 'YEAR',
                            name: '年'
                        },
                        {
                            id: 'MONTH',
                            name: '月'
                        },
                        {
                            id: 'DAY',
                            name: '日'
                        },
                        {
                            id: 'HOUR',
                            name: '小时'
                        },
                        {
                            id: 'MINUTE',
                            name: '分钟'
                        }
                    ]
                }
            },
            loading: false,
            tableLoading: false,
            dialog: {
                editorBox: {
                    show: false,
                    type: '',
                    form: {
                        data: {
                            id: '',
                            name: '',
                            timegranid: '',
                            grandefault: '',
                            standunit: '',
                            baseunit: '',
                            calctype: '',
                            interval: '',
                            startformat: '',
                            endformat: '',
                            timeformat: '',
                            extrainfo: '',
                            offsetinfo: ''
                        },
                        rules: {
                            id: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            name: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            timegranid: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            grandefault: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            standunit: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            baseunit: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            calctype: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            interval: [
                                { required: true, message: '该项不能为空', trigger: 'change' },
                                { validator: zCheckNumber1, trigger: 'change' }
                            ],
                            startformat: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            endformat: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ]
                        }
                    }
                },
                timeList: {
                    show: false,
                    row: null,
                    pageNum: 1,
                    pageSize: 20,
                    total: 0,
                    tableLoading: false,
                    tableData: [],
                    form: {
                        data: {
                            starttime: '',
                            endtime: ''
                        },
                        rules: {
                            // starttime: [
                            //     { required: true, message: '生成序列时该项不能为空' }
                            // ],
                            // endtime: [
                            //     { required: true, message: '生成序列时该项不能为空' }
                            // ]
                        }
                    }
                }
            }
        }
    },
    created () {
        this.activeMenu = window.localStorage.getItem('activeMenu');
    },
    mounted () {
        let that = this;
        window.PEDataObj = {
            // 将数据绑定到window上，供main页面使用
            vm: that,
            // tableArr：用于导出成Excel的表格的信息
            tableArr: [
                {
                    name: '',
                    id: 'singleTable'
                }
            ]
        };
        that.$nextTick(() => {
            // 立即获取的height有一定偏差，通过setTimeout延迟来解决
            setTimeout(() => {
                that.singleTableHeight = that.getRoleHeight(that.$refs['singleTable'].$el) - 45;
            }, 1);
        });
        that.getTimeGranData();
        that.getTableData();
    },
    methods: {
        //  计算树区域高度
        getRoleHeight (dom) {
            return window.innerHeight - dom.offsetTop;
        },
        // 获取时间粒度
        getTimeGranData () {
            let that = this
            let url = 'pass/ems/v1/trmtimegrans/getidandname/';
            that.axios.get(url)
                .then(function (res) {
                    if (res.code === '0') {
                        let arr = [];
                        let obj = {};
                        for (let item of res.data) {
                            arr.push({
                                id: item.id,
                                name: item.name
                            })
                            obj[item.id] = item.name;
                        }
                        that.nameObj.timegranid.arr = arr;
                        that.nameObj.timegranid.obj = obj;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        // 获取表格中的数据
        getTableData (pageNum) {
            let that = this,
                params = {
                    defid: that.filterForm.data.id,
                    defname: that.filterForm.data.name,
                    timegranid: that.filterForm.data.timegranid
                };
            that.pageNum = pageNum || that.pageNum;
            that.tableLoading = true;
            let url = 'pass/ems/v1/tcmtimedefinitions/like/?pageNum=' + that.pageNum + '&pageSize=' + that.pageSize;
            that.axios.get(url, {
                params: params
            })
                .then(function (res) {
                    if (res.code === '0') {
                        let arr = [];
                        for (let item of res.data.list) {
                            arr.push({
                                id: item.defid,
                                name: item.defname,
                                timegranid: item.timegranid,
                                grandefault: item.grandefault,
                                standunit: item.standunit,
                                baseunit: item.baseunit,
                                calctype: item.calctype,
                                interval: item.interval,
                                startformat: item.startformat,
                                endformat: item.endformat,
                                timeformat: item.timeformat,
                                extrainfo: item.extrainfo,
                                offsetinfo: item.offsetinfo,
                                createman: item.createman,
                                createtime: item.createtime,
                                updateman: item.updateman,
                                updatetime: item.updatetime
                            })
                        }
                        that.tableData = arr;
                        that.total = res.data.total;
                    } else {
                        that.$message.error(res.message);
                    }
                    that.tableLoading = false;
                }).catch(function () {
                    that.tableLoading = false;
                });
        },
        // 改变表格显示条数
        tableSizeChange (val) {
            let that = this;
            that.pageSize = val;
            that.getTableData(1);
        },
        // 重置搜索
        tableDataCancel () {
            let that = this;
            that.filterForm.data.id = '';
            that.filterForm.data.name = '';
            that.filterForm.data.timegranid = '';
            that.getTableData(1);
        },
        // 表格中多选按钮的相关方法
        handleSelectionChange (val) {
            let that = this;
            let tableFormDataObj = {};
            for (let item of that.tableData) {
                item.isSelection = false;
            }
            for (let item of val) {
                let obj = {};
                let xId = item.id;
                if (that.tableFormDataObj[xId]) {
                    tableFormDataObj[xId] = that.tableFormDataObj[xId];
                } else {
                    for (let key in item) {
                        obj[key] = item[key];
                    }
                    tableFormDataObj[xId] = obj;
                }
                item.isSelection = true;
            }
            that.tableFormDataObj = tableFormDataObj;
            that.multipleSelection = val;
        },
        but_add () {
            let that = this;
            that.dialog.editorBox.form.data.id = '';
            that.dialog.editorBox.form.data.name = '';
            that.dialog.editorBox.form.data.timegranid = '';
            that.dialog.editorBox.form.data.grandefault = '0';
            that.dialog.editorBox.form.data.standunit = '';
            that.dialog.editorBox.form.data.baseunit = '';
            that.dialog.editorBox.form.data.calctype = '';
            that.dialog.editorBox.form.data.interval = '';
            that.dialog.editorBox.form.data.startformat = '';
            that.dialog.editorBox.form.data.endformat = '';
            that.dialog.editorBox.form.data.timeformat = '';
            that.dialog.editorBox.form.data.extrainfo = '';
            that.dialog.editorBox.form.data.offsetinfo = '';
            that.dialog.editorBox.type = 'add';
            that.dialog.editorBox.show = true;
            setTimeout(() => {
                that.$refs['dialog_form'].clearValidate();
            }, 100);
        },
        // 批量修改
        but_edit_plural () {
            let that = this;
            if (that.multipleSelection.length > 0) {
                that.$refs['dialog_form_arr'].validate((valid) => {
                    if (valid) {
                        let SubmitData = [];
                        for (let key in that.tableFormDataObj) {
                            SubmitData.push({
                                defid: that.tableFormDataObj[key].id,
                                defname: that.tableFormDataObj[key].name,
                                timegranid: that.tableFormDataObj[key].timegranid,
                                grandefault: that.tableFormDataObj[key].grandefault,
                                standunit: that.tableFormDataObj[key].standunit,
                                baseunit: that.tableFormDataObj[key].baseunit,
                                calctype: that.tableFormDataObj[key].calctype,
                                interval: that.tableFormDataObj[key].interval,
                                startformat: that.tableFormDataObj[key].startformat,
                                endformat: that.tableFormDataObj[key].endformat,
                                timeformat: that.tableFormDataObj[key].timeformat,
                                extrainfo: that.tableFormDataObj[key].extrainfo,
                                offsetinfo: that.tableFormDataObj[key].offsetinfo
                            });
                        }
                        that.loading = true;
                        that.axios.put('pass/ems/v1/tcmtimedefinitions/', SubmitData)
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '修改成功',
                                        type: 'success'
                                    });
                                    that.getTableData();
                                    that.dialog.editorBox.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    }
                });
            } else {
                this.$message.error('至少要选择一条数据');
            }
        },
        // 批量删除
        but_del_plural () {
            let that = this;
            if (that.multipleSelection.length > 0) {
                let ids = [];
                for (let item of that.multipleSelection) {
                    ids.push(item.id);
                }
                that.$confirm('是否删除已选数据?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    state: 'warning'
                }).then(() => {
                    that.axios.delete('pass/ems/v1/tcmtimedefinitions/' + ids.toString())
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    message: '删除成功',
                                    type: 'success'
                                });
                                that.getTableData();
                            } else {
                                if (res.code === '51') {

                                }
                                that.$message.error(res.message);
                            }
                        }).catch(function () {
                        });
                }).catch(() => {
                });
            } else {
                this.$message.error('至少要选择一条数据');
            }
        },
        // but_edit (row) {
        //     let that = this;
        //     that.dialog.editorBox.form.data.id = row.id;
        //     that.dialog.editorBox.form.data.name = row.name;
        //     that.dialog.editorBox.form.data.timegranid = row.timegranid;
        //     that.dialog.editorBox.form.data.grandefault = row.grandefault;
        //     that.dialog.editorBox.form.data.standunit = row.standunit;
        //     that.dialog.editorBox.form.data.baseunit = row.baseunit;
        //     that.dialog.editorBox.form.data.calctype = row.calctype;
        //     that.dialog.editorBox.form.data.interval = row.interval;
        //     that.dialog.editorBox.form.data.startformat = row.startformat;
        //     that.dialog.editorBox.form.data.endformat = row.endformat;
        //     that.dialog.editorBox.form.data.timeformat = row.timeformat;
        //     that.dialog.editorBox.form.data.extrainfo = row.extrainfo;
        //     that.dialog.editorBox.form.data.offsetinfo = row.offsetinfo;
        //     that.dialog.editorBox.type = 'edit';
        //     that.dialog.editorBox.show = true;
        // },
        // but_del (row) {
        //     let that = this;
        //     that.$confirm('是否删除该条数据?', '提示', {
        //         confirmButtonText: '确定',
        //         cancelButtonText: '取消',
        //         state: 'warning'
        //     }).then(() => {
        //         that.axios.delete('pass/ems/v1/tcmtimedefinitions/' + row.id)
        //             .then(function (res) {
        //                 if (res.code === '0') {
        //                     that.$message({
        //                         message: '删除成功',
        //                         type: 'success'
        //                     });
        //                     that.getTableData();
        //                 } else {
        //                     that.$message.error(res.message);
        //                 }
        //             }).catch(function () {
        //             });
        //     }).catch(() => {
        //     });
        // },
        dataSave () {
            let that = this;
            let SubmitData = {
                id: that.dialog.editorBox.form.data.id,
                defname: that.dialog.editorBox.form.data.name,
                timegranid: that.dialog.editorBox.form.data.timegranid,
                grandefault: that.dialog.editorBox.form.data.grandefault,
                standunit: that.dialog.editorBox.form.data.standunit,
                baseunit: that.dialog.editorBox.form.data.baseunit,
                calctype: that.dialog.editorBox.form.data.calctype,
                interval: that.dialog.editorBox.form.data.interval,
                startformat: that.dialog.editorBox.form.data.startformat,
                endformat: that.dialog.editorBox.form.data.endformat,
                timeformat: that.dialog.editorBox.form.data.timeformat,
                extrainfo: that.dialog.editorBox.form.data.extrainfo,
                offsetinfo: that.dialog.editorBox.form.data.offsetinfo
            };
            that.$refs['dialog_form'].validate((valid) => {
                if (valid) {
                    if (that.dialog.editorBox.type === 'add') {
                        let foorData = new FormData();
                        for (let key in SubmitData) {
                            foorData.append(key, SubmitData[key]);
                        }
                        that.loading = true;
                        that.axios.post('pass/ems/v1/tcmtimedefinitions/', foorData, {
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        })
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '新增成功',
                                        type: 'success'
                                    });
                                    that.getTableData();
                                    that.dialog.editorBox.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    } else {
                        that.loading = true;
                        that.axios.put('pass/ems/v1/tcmtimedefinitions/' + SubmitData.id, SubmitData)
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '修改成功',
                                        type: 'success'
                                    });
                                    that.getTableData();
                                    that.dialog.editorBox.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    }
                }
            });
        },
        but_timeList (row) {
            let that = this;
            that.dialog.timeList.row = row;
            that.dialog.timeList.form.data.starttime = '';
            that.dialog.timeList.form.data.endtime = '';
            that.dialog.timeList.tableData = [];
            that.dialog.timeList.show = true;
            // that.getTimeListTableData(1);
        },
        // 获取序列列表表格中的数据
        getTimeListTableData (pageNum) {
            let that = this,
                params = {
                    defid: that.dialog.timeList.row.id,
                    defname: that.dialog.timeList.row.name,
                    timegranid: that.dialog.timeList.row.timegranid,
                    grandefault: that.dialog.timeList.row.grandefault,
                    standunit: that.dialog.timeList.row.standunit,
                    baseunit: that.dialog.timeList.row.baseunit,
                    calctype: that.dialog.timeList.row.calctype,
                    interval: that.dialog.timeList.row.interval,
                    startformat: that.dialog.timeList.row.startformat,
                    endformat: that.dialog.timeList.row.endformat,
                    timeformat: that.dialog.timeList.row.timeformat,
                    extrainfo: that.dialog.timeList.row.extrainfo,
                    offsetinfo: that.dialog.timeList.row.offsetinfo,
                    starttime: that.dialog.timeList.form.data.starttime,
                    endtime: that.dialog.timeList.form.data.endtime
                };
            that.dialog.timeList.pageNum = pageNum || that.dialog.timeList.pageNum;
            that.dialog.timeList.tableLoading = true;
            let url = 'pass/ems/v1/tcmtimelists/?pageNum=' + that.dialog.timeList.pageNum + '&pageSize=' + that.dialog.timeList.pageSize;
            that.axios.get(url, {
                params: params
            })
                .then(function (res) {
                    if (res.code === '0') {
                        let arr = [];
                        for (let item of res.data.list) {
                            arr.push({
                                // id: item.id,
                                desttime: item.desttime,
                                starttime: item.starttime,
                                endtime: item.endtime
                            })
                        }
                        that.dialog.timeList.tableData = arr;
                        that.dialog.timeList.total = res.data.total;
                    } else {
                        that.$message.error(res.message);
                    }
                    that.dialog.timeList.tableLoading = false;
                }).catch(function () {
                    that.dialog.timeList.tableLoading = false;
                });
        },
        // 改变序列列表表格显示条数
        timeListTableSizeChange (val) {
            let that = this;
            that.dialog.timeList.pageSize = val;
            that.getTimeListTableData(1);
        },
        addTimeListTableData () {
            let that = this;
            if (that.dialog.timeList.form.data.starttime && that.dialog.timeList.form.data.endtime) {
                if (that.dialog.timeList.form.data.starttime <= that.dialog.timeList.form.data.endtime) {
                    let SubmitData = {
                        id: that.dialog.timeList.row.id,
                        defname: that.dialog.timeList.row.name,
                        timegranid: that.dialog.timeList.row.timegranid,
                        grandefault: that.dialog.timeList.row.grandefault,
                        standunit: that.dialog.timeList.row.standunit,
                        baseunit: that.dialog.timeList.row.baseunit,
                        calctype: that.dialog.timeList.row.calctype,
                        interval: that.dialog.timeList.row.interval,
                        startformat: that.dialog.timeList.row.startformat,
                        endformat: that.dialog.timeList.row.endformat,
                        timeformat: that.dialog.timeList.row.timeformat,
                        extrainfo: that.dialog.timeList.row.extrainfo,
                        offsetinfo: that.dialog.timeList.row.offsetinfo,
                        starttime: that.dialog.timeList.form.data.starttime,
                        endtime: that.dialog.timeList.form.data.endtime
                    };
                    that.loading = true;
                    that.axios.post('pass/ems/v1/tcmtimelists/', SubmitData)
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    message: '生成成功',
                                    type: 'success'
                                });
                                that.getTimeListTableData(1);
                            } else {
                                that.$message.error(res.message);
                            }
                            that.loading = false;
                        }).catch(function () {
                            that.loading = false;
                        });
                } else {
                    that.$message.error('起始时间不能大于结束时间');
                }
            } else {
                that.$message.error('请输入起始时间与结束时间');
            }
        },
        delTimeListTableData () {
            let that = this;
            that.$confirm('是否清空已生成序列?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                state: 'warning'
            }).then(() => {
                let SubmitData = {
                    defid: that.dialog.timeList.row.id,
                    defname: that.dialog.timeList.row.name,
                    timegranid: that.dialog.timeList.row.timegranid,
                    grandefault: that.dialog.timeList.row.grandefault,
                    standunit: that.dialog.timeList.row.standunit,
                    baseunit: that.dialog.timeList.row.baseunit,
                    calctype: that.dialog.timeList.row.calctype,
                    interval: that.dialog.timeList.row.interval,
                    startformat: that.dialog.timeList.row.startformat,
                    endformat: that.dialog.timeList.row.endformat,
                    timeformat: that.dialog.timeList.row.timeformat,
                    extrainfo: that.dialog.timeList.row.extrainfo,
                    offsetinfo: that.dialog.timeList.row.offsetinfo,
                    starttime: that.dialog.timeList.form.data.starttime,
                    endtime: that.dialog.timeList.form.data.endtime
                };
                that.axios.delete('pass/ems/v1/tcmtimelists/', {
                    data: SubmitData,
                    contentType: 'application/json'
                })
                    .then(function (res) {
                        if (res.code === '0') {
                            that.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            that.getTimeListTableData(1);
                        } else {
                            that.$message.error(res.message);
                        }
                    }).catch(function () {
                    });
            }).catch(() => {
            });
        }
    }
}
</script>

<style lang="less">
.timeSeries {
    min-width: 700px;
    height: 100%;
    .box {
        height: 100%;
        padding: 15px 15px 0 15px;
        .box-top {
            .el-form-item {
                margin-bottom: 7px;
            }
            .box-top-gjl {
                overflow: hidden;
                // margin-top: -7px;
                padding: 7px 0;
                border-top: 1px solid #ccc;
                // border-bottom: 1px solid #ccc;
                // margin-bottom: 6px;
            }
        }
        .el-table .el-table__row {
            height: 35px;
        }
        .el-table__body .el-form-item--mini.el-form-item {
            margin: 0px;
            .error {
                overflow: hidden;
                color: #f56c6c;
                font-size: 12px;
                line-height: 1;
            }
        }
    }
    .color_no {
        color: #7a7a7a;
    }
    .color_yes {
        color: #1a9f17;
    }
}
</style>
