ShipmentHeaderModal.vue 6.07 KB
<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="type">
              <a-select
                show-search
                placeholder="请选择单据类型"
                option-filter-prop="children"
                v-model="model.type">
                <a-select-option v-for="item in shipmentTypeList" :key="item.name" :value="item.code">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="项目号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="project">
              <a-input v-model="model.project" placeholder="请输入项目号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="planType">
              <j-dict-select-tag type="list" v-model="model.planType" dictCode="plan_type" placeholder="请选择计划类型"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机台号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machineCode">
              <j-dict-select-tag type="list" v-model="model.machineCode" dictCode="machine_code" placeholder="请选择机台号"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCode">
              <j-search-select-tag v-model="model.materialCode" dict="material,spec,code" placeholder="请选择物料编码" :pageSize="10" :async="true"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开线数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lineQty">
              <a-input-number v-model="model.lineQty" placeholder="请输入开线数量" style="width: 100%"></a-input-number>
            </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 { getCompanyList, getZoneList } from '@/api/api'
import { getShipmentTypeList } from '@/api/api'
import { getCustomerList } from '@/api/api'
import { searchMaterialByCode } from '@/api/api'

export default {
  name: "ShipmentHeaderModal",
  components: {},
  data() {
    return {
      querySource: {},
      companyList: [],
      shipmentTypeList: [],
      customerList: [],
      zoneList: [],
      materialList: {},
      title: "操作",
      width: 800,
      visible: false,
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },

      confirmLoading: false,
      validatorRules: {
        project: [
          {required: true, message: '请输入项目号!'},
        ],
        planType: [
          {required: true, message: '请选择计划类型!'},
        ],
        machineCode: [
          {required: true, message: '请选择机台号!'},
        ],
        materialCode: [
          { required: true, message: '请选择物料编码!' }
        ],
        lineQty: [
          { required: true, message: '请输入开线数量!' }
        ],
      },
      url: {
        add: "/shipment/shipmentHeader/addLinePlanning",
        edit: "/shipment/shipmentHeader/edit",
      }

    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.loadFrom()
    this.searchMaterial()
  },
  methods: {
    searchMaterial() {
      this.querySource.materialCode = this.model.materialCode
      searchMaterialByCode(this.querySource).then(res => {
        this.materialList = res.result
      })
    },
    add() {
      let record = {companyCode: this.companyList[0].code, type: this.shipmentTypeList[0].code, zoneCode: this.zoneList[0].code}
      this.edit(record);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    handleOk() {
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          this.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              this.$message.success(res.message);
              this.$emit('ok');
            } else {
              this.$message.warning(res.message);
            }
          }).finally(() => {
            this.confirmLoading = false;
            this.close();
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    loadFrom() {
      getCompanyList().then((res) => {
        if (res.success) {
          this.companyList = res.result
        }
      });
      getShipmentTypeList().then((res) => {
        if (res.success) {
          this.shipmentTypeList = res.result
        }
      });
      getCustomerList().then((res) => {
        if (res.success) {
          this.customerList = res.result
        }
      });
      getZoneList().then((res) => {
        if (res.success) {
          this.zoneList = res.result
        }
      });
    },
  }
}
</script>