<template>
  <div class="app-container">
    <el-tabs v-model="activeTabs" type="card" @tab-click="handleClickTabs">
      <el-tab-pane
          v-for="item in packTabs"
          :key="item.name"
          :label="item.title"
          :name="item.name"
      >
      </el-tab-pane>
    </el-tabs>
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="90px" size="small">
      <el-form-item label="上传类型" prop="uploadingType">
        <el-select v-model="queryParams.uploadingType" clearable placeholder="请选择上传类型">
          <el-option
              v-for="dict in dict.type.sys_apk_uploading_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="安装包名称" prop="sysApkName">
        <el-input
            v-model="queryParams.sysApkName"
            clearable
            placeholder="请输入安装包名称"
            @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 label="安装包类型" prop="sysType">
        <el-select v-model="queryParams.sysType" clearable placeholder="请选择安装包类型">
          <el-option
              v-for="dict in dict.type.sys_apk_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上传状态" prop="uploadingStatus">
        <el-select v-model="queryParams.uploadingStatus" clearable placeholder="请选择上传状态">
          <el-option
              v-for="dict in dict.type.uploading_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建人" prop="created">
        <el-input
            v-model="queryParams.created"
            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"/>
      <template v-if="activeTabs=='1'">
        <el-table-column align="center" label="上传类型" prop="uploadingType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_apk_uploading_type" :value="scope.row.uploadingType"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="安装包名称" prop="sysApkName"/>
        <el-table-column align="center" label="版本号" prop="version"/>
        <el-table-column align="center" label="安装包" prop="sysApk"/>
        <el-table-column align="center" label="安装包大小" prop="sysApkSize"/>
        <el-table-column align="center" label="安装包类型" prop="sysType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_apk_type" :value="scope.row.sysType"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="创建人" prop="created"/>
      </template>
      <template v-if="activeTabs=='2'">
        <el-table-column align="center" label="安装包名称" prop="configId"/>
        <el-table-column :show-overflow-tooltip="true" align="center" label="版本号" prop="version"/>
        <el-table-column :show-overflow-tooltip="true" align="center" label="安装包大小" prop="sys_apk_size"/>
        <el-table-column :show-overflow-tooltip="true" align="center" label="上传方式" prop="uploading_type"/>
        <el-table-column :show-overflow-tooltip="true" align="center" label="创建人" prop="created"/>
        <el-table-column align="center" label="创建时间" prop="create_time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </template>
      <el-table-column align="center" label="状态" prop="uploading_status">
        <template slot-scope="scopeA">
          <dict-tag :options="dict.type.uploading_status" :value="scopeA.row.uploadingStatus"/>
        </template>
      </el-table-column>
      <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-download"
              size="mini"
              type="text"
              @click="handleDownload(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:detail']"
              icon="el-icon-view"
              size="mini"
              type="text"
              @click="handleDetail(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 { delINFO, listINFO } from '@/api/FDS/installList'

export default {
  name: 'InstallationList',
  dicts: ['sys_apk_uploading_type', 'uploading_status', 'sys_apk_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安装包管理（新）表格数据
      INFOList: [],
      packTabs: [{
        name: '1',
        title: 'APP安装包'
      }, {
        name: '2',
        title: 'H5模块包'
      }],
      // 日期范围
      create_time: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uploadingType: null,
        sysApkName: null,
        version: null,
        sysType: null,
        uploadingStatus: null,
        created: null
      },
      // 表单参数
      form: {},
      activeTabs: '1'
      // 表单校验
    }
  },
  watch: {
    $route(to, from) {
      if (to) this.getList()
    }
  },
  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() {
      const query = {
        activeTabs: this.activeTabs
      }
      this.$router.push({
        path: '/build/install/add/',
        query: query
      })
      // this.$tab.openPage('新增安装包', '/build/install/add/', params)

    },
    // 多选框选中数据
    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 delINFO(configIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 修改按钮操作 */
    handleEdit(row) {
      const query = {
        activeTabs: this.activeTabs,
        id: row.id
      }
      this.$router.push({
        path: '/build/install/edit/',
        query: query
      })

      // this.$tab.openPage('编辑安装包', '/build/install/add/', params)
    },
    /** 查看详情弹窗 **/
    handleDetail(row) {

      const params = {
        id: row.id
      }
      this.$tab.openPage('安装包详情', '/build/install/detail/', params)
    },

    /** 切换TAB触发的事件 */
    handleClickTabs() {
      this.getList()
    },

    /** 下载按钮 */
    handleDownload(row) {
      const configIds = row.id || this.ids
      this.$modal.confirm('是否确认下载编号为"' + configIds + '"的数据项？').then(function() {
        return delConfig(configIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('下载成功')
      }).catch(() => {
      })
    }
  }
}
</script>
