all-trips.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view class="all-trips">
  3. <!-- 顶部导航栏 -->
  4. <view class="navbar">
  5. <view class="back-btn" @tap="goBack">
  6. <text class="back-icon">←</text>
  7. <text class="back-text">返回</text>
  8. </view>
  9. <view class="title">全部行程</view>
  10. </view>
  11. <view class="container">
  12. <!-- 行程卡片列表 -->
  13. <view class="trip-list">
  14. <!-- 显示所有已保存的行程 -->
  15. <view
  16. v-for="(trip, index) in savedTrips"
  17. :key="trip.id"
  18. class="trip-card"
  19. hover-class="card-hover"
  20. @tap="viewTripDetail(trip.id)"
  21. >
  22. <!-- 添加景区图片背景 -->
  23. <image
  24. class="trip-background-image"
  25. :src="getTripCoverImage(trip)"
  26. mode="aspectFill"
  27. ></image>
  28. <view class="trip-overlay"></view>
  29. <view class="trip-info">
  30. <view class="trip-location">
  31. <image class="location-icon" src="/static/location_icon.png"></image>
  32. <view class="trip-main-info">
  33. <text class="trip-name">{{trip.name}}</text>
  34. <text v-if="trip.startDate" class="trip-date">{{formatDate(trip.startDate)}}</text>
  35. <view v-else class="trip-date-wrap">
  36. <text class="trip-date-label">出发时间</text>
  37. <text class="trip-date-value">待定</text>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="trip-members">
  42. <image class="member-icon" src="/static/member_icon.png"></image>
  43. <text class="member-count">共{{trip.peopleCount || 1}}名成员</text>
  44. </view>
  45. </view>
  46. <view class="trip-stats">
  47. <view class="trip-tag">
  48. <text class="tag-title">THE TRIP</text>
  49. <text class="tag-subtitle">MUST GO ON</text>
  50. <image class="globe-icon" src="/static/globe_icon.png"></image>
  51. </view>
  52. <view class="trip-divider"></view>
  53. <view class="trip-duration">
  54. <text class="stat-label">时长:</text>
  55. <text class="stat-value">{{trip.days}}天{{trip.days - 1}}晚</text>
  56. </view>
  57. <view v-if="trip.budget" class="trip-distance">
  58. <text class="stat-label">预算:</text>
  59. <text class="stat-value">¥{{trip.budget}}</text>
  60. </view>
  61. </view>
  62. <view class="card-shadow"></view>
  63. </view>
  64. <!-- 没有行程时显示的提示 -->
  65. <view class="empty-trip" v-if="savedTrips.length === 0">
  66. <view class="empty-icon">🗺️</view>
  67. <view class="empty-text">您还没有创建任何行程</view>
  68. <view class="empty-subtext">点击上方选项开始规划您的旅行</view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. export default {
  76. data() {
  77. return {
  78. savedTrips: [],
  79. defaultImages: [
  80. '/static/baoding.jpg',
  81. '/static/custom_plan_icon.png',
  82. '/static/beijing.jpg',
  83. '/static/chengdu.jpg'
  84. ]
  85. }
  86. },
  87. onLoad() {
  88. // 加载保存的行程数据
  89. this.loadSavedTrips();
  90. },
  91. methods: {
  92. // 加载保存的行程数据
  93. loadSavedTrips() {
  94. try {
  95. const trips = uni.getStorageSync('savedTrips') || [];
  96. console.log('已加载保存的行程:', trips.length);
  97. this.savedTrips = trips;
  98. } catch (e) {
  99. console.error('加载保存的行程失败:', e);
  100. this.savedTrips = [];
  101. }
  102. },
  103. // 获取行程封面图片
  104. getTripCoverImage(trip) {
  105. // 如果行程有spots并且第一个spot有图片,则使用该图片
  106. if (trip.spots && trip.spots.length > 0 && trip.spots[0].coverImage) {
  107. return trip.spots[0].coverImage;
  108. }
  109. // 根据行程名称选择默认图片
  110. if (trip.name.includes('保定')) {
  111. return '/static/baoding.jpg';
  112. } else if (trip.name.includes('西安')) {
  113. return '/static/xian.jpg';
  114. } else if (trip.name.includes('北京')) {
  115. return '/static/beijing.jpg';
  116. } else if (trip.name.includes('上海')) {
  117. return '/static/shanghai.jpg';
  118. }
  119. // 默认使用景点图片数组中的一张
  120. const hash = trip.id.split('_')[1] || Date.now();
  121. const index = hash % this.defaultImages.length;
  122. return this.defaultImages[index];
  123. },
  124. // 格式化日期显示
  125. formatDate(dateString) {
  126. if (!dateString) return '';
  127. const date = new Date(dateString);
  128. return `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`;
  129. },
  130. // 查看行程详情
  131. viewTripDetail(id) {
  132. uni.navigateTo({
  133. url: `/pages/travel-detail/index?planId=${id}`,
  134. fail: (err) => {
  135. console.error('跳转到行程详情页失败:', err);
  136. }
  137. });
  138. },
  139. // 返回上一页
  140. goBack() {
  141. uni.navigateBack();
  142. }
  143. }
  144. }
  145. </script>
  146. <style>
  147. .all-trips {
  148. min-height: 100vh;
  149. background: linear-gradient(to bottom, #dbf0ff 0%, #e3f4ff 40%, #f0f9ff 100%);
  150. padding-bottom: 30rpx;
  151. }
  152. .navbar {
  153. display: flex;
  154. align-items: center;
  155. height: 90rpx;
  156. padding: 0 30rpx;
  157. background-color: rgba(255, 255, 255, 0.8);
  158. border-bottom: 1rpx solid #eaeaea;
  159. position: relative;
  160. }
  161. .back-btn {
  162. display: flex;
  163. align-items: center;
  164. position: absolute;
  165. left: 30rpx;
  166. }
  167. .back-icon {
  168. font-size: 40rpx;
  169. }
  170. .back-text {
  171. font-size: 28rpx;
  172. margin-left: 6rpx;
  173. }
  174. .navbar .title {
  175. flex: 1;
  176. text-align: center;
  177. font-size: 32rpx;
  178. font-weight: 500;
  179. }
  180. .container {
  181. padding: 20rpx;
  182. }
  183. /* 行程卡片样式 */
  184. .trip-list {
  185. display: flex;
  186. flex-direction: column;
  187. gap: 30rpx;
  188. margin-top: 15rpx;
  189. }
  190. .trip-card {
  191. background-color: #fff;
  192. border-radius: 20rpx;
  193. display: flex;
  194. overflow: hidden;
  195. position: relative;
  196. box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
  197. transition: all 0.3s ease;
  198. }
  199. /* 行程卡片背景图片 */
  200. .trip-background-image {
  201. position: absolute;
  202. top: 0;
  203. left: 0;
  204. width: 100%;
  205. height: 100%;
  206. object-fit: cover;
  207. z-index: 1;
  208. }
  209. .trip-overlay {
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. width: 100%;
  214. height: 100%;
  215. background: linear-gradient(to right, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 100%);
  216. z-index: 2;
  217. }
  218. .card-shadow {
  219. position: absolute;
  220. bottom: 0;
  221. left: 0;
  222. right: 0;
  223. height: 8rpx;
  224. background: linear-gradient(to right, #4facfe, #00f2fe);
  225. border-radius: 0 0 20rpx 20rpx;
  226. z-index: 5;
  227. }
  228. .trip-info {
  229. flex: 1;
  230. padding: 30rpx;
  231. display: flex;
  232. flex-direction: column;
  233. justify-content: space-between;
  234. position: relative;
  235. z-index: 3;
  236. }
  237. .trip-location {
  238. display: flex;
  239. align-items: flex-start;
  240. margin-bottom: 30rpx;
  241. }
  242. .location-icon {
  243. width: 40rpx;
  244. height: 40rpx;
  245. margin-right: 15rpx;
  246. margin-top: 6rpx;
  247. }
  248. .trip-main-info {
  249. flex: 1;
  250. }
  251. /* 修改文本颜色以适应图片背景 */
  252. .trip-name {
  253. font-size: 32rpx;
  254. font-weight: bold;
  255. color: #ffffff;
  256. margin-bottom: 15rpx;
  257. line-height: 1.4;
  258. text-shadow: 1rpx 1rpx 3rpx rgba(0, 0, 0, 0.5);
  259. }
  260. .trip-date {
  261. font-size: 28rpx;
  262. color: #f0f0f0;
  263. text-shadow: 1rpx 1rpx 2rpx rgba(0, 0, 0, 0.5);
  264. }
  265. .trip-date-wrap {
  266. display: flex;
  267. align-items: center;
  268. }
  269. .trip-date-label {
  270. font-size: 26rpx;
  271. color: #e0e0e0;
  272. margin-right: 10rpx;
  273. text-shadow: 1rpx 1rpx 2rpx rgba(0, 0, 0, 0.5);
  274. }
  275. .trip-date-value {
  276. font-size: 26rpx;
  277. color: #ffffff;
  278. background-color: rgba(0, 0, 0, 0.3);
  279. padding: 4rpx 16rpx;
  280. border-radius: 100rpx;
  281. }
  282. .trip-members {
  283. display: flex;
  284. align-items: center;
  285. }
  286. .member-icon {
  287. width: 40rpx;
  288. height: 40rpx;
  289. margin-right: 15rpx;
  290. }
  291. .member-count {
  292. font-size: 26rpx;
  293. color: #f0f0f0;
  294. text-shadow: 1rpx 1rpx 2rpx rgba(0, 0, 0, 0.5);
  295. }
  296. .trip-stats {
  297. width: 200rpx;
  298. background: linear-gradient(to bottom, rgba(182, 230, 255, 0.9), rgba(132, 212, 255, 0.9));
  299. padding: 30rpx 20rpx;
  300. display: flex;
  301. flex-direction: column;
  302. align-items: center;
  303. justify-content: center;
  304. position: relative;
  305. z-index: 3;
  306. }
  307. .trip-tag {
  308. display: flex;
  309. flex-direction: column;
  310. align-items: center;
  311. margin-bottom: 20rpx;
  312. }
  313. .tag-title {
  314. font-size: 24rpx;
  315. font-weight: bold;
  316. color: #333;
  317. }
  318. .tag-subtitle {
  319. font-size: 24rpx;
  320. font-weight: bold;
  321. color: #333;
  322. }
  323. .globe-icon {
  324. width: 40rpx;
  325. height: 40rpx;
  326. margin-top: 10rpx;
  327. }
  328. .trip-divider {
  329. width: 80%;
  330. height: 2rpx;
  331. background-color: rgba(51, 51, 51, 0.2);
  332. margin: 15rpx 0;
  333. }
  334. .trip-duration,
  335. .trip-distance {
  336. width: 100%;
  337. display: flex;
  338. flex-direction: column;
  339. align-items: flex-end;
  340. margin-top: 10rpx;
  341. }
  342. .stat-label {
  343. font-size: 24rpx;
  344. color: #333;
  345. text-align: right;
  346. }
  347. .stat-value {
  348. font-size: 28rpx;
  349. font-weight: bold;
  350. color: #333;
  351. text-align: right;
  352. }
  353. /* 空行程状态样式 */
  354. .empty-trip {
  355. display: flex;
  356. flex-direction: column;
  357. justify-content: center;
  358. align-items: center;
  359. background-color: #f9f9f9;
  360. border-radius: 20rpx;
  361. padding: 60rpx 0;
  362. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.05);
  363. }
  364. .empty-icon {
  365. font-size: 80rpx;
  366. margin-bottom: 20rpx;
  367. }
  368. .empty-text {
  369. font-size: 32rpx;
  370. color: #666;
  371. margin-bottom: 10rpx;
  372. }
  373. .empty-subtext {
  374. font-size: 26rpx;
  375. color: #999;
  376. }
  377. </style>