<template>
  <div class="mod-config">
    <el-form
      style="display: flex; align-items: center; justify-content: right;"
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-select
          size="small"
          v-model="dataForm.vehicleId"
          filterable
          placeholder="车辆名称"
        >
          <el-option
            v-for="item in options2"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          size="small"
          v-model="dataForm.time"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      :stripe="true"
      :header-cell-style="{background:'#eef1f6',color:'#606266',height: '56px'}"
      v-loading="dataListLoading"
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        label="序号"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="taskCode"
        label="任务编码"
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="发起时间"
      >
        <template slot-scope="scope">
          {{ scope.row.createTime ? scope.row.createTime.replace('T', ' ') : '' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="taskSource"
        label="任务来源"
      >
      </el-table-column>
      <el-table-column
        prop="status"
        label="任务状态"
      >
      <template slot-scope="scope">
        {{ scope.row.status >= 0 ? statusList[scope.row.status] : '' }}
      </template>
      </el-table-column>
      <el-table-column
        prop="taskType"
        label="任务类型"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.taskType === 0
              ? "缓存到窑炉加工"
              : scope.row.taskType === 1
              ? "出炉到缓存"
              : scope.row.taskType === 2
              ? "缓存出库"
              : "入库缓存"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="startPosition"
        label="开始位置"
      >
      </el-table-column>
      <el-table-column
        prop="targetPosition"
        label="目标位置"
      >
      </el-table-column>
      <el-table-column
        prop="vehicleName"
        label="车辆名称"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="80"
        label="能耗情况">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="eleHandle(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="80"
        label="订单详情"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="LocationBtn(scope.row.id)"
            >订单详情</el-button
          >
        </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>
  </div>
</template>

<script>
// 任务状态列表
const statusList = {
  0: '等待执行',
  1: '执行中',
  2: '执行完成',
  3: '追加后完成'
}

export default {
  data () {
    return {
      dataForm: {
        vehicleId: '',
        time: []
      },
      dataList: [],
      options2: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      orderDetailVisible: false,
      statusList
    }
  },
  created () {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      console.log(this.dataForm.time)
      this.$http({
        url: this.$http.adornUrl('/taskHis/taskHis'),
        method: 'post',
        data: this.$http.adornData({
          current: this.pageIndex,
          size: this.pageSize,
          vehicleId: this.dataForm.vehicleId,
          startTime:
            this.dataForm.time && this.dataForm.time.length > 0
              ? this.dataForm.time[0]
              : '',
          endTime:
            this.dataForm.time && this.dataForm.time.length > 0
              ? this.dataForm.time[1]
              : ''
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.data.records
          this.totalPage = 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()
    },
    LocationBtn (id) {
      this.$router.push({ name: 'report-task-history-detail', query: { id } })
    },
    eleHandle (taskId) {
      this.$router.push({
        name: 'report-task-ele',
        query: { taskId }
      })
    }
  }
}
</script>
