<template>
  <!-- 模型日志弹窗 -->
  <div id="modelLog">
    <el-dialog title="模型日志" :visible.sync="modelLogVisible" width="40%" :before-close="handleClose">
      <div class="bodys">
        <el-tabs v-model="activeName" type="card" @tab-click="changeModel">
          <el-tab-pane label="上传日志" name="first">
            <el-table :data="filterlogData" stripe height="300px" style="width: 100%">
              <el-table-column prop="Version" label="版本"></el-table-column>
              <el-table-column prop="CreateTime" label="上传时间"></el-table-column>
              <el-table-column prop="UserName" label="上传人"></el-table-column>
              <el-table-column prop="address" label="操作">
                <template slot-scope="scope">
                  <el-button @click="handleClick(scope.row)" v-if="!scope.row.Removed" type='primary' size="mini" class="iconfont icon-download"></el-button>
                  <!-- 需求:先不支持删除 -->
                  <!-- <el-button @click="deleteModel(scope.row)" v-if="!scope.row.Removed" type='danger' plain size="mini">删除</el-button> -->
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="工程改造" name="second"></el-tab-pane>
        </el-tabs>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/api/model/file.js";
export default {
  props: {
    modelLogVisible: Boolean,
    modelFolderName: String,
    logData: Array
  },
  data() {
    return {
      dialogVisible: false, //是否显示该弹窗
      activeName: "first", //默认选择上传日志
      tableData: [] //列表数据
    };
  },
  computed: {
    filterlogData: function() {
      let newLogData = [];
      if (this.logData.length) {
        this.logData.forEach(item => {
          newLogData.push(item);
        });
      }
      return newLogData
    }
  },
  methods: {
    handleClose(done) {
      this.$emit("CloseModelLogDia");
    },
    handleClick(item) {
      console.log(item);
      if (item.Url) {
        let a = document.createElement("a");
        a.href = item.Url;
        a.download =`${this.modelFolderName}${item.FloorName}模型文件v${item.Version}.rvt`;
        a.click();
      } else {
        this.$message({
          message: "该文件夹下没有资源",
          type: "error"
        });
      }
    },
    changeModel() {},
    /**
     * 删除模型
     *
     */
    deleteModel(item) {
      this.$confirm(
        "此操作只可删除楼层模型文件，已经识别的对象及关系等，暂不可删除。确定删除？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          request.deleteModelFileList(item.Id, res => {
            if (res.Result == "success") {
              //  刷新页面
              this.$emit("deleteFinish");
              this.$message({
                type: "success",
                message: "删除成功!"
              });
            } else {
              this.$message({
                type: "error",
                message: res.Result
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>
<style lang="less" scoped>
#modelLog {
  .bodys {
    position: relative;
    padding-bottom: 30px;
    .delete-model {
      position: absolute;
      right: 0;
      top: 0;
      z-index: 10;
    }
  }
}
</style>

