ReceiptDetailModal.vue 8.32 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="materialCode">
              <j-search-select-tag
                v-model="model.materialCode"
                dict="material,name,code,spec,unit,texture,qnc"
                placeholder="请选择物项编码"
                @change="selectMaterialByCode(model)"
                :pageSize="10"
                :async="true"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单据数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qty">
              <a-input-number v-model="model.qty" placeholder="请输入单据数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物项状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inventoryStatus">
              <j-dict-select-tag
                type="list"
                v-model="model.inventoryStatus"
                dictCode="inventory_status"
                placeholder="请选择物项状态"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="需求计划编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="compCode">
              <a-input v-model="model.compCode" placeholder="请输入需求计划编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batch">
              <a-input v-model="model.lot" placeholder="请输入批号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="producedDate">
              <j-date :show-date="true" date-format="YYYY-MM-DD" placeholder="请选择生产日期"
                      class="query-group-cust-1" v-model="model.producedDate"></j-date>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="保质期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expiration">
              <j-date :show-date="true" date-format="YYYY-MM-DD" placeholder="请输入保质期"
                      class="query-group-cust-1" v-model="model.expiration"></j-date>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用部位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partUsed">
              <a-input v-model="model.partUsed" placeholder="请输入使用部位"></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierName">-->
<!--              <a-select-->
<!--                show-search-->
<!--                placeholder="请选择供应商"-->
<!--                option-filter-prop="children"-->
<!--                v-model="model.supplierName">-->
<!--                <a-select-option v-for="item in supplierList" :key="item.name" :value="item.name">{{-->
<!--                    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="manufacturer">
              <a-input v-model="model.manufacturer" placeholder="请输入生产厂家"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="texture">
              <a-input v-model="texture" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="质保等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qnc">
              <a-input v-model="qnc" :disabled="true"></a-input>
            </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,
  getInventoryByShipmentDetail,
  getReceiptTypeList, getSupplierList,
  searchMaterialByCode,
  selectMaterialByCode
} from '@/api/api'

export default {
  name: 'ReceiptDetailModal',
  components: {},
  props: {
    mainId: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: '操作',
      width: 800,
      visible: false,
      materialList: {},
      querySource: {},
      model: {},
      qnc: "",
      texture: "",
      supplierList: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        materialCode: [{ required: true, message: '请输入物项编码!' }],
        qty: [{ required: true, message: '请输入单据数量!' }],
        inventoryStatus: [{ required: true, message: '请输入物项状态!' }]
      },
      url: {
        add: '/receipt/receiptHeader/addReceiptDetail',
        edit: '/receipt/receiptHeader/editReceiptDetail'
      }
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.searchMaterial()
    // this.loadFrom();
  },
  methods: {
    selectMaterialByCode(model) {
      let params = {"code": model.materialCode}
      selectMaterialByCode(params).then((res) => {
        if (res.success) {
          this.texture = res.result.texture;
          this.qnc = res.result.qnc;
        }
        this.$refs.form.validate(valid => {
        })
      })
    },
    add() {
      let record = { inventoryStatus: 'good' }
      this.edit(record)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.texture = ""
      this.qnc = ""
      this.$refs.form.clearValidate()
    },
    // loadFrom() {
    //   getSupplierList().then((res) => {
    //     if (res.success) {
    //       this.supplierList = res.result
    //     }
    //   });
    // },
    searchMaterial() {
      const that = this
      that.querySource.materialCode = that.model.materialCode
      searchMaterialByCode(that.querySource).then(res => {
        that.materialList = res.result
      })
    },
    handleOk() {
      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'
          }
          this.model['receiptId'] = this.mainId
          this.model.texture = this.texture
          this.model.qnc = this.qnc
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok');
                this.$emit('dataSearch');
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.query-group-cust-1 {
  width: calc(100%)
}
</style>