InFeedFlowUploadModal.vue 5.89 KB
<template>
<a-modal
      :visible="visible"
      :title="title"
      :maskClosable="false"
      :centered='true'
      :confirmLoading="confirmLoading"
      @ok="handleSubmit"
      @cancel="handleCancel"
      cancelText="关闭"
    >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form" >
          <a-form-item label="上传配置编号:" :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol" v-show=" model.fileAttachmentNo ? true : false">
            <a-input
              :disabled="disabled"
              v-decorator="[ 'fileAttachmentNo',{'initialValue': model ? model.fileAttachmentNo : ''} ]"/>
          </a-form-item>
          <a-form-item label="提示文字:" :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol">
            <a-input
              v-decorator="[ 'title',validatorRules.title ]"/>
          </a-form-item>
          <a-form-item label="上传示例图片" :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol" extra="">
            <a-upload
              v-decorator="[
                'fileUrl',
                {
                  getValueFromEvent: normFile,
                },
              ]"
              name="file"
              :action="url.upload"
              listType="picture-card"
              :fileList="fileList"
              @preview="handlePreview"
              @change="handleChange"
            >
            <img v-if="picUrl" :src="picUrl" alt="头像" style="height:104px;max-width:300px"/>
              <div v-if="!picUrl&&(fileList.length < 1)">
                <a-icon type="plus" />
                <div class="ant-upload-text">Upload</div>
              </div>
            </a-upload>
          </a-form-item>
          <a-form-item label="备注" :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol">
            <a-textarea :rows="4" placeholder="最多输入60字" v-decorator="[ 'remark' ]" />
        </a-form-item>
      </a-form>
    </a-spin>
</a-modal>

</template>
<script>
  import store from '@/store'
  import pick from 'lodash.pick'
  import { saveFileAttachment, updateFileAttachment } from '@/api/insys'
  export default {
    name: "InFeedFlowUploadModal",
    data () {
      return {
        visible: false,
        confirmLoading: false,
        title: '',
        validatorRules:{
          fileAttachmentNo: {
            rules:[{
              required: true,
              message: '请输入上传配置编号'
            }]
          },
          title: {
            rules:[{
              required: true,
              message: '请输入提示文字'
            }]
          }
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        form: this.$form.createForm(this),
        model: {},
        url: {
          imgerver: window._CONFIG['domianURL'] + "/sys/common/view",
          syncUser: "/process/extActProcess/doSyncUser",
          upload:  window._CONFIG['uploadUrl'],
          delete: "/sys/user/delete",
          deleteBatch: "/sys/user/deleteBatch",
          exportXlsUrl: "/sys/user/exportXls",
          importExcelUrl: "sys/user/importExcel",
        },
        previewVisible: false,
        previewImage: '',
        fileList: [],
        picUrl:'',
        disabled:false
      }
    },
    created() {
    },
    mounted() {
    },
    methods: {
      getAvatarView(){
        return this.model.fileUrl;
      },
      handleCancel() {
        this.previewVisible = false;
      },
      handlePreview(file) {
        this.previewImage = file.response.data.fileURL || file.thumbUrl;
        this.previewVisible = true;
      },
      handleChange({ fileList }) {
        this.fileList = fileList;
        this.picUrl = ''
      },
      normFile(e) {
        if (Array.isArray(e)) {
          return e
        }
        return e && e.fileList
        // return e.file.response.data.fileURL;
      },
      edit (record) {
        this.model = record;
        this.picUrl = record.fileUrl
        this.form.resetFields();
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(record,'fileAttachmentNo','title','fileUrl','remark'));
          this.disabled = true
        });
      },

      add (val) {
        this.model = {};
        this.form.resetFields();
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue();
          this.disabled = false
        });
      },

      close () {
        this.$emit('close');
        this.visible = false;
        this.disableSubmit = false;
        this.selectedRole = [];
        this.fileList = [];
        this.picUrl = ''
      },
      handleSubmit () {
        // 触发表单验证
        let that = this
        this.form.validateFields((err, values) => {
           if (!err) {
            this.confirmLoading = true;
            let formData = values ,promiseFn;
            if(Array.isArray(formData.fileUrl)){
              formData.fileUrl = values.fileUrl[0].response.data.fileURL
            }
            
            if(!!this.model.id){ //编辑
              promiseFn = updateFileAttachment(formData);
            }else{
              
              promiseFn = saveFileAttachment(formData)
            }
            promiseFn.then((res)=>{
              if(res.status.statusCode == 0){
                this.$message.success(res.status.statusReason);
                this.$emit('ok');
              }else{
                this.$message.warning(res.status.statusReason);
              }
            }).finally(() => {
              this.confirmLoading = false;
              this.refresh()
              this.close();
            });
          }
          
        })
      },
      handleCancel () {
        this.close()
      },
      refresh(){
        this.fileList = [];
      }
    }
  }
</script>
<style scoped>

</style>