<template>
<!-- 应急物资信息维护 -->
    <div class="emermaterials">
        <div class="box">
            <div class="box-top">
                <el-form
                    style="overflow: hidden;"
                    size="mini"
                    label-width="80px"
                >
                    <el-row>
                        <el-col :span="5">
                            <el-form-item label="工序名称">
                                <el-select
                                    filterable 
                                    clearable
                                    v-model="filterForm.data.gx_name"
                                    :disabled="filterForm.disabled.gx_name"
                                    multiple
                                    collapse-tags
                                    placeholder="工序名称"
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.gx_name.arr"
                                        :key="item"
                                        :value="item"
                                        :label="item"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="物资大类">
                                <el-input clearable
                                    v-model.trim="filterForm.data.wzdl_name"
                                    placeholder="物资大类"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="物资类别">
                                <el-input clearable
                                    v-model.trim="filterForm.data.wzlb_name"
                                    placeholder="物资类别"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="物资名称">
                                <el-input clearable
                                    v-model.trim="filterForm.data.sbmc_name"
                                    placeholder="物资名称"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item label="型号">
                                <el-input clearable
                                    v-model.trim="filterForm.data.xh"
                                    placeholder="型号"
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="box-top-gjl">
                    <el-button
                            class="button"
                            type="primary"
                            icon="el-icon-search"
                            size="mini"
                            v-if="butPrivilege.QUERY"
                            @click="filterForm.useflag = '1';getTableData(1)"
                    >查询</el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-plus"
                        v-if="butPrivilege.ADD"
                        @click="but_add"
                    >新增
                    </el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-edit-outline"
                        v-if="butPrivilege.PUT"
                        @click="but_edit_plural()"
                    >修改</el-button>
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-delete"
                        v-if="butPrivilege.DELETE"
                        @click="but_del_plural"
                    >删除</el-button>
                </div>
            </div>
            <div class="box-bottom">
                <el-form
                    size="mini"
                    ref="dialog_form_arr"
                    label-width="0px"
                    :model="tableFormDataObj"
                >
                <el-table
                    id="singleTable"
                    ref="singleTable"
                    :data="tableData"
                    v-loading="tableLoading"
                    style="width: 100%;"
                    :height="singleTableHeight"
                    border
                    size="mini"
                    highlight-current-row
                    @selection-change="handleSelectionChange"
                    @current-change="handleCurrentChange"
                    :row-class-name="tableRowClassName"
                >
                    <el-table-column
                        type="selection"
                        width="40"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="tno"
                        label="序号"
                        width="50px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                            sortable
                            prop="gx_name"
                            label="工序名称"
                            width="100px"
                            :show-overflow-tooltip="true">
                         <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.gx_name'"
                                    :rules="dialog.editorBox.form.rules.gx_name"
                                >
                                     <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].gx_name"
                                    >
                                    <el-option
                                        v-for="item of nameObj.gx_name.arr"
                                        :key="item"
                                        :value="item"
                                        :label="item"
                                    ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{ nameObj.gx_name.obj[scope.row.gx_name] ? nameObj.gx_name.obj[scope.row.gx_name] : scope.row.gx_name }}</span>
                            </template>
                    </el-table-column>
                    <el-table-column
                    sortable
                        prop="wzdl_name"
                        label="物资大类"
                        width="120px"
                        :show-overflow-tooltip="true"
                    > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.wzdl_name'"
                                    :rules="dialog.editorBox.form.rules.wzdl_name"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].wzdl_name"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.wzdl_name}}</span>
                            </template>
                        </el-table-column>
                    <el-table-column
                        sortable
                        prop="wzlb_name"
                        label="物资类别"
                        min-width="120px"
                        :show-overflow-tooltip="true"
                    ><template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.wzlb_name'"
                                    :rules="dialog.editorBox.form.rules.wzlb_name"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].wzlb_name"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.wzlb_name}}</span>
                            </template>     
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="sbmc_name"
                        label="物资名称"
                        width="120px"
                        :show-overflow-tooltip="true"
                    > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.sbmc_name'"
                                    :rules="dialog.editorBox.form.rules.sbmc_name"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].sbmc_name"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.sbmc_name}}</span>
                            </template>
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="xh"
                        label="型号"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ><template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.xh'" 
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].xh"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.xh}}</span>
                            </template>   
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="dw"
                        label="单位"
                        min-width="80px"
                        :show-overflow-tooltip="true">  
                    <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.dw'"
                                    :rules="dialog.editorBox.form.rules.dw"
                                >
                                     <el-select
                                        filterable
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].dw"
                                    >
                                    <el-option
                                        v-for="item of nameObj.dw.arr"
                                        :key="item"
                                        :value="item"
                                        :label="item"
                                    ></el-option>
                                    </el-select>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{ nameObj.dw.obj[scope.row.dw] ? nameObj.dw.obj[scope.row.dw] : scope.row.dw }}</span>
                            </template>
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="yjwz_dd"
                        label="存放地点"
                        min-width="150px"
                        :show-overflow-tooltip="true"
                    > 
                    <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.yjwz_dd'"
                                    :rules="dialog.editorBox.form.rules.yjwz_dd"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].yjwz_dd"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.yjwz_dd}}</span>
                            </template>     
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="yjwz_ry"
                        label="负责人"
                        width="100px"
                        :show-overflow-tooltip="true"
                    > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.yjwz_ry'"
                                    :rules="dialog.editorBox.form.rules.yjwz_ry"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].yjwz_ry"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.yjwz_ry}}</span>
                            </template> 
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="lxdh"
                        label="联系电话"
                        width="90px"
                        :show-overflow-tooltip="true"
                    > <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.lxdh'"
                                    :rules="dialog.editorBox.form.rules.lxdh"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].lxdh"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.lxdh}}</span>
                            </template>  
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="hsyjz1"
                        label="黄色预警"
                        width="80px"
                        :show-overflow-tooltip="true"
                    >
                    <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.hsyjz1'"
                                    :rules="dialog.editorBox.form.rules.hsyjz1"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].hsyjz1"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.hsyjz1}}</span>
                            </template>       
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="hsyjz2"
                        label="红色预警"
                        min-width="80px"
                        :show-overflow-tooltip="true"
                    >
                    <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.hsyjz2'"
                                    :rules="dialog.editorBox.form.rules.hsyjz3"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].hsyjz2"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.hsyjz2}}</span>
                            </template>       
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="kcl"
                        label="库存量"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ><template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.kcl'"
                                    :rules="dialog.editorBox.form.rules.kcl"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].kcl"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.kcl}}</span>
                            </template>           
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="memo"
                        label="备注"
                        width="150px"
                        :show-overflow-tooltip="true"
                    >
                    <template slot-scope="scope">
                                <el-form-item
                                    v-if="scope.row.isSelection"
                                    :prop="scope.row.tno + '.memo'"
                                    :rules="dialog.editorBox.form.rules.memo"
                                >
                                    <el-input
                                        clearable
                                        style="width: 100%;"
                                        v-model="tableFormDataObj[scope.row.tno].memo"
                                    ></el-input>
                                    <template
                                        slot="error"
                                        slot-scope="scope"
                                    >
                                        <p
                                            class="error"
                                            :title="scope.error"
                                        >{{ scope.error }}</p>
                                    </template>
                                </el-form-item>
                                <span v-else>{{scope.row.memo}}</span>
                            </template>     
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="cjr"
                        label="创建人"
                        min-width="80px"
                        :show-overflow-tooltip="true"
                    >
                    </el-table-column>
                    <el-table-column
                        sortable
                        prop="cjsj"
                        label="创建时间"
                        min-width="120px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                </el-table>
                </el-form>
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    :page-sizes="[10, 20, 50, 100, 500, 1000]"
                    :page-size="pageSize"
                    :current-page.sync="pageNum"
                    @size-change="tableSizeChange"
                    @current-change="getTableData()"
                    style="text-align: right;margin-top: 10px;"
                ></el-pagination>
            </div>
        </div>
        <el-dialog
            :title="'应急物资 - ' + (dialog.editorBox.type === 'ADD' ? '新增' : '修改')"
            :visible.sync="dialog.editorBox.show"
            width="600px"
            :close-on-click-modal="false"
            :show-close="!loading"
             >
            <div>
                <el-form
                    ref="dialog_form"
                    :model="dialog.editorBox.form.data"
                    :rules="dialog.editorBox.form.rules"
                    size="mini"
                    label-width="85px"
                >
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="工序名称"
                                prop="gx_name"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.gx_name"
                                    :disabled="dialog.editorBox.form.disabled.gx_name"
                                >
                                    <el-option
                                        v-for="item of nameObj.gx_name.arr"
                                        :key="item"
                                        :value="item"
                                        :label="item"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="物资大类"
                                prop="wzdl_name"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.wzdl_name"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="物资类别"
                                prop="wzlb_name"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;margin-bottom:0px;line-height:15px"
                                    v-model="dialog.editorBox.form.data.wzlb_name"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="物资名称"
                                prop="sbmc_name"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.sbmc_name"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="型号"
                                prop="xh"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.xh"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="单位"
                                prop="dw"
                            >
                                <el-select
                                    filterable
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.dw"
                                >
                                    <el-option
                                        v-for="item of nameObj.dw.arr"
                                        :key="item"
                                        :value="item"
                                        :label="item"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="存放地点"
                                prop="yjwz_dd"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.yjwz_dd"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="负责人"
                                prop="yjwz_ry"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.yjwz_ry"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="联系电话"
                                prop="lxdh"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.lxdh"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="黄色预警"
                                prop="hsyjz1"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.hsyjz1"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="红色预警"
                                prop="hsyjz2"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.hsyjz2"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item
                                label="库存量"
                                prop="kcl"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.kcl"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item
                                label="备注"
                                prop="memo"
                            >
                                <el-input
                                    clearable
                                    style="width: 100%;"
                                    v-model="dialog.editorBox.form.data.memo"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialog.editorBox.show = false"
                    :loading="loading"
                >取 消</el-button>
                <el-button
                    type="primary"
                    @click="dataSave"
                    :loading="loading"
                >保 存</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { checkTel , checkNumber , zCheckNumber2 } from '~/utils/validator.js'
import { formatDate } from '@/utils/util.js'
import  store from '@/store/index.js' 
export default {
    name: 'emermaterials',
    data () {
        let checkhsyjz2 = (rule,value,callback)=>{
            let hsyjz1 = this.dialog.editorBox.form.data.hsyjz1-0
            let value1 = value - 0
            if(value1 > hsyjz1)
            {
                return callback(new Error('红色预警值不能大于黄色预警值'))
            }else{
                return callback();
           }
        };
        return {
            activeMenu: '',
            store,
            isActivestripe : true,
            filterForm: {
                useflag : '1',
                data: {
                    tno: '',
                    gx_name: '',
                    wzdl_name: '',
                    wzlb_name: '',
                    sbmc_name: '',
                    xh: '',
                    dw: '',
                    yjwz_dd: '',
                    yjwz_ry: '',
                    lxdh: '',
                    hsyjz1: '',
                    hsyjz2: '',
                    kcl: '',
                    memo: '',
                    cjr: '',
                    cjsj: ''
                },
                disabled: {
                    gx_name: false
                },
                rules: {

                }
            },
            pageNum: 1,
            pageSize: 100,
            total: 0,
            singleTableHeight: 100,
            tableData: [],
            multipleSelection: [],
            tableFormDataObj: {},
            nameObj: {
                gx_name: {
                    obj: {},
                    arr: []
                },
                dw: {
                    obj: {},
                    arr: []
                },
                energyid: {
                    obj: {},
                    arr: []
                },
                propertyid: {
                    obj: {},
                    arr: []
                },
                locateid: {
                    obj: {},
                    arr: []
                },
                networkid: {
                    obj: {},
                    arr: []
                },
                unitid: {
                    obj: {},
                    arr: []
                },
                hierarchy: {
                    obj: {},
                    arr: []
                }
            },
            loading: false,
            tableLoading: false,
            dialog: {
                editorBox: {
                    show: false,
                    activeName: '1',
                    type: '',
                    addRow: null,
                    form: {
                        data: {
                            tid: '',
                            gx_name: '',
                            wzdl_name: '',
                            wzlb_name: '',
                            sbmc_name: '',
                            xh: '',
                            dw: '',
                            yjwz_dd: '',
                            yjwz_ry: '',
                            lxdh: '',
                            hsyjz1: '',
                            hsyjz2: '',
                            kcl: '',
                            memo: ''
                        },
                        rules: {
                            gx_name: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            dw: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            yjwz_dd: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            yjwz_ry: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            lxdh: [
                                { validator: checkTel, trigger: 'blur' }
                            ],
                            wzdl_name: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            wzlb_name: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            sbmc_name: [
                                { required: false, message: '该项不能为空', trigger: 'change' }
                            ],
                            xh: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            hsyjz1: [
                                { validator: checkNumber, trigger: 'change' }
                            ],
                            hsyjz2: [
                                {validator: checkNumber, trigger: 'change'},
                                {validator: checkhsyjz2, trigger: 'change' } 
                            ],
                            hsyjz3: [
                                {validator: checkNumber, trigger: 'change'}
                            ],
                            kcl: [
                                { validator: checkNumber, trigger: 'change' }
                            ]
                        },
                        disabled:{
                            gx_name: false
                        }
                    },
                    form1: {
                        data: {
                            // 基础
                            defaultvalue: '',
                            digits: '',
                            node: '',
                            showno: '',
                            parentid: '',
                            recTime: '',
                            status: '',
                            useflag: '',
                            // 扩展
                            tagid: '',
                            tagname: '',
                            rangeVal: '',
                            tagBadSymbol: '',
                            tagModulus: '',
                            tagIdMap: '',
                            calcMod: '',
                            dataType: '',
                            meterType: '',
                            meterScale: '',
                            meterLoc: '',
                            // 特殊
                            tagTable: '',
                            tagCol: '',
                            maxVal: '',
                            minVal: '',
                            avgVal: '',
                            sumVal: '',
                            bcode: '',
                            bdesc1: '',
                            bdesc2: '',
                            btype1: '',
                            btype2: ''
                        },
                        rules: {
                            showno: [
                                { validator: zCheckNumber2, trigger: 'change' }
                            ]
                        }
                    }
                },
                equationEditing: {
                    show: false,
                    form: {
                        data: {
                            clock: '',
                            code: ''
                        }
                    }
                }
            },
            butPrivilege: {
                QUERY: false,
                ADD: false,
                PUT: false,
                DELETE: false
            }
        }
    },
    created () {
        // 获取按钮权限
        this.activeMenu = window.localStorage.getItem('activeMenu');
        for (let key in this.butPrivilege) {
            this.butPrivilege[key] = this.checkPrivilege(this.activeMenu + key);
        }
    },
    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);
        });

        if (that.$route.query.gx_name) {
            that.filterForm.disabled.gx_name = true;
            that.dialog.editorBox.form.disabled.gx_name = true;
            that.filterForm.data.gx_name = that.$route.query.gx_name.split(',') 
        }
       // that.getEnergyTypeIdData();
        //that.getEnergyIdData();
        //that.getPropertyIdData();
       // that.getLocateIdData();
        //that.getNetworkIdData();
        // that.getSourceTypeData();
        that.getDwData();
        that.getGxNameData();
       // that.getUnitIdData();
        //that.getHierarchyData();
        that.getTableData();
    },
    methods: {
        tableRowClassName({row,rowIndex}){   
            if(row.kcl !='' && row.kcl != null){
                let hsyjz1 = row.hsyjz1 - 0;
                let hsyjz2 = row.hsyjz2 - 0;
                let kcl = row.kcl - 0;
                if(kcl < hsyjz2){
                    return 'red-row';
                }else if(kcl<hsyjz1) {
                    return 'yellow-row';
                }
            }
            if(rowIndex % 2 ==1){
                return 'blue-row';
            }
            
        },
        but_del_plural () {
            let that = this;
            if (that.multipleSelection.length > 0) {
                let ids = [];
                for (let item of that.multipleSelection) {
                    ids.push(item.tno);
                }
                that.$confirm('是否删除已选数据?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    state: 'warning'
                }).then(() => {
                    that.axios.delete('pass/ems/v1/temergencymaterials/' + ids)
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    message: '删除成功',
                                    type: 'success'
                                });
                                that.getTableData();
                            } else {
                                if (res.code === '51') {

                                }
                                that.$message.error(res.message);
                            }
                        }).catch(function () {
                        });
                }).catch(() => {
                });
            } else {
                this.$message.error('至少要选择一条数据');
            }
        },
        
        handleSelectionChange (val) {
            let that = this;
            let tableFormDataObj = {};
            for (let item of that.tableData) {
                item.isSelection = false;
            }
            for (let item of val) {
                let obj = {};
                let xId = item.tno;
                if (that.tableFormDataObj[xId]) {
                    tableFormDataObj[xId] = that.tableFormDataObj[xId];
                } else {
                    for (let key in item) {
                        obj[key] = item[key];
                    }
                    tableFormDataObj[xId] = obj;
                }
                item.isSelection = true;
            }
            that.tableFormDataObj = tableFormDataObj;
            that.multipleSelection = val;
        },
        //  计算树区域高度
        getRoleHeight (dom) {
            return window.innerHeight - dom.offsetTop;
        },
        // 获取工序名称
        getGxNameData () {
            let that = this
            let url = 'pass/ems/v1/temergencymaterials/getGxName';
            that.axios.get(url)
                .then(function (res) {
                    if (res.code === '0') {
                        that.nameObj.gx_name.arr = res.data;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        // 获取单位
        getDwData () {
            let that = this
            let url = 'pass/ems/v1/temergencymaterials/getDw/';
            that.axios.get(url)
                .then(function (res) {
                    if (res.code === '0') {
                        that.nameObj.dw.arr = res.data;
                    } else {
                        that.$message.error(res.message);
                    }
                });
        },
        connn () {
            // this.filterForm.data.energytypeid = this.filterForm.data.energytypeid.join(',')
            // console.log(this.filterForm.data.energytypeid)
            // console.log(111)
            // let that = this;
            // let set = new Set();
            // console.log(that.filterForm.data.energytypeid)
            // if (!that.filterForm.data.energytypeid || that.filterForm.data.energytypeid.length === 0) {
            //     that.nameObj.energytypeid.showDataArr = that.nameObj.energytypeid.arr;
            // } else {
            //     for (let key of that.filterForm.data.energytypeid) {
            //         if (that.nameObj.energytypeid.obj[key]) {
            //             for (let name of that.nameObj.energytypeid.obj[key]) {
            //                 set.add(name);
            //             }
            //         }
            //     }
            //     that.nameObj.energytypeid.showDataArr = [...set];
            //     // console.log(that.nameObj.energytypeid.showDataArr)
            // }
        },
        // 获取表格中的数据
        getTableData (pageNum) {
            let that = this,
                params = {
                    gx_name: that.filterForm.data.gx_name.join(','),
                    wzdl_name: that.filterForm.data.wzdl_name,
                    wzlb_name: that.filterForm.data.wzlb_name,
                    sbmc_name: that.filterForm.data.sbmc_name,
                    xh: that.filterForm.data.xh
                };
            that.pageNum = pageNum || that.pageNum;
            that.tableLoading = true;
            let url = 'pass/ems/v1/temergencymaterials/like/?pageNum=' + that.pageNum + '&pageSize=' + that.pageSize
            that.axios.get(url, {
                params: params
            })
            /*let url = 'pass/ems/v1/temergencymaterials/getAll/';
            that.axios.get(url)*/
                .then(function (res) {
                    if (res.code === '0') {
                        let arr = [];
                        for (let item of res.data.list) {
                            arr.push({
                                tno: item.tno,
                                gx_code: item.gx_code,
                                gx_name: item.gx_name,
                                yjwz_dd: item.yjwz_dd,
                                yjwz_ry: item.yjwz_ry,
                                lxdh: item.lxdh,
                                wzdl_name: item.wzdl_name,
                                wzlb_name: item.wzlb_name,
                                sbmc_name: item.sbmc_name,
                                xh: item.xh,
                                dw: item.dw,
                                hsyjz1: item.hsyjz1,
                                hsyjz2: item.hsyjz2,
                                cjr: item.cjr,
                                memo: item.memo,
                                cjsj: item.cjsj,
                                kcl: item.kcl
                            })
                        }
                        that.tableData = arr;
                        that.total = res.data.list.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;
            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);
        },
        // 选择添加时的模板
        handleCurrentChange (row) {
            let that = this;
            that.dialog.editorBox.addRow = row;
        },
        // 自动生成名称
        autoSetName () {
            let that = this;
            if (that.dialog.editorBox.form.data.itemname === '') {
                if (that.dialog.editorBox.form.data.locateid && that.dialog.editorBox.form.data.energyid && that.dialog.editorBox.form.data.propertyid) {
                    that.dialog.editorBox.form.data.itemname += that.nameObj.locateid.obj[that.dialog.editorBox.form.data.locateid];
                    that.dialog.editorBox.form.data.itemname += that.nameObj.energyid.obj[that.dialog.editorBox.form.data.energyid].name;
                    that.dialog.editorBox.form.data.itemname += that.nameObj.propertyid.obj[that.dialog.editorBox.form.data.propertyid];
                }
            }
        },
        but_add () {
            let that = this; 
            that.dialog.editorBox.type = 'ADD';
            that.dialog.editorBox.show = true;
            for (let key in that.dialog.editorBox.form.data) {
                that.dialog.editorBox.form.data[key] = '';
            }
            if (that.$route.query.gx_name) {
                that.dialog.editorBox.form.data.gx_name = that.$route.query.gx_name.split(',')[0]
            }
            setTimeout(() => {
                that.$refs['dialog_form'].clearValidate();
            }, 100);
        },
        dataSave () {
            let that = this;
            let SubmitData = {
                gx_name: that.dialog.editorBox.form.data.gx_name,
                wzdl_name: that.dialog.editorBox.form.data.wzdl_name,
                wzlb_name: that.dialog.editorBox.form.data.wzlb_name,
                sbmc_name: that.dialog.editorBox.form.data.sbmc_name,
                xh: that.dialog.editorBox.form.data.xh,
                dw: that.dialog.editorBox.form.data.dw,
                yjwz_dd: that.dialog.editorBox.form.data.yjwz_dd,
                yjwz_ry: that.dialog.editorBox.form.data.yjwz_ry,
                lxdh: that.dialog.editorBox.form.data.lxdh,
                hsyjz1: that.dialog.editorBox.form.data.hsyjz1,
                hsyjz2: that.dialog.editorBox.form.data.hsyjz2,
                kcl: that.dialog.editorBox.form.data.kcl,
                memo: that.dialog.editorBox.form.data.memo
            }; 
            that.$refs['dialog_form'].validate((valid) => {
                if (valid) {
                    if (that.dialog.editorBox.type === 'ADD') {
                        let foorData = new FormData();
                        for (let key in SubmitData) {
                            foorData.append(key, SubmitData[key]);
                        }
                        that.loading = true;
                        console.log(foorData)
                        that.axios.post('pass/ems/v1/temergencymaterials/', foorData, {
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        })
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '新增成功',
                                        type: 'success'
                                    });
                                    
                                    that.getTableData();
                                    that.dialog.editorBox.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    } else {
                        that.loading = true;
                        that.axios.put('pass/ems/v1/temergencymaterials/' + SubmitData.id, SubmitData)
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '修改成功',
                                        type: 'success'
                                    });
                                    that.getTableData();
                                    that.dialog.editorBox.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    }
                }
            });
        },
        but_edit_plural () {
            let that = this;
            if (that.multipleSelection.length > 0) {
                console.log(that.multipleSelection)
                that.$refs['dialog_form_arr'].validate((valid) => {
                    if (valid) {
                        let SubmitData = [];
                        for (let key in that.tableFormDataObj) {
                            SubmitData.push({
                                tno : that.tableFormDataObj[key].tno,
                                gx_name: that.tableFormDataObj[key].gx_name,
                                wzdl_name: that.tableFormDataObj[key].wzdl_name,
                                wzlb_name: that.tableFormDataObj[key].wzlb_name,
                                sbmc_name: that.tableFormDataObj[key].sbmc_name,
                                xh: that.tableFormDataObj[key].xh,
                                dw: that.tableFormDataObj[key].dw,
                                yjwz_dd: that.tableFormDataObj[key].yjwz_dd,
                                yjwz_ry: that.tableFormDataObj[key].yjwz_ry,
                                lxdh: that.tableFormDataObj[key].lxdh,
                                hsyjz1: that.tableFormDataObj[key].hsyjz1,
                                hsyjz2: that.tableFormDataObj[key].hsyjz2,
                                kcl: that.tableFormDataObj[key].kcl,
                                memo: that.tableFormDataObj[key].memo
                            });
                        }
                        console.log(SubmitData)
                        that.loading = true;
                        that.$confirm('是否修改已选数据?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            state: 'warning'
                        }).then(() => {
                        that.axios.put('pass/ems/v1/temergencymaterials/', SubmitData)
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '修改成功',
                                        type: 'success'
                                    });
                                    that.getTableData();
                                    that.dialog.editorBox.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                        })
                    }
                });
            } else {
                this.$message.error('至少要选择一条数据');
            }
        },
        but_equationEditing (row) {
            let that = this;
            that.dialog.equationEditing.form.data.clock = that.filterForm.data.version;
            that.dialog.equationEditing.form.data.code = row.itemid;
            that.dialog.equationEditing.show = true;
        },
        rowClassName ({row, rowIndex}) {
            return row.useflag !== '1' ? 'rowDisable' : ''
        },
        upUseflag (row, useflag = 0) {
            let that = this;
            let SubmitData = {
                itemname: row.itemname,
                tagAlias: row.tagAlias,
                itemdesc: row.itemdesc,
                itemtype: row.itemtype,
                locateid: row.locateid,
                networkid: row.networkid,
                energytypeid: row.energytypeid,
                energyid: row.energyid,
                propertyid: row.propertyid,
                unitid: row.unitid,
                isschedule: row.isschedule,
                sourceType: row.sourceType,
                transfer: row.transfer,
                useflag: useflag,
                mintimegranid: row.mintimegranid
            };
            that.$confirm('是否' + (useflag === '1' ? '启用' : '禁用') + '?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.axios.put('pass/ems/v1/trmcalpoints/' + row.itemid, SubmitData)
                    .then(function (res) {
                        if (res.code === '0') {
                            that.$message({
                                message: useflag === '1' ? '启用成功' : '禁用成功',
                                type: 'success'
                            });
                            that.getTableData();
                            that.dialog.editorBox.show = false;
                        } else {
                            that.$message.error(res.message);
                        }
                    }).catch(function () {
                    });
            }).catch(() => {
            })
        }
    }
}
</script>

<style lang="less">
.emermaterials {
    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;
            }
        }
        .rowDisable td {
            background-color: #dfdfdf !important;
        }
    }
    .attribute-box {
        .item {
            border: #ccc 1px solid;
            padding: 5px;
            margin-bottom: 6px;
            .bt {
                font-size: 14px;
                font-weight: 600;
                color: #000;
                padding-left: 10px;
                border-left: #008fe0 5px solid;
            }
        }
    }
    .color_no {
        color: #7a7a7a;
    }
    .color_yes {
        color: #1a9f17;
    }
    .el-button--mini {
        padding: 7px 12px;
    }
    .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;
            }
        }
    .el-table .yellow-row{
        background : yellow !important;
    }
    .el-table .red-row{
        background : red !important;
    }
    .el-table .blue-row{
         background : rgb(204,241,255) !important;
    }
}
</style>
