<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="当班班组" prop="shiftTeam">
        <el-input
            v-model="queryParams.shiftTeam"
            clearable
            placeholder="请输入当班班组"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['shiftmgr:log:add']"
            icon="el-icon-plus"
            plain
            size="mini"
            type="primary"
            @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">
              <el-button
                v-hasPermi="['shiftmgr:log:edit']"
                :disabled="single"
                icon="el-icon-edit"
                plain
                size="mini"
                type="success"
                @click="handleUpdate"
              >修改
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['shiftmgr:log:remove']"
                :disabled="multiple"
                icon="el-icon-delete"
                plain
                size="mini"
                type="danger"
                @click="handleDelete"
              >删除
              </el-button>
            </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['shiftmgr:log:export']"-->
      <!--        >导出-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="logList" :height="clientHeight" border
              @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="当班班组" prop="shiftTeam"/>
      <el-table-column align="center" label="接班时间" prop="takeOverTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takeOverTime, '{y}-{m}-{d} {h}:{i}') }} </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="交班时间" prop="giveOverTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.giveOverTime, '{y}-{m}-{d} {h}:{i}') }} </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="接班时工艺状况" prop="tocp"/>
      <el-table-column align="center" label="交班班组人员" prop="hoShiftSup">
        <template slot-scope="scope">
          <span>{{ bzFormat(scope.row.hoShiftSup) }} </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="接班班组人员" prop="toShiftSup">
        <template slot-scope="scope">
          <span>{{ bzFormat(scope.row.toShiftSup) }} </span>
        </template>
      </el-table-column>
      <el-table-column :formatter="statusFormat" align="center" label="状态" prop="status"/>
      <el-table-column align="center" label="备注" prop="remarks"/>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button
              icon="el-icon-download"
              size="mini"
              type="text"
              v-if="scope.row.status==1"
              @click="exportLog(scope.row.id)"
          >导出
          </el-button>
          <el-button
              icon="el-icon-document"
              size="mini"
              type="text"
              @click="openDetail(scope.row.id)"
          >详情
          </el-button>
          <el-button
              v-if="scope.row.status!=1&&scope.row.hoShiftSup==userId"
              v-hasPermi="['shiftmgr:log:edit']"
              icon="el-icon-edit"
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
              v-if="scope.row.status!=1&&scope.row.hoShiftSup==userId"
              v-hasPermi="['shiftmgr:log:remove']"
              icon="el-icon-delete"
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
    />

    <!-- 添加或修改轮班日志对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body
               contentClassName="content"
               width="60%">
      <el-form ref="form" :model="form" :rules="rules" label-width="auto">
        <el-collapse>
          <el-descriptions :column="4" border direction="vertical" label-class-name="des-label label-hh" size="">
            <el-descriptions-item :span="2" label="Shift team 当班班组：">
              <el-form-item prop="shiftTeam">
                <el-input v-if="this.isEdit" v-model="form.shiftTeam" disabled placeholder="请输入当班班组"/>
                <el-select v-if="!this.isEdit" v-model="hoShiftTeam" clearable filterable placeholder="请选择交班班组"
                           style="width: 50%;">
                  <el-option
                      v-for="dict in teamOptions"
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="dict.dictValue"/>
                </el-select>
                <el-select v-if="!this.isEdit" v-model="toShiftTeam" clearable filterable placeholder="请选择接班班组"
                           style="width: 50%;">
                  <el-option
                      v-for="dict in teamOptions"
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="dict.dictValue"/>
                </el-select>
              </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item :span="2" label="Take-Over time 接班时间：">
              <el-form-item prop="takeOverTime">
                <el-date-picker v-model="form.takeOverTime"
                                clearable
                                format="yyyy-MM-dd HH:mm"
                                placeholder="请选择接班时间"
                                style="width: 100%"
                                type="datetime"
                                value-format="yyyy-MM-dd HH:mm">
                </el-date-picker>
              </el-form-item>
            </el-descriptions-item>
          </el-descriptions>
          <el-collapse-item title="►Take-Over Conditions of Process 接班时工艺状况:">
            <el-input v-model="form.tocp" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-collapse-item title="►EHS and 5S briefing 安全、环保、健康及5S事项班前简报">
            <el-input v-model="form.ehs5sBriefing" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-collapse-item title="►Plant Conditions and Actions/Quality 装置状况和操作/质量：">
            <el-collapse-item title="● Splitter and Oxidation/Absorption C4分离和氧化吸收">
              <el-input v-model="form.soa" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● Stripping and Hydrogenation   汽提和加氢">
              <el-input v-model="form.sh" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● BDO Cyclization   BDO环化">
              <el-input v-model="form.bdoc" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● THF Distillation   THF精馏">
              <el-input v-model="form.thfd" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● PTHF    PTHF单元">
              <el-input v-model="form.pthfUnit" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● DBP Distillation    DBP精馏">
              <el-input v-model="form.dbpd" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● TRU and Steam system    TRU和蒸汽系统">
              <el-input v-model="form.truss" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● PolyTHF Complex Utility system    PolyTHF Complex公用工程系统">
              <el-input v-model="form.pthfCus" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● BIP Utility system    BIP公用工程系统">
              <el-input v-model="form.bipus" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
          </el-collapse-item>
          <el-collapse-item title="►LPG and H2 (3rd party) 液化气和氢气（外部）">
            <el-input v-model="form.lpgH2" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-collapse-item title="►Environment, Health and Safety 环境，健康和安全">
            <el-descriptions :column="4" border direction="vertical" label-class-name="des-label label-hh" size="">
              <el-descriptions-item
                  :label="'● Environmental Protection Devices    环保设施状况'"
                  :span="4"
                  contentClassName="contentSty">
              </el-descriptions-item>
              <el-descriptions-item :span="2" label="TRU	CO	Q125601">
                <el-radio-group v-model="form.q125601">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="2" label="TRU 非甲烷总烃 Q125602">
                <el-radio-group v-model="form.q125602">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="1" label="厂界 THF Q312018-Q1">
                <el-radio-group v-model="form.q312018Q1">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="1" label="厂界 MeOH Q312018-Q2">
                <el-radio-group v-model="form.q312018Q2">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="1" label="厂界 MeAC Q312018-Q3">
                <el-radio-group v-model="form.q312018Q3">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="1" label="厂界 Xylene Q312018-Q4">
                <el-radio-group v-model="form.q312018Q4">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="2" label="雨水总管 TOC Q312000">
                <el-radio-group v-model="form.q312000">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item :span="2" label="雨水总管 PH Q312001">
                <el-radio-group v-model="form.q312001">
                  <el-radio :label="'正常'">正常</el-radio>
                  <el-radio :label="'异常'">异常</el-radio>
                </el-radio-group>
              </el-descriptions-item>
            </el-descriptions>
            <el-descriptions-item :span="4" label="异常状况描述:">
              <el-input v-model="form.epdOther" placeholder="请输入内容" type="textarea"/>
            </el-descriptions-item>
            <el-descriptions-item :span="4" label="● Other 其他">
              <el-input v-model="form.ehsOther" placeholder="请输入内容" type="textarea"/>
            </el-descriptions-item>
          </el-collapse-item>
          <el-collapse-item title="►Quality and Analytical Report 产品质量和分析报告">
            <el-input v-model="form.qar" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-collapse-item title="►Maintenance Activities 电仪和机械维修">
            <el-collapse-item title="● E&I电气及仪表">
              <el-input v-model="form.maEi" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● Mechanical 机械">
              <el-input v-model="form.maMechanical" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
          </el-collapse-item>
          <el-collapse-item title="►Third Party Communication 第三方联系">
            <el-input v-model="form.thirdPartyCommunication" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-collapse-item title="►Follow-up Activities for Maintenance part 接班班组需继续的维修工作">
            <el-collapse-item title="● E&I电气及仪表">
              <el-input v-model="form.fampEi" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
            <el-collapse-item title="● Mechanical 机械">
              <el-input v-model="form.fampMechanical" placeholder="请输入内容" type="textarea"/>
            </el-collapse-item>
          </el-collapse-item>
          <el-collapse-item title="►Follow-up Activities for Operation part 接班班组需继续的操作">
            <el-input v-model="form.faop" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-collapse-item title="►Miscellaneous / Comments 其他/评述">
            <el-input v-model="form.comments" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
          <el-descriptions :column="4" border direction="vertical" label-class-name="des-label label-hh" size="">
            <el-descriptions-item :span="2" label="Hand-Over Shift Supervisor 交班班组人员">
              <el-form-item prop="hoShiftSup">
                <el-select v-model="form.hoShiftSup" clearable filterable placeholder="请选择交班班组人员"
                           style="width: 100%;">
                  <el-option v-for="user in userList"
                             :key="user.userId"
                             :label="user.nickName"
                             :value="user.userId"
                  />
                </el-select>
              </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item :span="2" label="Take-Over Shift Supervisor 接班班组人员">
              <el-form-item prop="toShiftSup">
                <el-select v-model="form.toShiftSup" clearable filterable placeholder="请选择接班班组人员"
                           style="width: 100%;">
                  <el-option v-for="user in userList"
                             :key="user.userId"
                             :label="user.nickName"
                             :value="user.userId"
                  />
                </el-select>
              </el-form-item>
            </el-descriptions-item>
          </el-descriptions>
          <el-collapse-item title="备注">
            <el-input v-model="form.remarks" placeholder="请输入内容" type="textarea"/>
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :close-on-click-modal="false" :visible.sync="detail.open" append-to-body title="轮班日志详情"
               width="60%">
      <el-descriptions :column="4" border direction="vertical" label-class-name="label-hh" size="default">
        <el-descriptions-item :span="2" label="Shift team 当班班组：">
          {{ detail.data.shiftTeam }}
        </el-descriptions-item>
        <el-descriptions-item :span="1" label="Take-Over time 接班时间：">
          {{ detail.data.takeOverTime }}
        </el-descriptions-item>
        <el-descriptions-item :span="1" label="Hand-Over time 交班时间：">
          {{ detail.data.giveOverTime }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►Take-Over Conditions of Process 接班时工艺状况:">
          {{ detail.data.tocp }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►EHS and 5S briefing 安全、环保、健康及5S事项班前简报">
          {{ detail.data.ehs5sBriefing }}
        </el-descriptions-item>
        <el-descriptions-item
            :label="'►Plant Conditions and Actions/Quality 装置状况和操作/质量：\n● Splitter and Oxidation/Absorption C4分离和氧化吸收'"
            :span="4">
          {{ detail.data.soa }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● Stripping and Hydrogenation   汽提和加氢">
          {{ detail.data.sh }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● BDO Cyclization   BDO环化">
          {{ detail.data.bdoc }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● THF Distillation   THF精馏">
          {{ detail.data.thfd }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● PTHF    PTHF单元">
          {{ detail.data.pthfUnit }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● DBP Distillation    DBP精馏">
          {{ detail.data.dbpd }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● TRU and Steam system    TRU和蒸汽系统">
          {{ detail.data.truss }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● PolyTHF Complex Utility system    PolyTHF Complex公用工程系统">
          {{ detail.data.pthfCus }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● BIP Utility system    BIP公用工程系统">
          {{ detail.data.bipus }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►LPG and H2 (3rd party) 液化气和氢气（外部）">
          {{ detail.data.lpgH2 }}
        </el-descriptions-item>
        <el-descriptions-item
            :label="'►Environment, Health and Safety 环境，健康和安全\n● Environmental Protection Devices    环保设施状况'"
            :span="4"
            contentClassName="contentSty">
        </el-descriptions-item>
        <el-descriptions-item :span="2" label="TRU	CO	Q125601">
          {{ detail.data.q125601 }}
        </el-descriptions-item>
        <el-descriptions-item :span="2" label="TRU 非甲烷总烃 Q125602">
          {{ detail.data.q125602 }}
        </el-descriptions-item>
        <el-descriptions-item :span="1" label="厂界 THF Q312018-Q1">
          {{ detail.data.q312018Q1 }}
        </el-descriptions-item>
        <el-descriptions-item :span="1" label="厂界 MeOH Q312018-Q2">
          {{ detail.data.q312018Q2 }}
        </el-descriptions-item>
        <el-descriptions-item :span="1" label="厂界 MeAC Q312018-Q3">
          {{ detail.data.q312018Q3 }}
        </el-descriptions-item>
        <el-descriptions-item :span="1" label="厂界 Xylene Q312018-Q4">
          {{ detail.data.q312018Q4 }}
        </el-descriptions-item>
        <el-descriptions-item :span="2" label="雨水总管 TOC Q312000">
          {{ detail.data.q312000 }}
        </el-descriptions-item>
        <el-descriptions-item :span="2" label="雨水总管 PH Q312001">
          {{ detail.data.q312001 }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="异常状况描述:">
          {{ detail.data.epdOther }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● Other 其他">
          {{ detail.data.ehsOther }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►Quality and Analytical Report 产品质量和分析报告">
          {{ detail.data.qar }}
        </el-descriptions-item>
        <el-descriptions-item :label="'Maintenance Activities 电仪和机械维修\n● E&I电气及仪表'" :span="4">
          {{ detail.data.maEi }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● Mechanical 机械">
          {{ detail.data.maMechanical }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►Third Party Communication 第三方联系">
          {{ detail.data.thirdPartyCommunication }}
        </el-descriptions-item>
        <el-descriptions-item
            :label="'►Follow-up Activities for Maintenance part 接班班组需继续的维修工作\n● E&I电气及仪表'"
            :span="4">
          {{ detail.data.fampEi }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="● Mechanical 机械">
          {{ detail.data.fampMechanical }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►Follow-up Activities for Operation part 接班班组需继续的操作">
          {{ detail.data.faop }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="►Miscellaneous / Comments 其他/评述">
          {{ detail.data.comments }}
        </el-descriptions-item>
        <el-descriptions-item :span="2" label="Hand-Over Shift Supervisor 交班班组人员">
          {{ bzFormat(detail.data.hoShiftSup) }}
        </el-descriptions-item>
        <el-descriptions-item :span="2" label="Take-Over Shift Supervisor 接班班组人员">
          {{ bzFormat(detail.data.toShiftSup) }}
        </el-descriptions-item>
        <el-descriptions-item :span="4" label="备注">
          {{ detail.data.remark }}
        </el-descriptions-item>
      </el-descriptions>
      <div v-if="detail.data.toShiftSup==userId" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="conform">确 认</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addLog, delLog, getLog, listLog, updateLog,getLastData, wordView} from "@/api/shiftmgr/log";
import {listPostUser} from "@/api/system/user";

export default {
  name: "Log",
  data() {
    return {
      detail: {
        open: false,
        data: {},
      },
      // 页面高度
      clientHeight: 300,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      userId: '',
      hoShiftTeam: '',
      toShiftTeam: '',
      userList: [],
      teamList: [],
      // 非单个禁用
      single: true,
      isEdit: false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 轮班日志表格数据
      logList: [],
      // 班组字典
      teamOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        shiftTeam: null,
        takeOverTime: null,
        giveOverTime: null,
        tocp: null,
        ehs5sBriefing: null,
        soa: null,
        sh: null,
        bdoc: null,
        thfd: null,
        pthfUnit: null,
        dbpd: null,
        truss: null,
        pthfCus: null,
        bipus: null,
        lpgH2: null,
        q125601: null,
        q125602: null,
        q312018Q1: null,
        q312018Q2: null,
        q312018Q3: null,
        q312018Q4: null,
        q312000: null,
        q312001: null,
        epdOther: null,
        ehsOther: null,
        qar: null,
        maEi: null,
        maMechanical: null,
        thirdPartyCommunication: null,
        fampEi: null,
        fampMechanical: null,
        faop: null,
        comments: null,
        hoShiftSup: null,
        toShiftSup: null,
        status: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        shiftTeam: [
          {required: true, message: "当班班组不能为空", trigger: "blur"}
        ],
        hoShiftSup: [
          {required: true, message: "交班班组人员不能为空", trigger: "blur"}
        ],
        toShiftSup: [
          {required: true, message: "接班班组人员不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = (document.body.clientHeight - 80) * 0.8
    });
    this.getDicts("TEAM_DIVIDE").then(res => {
      this.teamOptions = res.data;
    });
    this.getBzUser();
  },
  methods: {
    statusFormat(row) {
      return row.status == 1 ? '已确认' : '未确认'
    },
    bzFormat(userId) {
      for (let user of this.userList) {
        if (userId == user.userId) {
          return user.nickName;
        }
      }
    },
    getBzUser() {
      listPostUser({postCode: 'se'}).then(response => {
        this.userList = response;
      });
    },
    openDetail(id) {
      getLog(id).then(response => {
        this.detail.data = response.data;
        this.detail.open = true;
      });
    },
    /** 查询轮班日志列表 */
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        this.logList = response.data.rows;
        this.total = response.data.total;
        this.userId = response.msg;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.detail.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        shiftTeam: null,
        takeOverTime: null,
        giveOverTime: null,
        tocp: null,
        ehs5sBriefing: null,
        soa: null,
        sh: null,
        bdoc: null,
        thfd: null,
        pthfUnit: null,
        dbpd: null,
        truss: null,
        pthfCus: null,
        bipus: null,
        lpgH2: null,
        q125601: null,
        q125602: null,
        q312018Q1: null,
        q312018Q2: null,
        q312018Q3: null,
        q312018Q4: null,
        q312000: null,
        q312001: null,
        epdOther: null,
        ehsOther: null,
        qar: null,
        maEi: null,
        maMechanical: null,
        thirdPartyCommunication: null,
        fampEi: null,
        fampMechanical: null,
        faop: null,
        comments: null,
        hoShiftSup: null,
        toShiftSup: null,
        delFlag: null,
        status: 0,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null,
        remarks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.isEdit = false;
      this.reset();
      this.open = true;
      this.title = "添加轮班日志";
      getLastData({}).then(res => {
        if (res.data) {
          this.form = res.data;
          this.form.id = null;
          this.form.status = null;
          this.form.takeOverTime = this.form.giveOverTime
          this.form.giveOverTime = null;
          this.form.hoShiftSup = parseInt(this.userId);
          this.form.toShiftSup = "";
        }
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.isEdit = true;
      const id = row.id || this.ids
      getLog(id).then(response => {
        response.data.toShiftSup = parseInt(response.data.toShiftSup);
        response.data.hoShiftSup = parseInt(response.data.hoShiftSup);
        this.form = response.data;
        this.open = true;
        this.title = "修改轮班日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (this.hoShiftTeam && this.hoShiftTeam) {
        if (this.hoShiftTeam === this.toShiftTeam) {
          return this.$message.error("交班班组不能为接班班组！")
        }
        for (let team of this.teamOptions) {
          if (team.dictValue === this.hoShiftTeam) {
            this.hoShiftTeam = team.dictLabel
          }
          if (team.dictValue === this.toShiftTeam) {
            this.toShiftTeam = team.dictLabel
          }
        }
        this.form.shiftTeam = this.hoShiftTeam + "->" + this.toShiftTeam;
      }
      if (this.form.giveOverTime) {
        this.form.giveOverTime.format("yyyy-MM-dd HH:mm")
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    conform() {
      this.detail.data.status = 1;
      updateLog(this.detail.data).then(response => {
        this.$modal.msgSuccess("确认成功");
        this.detail.open = false;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除数据项？').then(function () {
        return delLog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('shiftmgr/log/export', {
        ...this.queryParams
      }, `log_${new Date().getTime()}.xlsx`)
    },
    exportLog(id) {
      wordView(id).then(res => {
        if (res.msg)
          window.open(process.env.VUE_APP_BASE_API + res.msg);
      })
    }
  }
};
</script>

<style>
.des-label {
  color: #3a3a3a !important;
  font-size: 14px;
}

.label-hh {
  white-space: pre-line !important;
  width: 240px !important;
}

.contentSty {
  display: none !important;
}
</style>
