<template>
  <el-dialog
    :title=lang.associatedFiles
    :visible.sync="dialogVisible"
    width="calc(100% - 20px)"
    class="el-dialogClass"
    :before-close="handleClose"
  >
    <div class="f_box">
      <div class="f_box_top">
        <!-- <div class="f_box_top_left">
        </div> -->
        <!-- <div class="f_box_top_right"> -->
         
          <!-- <div class="btn" @click="serchFile">刷新</div> -->
        <!-- </div> -->
      </div>
      <div class="f_box_top">
        <div class="f_box_top_left">
          <div class="f_box_top_title">{{lang.myFiles}}</div>

          <el-select v-model="mofolderid" filterable @change="serchFile">
            <el-option
              v-for="item in myFolderArray"
              :key="item.folderid"
              :label="item.name"
              :value="item.folderid"
            >
            </el-option>
          </el-select>
        </div>
        <div class="f_box_top_right">
          <div class="input">
            <div class="serch" @click="serchFile"></div>

            <input
              type="text"
              v-model="fileName"
              :placeholder=lang.selectFileName
              @keyup.enter="serchFile"
            />
          </div>
          
          <el-button type="primary" size="small" @click="serchFile"
            >
            <img style="vertical-align: middle;transform: scale(1.1);padding-bottom: 2px;box-sizing: border-box;" src="../../../../assets/shuax.svg" alt="">
            {{lang.flushed}}</el-button
          >
          <span v-if="checkArray.length" style="margin-left: 12px;color: #b0b0b0;font-size: 14px;flex-shrink: 0;line-height: 35px;">{{lang.selectedFiles}}&nbsp;{{checkArray.length}}&nbsp;{{lang.piece}}</span>

        </div>
      </div>
      <div class="none_box"
            v-loading.body="isLoading"
      >{{lang.nouploadFiles}}</div>
      <!-- v-if="fileArray.length == 0"  -->
      <!-- v-else-if="fileArray.length" -->

      <div
        class="f_box_file_list"
      >
        <div class="list_file_box">
          <el-table
            :data="fileArray"
            border
            stripe
            style="width: 100%"
            @selection-change="handleSelectionChange"
            ref="myTable"
            max-height="800px"
            v-loading="isLoading"
            :row-key="row => row.id"
            :no-data-text="lang.nouploadFiles"
          >
            <el-table-column
              type="selection"
              width="50px"
              :reserve-selection="true"
            ></el-table-column>
            <el-table-column
              prop="name"
              :label=lang.fileName
              show-overflow-tooltip
              min-width="15"
            ></el-table-column>
            <el-table-column
              prop="folderName"
              :label=lang.folderBelongs
              show-overflow-tooltip
              min-width="20"
            ></el-table-column>
            <el-table-column
              prop="username"
              :label=lang.owner
              show-overflow-tooltip
              width="160"
            ></el-table-column>
           
            <el-table-column :label=lang.processStatus width="80px">
              <template slot-scope="scope">
                {{ getState(scope.row.ingestionStatus) }}
              </template>
            </el-table-column>
            <el-table-column :label=lang.graphExtracted width="150px">
              <template slot-scope="scope">
                {{ getState2(scope.row.extractionStatus) }}
              </template>
            </el-table-column>
            <el-table-column
              :label=lang.fileType
              show-overflow-tooltip
              min-width="10"
            >
              <template slot-scope="scope">
                {{ scope.row.documentType ? scope.row.documentType : "-" }}
              </template>
            </el-table-column>
            <!-- <el-table-column label="公开状态" show-overflow-tooltip width="80px"></el-table-column> -->
            <el-table-column
              prop="time"
              :label=lang.uploadTime
              show-overflow-tooltip
              min-width="20"
            ></el-table-column>
            <!-- <el-table-column label="操作" width="200px">
              <template slot-scope="scope">
                <div>
                  <el-button
                    type="primary"
                    size="small"
                    v-if="userid == data.userid && data.isMo == '2'"
                    @click="removeFile(scope.row.id, scope.row.documentid)"
                    >移除</el-button
                  >
                  <el-button
                    type="danger"
                    size="small"
                    v-if="userid == scope.row.userid"
                    @click="deleteFile(scope.row.id, scope.row.documentid)"
                    >删除</el-button
                  >
                </div>
              </template>
            </el-table-column> -->
          </el-table>
        </div>
        <el-pagination
          class="pageBox"
          style="margin-top: 10px"
          layout="total, prev, pager, next,  slot"
          :page-size="limit"
          :total="total"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 50, 100]"
      >
      <el-select v-model="limit" @change="handleSizeChange" class="file_mySelect">
          <el-option
              v-for="item in [10, 20, 50, 100]"
              :key="item"
              :label="item"
              :value="item"
              ></el-option>
          </el-select>
        </el-pagination>
      </div>
    </div>
    <span slot="footer">
      <el-button @click="dialogVisible = false">{{lang.close}}</el-button>
      <el-button @click="batchRemove" type="primary">{{lang.Add}}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      isLoading: false,
      fileArray: [],
      checkArray: [],
      checkArray2: [],
      userid: "",
      folderid: "",
      mofolderid: "",
      fileName: "",
      page: 1,
      total: 0,
      limit: 10,
      folderLoading: false,
      myFolderArray: []
    };
  },
  computed: {
    getState() {
      return function (item) {
        if (item == "success") {
          return this.lang.success;
        } else if (item == "failed") {
          return this.lang.fail;
        } else if (item == "augmenting") {
          return this.lang.uploading;
        } else if (item == "pending") {
          return this.lang.pending;
        } else if (item == "enriched") {
          return "enriched";
        } else if (!item) {
          return this.lang.uploading;
        } else {
          return item;
        }
      };
    },
    getState2() {
      return function (item) {
        if (item == "success") {
          return this.lang.success;
        } else if (item == "failed") {
          return this.lang.fail;
        } else if (item == "pending") {
          return this.lang.pending;
        } else if (item == "processing") {
          return this.lang.processing;
        } else if (item == "enriched") {
          return "enriched";
        } else if (!item) {
          return this.lang.uploading;
        } else {
          return item;
        }
      };
    }
  },
  methods: {
    handleClose(done) {
      done();
    },
    openG(uid, fid, mofid) {
      this.dialogVisible = true;
      this.userid = uid;
      this.folderid = fid;
      this.mofolderid = mofid;
      (this.page = 1), (this.fileName = "");
      this.getData();
      this.getFolder();
      this.$forceUpdate();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },
    handleSizeChange(val){
      this.page = 1;
      this.limit = val
      this.getData()
    },
    serchFile() {
      this.page = 1;
      this.getData();
    },
    getFolder() {
      this.folderLoading = true;
      let params = {
        uid: this.userid
      };
      this.ajax
        .post(this.$store.state.api + "getFolder", [params])
        .then(res => {
          this.folderLoading = false;
          let data = res.data[0];
          this.myFolderArray = data.filter(el => el.folderid != this.folderid);
        })
        .catch(err => {
          this.isLoading = false;
          console.error(err);
        });
    },
    getData() {
      this.isLoading = true;
      let params = {
        uid: this.userid,
        folderid: this.mofolderid,
        cfolderid: this.folderid,
        n: this.fileName,
        page: this.page,
        num: this.limit
      };
      this.ajax
        .post(this.$store.state.fileApi + "getFile2", [params])
        .then(res => {
          this.isLoading = false;
          console.log(res.data);
          this.total = res.data.result.length ? res.data.result[0].num : 0;
          this.fileArray = res.data.result;
        })
        .catch(err => {
          this.isLoading = false;
          console.error(err);
        });
    },
    handleSelectionChange(selectedRows) {
      this.checkArray = selectedRows.map(row => row.id);
      this.checkArray2 = selectedRows.map(row => ({
        id: row.id,
        documentid: row.documentid
      }));
    },
    async batchRemove() {
      if (this.checkArray2.length == 0) {
        this.$message.error(this.lang.selectLinkFile);
        return;
      }
      let array = this.checkArray2.map(item => item.id);
      let array2 = this.checkArray2.map(item => item.documentid);
      let params = {
        documentids: array2.join(","),
        ids: array.join(","),
        folderid: this.folderid
      };
      await this.ajax.post(this.$store.state.fileApi + "moveFile", [params]);
      this.$parent.getData();
      this.checkArray = [];
      this.checkArray2 = [];
      this.$refs.myTable.clearSelection();
      this.dialogVisible = false;
      this.$message.success(this.lang.addSuccess);
    }
  }
};
</script>

<style scoped>
.el-dialogClass >>> .el-dialog {
  margin: 10px auto 0 !important;
  height: calc(100% - 20px);
}

.el-dialogClass >>> .el-dialog__body {
  height: calc(100% - 70px - 55px);
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  padding: 0 20px;
}

.f_box {
  width: 100%;
  /* height: 100%; */
  position: relative;
  min-height: 400px;
}

.f_box_top {
  display: flex;
  align-items: center;
  padding: 10px 0;
  width: 100%;
  box-sizing: border-box;
}

.f_box_top_left {
  display: flex;
  align-items: center;
}
.f_box_top_left >>> .el-input--suffix .el-input__inner{
  height: 36px;
}
.f_box_top_title {
  font-size: 16px;
  margin-right: 16px;
  /* font-weight: bold; */
}

.btn {
  display: flex;
  cursor: pointer;
  align-items: center;
  height: 30px;
  padding: 0 8px;
  background: rgb(0, 97, 255);
  color: #fff;
  box-sizing: border-box;
  border-radius: 4px;
  font-size: 14px;
  align-items: center;
}

.btn2 {
  display: flex;
  cursor: pointer;
  align-items: center;
  height: 30px;
  padding: 0 8px;
  background: #fff;
  color: rgb(0, 97, 255);
  border: 1px solid rgb(0, 97, 255);
  box-sizing: border-box;
  border-radius: 4px;
  font-size: 14px;
  align-items: center;
}

.f_box_top .delBtn {
  background: rgb(255, 0, 13);
}

.btn + .btn2,
.btn + .btn,
.btn2 + .btn2,
.btn2 + .delBtn {
  margin-left: 15px;
}

.f_box_top_right {
  margin-left: auto;
  /* max-width: calc(100% - 280px); */
  overflow: hidden;
  display: flex;
  /* align-items: center; */
}
.f_box_top_right >>> .el-button{
  height: 35px !important;
  font-size: 12.8px;
  background-color: #3370FF;
  border-radius: 6px;
  margin-left: 12px;
}
.f_box_top_right > .input {
  position: relative;
  height: 40px;
}

.f_box_top_right > .input > input {
  width: 100%;
  height: 100%;
  border: 1px solid #dcdfe6;
  border-radius: 5px;
  padding: 0 15px 0 45px;
  box-sizing: border-box;
  font-size: 14px;
  width: 250px;
  height: 36px;
  font-size: 12.8px;
  border-radius: 6px;
  outline: none;
}

.f_box_top_right > .input > .serch {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background-image: url("../../../../assets/icon/sourceFile/search.png");
  background-size: 100% 100%;
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
}

.f_box_top_right > .tab {
  height: 30px;
  width: 80px;
  margin-left: 15px;
  background: #e7e7e7;
  border: 2px solid #d9d9d9;
  border-radius: 5px;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.f_box_top_right > .tab > .table,
.f_box_top_right > .tab > .list {
  width: 50%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.f_box_top_right > .tab > .list::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background-image: url("../../../../assets/icon/sourceFile/list.png");
  background-size: 100% 100%;
}

.f_box_top_right > .tab > .list.active,
.f_box_top_right > .tab > .table.active {
  background: #fff;
}

.f_box_top_right > .tab > .table::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background-image: url("../../../../assets/icon/sourceFile/table.png");
  background-size: 100% 100%;
}

.mask {
  /* background-color: rgb(0 0 0 / 30%); */
  /* position: fixed; */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progressBox {
  width: 300px;
  height: 150px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 0 6px 1px #bfbfbf;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: relative;
  color: #6c6c6c;
}

.progressBox >>> .el-progress-bar__outer {
  background-color: #d1dfff !important;
}

.progressBox .lbox {
  height: 50px;
  font-size: 19px;
  display: flex;
  align-items: center;
  color: #747474;
}

.progressBox .lbox img {
  width: 40px;
  margin-right: 20px;
}

.closeCss {
  position: absolute;
  top: 8px;
  right: 8px;
  cursor: pointer;
  width: 20px;
  height: 20px;
}

.closeCss > img {
  width: 100%;
  height: 100%;
}

.f_box_file_square {
  height: calc(100% - 55px);
  overflow: auto;
  width: 100%;
  padding: 55px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  position: relative;
}

.f_box_file_square > .f_box_file {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 160px;
  height: 160px;
  cursor: pointer;
  margin: 0 36px 36px 0;
  border-radius: 20px;
  position: relative;
}

.f_box_file_square > .f_box_file:hover {
  background: #f0f2f5;
}

.f_box_file_square > .f_box_file:hover > .check {
  display: block;
}

.f_box_file_square > .f_box_file.check {
  background: #e0eafb;
}

.f_box_file_square > .f_box_file.check > .check {
  display: block;
}

.f_box_file_square > .f_box_file > .check {
  position: absolute;
  left: 15px;
  top: 15px;
  width: 16px;
  height: 16px;
  background-size: 100%;
  display: none;
}

.f_box_file_square > .f_box_file > .check > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.f_box_file_square > .f_box_file > img {
  width: 90px;
  height: 90px;
  object-fit: cover;
}

.f_box_file_square > .f_box_file > .name {
  white-space: nowrap;
  font-size: 14px;
  max-width: 80%;
  overflow: hidden;
  margin: 4px auto 0;
  text-overflow: ellipsis;
  text-align: center;
}

.f_box_file_list {
  /* height: calc(100% - 55px); */
  /* overflow: auto; */
  width: 100%;
  padding: 10px 0;
  box-sizing: border-box;
}
.f_box_file_list >>> .el-table-column--selection .cell{
    display: flex !important;
    align-items: center !important;
}
/* .f_box_file_list > .f_box_file {
} */

.f_box_file_allCheck {
  display: flex;
  align-items: center;
  position: absolute;
  font-size: 14px;
  top: 20px;
  left: 10px;
  cursor: pointer;
}

.f_box_file_allCheck > img {
  width: 16px;
  height: 16px;
  object-fit: cover;
  margin-right: 5px;
}

.dialog >>> .el-dialog__body {
  padding: 10px 20px;
}

.type_nav_box {
}

.type_nav_box > .nav {
  height: 40px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  margin-bottom: 10px;
  font-size: 16px;
  color: #000;
}

.type_nav_box > .nav > .down {
  min-width: 14px;
  height: 14px;
  background-image: url("../../../../assets/icon/sourceFile/icon_arrow.png");
  background-size: 100% 100%;
  margin-right: 10px;
  transition: all 0.3s;
  transform: rotate(-90deg);
}

.type_nav_box > .nav.active > .down {
  transform: rotate(0deg);
}

.type_nav_box > .nav > .file {
  min-width: 18px;
  height: 18px;
  background-image: url("../../../../assets/icon/sourceFile/file.png");
  background-size: 100% 100%;
  margin-right: 10px;
}

.type_nav_box > .nav > .name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type_nav_box > .child {
}

.type_nav_box > .child > .nav {
  height: 40px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 10px 0 50px;
  box-sizing: border-box;
  margin-bottom: 10px;
  font-size: 16px;
  color: #000;
}

.type_nav_box > .child > .nav.active {
  background: #e0eafb;
}

.type_nav_box > .child > .nav > .file {
  min-width: 18px;
  height: 18px;
  background-image: url("../../../../assets/icon/sourceFile/file.png");
  background-size: 100% 100%;
  margin-right: 10px;
}

.type_nav_box > .child > .nav > .name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.none_box {
  height: calc(100% - 55px);
  overflow: auto;
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

.list_file_box {
  width: 100%;
}

.list_file_name {
  display: flex;
  align-items: center;
}

.list_file_name > img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  margin-right: 5px;
}

.list_file_name > div {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pageBox{
  display: flex;
}
.pageBox >>> .el-pagination__total{
  margin-right: auto;
}
.list_file_box {
  width: 100%;
}
.list_file_box>>> .el-table{
  border-radius: 10px !important;
  overflow: hidden !important;
}

.list_file_box >>>table th{
  border:none !important;
  background-color: #f2f3f6 !important; /* 浅灰色背景 */
  color: #00000099 !important;
}
.list_file_box >>>table tr td{
  border:none !important;
  border-bottom: 1px solid #EBEEF5 !important;
}

.list_file_box >>>table tr {
  border:1px #000 solid !important;
}

.list_file_box >>> .el-table__header-wrapper{
  margin-bottom: 10px !important;
}

.list_file_box >>> .el-table__row{
  border: 1px #ccc solid;
}
.list_file_box >>>table tr td:nth-child(1){
  border-radius: 10px 0 0 10px !important;
}
.list_file_box >>>table tr td:nth-last-child(1){
  border-radius: 0 10px 10px 0 !important;
}

.list_file_box >>>table tr th:nth-child(1){
  border-radius: 10px 0 0 10px;
}

.list_file_box >>>table tr th:nth-last-child(2){
  border-radius: 0 10px 10px 0 !important;
}
.list_file_box >>>.el-table::before{
  background-color: #fff;
}
.list_file_box >>>.el-table--border::after{
  background-color: #fff;
}
.list_file_box >>> .el-table--border{
  border: none;
  border-bottom: 1px solid #EBEEF5;
}
</style>
