zhangherong
18 小时以前 4dfd11f526b7b4fe578561a9ea4c27a24a88acb4
src/views/mes/modules/MesMaterialTransferRequestForm.vue
@@ -9,33 +9,44 @@
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="起始库存地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="originalWarehouseId">
              <j-dict-select-tag type="list" v-model="model.originalWarehouseId" dictCode="original_warehouse_list" placeholder="请选择起始库存地点" />
            <a-form-model-item label="起始库存地点" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="originalWarehouseId">
              <j-dict-select-tag type="list" v-model="model.originalWarehouseId" dictCode="original_warehouse_list"
                                 placeholder="请选择起始库存地点" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="任务号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOrderId">
              <a-input v-model="model.workOrderId" placeholder="请输入工单ID"  ></a-input>
            <a-form-model-item label="任务号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOrderCode">
              <work-order-select-modal :workOrder="workOrderObj" :submitDisabled="formDisabled"
                                       orderStatus="PUBLISHED" @ok="selectConfirm"></work-order-select-modal>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="目标库存地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="targetWarehouseId">
              <a-input v-model="model.targetWarehouseId" placeholder="自动获取" readOnly ></a-input>
            <a-form-model-item label="目标库存地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="warehouseName">
              <a-input v-model="model.warehouseName" placeholder="自动获取" readOnly></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="拉动类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialTransferCategory">
              <j-dict-select-tag type="list" v-model="model.materialTransferCategory" dictCode="material_transfer_category" placeholder="请选择拉动类型" />
            <a-form-model-item label="拉动类型" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="materialTransferCategory">
              <j-dict-select-tag type="list" v-model="model.materialTransferCategory"
                                 dictCode="material_transfer_category" placeholder="请选择拉动类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="最晚配送时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latestDeliveryTime">
              <j-date placeholder="请选择最晚配送时间"  v-model="model.latestDeliveryTime" :show-time="false" date-format="YYYY-MM-DD" style="width: 100%" />
            <a-form-model-item label="最晚配送时间" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="latestDeliveryTime">
              <a-date-picker placeholder="请选择最晚配送时间" v-model="model.latestDeliveryTime"
                             value-format="YYYY-MM-DD" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="拉动物料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialNumber">
              <j-dict-select-tag type="list" v-model="model.materialNumber" dictCode="priority" placeholder="请选择拉动物料" />
              <a-select v-model="model.materialNumber" placeholder="请选择拉动物料" @change="handleMaterialNumberChange">
                <a-select-option v-for="item in materialList" :value="item.materialNumber" :title="item.materialName" :key="item.materialNumber">
                  {{ item.materialName }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
@@ -51,104 +62,188 @@
<script>
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
import { getAction, httpAction } from '@/api/manage'
import WorkOrderSelectModal from '@/views/mes/modules/WorkOrderSelectModal.vue'
import moment from 'moment'
  export default {
    name: 'MesMaterialTransferRequestForm',
    components: {
export default {
  name: 'MesMaterialTransferRequestForm',
  components: {
    WorkOrderSelectModal
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        originalWarehouseId: [
          { required: true, message: '起始库存地点必选', trigger: 'change' }
        ],
        workOrderCode: [
          { required: true, message: '任务号必选', trigger: 'change' }
        ],
        materialNumber: [
          { required: true, message: '拉动物料必选', trigger: 'change' }
        ],
        specifiedQuantity: [
          { required: true, message: '拉动数量必填', trigger: 'change' }
        ],
        materialTransferCategory: [
          { required: true, message: '拉动类型必选', trigger: 'change' }
        ]
      },
      url: {
        add: '/mes/mesMaterialTransferRequest/add',
        edit: '/mes/mesMaterialTransferRequest/edit',
        queryById: '/mes/mesMaterialTransferRequest/queryById',
        queryByMaterialNumber: '/pms/processBillMaterialsDetail/queryByMaterialNumber',
        queryByFactoryId: '/base/lineSideWarehouse/queryByFactoryId',
        workOrderQuery: '/mes/mesProductionWorkOrder/queryById'
      },
      materialList: [], //物料列表
      workOrderObj: {}, //工单对象
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.modelDefault.latestDeliveryTime = moment()
      this.edit(this.modelDefault)
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          originalWarehouseId: [
            { required: true, message: '起始库存地点必选', trigger: 'change' }
          ],
          workOrderId: [
            { required: true, message: '任务号必选', trigger: 'change' }
          ],
          materialNumber: [
            { required: true, message: '拉动物料必选', trigger: 'change' }
          ],
          specifiedQuantity: [
            { required: true, message: '拉动数量必填', trigger: 'change' }
          ],
          materialTransferCategory: [
            { required: true, message: '拉动类型必选', trigger: 'change' }
          ],
        },
        url: {
          add: "/mes/mesMaterialTransferRequest/add",
          edit: "/mes/mesMaterialTransferRequest/edit",
          queryById: "/mes/mesMaterialTransferRequest/queryById"
    async edit(record) {
      this.model = Object.assign({}, record)
      this.model.workOrderCode = this.model.workOrderId_dictText
      this.visible = true
      if (this.model.workOrderId) {
        let workOrderRes = await this.loadProductionWorkOrder(this.model.workOrderId)
        if(!workOrderRes.success || !workOrderRes.result) {
          return;
        }
        //排产工单赋值
        this.workOrderObj = Object.assign({}, workOrderRes.result);
        //物料列表
        let materialListRes = await this.loadMaterialList(workOrderRes.result.materialNumber)
        if (materialListRes.success && materialListRes.result && materialListRes.result.length > 0) {
          this.materialList = [...materialListRes.result]
        } else {
          this.materialList = []
        }
        //目标库存地
        let warehouseRes = await this.loadLineWarehouse(workOrderRes.result.factoryId)
        if (warehouseRes.success && warehouseRes.result) {
          this.$set(this.model, 'targetWarehouseId', warehouseRes.result.id)
          this.$set(this.model, 'warehouseName', warehouseRes.result.warehouseName)
        } else {
          this.model.targetWarehouseId = undefined
          this.model.warehouseName = ''
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    async selectConfirm(rows) {
      if (rows && rows.length > 0) {
        //清空关联数据
        this.model.materialNumber = undefined;
        this.model.materialName = '';
        this.model.specifiedQuantity = 0;
        //赋值新的数据
        this.model.workOrderId = rows[0].id
        this.model.workOrderCode = rows[0].workOrderCode
        //排产工单赋值
        this.workOrderObj = Object.assign({}, rows[0]);
        let materialListRes = await this.loadMaterialList(rows[0].materialNumber)
        if (materialListRes.success && materialListRes.result && materialListRes.result.length > 0) {
          this.materialList = [...materialListRes.result]
        } else {
          this.materialList = []
        }
        let warehouseRes = await this.loadLineWarehouse(rows[0].factoryId)
        if (warehouseRes.success && warehouseRes.result) {
          this.$set(this.model, 'targetWarehouseId', warehouseRes.result.id)
          this.$set(this.model, 'warehouseName', warehouseRes.result.warehouseName)
        } else {
          this.model.targetWarehouseId = undefined
          this.model.warehouseName = ''
        }
      } else {
        //清空关联数据
        this.model.materialNumber = undefined;
        this.model.materialName = '';
        this.model.specifiedQuantity = 0;
        this.materialList = []
        this.model.targetWarehouseId = undefined
        this.model.warehouseName = ''
        this.workOrderObj = {};
      }
    },
    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;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.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){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.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) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
        })
      },
      })
    },
    loadMaterialList(materialNumber) {
      return getAction(this.url.queryByMaterialNumber, { materialNumber: materialNumber })
    },
    loadLineWarehouse(factoryId) {
      return getAction(this.url.queryByFactoryId, { factoryId: factoryId })
    },
    loadProductionWorkOrder(workOrderId) {
      return getAction(this.url.workOrderQuery, { id: workOrderId })
    },
    handleMaterialNumberChange(val) {
      let find = this.materialList.find(item => item.materialNumber === val)
      if (find) {
        this.model.materialName = find.materialName
      }
      this.model.specifiedQuantity = 0
    }
  }
}
</script>