gaoluyang
5 天以前 787ccc59ba89bacc075562a161ecf02bc76ebadc
src/views/erp/sale/order/modules/item-form.vue
@@ -1,5 +1,4 @@
<script lang="ts" setup>
import type { MdmItemApi } from '#/api/mdm/item';
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
import { computed, nextTick, onMounted, ref, watch } from 'vue';
@@ -10,11 +9,10 @@
  erpPriceMultiply,
} from '@vben/utils';
import { Input, InputNumber, Select } from 'ant-design-vue';
import { Input, InputNumber, Select, Tag } from 'ant-design-vue';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getItemPage } from '#/api/mdm/item';
import { getStockCount } from '#/api/erp/stock/stock';
import { MdmItemSelect } from '#/views/basicData/mdm/components';
import { useFormItemColumns } from '../data';
@@ -36,8 +34,7 @@
  'update:totalPrice',
]);
const tableData = ref<ErpSaleOrderApi.SaleOrderItem[]>([]); // 表格数据
const productOptions = ref<MdmItemApi.Item[]>([]); // 物料下拉选项
const tableData = ref<ErpSaleOrderApi.SaleOrderItem[]>([]);
/** 获取表格合计数据 */
const summaries = computed(() => {
@@ -124,8 +121,7 @@
  const newRow = {
    id: undefined,
    productId: undefined,
    productUnitName: undefined, // 产品单位
    productBarCode: undefined, // 产品条码
    productUnitName: undefined,
    productPrice: undefined,
    stockCount: undefined,
    count: 1,
@@ -134,6 +130,7 @@
    taxPrice: undefined,
    totalPrice: undefined,
    remark: undefined,
    needProduction: 1,
  };
  tableData.value.push(newRow);
  // 通知父组件更新
@@ -152,12 +149,11 @@
}
/** 处理产品变更 */
async function handleProductChange(productId: any, row: any) {
  const product = productOptions.value.find((p) => p.id === productId);
function handleProductChange(product: any, row: any) {
  if (!product) {
    return;
  }
  row.productId = productId;
  row.productId = product.id;
  row.productUnitId = product.unitMeasureId;
  row.productBarCode = product.barCode;
  row.productUnitName = product.unitMeasureName;
@@ -165,7 +161,6 @@
  row.productUnitName3 = product.unitMeasureName3;
  row.productSpecification = product.specification;
  row.productName = product.name;
  row.stockCount = (await getStockCount(productId)) || 0;
  row.productPrice = product.salesPrice || 0;
  row.count = row.count || 1;
  handleRowChange(row);
@@ -189,6 +184,10 @@
    row.taxPrice =
      erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
    row.totalPrice = row.totalProductPrice + row.taxPrice;
  }
  // 默认需要生产
  if (row.needProduction === undefined) {
    row.needProduction = 1;
  }
}
@@ -216,8 +215,6 @@
/** 初始化 */
onMounted(async () => {
  const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 });
  productOptions.value = res.list || [];
  // 目的:新增时,默认添加一行
  if (tableData.value.length === 0) {
    handleAdd();
@@ -228,18 +225,30 @@
<template>
  <Grid class="w-full">
    <template #productId="{ row }">
      <Select
      <MdmItemSelect
        v-if="!disabled"
        v-model:value="row.productId"
        :options="productOptions"
        :field-names="{ label: 'name', value: 'id' }"
        class="w-full"
        :model-value="row.productId"
        placeholder="请选择产品"
        show-search
        @update:model-value="row.productId = $event"
        @change="handleProductChange($event, row)"
      />
      <span v-else>{{ row.productName || '-' }}</span>
    </template>
    <template #needProduction="{ row }">
      <Select
        v-if="!disabled"
        v-model:value="row.needProduction"
        :options="[
          { label: '是', value: 1 },
          { label: '否', value: 0 },
        ]"
        class="w-full"
        placeholder="请选择"
        @change="handleRowChange(row)"
      />
      <Tag v-else-if="row.needProduction === 1" color="success">是</Tag>
      <Tag v-else color="default">否</Tag>
    </template>
    <template #count="{ row }">
      <InputNumber
        v-if="!disabled"