let modules;
modules = {
  name: 'propertiesDialog',
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
    treeNodeArr: {
      type: Array
    }
  },
  inject: ['current_prefix'],
  components: {},
  created() {
    let attachmentDTO = Object.assign({}, this.$attrs.editAttachment);
    this.attachmentDTO = attachmentDTO;
    /*this.current_prefix = attachmentDTO && attachmentDTO.serverName ? ('/' + attachmentDTO
        .serverName) :
      '';*/
    this.initFilePrefix();
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    return {
      showDialog: true,
      falseValue: false,
      vxeOption: {},
      showContent: true,
      attachmentDTO: {},
      // current_prefix: '',
      filePrefix: '',
      fileName: '',
      fileAttachAttributeDTOs: []
    };
  },
  watch: {
    fileName(val) {
      this.attachmentDTO.fileName = this.fileName + this.filePrefix;
    }
  },
  methods: {
    initFilePrefix() {
      let name = this.attachmentDTO.fileName;
      let index = name.lastIndexOf('.');
      if (index >= 0) {
        this.filePrefix = name.substring(index + 1, name.length)
        this.fileName = name.substring(0, index)
      } else {
        this.fileName = name;
      }
    },
    dialogClose() {
      this.$emit('update:visiable', false);
    },
    getAttributes() {
      this.$http({
        url: this.current_prefix + '/file_attach/attribute/list',
        method: 'post',
        data: {
          stringOne: this.attachmentDTO.fileSn
        },
        isLoading: true,
        // modalStrictly: true,
        success: res => {
          this.fileAttachAttributeDTOs = res.objx || [];
        }
      });
    },
    initTableM1() {
      if (this.attachmentDTO.dirs) {
        returnl;
      }
      //明细
      var that = this;
      const tableRef = 'table-m1';
      const tableOption = {
        vue: this,
        tableRef: tableRef,
        tableName: 'user_fileLibrary_recycleBinPropertiesDialog_list-m1',
        columns: [
          {
            type: 'checkbox',
            fixed: 'left',
            width: 48,
            resizable: false
          },
          {
            title: this.$t2('属性名称', 'components.fileLibrary.attributeName'),
            field: 'attributeName',
            width: 200
          },
          {
            title: this.$t2('属性值', 'components.fileLibrary.attributeValue'),
            field: 'attributeValue',
            width: 200
          },
          {
            width: 50,
            fixed: 'right',
            title: '',
            sortable: false
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        this.vxeOption = opts;
      });
      this.getAttributes();
    },
    formatFileSize(fileSize) {
      fileSize = fileSize || 0;
      if (fileSize < 1024) {
        return fileSize + 'B';
      } else if (fileSize < (1024 * 1024)) {
        var temp = fileSize / 1024;
        temp = temp.toFixed(2);
        return temp + 'KB';
      } else if (fileSize < (1024 * 1024 * 1024)) {
        var temp = fileSize / (1024 * 1024);
        temp = temp.toFixed(2);
        return temp + 'MB';
      } else {
        var temp = fileSize / (1024 * 1024 * 1024);
        temp = temp.toFixed(2);
        return temp + 'GB';
      }
    }
  }
};
export default modules;
