BomModal.vue 6.71 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 placeholder="请输入图号" v-decorator="[ 'drawingNo' ]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="物料编码">
          <a-input placeholder="请输入物料编码" disabled="false" v-decorator="['code']" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="名称">
          <a-input placeholder="请输入名称" v-decorator="[ 'name' ]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="规格">
          <a-input placeholder="请输入规格" v-decorator="[ 'description' ]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="单位">
          <a-input placeholder="请输入单位" v-decorator="[ 'unit' ]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="制造方式">
          <a-select
            mode="default"
            style="width: 100%"
            placeholder="请选择制造方式"
            v-model="model.method">
            <a-select-option v-for="(item, key) in methodList" :key="item.value" :value="item.value">{{item.text}}</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="设计类型">
          <a-select
            mode="default"
            style="width: 100%"
            placeholder="请选择设计类型"
            v-model="model.designType">
            <a-select-option v-for="item in designTypeList" :key="item.value" :value="item.value">{{item.text}}</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="WIP属性">
          <a-select
            mode="default"
            style="width: 100%"
            placeholder="请选择WIP属性"
            v-model="model.wipType">
            <a-select-option v-for="item in wipTypeList" :key="item.value" :value="item.value">{{item.text}}</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="品牌">
          <a-input placeholder="请输入品牌" v-decorator="[ 'brand' ]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="分类">
          <a-select
            mode="default"
            style="width: 100%"
            placeholder="分类"
            v-model="model.categories">
            <a-select-option v-for="item in categoryList" :key="item.value" :value="item.value">{{item.text}}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { getDictItemsFromCache } from '@/api/api'
import { editMaterial } from '../../../api/api'
export default {
  name: 'BomModal',
  data () {
    return {
      title:"操作",
      visible: false,
      bomDisabled: false,
      model: {},
      designType: '',
      wipType: '',
      method: '',
      categories: '',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      methodList: {},
      wipTypeList: {},
      designTypeList: {},
      categoryList: {}
    }
  },
  computed() {

  },
  created() {
    this.loadBaseData();
  },
  methods: {
    loadBaseData() {
      this.categoryList = getDictItemsFromCache('categories')
      this.designTypeList = getDictItemsFromCache('design_type')
      this.methodList = getDictItemsFromCache('plm_method')
      this.wipTypeList = getDictItemsFromCache('wip_type')
    },
    add () {
      this.edit({});
    },
    edit (record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;

      //编辑页面禁止修改角色编码
      if(this.model.id){
        this.bomDisabled = true;
      }else{
        this.bomDisabled = false;
      }
      this.$nextTick(() => {
        this.form.setFieldsValue({
          code: this.model.code,
          name: this.model.name,
          brand: this.model.brand,
          spec: this.model.spec,
          unit: this.model.unit,
          method: this.model.method,
          designType: this.model.designType,
          wipType: this.model.wipType,
          drawingNo: this.model.drawingNo,
          categories: this.model.categories
        })
      });
      this.method = this.model.method
      this.designType=this.model.designType
      this.wipType =this.model.wipType
      this.drawingNo=this.model.drawingNo
      this.categories=this.model.categories
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let formData = Object.assign(this.model, values);
          editMaterial(formData).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()
    },
    validateRoleCode(rule, value, callback){
      if(/[\u4E00-\u9FA5]/g.test(value)){
        callback("角色编码不可输入汉字!");
      }else{
        var params = {
          tableName: "sys_role",
          fieldName: "role_code",
          fieldVal: value,
          dataId: this.model.id,
        };
        duplicateCheck(params).then((res)=>{
          if(res.success){
            callback();
          }else{
            callback(res.message);
          }
        });
      }
    }

  }
}
</script>

<style scoped>

</style>