yyb
7 天以前 e43e196b3cde5ca76c2bca07045c112921963779
其他金额维护弹窗
已修改1个文件
282 ■■■■■ 文件已修改
src/views/salesManagement/salesLedger/index.vue 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/index.vue
@@ -30,6 +30,9 @@
          <el-button type="primary" @click="openForm('add')">
            新增台账
          </el-button>
          <el-button type="primary" plain @click="openOtherAmountDialog">
            其他金额维护
          </el-button>
          <el-button type="primary" plain @click="handleImport">导入</el-button>
          <el-button @click="handleOut">导出</el-button>
          <el-button type="danger" plain @click="handleDelete">删除</el-button>
@@ -647,6 +650,115 @@
                </div>
            </template>
        </el-dialog>
        <!-- 其他金额维护(新增/编辑/删除) -->
        <el-dialog
            v-model="otherAmountDialogVisible"
            title="其他金额维护"
            width="80%"
            :close-on-click-modal="false"
            @close="closeOtherAmountDialog"
        >
            <el-row :gutter="20">
                <el-col :span="14">
                    <el-table
                        :data="otherAmountRecords"
                        border
                        v-loading="otherAmountLoading"
                        height="55vh"
                    >
                        <el-table-column label="编码" prop="code" min-width="120" show-overflow-tooltip />
                        <el-table-column label="项目" prop="processName" min-width="180" show-overflow-tooltip />
                        <el-table-column label="数量" prop="quantity" min-width="110" :formatter="formattedNumber" />
                        <el-table-column label="单价(元)" prop="unitPrice" min-width="130" :formatter="formattedNumber" />
                        <el-table-column label="金额(元)" prop="amount" min-width="160" :formatter="formattedNumber" />
                        <el-table-column fixed="right" label="操作" width="160" align="center">
                            <template #default="scope">
                                <el-button link type="primary" size="small" @click="handleOtherEdit(scope.row)">编辑</el-button>
                                <el-button link type="danger" size="small" @click="handleOtherDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <pagination
                        v-show="otherAmountTotal > 0"
                        :total="otherAmountTotal"
                        layout="total, sizes, prev, pager, next, jumper"
                        :page="otherAmountPage.current"
                        :limit="otherAmountPage.size"
                        @pagination="otherAmountPaginationChange"
                    />
                </el-col>
                <el-col :span="10">
                    <div style="padding: 8px 0;">
                        <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 10px;">
                            <div style="font-weight:600;">
                                {{ otherAmountOperationType === 'add' ? '新增其他金额' : '编辑其他金额' }}
                            </div>
                            <el-button
                                type="primary"
                                plain
                                size="small"
                                @click="handleOtherAdd"
                                :disabled="otherAmountOperationType === 'add'"
                            >
                                新增
                            </el-button>
                        </div>
                        <el-form
                            :model="otherAmountForm"
                            label-width="120px"
                            label-position="top"
                            :rules="otherAmountRules"
                            ref="otherAmountFormRef"
                        >
                            <el-form-item label="编码code">
                                <el-input v-model="otherAmountForm.code" placeholder="请输入编码(可选)" clearable />
                            </el-form-item>
                            <el-form-item label="项目processName" prop="processName">
                                <el-input v-model="otherAmountForm.processName" placeholder="请输入项目名称" clearable />
                            </el-form-item>
                            <el-form-item label="数量quantity" prop="quantity">
                                <el-input-number
                                    v-model="otherAmountForm.quantity"
                                    :min="0"
                                    :precision="2"
                                    style="width:100%"
                                    placeholder="请输入数量"
                                    clearable
                                    @change="recalcOtherAmount"
                                />
                            </el-form-item>
                            <el-form-item label="单价unitPrice(元)" prop="unitPrice">
                                <el-input-number
                                    v-model="otherAmountForm.unitPrice"
                                    :min="0"
                                    :precision="2"
                                    style="width:100%"
                                    placeholder="请输入单价"
                                    clearable
                                    @change="recalcOtherAmount"
                                />
                            </el-form-item>
                            <el-form-item label="金额amount(元)">
                                <el-input v-model="otherAmountForm.amount" disabled />
                            </el-form-item>
                            <div style="display:flex; justify-content:flex-end; gap: 10px; margin-top: 8px;">
                                <el-button @click="closeOtherAmountDialog">取消</el-button>
                                <el-button type="primary" @click="submitOtherAmountForm">保存</el-button>
                            </div>
                        </el-form>
                    </div>
                </el-col>
            </el-row>
        </el-dialog>
    </div>
</template>
@@ -671,7 +783,12 @@
    delLedger,
    addOrUpdateSalesLedgerProduct,
    delProduct,
    delLedgerFile, getProductInventory,
    delLedgerFile,
    getProductInventory,
    salesLedgerProductProcessList,
    salesLedgerProductProcessAdd,
    salesLedgerProductProcessUpdate,
    salesLedgerProductProcessDelete,
} from "@/api/salesManagement/salesLedger.js";
import { modelList, productTreeList } from "@/api/basicData/product.js";
import useFormData from "@/hooks/useFormData.js";
@@ -810,6 +927,169 @@
});
const { deliveryForm, deliveryRules } = toRefs(deliveryFormData);
// 其他金额维护(工序/流程金额维护)
const otherAmountDialogVisible = ref(false);
const otherAmountLoading = ref(false);
const otherAmountRecords = ref([]);
const otherAmountTotal = ref(0);
const otherAmountPage = reactive({
    current: 1,
    size: 10,
});
const otherAmountOperationType = ref("add"); // add/edit
const otherAmountFormRef = ref(null);
const otherAmountForm = reactive({
    id: null,
    code: "", // 前端字段名:code;后端接口列表返回 remark,此处进行映射
    processName: "",
    quantity: 0,
    unitPrice: 0,
    amount: "0.00",
});
const otherAmountRules = reactive({
    processName: [{ required: true, message: "请输入项目名称", trigger: "change" }],
    quantity: [{ required: true, message: "请输入数量", trigger: "blur" }],
    unitPrice: [{ required: true, message: "请输入单价", trigger: "blur" }],
});
const recalcOtherAmount = () => {
    const quantity = Number(otherAmountForm.quantity ?? 0) || 0;
    const unitPrice = Number(otherAmountForm.unitPrice ?? 0) || 0;
    otherAmountForm.amount = (quantity * unitPrice).toFixed(2);
};
const resetOtherAmountForm = (type = "add") => {
    otherAmountOperationType.value = type;
    otherAmountForm.id = null;
    otherAmountForm.code = "";
    otherAmountForm.processName = "";
    otherAmountForm.quantity = 0;
    otherAmountForm.unitPrice = 0;
    otherAmountForm.amount = "0.00";
};
const openOtherAmountDialog = () => {
    otherAmountDialogVisible.value = true;
    resetOtherAmountForm("add");
    // 打开弹框时刷新数据,避免长时间停留导致数据过期
    otherAmountPage.current = otherAmountPage.current || 1;
    fetchOtherAmountList();
};
const closeOtherAmountDialog = () => {
    otherAmountDialogVisible.value = false;
    resetOtherAmountForm("add");
};
const fetchOtherAmountList = async () => {
    otherAmountLoading.value = true;
    try {
        const params = {
            current: otherAmountPage.current,
            size: otherAmountPage.size,
        };
        const res = await salesLedgerProductProcessList(params);
        // 兼容不同接口响应结构:可能是 res.records / res.total 或 res.data.records / res.data.total
        const records = res?.records ?? res?.data?.records ?? [];
        const total = res?.total ?? res?.data?.total ?? 0;
        otherAmountRecords.value = records.map((item) => {
            const quantity = Number(item.quantity ?? 0) || 0;
            const unitPrice = Number(item.unitPrice ?? 0) || 0;
            const amount = Number(item.amount ?? quantity * unitPrice) || 0;
            return {
                id: item.id,
                code: item.code ?? item.remark ?? "",
                processName: item.processName ?? "",
                quantity,
                unitPrice,
                amount: amount.toFixed(2),
            };
        });
        otherAmountTotal.value = total;
    } finally {
        otherAmountLoading.value = false;
    }
};
const otherAmountPaginationChange = (obj) => {
    otherAmountPage.current = obj.page;
    otherAmountPage.size = obj.limit;
    fetchOtherAmountList();
};
const handleOtherAdd = () => {
    resetOtherAmountForm("add");
};
const handleOtherEdit = (row) => {
    if (!row) return;
    otherAmountOperationType.value = "edit";
    otherAmountForm.id = row.id ?? null;
    otherAmountForm.code = row.code ?? "";
    otherAmountForm.processName = row.processName ?? "";
    otherAmountForm.quantity = Number(row.quantity ?? 0) || 0;
    otherAmountForm.unitPrice = Number(row.unitPrice ?? 0) || 0;
    recalcOtherAmount();
};
const submitOtherAmountForm = () => {
    otherAmountFormRef.value?.validate((valid) => {
        if (!valid) return;
        const payload = {
            processName: otherAmountForm.processName,
            quantity: Number(otherAmountForm.quantity) || 0,
            unitPrice: Number(otherAmountForm.unitPrice) || 0,
            amount: Number(otherAmountForm.amount) || 0,
            // 列表返回字段是 remark,这里按“code=remark”做映射
            remark: otherAmountForm.code,
            // 兼容后端可能直接使用 code 字段
            code: otherAmountForm.code,
        };
        if (otherAmountOperationType.value === "edit") {
            payload.id = otherAmountForm.id;
            salesLedgerProductProcessUpdate(payload).then(() => {
                proxy.$modal.msgSuccess("保存成功");
                fetchOtherAmountList();
                resetOtherAmountForm("add");
            });
        } else {
            salesLedgerProductProcessAdd(payload).then(() => {
                proxy.$modal.msgSuccess("保存成功");
                fetchOtherAmountList();
                resetOtherAmountForm("add");
            });
        }
    });
};
const handleOtherDelete = (row) => {
    if (!row?.id) return;
    ElMessageBox.confirm("确认删除该记录?", "删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
    })
        .then(() => {
            return salesLedgerProductProcessDelete(row.id).then(() => {
                proxy.$modal.msgSuccess("删除成功");
                fetchOtherAmountList();
                if (otherAmountOperationType.value === "edit" && otherAmountForm.id === row.id) {
                    resetOtherAmountForm("add");
                }
            });
        })
        .catch(() => {
            proxy.$modal.msg("已取消");
        });
};
// 发货审批人节点(仿协同审批 infoFormDia.vue)
const approverNodes = ref([{ id: 1, userId: null }]);
let nextApproverId = 2;