<template>
<!-- 能耗数据管理 -->
    <div class="energyDepletion">
        <div class="box">
            <div class="box-top">
                <el-form
                    style="overflow: hidden;"
                    :style="filterForm.show ? null : { height: '0px' }"
                    size="mini"
                    label-width="65px"
                >
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="时间粒度">
                                <el-select
                                    filterable clearable
                                    v-model="filterForm.data.timegranid"
                                    multiple
                                    collapse-tags
                                    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="时间">
                                <zj-timegran-date
                                    v-model="filterForm.data.clock"
                                    style="width: 100%;"
                                    :type="'daterange'"
                                    :timegranId="filterForm.data.timegranid"
                                    :timegranObj="nameObj.timegranid.obj"
                                    :oneFoo="getTableData"
                                    :defaultOffset="-1"
                                ></zj-timegran-date>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="工序">
                                <el-select
                                    filterable clearable
                                    v-model="filterForm.data.workprocid"
                                    multiple
                                    collapse-tags
                                    placeholder="工序"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.workprocid.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.propertyid"
                                    multiple
                                    collapse-tags
                                    placeholder="属性"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.propertyid.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="6">
                            <el-form-item label="能介">
                                <el-select
                                    filterable
                                    clearable
                                    v-model="filterForm.data.energyid"
                                    multiple
                                    collapse-tags
                                    placeholder="能介"
                                    style="width: 100%;"
                                >
                                    <template v-for="item of nameObj.energyid.arr">
                                        <el-option
                                            :key="item.id"
                                            :value="item.id"
                                            :label="item.name"
                                        ></el-option>
                                    </template>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="单位">
                                <el-select
                                    filterable clearable
                                    v-model="filterForm.data.unitid"
                                    multiple
                                    collapse-tags
                                    placeholder="属性"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.unitid.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="业务ID">
                                <el-input clearable
                                    v-model="filterForm.data.itemid"
                                    placeholder="能介业务id"
                                    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.itemname"
                                    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.itemdesc"
                                    placeholder="能介业务描述"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="状态">
                                <el-select
                                    filterable clearable
                                    v-model="filterForm.data.state"
                                    multiple
                                    collapse-tags
                                    placeholder="状态"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.state.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-download"
                        @click="getData()"
                        v-privilege="activeMenu + 'GETDATA'"
                        :loading="getDataButLoading"
                    >获取数据</el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-upload2"
                        @click="upState()"
                        v-privilege="activeMenu + 'PUTDATA'"
                    >上传</el-button>
                    <el-button
                        class="button"
                        size="mini"
                        icon="el-icon-refresh"
                        @click="upState('0')"
                        v-privilege="activeMenu + 'UNDODATA'"
                    >撤销上传</el-button>
                    <el-radio-group
                        v-model="operateType"
                        style="margin-left: 7px;"
                        @change="setOperateType()"
                        v-privilege="activeMenu + 'PUTCONFIG'"
                    >
                        <el-radio label="1" title="系统每天自动进行上传">自动上传</el-radio>
                        <el-radio label="0" title="需要手动进行上传确定操作">人工上传</el-radio>
                    </el-radio-group>
                    <div style="float:right; text-align: right;">
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            @click="showAll"
                        >{{showAllChildTable? "收起" : "展开"}}</el-button>
                        <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
                    @selection-change="handleSelectionChange"
                    show-summary
                    :summary-method="getSummaries"
                    :row-class-name="rowClassName"
                    @expand-change="getChildTable"
                >
                    <el-table-column
                        type="selection"
                        width="40"
                        align="center"
                        :selectable='checkboxT'
                        fixed="left"
                        class-name="cnspicuous"
                    ></el-table-column>
                    <el-table-column
                        type="expand"
                        width="45"
                    >
                        <template slot-scope="scope">
                            <el-table stripe
                                :data="scope.row.tableData"
                                v-loading="scope.row.tableLoading"
                                style="width: 1002px; resize: horizontal;"
                                border
                                size="mini"
                                highlight-current-row
                            >
                                <el-table-column
                                    sortable
                                    prop="itemid"
                                    label="计量点编号"
                                    width="150px"
                                    :show-overflow-tooltip="true"
                                ></el-table-column>
                                <el-table-column
                                    sortable
                                    prop="itemname"
                                    label="计量点名称"
                                    width="200px"
                                    :show-overflow-tooltip="true"
                                ></el-table-column>
                                <el-table-column
                                    sortable
                                    prop="tagAlias"
                                    label="TAG别名"
                                    width="200px"
                                    :show-overflow-tooltip="true"
                                ></el-table-column>
                                <el-table-column
                                    sortable
                                    prop="mintvalue"
                                    label="仪表期初值"
                                    mwidth="150px"
                                    :show-overflow-tooltip="true"
                                ></el-table-column>
                                <el-table-column
                                    sortable
                                    prop="mendvalue"
                                    label="仪表期末值"
                                    width="150px"
                                    :show-overflow-tooltip="true"
                                ></el-table-column>
                                <el-table-column
                                    sortable
                                    prop="apportvalue"
                                    label="最终值"
                                    width="150px"
                                    :show-overflow-tooltip="true"
                                ></el-table-column>
                            </el-table>
                        </template>
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="id"
                        label="主键流水"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="workprocidName"
                        label="工序"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="clock"
                        label="日期"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></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].name : scope.row.timegranid }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="state"
                        label="状态"
                        width="90px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span
                                :style="{color: nameObj.state.obj[scope.row.state] ? nameObj.state.obj[scope.row.state].color : ''}"
                            >{{ nameObj.state.obj[scope.row.state] ? nameObj.state.obj[scope.row.state].name : scope.row.state }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="energyidName"
                        label="能介"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="itemid"
                        label="能介业务ID"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <!-- <el-table-column
                        sortable
                        prop="itemname"
                        label="能介业务名称"
                        min-width="200px"
                        :show-overflow-tooltip="true"
                    ></el-table-column> -->
                    <el-table-column
                        sortable
                        prop="itemdesc"
                        label="能介业务描述"
                        min-width="200px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="propertyidName"
                        label="属性"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="apportvalue"
                        label="最终值"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="unitidName"
                        label="单位"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="formula"
                        label="项目公式计量点编码"
                        min-width="150px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="formuladescription"
                        label="项目公式计量点名称"
                        min-width="150px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="memo"
                        label="备注"
                        min-width="150px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <el-input clearable
                                v-if="scope.row.isSelection && scope.row.state === '0'"
                                v-model="scope.row.memo"
                                size="mini"
                            ></el-input>
                            <span v-else>{{scope.row.memo}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="operatorMan"
                        label="上传操作人"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="operatorDate"
                        label="上传操作时间"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="recman"
                        label="接收人"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="rectime"
                        label="接收时间"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></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>
    </div>
</template>

<script>
import timegranDate from '@/components/zg/timegranDate.vue'
import {formatDate, commonSummaries} from '@/utils/util.js';
export default {
    name: 'energyDepletion',
    components: {
        'zj-timegran-date': timegranDate
    },
    data () {
        return {
            showAllChildTable: false,
            activeMenu: '',
            operateType: '0',
            filterForm: {
                show: true,
                data: {
                    timegranid: ['DAY'],
                    clock: '',
                    workprocid: '',
                    propertyid: '',
                    energyid: '',
                    itemid: '',
                    itemname: '',
                    itemdesc: '',
                    unitid: '',
                    state: ''
                },
                rules: {

                }
            },
            pageNum: 1,
            pageSize: 20,
            total: 0,
            singleTableHeight: 100,
            tableData: [
                // {
                //     id: 'C035',
                //     state: '0',
                //     apportvalue: 2234
                // },
                // {
                //     id: 'C035',
                //     state: '1',
                //     apportvalue: 6754
                // },
                // {
                //     id: 'C035',
                //     state: '2',
                //     apportvalue: 245.1231
                // }
            ],
            multipleSelection: [],
            loading: false,
            getDataButLoading: false,
            tableLoading: false,
            nameObj: {
                timegranid: {
                    obj: {
                        'DAY': {
                            name: '日',
                            format: 'yyyy-MM-dd'
                        },
                        'MONTH': {
                            name: '月',
                            format: 'yyyy-MM'
                        },
                        'YEAR': {
                            name: '年',
                            format: 'yyyy'
                        }
                    },
                    arr: [
                        {
                            id: 'DAY',
                            name: '日'
                        },
                        {
                            id: 'MONTH',
                            name: '月'
                        },
                        {
                            id: 'YEAR',
                            name: '年'
                        }
                    ]
                },
                state: {
                    obj: {
                        '0': {
                            name: '已生成',
                            color: '#7a7a7a'
                        },
                        '1': {
                            name: '已上传',
                            color: 'rgb(28, 111, 217)'
                        },
                        '2': {
                            name: '已接收',
                            color: 'red'
                        }
                    },
                    arr: [
                        {
                            id: '0',
                            name: '已生成'
                        },
                        {
                            id: '1',
                            name: '已上传'
                        },
                        {
                            id: '2',
                            name: '已接收'
                        }
                    ]
                },
                workprocid: {
                    obj: {},
                    arr: []
                },
                propertyid: {
                    obj: {},
                    arr: []
                },
                energyid: {
                    obj: {},
                    arr: []
                },
                unitid: {
                    obj: {},
                    arr: []
                }
            }
        }
    },
    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.getNodeData();
        that.getPropertyIdData();
        that.getUnitIdData();
        that.getEnergyIdData();
        that.getOperateType();
    },
    methods: {
        //  计算树区域高度
        getRoleHeight (dom) {
            return window.innerHeight - dom.offsetTop;
        },
        // 自定义的表格合计方法：只给指定列进行合计
        getSummaries (param) {
            const prop = ['apportvalue']; // 合计列绑定的prop
            return commonSummaries(param, prop);
        },
        // 获取工序列表
        getNodeData () {
            let that = this
            let url = 'pass/ems/v1/trmworkprocs/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.workprocid.arr = arr;
                        that.nameObj.workprocid.obj = obj;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        // 获取属性
        getPropertyIdData () {
            let that = this
            let url = 'pass/ems/v1/trmenergypropertys/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.propertyid.arr = arr;
                        that.nameObj.propertyid.obj = obj;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        // 获取能介
        getEnergyIdData () {
            let that = this;
            let url = 'pass/ems/v1/trmenergys/selectNameAndId/';
            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,
                                energytypeid: item.energytypeid,
                                unitid: item.unitid
                            })
                            obj[item.id] = {
                                name: item.name,
                                unitid: item.unitid
                            }
                        }
                        that.nameObj.energyid.arr = arr;
                        that.nameObj.energyid.obj = obj;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        // 获取标准计量单位
        getUnitIdData () {
            let that = this
            let url = 'pass/ems/v1/trmunits/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.unitid.arr = arr;
                        that.nameObj.unitid.obj = obj;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        // 获取表格中的数据
        getTableData (pageNum) {
            let that = this,
                params = {
                    timegranid: that.filterForm.data.timegranid.toString(),
                    clock: that.filterForm.data.clock[0],
                    clocke: that.filterForm.data.clock[1],
                    workprocid: that.filterForm.data.workprocid.toString(),
                    propertyid: that.filterForm.data.propertyid.toString(),
                    energyid: that.filterForm.data.energyid.toString(),
                    itemid: that.filterForm.data.itemid,
                    itemname: that.filterForm.data.itemname,
                    itemdesc: that.filterForm.data.itemdesc,
                    unitid: that.filterForm.data.unitid.toString(),
                    state: that.filterForm.data.state.toString()
                };
            that.pageNum = pageNum || that.pageNum;
            that.tableLoading = true;
            let url = 'pass/ems/v1/ifemsmesactitems/?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.id,
                                state: item.state,
                                workprocid: item.workprocid,
                                workprocidName: item.workprocidName,
                                timegranid: item.timegranid,
                                clock: item.clock,
                                energyid: item.energyid,
                                energyidName: item.energyidName,
                                propertyid: item.propertyid,
                                propertyidName: item.propertyidName,
                                unitid: item.unitid,
                                unitidName: item.unitidName,
                                itemid: item.itemid,
                                itemname: item.itemname,
                                itemdesc: item.itemdesc,
                                apportvalue: item.apportvalue,
                                operatorMan: item.operatorMan,
                                operatorDate: item.operatorDate,
                                recman: item.recman,
                                rectime: item.rectime,
                                memo: item.memo,
                                formula: item.formula,
                                formuladescription: item.formuladescription,
                                tableData: [],
                                tableLoading: false,
                                getTable: false
                            })
                        }
                        that.tableData = arr;
                        that.total = res.data.total;
                    } else {
                        that.$message.error(res.message);
                    }
                    that.tableLoading = false;
                    that.$nextTick(() => {
                        setTimeout(() => {
                            that.singleTableHeight = that.getRoleHeight(that.$refs['singleTable'].$el) - 46;
                        }, 1);
                    });
                }).catch(function () {
                    that.tableLoading = false;
                });
        },
        // 改变表格显示条数
        tableSizeChange (val) {
            let that = this;
            that.pageSize = val;
            that.getTableData(1);
        },
        // 重置搜索
        tableDataCancel () {
            let that = this;
            for (let key in that.filterForm.data) {
                if (that.filterForm.data[key] instanceof Array) {
                    that.filterForm.data[key] = [];
                } else {
                    that.filterForm.data[key] = '';
                }
            }
            that.getTableData(1);
        },
        // 只允许对未接受的数据进行操作
        checkboxT (row, index) {
            if (row.state === '2') {
                return false;
            } else {
                return true;
            }
        },
        handleSelectionChange (val) {
            let that = this;
            for (let item of that.tableData) {
                item.isSelection = false;
            }
            for (let item of val) {
                item.isSelection = true;
            }
            that.multipleSelection = val;
        },
        upState (state = '1') {
            let that = this;
            let dataArr = [];
            for (let item of that.multipleSelection) {
                if (item.state !== state) {
                    dataArr.push(item);
                }
            }
            if (dataArr.length > 0) {
                that.$confirm('本次将要' + (state === '1' ? '上传' : '撤销上传') + dataArr.length + '条数据，是否确定?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    state: 'warning'
                }).then(() => {
                    let SubmitData = [];
                    for (let item of dataArr) {
                        SubmitData.push({
                            id: item.id,
                            state: state,
                            memo: item.memo
                        });
                    }
                    that.loading = true;
                    that.axios.put('pass/ems/v1/ifemsmesactitems/', SubmitData)
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    message: (state === '1' ? '上传' : '撤销') + '成功',
                                    type: 'success'
                                });
                                that.getTableData();
                            } else {
                                that.$message.error(res.message);
                            }
                            that.loading = false;
                        }).catch(function () {
                            that.loading = false;
                        });
                }).catch(() => {
                });
            } else {
                if (that.multipleSelection.length > 0) {
                    this.$message.error('没有需要' + (state === '1' ? '上传' : '撤销') + '的数据');
                } else {
                    this.$message.error('至少要选择一条数据');
                }
            }
        },
        getData () {
            let that = this;
            let url = 'pass/ems/v1/ifemsmesactitems/getdatafromems/';
            that.getDataButLoading = true;
            that.axios.get(url)
                .then(function (res) {
                    if (res.code === '0') {
                        that.$message({
                            message: res.data,
                            type: 'success'
                        });
                        that.getDataButLoading = false;
                        that.getTableData(1);
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        rowClassName ({row, rowIndex}) {
            return row.propertyid === '2' || row.propertyid === '3' ? 'rowDisable' : ''
        },
        getChildTable (row, expandedRows) {
            let that = this;
            if (!row.getTable) {
                let itemids = [],
                    regex = /\[.+?\]/g,
                    str = row.formula,
                    m;
                while ((m = regex.exec(str)) !== null) {
                    // This is necessary to avoid infinite loops with zero-width matches
                    if (m.index === regex.lastIndex) {
                        regex.lastIndex++;
                    }
                    // The result can be accessed through the `m`-variable.
                    m.forEach((match, groupIndex) => {
                        itemids.push(match.replace('[', '').replace(']', ''));
                    });
                }
                if (itemids.length > 0) {
                    let params = {
                            clock: row.clock,
                            timegranid: row.timegranid,
                            itemid: itemids.toString()
                        };
                    row.tableLoading = true;
                    let url = 'pass/ems/v1/trmcalpoints/getInIdDate312';
                    that.axios.get(url, {
                        params: params
                    })
                        .then(function (res) {
                            if (res.code === '0') {
                                let arr = [];
                                for (let item of res.data) {
                                    arr.push({
                                        itemid: item.ITEMID,
                                        clock: item.CLOCK,
                                        itemname: item.ITEMNAME,
                                        tagAlias: item.TAG_ALIAS,
                                        tagModulus: item.TAG_MODULUS,
                                        unitid: item.UNITID,
                                        mintvalue: item.MINTVALUE,
                                        mendvalue: item.MENDVALUE,
                                        actualvalue: item.ACTUALVALUE,
                                        correctvalue: item.CORRECTVALUE,
                                        apportvalue: item.APPORTVALUE,
                                        sumvalue: item.SUMVALUE,
                                        bz: item.BZ,
                                        updateReason: item.UPDATE_REASON,
                                        rectime: item.REC_TIME,
                                        updateUser: item.UPDATE_USER,
                                        itemtype: item.ITEMTYPE,
                                        timegranid: item.TIMEGRANID
                                    })
                                }
                                row.tableData = arr;
                                row.getTable = true;
                            } else {
                                that.$message.error(res.message);
                            }
                            row.tableLoading = false;
                        }).catch(function () {
                            row.tableLoading = false;
                        });
                }
            }
        },
        showAll () {
            let that = this;
            that.showAllChildTable = !that.showAllChildTable;
            for (let i = 0; i < that.tableData.length; i++) {
                that.$refs.singleTable.toggleRowExpansion(that.tableData[i], that.showAllChildTable);
            }
        },
        getOperateType () {
            let that = this;
            let url = 'pass/ems/v1/ifemsmesactitems/uploadstate/';
            that.axios.get(url)
                .then(function (res) {
                    if (res.code === '0') {
                        that.operateType = res.data;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        setOperateType () {
            let that = this;
            that.axios.post('pass/ems/v1/ifemsmesactitems/uploadstate/?uploadstate=' + that.operateType)
                .then(function (res) {
                    if (res.code === '0') {
                    } else {
                        that.getOperateType();
                        that.$message.error(res.message);
                    }
                }).catch(function () {
                    that.getOperateType();
                });
        }
    }
}
</script>

<style lang="less">
.energyDepletion {
    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;
                padding: 7px 0;
                border-top: 1px solid #ccc;
            }
        }
        .rowDisable td {
            color: #6bb025 !important;
        }
        .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;
    }
    .cnspicuous .el-checkbox__input.is-disabled .el-checkbox__inner {
        background-color: #dcdfe6;
        border-color: #babbbf;
    }
}
</style>
