<template>
  <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :modal-append-to-body="false" :title="title"
             :visible.sync="open" v-bind="$attrs" width="700px"
             @close="onClose"
             @open="onOpen"
             v-on="$listeners"
  >
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="90px"
             size="small"
    >
      <el-form-item label="安装包名称" prop="installpackName">
        <el-input
          v-model="queryParams.sysApkName"
          clearable
          placeholder="请输入安装包名称"
          style="width: 240px"
          @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-table v-loading="loading" :data="moduleList">
      <el-table-column align="center" label="安装包名称" prop="sysApkName"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="版本号" prop="version"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="安装包大小" prop="sysApkSize"/>
      <el-table-column :show-overflow-tooltip="true" align="center" label="适用系统" prop="sysType"/>
      <!--      <el-table-column align="center" label="状态" prop="uploadingStatus">-->
      <!--        <template slot-scope="scopeA">-->
      <!--          <dict-tag :options="dict.type.sys_yes_no" :value="scopeA.row.type"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="50">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-plus" size="20" type="primary"
                     @click="addPack(scope.row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>

import { listINFO } from '@/api/FDS/installList'

export default {
  name: 'AddPack',
  dicts: ['sys_yes_no'],
  props: {
    systemType: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 遮罩层
      title: '添加安装包',
      loading: true,
      configName: undefined,
      form: {},
      moduleList: [],
      // 显示搜索条件
      showSearch: true,
      total: 0,
      open: true,
      // 白名单配置表单验证
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysApkName: null,
        appCode: '000000'
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {

    /** 查询参数列表 */
    getList() {
      this.loading = true
      console.log(this.systemType)
      listINFO(
        {
          ...this.queryParams,
          sysType: this.systemType
        }).then(response => {
        this.moduleList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },

    /** 新增当前包的按钮 */
    addPack(row) {
      this.$emit('addPack', {
        apkId: row.id,
        version: row.version,
        sysType: row.sysType,
        sysApkName: row.sysApkName,
        sysApk: row.sysApk
      })
    },

    closeModal() {
      this.$emit('close')
    },
    onOpen() {
      this.active = this.current
      this.key = ''
    },
    onClose() {
    }
  }
}
</script>
