<template>  
    <div>
      <i-form :model = "fileObj">
         <Form-item label = "文件">
            <i-input type="text" disabled="disabled" v-model = "fileObj.files.FileName" class="disInput"></i-input>
            <span>我们支持Excel格式、图片格式、rar或zip压缩包、jio等文件</span>
            <webUploader :item = "uploader" :methods = "uploaderMethods"></webUploader>
        </Form-item>
         <Form-item label = "标题">
            <i-input type="text"  v-model = "fileObj.files.ShowName" clearable></i-input>
        </Form-item>
        <Form-item label = "其他">
            <Checkbox v-model = "fileObj.files.isNew" :disabled = "fileObj.files.isHide">显示"新"字</Checkbox>
            <Checkbox v-model = "fileObj.files.isTop" :disabled = "fileObj.files.isHide">置顶显示</Checkbox>
            <Checkbox v-model = "fileObj.files.isHide">隐藏</Checkbox>
        </Form-item>
        </i-form>
    </div>
</template>
<script>
import webUploader from "@components/WebUploader/WebUploader.vue";
export default {
  name: "FileModal",
  props: ["fileObj", "uploader", "filterHide", "newlyIncreFiles", "setRep"],
  data: () => ({
    mefile: {},
    uploaderMethods: null
  }),
  computed: {},
  mounted() {
    this.uploaderMethods = {
      addFileQueued: this.addFileQueued,
      loadFileSuccess: this.loadFileSuccess
    };
  },
  methods: {
    addFileQueued(file) {
      let self = this,
        id = self.fileObj.id,
        mfile = self.fileObj.files;
        self.uploader.formData["Guid"] = self.newGuid();
      self.mefile = {
        ShowName: file.name,
        FileName: file.name
      };
      let repObj = {
        id: id,
        rep: true
      };
      self.setRep(repObj);
      $.extend(self.fileObj.files, self.mefile);
    },
    loadFileSuccess(result) {
      if (!result.Code && !result.ErrorMessage && !result.Result) {
        self.$Notice.info({
          title: "出现上传异常，请稍后上传.",
          desc: ""
        });
        return;
      }
      if (!result.Code && !result.ErrorMessage) {
        let self = this,
          id = self.fileObj.id,
          filterHide = self.filterHide,
          paylod = {
            filterHide: filterHide,
            id: id
          };
        self.$Notice.info({
          title: "上传成功.",
          desc: ""
        });
        $.extend(self.fileObj.files, result.Result);
        self.$Modal.remove();
        self.newlyIncreFiles(paylod);
      } else {
        self.$Notice.info({
          title: result.ErrorMessage + ",状态码为：" + result.Code,
          desc: ""
        });
        self.$Modal.remove();
      }
    },
    newGuid() {
      return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
        c
      ) {
        var r = (Math.random() * 16) | 0,
          v = c == "x" ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      });
    }
  },
  components: {
    webUploader
  }
};
</script>
<style>
.disInput input.ivu-input-disabled {
  color: #626262;
}
</style>


