<!--应用升级-->
<template>
  <div class="app-container applyUpgrades">
    <div class="page-container applyUpgradesPage">
      <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="name" label-width="90px">
            <el-input
              maxLength="30"
              v-model="queryParams.name"
              placeholder="请输入设备号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="type">
            <el-select v-model="queryParams.type" clearable placeholder="请选择设备类型" style="width: 200px">
              <el-option
                v-for="item in optionList"
                :key="item.type"
                :label="item.name"
                :value="item.type">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-select v-model="queryParams.state" clearable placeholder="请选择状态" style="width: 200px">
              <el-option label="启用" :value="true"></el-option>
              <el-option label="禁用" :value="false"></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>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="handleClick()"
          >批量升级</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="tableList" ref="multipleTable">
          <el-table-column label="设备号" align="center" prop="deviceNum" show-overflow-tooltip width="180"/>
          <el-table-column label="设备类型" align="center" prop="type" show-overflow-tooltip width="180">
            <template slot-scope="scope">
              <p v-for="item in optionList" v-if="item.type == scope.row.type">{{item.name}}</p>
            </template>
          </el-table-column>
          <el-table-column label="应用名" align="center" prop="name" show-overflow-tooltip/>
          <el-table-column label="原始版本" align="center" prop="origVersion" show-overflow-tooltip width="100"/>
          <el-table-column label="升级版本" align="center" prop="upgradedVersion" show-overflow-tooltip width="120"/>
          <el-table-column label="状态" align="center" prop="state" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              {{scope.row.state?'成功':'失败'}}
            </template>
          </el-table-column>
          <el-table-column label="升级时间" align="center" prop="createTime" show-overflow-tooltip width="180">
            <template slot-scope="scope">
              {{parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}")}}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" prop="deptName" width="200">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p" v-if="!scope.row.state" @click="tableButton(1,scope.row)">重试</p>
                <p class="table-button-p" @click="tableButton(2,scope.row)">修改</p>
                <p class="table-button-null"></p>
              </div>
            </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 { appUpgradeList,appInfoAdd,appInfoType } from "@/api/serviceCenter/index";
  export default {
    name: 'applyUpgrades',
    data(){
      return{
        loading:false,
        optionList:[],
        queryParams:{
          page:1,
          pageSize:20,
          name:"",
          type:"",
        },
        tableList:[],
        total:0,
      }
    },
    created(){

    },
    mounted(){
      this.getList();
      this.appInfoType();
    },
    methods:{
      //获取设备类型
      appInfoType(){
        appInfoType().then(response => {
          this.$set(this,'optionList',response.data);
        });
      },
      //新增
      handleClick(){

      },
      //查询
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          name:"",
          type:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        appUpgradeList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'tableList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){

      },
    },
  }
</script>

<style scoped lang="scss">
  .applyUpgrades{
    .applyUpgradesPage{

    }
  }
</style>
