liu
8 天以前 5c124cdf26e4d749eae1e7fc9df366e9a5f4d259
src/views/crm/saleQuotation/modules/item-form.vue
@@ -2,14 +2,14 @@
import type { MdmItemApi } from '#/api/mdm/item';
import type { CrmSaleQuotationApi } from '#/api/crm/saleQuotation';
import { computed, onMounted, ref } from 'vue';
import { computed, ref } from 'vue';
import { erpPriceMultiply } from '#/packages/utils/src';
import { InputNumber, Select } from 'ant-design-vue';
import { InputNumber } from 'ant-design-vue';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getItemPage } from '#/api/mdm/item';
import MdmItemSelect from '#/views/basicData/mdm/components/select.vue';
import { useItemColumns } from '../data';
@@ -24,7 +24,7 @@
const emit = defineEmits(['change']);
const tableData = ref<CrmSaleQuotationApi.SaleQuotationItem[]>([]);
const itemOptions = ref<MdmItemApi.Item[]>([]);
const selectedItem = ref<MdmItemApi.Item>();
/** 获取表格合计数据 */
const summaries = computed(() => {
@@ -93,13 +93,23 @@
  }
}
/** 处理物料变更 */
function handleItemChange(itemId: number, row: any) {
  const item = itemOptions.value.find((p) => p.id === itemId);
/** 处理产品变更 */
function handleItemChange(item: MdmItemApi.Item | undefined, row: any) {
  if (!item) {
    row.itemId = undefined;
    row.itemName = undefined;
    row.itemCode = undefined;
    row.itemBarCode = undefined;
    row.itemSpecification = undefined;
    row.itemUnitName = undefined;
    row.itemUnitName2 = undefined;
    row.itemUnitName3 = undefined;
    row.itemPrice = undefined;
    row.quotationPrice = undefined;
    row.totalPrice = 0;
    return;
  }
  row.itemId = itemId;
  row.itemId = item.id;
  row.itemName = item.name;
  row.itemCode = item.code;
  row.itemBarCode = item.barCode;
@@ -133,7 +143,7 @@
    const item = tableData.value[i];
    if (item) {
      if (!item.itemId) {
        throw new Error(`第 ${i + 1} 行:物料不能为空`);
        throw new Error(`第 ${i + 1} 行:产品不能为空`);
      }
      if (!item.count || item.count <= 0) {
        throw new Error(`第 ${i + 1} 行:数量不能为空`);
@@ -173,25 +183,17 @@
  getData,
  resetData,
});
/** 初始化 */
onMounted(async () => {
  const res = await getItemPage({ pageNo: 1, pageSize: 100, status: 0 });
  itemOptions.value = res.list || [];
});
</script>
<template>
  <Grid class="w-full">
    <template #itemId="{ row }">
      <Select
      <MdmItemSelect
        v-if="!disabled"
        v-model:value="row.itemId"
        :options="itemOptions"
        :field-names="{ label: 'name', value: 'id' }"
        class="w-full"
        placeholder="请选择物料"
        @change="(val) => handleItemChange(val, row)"
        v-model:model-value="row.itemId"
        :label="row.itemName"
        placeholder="请选择产品"
        @change="(item) => handleItemChange(item, row)"
      />
      <span v-else>{{ row.itemName || '-' }}</span>
    </template>
@@ -224,7 +226,7 @@
            type: 'link',
            danger: true,
            popConfirm: {
              title: '确认删除该物料吗?',
              title: '确认删除该产品吗?',
              confirm: handleDelete.bind(null, row),
            },
          },
@@ -247,7 +249,7 @@
        class="mt-2 flex justify-center"
        :actions="[
          {
            label: '添加物料',
            label: '添加产品',
            type: 'default',
            onClick: handleAdd,
          },