index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_api_luyou = require("../api/luyou.js");
  4. const common_assets = require("../../common/assets.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. title: "旅游规划",
  9. isLoadingSpots: true,
  10. hotSpots: [],
  11. savedTrips: [],
  12. defaultImages: [
  13. "/static/beijing.jpg",
  14. "/static/shanghai.jpg",
  15. "/static/chengdu.jpg",
  16. "/static/hangzhou.jpg",
  17. "/static/guangzhou.jpg"
  18. ]
  19. };
  20. },
  21. onLoad() {
  22. this.loadHotSpots();
  23. common_vendor.index.$on("refreshTrips", () => {
  24. common_vendor.index.__f__("log", "at pages/planning/index.vue:184", "接收到刷新行程列表事件");
  25. this.loadSavedTrips();
  26. });
  27. },
  28. onShow() {
  29. this.loadSavedTrips();
  30. if (this.hotSpots.length === 0 && !this.isLoadingSpots) {
  31. this.loadHotSpots();
  32. }
  33. },
  34. onUnload() {
  35. common_vendor.index.$off("refreshTrips");
  36. },
  37. computed: {
  38. // 限制只显示前3个热门景点
  39. displaySpots() {
  40. return this.hotSpots.slice(0, 3);
  41. },
  42. // 限制只显示前2个行程
  43. displayTrips() {
  44. return this.savedTrips.slice(0, 2);
  45. }
  46. },
  47. methods: {
  48. // 加载热门景点数据
  49. loadHotSpots() {
  50. this.isLoadingSpots = true;
  51. pages_api_luyou.findalls().then((res) => {
  52. common_vendor.index.__f__("log", "at pages/planning/index.vue:222", "景点API返回数据:", res);
  53. if (res && res.code === 200) {
  54. let spotsData = res.obj;
  55. if (!Array.isArray(spotsData)) {
  56. if (Array.isArray(res.data)) {
  57. spotsData = res.data;
  58. } else if (res.data && Array.isArray(res.data.obj)) {
  59. spotsData = res.data.obj;
  60. }
  61. }
  62. if (Array.isArray(spotsData) && spotsData.length > 0) {
  63. const validSpots = spotsData.filter(
  64. (spot) => spot.name && (spot.latitude || spot.latitude === 0) && (spot.longitude || spot.longitude === 0)
  65. );
  66. this.hotSpots = validSpots.sort((a, b) => {
  67. const levelA = a.level ? a.level.replace("A", "") : "0";
  68. const levelB = b.level ? b.level.replace("A", "") : "0";
  69. const levelDiff = parseInt(levelB) - parseInt(levelA);
  70. if (levelDiff === 0) {
  71. if (a.city === "保定市" && b.city !== "保定市")
  72. return -1;
  73. if (a.city !== "保定市" && b.city === "保定市")
  74. return 1;
  75. }
  76. return levelDiff;
  77. });
  78. this.hotSpots = this.hotSpots.map((spot, index) => {
  79. if (!spot.coverImage) {
  80. spot.coverImage = this.defaultImages[index % this.defaultImages.length];
  81. } else if (spot.coverImage.startsWith("http"))
  82. ;
  83. else if (!spot.coverImage.startsWith("/")) {
  84. spot.coverImage = "/" + spot.coverImage;
  85. }
  86. return spot;
  87. });
  88. common_vendor.index.__f__("log", "at pages/planning/index.vue:278", "已加载热门景点:", this.hotSpots.length);
  89. } else {
  90. common_vendor.index.__f__("error", "at pages/planning/index.vue:280", "API返回的数据不是数组格式:", spotsData);
  91. this.hotSpots = [];
  92. }
  93. } else {
  94. common_vendor.index.__f__("error", "at pages/planning/index.vue:284", "API返回错误:", res);
  95. this.hotSpots = [];
  96. }
  97. }).catch((err) => {
  98. common_vendor.index.__f__("error", "at pages/planning/index.vue:288", "加载景点数据失败:", err);
  99. this.hotSpots = [];
  100. }).finally(() => {
  101. this.isLoadingSpots = false;
  102. });
  103. },
  104. // 获取景点的简短描述
  105. getShortDesc(spot) {
  106. if (spot.description) {
  107. return spot.description.length > 15 ? spot.description.substring(0, 15) + "..." : spot.description;
  108. } else if (spot.city) {
  109. return spot.city + (spot.category ? " · " + spot.category : "");
  110. } else if (spot.category) {
  111. return spot.category;
  112. } else {
  113. return "热门景点";
  114. }
  115. },
  116. // 选择目的地
  117. selectDestination(name, spot = null) {
  118. if (spot) {
  119. common_vendor.index.showLoading({
  120. title: "加载景点详情..."
  121. });
  122. pages_api_luyou.findById(spot.id).then((res) => {
  123. common_vendor.index.hideLoading();
  124. common_vendor.index.__f__("log", "at pages/planning/index.vue:323", "景点详情API返回:", res);
  125. let detailSpot = null;
  126. if (res && res.code === 200) {
  127. if (res.obj) {
  128. detailSpot = res.obj;
  129. } else if (res.data && res.data.obj) {
  130. detailSpot = res.data.obj;
  131. } else if (res.data) {
  132. detailSpot = res.data;
  133. }
  134. }
  135. const finalSpot = detailSpot ? { ...spot, ...detailSpot } : spot;
  136. common_vendor.index.navigateTo({
  137. url: `/pages/spot-detail/index?spotId=${finalSpot.id}&spotName=${encodeURIComponent(finalSpot.name)}`,
  138. fail: (err) => {
  139. common_vendor.index.__f__("error", "at pages/planning/index.vue:346", "跳转到景点详情页失败:", err);
  140. this.navigateToSpotMap(finalSpot);
  141. }
  142. });
  143. }).catch((err) => {
  144. common_vendor.index.hideLoading();
  145. common_vendor.index.__f__("error", "at pages/planning/index.vue:353", "获取景点详情失败:", err);
  146. this.navigateToSpotMap(spot);
  147. });
  148. } else {
  149. common_vendor.index.showToast({
  150. title: "已选择目的地: " + name,
  151. icon: "none"
  152. });
  153. }
  154. },
  155. // 导航到景点地图页面
  156. navigateToSpotMap(spot) {
  157. common_vendor.index.navigateTo({
  158. url: `/pages/custom-trip/map?lat=${spot.latitude}&lng=${spot.longitude}&name=${encodeURIComponent(spot.name)}`,
  159. fail: (err) => {
  160. common_vendor.index.__f__("error", "at pages/planning/index.vue:371", "跳转到地图页面失败:", err);
  161. common_vendor.index.showToast({
  162. title: "跳转失败",
  163. icon: "none"
  164. });
  165. }
  166. });
  167. },
  168. createCustomPlan() {
  169. common_vendor.index.showToast({
  170. title: "跳转到保定自定义行程",
  171. icon: "none",
  172. duration: 2e3
  173. });
  174. common_vendor.index.navigateTo({
  175. url: "/pages/custom-trip/map",
  176. success: () => {
  177. common_vendor.index.__f__("log", "at pages/planning/index.vue:391", "成功打开保定自定义行程!");
  178. },
  179. fail: (err) => {
  180. common_vendor.index.__f__("error", "at pages/planning/index.vue:394", "打开保定自定义行程失败:", err);
  181. common_vendor.index.showModal({
  182. title: "跳转失败",
  183. content: JSON.stringify(err),
  184. showCancel: false
  185. });
  186. }
  187. });
  188. },
  189. createAiPlan() {
  190. common_vendor.index.navigateTo({
  191. url: "/pages/ai-assistant/index",
  192. success: (navRes) => {
  193. navRes.eventChannel.emit("setAIType", {
  194. aiType: 1
  195. });
  196. common_vendor.index.__f__("log", "at pages/planning/index.vue:412", "成功打开AI行程助手!");
  197. },
  198. fail: (err) => {
  199. common_vendor.index.__f__("error", "at pages/planning/index.vue:415", "打开AI行程助手失败:", err);
  200. common_vendor.index.showModal({
  201. title: "跳转失败",
  202. content: JSON.stringify(err),
  203. showCancel: false
  204. });
  205. }
  206. });
  207. },
  208. viewTripDetail(id) {
  209. common_vendor.index.showToast({
  210. title: "查看行程详情: " + id,
  211. icon: "none"
  212. });
  213. common_vendor.index.navigateTo({
  214. url: `/pages/travel-detail/index?planId=${id}`,
  215. fail: (err) => {
  216. common_vendor.index.__f__("error", "at pages/planning/index.vue:434", "跳转到行程详情页失败:", err);
  217. }
  218. });
  219. },
  220. showMoreTrips() {
  221. common_vendor.index.navigateTo({
  222. url: "/pages/planning/all-trips",
  223. success: () => {
  224. common_vendor.index.__f__("log", "at pages/planning/index.vue:443", "成功跳转到全部行程页面");
  225. },
  226. fail: (err) => {
  227. common_vendor.index.__f__("error", "at pages/planning/index.vue:446", "跳转到全部行程页面失败:", err);
  228. common_vendor.index.showToast({
  229. title: "跳转失败",
  230. icon: "none"
  231. });
  232. }
  233. });
  234. },
  235. // 加载保存的行程数据
  236. loadSavedTrips() {
  237. if (this.$api) {
  238. common_vendor.index.showLoading({
  239. title: "加载行程数据...",
  240. mask: false
  241. });
  242. this.$api.trip.list().then((res) => {
  243. if (res && res.data) {
  244. common_vendor.index.__f__("log", "at pages/planning/index.vue:470", "从API加载行程数据成功:", res.data.length);
  245. this.savedTrips = res.data;
  246. common_vendor.index.setStorageSync("savedTrips", res.data);
  247. } else {
  248. common_vendor.index.__f__("log", "at pages/planning/index.vue:476", "API没有返回行程数据,尝试从本地存储加载");
  249. this.loadLocalTrips();
  250. }
  251. }).catch((err) => {
  252. common_vendor.index.__f__("error", "at pages/planning/index.vue:481", "从API加载行程数据失败:", err);
  253. this.loadLocalTrips();
  254. }).finally(() => {
  255. common_vendor.index.hideLoading();
  256. });
  257. } else {
  258. this.loadLocalTrips();
  259. }
  260. },
  261. // 从本地存储加载行程数据
  262. loadLocalTrips() {
  263. try {
  264. const trips = common_vendor.index.getStorageSync("savedTrips") || [];
  265. common_vendor.index.__f__("log", "at pages/planning/index.vue:498", "从本地存储加载的行程:", trips.length);
  266. this.savedTrips = trips;
  267. if (trips.length > 0 && this.$api) {
  268. common_vendor.index.__f__("log", "at pages/planning/index.vue:503", "有本地行程数据,可以考虑同步到服务器");
  269. }
  270. } catch (e) {
  271. common_vendor.index.__f__("error", "at pages/planning/index.vue:507", "加载本地行程失败:", e);
  272. this.savedTrips = [];
  273. }
  274. },
  275. // 格式化日期显示
  276. formatDate(dateString) {
  277. if (!dateString)
  278. return "";
  279. const date = new Date(dateString);
  280. return `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`;
  281. },
  282. // 获取行程封面图片
  283. getTripCoverImage(trip) {
  284. if (trip.spots && trip.spots.length > 0 && trip.spots[0].coverImage) {
  285. return trip.spots[0].coverImage;
  286. }
  287. if (trip.name.includes("保定")) {
  288. return "/static/baoding.jpg";
  289. } else if (trip.name.includes("西安")) {
  290. return "/static/xian.jpg";
  291. } else if (trip.name.includes("北京")) {
  292. return "/static/beijing.jpg";
  293. } else if (trip.name.includes("上海")) {
  294. return "/static/shanghai.jpg";
  295. }
  296. const defaultImages = [
  297. "/static/baoding.jpg",
  298. "/static/custom_plan_icon.png",
  299. "/static/beijing.jpg",
  300. "/static/chengdu.jpg"
  301. ];
  302. const hash = trip.id.split("_")[1] || Date.now();
  303. const index = hash % defaultImages.length;
  304. return defaultImages[index];
  305. }
  306. }
  307. };
  308. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  309. return common_vendor.e({
  310. a: common_assets._imports_0$1,
  311. b: common_vendor.o((...args) => $options.createCustomPlan && $options.createCustomPlan(...args)),
  312. c: common_assets._imports_1$1,
  313. d: common_vendor.o((...args) => $options.createAiPlan && $options.createAiPlan(...args)),
  314. e: common_vendor.o((...args) => $options.showMoreTrips && $options.showMoreTrips(...args)),
  315. f: common_vendor.f($options.displayTrips, (trip, index, i0) => {
  316. return common_vendor.e({
  317. a: $options.getTripCoverImage(trip),
  318. b: common_vendor.t(trip.name),
  319. c: trip.startDate
  320. }, trip.startDate ? {
  321. d: common_vendor.t($options.formatDate(trip.startDate))
  322. } : {}, {
  323. e: common_vendor.t(trip.peopleCount || 1),
  324. f: common_vendor.t(trip.days),
  325. g: common_vendor.t(trip.days - 1),
  326. h: trip.budget
  327. }, trip.budget ? {
  328. i: common_vendor.t(trip.budget)
  329. } : {}, {
  330. j: trip.id,
  331. k: common_vendor.o(($event) => $options.viewTripDetail(trip.id), trip.id)
  332. });
  333. }),
  334. g: common_assets._imports_0$2,
  335. h: common_assets._imports_1$2,
  336. i: common_assets._imports_2$1,
  337. j: $data.savedTrips.length === 0
  338. }, $data.savedTrips.length === 0 ? {} : {}, {
  339. k: common_assets._imports_5,
  340. l: common_vendor.o(($event) => $options.selectDestination("故宫博物院", {
  341. name: "故宫博物院",
  342. city: "北京",
  343. district: "东城区"
  344. })),
  345. m: common_assets._imports_6,
  346. n: common_vendor.o(($event) => $options.selectDestination("上海外滩", {
  347. name: "上海外滩",
  348. city: "上海",
  349. district: "黄浦区"
  350. }))
  351. });
  352. }
  353. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  354. wx.createPage(MiniProgramPage);
  355. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/planning/index.js.map