<!--
  @description: app菜单列表
  @Modifier: zxl
  @routerPath:
  @date: 2020-2-20-14:56
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :search-form.sync="searchForm"
      search-label-width="100px"
      :menu="true"
      @on-load="loadData"
    >
      <template v-slot:header>
        版本信息列表
      </template>
      <template v-slot:search="search">
        <el-form-item label="系统类型" prop="systemType">
          <el-input v-model.trim="searchForm.systemType" placeholder="请输入" @keyup.enter.native="search.onSearch" />
          <el-select v-model="searchForm.systemType" placeholder="请选择" style="width:228px">
            <el-option
              v-for="(item,index) in app_system_typeList"
              :key="index"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="包名" prop="packageName">
          <el-input v-model.trim="searchForm.packageName" placeholder="请输入" @keyup.enter.native="search.onSearch" />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <el-button type="primary" @click="addMenu">
          新增
        </el-button>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
          />
          <el-table-column
            header-align="center"
            prop="versionNum"
            label="版本序号"
            min-width="230"
          />
          <el-table-column
            header-align="center"
            prop="versionCode"
            label="版本编号"
            min-width="180"
            align="center"
          />

          <el-table-column
            header-align="center"
            prop="versionDesc"
            label="版本说明"
            min-width="230"
            align="center"
          />

          <el-table-column
            header-align="center"
            prop="packageName"
            label="包名"
            min-width="180"
            align="center"
          />
          <!--          <el-table-column
            header-align="center"
            prop="userName"
            label="用户名称"
            min-width="180"
            align="center"
          />-->
          <el-table-column
            header-align="center"
            prop="systemType"
            label="系统类型"
            min-width="90"
            align="center"
          />
          <el-table-column
            header-align="center"
            prop="isMust"
            label="是否强制"
            min-width="90"
            align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.isMust === '01'?'是':'否' }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="安装包"
            min-width="90"
            align="center"
          >
            <template slot-scope="scope">
              <downloadFile :data="scope.row.fileData" />
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" width="125">
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click="toEdit(scope.row)"
              >
                [编辑]
              </el-link>
              <el-link
                type="primary"
                @click="toDel(scope.row,scope.$index)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>

    <!--    <platform-add-dialog v-if="dialogData.flag" :dialog-data="dialogData" @change="callBack" />-->
    <appVersionAddDialog v-if="dialogData.flag" :dialog-data="dialogData" @change="callBack" />
  </div>
</template>

<script>
import downloadFile from '@comp/common/updownload/downloadFile'
/* 混合开发方法-参数字段*/
import { filterDictText } from '../../../assets/js/utils'
import { delAppVersion, queryAppVersionPage } from '../../../api/appManagement/appVersion'
import appVersionAddDialog from './appVersionAdd-dialog.vue'
export default {
  components: {
    downloadFile,
    appVersionAddDialog
  },
  data() {
    return {
      loading: true,
      searchForm: {
        systemType: '', // 系统类型
        packageName: ''// 包名
      },
      tableData: [],
      dialogData: {
        flag: false,
        row: null
      },
      app_system_typeList: []
    }
  },
  created() {
    this.initGroup()
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 字典请求
    initGroup() {
      this.$store.dispatch('getGroupType', ['app_system_type']).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 获取数据
    loadData(params, callback) {
      queryAppVersionPage(params).then(response => {
        this.tableData = (response.data.records || []).map(item => {
          item.fileData = {
            fileId: item.id,
            fileType: 'app_package_file'
          }
          return item
        })
        this.loading = false
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    addMenu() {
      this.dialogData.row = null
      this.dialogData.flag = true
    },
    toEdit(row) {
      this.dialogData.row = row
      this.dialogData.flag = true
    },
    toDel(row, index) {
      this.$confirm('确认是否删除该条数据？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        delAppVersion({ id: row.id }).then(res => {
          this.tableData.splice(index, 1)
        }).catch(() => {
        })
      }).catch(() => {
      })
    },
    // 详情
    handleDetail(row) {

    },
    // 操作回调
    callBack() {
      this.$refs.tableCrud.onSearchChange()
    }
  }
}
</script>

<style lang="less" scoped>
.img_pic {
  max-height: 50px;
}
</style>
