qushaowei
2023-08-31 b5e4adfc3a55490ad1cd49f50dfcc9dfb7b57d33
src/views/eam/modules/repairorder/EquipmentDocumentModal.vue
@@ -7,29 +7,57 @@
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      <a-form-model
        ref="form"
        :model="model"
        :rules="validatorRules"
      >
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="文档编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input v-model="model.num" placeholder="请输入文档编号" ></a-input>
            <a-form-model-item
              label="文档编号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="num"
            >
              <a-input
                v-model="model.num"
                placeholder="请输入文档编号"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="文档类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="documentTypeId">
            <a-form-model-item
              label="文档类型"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="documentTypeId"
            >
              <j-dict-select-tag
                allow-clear
                placeholder="请选择文档类型"
                :triggerChange="true"
                dictCode="common_upload_type"
                dictCode="mom_eam_document_type,name,id, del_flag!='1'"
                v-model="model.documentTypeId"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上传" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="file">
                <j-upload :returnUrl= "false" :isMultiple="false"  v-model="model.file" ></j-upload>
            <a-form-model-item
              label="上传"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="file"
            >
              <j-upload
                :returnUrl="false"
                :isMultiple="false"
                v-model="model.file"
              ></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
@@ -40,116 +68,116 @@
<script>
  import { httpAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import { duplicateCheck } from '@/api/api'
import { httpAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { duplicateCheck } from '@/api/api'
  export default {
    name: "EquipmentDocumentModal",
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
export default {
  name: "EquipmentDocumentModal",
  components: {
  },
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: "操作",
      width: 800,
      visible: false,
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        num: [
          { required: true, message: '请输入文档编号!' },
          { validator: this.validateNum },
          { max: 32, message: '超过最大输入限制,请缩减长度' }
        ],
        documentTypeId: [
          { required: true, message: '请选择文件类型!' },
        ],
        file: [
          { required: true, message: '请上传文件!' },
        ]
      },
      url: {
        add: "/eam/repairOrder/addEquipmentDocument",
        edit: "/eam/repairOrder/editEquipmentDocument",
      }
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          num:[
              { required: true, message: '请输入文档编号!'},
              { validator: this.validateNum },
              {max:32,message:'超过最大输入限制,请缩减长度'}
           ],
           documentTypeId:[
              { required: true, message: '请选择文件类型!'},
           ],
           file:[
              { required: true, message: '请上传文件!'},
           ]
        },
        url: {
          add: "/eam/repairOrder/addEquipmentDocument",
          edit: "/eam/repairOrder/editEquipmentDocument",
        }
      }
    },
    created () {
    }
  },
  created() {
    //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            console.log(this.model.file)
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.model['name'] = this.model.file[0].fileName;
            this.model['path'] = this.model.file[0].filePath;
            this.model['size'] = this.model.file[0].fileSize;
            this.model['repairOrderId'] = this.mainId
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          console.log(this.model.file)
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
        })
      },
      handleCancel () {
        this.close()
      },
       //表单校验
       validateNum(rule, value, callback) {
          this.model['name'] = this.model.file[0].fileName;
          this.model['path'] = this.model.file[0].filePath;
          this.model['size'] = this.model.file[0].fileSize;
          this.model['repairOrderId'] = this.mainId
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    //表单校验
    validateNum(rule, value, callback) {
      var params = {
        tableName: 'mom_eam_repair_order_operation_guidance',
        fieldName: 'num',
@@ -168,6 +196,6 @@
    }
    }
  }
}
</script>