123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const util_api = require("../../util/api.js");
- const _sfc_main = {
- data() {
- return {
- isLoading: false,
- tripId: null,
- tripData: {},
- options: null,
- defaultImages: [
- "/static/baoding.jpg",
- "/static/custom_plan_icon.png",
- "/static/beijing.jpg",
- "/static/chengdu.jpg"
- ],
- showQrCode: false,
- qrCodeUrl: "",
- qrCodeExpireTime: 0
- };
- },
- onLoad(options) {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:136", "行程详情页面加载,参数:", options);
- this.options = options;
- if (options && options.planId) {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:141", "接收到行程ID:", options.planId);
- this.tripId = options.planId;
- this.loadTripData();
- } else {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:145", "没有接收到行程ID,使用默认数据");
- this.createDefaultTrip();
- }
- },
- // 监听app全局事件
- onShow() {
- common_vendor.index.$on("loadTripDetail", this.handleLoadTripDetail);
- },
- onHide() {
- common_vendor.index.$off("loadTripDetail", this.handleLoadTripDetail);
- },
- methods: {
- // 处理通过事件加载行程
- handleLoadTripDetail(data) {
- if (data && data.tripId) {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:166", "通过事件加载行程:", data.tripId);
- this.tripId = data.tripId;
- this.loadTripData();
- }
- },
- // 创建默认行程
- createDefaultTrip() {
- this.tripData = {
- id: "default_trip_" + Date.now(),
- name: "保定精彩三日游",
- days: 3,
- nights: 2,
- startDate: this.formatDate(/* @__PURE__ */ new Date()),
- budget: 1580
- };
- common_vendor.index.showToast({
- title: "默认行程已生成",
- icon: "success"
- });
- },
- // 加载行程数据
- loadTripData() {
- this.isLoading = true;
- if (this.tripId && !this.tripId.startsWith("trip_")) {
- util_api.API.trip.detail(this.tripId).then((res) => {
- if (res.data) {
- this.tripData = res.data;
- common_vendor.index.showToast({
- title: "行程加载成功",
- icon: "success"
- });
- } else {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:206", "API返回空数据,尝试从本地加载");
- this.loadFromLocalStorage();
- }
- }).catch((err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:211", "通过API加载行程失败:", err);
- this.loadFromLocalStorage();
- }).finally(() => {
- this.isLoading = false;
- });
- } else {
- this.loadFromLocalStorage();
- }
- },
- // 从本地存储加载行程
- loadFromLocalStorage() {
- try {
- const savedTrips = common_vendor.index.getStorageSync("savedTrips") || [];
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:228", "已保存行程:", savedTrips);
- const tripData = savedTrips.find((trip) => trip.id === this.tripId);
- if (tripData) {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:234", "找到行程数据:", tripData);
- this.tripData = tripData;
- common_vendor.index.showToast({
- title: "行程加载成功",
- icon: "success"
- });
- } else {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:242", "未找到行程数据,使用默认数据");
- this.createDefaultTrip();
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:247", "加载行程数据失败:", e);
- this.createDefaultTrip();
- } finally {
- this.isLoading = false;
- }
- },
- // 修改行程
- editTrip() {
- if (!this.tripData || !this.tripData.id) {
- common_vendor.index.showToast({
- title: "无法修改默认行程",
- icon: "none"
- });
- return;
- }
- try {
- if (this.tripData.spots && this.tripData.spots.length > 0) {
- common_vendor.index.setStorageSync("selectedLocations", JSON.stringify(this.tripData.spots));
- common_vendor.index.navigateTo({
- url: `/pages/custom-trip/plan-detail?tripId=${this.tripData.id}`,
- success: () => {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:275", "成功跳转到行程编辑页面,行程ID:", this.tripData.id);
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:278", "跳转到行程编辑页面失败:", err);
- common_vendor.index.showToast({
- title: "跳转失败",
- icon: "none"
- });
- }
- });
- } else {
- common_vendor.index.showToast({
- title: "行程没有景点数据",
- icon: "none"
- });
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:292", "保存临时数据失败:", e);
- common_vendor.index.showToast({
- title: "准备编辑数据失败",
- icon: "none"
- });
- }
- },
- // 获取行程封面图片
- getTripCoverImage() {
- if (this.tripData.spots && this.tripData.spots.length > 0) {
- if (this.tripData.spots[0].coverImage) {
- return this.tripData.spots[0].coverImage;
- }
- }
- if (this.tripData.name && this.tripData.name.includes("保定")) {
- return "/static/baoding.jpg";
- } else if (this.tripData.name && this.tripData.name.includes("西安")) {
- return "/static/xian.jpg";
- } else if (this.tripData.name && this.tripData.name.includes("北京")) {
- return "/static/beijing.jpg";
- } else if (this.tripData.name && this.tripData.name.includes("上海")) {
- return "/static/shanghai.jpg";
- }
- const hash = this.tripData.id ? this.tripData.id.split("_")[1] : Date.now();
- const index = hash % this.defaultImages.length;
- return this.defaultImages[index];
- },
- // 格式化日期
- formatDate(date) {
- if (!date) {
- const now = /* @__PURE__ */ new Date();
- const year = now.getFullYear();
- const month = now.getMonth() + 1;
- const day = now.getDate();
- return `${year}.${month}.${day}`;
- }
- if (date instanceof Date) {
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const day = date.getDate();
- return `${year}.${month}.${day}`;
- }
- return date;
- },
- // 返回上一页
- goBack() {
- common_vendor.index.navigateBack({
- fail: () => {
- this.goToHome();
- }
- });
- },
- // 回到首页
- goToHome() {
- common_vendor.index.switchTab({
- url: "/pages/planning/index"
- });
- },
- // 计算两个景点之间的距离
- calculateDistance(spot1, spot2) {
- if (!spot1 || !spot2 || !spot1.latitude || !spot1.longitude || !spot2.latitude || !spot2.longitude) {
- return "未知";
- }
- const lat1 = Number(spot1.latitude);
- const lng1 = Number(spot1.longitude);
- const lat2 = Number(spot2.latitude);
- const lng2 = Number(spot2.longitude);
- if (isNaN(lat1) || isNaN(lng1) || isNaN(lat2) || isNaN(lng2)) {
- return "未知";
- }
- 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 distance.toFixed(1);
- },
- // 角度转弧度
- toRadians(degrees) {
- return degrees * Math.PI / 180;
- },
- // 获取两个景点之间的距离
- getDistanceBetween(spot1, spot2) {
- if (spot2.distanceFromPrevious !== void 0 && spot2.distanceFromPrevious !== null) {
- return spot2.distanceFromPrevious;
- }
- return this.calculateDistance(spot1, spot2);
- },
- // 显示删除确认对话框
- showDeleteConfirm() {
- if (!this.tripData || !this.tripData.id) {
- common_vendor.index.showToast({
- title: "无法删除默认行程",
- icon: "none"
- });
- return;
- }
- common_vendor.index.showModal({
- title: "确认删除",
- content: "确定要删除此行程吗?此操作不可恢复。",
- confirmColor: "#ff4d4f",
- success: (res) => {
- if (res.confirm) {
- this.deleteTrip();
- }
- }
- });
- },
- // 删除行程
- deleteTrip() {
- common_vendor.index.showLoading({
- title: "正在删除...",
- mask: true
- });
- if (this.tripId && !this.tripId.startsWith("trip_")) {
- util_api.API.trip.delete(this.tripId).then((res) => {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:449", "API删除行程成功:", res);
- this.deleteFromLocalStorage();
- common_vendor.index.showToast({
- title: "行程已删除",
- icon: "success"
- });
- setTimeout(() => {
- this.goToHome();
- }, 1e3);
- }).catch((err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:464", "通过API删除行程失败:", err);
- this.deleteFromLocalStorage();
- }).finally(() => {
- common_vendor.index.hideLoading();
- });
- } else {
- this.deleteFromLocalStorage();
- common_vendor.index.hideLoading();
- }
- },
- // 从本地存储中删除行程
- deleteFromLocalStorage() {
- try {
- const savedTrips = common_vendor.index.getStorageSync("savedTrips") || [];
- const updatedTrips = savedTrips.filter((trip) => trip.id !== this.tripId);
- common_vendor.index.setStorageSync("savedTrips", updatedTrips);
- common_vendor.index.showToast({
- title: "行程已删除",
- icon: "success"
- });
- common_vendor.index.$emit("refreshTrips");
- setTimeout(() => {
- this.goToHome();
- }, 1e3);
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:503", "从本地存储删除行程失败:", e);
- common_vendor.index.showToast({
- title: "删除失败",
- icon: "none"
- });
- }
- },
- // 处理弹窗背景点击
- handlePopupBackdrop(e) {
- this.closeQrCode();
- },
- // 分享行程方法
- shareTrip() {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:519", "点击分享按钮");
- this.generateQrCode();
- common_vendor.index.showToast({
- title: "正在生成二维码",
- icon: "loading",
- duration: 1e3
- });
- },
- // 生成行程二维码
- generateQrCode() {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:533", "点击生成二维码按钮");
- if (!this.tripData || !this.tripData.id) {
- common_vendor.index.showToast({
- title: "无法生成默认行程的二维码",
- icon: "none"
- });
- return;
- }
- if (this.qrCodeUrl && this.qrCodeExpireTime > Date.now()) {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:544", "使用缓存的二维码");
- this.showQrCode = true;
- return;
- }
- this.generateLocalQrCode();
- const simpleTripData = {
- id: this.tripData.id,
- name: this.tripData.name,
- days: this.tripData.days,
- budget: this.tripData.budget
- };
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:561", "发送到后端的数据:", JSON.stringify(simpleTripData));
- util_api.API.trip.generateQrCode(simpleTripData).then((res) => {
- var _a, _b, _c;
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:567", "后端返回的二维码数据:", res);
- if (res.qrCodeUrl || ((_a = res.data) == null ? void 0 : _a.qrCodeUrl)) {
- this.qrCodeUrl = res.qrCodeUrl || ((_b = res.data) == null ? void 0 : _b.qrCodeUrl);
- this.qrCodeExpireTime = res.expireTime || ((_c = res.data) == null ? void 0 : _c.expireTime) || Date.now() + 36e5;
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:575", "二维码URL:", this.qrCodeUrl);
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:576", "二维码内容:", res.qrContent || "未提供");
- this.$nextTick(() => {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:581", "二维码图片已更新");
- common_vendor.index.showToast({
- title: "二维码生成成功",
- icon: "success",
- duration: 1500
- });
- });
- } else {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:591", "生成二维码失败: 返回数据中无qrCodeUrl", res);
- common_vendor.index.showToast({
- title: "使用本地二维码",
- icon: "none"
- });
- }
- }).catch((err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:600", "生成二维码失败:", err);
- common_vendor.index.showToast({
- title: "使用本地二维码",
- icon: "none",
- duration: 1500
- });
- });
- },
- // 生成本地二维码(不依赖后端)
- generateLocalQrCode() {
- try {
- this.showQrCode = true;
- const qrContent = `pages/travel-detail/index?planId=${this.tripData.id}`;
- const loadingQrCode = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrContent)}`;
- this.qrCodeUrl = loadingQrCode;
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:620", "生成临时二维码:", loadingQrCode);
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:621", "二维码内容:", qrContent);
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:625", "生成本地二维码失败:", e);
- }
- },
- // 关闭二维码弹窗
- closeQrCode() {
- this.showQrCode = false;
- },
- // 保存二维码到相册
- saveQrCode() {
- if (!this.qrCodeUrl) {
- common_vendor.index.showToast({
- title: "二维码不存在",
- icon: "none"
- });
- return;
- }
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.writePhotosAlbum"]) {
- common_vendor.index.authorize({
- scope: "scope.writePhotosAlbum",
- success: () => {
- this.downloadQrCode();
- },
- fail: () => {
- common_vendor.index.showModal({
- title: "提示",
- content: "请授权保存图片到相册的权限",
- confirmText: "去设置",
- success: (res2) => {
- if (res2.confirm) {
- common_vendor.index.openSetting();
- }
- }
- });
- }
- });
- } else {
- this.downloadQrCode();
- }
- }
- });
- },
- // 下载二维码到本地
- downloadQrCode() {
- common_vendor.index.showLoading({
- title: "保存中..."
- });
- if (this.qrCodeUrl && this.qrCodeUrl.indexOf("data:image/png;base64,") === 0) {
- common_vendor.index.__f__("log", "at pages/travel-detail/index.vue:681", "检测到Base64格式图片,直接保存");
- const base64Data = this.qrCodeUrl.split(",")[1];
- try {
- const fs = common_vendor.wx$1.getFileSystemManager();
- const filePath = `${common_vendor.wx$1.env.USER_DATA_PATH}/trip_qrcode_${Date.now()}.png`;
- fs.writeFile({
- filePath,
- data: base64Data,
- encoding: "base64",
- success: () => {
- common_vendor.wx$1.saveImageToPhotosAlbum({
- filePath,
- success: () => {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "保存成功",
- icon: "success"
- });
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:705", "保存到相册失败:", err);
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "保存失败",
- icon: "none"
- });
- }
- });
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:715", "写入文件失败:", err);
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "保存失败",
- icon: "none"
- });
- }
- });
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:724", "保存Base64图片失败:", err);
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "当前平台不支持保存",
- icon: "none"
- });
- }
- } else {
- common_vendor.index.downloadFile({
- url: this.qrCodeUrl,
- success: (res) => {
- if (res.statusCode === 200) {
- common_vendor.index.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: () => {
- common_vendor.index.showToast({
- title: "保存成功",
- icon: "success"
- });
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:747", "保存到相册失败:", err);
- common_vendor.index.showToast({
- title: "保存失败",
- icon: "none"
- });
- }
- });
- }
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/travel-detail/index.vue:757", "下载二维码失败:", err);
- common_vendor.index.showToast({
- title: "保存失败",
- icon: "none"
- });
- },
- complete: () => {
- common_vendor.index.hideLoading();
- }
- });
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $options.getTripCoverImage(),
- b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
- c: common_vendor.t($data.tripData.name || "保定精彩之旅"),
- d: common_vendor.t($data.tripData.days || "3"),
- e: common_vendor.t($data.tripData.days - 1 || "2"),
- f: common_vendor.t($options.formatDate($data.tripData.startDate)),
- g: common_vendor.t($data.tripData.days || "3"),
- h: common_vendor.t($data.tripData.days - 1 || "2"),
- i: common_vendor.t($options.formatDate($data.tripData.startDate)),
- j: $data.tripData.budget
- }, $data.tripData.budget ? {
- k: common_vendor.t($data.tripData.budget)
- } : {}, {
- l: common_vendor.t($data.tripData.peopleCount || 1),
- m: $data.tripData.spots && $data.tripData.spots.length > 0
- }, $data.tripData.spots && $data.tripData.spots.length > 0 ? {
- n: common_vendor.f($data.tripData.spots, (spot, index, i0) => {
- return common_vendor.e({
- a: common_vendor.t(index + 1),
- b: common_vendor.t(spot.name),
- c: spot.address
- }, spot.address ? {
- d: common_vendor.t(spot.address)
- } : {}, {
- e: index < $data.tripData.spots.length - 1
- }, index < $data.tripData.spots.length - 1 ? {
- f: common_vendor.t($options.getDistanceBetween(spot, $data.tripData.spots[index + 1]))
- } : {}, {
- g: index
- });
- })
- } : {}, {
- o: common_vendor.o((...args) => $options.editTrip && $options.editTrip(...args)),
- p: common_vendor.o((...args) => $options.goToHome && $options.goToHome(...args)),
- q: common_vendor.o((...args) => $options.shareTrip && $options.shareTrip(...args)),
- r: common_vendor.o((...args) => $options.showDeleteConfirm && $options.showDeleteConfirm(...args)),
- s: $data.showQrCode
- }, $data.showQrCode ? {
- t: common_vendor.o((...args) => $options.closeQrCode && $options.closeQrCode(...args)),
- v: $data.qrCodeUrl,
- w: common_vendor.t($data.tripData.name),
- x: common_vendor.t($data.tripData.days),
- y: common_vendor.t($data.tripData.budget),
- z: common_vendor.o((...args) => $options.saveQrCode && $options.saveQrCode(...args)),
- A: common_vendor.o(() => {
- }),
- B: common_vendor.o((...args) => $options.handlePopupBackdrop && $options.handlePopupBackdrop(...args))
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/travel-detail/index.js.map
|