<!-- 应用升级任务列表 -->
<template>
  <div class="app-container applyUpgradesQuest">
    <div class="page-container applyUpgradesQuestPage">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="deviceCode">
            <el-input
              maxLength="30"
              v-model="queryParams.deviceCode"
              placeholder="设备码"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="batchNumber">
            <el-input
              maxLength="30"
              v-model="queryParams.batchNumber"
              placeholder="批次号"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="appVersion">
            <el-input
              maxLength="30"
              v-model="queryParams.appVersion"
              placeholder="app版本"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="status">
            <el-select v-model="queryParams.status" placeholder="任务状态" clearable style="width:200px;">
              <el-option
                v-for="dict in optionList"
                :key="dict.code"
                :label="dict.description"
                :value="dict.code"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="terminalType">
            <el-select v-model="queryParams.terminalType" placeholder="app类型" style="width: 200px">
              <el-option label="化学品终端" value="aio_chemical"></el-option>
              <el-option label="电子信息牌" value="aio_infobord"></el-option>
              <el-option label="学习考试一体" value="aio_exam"></el-option>
              <el-option label="化学品终端升级APP" value="aio_chemical_update"></el-option>
              <el-option label="电子信息牌升级APP" value="aio_infobord_update"></el-option>
              <el-option label="学习考试一体升级APP" value="aio_exam_update"></el-option>
            </el-select>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="app名称" prop="appName"  show-overflow-tooltip/>
          <el-table-column label="app版本" prop="appVersion" width="80" show-overflow-tooltip/>
          <el-table-column label="设备码" prop="deviceCode" width="170" show-overflow-tooltip/>
          <el-table-column label="设备名称" prop="deviceName" width="170" show-overflow-tooltip/>
          <el-table-column label="批次号" prop="batchNumber" width="100" show-overflow-tooltip/>
          <el-table-column label="优先级" prop="priority" width="60" show-overflow-tooltip/>
          <el-table-column label="包名" prop="startLaunchPackage" width="120" show-overflow-tooltip/>
          <el-table-column label="状态" prop="status" width="90" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.status=='failed'?'失败':(scope.row.status=='downloaded'?'下载成功':(scope.row.status=='success'?'升级成功':(scope.row.status=='pending'?'待执行':'')))}}
            </template>
          </el-table-column>
          <el-table-column label="开始时间" prop="startTime" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.startTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" prop="endTime" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.endTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" prop="createTime" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
  import {
    terminalUpgradeWebTaskList,
    terminalUpgradeWebTaskStatus,
  } from "@/api/iotDevice/index";
  export default {
    name: 'index',
    data () {
      return {
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          status:"",
          deviceCode :"",
          batchNumber :"",
          appVersion :"",
          terminalType :"",
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
      }
    },
    created () {

    },
    mounted () {
      this.terminalUpgradeWebTaskStatus();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          status:"",
          deviceCode :"",
          batchNumber :"",
          appVersion :"",
          terminalType :"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        terminalUpgradeWebTaskList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      terminalUpgradeWebTaskStatus(){
        terminalUpgradeWebTaskStatus({}).then(response => {
          this.$set(this,'optionList',response.data);
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .applyUpgradesQuest{
    .applyUpgradesQuestPage{

    }
  }
</style>
