From b58f53769f004fb0ba6b5aedf55ef602850c7c97 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 20 九月 2026 15:46:05 +0800
Subject: [PATCH] 天津豹鸣app 1.部署修改
---
src/pages/sales/contractManagement/edit.vue | 628 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 628 insertions(+), 0 deletions(-)
diff --git a/src/pages/sales/contractManagement/edit.vue b/src/pages/sales/contractManagement/edit.vue
new file mode 100644
index 0000000..9ee981b
--- /dev/null
+++ b/src/pages/sales/contractManagement/edit.vue
@@ -0,0 +1,628 @@
+<template>
+ <view class="account-detail">
+ <PageHeader :title="pageTitle"
+ @back="goBack" />
+ <view class="form-container">
+ <up-form ref="formRef"
+ :model="form"
+ :rules="rules"
+ label-width="120"
+ input-align="right"
+ error-message-align="right">
+ <u-cell-group title="鍚堝悓涓绘。"
+ class="form-section">
+ <up-form-item label="鍚堝悓缂栧彿"
+ prop="contractNo"
+ required>
+ <up-input v-model="form.contractNo"
+ placeholder="璇疯緭鍏ュ悎鍚岀紪鍙�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="绛捐鏃堕棿"
+ prop="signDate"
+ required>
+ <FormPicker v-model="form.signDate"
+ type="date"
+ placeholder="璇烽�夋嫨绛捐鏃堕棿" />
+ </up-form-item>
+ <up-form-item label="绛剧害鍗曚綅绠�绉�"
+ prop="signingUnit"
+ required>
+ <up-input v-model="form.signingUnit"
+ placeholder="璇疯緭鍏ョ绾﹀崟浣嶇畝绉�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="绛剧害鍛ㄦ湡"
+ prop="contractPeriod">
+ <up-input v-model="form.contractPeriod"
+ placeholder="璇疯緭鍏ョ绾﹀懆鏈�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="瀛樻。鐘舵��"
+ prop="archiveStatus"
+ required>
+ <FormPicker v-model="form.archiveStatus"
+ type="select"
+ title="閫夋嫨瀛樻。鐘舵��"
+ :options="ARCHIVE_STATUS_OPTIONS"
+ placeholder="璇烽�夋嫨瀛樻。鐘舵��" />
+ </up-form-item>
+ <up-form-item label="瀛樻。鎯呭喌璇存槑"
+ prop="archiveRemark">
+ <up-input v-model="form.archiveRemark"
+ placeholder="璇疯緭鍏ュ瓨妗f儏鍐佃鏄�"
+ clearable />
+ </up-form-item>
+ </u-cell-group>
+
+ <u-cell-group title="浜у搧淇℃伅"
+ class="form-section">
+ <view class="section-tools">
+ <up-button type="primary"
+ size="small"
+ text="娣诲姞浜у搧"
+ @click="addProduct" />
+ </view>
+ <view v-if="productList.length === 0"
+ class="empty-text">
+ <text>鏆傛棤浜у搧锛岃鍏堟坊鍔犱骇鍝�</text>
+ </view>
+ <view v-else
+ class="product-list">
+ <view v-for="(row, index) in productList"
+ :key="row.uid"
+ class="product-card">
+ <view class="product-header">
+ <text class="product-title">浜у搧 {{ index + 1 }}</text>
+ <up-icon name="trash"
+ color="#ee0a24"
+ size="18"
+ @click="removeProduct(index)"></up-icon>
+ </view>
+ <up-divider></up-divider>
+ <view class="product-body">
+ <up-form-item label="浜у搧澶х被">
+ <up-input v-model="row.productCategory"
+ placeholder="璇烽�夋嫨浜у搧澶х被"
+ readonly
+ @click="openCategoryPicker(index)" />
+ <template #right>
+ <up-icon name="arrow-right"
+ @click="openCategoryPicker(index)"></up-icon>
+ </template>
+ </up-form-item>
+ <up-form-item label="瑙勬牸鍨嬪彿">
+ <up-input v-model="row.specificationModel"
+ placeholder="璇烽�夋嫨瑙勬牸鍨嬪彿"
+ readonly
+ @click="openModelPicker(index)" />
+ <template #right>
+ <up-icon name="arrow-right"
+ @click="openModelPicker(index)"></up-icon>
+ </template>
+ </up-form-item>
+ <up-form-item label="鍚堝悓璁¢噺鍗曚綅">
+ <up-input v-model="row.contractUnit"
+ placeholder="璇疯緭鍏ヨ閲忓崟浣�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="鍚◣鍗曚环">
+ <up-input v-model="row.taxInclusiveUnitPrice"
+ type="number"
+ placeholder="璇疯緭鍏ュ惈绋庡崟浠�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="绾﹀畾/鏆備及鐢ㄩ噺">
+ <up-input v-model="row.agreedQuantity"
+ type="number"
+ placeholder="璇疯緭鍏ョ害瀹氱敤閲�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="宸插彂璐ф暟閲�">
+ <up-input v-model="row.shippedQuantity"
+ type="number"
+ placeholder="璇疯緭鍏ュ凡鍙戣揣鏁伴噺"
+ clearable />
+ </up-form-item>
+ <up-form-item label="浜у��">
+ <up-input :model-value="formatAmount(productOutputValue(row))"
+ disabled
+ placeholder="鑷姩璁$畻" />
+ </up-form-item>
+ </view>
+ </view>
+ </view>
+ </u-cell-group>
+
+ <u-cell-group title="灞ョ害涓庤川淇�"
+ class="form-section">
+ <up-form-item label="灞ョ害淇濊瘉閲�">
+ <up-input v-model="form.performanceBond"
+ type="number"
+ placeholder="璇疯緭鍏ュ饱绾︿繚璇侀噾"
+ clearable />
+ </up-form-item>
+ <up-form-item label="璐ㄤ繚閲戞儏鍐�">
+ <up-input v-model="form.warrantyDeposit"
+ type="number"
+ placeholder="璇疯緭鍏ヨ川淇濋噾"
+ clearable />
+ </up-form-item>
+ <up-form-item label="浜у��">
+ <up-input :model-value="formatAmount(computedOutputValue)"
+ disabled
+ placeholder="鑷姩姹囨��" />
+ </up-form-item>
+ </u-cell-group>
+
+ <u-cell-group title="鍥炴涓庣粨绠�"
+ class="form-section">
+ <up-form-item label="宸插洖娆鹃噾棰�">
+ <up-input v-model="form.receivedAmount"
+ type="number"
+ placeholder="璇疯緭鍏ュ凡鍥炴閲戦"
+ clearable />
+ </up-form-item>
+ <up-form-item label="缁撶畻娆℃暟">
+ <up-input v-model="form.settlementCount"
+ type="number"
+ placeholder="璇疯緭鍏ョ粨绠楁鏁�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="搴旀敹閲戦">
+ <up-input v-model="form.receivableAmount"
+ type="number"
+ placeholder="璇疯緭鍏ュ簲鏀堕噾棰�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="搴斾粯姣斾緥">
+ <up-input v-model="form.payableRatio"
+ placeholder="渚嬪锛�30% 鎴� 0.3"
+ clearable />
+ </up-form-item>
+ <up-form-item label="鍚堝悓鑺傜偣搴旀敹">
+ <up-input v-model="form.nodeReceivable"
+ type="number"
+ placeholder="璇疯緭鍏ュ悎鍚岃妭鐐瑰簲鏀�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="绾﹀畾浠樻鑺傜偣">
+ <up-input v-model="form.paymentNodes"
+ placeholder="璇疯緭鍏ュ悎鍚岀害瀹氫粯娆捐妭鐐�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="缁撶畻璁板綍">
+ <up-textarea v-model="form.settlementRecord"
+ placeholder="璇疯緭鍏ョ粨绠楄褰�"
+ auto-height />
+ </up-form-item>
+ </u-cell-group>
+
+ <u-cell-group title="寮�绁ㄤ笌杩濈害"
+ class="form-section">
+ <up-form-item label="寮�绁ㄨ姹�">
+ <up-input v-model="form.invoiceRequirement"
+ placeholder="璇疯緭鍏ュ紑绁ㄨ姹�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="鏈�杩戝紑绁ㄦ椂闂�">
+ <FormPicker v-model="form.lastInvoiceDate"
+ type="date"
+ placeholder="璇烽�夋嫨鏈�杩戜竴娆″紑绁ㄦ椂闂�" />
+ </up-form-item>
+ <up-form-item label="宸插紑绁ㄩ噾棰�">
+ <up-input v-model="form.invoicedAmount"
+ type="number"
+ placeholder="璇疯緭鍏ュ凡寮�绁ㄩ噾棰�"
+ clearable />
+ </up-form-item>
+ <up-form-item label="杩濈害閲戠害瀹�">
+ <up-textarea v-model="form.penaltyAgreement"
+ placeholder="璇疯緭鍏ヨ繚绾﹂噾绾﹀畾"
+ auto-height />
+ </up-form-item>
+ <up-form-item label="鎯呭喌璇存槑">
+ <up-textarea v-model="form.remark"
+ placeholder="璇疯緭鍏ユ儏鍐佃鏄�"
+ auto-height />
+ </up-form-item>
+ </u-cell-group>
+ </up-form>
+ </view>
+
+ <FooterButtons :loading="loading"
+ confirmText="淇濆瓨"
+ @cancel="goBack"
+ @confirm="handleSubmit" />
+
+ <up-action-sheet :show="showCategorySheet"
+ title="閫夋嫨浜у搧澶х被"
+ :actions="categoryActions"
+ @select="onSelectCategory"
+ @close="showCategorySheet = false" />
+ <up-action-sheet :show="showModelSheet"
+ title="閫夋嫨瑙勬牸鍨嬪彿"
+ :actions="modelActions"
+ @select="onSelectModel"
+ @close="showModelSheet = false" />
+ </view>
+</template>
+
+<script setup>
+ import { computed, onMounted, ref } from "vue";
+ import { onLoad } from "@dcloudio/uni-app";
+ import FooterButtons from "@/components/FooterButtons.vue";
+ import PageHeader from "@/components/PageHeader.vue";
+ import FormPicker from "@/components/FormPicker.vue";
+ import { modelList, productTreeList } from "@/api/basicData/product";
+ import { loadDetailData } from "@/utils/detailCache";
+ import {
+ addOrUpdateContract,
+ getContractDetail,
+ } from "@/api/salesManagement/contractManagement";
+
+ const ARCHIVE_STATUS_OPTIONS = [
+ { name: "宸插瓨妗�", value: "宸插瓨妗�" },
+ { name: "宸茬敤绔犳湭瀵勫洖", value: "宸茬敤绔犳湭瀵勫洖" },
+ { name: "鏈绾�", value: "鏈绾�" },
+ ];
+
+ const formRef = ref();
+ const loading = ref(false);
+ const contractId = ref("");
+ const productList = ref([]);
+ const categoryOptions = ref([]);
+ const categoryActions = ref([]);
+ const modelActions = ref([]);
+ const showCategorySheet = ref(false);
+ const showModelSheet = ref(false);
+ const currentProductIndex = ref(-1);
+
+ let uidSeed = 1;
+
+ const form = ref({
+ id: undefined,
+ contractNo: "",
+ signDate: "",
+ signingUnit: "",
+ contractPeriod: "",
+ archiveStatus: "",
+ archiveRemark: "",
+ performanceBond: undefined,
+ warrantyDeposit: undefined,
+ outputValue: undefined,
+ receivedAmount: undefined,
+ settlementCount: undefined,
+ receivableAmount: undefined,
+ payableRatio: "",
+ nodeReceivable: undefined,
+ paymentNodes: "",
+ settlementRecord: "",
+ invoiceRequirement: "",
+ lastInvoiceDate: "",
+ invoicedAmount: undefined,
+ penaltyAgreement: "",
+ remark: "",
+ });
+
+ const rules = {
+ contractNo: [{ required: true, message: "璇疯緭鍏ュ悎鍚岀紪鍙�", trigger: "blur" }],
+ signDate: [{ required: true, message: "璇烽�夋嫨绛捐鏃堕棿", trigger: "change" }],
+ signingUnit: [
+ { required: true, message: "璇疯緭鍏ョ绾﹀崟浣嶇畝绉�", trigger: "blur" },
+ ],
+ archiveStatus: [
+ { required: true, message: "璇烽�夋嫨瀛樻。鐘舵��", trigger: "change" },
+ ],
+ };
+
+ const pageTitle = computed(() => (contractId.value ? "缂栬緫鍚堝悓" : "鏂板鍚堝悓"));
+
+ const productOutputValue = row =>
+ Number(
+ (
+ Number(row?.taxInclusiveUnitPrice || 0) *
+ Number(row?.shippedQuantity || 0)
+ ).toFixed(2)
+ );
+
+ const computedOutputValue = computed(() =>
+ Number(
+ productList.value
+ .reduce((sum, row) => sum + productOutputValue(row), 0)
+ .toFixed(2)
+ )
+ );
+
+ const formatAmount = amount => `楼${Number(amount || 0).toFixed(2)}`;
+ const goBack = () => uni.navigateBack();
+
+ const flattenProductTree = nodes => {
+ const result = [];
+ const walk = list => {
+ (list || []).forEach(item => {
+ if (item.children && item.children.length) {
+ walk(item.children);
+ } else {
+ result.push({
+ label: item.label || item.productName || "",
+ value: item.id || item.value,
+ });
+ }
+ });
+ };
+ walk(nodes);
+ return result;
+ };
+
+ const findNodeIdByLabel = (nodes, label) => {
+ if (!label) return null;
+ for (let i = 0; i < nodes.length; i++) {
+ const node = nodes[i];
+ if (node.label === label) return node.value;
+ if (node.children && node.children.length > 0) {
+ const found = findNodeIdByLabel(node.children, label);
+ if (found !== null && found !== undefined) return found;
+ }
+ }
+ return null;
+ };
+
+ const createEmptyProduct = () => ({
+ uid: `p_${uidSeed++}`,
+ categoryId: "",
+ productCategory: "",
+ productModelId: "",
+ specificationModel: "",
+ contractUnit: "",
+ taxInclusiveUnitPrice: undefined,
+ agreedQuantity: undefined,
+ shippedQuantity: undefined,
+ modelOptions: [],
+ });
+
+ const addProduct = () => productList.value.push(createEmptyProduct());
+
+ const removeProduct = index => {
+ productList.value.splice(index, 1);
+ };
+
+ const fetchBaseOptions = async () => {
+ try {
+ const res = await productTreeList();
+ const nodes = Array.isArray(res) ? res : res?.data || [];
+ categoryOptions.value = flattenProductTree(nodes);
+ } catch (error) {
+ categoryOptions.value = [];
+ }
+ };
+
+ const fetchModelOptions = async (categoryId, row) => {
+ try {
+ const res = await modelList({ id: categoryId });
+ const rows = res?.data?.records || res?.data || res?.records || res || [];
+ row.modelOptions = Array.isArray(rows) ? rows : [];
+ } catch (error) {
+ row.modelOptions = [];
+ }
+ };
+
+ const openCategoryPicker = index => {
+ currentProductIndex.value = index;
+ categoryActions.value = categoryOptions.value.map(item => ({
+ name: item.label,
+ value: item.value,
+ label: item.label,
+ }));
+ showCategorySheet.value = true;
+ };
+
+ const openModelPicker = index => {
+ currentProductIndex.value = index;
+ const row = productList.value[index];
+ if (!row?.categoryId) {
+ uni.showToast({ title: "璇峰厛閫夋嫨浜у搧澶х被", icon: "none" });
+ return;
+ }
+ modelActions.value = (row.modelOptions || []).map(item => ({
+ name: item.model || item.specification,
+ value: item.id,
+ unit: item.unit,
+ }));
+ if (!modelActions.value.length) {
+ uni.showToast({ title: "鏆傛棤瑙勬牸鍨嬪彿", icon: "none" });
+ return;
+ }
+ showModelSheet.value = true;
+ };
+
+ const onSelectCategory = action => {
+ const row = productList.value[currentProductIndex.value];
+ showCategorySheet.value = false;
+ if (!row) return;
+ row.categoryId = action.value;
+ row.productCategory = action.label;
+ row.productModelId = "";
+ row.specificationModel = "";
+ row.contractUnit = "";
+ row.modelOptions = [];
+ fetchModelOptions(action.value, row);
+ };
+
+ const onSelectModel = action => {
+ const row = productList.value[currentProductIndex.value];
+ showModelSheet.value = false;
+ if (!row) return;
+ row.productModelId = action.value;
+ row.specificationModel = action.name;
+ row.contractUnit = action.unit || row.contractUnit;
+ };
+
+ const normalizeProductRows = async rows => {
+ const normalized = await Promise.all(
+ (Array.isArray(rows) ? rows : []).map(async item => {
+ const row = {
+ uid: `p_${uidSeed++}`,
+ categoryId:
+ item.categoryId ||
+ findNodeIdByLabel(categoryOptions.value, item.productCategory) ||
+ "",
+ productCategory: item.productCategory || "",
+ productModelId: item.productModelId || "",
+ specificationModel: item.specificationModel || "",
+ contractUnit: item.contractUnit || "",
+ taxInclusiveUnitPrice: item.taxInclusiveUnitPrice,
+ agreedQuantity: item.agreedQuantity,
+ shippedQuantity: item.shippedQuantity,
+ modelOptions: [],
+ };
+ if (row.categoryId) {
+ await fetchModelOptions(row.categoryId, row);
+ // 浠呭瓨浜嗗瀷鍙峰悕绉版椂锛屼粠鍨嬪彿鍒楄〃鍙嶆煡 id锛屼繚璇侀�夋嫨鍣ㄨ兘鍙嶆樉
+ if (!row.productModelId && row.specificationModel) {
+ const matched = row.modelOptions.find(
+ m => (m.model || m.specification) === row.specificationModel
+ );
+ if (matched) row.productModelId = matched.id;
+ }
+ }
+ return row;
+ })
+ );
+ productList.value = normalized;
+ };
+
+ const loadDetail = async () => {
+ if (!contractId.value) return;
+ let data = null;
+ try {
+ data = await loadDetailData({
+ cacheKey: "contractDetail",
+ id: contractId.value,
+ fetcher: getContractDetail,
+ });
+ } catch (error) {
+ data = null;
+ }
+ if (!data) {
+ uni.showToast({ title: "鑾峰彇鍚堝悓璇︽儏澶辫触", icon: "none" });
+ return;
+ }
+ const { productList: rows, ...rest } = data;
+ form.value = { ...form.value, ...rest, id: data.id };
+ await normalizeProductRows(rows);
+ };
+
+ const buildPayload = () => ({
+ ...form.value,
+ outputValue: computedOutputValue.value,
+ productList: productList.value.map(row => ({
+ productCategory: row.productCategory,
+ specificationModel: row.specificationModel,
+ productModelId: row.productModelId,
+ contractUnit: row.contractUnit,
+ taxInclusiveUnitPrice: Number(row.taxInclusiveUnitPrice || 0),
+ agreedQuantity: Number(row.agreedQuantity || 0),
+ shippedQuantity: Number(row.shippedQuantity || 0),
+ outputValue: productOutputValue(row),
+ })),
+ });
+
+ const handleSubmit = async () => {
+ const valid = await formRef.value.validate().catch(() => false);
+ if (!valid) return;
+
+ loading.value = true;
+ addOrUpdateContract(buildPayload())
+ .then(() => {
+ uni.showToast({ title: "淇濆瓨鎴愬姛", icon: "success" });
+ setTimeout(() => uni.navigateBack(), 300);
+ })
+ .catch(() => {
+ uni.showToast({ title: "淇濆瓨澶辫触", icon: "none" });
+ })
+ .finally(() => {
+ loading.value = false;
+ });
+ };
+
+ onLoad(options => {
+ if (options?.id) {
+ contractId.value = options.id;
+ form.value.id = options.id;
+ }
+ });
+
+ onMounted(async () => {
+ await fetchBaseOptions();
+ if (contractId.value) await loadDetail();
+ });
+</script>
+
+<style scoped lang="scss">
+ @import "@/static/scss/form-common.scss";
+
+ .account-detail {
+ min-height: 100vh;
+ background: #f8f9fa;
+ padding-bottom: 100px;
+ }
+
+ .form-container {
+ padding: 12px 12px 0;
+ }
+
+ .form-section {
+ margin-bottom: 12px;
+ border-radius: 12px;
+ overflow: hidden;
+ box-shadow: 0 2px 10px rgba(15, 35, 95, 0.05);
+ }
+
+ .section-tools {
+ display: flex;
+ justify-content: flex-end;
+ padding: 12px 12px 0;
+ }
+
+ .product-list {
+ padding: 12px;
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ }
+
+ .product-card {
+ background: #fff;
+ border-radius: 12px;
+ padding: 0 12px 12px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
+ }
+
+ .product-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 12px 0;
+ }
+
+ .product-title {
+ font-size: 14px;
+ font-weight: 600;
+ color: #22324d;
+ }
+
+ .empty-text {
+ padding: 16px 12px;
+ color: #999;
+ font-size: 14px;
+ }
+
+ :deep(.u-cell-group__title) {
+ padding: 14px 18px 10px !important;
+ font-size: 15px !important;
+ font-weight: 600 !important;
+ color: #22324d !important;
+ background: #f8fbff !important;
+ }
+</style>
--
Gitblit v1.9.3