PurchaseInModal.vue 7.25 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="请输入物料编码" disabled="false" v-decorator="['materialCode']" />
        </a-form-item>

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

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

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

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

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <a-select
            v-model="status" disabled="false"          >
            <a-select-option v-for="item in statusList" :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="请输入供应商"   ref=""  v-decorator="['supplier']" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系人">
          <a-input placeholder="请输入联系人"  v-decorator="['contact']" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="联系方式">
          <a-input placeholder="请输入联系方式"   v-decorator="['phone']" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="初次计划完成时间">
          <a-date-picker disabled="false"
            v-decorator="['planEndTime']"
            type="date"
          />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="变更计划完成时间">
          <a-date-picker
            v-decorator="['changePlanEndTime']"
            type="date"
          />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="实际结束时间">
          <a-date-picker disabled="false"
            v-decorator="['actualEndTime']"
            type="date"
          />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-input v-decorator="['remark']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { editPurchase, ajaxGetDictItems } from '../../../api/api'

export default {
  name: 'PurchaseInModal',
  data () {
    return {
      title:"操作",
      visible: false,
      bomDisabled: false,
      model: {},
      designType: '',
      wipType: '',
      method: '',
      categories: '',
      remark: '',
      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: {},
      statusList:[],
      status:''
    }
  },
  computed() {

  },
  created() {
    this.loadBaseData();
  },
  methods: {
    loadBaseData() {
      ajaxGetDictItems('purchased_status').then((res)=> {
          if (res.success) {
            this.statusList = res.result
          }
      })
    },
    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({
          materialCode: this.model.materialCode,
          materialName: this.model.materialName,
          qty: this.model.qty,
          unit: this.model.unit,
          method: this.model.method,
          planStartTime: this.model.planStartTime,
          planEndTime: this.model.planEndTime,
          actualStartTime: this.model.actualStartTime,
          actualEndTime: this.model.actualEndTime,
          contact: this.model.contact,
          status: this.model.status,
          changePlanEndTime:this.model.changePlanEndTime,
          code: this.model.code
        })
      });
      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
      this.remark = this.model.remark
      this.status = this.model.status
      this.supplier = this.model.supplier
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        // alert('ddd')
        if (!err) {
          that.confirmLoading = true;
          let formData = Object.assign(this.model, values);
          editPurchase(formData).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            // alert('23343')
            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>