123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const pages_api_luyou = require("../api/luyou.js");
- const common_assets = require("../../common/assets.js");
- const _sfc_main = {
- data() {
- return {
- title: "旅游规划",
- isLoadingSpots: true,
- hotSpots: [],
- savedTrips: [],
- defaultImages: [
- "/static/beijing.jpg",
- "/static/shanghai.jpg",
- "/static/chengdu.jpg",
- "/static/hangzhou.jpg",
- "/static/guangzhou.jpg"
- ]
- };
- },
- onLoad() {
- this.loadHotSpots();
- common_vendor.index.$on("refreshTrips", () => {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:184", "接收到刷新行程列表事件");
- this.loadSavedTrips();
- });
- },
- onShow() {
- this.loadSavedTrips();
- if (this.hotSpots.length === 0 && !this.isLoadingSpots) {
- this.loadHotSpots();
- }
- },
- onUnload() {
- common_vendor.index.$off("refreshTrips");
- },
- computed: {
- // 限制只显示前3个热门景点
- displaySpots() {
- return this.hotSpots.slice(0, 3);
- },
- // 限制只显示前2个行程
- displayTrips() {
- return this.savedTrips.slice(0, 2);
- }
- },
- methods: {
- // 加载热门景点数据
- loadHotSpots() {
- this.isLoadingSpots = true;
- pages_api_luyou.findalls().then((res) => {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:222", "景点API返回数据:", res);
- if (res && res.code === 200) {
- let spotsData = res.obj;
- if (!Array.isArray(spotsData)) {
- if (Array.isArray(res.data)) {
- spotsData = res.data;
- } else if (res.data && Array.isArray(res.data.obj)) {
- spotsData = res.data.obj;
- }
- }
- if (Array.isArray(spotsData) && spotsData.length > 0) {
- const validSpots = spotsData.filter(
- (spot) => spot.name && (spot.latitude || spot.latitude === 0) && (spot.longitude || spot.longitude === 0)
- );
- this.hotSpots = validSpots.sort((a, b) => {
- const levelA = a.level ? a.level.replace("A", "") : "0";
- const levelB = b.level ? b.level.replace("A", "") : "0";
- const levelDiff = parseInt(levelB) - parseInt(levelA);
- if (levelDiff === 0) {
- if (a.city === "保定市" && b.city !== "保定市")
- return -1;
- if (a.city !== "保定市" && b.city === "保定市")
- return 1;
- }
- return levelDiff;
- });
- this.hotSpots = this.hotSpots.map((spot, index) => {
- if (!spot.coverImage) {
- spot.coverImage = this.defaultImages[index % this.defaultImages.length];
- } else if (spot.coverImage.startsWith("http"))
- ;
- else if (!spot.coverImage.startsWith("/")) {
- spot.coverImage = "/" + spot.coverImage;
- }
- return spot;
- });
- common_vendor.index.__f__("log", "at pages/planning/index.vue:278", "已加载热门景点:", this.hotSpots.length);
- } else {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:280", "API返回的数据不是数组格式:", spotsData);
- this.hotSpots = [];
- }
- } else {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:284", "API返回错误:", res);
- this.hotSpots = [];
- }
- }).catch((err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:288", "加载景点数据失败:", err);
- this.hotSpots = [];
- }).finally(() => {
- this.isLoadingSpots = false;
- });
- },
- // 获取景点的简短描述
- getShortDesc(spot) {
- if (spot.description) {
- return spot.description.length > 15 ? spot.description.substring(0, 15) + "..." : spot.description;
- } else if (spot.city) {
- return spot.city + (spot.category ? " · " + spot.category : "");
- } else if (spot.category) {
- return spot.category;
- } else {
- return "热门景点";
- }
- },
- // 选择目的地
- selectDestination(name, spot = null) {
- if (spot) {
- common_vendor.index.showLoading({
- title: "加载景点详情..."
- });
- pages_api_luyou.findById(spot.id).then((res) => {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("log", "at pages/planning/index.vue:323", "景点详情API返回:", res);
- let detailSpot = null;
- if (res && res.code === 200) {
- if (res.obj) {
- detailSpot = res.obj;
- } else if (res.data && res.data.obj) {
- detailSpot = res.data.obj;
- } else if (res.data) {
- detailSpot = res.data;
- }
- }
- const finalSpot = detailSpot ? { ...spot, ...detailSpot } : spot;
- common_vendor.index.navigateTo({
- url: `/pages/spot-detail/index?spotId=${finalSpot.id}&spotName=${encodeURIComponent(finalSpot.name)}`,
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:346", "跳转到景点详情页失败:", err);
- this.navigateToSpotMap(finalSpot);
- }
- });
- }).catch((err) => {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("error", "at pages/planning/index.vue:353", "获取景点详情失败:", err);
- this.navigateToSpotMap(spot);
- });
- } else {
- common_vendor.index.showToast({
- title: "已选择目的地: " + name,
- icon: "none"
- });
- }
- },
- // 导航到景点地图页面
- navigateToSpotMap(spot) {
- common_vendor.index.navigateTo({
- url: `/pages/custom-trip/map?lat=${spot.latitude}&lng=${spot.longitude}&name=${encodeURIComponent(spot.name)}`,
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:371", "跳转到地图页面失败:", err);
- common_vendor.index.showToast({
- title: "跳转失败",
- icon: "none"
- });
- }
- });
- },
- createCustomPlan() {
- common_vendor.index.showToast({
- title: "跳转到保定自定义行程",
- icon: "none",
- duration: 2e3
- });
- common_vendor.index.navigateTo({
- url: "/pages/custom-trip/map",
- success: () => {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:391", "成功打开保定自定义行程!");
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:394", "打开保定自定义行程失败:", err);
- common_vendor.index.showModal({
- title: "跳转失败",
- content: JSON.stringify(err),
- showCancel: false
- });
- }
- });
- },
- createAiPlan() {
- common_vendor.index.navigateTo({
- url: "/pages/ai-assistant/index",
- success: (navRes) => {
- navRes.eventChannel.emit("setAIType", {
- aiType: 1
- });
- common_vendor.index.__f__("log", "at pages/planning/index.vue:412", "成功打开AI行程助手!");
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:415", "打开AI行程助手失败:", err);
- common_vendor.index.showModal({
- title: "跳转失败",
- content: JSON.stringify(err),
- showCancel: false
- });
- }
- });
- },
- viewTripDetail(id) {
- common_vendor.index.showToast({
- title: "查看行程详情: " + id,
- icon: "none"
- });
- common_vendor.index.navigateTo({
- url: `/pages/travel-detail/index?planId=${id}`,
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:434", "跳转到行程详情页失败:", err);
- }
- });
- },
- showMoreTrips() {
- common_vendor.index.navigateTo({
- url: "/pages/planning/all-trips",
- success: () => {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:443", "成功跳转到全部行程页面");
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:446", "跳转到全部行程页面失败:", err);
- common_vendor.index.showToast({
- title: "跳转失败",
- icon: "none"
- });
- }
- });
- },
- // 加载保存的行程数据
- loadSavedTrips() {
- if (this.$api) {
- common_vendor.index.showLoading({
- title: "加载行程数据...",
- mask: false
- });
- this.$api.trip.list().then((res) => {
- if (res && res.data) {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:470", "从API加载行程数据成功:", res.data.length);
- this.savedTrips = res.data;
- common_vendor.index.setStorageSync("savedTrips", res.data);
- } else {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:476", "API没有返回行程数据,尝试从本地存储加载");
- this.loadLocalTrips();
- }
- }).catch((err) => {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:481", "从API加载行程数据失败:", err);
- this.loadLocalTrips();
- }).finally(() => {
- common_vendor.index.hideLoading();
- });
- } else {
- this.loadLocalTrips();
- }
- },
- // 从本地存储加载行程数据
- loadLocalTrips() {
- try {
- const trips = common_vendor.index.getStorageSync("savedTrips") || [];
- common_vendor.index.__f__("log", "at pages/planning/index.vue:498", "从本地存储加载的行程:", trips.length);
- this.savedTrips = trips;
- if (trips.length > 0 && this.$api) {
- common_vendor.index.__f__("log", "at pages/planning/index.vue:503", "有本地行程数据,可以考虑同步到服务器");
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/planning/index.vue:507", "加载本地行程失败:", e);
- this.savedTrips = [];
- }
- },
- // 格式化日期显示
- formatDate(dateString) {
- if (!dateString)
- return "";
- const date = new Date(dateString);
- return `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`;
- },
- // 获取行程封面图片
- getTripCoverImage(trip) {
- if (trip.spots && trip.spots.length > 0 && trip.spots[0].coverImage) {
- return trip.spots[0].coverImage;
- }
- if (trip.name.includes("保定")) {
- return "/static/baoding.jpg";
- } else if (trip.name.includes("西安")) {
- return "/static/xian.jpg";
- } else if (trip.name.includes("北京")) {
- return "/static/beijing.jpg";
- } else if (trip.name.includes("上海")) {
- return "/static/shanghai.jpg";
- }
- const defaultImages = [
- "/static/baoding.jpg",
- "/static/custom_plan_icon.png",
- "/static/beijing.jpg",
- "/static/chengdu.jpg"
- ];
- const hash = trip.id.split("_")[1] || Date.now();
- const index = hash % defaultImages.length;
- return defaultImages[index];
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_assets._imports_0$1,
- b: common_vendor.o((...args) => $options.createCustomPlan && $options.createCustomPlan(...args)),
- c: common_assets._imports_1$1,
- d: common_vendor.o((...args) => $options.createAiPlan && $options.createAiPlan(...args)),
- e: common_vendor.o((...args) => $options.showMoreTrips && $options.showMoreTrips(...args)),
- f: common_vendor.f($options.displayTrips, (trip, index, i0) => {
- return common_vendor.e({
- a: $options.getTripCoverImage(trip),
- b: common_vendor.t(trip.name),
- c: trip.startDate
- }, trip.startDate ? {
- d: common_vendor.t($options.formatDate(trip.startDate))
- } : {}, {
- e: common_vendor.t(trip.peopleCount || 1),
- f: common_vendor.t(trip.days),
- g: common_vendor.t(trip.days - 1),
- h: trip.budget
- }, trip.budget ? {
- i: common_vendor.t(trip.budget)
- } : {}, {
- j: trip.id,
- k: common_vendor.o(($event) => $options.viewTripDetail(trip.id), trip.id)
- });
- }),
- g: common_assets._imports_0$2,
- h: common_assets._imports_1$2,
- i: common_assets._imports_2$1,
- j: $data.savedTrips.length === 0
- }, $data.savedTrips.length === 0 ? {} : {}, {
- k: common_assets._imports_5,
- l: common_vendor.o(($event) => $options.selectDestination("故宫博物院", {
- name: "故宫博物院",
- city: "北京",
- district: "东城区"
- })),
- m: common_assets._imports_6,
- n: common_vendor.o(($event) => $options.selectDestination("上海外滩", {
- name: "上海外滩",
- city: "上海",
- district: "黄浦区"
- }))
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/planning/index.js.map
|