ElecticalFileModal.vue 4.08 KB
<template>
  <a-modal
    :title="'批量修改'"
    :width="800"
    :visible="batchVisible"
    :confirmLoading="confirmLoading"
    @ok="handleBatchOk"
    @cancel="handleBatchCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top:5%;height: 85%;overflow-y: hidden">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="区域电气图纸">
          <input id="upfile" type="file" accept="image/*" class="add_upload_file" @change="fileUpload('1')" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="使用说明书">
          <input id="upfile2" type="file" accept="file/*" class="add_upload_file" @change="fileUpload('2')" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="维修与保养手册">
          <input id="upfile3" type="file" accept="file/*" class="add_upload_file" @change="fileUpload('3')" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { ajaxGetDictItems, editsBatchPurchase, editPurchase } from '../../../api/api'

export default {
  name: 'ElecticalFileModal',
  data() {
    return {
      code: '',
      workno:'',
      uuid:'',
      electricalNo:'',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      model: {},
      batchVisible: false,
      form: this.$form.createForm(this),
      confirmLoading: false,
      statusList:[],
      status:'',
    }
  },
  created() {
    this.loadBaseData();
  },
  methods: {
    handleBatchCancel() {
      this.ids = ''
      this.batchVisible = false
    },
    fileUpload(type){
      let that = this;
      let file = document.getElementById('upfile');
      let fileName = file.value;
      let files = file.files;
      if(fileName == null || fileName==""){
        this.$message.error("请选择文件");
      }else{
        let fileType = fileName.substr(fileName.length-4,fileName.length);
        if(fileType == ".jpg" || fileType == ".png"){
          if (files[0]) {
            let formData = new window.FormData()
            formData.append('file', files[0])
            formData.append('mod', 5)
            formData.append('opt', 2)
            formData.append('workno', this.workno)
            formData.append('uuid', this.uuid)
            formData.append('code', this.code)
            formData.append('type', type)

            let data = {
              mod: 5,
              opt: 2,
              formData
            };
            this.$message.info("上传中!")
            fetch('http://127.0.0.1:8080/jeecg-boot/sys/upload/mmsEleMinio', {
              method: 'POST',
              body: formData,
              headers: {
                // Auth: 'token'
                'Access-Control-Allow-Origin': '*',
                Authorization: 'Bearer',
              },
            }).then((res) => {
              return res.json()
            }).then((res) => {
              if (res.code == 0) {
                let reader = new FileReader();
                reader.readAsDataURL(files[0]);
                reader.onload = function (e) {
                  console.log("aaa:"+this.result)
                  that.imgs.push({id: res.message, base64: this.result})
                  console.log(that.imgs)
                }
                this.$message.success("上传成功!")
              } else {
                this.$message.error("上传失败!")
              }
            })

          } else {
            this.$message.error("请选择要上传的图片");
          }
        }else{
          this.$message.error("上传文件类型错误!");
        }
      }
    },
    edit (code,workno,uuid) {
      this.code = code
      this.workno = workno
      this.uuid = uuid
      this.form.resetFields();
      this.batchVisible = true;
    },
  }
}
</script>

<style scoped>

</style>