| | |
| | | import { |
| | | afterSalesServiceAdd, |
| | | afterSalesServiceUpdate, |
| | | getAllCustomerList, |
| | | getSalesLedger, |
| | | } from "@/api/customerService/index.js"; |
| | | import { ledgerListNoPage, productList as getSalesLedgerProductList } from "@/api/salesManagement/salesLedger.js"; |
| | | import { getCurrentDate } from "@/utils/index.js"; |
| | | const { proxy } = getCurrentInstance(); |
| | | const emit = defineEmits(["close"]); |
| | |
| | | .filter(item => item !== undefined && item !== null && item !== ""); |
| | | }); |
| | | |
| | | const associatedSalesOrderNumberOptions = ref([]); |
| | | // 当前销售单号下的产品池,供“选择产品”弹窗使用 |
| | | const salesLedgerProducts = ref([]); |
| | | |
| | | const loadSalesLedgerOptions = customerId => { |
| | | if (!customerId) { |
| | | associatedSalesOrderNumberOptions.value = []; |
| | | return Promise.resolve([]); |
| | | } |
| | | return getSalesLedger({ customerId }).then(res => { |
| | | const records = res?.code === 200 ? res.data?.records || [] : []; |
| | | associatedSalesOrderNumberOptions.value = records.map(item => ({ |
| | | label: item.salesContractNo, |
| | | value: item.salesContractNo, |
| | | id: item.id, |
| | | })); |
| | | return records; |
| | | }); |
| | | }; |
| | | |
| | | const loadSalesLedgerProducts = salesLedgerId => { |
| | | if (!salesLedgerId) { |
| | | salesLedgerProducts.value = []; |
| | | return Promise.resolve([]); |
| | | } |
| | | return getSalesLedgerProductList({ salesLedgerId, type: 1 }).then(res => { |
| | | const rows = Array.isArray(res?.data) ? res.data : []; |
| | | salesLedgerProducts.value = rows.map(normalizeProductRow); |
| | | return salesLedgerProducts.value; |
| | | }); |
| | | }; |
| | | |
| | | const associatedSalesOrderNumberChange = () => { |
| | | const opt = associatedSalesOrderNumberOptions.value.find( |
| | | item => item.value === form.value.salesContractNo |
| | | ); |
| | | tableData.value = (opt?.productData || []).map(normalizeProductRow); |
| | | form.value.salesLedgerId = opt?.id || null; |
| | | tableData.value = []; |
| | | loadSalesLedgerProducts(form.value.salesLedgerId).then(products => { |
| | | tableData.value = products.map(row => ({ ...row })); |
| | | }); |
| | | }; |
| | | |
| | | const associatedSalesOrderNumberOptions = ref([]); |
| | | |
| | | const currentSalesOrderProducts = computed(() => { |
| | | const opt = associatedSalesOrderNumberOptions.value.find( |
| | | item => item.value === form.value.salesContractNo |
| | | ); |
| | | return (opt?.productData || []).map(normalizeProductRow); |
| | | }); |
| | | const currentSalesOrderProducts = computed(() => salesLedgerProducts.value); |
| | | |
| | | const customerNameChange = val => { |
| | | form.value.salesContractNo = ""; |
| | | form.value.salesLedgerId = null; |
| | | tableData.value = []; |
| | | salesLedgerProducts.value = []; |
| | | associatedSalesOrderNumberOptions.value = []; |
| | | const opt = customerNameOptions.value.find(item => item.value === val); |
| | | if (opt) { |
| | | form.value.customerId = opt.id; |
| | | } else { |
| | | form.value.customerId = null; |
| | | } |
| | | getSalesLedger({ |
| | | customerId: form.value.customerId, |
| | | }).then(res => { |
| | | if (res.code === 200) { |
| | | associatedSalesOrderNumberOptions.value = res.data.records.map(item => ({ |
| | | label: item.salesContractNo, |
| | | value: item.salesContractNo, |
| | | productData: item.productData, |
| | | id: item.id, |
| | | })); |
| | | } |
| | | }); |
| | | form.value.customerId = opt ? opt.id : null; |
| | | loadSalesLedgerOptions(form.value.customerId); |
| | | }; |
| | | |
| | | const getApproveStatusText = row => { |
| | | if (!row) return "不足"; |
| | | if ( |
| | | row.approveStatus === 1 && |
| | | (!row.shippingDate || !row.shippingCarNumber) |
| | | ) { |
| | | if (row.approveStatus === 1) { |
| | | return "充足"; |
| | | } |
| | | if (row.approveStatus === 0 && (row.shippingDate || row.shippingCarNumber)) { |
| | | if (row.approveStatus === 0 && Number(row.noQuantity) === 0) { |
| | | return "已出库"; |
| | | } |
| | | return "不足"; |
| | |
| | | 审核中: "审核中", |
| | | 审核拒绝: "审核拒绝", |
| | | 审核通过: "审核通过", |
| | | 部分发货: "部分发货", |
| | | 已发货: "已发货", |
| | | }; |
| | | return map[String(status).trim()] || "待发货"; |
| | |
| | | 审核中: "warning", |
| | | 审核拒绝: "danger", |
| | | 审核通过: "success", |
| | | 部分发货: "warning", |
| | | 已发货: "success", |
| | | }; |
| | | return map[String(status).trim()] || "info"; |
| | | }; |
| | | |
| | | // 客户下拉仅展示销售台账中存在记录的客户 |
| | | const loadLedgerCustomerOptions = () => { |
| | | return ledgerListNoPage({}).then(res => { |
| | | const rows = Array.isArray(res?.data) ? res.data : []; |
| | | const seen = new Set(); |
| | | const options = []; |
| | | rows.forEach(row => { |
| | | const customerName = row?.customerName; |
| | | const customerId = row?.customerId; |
| | | if (!customerName || customerId === null || customerId === undefined) { |
| | | return; |
| | | } |
| | | if (seen.has(customerName)) return; |
| | | seen.add(customerName); |
| | | options.push({ label: customerName, value: customerName, id: customerId }); |
| | | }); |
| | | customerNameOptions.value = options; |
| | | }); |
| | | }; |
| | | |
| | | // 打开弹框 |
| | | const openDialog = async (type, row) => { |
| | | // 请求多个接口,获取数据 |
| | | let res = await getAllCustomerList({ |
| | | current: 1, |
| | | size: 1000, |
| | | total: 0, |
| | | }); |
| | | console.log(res, "res"); |
| | | |
| | | if (res.data.records) { |
| | | customerNameOptions.value = res.data.records.map(item => ({ |
| | | label: item.customerName, |
| | | value: item.customerName, |
| | | id: item.id, |
| | | })); |
| | | } else { |
| | | } |
| | | await loadLedgerCustomerOptions(); |
| | | |
| | | operationType.value = type; |
| | | dialogFormVisible.value = true; |
| | |
| | | // 新增时清空已选关联产品 |
| | | if (type === "add") { |
| | | tableData.value = []; |
| | | salesLedgerProducts.value = []; |
| | | associatedSalesOrderNumberOptions.value = []; |
| | | } |
| | | userListNoPageByTenantId().then(res => { |
| | | userList.value = res.data; |
| | | }); |
| | | if (type === "edit") { |
| | | form.value = { ...row }; |
| | | if (form.value.customerName) { |
| | | const res = await getSalesLedger({ |
| | | customerId: form.value.customerId, |
| | | }); |
| | | if (res?.code === 200) { |
| | | console.log(res); |
| | | associatedSalesOrderNumberOptions.value = (res.data?.records || []).map( |
| | | item => ({ |
| | | label: item.salesContractNo, |
| | | value: item.salesContractNo, |
| | | productData: item.productData, |
| | | id: item.id, |
| | | }) |
| | | ); |
| | | const opt = associatedSalesOrderNumberOptions.value.find( |
| | | item => item.value === form.value.salesContractNo |
| | | ); |
| | | if (opt) { |
| | | let restoredData = (opt.productData || []).map(normalizeProductRow); |
| | | const selectedIds = form.value.productModelIds ? String(form.value.productModelIds).split(",") : []; |
| | | const quantities = form.value.productModelQuantities ? String(form.value.productModelQuantities).split(",") : []; |
| | | tableData.value = restoredData.filter(item => selectedIds.includes(String(item.id))).map(item => { |
| | | let qIndex = selectedIds.indexOf(String(item.id)); |
| | | if (qIndex !== -1 && qIndex < quantities.length && quantities[qIndex] !== "") { |
| | | item.quantity = Number(quantities[qIndex]); |
| | | } |
| | | return item; |
| | | }); |
| | | } |
| | | } |
| | | // 售后单只存了客户名称,这里按名称反查客户 ID |
| | | if (!form.value.customerId && form.value.customerName) { |
| | | const customer = customerNameOptions.value.find( |
| | | item => item.value === form.value.customerName |
| | | ); |
| | | form.value.customerId = customer?.id ?? null; |
| | | } |
| | | console.log(form.value); |
| | | await loadSalesLedgerOptions(form.value.customerId); |
| | | const products = await loadSalesLedgerProducts(form.value.salesLedgerId); |
| | | const selectedIds = form.value.productModelIds |
| | | ? String(form.value.productModelIds).split(",") |
| | | : []; |
| | | const quantities = form.value.productModelQuantities |
| | | ? String(form.value.productModelQuantities).split(",") |
| | | : []; |
| | | tableData.value = products |
| | | .filter(item => selectedIds.includes(String(item.id))) |
| | | .map(item => { |
| | | const qIndex = selectedIds.indexOf(String(item.id)); |
| | | if ( |
| | | qIndex !== -1 && |
| | | qIndex < quantities.length && |
| | | quantities[qIndex] !== "" |
| | | ) { |
| | | item.quantity = Number(quantities[qIndex]); |
| | | } |
| | | return item; |
| | | }); |
| | | } |
| | | }; |
| | | const submitForm = () => { |