index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <view class="spot-detail">
  3. <!-- 顶部封面区域 -->
  4. <view class="cover-section">
  5. <image class="cover-image" :src="spotData.coverImage || defaultImage" mode="aspectFill"></image>
  6. <view class="cover-mask"></view>
  7. <view class="cover-content">
  8. <view class="back-btn" @tap="goBack">
  9. <text class="back-icon">←</text>
  10. </view>
  11. <view class="spot-title">{{spotData.name || '景点详情'}}</view>
  12. <view class="spot-subtitle" v-if="spotData.level">{{spotData.level}}级景区</view>
  13. </view>
  14. </view>
  15. <!-- 景点信息 -->
  16. <view class="spot-info">
  17. <view class="info-title">景点信息</view>
  18. <view class="info-content">
  19. <view class="info-item" v-if="spotData.category">
  20. <text class="info-label">类型</text>
  21. <text class="info-value">{{spotData.category}}</text>
  22. </view>
  23. <view class="info-item" v-if="spotData.city">
  24. <text class="info-label">城市</text>
  25. <text class="info-value">{{spotData.city}}</text>
  26. </view>
  27. <view class="info-item" v-if="spotData.address">
  28. <text class="info-label">地址</text>
  29. <text class="info-value">{{spotData.address}}</text>
  30. </view>
  31. <view class="info-item" v-if="spotData.businessHours">
  32. <text class="info-label">开放时间</text>
  33. <text class="info-value">{{spotData.businessHours}}</text>
  34. </view>
  35. <view class="info-item" v-if="spotData.ticketPrice">
  36. <text class="info-label">票价</text>
  37. <text class="info-value">{{spotData.ticketPrice}}</text>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 景点描述 -->
  42. <view class="spot-description" v-if="spotData.description">
  43. <view class="section-title">景点介绍</view>
  44. <view class="description-content">
  45. {{spotData.description}}
  46. </view>
  47. </view>
  48. <!-- 景点位置 -->
  49. <view class="spot-location" v-if="spotData.latitude && spotData.longitude">
  50. <view class="section-title">景点位置</view>
  51. <view class="location-map">
  52. <map
  53. class="map"
  54. :latitude="Number(spotData.latitude)"
  55. :longitude="Number(spotData.longitude)"
  56. :markers="mapMarkers"
  57. scale="14"
  58. show-location="true"
  59. ></map>
  60. </view>
  61. </view>
  62. <!-- 按钮区域 -->
  63. <view class="action-buttons">
  64. <button class="add-btn" @tap="addToTrip">添加到行程</button>
  65. <button class="map-btn" @tap="viewOnMap">在地图中查看</button>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import { findById } from '@/pages/api/luyou.js';
  71. export default {
  72. data() {
  73. return {
  74. isLoading: true,
  75. spotId: null,
  76. spotName: '',
  77. spotData: {},
  78. defaultImage: '/static/baoding.jpg',
  79. mapMarkers: []
  80. }
  81. },
  82. onLoad(options) {
  83. console.log('景点详情页面加载,参数:', options);
  84. // 获取景点ID
  85. if (options && options.spotId) {
  86. console.log('接收到景点ID:', options.spotId);
  87. this.spotId = options.spotId;
  88. this.spotName = options.spotName || '景点详情';
  89. this.loadSpotData();
  90. } else {
  91. console.log('没有接收到景点ID,使用默认数据');
  92. uni.showToast({
  93. title: '景点信息不完整',
  94. icon: 'none'
  95. });
  96. setTimeout(() => {
  97. this.goBack();
  98. }, 1500);
  99. }
  100. },
  101. methods: {
  102. // 加载景点数据
  103. loadSpotData() {
  104. this.isLoading = true;
  105. uni.showLoading({
  106. title: '加载景点信息...'
  107. });
  108. // 调用API获取景点详情
  109. findById(this.spotId).then(res => {
  110. console.log('景点详情API返回:', res);
  111. // 解析API返回的数据
  112. if (res && res.code === 200) {
  113. // 尝试从不同位置获取数据
  114. if (res.obj) {
  115. this.spotData = res.obj;
  116. } else if (res.data && res.data.obj) {
  117. this.spotData = res.data.obj;
  118. } else if (res.data) {
  119. this.spotData = res.data;
  120. }
  121. // 处理封面图片
  122. if (this.spotData.coverImage) {
  123. if (this.spotData.coverImage.startsWith('http')) {
  124. // 如果是完整URL,直接使用
  125. // 不做处理
  126. } else if (!this.spotData.coverImage.startsWith('/')) {
  127. // 如果不是以/开头,添加/
  128. this.spotData.coverImage = '/' + this.spotData.coverImage;
  129. }
  130. } else {
  131. this.spotData.coverImage = this.defaultImage;
  132. }
  133. // 设置地图标记
  134. if (this.spotData.latitude && this.spotData.longitude) {
  135. this.mapMarkers = [{
  136. id: 1,
  137. latitude: Number(this.spotData.latitude),
  138. longitude: Number(this.spotData.longitude),
  139. title: this.spotData.name,
  140. iconPath: '/static/marker_attraction.png',
  141. width: 32,
  142. height: 32,
  143. callout: {
  144. content: this.spotData.name,
  145. color: '#333333',
  146. fontSize: 12,
  147. borderRadius: 4,
  148. padding: 5,
  149. display: 'ALWAYS'
  150. }
  151. }];
  152. }
  153. uni.setNavigationBarTitle({
  154. title: this.spotData.name || this.spotName
  155. });
  156. } else {
  157. console.error('API返回错误:', res);
  158. uni.showToast({
  159. title: '加载景点信息失败',
  160. icon: 'none'
  161. });
  162. }
  163. }).catch(err => {
  164. console.error('加载景点信息失败:', err);
  165. uni.showToast({
  166. title: '加载景点信息失败',
  167. icon: 'none'
  168. });
  169. }).finally(() => {
  170. this.isLoading = false;
  171. uni.hideLoading();
  172. });
  173. },
  174. // 添加到行程
  175. addToTrip() {
  176. if (!this.spotData || !this.spotData.id) {
  177. uni.showToast({
  178. title: '景点信息不完整',
  179. icon: 'none'
  180. });
  181. return;
  182. }
  183. // 准备景点数据
  184. const spot = {
  185. id: this.spotData.id,
  186. name: this.spotData.name,
  187. address: this.spotData.address,
  188. latitude: this.spotData.latitude,
  189. longitude: this.spotData.longitude,
  190. coverImage: this.spotData.coverImage,
  191. category: this.spotData.category,
  192. description: this.spotData.description
  193. };
  194. // 跳转到地图页面并传递景点数据
  195. uni.navigateTo({
  196. url: `/pages/custom-trip/map?lat=${spot.latitude}&lng=${spot.longitude}&name=${encodeURIComponent(spot.name)}`,
  197. success: () => {
  198. console.log('成功跳转到地图页面');
  199. },
  200. fail: (err) => {
  201. console.error('跳转到地图页面失败:', err);
  202. uni.showToast({
  203. title: '跳转失败',
  204. icon: 'none'
  205. });
  206. }
  207. });
  208. },
  209. // 在地图中查看
  210. viewOnMap() {
  211. if (!this.spotData || !this.spotData.latitude || !this.spotData.longitude) {
  212. uni.showToast({
  213. title: '景点位置信息不完整',
  214. icon: 'none'
  215. });
  216. return;
  217. }
  218. // 跳转到地图页面
  219. uni.navigateTo({
  220. url: `/pages/custom-trip/map?lat=${this.spotData.latitude}&lng=${this.spotData.longitude}&name=${encodeURIComponent(this.spotData.name)}`,
  221. fail: (err) => {
  222. console.error('跳转到地图页面失败:', err);
  223. uni.showToast({
  224. title: '跳转失败',
  225. icon: 'none'
  226. });
  227. }
  228. });
  229. },
  230. // 返回上一页
  231. goBack() {
  232. uni.navigateBack({
  233. fail: () => {
  234. // 如果无法返回上一页,则回到首页
  235. uni.switchTab({
  236. url: '/pages/planning/index'
  237. });
  238. }
  239. });
  240. }
  241. }
  242. }
  243. </script>
  244. <style>
  245. .spot-detail {
  246. padding-bottom: 40rpx;
  247. background-color: #f5f7fa;
  248. }
  249. /* 顶部封面区域 */
  250. .cover-section {
  251. position: relative;
  252. height: 400rpx;
  253. overflow: hidden;
  254. }
  255. .cover-image {
  256. width: 100%;
  257. height: 100%;
  258. }
  259. .cover-mask {
  260. position: absolute;
  261. top: 0;
  262. left: 0;
  263. width: 100%;
  264. height: 100%;
  265. background: linear-gradient(to bottom, rgba(0,0,0,0.1), rgba(0,0,0,0.6));
  266. }
  267. .cover-content {
  268. position: absolute;
  269. bottom: 40rpx;
  270. left: 0;
  271. width: 100%;
  272. padding: 0 40rpx;
  273. box-sizing: border-box;
  274. }
  275. .back-btn {
  276. position: absolute;
  277. top: -280rpx;
  278. left: 0;
  279. width: 80rpx;
  280. height: 80rpx;
  281. background-color: rgba(255,255,255,0.2);
  282. border-radius: 50%;
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. }
  287. .back-icon {
  288. font-size: 48rpx;
  289. color: #ffffff;
  290. }
  291. .spot-title {
  292. font-size: 48rpx;
  293. font-weight: bold;
  294. color: #ffffff;
  295. margin-bottom: 16rpx;
  296. text-shadow: 0 2rpx 8rpx rgba(0,0,0,0.3);
  297. }
  298. .spot-subtitle {
  299. font-size: 28rpx;
  300. color: rgba(255,255,255,0.9);
  301. background-color: rgba(0,0,0,0.3);
  302. padding: 6rpx 20rpx;
  303. border-radius: 100rpx;
  304. display: inline-block;
  305. }
  306. /* 景点信息 */
  307. .spot-info {
  308. margin: 30rpx;
  309. padding: 30rpx;
  310. background-color: #ffffff;
  311. border-radius: 20rpx;
  312. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.05);
  313. }
  314. .info-title {
  315. font-size: 32rpx;
  316. font-weight: bold;
  317. margin-bottom: 20rpx;
  318. color: #333;
  319. position: relative;
  320. padding-left: 20rpx;
  321. }
  322. .info-title::before {
  323. content: "";
  324. position: absolute;
  325. left: 0;
  326. top: 6rpx;
  327. width: 8rpx;
  328. height: 32rpx;
  329. background: linear-gradient(to bottom, #4facfe, #00f2fe);
  330. border-radius: 4rpx;
  331. }
  332. .info-content {
  333. display: flex;
  334. flex-direction: column;
  335. }
  336. .info-item {
  337. display: flex;
  338. justify-content: space-between;
  339. padding: 16rpx 0;
  340. border-bottom: 1px solid #f0f0f0;
  341. }
  342. .info-item:last-child {
  343. border-bottom: none;
  344. }
  345. .info-label {
  346. color: #666;
  347. font-size: 28rpx;
  348. }
  349. .info-value {
  350. color: #333;
  351. font-size: 28rpx;
  352. font-weight: 500;
  353. }
  354. /* 景点描述 */
  355. .spot-description {
  356. margin: 30rpx;
  357. padding: 30rpx;
  358. background-color: #ffffff;
  359. border-radius: 20rpx;
  360. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.05);
  361. }
  362. .section-title {
  363. font-size: 32rpx;
  364. font-weight: bold;
  365. margin-bottom: 20rpx;
  366. color: #333;
  367. position: relative;
  368. padding-left: 20rpx;
  369. }
  370. .section-title::before {
  371. content: "";
  372. position: absolute;
  373. left: 0;
  374. top: 6rpx;
  375. width: 8rpx;
  376. height: 32rpx;
  377. background: linear-gradient(to bottom, #4facfe, #00f2fe);
  378. border-radius: 4rpx;
  379. }
  380. .description-content {
  381. font-size: 28rpx;
  382. color: #333;
  383. line-height: 1.8;
  384. text-align: justify;
  385. }
  386. /* 景点位置 */
  387. .spot-location {
  388. margin: 30rpx;
  389. padding: 30rpx;
  390. background-color: #ffffff;
  391. border-radius: 20rpx;
  392. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.05);
  393. }
  394. .location-map {
  395. margin-top: 20rpx;
  396. height: 400rpx;
  397. border-radius: 16rpx;
  398. overflow: hidden;
  399. }
  400. .map {
  401. width: 100%;
  402. height: 100%;
  403. }
  404. /* 按钮区域 */
  405. .action-buttons {
  406. padding: 40rpx 30rpx;
  407. display: flex;
  408. gap: 20rpx;
  409. justify-content: space-between;
  410. }
  411. .add-btn {
  412. background-color: #3e98ff;
  413. color: #ffffff;
  414. border-radius: 50rpx;
  415. font-size: 32rpx;
  416. padding: 20rpx 0;
  417. flex: 1;
  418. }
  419. .map-btn {
  420. background-color: #f0f0f0;
  421. color: #333;
  422. border-radius: 50rpx;
  423. font-size: 32rpx;
  424. padding: 20rpx 0;
  425. flex: 1;
  426. }
  427. </style>