<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">班次类型：</span>
        <el-select v-model="dataTypeValue" placeholder="班次类型" size="small" style="width:150px">
          <el-option
            label="白班"
            value="1"/>
          <el-option
            label="夜班"
            value="2"/>
        </el-select>
        <span style="margin-left: 10px">日志描述：</span>
        <span style="margin-left: 10px">时间：</span>
        <el-date-picker
          :clearable="false"
          v-model="dateTime"
          size="small"
          type="date"
          align="center"
          style="width: 240px;"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
        />
        <el-button
          type="primary"
          plain
          size="small"
          icon="el-icon-search"
          style="margin-left: 5px"
          @click="searchTable()">查询
        </el-button>
        <el-button type="distribution" icon="el-icon-circle-plus-outline" size="small" @click="addTo">修改</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        :expand-row-keys="expandsDetail"
        :row-key="getRowKeys"
        highlight-current-row
        border
        size="mini"
        height="740"
        center
        style="width: 100%"
        @expand-change="selectPlan">
        <!--<el-table-column width="40" label="序号" type="index" align="center"/>-->
        <el-table-column align="center" type="expand" label="" fixed width="35">
          <template slot-scope="scope">
            <div style="display: flex">
              <div style="margin: 5px 10px;width: 1600px;z-index: 99;">
                <el-table
                  :data="passTableData"
                  :header-cell-style="{ background: '#e5e7f8', color: '#606266' }"
                  element-loading-text="数据加载中"
                  element-loading-spinner="el-icon-loading"
                  element-loading-background="rgba(0, 0, 0, 0.2)"
                  class="main"
                  tooltip-effect="dark"
                  style="width: 100%"
                  max-height="400px"
                  border
                  size="mini">
                  <el-table-column width="40" label="序号" type="index" align="center"/>
                  <el-table-column align="center" label="订单号" width="130">
                    <template slot-scope="scope">
                      {{ scope.row.订单号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" width="400" label="总成条码">
                    <template slot-scope="scope">
                      {{ scope.row.发动机号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" width="100" label="机型">
                    <template slot-scope="scope">
                      {{ scope.row.发动机型号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" width="100" label="操作者工号">
                    <template slot-scope="scope">
                      {{ scope.row.操作者工号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="到达时间">
                    <template slot-scope="scope">
                      {{ scope.row.到达时间 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="离开时间">
                    <template slot-scope="scope">
                      {{ scope.row.离开时间 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="在线时间(秒)">
                    <template slot-scope="scope">
                      {{ scope.row.在线时间 }}
                    </template>
                  </el-table-column>
                  <!--<el-table-column align="center" label="操作">-->
                  <!--  <template slot-scope="scope">-->
                  <!--    <el-button size="mini" type="text" icon="el-icon-success" @click="printMqttShow(scope.row)">打印条码</el-button>-->
                  <!--  </template>-->
                  <!--</el-table-column>-->
                </el-table>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="工位号" width="120" align="center">
          <template slot-scope="scope">
            {{ scope.row.工位号 }}
          </template>
        </el-table-column>
        <el-table-column label="日期" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.日期 }}
          </template>
        </el-table-column>
        <el-table-column label="总时间" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.总时间 }}
          </template>
        </el-table-column>
        <el-table-column label="早会" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.早会 }}
          </template>
        </el-table-column>
        <el-table-column label="间休" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.间休 }}
          </template>
        </el-table-column>
        <el-table-column label="午餐" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.午餐 }}
          </template>
        </el-table-column>
        <el-table-column label="晚休" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.晚休 }}
          </template>
        </el-table-column>
        <el-table-column label="晚餐" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.晚餐 }}
          </template>
        </el-table-column>
        <el-table-column label="负荷时间" width="90" align="center">
          <template slot-scope="scope">
            {{ scope.row.负荷时间 }}
          </template>
        </el-table-column>
        <el-table-column label="生产" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.生产 }}
          </template>
        </el-table-column>
        <el-table-column label="质量" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.质量 }}
          </template>
        </el-table-column>
        <el-table-column label="设备" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.设备 }}
          </template>
        </el-table-column>
        <el-table-column label="物流" width="70" align="center">
          <template slot-scope="scope">
            {{ scope.row.物流 }}
          </template>
        </el-table-column>
        <el-table-column label="开动时间" width="90" align="center">
          <template slot-scope="scope">
            {{ scope.row.开动时间 }}
          </template>
        </el-table-column>
        <el-table-column label="时间利用率" width="100" align="center">
          <template slot-scope="scope">
            {{ scope.row.时间利用率 }}
          </template>
        </el-table-column>
        <el-table-column label="设计节拍" align="center">
          <template slot-scope="scope">
            {{ scope.row.设计节拍 }}
          </template>
        </el-table-column>
        <el-table-column label="实际节拍" align="center">
          <template slot-scope="scope">
            {{ scope.row.实际节拍 }}
          </template>
        </el-table-column>
        <el-table-column label="产量" align="center">
          <template slot-scope="scope">
            {{ scope.row.产量 }}
          </template>
        </el-table-column>
        <el-table-column label="性能利用率" width="100" align="center">
          <template slot-scope="scope">
            {{ scope.row.性能利用率 }}
          </template>
        </el-table-column>
        <el-table-column label="合格数" align="center">
          <template slot-scope="scope">
            {{ scope.row.合格数 }}
          </template>
        </el-table-column>
        <el-table-column label="不合格数" align="center">
          <template slot-scope="scope">
            {{ scope.row.不合格数 }}
          </template>
        </el-table-column>
        <el-table-column label="良品率" align="center">
          <template slot-scope="scope">
            {{ scope.row.良品率 }}
          </template>
        </el-table-column>
        <el-table-column label="OEE" align="center">
          <template slot-scope="scope">
            {{ scope.row.OEE }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
      :visible.sync="dialogFormVisible"
      title="计划停机时间修改"
      center
      style="min-height: 200px;"
      width="400px">
      <el-form ref="form1" :model="planStopTimeFrom" label-position="right" label-width="110px">
        <el-form-item label="总时间:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.总时间" :min="0" label="总时间"/>
        </el-form-item>
        <el-form-item label="早会:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.早会" :min="0" label="早会"/>
        </el-form-item>
        <el-form-item label="间休:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.间休" :min="0" label="间休"/>
        </el-form-item>
        <el-form-item label="午餐:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.午餐" :min="0" label="午餐"/>
        </el-form-item>
        <el-form-item label="晚休:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.晚休" :min="0" label="晚休"/>
        </el-form-item>
        <el-form-item label="晚餐:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.晚餐" :min="0" label="晚餐"/>
        </el-form-item>
        <el-form-item label="5S节拍:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.节拍5S" :min="0" label="5S节拍"/>
        </el-form-item>
        <el-form-item label="6S节拍:" prop="number" style="display: inline-block">
          <el-input-number v-model="planStopTimeFrom.节拍6S" :min="0" label="6S节拍"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" size="small" @click="submitUpdate()">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      expands: [],
      expandsDetail: [],
      dataType: [], // 日志类型数组
      dataTypeValue: '1', // 班次类型
      valueType: [],
      valueTypeValue: '',
      alarmType: [],
      alarmTypeValue: '',
      dateTime: '', // 时间
      passTableData: [],
      dialogFormVisible: false,
      planStopTimeFrom: {}
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new Date() // 修改数据date
    year = new Date().getFullYear()
    month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
    day = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
    audiTime = year + '-' + month + '-' + day
    console.log(audiTime, 'audiTime')
    this.dateTime = audiTime
    this.searchTable()
  },
  methods: {
    // 控制展开列
    selectPlan(row, expandedRows) {
      if (expandedRows.length) {
        this.expandsDetail = []
        if (row) {
          this.passTableData = []
          var param = []
          param[0] = ['工位号', row.工位号]
          param[1] = ['日期', row.日期]
          var Data = this.CreateData('11', '测量数据发动机在线状态_工位数据_日期_查询', param)
          this.ExecDatabase(Data).then(response => {
            console.log(response.data)
            if (response.data.length !== 0) {
              this.passTableData = response.data
            }
            this.expandsDetail.push(row.工位号)
          })
        }
      } else {
        this.expandsDetail = []
      }
    },
    // 获取展开列的工单号
    getRowKeys(row) {
      return row.工位号
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      param[0] = ['date', this.dateTime]
      param[1] = ['班次代码', this.dataTypeValue]
      var Data = this.CreateData('11', 'MES_OEE计算_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.loading = false
        if (response.data.length !== 0) {
          this.tableData = response.data
        }
      })
    },
    addTo() {
      this.dialogFormVisible = true
      // 将当前数据查询到表单中
      this.planStopTimeFrom = { ...this.tableData[1] }
    },
    // 提交修改计划停机时间
    submitUpdate() {
      var param = []
      param[0] = ['日期', this.dateTime]
      param[1] = ['班次代码', this.dataTypeValue]
      param[2] = ['总时间', this.planStopTimeFrom.总时间]
      param[3] = ['早会 ', this.planStopTimeFrom.早会]
      param[4] = ['间休 ', this.planStopTimeFrom.间休]
      param[5] = ['午餐 ', this.planStopTimeFrom.午餐]
      param[6] = ['晚休 ', this.planStopTimeFrom.晚休]
      param[7] = ['晚餐 ', this.planStopTimeFrom.晚餐]
      param[8] = ['节拍5S ', this.planStopTimeFrom.节拍5S]
      param[9] = ['节拍6S ', this.planStopTimeFrom.节拍6S]
      var Data = this.CreateData('12', '北汽福田_计划停机时间表_修改', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result == 1) {
          this.$message.success('修改成功！')
          this.searchTable()
          this.dialogFormVisible = false
        } else {
          this.$message.error('修改失败！')
        }
      })
    }
  }
}
</script>

<style scoped>
.topDiv {
  margin-bottom: 10px;
}
</style>
