<!--应用列表-->
<template>
  <div class="app-container applyList">
    <div class="page-container applyListPage">
      <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="appName" label-width="90px">
            <el-input
              maxLength="30"
              v-model="queryParams.appName"
              placeholder="请输入应用名"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="terminalType">
            <el-select v-model="queryParams.terminalType" placeholder="请选择类型" 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>
          <p class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
          >新增</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="appName" show-overflow-tooltip/>
          <el-table-column label="类型" align="center" prop="terminalType" show-overflow-tooltip width="200">
            <template slot-scope="scope">
              {{scope.row.terminalType=='aio_chemical'?'化学品终端':(
              scope.row.terminalType=='aio_infobord'?'电子信息牌':(
              scope.row.terminalType=='aio_exam'?'学习考试一体':(
              scope.row.terminalType=='aio_chemical_update'?'化学品终端升级APP':(
              scope.row.terminalType=='aio_infobord_update'?'电子信息牌升级APP':(
              scope.row.terminalType=='aio_exam_update'?'学习考试一体升级APP':scope.row.terminalType)))))}}
            </template>
          </el-table-column>
          <el-table-column label="描述" align="center" prop="description" show-overflow-tooltip width="600"/>
          <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="140">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(3,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>
    <el-dialog :title="dialogForm.appId?'编辑':'新增'" class="applyList-dialog-box" :visible.sync="dialogType" v-if="dialogType"
               width="560px" append-to-body :close-on-click-modal="false">
      <div class="applyList-dialog-min-box scrollbar-box">
        <el-form  v-loading="loading" :rules="dialogRules" :model="dialogForm" ref="dialogForm">
          <el-form-item label="应用名称" prop="appName" label-width="90px">
            <el-input
              v-model="dialogForm.appName"
              maxLength="20"
              placeholder="请输入应用名称"
              style="width: 360px"
            />
          </el-form-item>
          <el-form-item label="app包名" prop="startLaunchPackage" label-width="90px">
            <el-input
              v-model="dialogForm.startLaunchPackage"
              maxLength="30"
              placeholder="请输入包名"
              style="width: 360px"
            />
          </el-form-item>
          <el-form-item label="类型" prop="terminalType" style="display: block" label-width="90px">
            <el-select v-model="dialogForm.terminalType" placeholder="请选择类型" style="width: 360px">
              <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>
          <el-form-item label="描述" prop="description" label-width="90px">
            <el-input
              resize="none"
              type="textarea"
              v-model="dialogForm.description"
              maxLength="100"
              placeholder="请输入描述"
              style="width: 360px"
              show-word-limit
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogCancel">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    terminalAppList,
    terminalAppDelete,
    terminalAppAdd,
    terminalAppUpdate,
  } from "@/api/iotDevice/index";
  export default {
    name: 'applyList',
    data(){
      return{
        loading:false,
        queryParams:{
          page:1,
          pageSize:20,
          appName:"",
          terminalType:"",
        },
        tableList:[],
        total:0,
        dialogType:false,
        dialogForm:{
          appName:"",
          startLaunchPackage:"",
          terminalType:"",
          description:"",
        },
        dialogRules:{
          appName: [
            { required: true, message: "请输入应用名称", trigger: "blur" }
          ],
          startLaunchPackage: [
            { required: true, message: "请输入包名", trigger: "blur" }
          ],
          terminalType: [
            { required: true, message: "请选择类型", trigger: "blur" },
          ],
        },
      }
    },
    created(){

    },
    mounted(){
      this.getList();
    },
    methods:{
      //提交按钮
      dialogSubmit(){
        this.$refs["dialogForm"].validate(valid => {
          if (valid) {
            if(this.dialogForm.appId){
              terminalAppUpdate(this.dialogForm).then( response => {
                this.msgSuccess(response.message);
                this.$set(this,'dialogType',false);
                this.resetQuery();
              });
            }else{
              terminalAppAdd(this.dialogForm).then( response => {
                this.msgSuccess(response.message);
                this.$set(this,'dialogType',false);
                this.resetQuery();
              });
            }
          }
        })
      },
      //关闭按钮
      dialogCancel(){
        this.$set(this,'dialogType',false);
      },
      //查询
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          appName:"",
          terminalType:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        terminalAppList(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){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'dialogForm',{
            appName:"",
            startLaunchPackage:"",
            terminalType:"",
            description:"",
          });
          this.$set(this,'dialogType',true);
        }else if(type == 2){
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'dialogForm',{
            appId:obj.id,
            appName:obj.appName,
            startLaunchPackage:obj.startLaunchPackage,
            terminalType:obj.terminalType,
            description:obj.description,
          });
          this.$set(this,'dialogType',true);
        }else if(type == 3){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            terminalAppDelete({appId:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }
      },
    },
  }
</script>

<style scoped lang="scss">
  .applyList{
    .applyListPage{
      flex: 1;
    }
  }
</style>

<style lang="scss">
  .applyList-dialog-box{
    .text-box{
      width:360px;
      display: flex;
      p:nth-child(1){
        width:200px;
        display:block;
        overflow:hidden;
        text-overflow:ellipsis;
        white-space:nowrap;
      }
      p:nth-child(2){
        width:100px;
        text-align: center;
      }
      p:nth-child(3){
        width:60px;
        text-align: right;
      }
    }
    .applyList-dialog-min-box{
      height:500px;
    }
    .uploader-drop{
      width:500px;
      .el-icon-upload{
        color:#0183FA;
        display: block;
        font-size:78px;
        width:78px;
        height:78px;
        margin:0 auto;
      }
      .el-upload__text{
        width:210px;
        margin:0 auto;
      }
      .uploader-btn{
        border:none;
        color:#0183FA;
      }
    }
    .uploader-files{
      width:360px;
    }
    .up-data-p{
      width:80px;
      text-align: center;
      background-color:#0183fa;
      cursor:pointer;
      border-radius:4px;
      color:#fff;
      margin-top:2px;
    }
  }
  .confirmBatchButton{
    background-color: #0183FA !important;
    border:1px solid #0183FA !important;
    color: #ffffff !important;
    font-size:14px;
  }
  .confirmBatchButton:hover{
    background-color: #409EFF !important;
    border:1px solid #409EFF !important;
    color:#ffffff !important;
  }
</style>
