simple.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_api_ai = require("../api/ai.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. formData: {
  8. userId: "user_123",
  9. // 模拟用户ID
  10. destination: "保定",
  11. days: 3,
  12. budget: 3e3,
  13. season: "春季",
  14. preferences: ["景点", "美食"],
  15. transportation: "公共交通",
  16. accommodation: "经济型酒店",
  17. includeTransportation: true,
  18. includeMeals: true,
  19. includeTickets: true
  20. },
  21. seasons: ["春季", "夏季", "秋季", "冬季", "四季皆宜"],
  22. preferences: ["景点", "美食", "文化", "购物", "自然", "摄影", "历史", "休闲"],
  23. transportations: ["公共交通", "自驾", "步行", "共享单车", "出租车"],
  24. accommodations: ["经济型酒店", "舒适型酒店", "豪华酒店", "民宿", "青旅"]
  25. };
  26. },
  27. methods: {
  28. goBack() {
  29. common_vendor.index.navigateBack();
  30. },
  31. onDaysChange(e) {
  32. this.formData.days = e.detail.value;
  33. },
  34. onBudgetChange(e) {
  35. this.formData.budget = e.detail.value;
  36. },
  37. togglePreference(preference) {
  38. const index = this.formData.preferences.indexOf(preference);
  39. if (index > -1) {
  40. this.formData.preferences.splice(index, 1);
  41. } else {
  42. if (this.formData.preferences.length < 5) {
  43. this.formData.preferences.push(preference);
  44. } else {
  45. common_vendor.index.showToast({
  46. title: "最多选择5个偏好",
  47. icon: "none"
  48. });
  49. }
  50. }
  51. },
  52. resetForm() {
  53. this.formData = {
  54. userId: "user_123",
  55. destination: "保定",
  56. days: 3,
  57. budget: 3e3,
  58. season: "春季",
  59. preferences: ["景点", "美食"],
  60. transportation: "公共交通",
  61. accommodation: "经济型酒店",
  62. includeTransportation: true,
  63. includeMeals: true,
  64. includeTickets: true
  65. };
  66. },
  67. generatePlan() {
  68. if (!this.formData.destination) {
  69. common_vendor.index.showToast({
  70. title: "请输入目的地",
  71. icon: "none"
  72. });
  73. return;
  74. }
  75. if (this.formData.preferences.length === 0) {
  76. common_vendor.index.showToast({
  77. title: "请至少选择一个偏好",
  78. icon: "none"
  79. });
  80. return;
  81. }
  82. common_vendor.index.showLoading({
  83. title: "正在生成行程..."
  84. });
  85. pages_api_ai.generateAIPlan(this.formData).then((res) => {
  86. common_vendor.index.hideLoading();
  87. common_vendor.index.__f__("log", "at pages/ai-assistant/simple.vue:208", "AI响应:", res);
  88. if (res && res.data) {
  89. pages_api_ai.saveAIPlan(this.formData).then((saveRes) => {
  90. common_vendor.index.__f__("log", "at pages/ai-assistant/simple.vue:214", "保存行程成功:", saveRes);
  91. common_vendor.index.navigateTo({
  92. url: `/pages/travel-detail/index?planId=${saveRes.data.planId}`
  93. });
  94. }).catch((err) => {
  95. common_vendor.index.__f__("error", "at pages/ai-assistant/simple.vue:222", "保存行程失败:", err);
  96. common_vendor.index.showModal({
  97. title: "保存失败",
  98. content: "行程已生成但保存失败,请重试",
  99. showCancel: false
  100. });
  101. });
  102. } else {
  103. common_vendor.index.showModal({
  104. title: "生成失败",
  105. content: "无法生成行程,请稍后再试",
  106. showCancel: false
  107. });
  108. }
  109. }).catch((err) => {
  110. common_vendor.index.hideLoading();
  111. common_vendor.index.__f__("error", "at pages/ai-assistant/simple.vue:239", "生成行程失败:", err);
  112. common_vendor.index.showModal({
  113. title: "生成失败",
  114. content: "无法连接服务器,请检查网络连接",
  115. showCancel: false
  116. });
  117. });
  118. }
  119. }
  120. };
  121. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  122. return {
  123. a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  124. b: $data.formData.destination,
  125. c: common_vendor.o(($event) => $data.formData.destination = $event.detail.value),
  126. d: $data.formData.days,
  127. e: common_vendor.o((...args) => $options.onDaysChange && $options.onDaysChange(...args)),
  128. f: $data.formData.budget,
  129. g: common_vendor.o((...args) => $options.onBudgetChange && $options.onBudgetChange(...args)),
  130. h: common_vendor.t($data.formData.budget),
  131. i: common_vendor.f($data.seasons, (season, index, i0) => {
  132. return {
  133. a: common_vendor.t(season),
  134. b: index,
  135. c: $data.formData.season === season ? 1 : "",
  136. d: common_vendor.o(($event) => $data.formData.season = season, index)
  137. };
  138. }),
  139. j: common_vendor.f($data.preferences, (preference, index, i0) => {
  140. return {
  141. a: common_vendor.t(preference),
  142. b: index,
  143. c: $data.formData.preferences.includes(preference) ? 1 : "",
  144. d: common_vendor.o(($event) => $options.togglePreference(preference), index)
  145. };
  146. }),
  147. k: common_vendor.f($data.transportations, (transport, index, i0) => {
  148. return {
  149. a: common_vendor.t(transport),
  150. b: index,
  151. c: $data.formData.transportation === transport ? 1 : "",
  152. d: common_vendor.o(($event) => $data.formData.transportation = transport, index)
  153. };
  154. }),
  155. l: common_vendor.f($data.accommodations, (accom, index, i0) => {
  156. return {
  157. a: common_vendor.t(accom),
  158. b: index,
  159. c: $data.formData.accommodation === accom ? 1 : "",
  160. d: common_vendor.o(($event) => $data.formData.accommodation = accom, index)
  161. };
  162. }),
  163. m: $data.formData.includeTransportation,
  164. n: common_vendor.o(($event) => $data.formData.includeTransportation = $event.detail.value),
  165. o: $data.formData.includeMeals,
  166. p: common_vendor.o(($event) => $data.formData.includeMeals = $event.detail.value),
  167. q: $data.formData.includeTickets,
  168. r: common_vendor.o(($event) => $data.formData.includeTickets = $event.detail.value),
  169. s: common_vendor.o((...args) => $options.resetForm && $options.resetForm(...args)),
  170. t: common_vendor.o((...args) => $options.generatePlan && $options.generatePlan(...args))
  171. };
  172. }
  173. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  174. wx.createPage(MiniProgramPage);
  175. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/ai-assistant/simple.js.map