"use strict"; const common_vendor = require("../../common/vendor.js"); const _sfc_main = { data() { return { selectedLocations: [], tripDays: 1, budget: "", startDate: (/* @__PURE__ */ new Date()).toISOString().split("T")[0], // 今天的日期,格式:YYYY-MM-DD peopleCount: 2, options: {}, editMode: false, tripId: null }; }, computed: { // 计算推荐天数 recommendedDays() { return Math.max(1, Math.ceil(this.selectedLocations.length / 3)); }, // 检查是否可以提交 canSubmit() { return this.selectedLocations.length > 0 && this.tripDays >= 1 && this.budget && this.startDate; } }, onLoad(options) { common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:124", "规划详情页参数:", options); this.options = options || {}; this.editMode = options && options.tripId ? true : false; this.tripId = options && options.tripId ? options.tripId : null; try { const locationsData = common_vendor.index.getStorageSync("selectedLocations"); if (locationsData) { this.selectedLocations = JSON.parse(locationsData); common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:134", "已加载选择的景点数据:", this.selectedLocations); if (this.editMode && this.tripId) { this.loadExistingTripData(); } else { this.tripDays = this.recommendedDays; } } else { common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:144", "未找到已选景点数据"); common_vendor.index.showToast({ title: "请先选择景点", icon: "none" }); setTimeout(() => { common_vendor.index.navigateBack(); }, 1500); } } catch (e) { common_vendor.index.__f__("error", "at pages/custom-trip/plan-detail.vue:155", "读取已选景点数据失败:", e); } }, methods: { // 加载现有行程数据 loadExistingTripData() { try { const savedTrips = common_vendor.index.getStorageSync("savedTrips") || []; const tripData = savedTrips.find((trip) => trip.id === this.tripId); if (tripData) { common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:168", "找到现有行程数据:", tripData); this.tripDays = tripData.days || 1; this.budget = tripData.budget ? tripData.budget.toString() : ""; this.startDate = tripData.startDate; this.peopleCount = tripData.peopleCount || 2; common_vendor.index.setNavigationBarTitle({ title: "修改行程" }); } else { common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:180", "未找到现有行程数据"); this.tripDays = this.recommendedDays; } } catch (e) { common_vendor.index.__f__("error", "at pages/custom-trip/plan-detail.vue:184", "加载现有行程数据失败:", e); this.tripDays = this.recommendedDays; } }, // 增加天数 increaseDays() { this.tripDays++; }, // 减少天数 decreaseDays() { if (this.tripDays > 1) { this.tripDays--; } }, // 增加人数 increasePeople() { this.peopleCount++; }, // 减少人数 decreasePeople() { if (this.peopleCount > 1) { this.peopleCount--; } }, // 格式化日期显示 formatDate(dateString) { if (!dateString) return "请选择日期"; const date = new Date(dateString); return `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`; }, // 日期选择变化处理 onDateChange(e) { this.startDate = e.detail.value; }, // 移除景点 removeSpot(index) { common_vendor.index.showModal({ title: "移除景点", content: `确定要移除"${this.selectedLocations[index].name}"吗?`, success: (res) => { if (res.confirm) { this.selectedLocations.splice(index, 1); this.updateLocalStorage(); } } }); }, // 更新本地存储 updateLocalStorage() { try { common_vendor.index.setStorageSync("selectedLocations", JSON.stringify(this.selectedLocations)); common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:244", "已更新本地存储的景点数据"); } catch (e) { common_vendor.index.__f__("error", "at pages/custom-trip/plan-detail.vue:246", "更新本地存储失败:", e); } }, // 创建行程 createTrip() { if (!this.canSubmit) { common_vendor.index.showToast({ title: "请完善行程信息", icon: "none" }); return; } common_vendor.index.showLoading({ title: this.editMode ? "保存更改中..." : "行程生成中..." }); const spotsWithCoverImage = this.selectedLocations.map((location, index) => { let coverImage = "/static/baoding.jpg"; if (location.name && location.name.includes("古莲花池")) { coverImage = "/static/baoding.jpg"; } else if (location.name && location.name.includes("直隶")) { coverImage = "/static/xian.jpg"; } else if (location.name && location.name.includes("野三坡")) { coverImage = "/static/beijing.jpg"; } else { const images = [ "/static/baoding.jpg", "/static/beijing.jpg", "/static/shanghai.jpg", "/static/chengdu.jpg" ]; const imageIndex = index % images.length; coverImage = images[imageIndex]; } let distanceFromPrevious = null; if (index > 0) { const prevLocation = this.selectedLocations[index - 1]; distanceFromPrevious = this.calculateDistance( prevLocation.latitude, prevLocation.longitude, location.latitude, location.longitude ); } const latitude = Number(location.latitude); const longitude = Number(location.longitude); common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:304", `景点${index + 1} - ${location.name} 经纬度:`, latitude, longitude); return { id: location.id || `spot_${Date.now()}_${index}`, // 确保有唯一ID name: location.name || "未命名景点", address: location.address || "无地址信息", latitude, longitude, order: index + 1, coverImage, // 添加封面图片 distanceFromPrevious // 添加距离信息 }; }); const tripData = { name: "保定自定义行程", days: this.tripDays, budget: this.budget ? Number(this.budget) : null, startDate: this.startDate, peopleCount: this.peopleCount, spots: spotsWithCoverImage, createdAt: (/* @__PURE__ */ new Date()).toISOString(), updatedAt: (/* @__PURE__ */ new Date()).toISOString() }; if (this.editMode && this.tripId) { if (this.tripId.startsWith("trip_")) { tripData.id = null; } else { tripData.id = this.tripId; } } else { tripData.id = null; } common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:344", "准备保存行程数据:", JSON.stringify(tripData)); if (this.$api && this.$api.trip) { const apiMethod = this.editMode ? this.$api.trip.update : this.$api.trip.create; apiMethod(tripData).then((res) => { common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:353", "API保存行程成功:", res); const finalTripData = res && res.data ? res.data : tripData; this.saveToLocalStorage(finalTripData, true); common_vendor.index.removeStorageSync("selectedLocations"); common_vendor.index.showToast({ title: this.editMode ? "行程更新成功!" : "行程创建成功!", icon: "success", duration: 2e3 }); setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/planning/index", success: () => { common_vendor.index.$emit("refreshTrips"); common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:377", "成功返回规划页面并请求刷新"); } }); }, 1e3); }).catch((err) => { common_vendor.index.__f__("error", "at pages/custom-trip/plan-detail.vue:383", "API请求失败,回退到本地存储:", err); this.saveToLocalStorage(tripData); }).finally(() => { common_vendor.index.hideLoading(); }); } else { common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:392", "API不可用,使用本地存储保存行程"); this.saveToLocalStorage(tripData); } }, // 保存到本地存储(作为后备方案) saveToLocalStorage(tripData, skipToast = false) { try { let savedTrips = common_vendor.index.getStorageSync("savedTrips") || []; if (this.editMode && this.tripId) { const index = savedTrips.findIndex((trip) => trip.id === this.tripId); if (index !== -1) { const originalCreatedAt = savedTrips[index].createdAt; tripData.createdAt = originalCreatedAt; savedTrips[index] = tripData; if (!skipToast) { common_vendor.index.showToast({ title: "行程更新成功!", icon: "success", duration: 2e3 }); } } } else { savedTrips.push(tripData); if (!skipToast) { common_vendor.index.showToast({ title: "行程创建成功!", icon: "success", duration: 2e3 }); } } common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:435", "保存到本地的行程数据:", savedTrips); common_vendor.index.setStorageSync("savedTrips", savedTrips); common_vendor.index.removeStorageSync("selectedLocations"); if (!skipToast) { setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/planning/index", success: () => { common_vendor.index.$emit("refreshTrips"); common_vendor.index.__f__("log", "at pages/custom-trip/plan-detail.vue:452", "成功返回规划页面并请求刷新"); }, fail: (err) => { common_vendor.index.__f__("error", "at pages/custom-trip/plan-detail.vue:455", "返回规划页面失败:", err); } }); }, 1e3); } } catch (e) { common_vendor.index.__f__("error", "at pages/custom-trip/plan-detail.vue:461", "保存行程失败:", e); common_vendor.index.showToast({ title: "保存行程失败", icon: "none" }); } }, // 返回上一页 goBack() { common_vendor.index.navigateBack(); }, // 计算两点之间的距离(公里) calculateDistance(lat1, lng1, lat2, lng2) { lat1 = Number(lat1); lng1 = Number(lng1); lat2 = Number(lat2); lng2 = Number(lng2); if (isNaN(lat1) || isNaN(lng1) || isNaN(lat2) || isNaN(lng2)) { return null; } const R = 6371; const dLat = this.toRadians(lat2 - lat1); const dLng = this.toRadians(lng2 - lng1); const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); const distance = R * c; return parseFloat(distance.toFixed(1)); }, // 角度转弧度 toRadians(degrees) { return degrees * Math.PI / 180; } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)), b: common_vendor.t($data.editMode ? "修改行程" : "定制行程"), c: common_vendor.t($data.selectedLocations.length), d: common_vendor.t($data.editMode ? "请修改行程信息" : "请完善行程信息"), e: common_vendor.o((...args) => $options.decreaseDays && $options.decreaseDays(...args)), f: $data.tripDays <= 1 ? 1 : "", g: common_vendor.t($data.tripDays), h: common_vendor.o((...args) => $options.increaseDays && $options.increaseDays(...args)), i: common_vendor.t($options.recommendedDays), j: $data.budget, k: common_vendor.o(($event) => $data.budget = $event.detail.value), l: common_vendor.t($options.formatDate($data.startDate)), m: $data.startDate, n: common_vendor.o((...args) => $options.onDateChange && $options.onDateChange(...args)), o: common_vendor.o((...args) => $options.decreasePeople && $options.decreasePeople(...args)), p: $data.peopleCount <= 1 ? 1 : "", q: common_vendor.t($data.peopleCount), r: common_vendor.o((...args) => $options.increasePeople && $options.increasePeople(...args)), s: common_vendor.f($data.selectedLocations, (spot, index, i0) => { return { a: common_vendor.t(index + 1), b: common_vendor.t(spot.name || "未命名景点"), c: common_vendor.t(spot.address || "无地址信息"), d: common_vendor.o(($event) => $options.removeSpot(index), index), e: index }; }), t: $data.selectedLocations.length === 0 }, $data.selectedLocations.length === 0 ? {} : {}, { v: common_vendor.t($data.editMode ? "" : "修改"), w: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)), x: common_vendor.t($data.editMode ? "保存修改" : "生成行程"), y: common_vendor.o((...args) => $options.createTrip && $options.createTrip(...args)), z: !$options.canSubmit ? 1 : "" }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/custom-trip/plan-detail.js.map