zenglf
2023-09-18 92ff846fb659c62037a32b1d8c15eae9df9d9b54
src/views/eam/modules/repairorder/EquipmentDocumentModal.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,201 @@
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <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>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="文档类型"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="documentTypeId"
            >
              <j-dict-select-tag
                allow-clear
                placeholder="请选择文档类型"
                :triggerChange="true"
                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>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>
<script>
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: ''
    }
  },
  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() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  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
        }
      })
    },
    handleCancel() {
      this.close()
    },
    //表单校验
    validateNum(rule, value, callback) {
      var params = {
        tableName: 'mom_eam_repair_order_operation_guidance',
        fieldName: 'num',
        fieldVal: value,
        dataId: this.model.id,
        //数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false å‡åˆ é™¤ï¼štrue
        delFlag: '0',
      };
      duplicateCheck(params).then((res) => {
        if (res.success) {
          callback();
        } else {
          callback("编号已存在!");
        }
      })
    }
  }
}
</script>