<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="90px" size="small">

      <el-form-item label="选择APP" prop="sysApkName">
        <el-input
            v-model="queryParams.sysApkName"
            clearable
            placeholder="请输入APP"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-input
            v-model="queryParams.version"
            clearable
            placeholder="请输入版本号"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['system:config:add']"
            icon="el-icon-plus"
            plain
            size="mini"
            type="primary"
            @click="handleAdd"
        >新建
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            v-hasPermi="['system:config:delete']"
            :disabled="multiple"
            icon="el-icon-plus"
            plain
            size="mini"
            type="info"
            @click="handleDelete"
        >批量删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="INFOList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="APP" prop="APP"/>
      <el-table-column align="center" label="最新版本号" prop="version"/>
      <el-table-column align="center" label="文件类型" prop="sysApk"/>
      <el-table-column align="center" label="公开时间" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="请求次数" prop="sysApk"/>
      <el-table-column align="center" label="注册时间" prop="sysApk"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="250">
        <template slot-scope="scope">
          <el-button
              v-hasPermi="['system:config:dowmload']"
              icon="el-icon-edit"
              size="mini"
              type="text"
              @click="handleDown(scope.row)"
          >下架
          </el-button>
          <el-button
              v-hasPermi="['system:config:edit']"
              icon="el-icon-edit"
              size="mini"
              type="text"
              @click="handleEdit(scope.row)"
          >编辑
          </el-button>
          <el-button
              v-hasPermi="['system:config:delete']"
              icon="el-icon-delete"
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
    />
  </div>
</template>
<script>
// import { listINFO, getINFO, delINFO, addINFO, updateINFO } from "@/api/deploy/INFO";
export default {
  name: 'ChannelManagement',
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安装包管理（新）表格数据
      INFOList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysApkName: null,
        version: null
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询安装包管理（新）列表 */
    getList() {
      this.loading = false
      // listINFO(this.queryParams).then(response => {
      //   this.INFOList = response.rows
      //   this.total = response.total
      //   this.loading = false
      // })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.create_time = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: 'install/add',
        params: {
          type: 'add',
          activeTabs: this.activeTabs
        }
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const configIds = row.id || this.ids
      this.$modal.confirm('是否确认删除编号为"' + configIds + '"的数据项？').then(function() {
        return delConfig(configIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 修改按钮操作 */
    handleEdit(row) {
      this.reset()
      const configId = row.id || this.ids
      getConfig(configId).then(response => {
        this.$router.push({
          path: 'install/add',
          params: {
            type: 'edit',
            activeTabs: this.activeTabs
          }
        })
      })
    },
    /** 下架操作 **/
    handleDown() {
    }

  }
}
</script>
