src/views/procurementManagement/purchaseReturnOrder/New.vue
@@ -3,8 +3,10 @@
    <el-dialog
        v-model="isShow"
        title="新增采购退货"
        width="1600"
        width="70%"
        top="3vh"
        @close="closeModal"
        class="purchase-return-dialog"
    >
      <el-form label-width="140px" :model="formState" label-position="top" ref="formRef" :inline="true">
        <div class="section-title">
@@ -54,6 +56,63 @@
            <el-option label="拒收" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item
            label="发货类型"
            prop="shippingType"
            :rules="[
                {
                  required: true,
                  message: '请选择发货类型',
                  trigger: 'change',
                }
              ]"
        >
          <el-select
              v-model="formState.shippingType"
              placeholder="请选择发货类型"
              style="width: 240px"
              @change="handleShippingTypeChange"
          >
            <el-option label="货车" :value="1" />
            <el-option label="快递" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item
            v-if="formState.shippingType === 1"
            label="发货车牌号"
            prop="truckPlateNo"
        >
          <el-input
              v-model="formState.truckPlateNo"
              placeholder="请输入发货车牌号"
              style="width: 240px"
          />
        </el-form-item>
        <template v-else-if="formState.shippingType === 2">
          <el-form-item
              label="快递公司"
              prop="expressCompany"
          >
            <el-input
                v-model="formState.expressCompany"
                placeholder="请输入快递公司"
                style="width: 240px"
            />
          </el-form-item>
          <el-form-item
              label="快递单号"
              prop="expressNo"
          >
            <el-input
                v-model="formState.expressNo"
                placeholder="请输入快递单号"
                style="width: 240px"
            />
          </el-form-item>
        </template>
        <el-form-item
            label="供应商名称"
@@ -221,18 +280,19 @@
          <el-input style="width: 240px" v-model="formState.remark" :rows="1" type="textarea" placeholder="请输入备注"/>
        </el-form-item>
        <div style="margin: 20px 0;">
        <div style="margin:20px 0;min-width:0;">
            <div class="section-title">
              <span class="title-dot"></span>
              <span class="title-text">产品列表</span>
            </div>
            <el-button type="primary" size="small" style="margin-bottom: 20px" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">添加产品</el-button>
            <el-table :data="formState.purchaseReturnOrderProductsDtos"
            <el-button type="primary" size="small" style="margin-bottom:20px" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">添加产品</el-button>
            <el-table
                      :data="formState.purchaseReturnOrderProductsDtos"
                      border
                      max-height="400"
                      :scroll-y="true"
                      show-summary
                      :summary-method="summarizeChildrenTable">
                      :summary-method="summarizeChildrenTable"
                      style="width:100%;min-width:0;">
              <el-table-column align="center"
                               type="selection"
                               width="55" />
@@ -240,6 +300,12 @@
                               label="序号"
                               type="index"
                               width="60" />
              <el-table-column label="入库单号"
                               prop="inboundBatches"
                               width="150" />
              <el-table-column label="批次号"
                               prop="batchNo"
                               width="150" />
              <el-table-column label="产品大类"
                               prop="productCategory" />
              <el-table-column label="规格型号"
@@ -248,11 +314,20 @@
                               prop="unit"
                               width="70" />
              <el-table-column label="数量"
                               prop="quantity"
                               prop="stockInNum"
                               width="100" />
              <el-table-column label="销售发货数量"
                               prop="saleOutQuantity"
                               width="120" />
                               <el-table-column label="可退货数量"
                               prop="availableQuality"
                               prop="unQuantity"
                               width="130" />
              <el-table-column label="已退货数量"
                               width="130">
                <template #default="scope">
                  {{ formattedNumber(scope.row, null, scope.row.totalReturnNum || 0) }}
                </template>
              </el-table-column>
              <el-table-column label="退货数量"
                               prop="returnQuantity"
                               width="180">
@@ -268,27 +343,27 @@
                            placeholder="请输入退货数量" />
                </template>
              </el-table-column>
              <el-table-column label="库存预警数量"
              <!-- <el-table-column label="库存预警数量"
                               prop="warnNum"
                               width="120"
                               show-overflow-tooltip />
              <el-table-column label="税率(%)"
                               prop="taxRate"
                               width="80" />
                               width="80" /> -->
              <el-table-column label="含税单价(元)"
                               prop="taxInclusiveUnitPrice"
                               :formatter="formattedNumber"
                               width="150" />
                               width="120" />
              <el-table-column label="退货总价(元)"
                               prop="taxInclusiveTotalPrice"
                               width="180">
                               width="120">
                <template #default="scope">
                  {{ formatAmount(getReturnTotal(scope.row)) || '--' }}
                </template>
              </el-table-column>
              <el-table-column label="是否质检"
                               prop="isChecked"
                               width="150">
                               width="100">
                <template #default="scope">
                  <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
                    {{ scope.row.isChecked ? '是' : '否' }}
@@ -405,12 +480,9 @@
<script setup>
import {ref, computed, getCurrentInstance, watch, defineAsyncComponent} from "vue";
import {createPurchaseReturnOrder} from "@/api/procurementManagement/purchase_return_order.js";
import {getOptions, purchaseList} from "@/api/procurementManagement/procurementLedger.js";
import {getOptions, purchaseReturnableList} from "@/api/procurementManagement/procurementLedger.js";
import {userListNoPageByTenantId} from "@/api/system/user.js";
const ProductList = defineAsyncComponent(() => import("@/views/procurementManagement/purchaseReturnOrder/ProductList.vue"));
  import {
    productList,
  } from "@/api/procurementManagement/procurementLedger.js";
const props = defineProps({
  visible: {
    type: Boolean,
@@ -443,6 +515,10 @@
  no: '',
  isDefaultNo: true,
  returnType: 0,
  shippingType: undefined,
  truckPlateNo: '',
  expressCompany: '',
  expressNo: '',
  incomeType: undefined,
  remark: '',
  supplierId: undefined,
@@ -488,6 +564,19 @@
const purchaseLedgerOptions = ref([])
// 是否展示产品列表数据
const isShowProductsModal = ref(false)
const handleShippingTypeChange = (val) => {
  if (val === 1) {
    formState.value.expressCompany = '';
    formState.value.expressNo = '';
  } else if (val === 2) {
    formState.value.truckPlateNo = '';
  } else {
    formState.value.truckPlateNo = '';
    formState.value.expressCompany = '';
    formState.value.expressNo = '';
  }
};
const isShow = computed({
  get() {
@@ -553,7 +642,7 @@
}
const getReturnQtyMax = (row) => {
  const max = Number(row?.availableQuality)
  const max = Number(row?.unQuantity)
  if (Number.isNaN(max) || max < 0) {
    return 0
  }
@@ -561,6 +650,10 @@
}
const closeModal = () => {
  formState.value.shippingType = undefined;
  formState.value.truckPlateNo = '';
  formState.value.expressCompany = '';
  formState.value.expressNo = '';
  isShow.value = false;
};
@@ -568,17 +661,17 @@
  return proxy.summarizeTable(
      param,
      [
        "quantity",
        "availableQuality",
        "stockInNum",
        "unQuantity",
        "returnQuantity",
        "taxInclusiveUnitPrice",
        "taxInclusiveTotalPrice",
        "taxExclusiveTotalPrice",
      ],
      {
        quantity: { noDecimal: true }, // 不保留小数
        stockInNum: { noDecimal: true }, // 不保留小数
        returnQuantity: { noDecimal: true }, // 不保留小数
        availableQuality: { noDecimal: true }, // 不保留小数
        unQuantity: { noDecimal: true }, // 不保留小数
      }
  );
};
@@ -654,26 +747,16 @@
const fetchPurchaseLedgerOptions = () => {
  purchaseLedgerOptions.value = []
  if (formState.value.supplierId) {
    purchaseList({supplierId: formState.value.supplierId,approvalStatus:3}).then((res) => {
    purchaseReturnableList({ supplierId: formState.value.supplierId }).then((res) => {
      purchaseLedgerOptions.value = res.rows;
    });
  }
}
// 处理改变采购台账数据
const handleChangePurchaseLedgerId = async () => {
// 处理改变采购台账数据(不请求接口回显产品,产品仅在「添加产品」弹窗勾选后写入)
const handleChangePurchaseLedgerId = () => {
  resetFeeInfo()
  if (!formState.value.purchaseLedgerId) {
    formState.value.purchaseReturnOrderProductsDtos = []
    return
  }
  const res = await productList({ salesLedgerId: formState.value.purchaseLedgerId, type: 2 });
  formState.value.purchaseReturnOrderProductsDtos = res.data.map(item => ({
    ...item,
    returnQuantity: undefined,
    taxInclusiveTotalPrice: 0,
    salesLedgerProductId: item.id,
  }))
  formState.value.purchaseReturnOrderProductsDtos = []
  syncTotalAmount()
}
@@ -691,7 +774,7 @@
    ...item,
    returnQuantity: undefined,
    taxInclusiveTotalPrice: 0,
    salesLedgerProductId: item.id,
    // salesLedgerProductId: item.salesLedgerProductId,
  }));
  formState.value.purchaseReturnOrderProductsDtos.push(...newProducts);
  syncTotalAmount()
@@ -717,7 +800,7 @@
  // 逐行校验退货数量:任意一行未填/非法/超限都不允许提交
  const invalidRowIndex = productList.findIndex((item) => {
    const qty = Number(item.returnQuantity)
    const maxQty = Number(item.availableQuality)
    const maxQty = Number(item.unQuantity)
    if (item.returnQuantity === null || item.returnQuantity === undefined || item.returnQuantity === "") {
      return true
@@ -738,7 +821,15 @@
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      createPurchaseReturnOrder(formState.value).then(res => {
      console.log(productList)
      const submitPayload = {
        ...formState.value,
        purchaseReturnOrderProductsDtos: productList.map((row) => ({
          ...row,
          stockInRecordId: row.id,
        })),
      }
      createPurchaseReturnOrder(submitPayload).then(res => {
        // 关闭模态框
        isShow.value = false;
        // 告知父组件已完成
@@ -785,4 +876,6 @@
  border-radius: 50%;
  margin-right: 8px;
}
</style>
</style>