<template>
    <!-- 电力运方单编制 -->
    <div class="EODCompile">
        <div class="box">
            <div class="box-top">
                <el-form
                    style="overflow: hidden;"
                    :style="filterForm.show ? null : { height: '0px' }"
                    size="mini"
                    label-width="110px"
                >
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="编制时间">
                                <el-date-picker
                                    type="datetimerange"
                                    v-model="filterForm.data.creattime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="运行主管">
                                <el-input clearable
                                    v-model="filterForm.data.applyman"
                                    placeholder=""
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="签收时间">
                                <el-date-picker
                                    type="datetimerange"
                                    v-model="filterForm.data.signtime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="用户名称">
                                <el-input clearable
                                    v-model="filterForm.data.manname"
                                    placeholder=""
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="实际执行时间">
                                <el-date-picker
                                    type="datetimerange"
                                    v-model="filterForm.data.executivetime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="变电所（室）">
                                <el-input clearable
                                    v-model="filterForm.data.changeelectricroom"
                                    placeholder=""
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="停役持续开始时间">
                                <el-date-picker
                                    type="datetimerange"
                                    v-model="filterForm.data.starttime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="线路（设备）">
                                <el-input clearable
                                    v-model="filterForm.data.lineequip"
                                    placeholder=""
                                    style="width: 100%;"
                                    @keyup.enter.native="getTableData(1)"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="停电工作开始时间">
                                <el-date-picker
                                    type="datetimerange"
                                    v-model="filterForm.data.tdstarttime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="单据状态">
                                <el-select
                                    filterable clearable
                                    v-model="filterForm.data.billstatus"
                                    placeholder=""
                                    style="width: 100%;"
                                    disabled
                                >
                                    <el-option
                                        v-for="item of nameObj.billstatus.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.operatestatus"
                                    placeholder=""
                                    style="width: 100%;"
                                >
                                    <el-option
                                        v-for="item of nameObj.operatestatus.arr"
                                        :key="item.id"
                                        :value="item.id"
                                        :label="item.name"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col> -->
                    </el-row>
                </el-form>
                <div class="box-top-gjl">
                    <el-button
                        class="button"
                        type="primary"
                        size="mini"
                        icon="el-icon-plus"
                        v-privilege="activeMenu + 'ADD'"
                        @click="but_add"
                    >新增</el-button>
                    <div style="float:right; text-align: right;">
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-search"
                            v-privilege="activeMenu + 'QUERY'"
                            @click="getTableData(1)"
                        >查询</el-button>
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-refresh"
                            v-privilege="activeMenu + 'QUERY'"
                            @click="tableDataCancel();"
                        >重置</el-button>
                        <el-button
                            size="mini"
                            :icon="filterForm.show ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"
                            :title="filterForm.show ? '收起搜索区' : '展开搜索区'"
                            @click="filterForm.show = !filterForm.show;
                                $nextTick(() => {
                                    singleTableHeight = getRoleHeight($refs['singleTable'].$el) - 45;
                                }
                            );"
                        >{{ filterForm.show ? '收起' : '展开' }}</el-button>
                    </div>
                </div>
            </div>
            <div class="box-bottom">
                <el-table
                    stripe
                    id="singleTable"
                    ref="singleTable"
                    :data="tableData"
                    v-loading="tableLoading"
                    style="width: 100%;"
                    :height="singleTableHeight"
                    border
                    size="mini"
                    highlight-current-row
                >
                    <el-table-column
                        sortable
                        prop="billsno"
                        label="运方单编号"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="creattime"
                        label="编制时间"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="applyman"
                        label="运行主管"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="manname"
                        label="用户名称"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="lineequip"
                        label="线路（设备）"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <el-table-column
                        sortable
                        prop="chargeman"
                        label="工作负责人"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    ></el-table-column>
                    <!-- <el-table-column
                    sortable
                        prop="operatestatus"
                        label="操作状态"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.operatestatus.obj[scope.row.operatestatus] ? nameObj.operatestatus.obj[scope.row.operatestatus] : scope.row.operatestatus }}</span>
                        </template>
                    </el-table-column> -->
                    <el-table-column
                        sortable
                        prop="billstatus"
                        label="单据状态"
                        min-width="100px"
                        :show-overflow-tooltip="true"
                    >
                        <template slot-scope="scope">
                            <span>{{ nameObj.billstatus.obj[scope.row.billstatus] ? nameObj.billstatus.obj[scope.row.billstatus] : scope.row.billstatus }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        class-name="gn-TableDownloadExcel-none"
                        label="操作"
                        align="center"
                        width="140px"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div>
                                <el-button
                                    type="primary"
                                    size="mini"
                                    v-privilege="activeMenu + 'PUT'"
                                    @click="but_edit(scope.row)"
                                >修改</el-button>
                                <el-button
                                    type="danger"
                                    size="mini"
                                    v-privilege="activeMenu + 'DELETE'"
                                    @click="but_del(scope.row)"
                                >删除</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    :page-sizes="[10, 20, 50, 100, 500, 1000]"
                    :page-size="pageSize"
                    :current-page.sync="pageNum"
                    @size-change="tableSizeChange"
                    @current-change="getTableData()"
                    style="text-align: right;margin-top: 10px;"
                ></el-pagination>
            </div>
        </div>
        <el-dialog
            :title="'电力运行方式变更通知单 - ' + (dialog.editorBox.type === 'add' ? '新增' : '修改')"
            :visible.sync="dialog.editorBox.show"
            width="940px"
            :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="120px"
                >
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label="介质系统"
                                prop="mediumsystem"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.mediumsystem"
                                    placeholder=""
                                    style="width: 100%;"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="运方单编号"
                                prop="billsno"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.billsno"
                                    placeholder=""
                                    style="width: 100%;"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="编制时间"
                                prop="creattime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.creattime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label="运行主管"
                                prop="applyman"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.applyman"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="用户名称"
                                prop="manname"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.manname"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="通知日期"
                                prop="noticetime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.noticetime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label="变电所（室）"
                                prop="changeelectricroom"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.changeelectricroom"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="线路（设备）"
                                prop="lineequip"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.lineequip"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="工作负责人"
                                prop="chargeman"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.chargeman"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label="停役持续开始时间"
                                prop="starttime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.starttime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="停役持续结束时间"
                                prop="stoptime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.stoptime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="联系电话"
                                prop="chargetel"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.chargetel"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label="停电工作开始时间"
                                prop="tdstarttime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.tdstarttime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="停电工作结束时间"
                                prop="tdstoptime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.tdstoptime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-container>
                        <el-main style="padding: 0;">
                            <el-form-item
                                label="工作内容"
                                prop="workcontent"
                            >
                                <el-input clearable
                                    class="nr-textarea"
                                    type="textarea"
                                    v-model="dialog.editorBox.form.data.workcontent"
                                    placeholder=""
                                    style="width: 100%;"
                                ></el-input>
                            </el-form-item>
                        </el-main>
                        <el-aside
                            width="200px"
                            style="padding-left: 15px;"
                        >
                            <zj-fileUploadBox
                                class="fileUploadBox"
                                :files="dialog.editorBox.files"
                            ></zj-fileUploadBox>
                        </el-aside>
                    </el-container>
                    <el-form-item
                        label="运行方式"
                        prop="runway"
                    >
                        <el-input clearable
                            type="textarea"
                            v-model="dialog.editorBox.form.data.runway"
                            placeholder=""
                            style="width: 100%;"
                        ></el-input>
                    </el-form-item>
                    <el-form-item
                        label="注意事项"
                        prop="attention"
                    >
                        <el-input clearable
                            type="textarea"
                            v-model="dialog.editorBox.form.data.attention"
                            placeholder=""
                            style="width: 100%;"
                        ></el-input>
                    </el-form-item>
                    <el-form-item
                        label="工作内容修改"
                        prop="contentchange"
                    >
                        <el-input clearable
                            type="textarea"
                            v-model="dialog.editorBox.form.data.contentchange"
                            placeholder=""
                            style="width: 100%;"
                        ></el-input>
                    </el-form-item>
                    <el-row>
                        <el-col :span="16">
                            <el-form-item
                                label="签收人"
                                prop="signman"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.signman"
                                    placeholder=""
                                    style="width: 100%;"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="签收时间"
                                prop="signtime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.signtime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    disabled
                                ></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item
                        label="执行情况"
                        prop="executivesituation"
                    >
                        <el-input clearable
                            type="textarea"
                            v-model="dialog.editorBox.form.data.executivesituation"
                            placeholder=""
                            style="width: 100%;"
                            disabled
                        ></el-input>
                    </el-form-item>
                    <el-form-item
                        label="备注"
                        prop="note"
                    >
                        <el-input clearable
                            type="textarea"
                            v-model="dialog.editorBox.form.data.note"
                            placeholder=""
                            style="width: 100%;"
                            disabled
                        ></el-input>
                    </el-form-item>
                    <el-row>
                        <el-col :span="16">
                            <el-form-item
                                label="执行负责人"
                                prop="executivechargeman"
                            >
                                <el-input clearable
                                    v-model="dialog.editorBox.form.data.executivechargeman"
                                    placeholder=""
                                    style="width: 100%;"
                                    disabled
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="实际执行时间"
                                prop="executivetime"
                            >
                                <el-date-picker
                                    type="datetime"
                                    v-model="dialog.editorBox.form.data.executivetime"
                                    placeholder=""
                                    style="width: 100%;"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    disabled
                                ></el-date-picker>
                            </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()"
                >暂 存</el-button>
                <el-button
                    type="primary"
                    @click="submitBut()"
                >提 交</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import fileUploadBox from '~/components/zg/fileUploadBox.vue'
import { formatDate } from '@/utils/util.js';
import store from '@/store/index.js';
export default {
    name: 'EODCompile',
    components: {
        'zj-fileUploadBox': fileUploadBox
    },
    data () {
        return {
            store,
            userInfo: {
                data: null
            },
            activeMenu: '',
            filterForm: {
                show: true,
                data: {
                    creattime: '',
                    applyman: '',
                    signtime: '',
                    manname: '',
                    executivetime: '',
                    changeelectricroom: '',
                    starttime: '',
                    lineequip: '',
                    tdstarttime: '',
                    billstatus: 'create'
                    // operatestatus: 'save'
                },
                rules: {

                }
            },
            pageNum: 1,
            pageSize: 20,
            total: 0,
            singleTableHeight: 100,
            tableData: [
                // {
                //     billsno: 'TFY_20190826_0001',
                //     creattime: '2019-08-26 15:03:56',
                //     applyman: 'admin',
                //     manname: '111',
                //     lineequip: 'cs',
                //     chargeman: '222',
                //     operatestatus: '暂存',
                //     billstatus: '编制'
                // }
            ],
            nameObj: {
                // operatestatus: {
                //     obj: {
                //         'save': '暂存'
                //     },
                //     arr: [
                //         {
                //             id: 'save',
                //             name: '暂存'
                //         }
                //     ]
                // },
                billstatus: {
                    obj: {
                        '': '全部',
                        'create': '编制',
                        'sign': '待签收',
                        'execute': '待执行',
                        'executed': '结束',
                        'drop': '报废'
                    },
                    arr: [
                        {
                            id: '',
                            name: '全部'
                        },
                        {
                            id: 'create',
                            name: '编制'
                        },
                        {
                            id: 'sign',
                            name: '待签收'
                        },
                        {
                            id: 'execute',
                            name: '待执行'
                        },
                        {
                            id: 'executed',
                            name: '结束'
                        },
                        {
                            id: 'drop',
                            name: '报废'
                        }
                    ]
                }
            },
            loading: false,
            tableLoading: false,
            dialog: {
                editorBox: {
                    show: false,
                    type: '',
                    form: {
                        data: {
                            mediumsystem: '电力',
                            billsno: '',
                            creattime: '',
                            applyman: '',
                            manname: '',
                            noticetime: '',
                            changeelectricroom: '',
                            lineequip: '',
                            chargeman: '',
                            starttime: '',
                            stoptime: '',
                            chargetel: '',
                            tdstarttime: '',
                            tdstoptime: '',
                            workcontent: '',
                            runway: '',
                            attention: '',
                            contentchange: '',
                            signman: '',
                            signtime: '',
                            executivesituation: '',
                            note: '',
                            executivechargeman: '',
                            executivetime: '',
                            content: '' // 上传文件名
                        },
                        rules: {
                            // billsno: [
                            //     { required: true, message: '该项不能为空', trigger: 'change' }
                            // ],
                            creattime: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            applyman: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            manname: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            noticetime: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            changeelectricroom: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            lineequip: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            chargeman: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            starttime: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            stoptime: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            chargetel: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            tdstarttime: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            tdstoptime: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            workcontent: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            runway: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            attention: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ],
                            contentchange: [
                                { required: true, message: '该项不能为空', trigger: 'change' }
                            ]
                        }
                    },
                    files: [
                        // {
                        //     name: '测试',
                        //     url: '',
                        //     file: null,
                        //     operation: '' // add or del
                        // }
                    ]
                }
            }
        };
    },
    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.store.dispatch('getUserInfo').then((res) => {
            that.userInfo.data = res.data;
        });
        that.getTableData();
    },
    methods: {
        //  计算树区域高度
        getRoleHeight (dom) {
            return window.innerHeight - dom.offsetTop;
        },
        // 获取表格中的数据
        getTableData (pageNum) {
            let that = this,
                params = {
                    creattime: that.filterForm.data.creattime[0],
                    creattimee: that.filterForm.data.creattime[1],
                    applyman: that.filterForm.data.applyman,
                    signtime: that.filterForm.data.signtime[0],
                    sigtimee: that.filterForm.data.signtime[1],
                    manname: that.filterForm.data.manname,
                    executivetime: that.filterForm.data.executivetime[0],
                    executivetimee: that.filterForm.data.executivetime[1],
                    changeelectricroom: that.filterForm.data.changeelectricroom,
                    starttime: that.filterForm.data.starttime[0],
                    starttimee: that.filterForm.data.starttime[1],
                    lineequip: that.filterForm.data.lineequip,
                    tdstarttime: that.filterForm.data.tdstarttime[0],
                    tdstarttimee: that.filterForm.data.tdstarttime[1],
                    billstatus: that.filterForm.data.billstatus
                    // operatestatus: that.filterForm.data.operatestatus
                };
            that.pageNum = pageNum || that.pageNum;
            that.tableLoading = true;
            let url = 'pass/ems/v1/tcm0365s/?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({
                                mediumsystem: item.mediumsystem,
                                billsno: item.billsno,
                                creattime: item.creattime,
                                applyman: item.applyman,
                                manname: item.manname,
                                noticetime: item.noticetime,
                                changeelectricroom: item.changeelectricroom,
                                lineequip: item.lineequip,
                                chargeman: item.chargeman,
                                starttime: item.starttime,
                                stoptime: item.stoptime,
                                chargetel: item.chargetel,
                                tdstarttime: item.tdstarttime,
                                tdstoptime: item.tdstoptime,
                                workcontent: item.workcontent,
                                runway: item.runway,
                                attention: item.attention,
                                contentchange: item.contentchange,
                                signman: item.signman,
                                signtime: item.signtime,
                                executivesituation: item.executivesituation,
                                note: item.note,
                                executivechargeman: item.executivechargeman,
                                executivetime: item.executivetime,
                                // operatestatus: item.operatestatus,
                                billstatus: item.billstatus,
                                content: item.content // 上传文件名
                            })
                        }
                        that.tableData = arr;
                        that.total = res.data.total;
                    } else {
                        that.$message.error(res.message);
                    }
                    that.tableLoading = false;
                }).catch(function () {
                    that.tableLoading = false;
                });
        },
        // 改变表格显示条数
        tableSizeChange (val) {
            let that = this;
            that.pageSize = val;
            that.getTableData(1);
        },
        // 重置搜索
        tableDataCancel () {
            let that = this;
            for (let key in that.filterForm.data) {
                if (that.filterForm.data[key] instanceof Array) {
                    that.filterForm.data[key] = [];
                } else {
                    that.filterForm.data[key] = '';
                }
            }
            that.filterForm.data.billstatus = 'create';
            that.getTableData(1);
        },
        but_add () {
            let that = this;
            that.dialog.editorBox.files = [];
            for (let key in that.dialog.editorBox.form.data) {
                that.dialog.editorBox.form.data[key] = '';
            }
            that.dialog.editorBox.form.data.mediumsystem = '电力';
            that.dialog.editorBox.form.data.manname = that.userInfo.data.userName;
            that.dialog.editorBox.form.data.noticetime = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss');
            that.dialog.editorBox.form.data.starttime = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss');
            that.dialog.editorBox.form.data.stoptime = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss');
            that.dialog.editorBox.form.data.tdstarttime = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss');
            that.dialog.editorBox.form.data.tdstoptime = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss');
            that.dialog.editorBox.type = 'add';
            that.dialog.editorBox.show = true;
            setTimeout(() => {
                that.$refs['dialog_form'].clearValidate();
            }, 100);
        },
        but_edit (row) {
            let that = this;
            that.dialog.editorBox.files = [];
            for (let key in that.dialog.editorBox.form.data) {
                if (typeof row[key] !== 'undefined') {
                    that.dialog.editorBox.form.data[key] = row[key];
                } else {
                    console.log(key);
                }
            }
            if (row.content) {
                let fn = (row.content + '').trim().split(';')
                if (fn && fn.length > 0) {
                    let billsno = row.billsno;
                    for (let i = 0; i < fn.length; i++) {
                        if (fn[i]) {
                            let fname = {name: fn[i], url: '/zhongsteel.pass.web/pass/ems/static/' + billsno + '/' + fn[i], file: null, operation: ''};
                            that.dialog.editorBox.files.push(fname);
                        }
                    }
                }
            }
            that.dialog.editorBox.type = 'edit';
            that.dialog.editorBox.show = true;
        },
        but_del (row) {
            let that = this;
            that.$confirm('是否删除该条数据?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                state: 'warning'
            }).then(() => {
                that.axios.delete('pass/ems/v1/tcm0365s/' + row.billsno)
                    .then(function (res) {
                        if (res.code === '0') {
                            that.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            that.getTableData();
                        } else {
                            that.$message.error(res.message);
                        }
                    }).catch(function () {
                    });
            }).catch(() => {
            });
        },
        submitBut () {
            let that = this;
            that.$confirm('是否提交?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.dataSave('submit');
            }).catch(() => {
            });
        },
        dataSave (billstatus) {
            let that = this;
            let SubmitData = {
                mediumsystem: that.dialog.editorBox.form.data.mediumsystem,
                billsno: that.dialog.editorBox.form.data.billsno,
                creattime: that.dialog.editorBox.form.data.creattime,
                applyman: that.dialog.editorBox.form.data.applyman,
                manname: that.dialog.editorBox.form.data.manname,
                noticetime: that.dialog.editorBox.form.data.noticetime,
                changeelectricroom: that.dialog.editorBox.form.data.changeelectricroom,
                lineequip: that.dialog.editorBox.form.data.lineequip,
                chargeman: that.dialog.editorBox.form.data.chargeman,
                starttime: that.dialog.editorBox.form.data.starttime,
                stoptime: that.dialog.editorBox.form.data.stoptime,
                chargetel: that.dialog.editorBox.form.data.chargetel,
                tdstarttime: that.dialog.editorBox.form.data.tdstarttime,
                tdstoptime: that.dialog.editorBox.form.data.tdstoptime,
                workcontent: that.dialog.editorBox.form.data.workcontent,
                runway: that.dialog.editorBox.form.data.runway,
                attention: that.dialog.editorBox.form.data.attention,
                contentchange: that.dialog.editorBox.form.data.contentchange,
                signman: that.dialog.editorBox.form.data.signman,
                signtime: that.dialog.editorBox.form.data.signtime,
                executivesituation: that.dialog.editorBox.form.data.executivesituation,
                note: that.dialog.editorBox.form.data.note,
                executivechargeman: that.dialog.editorBox.form.data.executivechargeman,
                executivetime: that.dialog.editorBox.form.data.executivetime,
                billstatus: 'create'
            };
            // content: that.dialog.editorBox.files 上传文件
            let message = '保存成功';
            if (billstatus && billstatus !== 'submit') {
                SubmitData.billstatus = billstatus;
                message = '操作成功';
            }
            that.$refs['dialog_form'].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    let url = 'pass/ems/v1/tcm0365s/';
                    if (billstatus === 'submit') {
                        message = '提交成功';
                        url = 'pass/ems/v1/tcm0365s/submit/';
                    }
                    let fileData = new FormData();
                    for (let key in SubmitData) {
                        fileData.append(key, SubmitData[key] ? SubmitData[key] : '');
                    }
                    // 删除的文件名
                    let del = '';
                    // 保存的文件名
                    let content = '';
                    for (let item of that.dialog.editorBox.files) {
                        if (item.operation === 'add' && item.file && item.name) {
                            fileData.append('file', item.file);
                        }
                        if (item.operation === 'del' && item.name) {
                            del += item.name + ';';
                        }
                        if (item.operation !== 'del' && item.name) {
                            content += item.name + ';';
                        }
                    }
                    fileData.set('content', content);
                    fileData.set('del', del);
                    that.axios.put(url, fileData, {headers: {'Content-Type': 'multipart/form-data'}})
                        .then(function (res) {
                            if (res.code === '0') {
                                that.$message({
                                    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;
                        });
                }
            });
        }
    }
}
</script>

<style lang="less">
.EODCompile {
    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;
            }
        }
    }
    .nr-textarea {
        .el-textarea__inner {
            min-height: 130px !important;
        }
    }
    .fileUploadBox {
        height: 130px;
        min-height: 130px !important;
        margin-bottom: 18px;
    }
}
</style>
