importBom.vue 5.48 KB
<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    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="节点编码">
          <a-input v-decorator="['no']"  :disabled="true"  />
          <a-input v-decorator="['uuid']"  :disabled="true"  />
          <a-input v-decorator="['cno']"   style="display:none"/>
          <a-input v-decorator="['js']"   style="display:none"/>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="项目名称">
          <a-input placeholder="请输入项目名称" :disabled="roleDisabled" v-decorator.trim="[ 'projectName', validatorRules.projectName]" />
        </a-form-item>


        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="生产令号">
          <j-search-select-tag placeholder="请选择生产令号" v-decorator="['orderNo', { rules: [{ required: true, message: '请输入生产令号!' }] }]" :dictOptions="searchOptions">
          </j-search-select-tag>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="bom套数">
          <a-input placeholder="请输入正整数"  :disabled="roleDisabled" v-decorator.trim="['multiple',validatorRules.multiple]" />
        </a-form-item>
        <p style="margin-left: 85px;color: red" >注:输入正整数套数相乘,负整数套数相除</p>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { importBom,checkName,getWorkOrderList } from '@api/api'
import JDictSelectTag from '/src/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
export default {
  name: 'importBom',
  props:['pro_no','pno_no',"js","uuid"],
  components: {
    JDictSelectTag,
    JSearchSelectTag
  },
  data () {
    return {
      title:"操作",
      visible: false,
      roleDisabled: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      searchOptions:[],
      validatorRules:{
        roleType:{
          type: [
            { required: true, message: '请输入编码!' },
            { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
          ]},
        projectName:{
          rules: [{
            required: true, message: '请输入项目名称!'
          },{
            validator: this.validateName,
          }]
        },multiple:{
          rules: [
              {validator: this.validateDigits},
            ]
        }

      },
    }
  },
  created () {
    this.getWorkOrder();

  },
  methods: {
    add () {
      if(this.pro_no==''){
        const that = this;
        that.$message.warning("请至少勾选一条列表");
      }else{
        this.edit({});
      }
    },
    edit (record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
      //编辑页面禁止修改角色编码
      if(this.model.id){
        this.roleDisabled = true;
      }else{
        this.roleDisabled = false;
      }

      this.$nextTick(() =>  {
        this.form.setFieldsValue({
          projectName:  this.model.projectName,
          orderNo: this.model.orderNo,
          no:this.pro_no,
          cno:this.pno_no,
          js:this.js,
          uuid:this.uuid,
          multiple:'1'
        })
      })
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },

    getWorkOrder(){
      var params ='';
      getWorkOrderList(params).then((res) => {
        this.searchOptions=res.result
      })

    },

    handleOk () {

      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          values.projectName = (values.projectName || '').trim()
          values.orderNo = (values.orderNo || '').trim()
          values.no = (values.no || '').trim()
          //values.multiple = (values.multiple || '').trim()
          let formData = Object.assign(this.model, values);
          let obj;
          obj=importBom(formData);
          obj.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();
          })
        }
      })
    },
    handleCancel () {
      this.close()
    },
    validateName(rule, value, callback){
      var params = {
        projectName: value,
      };
      checkName(params).then((res) => {
        if (res.success) {
          callback()
        } else {
          callback("项目名称已存在!")
        }
      })
    },

    validateDigits(rule, value, callback){
      //if(!(/(^[1-9]\d-*$)/.test(value))){
      var reg=/-?[1-9]\d*/;
      if(!reg.test(value)){
        callback("输入整数!")
      }else{
        callback()
      }
    },

  }
}
</script>

<style scoped>

</style>