<template>
<!-- 数据源计算逻辑维护 -->
    <div class="dataCalculateLogic">
        <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-select
                                filterable clearable
                                    v-model="filterForm.data.datasourcename"
                                    placeholder=""
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.datasourcename.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </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-col :span="6">
                            <el-form-item label="计算方式">
                                <el-select
                                filterable clearable
                                    v-model="filterForm.data.calcmode"
                                    placeholder=""
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.calcmode.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="累计粒度">
                                <el-select
                                filterable clearable
                                    v-model="filterForm.data.sumgran"
                                    placeholder=""
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.sumgran.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>
                    <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-table stripe
                    id="singleTable"
                    ref="singleTable"
                    :data="tableData"
                    v-loading="tableLoading"
                    style="width: 100%;"
                    :height="singleTableHeight"
                    border
                    size="mini"
                    highlight-current-row
                >
                    <el-table-column
                    sortable
                        prop="datasourcename"
                        label="数据源名称"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.datasourcename.obj[scope.row.datasourcename] ? nameObj.datasourcename.obj[scope.row.datasourcename] : scope.row.datasourcename }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="timegranid"
                        label="时间粒度"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ 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="initOffset"
                        label="初始偏移"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                    sortable
                        prop="calcmode"
                        label="默认计算方式"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.calcmode.obj[scope.row.calcmode] ? nameObj.calcmode.obj[scope.row.calcmode] : scope.row.calcmode }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="calcgran"
                        label="计算基础粒度"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.timegranid.obj[scope.row.calcgran] ? nameObj.timegranid.obj[scope.row.calcgran] : scope.row.calcgran }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="ucenabled"
                        label="是否计算单耗"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span :class="{color_yes:  scope.row.granDefault === '1', color_no:  scope.row.granDefault === '0'}">{{ scope.row.ucenabled === '0' ? '否' : scope.row.ucenabled === '1' ? '是' : '' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="sumenabled"
                        label="是否需要累计"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span :class="{color_yes:  scope.row.granDefault === '1', color_no:  scope.row.granDefault === '0'}">{{ scope.row.sumenabled === '0' ? '否' : scope.row.sumenabled === '1' ? '是' : '' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="enablesumfmla"
                        label="使用累计计算公式"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span :class="{color_yes:  scope.row.granDefault === '1', color_no:  scope.row.granDefault === '0'}">{{ scope.row.enablesumfmla === '0' ? '否' : scope.row.enablesumfmla === '1' ? '是' : '' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="sumgran"
                        label="累计粒度"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.sumgran.obj[scope.row.sumgran] ? nameObj.sumgran.obj[scope.row.sumgran] : scope.row.sumgran }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="autocpmode"
                        label="自动计算点算法"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.autocpmode.obj[scope.row.autocpmode] ? nameObj.autocpmode.obj[scope.row.autocpmode] : scope.row.autocpmode }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        class-name="gn-TableDownloadExcel-none"
                        label="操作"
                        align="center"
                        width="230px"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div>
                                <el-button
                                    type="primary"
                                    size="mini"
                                    @click="but_additional(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-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"
        >
            <el-tabs
                v-model="dialog.editorBox.activeName"
                type="border-card"
            >
                <el-tab-pane
                    label="基础信息"
                    name="1"
                >
                    <div>
                        <el-form
                            ref="dialog_form"
                            :model="dialog.editorBox.form.data"
                            :rules="dialog.editorBox.form.rules"
                            size="mini"
                            label-width="120px"
                        >
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item
                                        label="数据源名称"
                                        prop="datasourcename"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.datasourcename"
                                            :disabled="dialog.editorBox.boxType === 1"
                                        >
                                            <el-option
                                                v-for="item of nameObj.datasourcename.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="timegranid"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.timegranid"
                                            :disabled="dialog.editorBox.boxType === 1"
                                        >
                                            <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-row>
                                <el-col :span="12">
                                    <el-form-item
                                        label="初始偏移"
                                        v-if="dialog.editorBox.boxType === 0"
                                        prop="initOffset"
                                    >
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.initOffset"
                                        ></el-input>
                                    </el-form-item>
                                    <el-form-item
                                        label="项目"
                                        v-if="dialog.editorBox.boxType === 1"
                                        prop="itemid"
                                    >
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.itemid"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item
                                        label="默认计算方式"
                                        prop="calcmode"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.calcmode"
                                        >
                                            <el-option
                                                v-for="item of nameObj.calcmode.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="calcgran"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.calcgran"
                                        >
                                            <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="ucenabled"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.ucenabled"
                                        >
                                            <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="sumenabled"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.sumenabled"
                                        >
                                            <el-option
                                                label="是"
                                                value="1"
                                            ></el-option>
                                            <el-option
                                                label="否"
                                                value="0"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item
                                        label="使用累计计算公式"
                                        prop="enablesumfmla"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.enablesumfmla"
                                        >
                                            <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="sumgran"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.sumgran"
                                        >
                                            <el-option
                                                v-for="item of nameObj.sumgran.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="autocpmode"
                                    >
                                        <el-select
                                filterable clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form.data.autocpmode"
                                        >
                                            <el-option
                                                v-for="item of nameObj.autocpmode.arr"
                                                :key="item.id"
                                                :value="item.id"
                                                :label="item.name"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </div>
                </el-tab-pane>
                <el-tab-pane
                    label="额外属性"
                    name="2"
                >
                    <div>
                        <el-form
                            ref="dialog_form1"
                            :model="dialog.editorBox.form1.data"
                            :rules="dialog.editorBox.form1.rules"
                            size="mini"
                            label-width="120px"
                        >
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="默认精度" prop="digits">
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form1.data.digits"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="累计值精度" prop="sumdigits">
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form1.data.sumdigits"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="折标值精度" prop="stddigits">
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form1.data.stddigits"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="折标累计精度" prop="sumstddigits">
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form1.data.sumstddigits"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="单耗值精度" prop="ucdigits">
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form1.data.ucdigits"
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="累计单耗值精度" prop="sumucdigits">
                                        <el-input clearable
                                            style="width: 100%;"
                                            v-model="dialog.editorBox.form1.data.sumucdigits"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </div>
                </el-tab-pane>
            </el-tabs>
            <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.additionalBox.show"
            width="80%"
            :close-on-click-modal="false"
            :show-close="!loading"
        >
            <div>
                <div style="padding-bottom: 7px;">
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-plus"
                        @click="but_add(1)"
                    >新增</el-button>
                </div>
                <el-table stripe
                    :data="dialog.additionalBox.tableData"
                    v-loading="dialog.additionalBox.tableLoading"
                    style="width: 100%;"
                    :height="(singleTableHeight - 60) + 'px'"
                    border
                    size="mini"
                    highlight-current-row
                >
                    <el-table-column
                    sortable
                        prop="datasourcename"
                        label="数据源名称"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.datasourcename.obj[scope.row.datasourcename] ? nameObj.datasourcename.obj[scope.row.datasourcename] : scope.row.datasourcename }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="timegranid"
                        label="时间粒度"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ 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="itemid"
                        label="项目"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                    sortable
                        prop="calcmode"
                        label="默认计算方式"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.calcmode.obj[scope.row.calcmode] ? nameObj.calcmode.obj[scope.row.calcmode] : scope.row.calcmode }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="calcgran"
                        label="计算基础粒度"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.timegranid.obj[scope.row.calcgran] ? nameObj.timegranid.obj[scope.row.calcgran] : scope.row.calcgran }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="ucenabled"
                        label="是否计算单耗"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span :class="{color_yes:  scope.row.granDefault === '1', color_no:  scope.row.granDefault === '0'}">{{ scope.row.ucenabled === '0' ? '否' : scope.row.ucenabled === '1' ? '是' : '' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="sumenabled"
                        label="是否需要累计"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span :class="{color_yes:  scope.row.granDefault === '1', color_no:  scope.row.granDefault === '0'}">{{ scope.row.sumenabled === '0' ? '否' : scope.row.sumenabled === '1' ? '是' : '' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="enablesumfmla"
                        label="使用累计计算公式"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span :class="{color_yes:  scope.row.granDefault === '1', color_no:  scope.row.granDefault === '0'}">{{ scope.row.enablesumfmla === '0' ? '否' : scope.row.enablesumfmla === '1' ? '是' : '' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="sumgran"
                        label="累计粒度"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.sumgran.obj[scope.row.sumgran] ? nameObj.sumgran.obj[scope.row.sumgran] : scope.row.sumgran }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="autocpmode"
                        label="自动计算点算法"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.autocpmode.obj[scope.row.autocpmode] ? nameObj.autocpmode.obj[scope.row.autocpmode] : scope.row.autocpmode }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        label="操作"
                        align="center"
                        width="140px"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div>
                                <el-button
                                    type="primary"
                                    size="mini"
                                    @click="but_edit(scope.row, 1)"
                                >修改</el-button>
                                <el-button
                                    type="danger"
                                    size="mini"
                                    @click="but_del(scope.row, 1)"
                                >删除</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="dialog.additionalBox.total"
                    :page-sizes="[10, 20, 50, 100, 500, 1000]"
                    :page-size="dialog.additionalBox.pageSize"
                    :current-page.sync="dialog.additionalBox.pageNum"
                    @size-change="additionalTableSizeChange"
                    @current-change="getAdditionalTableData()"
                    style="text-align: right;margin-top: 10px;"
                ></el-pagination>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button @click="dialog.additionalBox.show = false">取 消</el-button>
                <el-button
                    type="primary"
                    @click="dialog.additionalBox.show = false"
                >保 存</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { zCheckNumber2 } from '@/utils/validator.js'
export default {
    name: 'dataCalculateLogic',
    data () {
        return {
            activeMenu: '',
            filterForm: {
                show: true,
                data: {
                    datasourcename: '',
                    timegranid: '',
                    calcmode: '',
                    sumgran: ''
                },
                rules: {

                }
            },
            pageNum: 1,
            pageSize: 20,
            total: 0,
            singleTableHeight: 100,
            tableData: [
                // {
                //     recordid: '001', // id
                //     datasourcename: '计量点项目',
                //     timegranid: '日',
                //     initOffset: 'dd-1',
                //     calcmode: '其间累加',
                //     calcgran: '日',
                //     ucenabled: '0',
                //     sumenabled: '0',
                //     enablesumfmla: '0',
                //     sumgran: '日',
                //     autocpmode: '使用默认'
                // }
            ],
            nameObj: {
                datasourcename: {
                    obj: {
                        'T_RM_CALPOINT_VALUE.': '计量点项目',
                        'T_RM_ENERGY_CONVERT.': '折算系数',
                        'T_RM_INDEX_VALUE.': '经济指标',
                        'T_RM_BALANCE_VALUE.B': '平衡表项目',
                        'T_RM_ACT_VALUE.R': '供需实绩项目',
                        'T_RM_PLAN_VALUE.P': '供需计划项目',
                        'T_CM_0318.': '质量水项目',
                        'T_CM_0318ZZ.': '质量厂水项目',
                        'T_CM_0348.': '质量动力项目',
                        'T_CM_0331.': '质量环保项目',
                        'T_RM_WORKPROC_MATERIAL_VALUE.P': '计划原材料耗用量',
                        'T_RM_WORKPROC_MATERIAL_VALUE.R': '实绩原材料耗用量',
                        'T_RM_WORKPROC_PRODUCT_VALUE.P': '计划产量',
                        'T_RM_WORKPROC_PRODUCT_VALUE.R': '实绩产量'
                    },
                    arr: [
                        {
                            id: 'T_RM_CALPOINT_VALUE.',
                            name: '计量点项目'
                        },
                        {
                            id: 'T_RM_ENERGY_CONVERT.',
                            name: '折算系数'
                        },
                        {
                            id: 'T_RM_INDEX_VALUE.',
                            name: '经济指标'
                        },
                        {
                            id: 'T_RM_BALANCE_VALUE.B',
                            name: '平衡表项目'
                        },
                        {
                            id: 'T_RM_ACT_VALUE.R',
                            name: '供需实绩项目'
                        },
                        {
                            id: 'T_RM_PLAN_VALUE.P',
                            name: '供需计划项目'
                        },
                        {
                            id: 'T_CM_0318.',
                            name: '质量水项目'
                        },
                        {
                            id: 'T_CM_0318ZZ.',
                            name: '质量厂水项目'
                        },
                        {
                            id: 'T_CM_0348.',
                            name: '质量动力项目'
                        },
                        {
                            id: 'T_CM_0331.',
                            name: '质量环保项目'
                        },
                        {
                            id: 'T_RM_WORKPROC_MATERIAL_VALUE.P',
                            name: '计划原材料耗用量'
                        },
                        {
                            id: 'T_RM_WORKPROC_MATERIAL_VALUE.R',
                            name: '实绩原材料耗用量'
                        },
                        {
                            id: 'T_RM_WORKPROC_PRODUCT_VALUE.P',
                            name: '计划产量'
                        },
                        {
                            id: 'T_RM_WORKPROC_PRODUCT_VALUE.R',
                            name: '实绩产量'
                        }
                    ]
                },
                calcmode: {
                    obj: {
                        'SUM': '期间累加',
                        'FORMULA': '调用报表公式',
                        'AVGSHARE': '平均分摊',
                        'ROLLSHARE': '滚动分摊',
                        'PLANCONFIG': '计划配置'
                    },
                    arr: [
                        {
                            id: 'SUM',
                            name: '期间累加'
                        },
                        {
                            id: 'FORMULA',
                            name: '调用报表公式'
                        },
                        {
                            id: 'AVGSHARE',
                            name: '平均分摊'
                        },
                        {
                            id: 'ROLLSHARE',
                            name: '滚动分摊'
                        },
                        {
                            id: 'PLANCONFIG',
                            name: '计划配置'
                        }
                    ]
                },
                sumgran: {
                    obj: {
                        'YEAR': '年',
                        'MONTH': '月',
                        'DAY': '日',
                        'HOUR': '小时'
                    },
                    arr: [
                        {
                            id: 'YEAR',
                            name: '年'
                        },
                        {
                            id: 'MONTH',
                            name: '月'
                        },
                        {
                            id: 'DAY',
                            name: '日'
                        },
                        {
                            id: 'HOUR',
                            name: '小时'
                        }
                    ]
                },
                autocpmode: {
                    obj: {
                        'HourMinus': '首尾相减',
                        'SumHour': '小时累计',
                        'Default': '使用默认'
                    },
                    arr: [
                        {
                            id: 'HourMinus',
                            name: '首尾相减'
                        },
                        {
                            id: 'SumHour',
                            name: '小时累计'
                        },
                        {
                            id: 'Default',
                            name: '使用默认'
                        }
                    ]
                },
                timegranid: {
                    obj: {},
                    arr: []
                }
            },
            loading: false,
            tableLoading: false,
            dialog: {
                editorBox: {
                    show: false,
                    type: '',
                    activeName: '1',
                    boxType: 0,
                    form: {
                        data: {
                            recordid: '',
                            datasourcename: '',
                            timegranid: '',
                            initOffset: '',
                            itemid: '',
                            calcmode: '',
                            calcgran: '',
                            ucenabled: '',
                            sumenabled: '',
                            enablesumfmla: '',
                            sumgran: '',
                            autocpmode: ''
                        },
                        rules: {
                            datasourcename: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            timegranid: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            itemid: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ]
                        }
                    },
                    form1: {
                        data: {
                            digits: '',
                            sumdigits: '',
                            ucdigits: '',
                            sumucdigits: '',
                            stddigits: '',
                            sumstddigits: ''
                        },
                        rules: {
                            digits: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ],
                            sumdigits: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ],
                            ucdigits: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ],
                            sumucdigits: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ],
                            stddigits: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ],
                            sumstddigits: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ]
                        }
                    }
                },
                additionalBox: {
                    intentRow: {},
                    show: false,
                    pageNum: 1,
                    pageSize: 20,
                    total: 0,
                    singleTableHeight: 100,
                    tableData: [
                        {
                            recordid: '001',
                            datasourcename: '计量点项目',
                            timegranid: '日',
                            itemid: 'sdfafa',
                            calcmode: '其间累加',
                            calcgran: '日',
                            ucenabled: '0',
                            sumenabled: '0',
                            enablesumfmla: '0',
                            sumgran: '日',
                            autocpmode: '使用默认'
                        }
                    ],
                    tableLoading: false
                }
            }
        }
    },
    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 = {
                    datasourcename: that.filterForm.data.datasourcename,
                    timegranid: that.filterForm.data.timegranid,
                    calcmode: that.filterForm.data.calcmode,
                    sumgran: that.filterForm.data.sumgran
                };
            that.pageNum = pageNum || that.pageNum;
            that.tableLoading = true;
            let url = 'pass/ems/v1/tcmdatasourcetimegrans/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({
                                recordid: item.recordid,
                                datasourcename: item.datasourcename,
                                timegranid: item.timegranid,
                                initOffset: item.initOffset,
                                calcmode: item.calcmode,
                                calcgran: item.calcgran,
                                ucenabled: item.ucenabled,
                                sumenabled: item.sumenabled,
                                enablesumfmla: item.enablesumfmla,
                                sumgran: item.sumgran,
                                autocpmode: item.autocpmode,
                                // 额外属性
                                digits: item.digits,
                                sumdigits: item.sumdigits,
                                ucdigits: item.ucdigits,
                                sumucdigits: item.sumucdigits,
                                stddigits: item.stddigits,
                                sumstddigits: item.sumstddigits
                            })
                        }
                        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.datasourcename = '';
            that.filterForm.data.timegranid = '';
            that.filterForm.data.calcmode = '';
            that.filterForm.data.sumgran = '';
            that.getTableData(1);
        },
        but_additional (row) {
            let that = this;
            that.dialog.additionalBox.intentRow = row;
            that.dialog.additionalBox.tableData = [];
            that.dialog.additionalBox.total = 0;
            that.getAdditionalTableData(1);
            that.dialog.additionalBox.show = true;
        },
        // 获取算法额外的表格中的数据
        getAdditionalTableData (pageNum) {
            let that = this,
                params = {
                    datasourcename: that.dialog.additionalBox.intentRow.datasourcename,
                    timegranid: that.dialog.additionalBox.intentRow.timegranid
                };
            that.pageNum = pageNum || that.dialog.additionalBox.pageNum;
            that.dialog.additionalBox.tableLoading = true;
            let url = 'pass/ems/v1/tcmdatasourceexceptions/?pageNum=' + that.dialog.additionalBox.pageNum + '&pageSize=' + that.dialog.additionalBox.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({
                                recordid: item.recordid,
                                datasourcename: item.datasourcename,
                                timegranid: item.timegranid,
                                itemid: item.itemid,
                                calcmode: item.calcmode,
                                calcgran: item.calcgran,
                                ucenabled: item.ucenabled,
                                sumenabled: item.sumenabled,
                                enablesumfmla: item.enablesumfmla,
                                sumgran: item.sumgran,
                                autocpmode: item.autocpmode,
                                // 额外属性
                                digits: item.digits,
                                sumdigits: item.sumdigits,
                                ucdigits: item.ucdigits,
                                sumucdigits: item.sumucdigits,
                                stddigits: item.stddigits,
                                sumstddigits: item.sumstddigits
                            })
                        }
                        that.dialog.additionalBox.tableData = arr;
                        that.dialog.additionalBox.total = res.data.total;
                    } else {
                        that.$message.error(res.message);
                    }
                    that.dialog.additionalBox.tableLoading = false;
                }).catch(function () {
                    that.dialog.additionalBox.tableLoading = false;
                });
        },
        // 改变算法额外的表格显示条数
        additionalTableSizeChange (val) {
            let that = this;
            that.pageSize = val;
            that.getAdditionalTableData(1);
        },
        but_add (type = 0) {
            let that = this;
            if (type === 1) {
                for (let key in that.dialog.editorBox.form.data) {
                    if (typeof that.dialog.additionalBox.intentRow[key] !== 'undefined') {
                        that.dialog.editorBox.form.data[key] = that.dialog.additionalBox.intentRow[key];
                    }
                }
                for (let key in that.dialog.editorBox.form1.data) {
                    if (typeof that.dialog.additionalBox.intentRow[key] !== 'undefined') {
                        that.dialog.editorBox.form1.data[key] = that.dialog.additionalBox.intentRow[key];
                    }
                }
                that.dialog.editorBox.form.data.recordid = '';
                that.dialog.editorBox.form.data.itemid = '';
            } else {
                for (let key in that.dialog.editorBox.form.data) {
                    that.dialog.editorBox.form.data[key] = '';
                }
                that.dialog.editorBox.form.data.ucenabled = '0';
                that.dialog.editorBox.form.data.sumenabled = '0';
                that.dialog.editorBox.form.data.enablesumfmla = '0';
                for (let key in that.dialog.editorBox.form1.data) {
                    that.dialog.editorBox.form1.data[key] = '';
                }
            }
            that.dialog.editorBox.boxType = type;
            that.dialog.editorBox.activeName = '1';
            that.dialog.editorBox.type = 'add';
            that.dialog.editorBox.show = true;
            setTimeout(() => {
                that.$refs['dialog_form'].clearValidate();
            }, 100);
        },
        but_edit (row, type = 0) {
            let that = this;
            for (let key in that.dialog.editorBox.form.data) {
                if (typeof row[key] !== 'undefined') {
                    that.dialog.editorBox.form.data[key] = row[key];
                }
            }
            for (let key in that.dialog.editorBox.form1.data) {
                if (typeof row[key] !== 'undefined') {
                    that.dialog.editorBox.form1.data[key] = row[key];
                }
            }
            that.dialog.editorBox.boxType = type;
            that.dialog.editorBox.activeName = '1';
            that.dialog.editorBox.type = 'edit';
            that.dialog.editorBox.show = true;
        },
        but_del (row, type = 0) {
            let that = this;
            that.$confirm('是否删除该条数据?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                state: 'warning'
            }).then(() => {
                let url = 'pass/ems/v1/tcmdatasourcetimegrans/';
                let getTableData = that.getTableData;
                if (that.dialog.editorBox.boxType === 1) {
                    url = 'pass/ems/v1/tcmdatasourceexceptions/';
                    getTableData = that.getAdditionalTableData;
                }
                that.axios.delete(url + row.recordid)
                    .then(function (res) {
                        if (res.code === '0') {
                            that.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            getTableData();
                        } else {
                            that.$message.error(res.message);
                        }
                    }).catch(function () {
                    });
            }).catch(() => {
            });
        },
        dataSave () {
            let that = this;
            let SubmitData = {
                recordid: that.dialog.editorBox.form.data.recordid,
                datasourcename: that.dialog.editorBox.form.data.datasourcename,
                timegranid: that.dialog.editorBox.form.data.timegranid,
                initOffset: that.dialog.editorBox.form.data.initOffset,
                itemid: that.dialog.editorBox.form.data.itemid,
                calcmode: that.dialog.editorBox.form.data.calcmode,
                calcgran: that.dialog.editorBox.form.data.calcgran,
                ucenabled: that.dialog.editorBox.form.data.ucenabled,
                sumenabled: that.dialog.editorBox.form.data.sumenabled,
                enablesumfmla: that.dialog.editorBox.form.data.enablesumfmla,
                sumgran: that.dialog.editorBox.form.data.sumgran,
                autocpmode: that.dialog.editorBox.form.data.autocpmode,
                // 额外属性
                digits: that.dialog.editorBox.form1.data.digits,
                sumdigits: that.dialog.editorBox.form1.data.sumdigits,
                ucdigits: that.dialog.editorBox.form1.data.ucdigits,
                sumucdigits: that.dialog.editorBox.form1.data.sumucdigits,
                stddigits: that.dialog.editorBox.form1.data.stddigits,
                sumstddigits: that.dialog.editorBox.form1.data.sumstddigits
            };
            let validate = true;
            that.$refs['dialog_form'].validate((valid) => {
                if (valid) {
                    that.$refs['dialog_form1'].validate((valid) => {
                        if (!valid) {
                            that.dialog.editorBox.activeName = '2';
                            validate = false;
                        }
                    });
                } else {
                    that.dialog.editorBox.activeName = '1';
                    validate = false;
                }
            });
            if (validate) {
                if (that.dialog.editorBox.type === 'add') {
                    // let foorData = new FormData();
                    // for (let key in SubmitData) {
                    //     foorData.append(key, SubmitData[key]);
                    // }
                    let url = 'pass/ems/v1/tcmdatasourcetimegrans/';
                    let getTableData = that.getTableData;
                    if (that.dialog.editorBox.boxType === 1) {
                        url = 'pass/ems/v1/tcmdatasourceexceptions/';
                        getTableData = that.getAdditionalTableData;
                    }
                    that.loading = true;
                    that.axios.post(url, SubmitData, {
                        contentType: 'application/json'
                    })
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    message: '新增成功',
                                    type: 'success'
                                });
                                getTableData();
                                that.dialog.editorBox.show = false;
                            } else {
                                that.$message.error(res.message);
                            }
                            that.loading = false;
                        }).catch(function () {
                            that.loading = false;
                        });
                } else {
                    let url = 'pass/ems/v1/tcmdatasourcetimegrans/';
                    let getTableData = that.getTableData;
                    if (that.dialog.editorBox.boxType === 1) {
                        url = 'pass/ems/v1/tcmdatasourceexceptions/';
                        getTableData = that.getAdditionalTableData;
                    }
                    that.loading = true;
                    that.axios.put(url + SubmitData.recordid, SubmitData)
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    message: '修改成功',
                                    type: 'success'
                                });
                                getTableData();
                                that.dialog.editorBox.show = false;
                            } else {
                                that.$message.error(res.message);
                            }
                            that.loading = false;
                        }).catch(function () {
                            that.loading = false;
                        });
                }
            }
        }
    }
}
</script>

<style lang="less">
.dataCalculateLogic {
    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;
            }
        }
    }
    .color_no {
        color: #7a7a7a;
    }
    .color_yes {
        color: #1a9f17;
    }
}
</style>
