<template>
  <div style="height: 100%;width: 100%;background: #d6dde5">
    <el-col :span="20" style="height: 100%; background: #fff">
      <el-row
          style="background-color: #ffffff;height: 100%;position: relative;margin: 0 6px 0 3px;cursor: pointer;border: 2px solid #9e9b9b"
          @click.native="showAlarmList()">
        <el-col :span="3" style="text-align: center;border-right: 2px solid #9e9b9b">
          <div style="font-size: 32px;background-color: #d7dee6;">
            报警信息：
          </div>
        </el-col>
        <el-col :span="21">
          <div v-if="alarmList.length > 0" class="slogan">
            {{ alarmList[0].报警内容 }}
          </div>
          <div v-else class="slogan1"/>
        </el-col>
      </el-row>
    </el-col>
    <el-col :span="4" style="height: 100%">
      <el-row style="height: 100%">
        <el-popover content="" placement="bottom" title="" trigger="click" width="290">
          <div style="width: 290px;">
            <el-switch
                v-if="buttonShowList.indexOf('MES_OnlineStatus') > -1"
                v-model="value"
                active-color="#13ce66"
                active-text="MES在线"
                inactive-color="#ff4949"
                inactive-text="MES屏蔽"
                @change="changeStationStatus"
            />
            <el-switch
                v-if="buttonShowList.indexOf('MES_PartStatus') > -1"
                v-model="TurnLineWorkValue"
                active-color="#13ce66"
                active-text="正常工件"
                inactive-color="#ff4949"
                inactive-text="转线工件"
                @change="changeTurnLineWork"
            />
            <el-button v-if="buttonShowList.indexOf('MES_ConfirmOk') > -1" class="button" plain type="primary"
                       @click="qualifiedRelease">
              <span style="font-size: 28px">合 格 放 行</span>
            </el-button>
            <el-button v-if="buttonShowList.indexOf('MES_NgGO') > -1" class="button" plain type="primary"
                       @click="unqualifiedRelease">
              <span style="font-size: 28px">不 合 格 放 行</span>
            </el-button>
            <el-button v-if="buttonShowList.indexOf('MES_WritePallet') > -1" class="button" plain type="primary"
                       @click="mesWritePallet">
              <span style="font-size: 28px">修改托盘号</span>
            </el-button>
            <el-button v-if="buttonShowList.indexOf('MES_Reset') > -1" class="button" plain type="primary"
                       @click="mesReset">
              <span style="font-size: 28px">MES 复 位</span>
            </el-button>
            <el-button
                v-if="buttonShowList.indexOf('MES_AgainPartLoad') > -1"
                class="button"
                plain
                type="primary"
                @click="againPartLoad">
              <span>重 新 申 请 上 线</span>
            </el-button>
            <el-button
                v-if="buttonShowList.indexOf('MES_SkipWork') > -1"
                class="button"
                plain
                type="primary"
                @click="skipWork()">
              <span>跳 过 交 互</span>
            </el-button>
            <el-button
                v-if="buttonShowList.indexOf('MES_ForceOffLine') > -1"
                class="button"
                plain
                type="primary"
                @click="forceOffLine">
              <span>强 制 下 线</span>
            </el-button>
            <el-button
                v-if="buttonShowList.indexOf('MES_FaultStart') > -1"
                class="button"
                plain
                type="primary"
                @click="faultStart">
              <span>故 障 停 机</span>
            </el-button>
            <el-button
                v-if="buttonShowList.indexOf('MES_FaultEnd') > -1"
                class="button"
                plain
                style="background-color:#fbff08;"
                type="primary"
                @click="faultEnd">
              <span>停 机 结 束</span>
            </el-button>
            <el-button class="button" plain type="primary" @click="loginOut">
              <span >退 出 系 统</span>
            </el-button>
          </div>
          <el-button slot="reference"
                     style="font-size: 25px;background-color: #005bac;color: white; width: 99%; height: 100%;border: 3px solid black;padding: 0;">
            功能按钮
          </el-button>
        </el-popover>
      </el-row>
    </el-col>
    <el-dialog :append-to-body="true" :visible.sync="dialogFormVisible2" center style="text-align: center"
               title="报警列表"
               width="850px">
      <el-table
          :data="alarmList"
          :header-cell-style="{background:'#F5F5F5'}"
          :index="tableIndexValue"
          :row-class-name="tableRowClassName"
          max-height="500px"
          style="width: 100%; border: 1px solid #9e9b9b"
          tooltip-effect="dark"
      >
        <el-table-column align="center" label="#" type="index" width="50px"/>
        <el-table-column align="center" label="报警内容" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.报警内容 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="报警等级" width="300px">
          <template #default="scope">
            {{ scope.row.报警等级 }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog :append-to-body="true" :visible.sync="dialogFormVisible1" center style="text-align: center"
               title="合格放行"
               width="400px">
      <div style="text-align: center">
        <el-form
            ref="form1"
            :model="form1"
            class="demo-ruleForm"
            label-position="left"
            label-width="100px"
            style="width: 90%;margin: auto"
        >
          <div>
            <span style="font-size: large; color: black; line-height: 90px; ">请输入用户名：</span>
            <el-input v-model="form1.userName"
                      style="width:150px; margin-top: 20px; border: 2px solid black; border-radius:6px"/>
          </div>
          <div>
            <span style="font-size: large; color: black; line-height: 90px; ">请输入密码：</span>
            <el-input v-model="form1.userPassword"
                      style="width:150px; margin-top: 20px; margin-left: 15px; border: 2px solid black; border-radius:6px"/>
          </div>
          <div style="text-align: center; margin-top: 20px">
            <el-button class="el-icon-check" type="primary" @click="confirm11()">确定</el-button>
            <el-button class="el-icon-close" style="margin-left: 60px" @click="cancel()">取消</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <el-dialog :append-to-body="true" :visible.sync="mesWritePalletVisible" center style="text-align: center"
               title="修改托盘编号"
               width="400px">
      <div style="text-align: center">
        <el-form
            ref="form2"
            :model="form2"
            label-position="left"
            label-width="100px"
            style="width: 100%;margin: auto"
        >
          <div>
            <span style="font-size: large; color: black; line-height: 90px; ">托盘编号：</span>
            <el-input-number v-model="form2.pallet" :min="0" :step="1" style="width:150px;"/>
          </div>
          <div style="text-align: center; margin-top: 20px">
            <el-button class="el-icon-check" type="primary" @click="confirmWritePallet()">确定</el-button>
            <el-button class="el-icon-close" style="margin-left: 50px" @click="cancelWritePallet()">关闭</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!--// 故障停机弹出框-->
    <el-dialog
        :append-to-body="true"
        :visible.sync="isShowFaultStart"
        center
        style="text-align: center"
        title="故障停机"
        width="400px">
      <div style="text-align: center">
        <el-form
            ref="faultStartFormRef"
            :model="faultStartForm"
            label-position="left"
            label-width="100px"
            style="width: 100%;margin: auto"
        >
          <el-form-item label="故障开始时间" prop="engineTypeValue" style="display: inline-block">
            <el-date-picker
                v-model="faultStartForm.startTime"
                placeholder="请选择故障开始时间"
                size="small"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"/>
          </el-form-item>
          <el-form-item label="故障发现人" prop="engineTypeValue" style="display: inline-block">
            <el-input
                v-model="faultStartForm.discoverer"
                placeholder="请输入故障发现人工号"
                size="small"
                style="width:200px;"/>
          </el-form-item>
          <!--底部按钮-->
          <div style="text-align: center; margin-top: 20px">
            <el-button class="el-icon-check" type="primary" @click="faultStartSubmit()">确定</el-button>
            <el-button class="el-icon-close" style="margin-left: 50px" @click="isShowFaultStart = false">关闭
            </el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!--// 停机结束弹出框-->
    <el-dialog
        :append-to-body="true"
        :visible.sync="isShowFaultEnd"
        center
        style="text-align: center"
        title="停机结束"
        width="450px">
      <div style="text-align: center">
        <el-form
            ref="faultStartFormRef"
            :model="faultStartForm"
            label-position="right"
            label-width="130px"
            style="width: 100%;margin: auto"
        >
          <el-form-item label="故障开始时间" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-date-picker
                v-model="faultEndForm.startTime"
                placeholder="请选择故障开始时间"
                size="small"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="faultStartEndTimeChange()"/>
          </el-form-item>
          <el-form-item label="故障结束时间" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-date-picker
                v-model="faultEndForm.endTime"
                placeholder="请选择故障结束时间"
                size="small"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="faultStartEndTimeChange()"/>
          </el-form-item>
          <el-form-item label="停机时长(秒)" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input-number
                v-model="faultEndForm.stopTIme"
                :max="999999"
                :precision="0"
                :step="1"
                size="small"
                style="width:220px;"></el-input-number>
          </el-form-item>
          <el-form-item label="停机时长" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input v-model="faultEndForm.stopTimeStr" placeholder="停机时长" size="small" style="width:220px;"/>
          </el-form-item>
          <el-form-item label="故障处理人工号" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input
                v-model="faultEndForm.handlinger"
                placeholder="请输入故障处理人"
                size="small"
                style="width:220px;"/>
          </el-form-item>
          <el-form-item label="停机原因" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input
                v-model="faultEndForm.stopCause"
                :rows="2"
                placeholder="请输入停机原因"
                style="height: 42px;width: 220px"
                type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="故障停机类型" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-select
                v-model="backWorkform.faultType"
                placeholder="请选择故障原因"
                style="width:220px;"
                size="small">
              <el-option
                  v-for="item in backWorkform.faultTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  size="mini"/>
            </el-select>
          </el-form-item>
          <!--底部按钮-->
          <div style="text-align: center; margin-top: 20px">
            <el-button class="el-icon-check" type="primary" @click="faultEndSubmit()">确定</el-button>
            <el-button class="el-icon-close" style="margin-left: 50px" @click="isShowFaultEnd = false">关闭</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!--// 强制下线弹出框-->
    <el-dialog
        :append-to-body="true"
        :visible.sync="isForceOffLine"
        center
        style="text-align: center"
        title="强制下线记录"
        width="450px">
      <div style="text-align: center">
        <el-form
            ref="faultStartFormRef"
            :model="forceOffLineForm"
            label-position="right"
            label-width="130px"
            style="width: 100%;margin: auto"
        >
          <el-form-item label="制造编号" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input
                v-model="forceOffLineForm.workCode"
                :rows="1"
                placeholder="制造编号"
                style="height: 42px;width: 220px"
                readonly
                type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="单元号" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input
                v-model="forceOffLineForm.unitCode"
                :rows="1"
                readonly
                placeholder="单元号"
                style="height: 42px;width: 220px"
                type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="下线类型" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-select
                v-model="forceOffLineForm.type"
                placeholder="请选择下线类型"
                style="width:220px;"
                size="small">
              <el-option
                  v-for="item in forceOffTypeList"
                  :key="item"
                  :label="item"
                  :value="item"
                  size="mini"/>
            </el-select>
          </el-form-item>
          <el-form-item label="强制下线原因" prop="engineTypeValue" style="display: inline-block;width: 100%">
            <el-input
                v-model="forceOffLineForm.offLineTest"
                :rows="2"
                placeholder="请输入下线原因"
                style="height: 42px;width: 220px"
                type="textarea">
            </el-input>
          </el-form-item>
          <!--底部按钮-->
          <div style="text-align: center; margin-top: 20px">
            <el-button class="el-icon-check" type="primary" @click="forceOffLineSubmit()">确定</el-button>
            <el-button class="el-icon-close" style="margin-left: 50px" @click="isForceOffLine = false">关闭</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>

export default {
  data() {
    return {
      tableIndexValue: Math.random(),
      value: true,
      NullWorkValue: false,
      mesWritePalletVisible: false,
      TurnLineWorkValue: true,
      publication: {
        topic: '',
        qos: 0,
        payload: ''
      },
      options: [
        {
          value: 0,
          label: '在线'
        }, {
          value: 2,
          label: '屏蔽'
        }
      ],
      slogan: 'MES系统正在调试！！',
      visible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      isForceOffLine: false,
      isShowFaultStart: false,
      isShowFaultEnd: false,
      alarmListTagId: [''],
      TagIdList: new Map(),
      alarmList: [],
      alarmList_Alarm: [],
      alarmList_Error: [],
      alarmList_Warning: [],
      title: '合格放行',
      form1: {
        userName: '',
        userPassword: ''
      },
      form2: {
        pallet: 0
      },
      forceOffLineForm: {
        opName: '',
        workCode: '',
        unitCode: '',
        engineID: '',
        type: '',
        offLineTest: '' // 下线原因
      },
      forceOffTypeList: ['工件下线处理', '重新上线加工'],
      backWorkform: {
        remark: '', // 备注
        identifying: '', // 确认人
        discoverer: '', // 发现人
        faultCode: '', // 故障原因代码
        faultTxt: '', // 故障原因内容  用于其他选项
        faultList: [], // 故障列表
        faultType: '', // 故障类型
        backWorkType: '', // 返工类型
        faultTypeList: [
          {
            value: '1',
            label: '生产停机'
          },
          {
            value: '2',
            label: '质量停机'
          },
          {
            value: '3',
            label: '设备停机'
          },
          {
            value: '4',
            label: '物流停机'
          }
        ], // 故障类型列表
        backWorkTypeList: [
          {
            value: '返工站返工',
            label: '返工站返工'
          },
          {
            value: '本工位返工',
            label: '本工位返工'
          }
        ] // 返工类型列表
      },
      buttonShowList: [],
      faultStartForm: {
        startTime: '', // 开始时间
        discoverer: '' // 故障发现人
      },
      faultEndForm: {
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        handlinger: '', // 故障处理人
        stopTIme: '', // 停机时间
        stopCause: '', // 停机原因
        stopTimeStr: '' // 停机时间中文
      }
    }
  },
  mounted() {
    this.getStationStatus()
    this.getStationButton()
    this.getTagList()
  },
  methods: {
    tableRowClassName({ row }) {
      if (row.报警等级 === '错误') {
        return 'alarm_Alarm'
      } else if (row.报警等级 === '报警') {
        return 'alarm_Alarm'
      } else if (row.报警等级 === '警告') {
        return 'warning_Alarm'
      } else {
        return 'alarm_Default'
      }
    },
    getTagList() {
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      const Data = this.CreateData('11', 'MES_基本变量_原始数据_根据工位号查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          for (let i = 0; i < response.data.length; i++) {
            this.TagIdList.set(response.data[i].TagID, response.data[i])
          }
        }
      })
    },
    loginOut() {
      this.$store.commit('set_processList_table', [])
      this.$store.commit('set_materialList_table', [])
      this.$store.commit('set_pic', '')
      this.$store.commit('set_smile', '')
      this.$store.commit('set_tighteningPosition', [])
      this.$store.commit('set_greenBoltInformation', [])
      this.$store.commit('set_partAssemblyInformation', {})
      this.$store.commit('set_engineValue', {})
      this.$router.push('/')
    },
    solveAlarm(m_Value) {
      console.log('触发报警方法:', m_Value)
      const m_ValueList = m_Value.split('&')
      const tagId = m_ValueList[0]
      const tagValue = m_ValueList[1]
      const alarmContent = m_ValueList[2]
      const alarmType = m_ValueList[3]
      if (tagValue === '1') {
        if (this.alarmListTagId.indexOf(tagId) === -1) {
          const tagInfo = this.TagIdList.get(tagId)
          this.alarmListTagId.push(tagId)
          switch (alarmType) {
            case '报警':
              this.alarmList_Alarm.unshift({
                TagId: tagId,
                报警内容: tagInfo['DbName'] + '.' + tagInfo['变量类型'] + tagInfo['变量地址'] + tagInfo['变量其它'] + '【' + alarmContent + '】',
                报警等级: alarmType
              })
              break
            case '错误':
              this.alarmList_Error.unshift({
                TagId: tagId,
                报警内容: tagInfo['DbName'] + '.' + tagInfo['变量类型'] + tagInfo['变量地址'] + tagInfo['变量其它'] + '【' + alarmContent + '】',
                报警等级: alarmType
              })
              break
            case '警告':
              this.alarmList_Warning.unshift({
                TagId: tagId,
                报警内容: tagInfo['DbName'] + '.' + tagInfo['变量类型'] + tagInfo['变量地址'] + tagInfo['变量其它'] + '【' + alarmContent + '】',
                报警等级: alarmType
              })
              break
          }
          this.alarmList = []
          this.alarmList = [...this.alarmList_Error, ...this.alarmList_Alarm, ...this.alarmList_Warning]
        }
      } else {
        this.alarmListTagId = this.alarmListTagId.filter(item => item !== tagId)
        this.alarmList_Alarm = this.alarmList_Alarm.filter(res => {
          return res.TagId !== tagId
        })
        this.alarmList_Error = this.alarmList_Error.filter(res => {
          return res.TagId !== tagId
        })
        this.alarmList_Warning = this.alarmList_Warning.filter(res => {
          return res.TagId !== tagId
        })
        this.alarmList = []
        this.alarmList = [...this.alarmList_Error, ...this.alarmList_Alarm, ...this.alarmList_Warning]
      }
      this.tableIndexValue = Math.random()
    },
    showAlarmList() {
      this.dialogFormVisible2 = true
      this.tableIndexValue = Math.random()
    },
    // 故障停机提交
    faultStartSubmit() {
      if (!this.faultStartForm.discoverer) {
        this.$message({
          message: '故障发现人不能为空',
          type: 'error'
        })
        return false
      }
      var param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      param[1] = ['故障发现人', this.faultStartForm.discoverer]
      param[2] = ['操作人', this.$store.state.station.stationUserCount]
      param[3] = ['开始时间', this.faultStartForm.startTime]
      var Data = this.CreateData('12', 'MES_停机记录_开始', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            message: '故障停机提交成功',
            type: 'success'
          })
          // 查询更新后的功能按钮列表
          this.getStationButton()
          this.isShowFaultStart = false
        } else {
          this.$message({
            message: '故障停机提交失败',
            type: 'error'
          })
        }
      })
    },
    // 强制下线记录
    forceOffLineSubmit() {
      var param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      param[1] = ['操作者', this.$store.state.station.stationUserCount]
      param[2] = ['原因', this.forceOffLineForm.offLineTest]
      param[3] = ['工件编号', this.forceOffLineForm.engineID]
      param[4] = ['下线类型', this.forceOffLineForm.type]
      var Data = this.CreateData('12', 'MES_强制下线记录_增加', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.publication.topic = window.g.mqttPublishTopic
          this.publication.payload = 'WEB|skipWork|' + this.$store.state.station.stationName + '|' + 1
          const result = window.g.mqttClient.doPublish(this.publication)
          this.$message({
            message: '强制下线提交成功',
            type: 'success'
          })
          this.isForceOffLine = false
        } else {
          this.$message({
            message: '强制下线提交失败',
            type: 'error'
          })
        }
      })
    },
    // 故障结束提交
    faultEndSubmit() {
      var param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      param[1] = ['故障处理人', this.faultEndForm.handlinger]
      param[2] = ['结束时间', this.faultEndForm.endTime]
      param[3] = ['开始时间', this.faultEndForm.startTime]
      param[4] = ['停机时长', this.faultEndForm.stopTIme]
      param[5] = ['停机时长统计', this.faultEndForm.stopTimeStr]
      param[6] = ['停机原因', this.faultEndForm.stopCause]
      param[7] = ['停机类型', this.backWorkform.faultType]
      var Data = this.CreateData('12', 'MES_停机记录_结束', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            message: '停机结束提交成功',
            type: 'success'
          })
          // 查询更新后的功能按钮列表
          this.getStationButton()
          this.isShowFaultEnd = false
        } else {
          this.$message({
            message: '停机结束提交失败',
            type: 'error'
          })
        }
      })
    },
    // 故障停机弹窗
    faultStart() {
      this.isShowFaultStart = true
      this.faultStartForm.startTime = this.getNowFormatDate()
      this.faultStartForm.discoverer = ''
    },
    // 重新申请上线
    againPartLoad() {
      if (this.$store.state.station.statusValue[2].status == 0) {
        this.$message({
          type: 'warning',
          message: '请在工件到位后再进行此操作！'
        })
        return
      }
      this.$confirm(`请确定当前上线工位存在工件且未成功上线,并且确认生产计划是否一致`, '提示', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.publication.topic = window.g.mqttPublishTopic
        this.publication.payload = 'WEB|againPartLoad|' + this.$store.state.station.stationName + '|' + 1
        const result = window.g.mqttClient.doPublish(this.publication)
        if (result === true) {

        } else {
          this.$notify.error({
            title: '提示',
            message: '重新申请上线失败！',
            position: 'bottom-right',
            offset: 170
          })
        }
      })
    },
    // 跳过交互
    skipWork() {
      if (this.$store.state.station.statusValue[2].status == 0) {
        this.$message({
          type: 'warning',
          message: '请在允许工作后再进行此操作！'
        })
        return
      }
      this.$confirm(`是否跳过该工位MES与PLC的所有交互，此工件在该工位将不会记录任何数据`, '提示', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.publication.topic = window.g.mqttPublishTopic
        this.publication.payload = 'WEB|skipWork|' + this.$store.state.station.stationName + '|' + 1
        const result = window.g.mqttClient.doPublish(this.publication)
        if (result === true) {

        } else {
          this.$notify.error({
            title: '提示',
            message: '重新申请上线失败！',
            position: 'bottom-right',
            offset: 170
          })
        }
      })
    },
    // 强制下线
    forceOffLine() {
      if (this.$store.state.station.statusValue[2].status == 0) {
        this.$message({
          type: 'warning',
          message: '请在允许工作后再进行此操作！'
        })
        return
      }
      this.isForceOffLine = true
      this.forceOffLineForm.engineID = this.$store.state.station.engineValue.EngineID
      this.forceOffLineForm.unitCode = this.$store.state.station.engineValue.unidCode
      this.forceOffLineForm.workCode = this.$store.state.station.engineValue.workCode
      this.forceOffLineForm.type = ''
      this.forceOffLineForm.offLineTest = ''
    },
    // 将秒转为日 时 分 秒
    getSecondTurnDate(seconds) {
      let d = Math.floor(seconds / (3600 * 24))
      let h = Math.floor(seconds % (3600 * 24) / 3600)
      let m = Math.floor(seconds % 3600 / 60)
      let s = Math.floor(seconds % 60)

      d = d > 10 ? d : '0' + d
      h = h > 10 ? h : '0' + h
      m = m > 10 ? m : '0' + m
      s = s > 10 ? s : '0' + s

      d = parseInt(seconds / 60 / 60 / 24) // 计算天数
      h = parseInt(seconds / 60 / 60 % 24) // 计算小时
      m = parseInt(seconds / 60 % 60) // 计算分数
      s = parseInt(seconds % 60) // 计算当前秒数

      let timeStr = s + '秒'
      if (m !== 0) {
        timeStr = m + '分 ' + timeStr
      }
      if (h !== 0) {
        timeStr = h + '小时 ' + timeStr
      }
      if (d !== 0) {
        timeStr = d + '天 ' + timeStr
      }
      return timeStr
    },
    // 停机开始结束时间发生改变
    faultStartEndTimeChange() {
      console.log(6666)
      this.faultEndForm.stopTIme = (new Date(this.faultEndForm.endTime) - new Date(this.faultEndForm.startTime)) / 1000
      this.faultEndForm.stopTimeStr = this.getSecondTurnDate(this.faultEndForm.stopTIme)
    },
    // 停机结束弹窗
    faultEnd() {
      // 查询停机记录进行回写
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      const Data = this.CreateData('11', 'MES_停机记录_开始_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.faultEndForm.startTime = response.data[0].开始时间
          this.faultStartForm.discoverer = response.data[0].故障发现人
          // 将数据进行处理
          this.faultEndForm.endTime = this.getNowFormatDate()
          this.faultEndForm.handlinger = ''
          // 获取相差秒数
          console.log((new Date(this.faultEndForm.endTime) - new Date(response.data[0].开始时间)) / 1000)
          this.faultEndForm.stopTIme = (new Date(this.faultEndForm.endTime) - new Date(response.data[0].开始时间)) / 1000
          this.faultEndForm.stopTimeStr = this.getSecondTurnDate(this.faultEndForm.stopTIme)
          this.faultEndForm.stopCause = ''
          this.isShowFaultEnd = true
        }
      })
    },
    // 获取当前日期函数
    getNowFormatDate() {
      var date = new Date()
      // 年 getFullYear()：四位数字返回年份
      var year = date.getFullYear() // getFullYear()代替getYear()
      // 月 getMonth()：0 ~ 11
      var month = date.getMonth() + 1
      // 日 getDate()：(1 ~ 31)
      var day = date.getDate()
      // 时 getHours()：(0 ~ 23)
      var hour = date.getHours()
      // 分 getMinutes()： (0 ~ 59)
      var minute = date.getMinutes()
      // 秒 getSeconds()：(0 ~ 59)
      var second = date.getSeconds()
      var time = year + '-' + this.addZero(month) + '-' + this.addZero(day) + ' ' + this.addZero(hour) + ':' + this.addZero(minute) + ':' + this.addZero(second)
      return time
    },
    // 小于10的拼接上0字符串
    addZero(s) {
      return s < 10 ? ('0' + s) : s
    },
    // 不合格放行
    unqualifiedRelease() {
      this.publication.topic = window.g.mqttPublishTopic
      this.publication.payload = 'WEB|NgGO|' + this.$store.state.station.stationName + '|' + '1'
      const result = window.g.mqttClient.doPublish(this.publication)
      if (result === true) {
        this.$notify.success({
          title: '提示',
          message: '不合格放行成功！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      } else {
        this.$notify.error({
          title: '提示',
          message: '不合格放行失败！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      }
    },
    // mes复位
    mesReset() {
      this.publication.topic = window.g.mqttPublishTopic
      this.publication.payload = 'WEB|Reset|' + this.$store.state.station.stationName + '|' + '1'
      const result = window.g.mqttClient.doPublish(this.publication)
      if (result === true) {
        this.$notify.success({
          title: '提示',
          message: 'MES复位成功！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      } else {
        this.$notify.error({
          title: '提示',
          message: 'MES复位失败！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      }
    },
    // mes写入托盘号
    mesWritePallet() {
      this.mesWritePalletVisible = true
    },
    // 是否屏蔽MES
    changeStationStatus(status) {
      const str = status ? '0' : '2'
      this.publication.topic = window.g.mqttPublishTopic
      this.publication.payload = 'WEB|OnLineState|' + this.$store.state.station.stationName + '|' + str
      window.g.mqttClient.doPublish(this.publication)
    },
    // 空托盘放行
    changeStationStatusNullWork(status) {
      const str = !status ? '0' : '1'
      this.publication.topic = window.g.mqttPublishTopic
      this.publication.payload = 'WEB|NullWorkGo|' + this.$store.state.station.stationName + '|' + str
      window.g.mqttClient.doPublish(this.publication)
    },
    // MA150独有 转线工件上线
    changeTurnLineWork(status) {
      const str = status ? '0' : '1'
      this.publication.topic = window.g.mqttPublishTopic
      this.publication.payload = 'WEB|TurnLineWork|' + this.$store.state.station.stationName + '|' + str
      window.g.mqttClient.doPublish(this.publication)
    },
    getStationStatus() {
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      const Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询_在线状态', param)
      this.ExecDatabase(Data).then(response => {
        this.value = parseInt(response.data[0]['在线状态']) === 0
        console.log(this.value)
      })
    },
    getStationButton() {
      setTimeout(() => {
        this.buttonShowList = []
        const param = []
        param[0] = ['工位号', this.$store.state.station.stationName]
        const Data = this.CreateData('11', 'MES界面显示_功能按钮_查询', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.buttonShowList.push(response.data[i]['按钮ID'])
          }
          console.log(this.buttonShowList)
        })
      }, 500)
    },
    qualifiedRelease() {
      // console.log('合格放型')
      this.dialogFormVisible1 = true
    },
    cancel() {
      this.dialogFormVisible1 = false
    },
    confirm11() {
      if (this.form1.userName && this.form1.userPassword) {
        if (this.$store.state.station.stationUserCount === this.form1.userName) {
          this.publication.topic = window.g.mqttPublishTopic
          this.publication.payload = 'WEB|ConfirmOkGo|' + this.$store.state.station.stationName + '|' + '1'
          const result = window.g.mqttClient.doPublish(this.publication)
          if (result === true) {
            this.$notify.success({
              title: '提示',
              message: '合格放行成功！',
              position: 'bottom-right',
              duration: 2000,
              offset: 170
            })
          } else {
            this.$notify.error({
              title: '提示',
              message: '合格放行失败！',
              position: 'bottom-right',
              duration: 2000,
              offset: 170
            })
          }
        } else {
          this.$notify.error({
            title: '提示',
            message: '用户名错误！',
            position: 'bottom-right',
            duration: 2000,
            offset: 170
          })
        }
        this.dialogFormVisible1 = false
      } else {
        this.$notify.error({
          title: '提示',
          message: '用户名或密码为空！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      }
    },
    confirmWritePallet() {
      this.publication.topic = window.g.mqttPublishTopic
      this.publication.payload = 'WEB|WritePartPalletCode|' + this.$store.state.station.stationName + '|' + this.form2.pallet
      const result = window.g.mqttClient.doPublish(this.publication)
      if (result === true) {
        this.$notify.success({
          title: '提示',
          message: '发送申请写入托盘号成功！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      } else {
        this.$notify.error({
          title: '提示',
          message: '发送申请写入托盘号失败！',
          position: 'bottom-right',
          duration: 2000,
          offset: 170
        })
      }
    },
    cancelWritePallet() {
      this.mesWritePalletVisible = false
    }
  }
}
</script>

<style scoped>

::v-deep.el-table .alarm_Alarm {
  background: #ff0000 !important;
  color: #000 !important;
}

::v-deep.el-table .alarm_Default {
  background: #ffffff !important;
  color: #000 !important;
}

::v-deep.el-table .warning_Alarm {
  background: #ffad1b !important;
  color: #000 !important;
}

::v-deep.el-table th.el-table__cell > .cell {
  font-size: 22px;
  color: #2f2f2f;
}

.button {
  background-color: white;
  color: black;
  margin: 10px 0 0 0;
  border: 2px solid black;
  font-size: 29px;
  line-height: 0px;
  /*宽度原先290 无高度限制  字体大小29*/
  width: 290px;
  height: 50px;
}

.slogan {
  color: #000;
  background-color: red;
  font-size: 32px;
  font-weight: bolder;
  text-align: center;
  animation: alarm_bg 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.yellow-slogan {
  color: #000;
  background-color: #ffad1b;
  font-size: 32px;
  font-weight: bolder;
  text-align: center;
  animation: yellow-alarm_bg 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.slogan1 {
  color: #000;
  background-color: #ffffff;
  font-size: 32px;
  font-weight: bolder;
  text-align: center;
}

.el-switch {
  margin: 10px 0;
}

@keyframes alarm_bg {
  0% {
    color: #000;
    background-color: #ff0000;
  }
  100% {
    color: #000;
    background-color: #ffffff;
  }
}

@keyframes yellow-alarm_bg {
  0% {
    color: #000;
    background-color: rgba(255, 135, 0, 0.89);
  }
  100% {
    color: #000;
    background-color: #ffffff;
  }
}

@keyframes example {
  0% {
    left: 0px;
    top: 0px;
  }

  50% {
    left: 1250px;
    top: 0px;
  }

  100% {
    left: 0px;
    top: 0px;
  }
}

::v-deep.el-table th.el-table__cell > .cell {
  font-size: 20px;
  color: #2f2f2f;
}

::v-deep.el-table td.el-table__cell div {
  font-size: 16px !important;
}

/*多选框选样式*/
::v-deep .el-checkbox__input.is-indeterminate .el-checkbox__inner::before {
  top: 8px;
}

::v-deep .el-checkbox__inner {
  width: 20px;
  height: 20px;
}

::v-deep .el-checkbox__inner::after {
  left: 7px;
  top: 4px;
}

::v-deep .el-table--scrollable-y .el-table__body-wrapper {
  max-height: 240px !important;
}
</style>
</style>
