<template>
  <div>
    <div class="my-title">历史记录</div>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
      <el-form-item label="上报时间">
        <el-date-picker
          v-model="dataForm.date"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="search()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center">
      </el-table-column>
      <el-table-column
        prop="deviceName"
        header-align="center"
        align="center"
        min-width="120"
        label="设备编号">
      </el-table-column>
      <el-table-column
        prop="deviceTimeStr"
        header-align="center"
        align="center"
        min-width="160"
        :show-overflow-tooltip="true"
        label="上报时间">
      </el-table-column>
      <el-table-column
        prop="serverTimeStr"
        header-align="center"
        align="center"
        min-width="160"
        :show-overflow-tooltip="true"
        label="系统接收时间">
      </el-table-column>
      <el-table-column
        prop="version"
        header-align="center"
        align="center"
        min-width="100"
        label="协议版本">
      </el-table-column>
      <el-table-column
        prop="ack"
        header-align="center"
        align="center"
        min-width="100"
        label="是否需要响应">
        <template slot-scope="scope">
          <span>{{ scope.row.ack === '0'?'否':'是' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="longitude"
        header-align="center"
        align="center"
        min-width="100"
        label="纬度">
      </el-table-column>
      <el-table-column
        prop="latitude"
        header-align="center"
        align="center"
        min-width="100"
        :show-overflow-tooltip="true"
        label="经度">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="150"
        label="NC软件版本">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NCVersion'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="NC名称">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NCInfo'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="第一轴下一指令">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos1'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="第二轴下一指令">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos2'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="第三轴下一指令">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos3'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="第四轴下一指令">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos4'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="第五轴下一指令">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos5'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="第六轴下一指令">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos6'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="自动运行时间">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='RunTime'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="自动启动时间">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='StartTime'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="循环时间">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CycleTime'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="上电时间">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='KeepAliveTime'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="系统日期">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='SystemDate'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="系统时间">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='SystemTime'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        :show-overflow-tooltip="true"
        label="主程序名">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MainProName'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="当前运行程序号">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CuRunProNum'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="120"
        :show-overflow-tooltip="true"
        label="当前运行程序内容">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CuRunProContent'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="120"
        :show-overflow-tooltip="true"
        label="设备报警">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='AlarmMsg'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        :show-overflow-tooltip="true"
        label="进给设定转速FA">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='FeedSetSpeed'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        :show-overflow-tooltip="true"
        label="进给实际速度FE">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='FeedActualSpeed'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="主轴设定转速">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='SpindleSetSpeed'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="主轴实际转速">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='SpindleActualSpeed'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="主轴倍率">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='SpindleRate'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="进给倍率">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='FeedRate'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="快速移动倍率">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MoveRate'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="主轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='SpindleLoad'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="第一轴伺服轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ServoLoad1'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="第二轴伺服轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ServoLoad2'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="第三轴伺服轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ServoLoad3'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="第四轴伺服轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ServoLoad4'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="90"
        label="第五轴伺服轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ServoLoad5'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第六轴伺服轴负载">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ServoLoad6'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="设备运行模式">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='RunMode'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="设备运行状态">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='RunStatus'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="当前刀具号">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CulToolNum'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="设备急停状态">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='EmergencyStop'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="G代码状态">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='GCodeStatus'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="累计生产件数">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='ProductCounts'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第一轴机械坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MacPos1'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第二轴机械坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MacPos2'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第三轴机械坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MacPos3'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第四轴机械坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MacPos4'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第五轴机械坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MacPos5'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第六轴机械坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='MacPos6'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第一轴工件坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='WorkPos1'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第二轴工件坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='WorkPos2'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第三轴工件坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='WorkPos3'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第四轴工件坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='WorkPos4'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第五轴工件坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='WorkPos5'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第六轴工件坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='WorkPos6'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第一轴当前(相对)坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CurrentPos1'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第二轴当前(相对)坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CurrentPos2'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第三轴当前(相对)坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CurrentPos3'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第四轴当前(相对)坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CurrentPos4'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第五轴当前(相对)坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CurrentPos5'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第六轴当前(相对)坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='CurrentPos6'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第一轴剩余坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='DistancePos1'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第二轴剩余坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='DistancePos2'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第三轴剩余坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='DistancePos3'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第四轴剩余坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='DistancePos4'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第五轴剩余坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='DistancePos5'">{{ item.value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="100"
        label="第六轴剩余坐标">
        <template slot-scope="scope">
          <span v-for="item in scope.row.points" v-if="item.name==='DistancePos6'">{{ item.value }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <span slot="footer" class="dialog-footer">
      <el-button @click="onChose">返回</el-button>
    </span>
  </div>
</template>

<script>
export default {
  name: 'device-history',
  components: {
  },
  data () {
    return {
      code: 0,
      dataForm: {},
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: []
    }
  },
  methods: {
    async init (code) {
      this.code = code
      this.search()
    },
    onChose () {
      this.$emit('onChose')
    },
    // 查询
    search () {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.addOrUpdateVisible = false
      this.$http({
        url: this.$http.adornUrl('/iot-platform/data-gateway/history'),
        method: 'get',
        params: this.$http.adornParams({
          'current': this.pageIndex,
          'size': this.pageSize,
          'code': this.code,
          'timeStart': this.dataForm.date ? this.dataForm.date[0] : null,
          'timeEnd': this.dataForm.date ? this.dataForm.date[1] : null
        })
      }).then(({data}) => {
        if (data && data.code === '200') {
          this.dataList = data.data.records
          this.totalPage = Number(data.data.total)
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 详情
    detailHandle (row) {
      // todo
    }
  }
}
</script>

<style scoped>

</style>
