+
+
{{ t("purchase.back_to_list") }}
+
+
+
+ {{ t("purchase.edit_order") }}
+
@@ -538,7 +549,7 @@ onMounted(fetchOrder);
- {{ costTotalYuan.toFixed(2) }}
+
|
+/**
+ * 采购订单编辑页面
+ *
+ * 功能概述:
+ * - 通过路由参数 :id 加载已有订单数据
+ * - 使用 PurchaseOrderForm 组件展示可编辑表单
+ * - 提交时调用 /purchase/updateorder 保存修改
+ */
+
+import { reactive, ref, onMounted } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRoute, useRouter } from "vue-router";
+import { useToastStore } from "@/stores/toast";
+import { usePageTitle } from "@/composables/usePageTitle";
+import { useValidation } from "@/composables";
+import { purchaseApi } from "@/api/purchase";
+import PurchaseOrderForm from "@/components/PurchaseOrderForm.vue";
+
+usePageTitle("purchase_addorder.edit_order");
+
+const route = useRoute();
+const router = useRouter();
+const { t } = useI18n();
+const toast = useToastStore();
+const { validate, errors, clearErrors } = useValidation();
+
+const orderId = Number(route.params.id);
+
+// ==================== 状态 ====================
+const loading = ref(false);
+const pageLoading = ref(true);
+const pageError = ref("");
+
+/** 回填的费用明细(分为单位,传给 PurchaseOrderForm) */
+const initialCosts = ref([]);
+/** 回填的图片列表 */
+const initialPhotos = ref([]);
+
+/** 表单数据 */
+const form = reactive({
+ title: "",
+ remark: "",
+ link: "",
+ styles: "",
+ photos: [],
+ costs: [],
+ _costs: [], // 由 PurchaseOrderForm 组件同步的分为单位费用数组
+});
+
+/** PurchaseOrderForm 组件引用(用于获取图片哈希) */
+const formRef = ref(null);
+
+// ==================== 加载订单数据 ====================
+onMounted(async () => {
+ if (!orderId) {
+ pageError.value = t("purchase.order_not_found");
+ pageLoading.value = false;
+ return;
+ }
+
+ try {
+ const res = await purchaseApi.getOrder(orderId);
+ console.log(res)
+ if (res.errCode !== 0 || res.raw?.err_code !== 0) {
+ pageError.value = t("purchase.order_not_found");
+ pageLoading.value = false;
+ return;
+ }
+
+ const { order, costs, photos } = res.raw.data;
+
+ // 回填基本信息
+ form.title = order.Title ?? "";
+ form.remark = order.Remark ?? "";
+ form.link = order.Link ?? "";
+ form.styles = order.Styles ?? "";
+
+ // 回填费用(传给子组件,由子组件转换为元展示)
+ initialCosts.value = costs ?? [];
+ // 回填图片
+ initialPhotos.value = photos ?? [];
+ } catch {
+ pageError.value = t("purchase.order_not_found");
+ } finally {
+ pageLoading.value = false;
+ }
+});
+
+// ==================== 提交 ====================
+async function handleSubmit() {
+ clearErrors();
+ const ok = validate("title", form.title, t("purchase_addorder.title"));
+ if (!ok) return;
+
+ // 获取图片哈希
+ form.photos = formRef.value?.getPhotoHashes() ?? [];
+ // 使用子组件同步的费用(分为单位)
+ form.costs = form._costs ?? [];
+
+ loading.value = true;
+ try {
+ const res = await purchaseApi.updateOrder(orderId, {
+ title: form.title,
+ remark: form.remark,
+ link: form.link,
+ styles: form.styles,
+ photos: form.photos,
+ costs: form.costs,
+ });
+
+ if (res.errCode === 0 && res.raw?.err_code === 0) {
+ toast.success(t("message.save_ok"));
+ setTimeout(() => {
+ router.replace(`/purchase/showorder/${orderId}`);
+ }, 800);
+ } else {
+ toast.error(t("message.server_error"));
+ }
+ } catch {
+ toast.error(t("message.server_error"));
+ } finally {
+ loading.value = false;
+ }
+}
+
+
+
+
+
+
+
+ {{ t("message.loading") }}
+
+
+
+
+ {{ pageError }}
+
+
+
+
+
+
+
+ {{ t("purchase_addorder.edit_order") }}
+
+
+
+
+
+
+
+ {{ errors.title }}
+
+
+
+
+
+
+
+
+
+
+
+
|