sales-detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <view class="detail-container">
  3. <!-- 顶部封面图轮播 -->
  4. <view class="image-section">
  5. <swiper
  6. class="image-swiper"
  7. :indicator-dots="false"
  8. :circular="false"
  9. :autoplay="false"
  10. @change="onSwiperChange"
  11. >
  12. <swiper-item v-for="(image, index) in imageList" :key="index" @click="previewImage(index)">
  13. <image :src="image" mode="aspectFill" class="cover-image" lazy-load></image>
  14. </swiper-item>
  15. </swiper>
  16. <!-- 自定义分页指示器 -->
  17. <view class="custom-dots" v-if="imageList.length > 1">
  18. <view
  19. class="dot"
  20. :class="{ active: currentImageIndex === index }"
  21. v-for="(item, index) in imageList"
  22. :key="index"
  23. ></view>
  24. </view>
  25. </view>
  26. <!-- 标题和类型标签 -->
  27. <view class="title-section">
  28. <view class="title-content">
  29. <text class="product-title">{{ productInfo.title }}</text>
  30. <view class="type-tag" :class="productInfo.type">
  31. {{ productInfo.type === 'sale' ? '出售' : '收购' }}
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 核心信息展示卡片 -->
  36. <view class="info-card">
  37. <view class="info-row">
  38. <text class="info-label">分类</text>
  39. <text class="info-value">{{ productInfo.category }}</text>
  40. </view>
  41. <view class="info-row">
  42. <text class="info-label">{{ productInfo.type === 'sale' ? '单价' : '收购价' }}</text>
  43. <text class="info-value price">¥{{ productInfo.price }}/{{ productInfo.unit }}</text>
  44. </view>
  45. <view class="info-row">
  46. <text class="info-label">数量</text>
  47. <text class="info-value">{{ productInfo.quantity }}{{ productInfo.unit }}</text>
  48. </view>
  49. <view class="info-row">
  50. <text class="info-label">所在地</text>
  51. <text class="info-value location">{{ productInfo.location }}</text>
  52. </view>
  53. </view>
  54. <!-- 补充说明区域 -->
  55. <view class="description-card">
  56. <view class="card-title">
  57. <text>{{ productInfo.type === 'sale' ? '产品详情' : '收购要求' }}</text>
  58. </view>
  59. <view class="description-content">
  60. <text class="description-text">
  61. {{ productInfo.description || '无补充说明' }}
  62. </text>
  63. </view>
  64. </view>
  65. <!-- 发布者信息卡片 -->
  66. <view class="publisher-card">
  67. <view class="card-title">
  68. <text>发布者信息</text>
  69. </view>
  70. <view class="publisher-info">
  71. <view class="info-row">
  72. <text class="info-label">联系人</text>
  73. <text class="info-value">{{ productInfo.publisher.name }}</text>
  74. </view>
  75. <view class="info-row">
  76. <text class="info-label">联系电话</text>
  77. <text class="info-value phone">{{ productInfo.publisher.phone }}</text>
  78. </view>
  79. <view class="info-row">
  80. <text class="info-label">发布时间</text>
  81. <text class="info-value">{{ productInfo.publishTime }}</text>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 底部操作按钮 -->
  86. <view class="action-buttons" v-if="shouldShowActionButtons">
  87. <!-- 当前用户发布的内容 -->
  88. <template v-if="isOwnProduct">
  89. <!-- 已上架状态:显示编辑和下架 -->
  90. <template v-if="productStatus === 'approved'">
  91. <button class="action-btn edit-btn" @click="editProduct">
  92. 编辑
  93. </button>
  94. <button class="action-btn remove-btn" @click="removeProduct">
  95. 下架
  96. </button>
  97. </template>
  98. <!-- 审核中状态:显示编辑和撤销 -->
  99. <template v-else-if="productStatus === 'pending'">
  100. <button class="action-btn edit-btn" @click="editProduct">
  101. 编辑
  102. </button>
  103. <button class="action-btn cancel-btn" @click="cancelProduct">
  104. 撤销
  105. </button>
  106. </template>
  107. <!-- 已下架状态:不显示任何按钮 -->
  108. </template>
  109. <!-- 他人发布的内容 -->
  110. <template v-else>
  111. <button class="action-btn contact-btn" @click="contactPublisher">
  112. 立即联系
  113. </button>
  114. </template>
  115. </view>
  116. </view>
  117. </template>
  118. <script>
  119. export default {
  120. data() {
  121. return {
  122. currentImageIndex: 0,
  123. source: '', // 页面来源,myPublish表示来自我的发布页面
  124. productStatus: '', // 产品状态:pending, approved, rejected
  125. productInfo: {
  126. id: '',
  127. type: 'sale', // sale: 出售, purchase: 收购
  128. title: '',
  129. category: '',
  130. price: '',
  131. quantity: '',
  132. unit: '',
  133. location: '',
  134. description: '',
  135. publisher: {
  136. name: '',
  137. phone: '',
  138. userId: ''
  139. },
  140. publishTime: '',
  141. images: []
  142. },
  143. imageList: [],
  144. isOwnProduct: false // 是否为当前用户发布的产品
  145. }
  146. },
  147. onLoad(options) {
  148. // 获取页面参数
  149. if (options.id) {
  150. this.source = options.source || '';
  151. this.productStatus = options.status || '';
  152. this.loadProductDetail(options.id, options.type);
  153. }
  154. },
  155. computed: {
  156. // 判断是否显示操作按钮
  157. shouldShowActionButtons() {
  158. if (!this.isOwnProduct) {
  159. // 他人发布的内容始终显示联系按钮
  160. return true;
  161. } else {
  162. // 自己发布的内容,已下架状态不显示任何按钮
  163. return this.productStatus !== 'rejected';
  164. }
  165. }
  166. },
  167. methods: {
  168. // 加载产品详情
  169. loadProductDetail(id, type) {
  170. // 根据类型模拟不同的数据结构
  171. let mockData;
  172. if (type === 'purchase') {
  173. // 收购信息的数据结构
  174. mockData = {
  175. id: id,
  176. type: 'purchase',
  177. title: '高价收购优质土豆',
  178. category: '蔬菜',
  179. price: '3.5',
  180. quantity: '1000',
  181. unit: '斤',
  182. location: '山东·烟台',
  183. description: '大量收购优质土豆,要求新鲜无病害,无青皮,规格统一。支持长期合作,价格优惠,现金结算。有货源的农户欢迎联系,我们提供上门收购服务。',
  184. publisher: {
  185. name: '李**',
  186. phone: '138****5678',
  187. userId: 'user456'
  188. },
  189. publishTime: '2025-01-21 10:30',
  190. images: [
  191. '/static/images/products/agriculture-tools.jpg',
  192. '/static/images/products/organic-fertilizer-new.jpg',
  193. '/static/images/products/plastic-film.jpg'
  194. ]
  195. };
  196. } else {
  197. // 出售信息的数据结构
  198. mockData = {
  199. id: id,
  200. type: type || 'sale',
  201. title: '2024年红富士苹果',
  202. category: '水果',
  203. price: '8.5',
  204. quantity: '1000',
  205. unit: '斤',
  206. location: '山东·烟台',
  207. description: '自家果园种植的红富士苹果,个大味甜,果形端正,色泽鲜艳。采用有机种植方式,无农药残留,口感清脆香甜。现大量上市,欢迎各地客商前来洽谈合作。支持批发零售,量大价优。',
  208. publisher: {
  209. name: '张**',
  210. phone: '188****1234',
  211. userId: 'user123'
  212. },
  213. publishTime: '2025-01-21 14:20',
  214. images: [
  215. '/static/images/products/corn-seeds-new.jpg',
  216. '/static/images/products/rice-seeds.jpg',
  217. '/static/images/products/seeds-packets.jpg',
  218. '/static/images/products/greenhouse-film.jpg'
  219. ]
  220. };
  221. }
  222. this.productInfo = mockData;
  223. this.imageList = mockData.images;
  224. // 判断是否为当前用户发布的产品
  225. // 如果来源是我的发布页面,则表示是自己的产品
  226. this.isOwnProduct = this.source === 'myPublish';
  227. },
  228. // 轮播图切换
  229. onSwiperChange(e) {
  230. this.currentImageIndex = e.detail.current;
  231. },
  232. // 预览图片
  233. previewImage(index) {
  234. uni.previewImage({
  235. current: index,
  236. urls: this.imageList
  237. });
  238. },
  239. // 编辑产品
  240. editProduct() {
  241. if (this.productInfo.type === 'purchase') {
  242. // 收购信息跳转到收购编辑页面
  243. uni.navigateTo({
  244. url: `/pages/service/purchase-publish?action=edit&id=${this.productInfo.id}`
  245. });
  246. } else {
  247. // 销售信息跳转到销售编辑页面
  248. uni.navigateTo({
  249. url: `/pages/service/sales-publish?action=edit&id=${this.productInfo.id}&type=${this.productInfo.type}`
  250. });
  251. }
  252. },
  253. // 下架产品
  254. removeProduct() {
  255. uni.showModal({
  256. title: '确认下架',
  257. content: '确定要下架这条信息吗?下架后其他用户将无法查看。',
  258. confirmText: '确认下架',
  259. cancelText: '取消',
  260. success: (res) => {
  261. if (res.confirm) {
  262. // 执行下架操作
  263. this.handleRemoveProduct();
  264. }
  265. }
  266. });
  267. },
  268. // 处理下架操作
  269. handleRemoveProduct() {
  270. // 模拟下架API调用
  271. uni.showLoading({ title: '下架中...' });
  272. setTimeout(() => {
  273. uni.hideLoading();
  274. uni.showToast({
  275. title: '下架成功',
  276. icon: 'success'
  277. });
  278. // 返回上一页
  279. setTimeout(() => {
  280. uni.navigateBack();
  281. }, 1500);
  282. }, 1000);
  283. },
  284. // 联系发布者
  285. contactPublisher() {
  286. // 获取真实电话号码并拨打
  287. const realPhone = this.getRealPhoneNumber();
  288. uni.showModal({
  289. title: '联系发布者',
  290. content: `确定要拨打 ${realPhone} 吗?`,
  291. confirmText: '拨打',
  292. cancelText: '取消',
  293. success: (res) => {
  294. if (res.confirm) {
  295. uni.makePhoneCall({
  296. phoneNumber: realPhone,
  297. fail: () => {
  298. uni.showToast({
  299. title: '拨号失败',
  300. icon: 'none'
  301. });
  302. }
  303. });
  304. }
  305. }
  306. });
  307. },
  308. // 撤销产品(审核中状态)
  309. cancelProduct() {
  310. uni.showModal({
  311. title: '确认撤销',
  312. content: '确定要撤销这条发布信息吗?撤销后需要重新提交审核。',
  313. confirmText: '确认撤销',
  314. cancelText: '取消',
  315. success: (res) => {
  316. if (res.confirm) {
  317. // 执行撤销操作
  318. this.handleCancelProduct();
  319. }
  320. }
  321. });
  322. },
  323. // 处理撤销操作
  324. handleCancelProduct() {
  325. // 模拟撤销API调用
  326. uni.showLoading({ title: '撤销中...' });
  327. setTimeout(() => {
  328. uni.hideLoading();
  329. uni.showToast({
  330. title: '撤销成功',
  331. icon: 'success'
  332. });
  333. // 返回上一页
  334. setTimeout(() => {
  335. uni.navigateBack();
  336. }, 1500);
  337. }, 1000);
  338. },
  339. // 获取真实电话号码(实际应用中从API获取)
  340. getRealPhoneNumber() {
  341. // 模拟从API获取真实电话号码
  342. return '18812341234';
  343. }
  344. }
  345. }
  346. </script>
  347. <style lang="scss">
  348. .detail-container {
  349. min-height: 100vh;
  350. background-color: #f5f5f5;
  351. padding-bottom: 120rpx;
  352. }
  353. // 顶部封面图轮播
  354. .image-section {
  355. position: relative;
  356. margin: 20rpx;
  357. border-radius: 16rpx;
  358. overflow: hidden;
  359. background-color: #fff;
  360. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  361. }
  362. .image-swiper {
  363. width: 100%;
  364. height: 500rpx;
  365. }
  366. swiper-item {
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. width: 100%;
  371. height: 100%;
  372. }
  373. .cover-image {
  374. width: 100%;
  375. height: 100%;
  376. }
  377. .custom-dots {
  378. position: absolute;
  379. bottom: 20rpx;
  380. left: 50%;
  381. transform: translateX(-50%);
  382. display: flex;
  383. gap: 12rpx;
  384. }
  385. .dot {
  386. width: 12rpx;
  387. height: 12rpx;
  388. border-radius: 6rpx;
  389. background-color: rgba(255, 255, 255, 0.5);
  390. transition: all 0.3s ease;
  391. &.active {
  392. background-color: #fff;
  393. width: 24rpx;
  394. }
  395. }
  396. // 标题和类型标签
  397. .title-section {
  398. margin: 0 20rpx 20rpx;
  399. background-color: #fff;
  400. border-radius: 16rpx;
  401. padding: 30rpx;
  402. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  403. }
  404. .title-content {
  405. display: flex;
  406. justify-content: space-between;
  407. align-items: flex-start;
  408. gap: 20rpx;
  409. }
  410. .product-title {
  411. flex: 1;
  412. font-size: 32rpx;
  413. font-weight: bold;
  414. color: #333;
  415. line-height: 1.4;
  416. }
  417. .type-tag {
  418. padding: 8rpx 16rpx;
  419. border-radius: 20rpx;
  420. font-size: 24rpx;
  421. font-weight: bold;
  422. flex-shrink: 0;
  423. &.sale {
  424. background-color: #e8f5e8;
  425. color: #4CAF50;
  426. }
  427. &.purchase {
  428. background-color: #e6f7ff;
  429. color: #1890ff;
  430. }
  431. }
  432. // 信息卡片通用样式
  433. .info-card, .description-card, .publisher-card {
  434. margin: 0 20rpx 20rpx;
  435. background-color: #fff;
  436. border-radius: 16rpx;
  437. padding: 30rpx;
  438. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  439. }
  440. .card-title {
  441. font-size: 28rpx;
  442. font-weight: bold;
  443. color: #333;
  444. margin-bottom: 24rpx;
  445. padding-bottom: 16rpx;
  446. border-bottom: 2rpx solid #f5f5f5;
  447. }
  448. // 核心信息展示
  449. .info-row {
  450. display: flex;
  451. justify-content: space-between;
  452. align-items: center;
  453. padding: 16rpx 0;
  454. border-bottom: 1rpx solid #f8f8f8;
  455. &:last-child {
  456. border-bottom: none;
  457. }
  458. }
  459. .info-label {
  460. font-size: 28rpx;
  461. color: #666;
  462. flex-shrink: 0;
  463. width: 120rpx;
  464. }
  465. .info-value {
  466. font-size: 28rpx;
  467. color: #333;
  468. font-weight: 500;
  469. text-align: right;
  470. flex: 1;
  471. &.price {
  472. color: #ff6b35;
  473. font-weight: bold;
  474. font-size: 30rpx;
  475. }
  476. &.location {
  477. color: #4CAF50;
  478. }
  479. &.phone {
  480. color: #1890ff;
  481. }
  482. }
  483. // 补充说明区域
  484. .description-content {
  485. padding: 20rpx;
  486. background-color: #f8f9fa;
  487. border-radius: 12rpx;
  488. border-left: 4rpx solid #4CAF50;
  489. }
  490. .description-text {
  491. font-size: 26rpx;
  492. color: #666;
  493. line-height: 1.6;
  494. }
  495. // 发布者信息
  496. .publisher-info {
  497. .info-row {
  498. padding: 20rpx 0;
  499. }
  500. }
  501. // 底部操作按钮
  502. .action-buttons {
  503. position: fixed;
  504. bottom: 0;
  505. left: 0;
  506. right: 0;
  507. padding: 20rpx 30rpx;
  508. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  509. background-color: #fff;
  510. border-top: 1rpx solid #f0f0f0;
  511. display: flex;
  512. gap: 20rpx;
  513. z-index: 100;
  514. }
  515. .action-btn {
  516. flex: 1;
  517. height: 80rpx;
  518. border-radius: 40rpx;
  519. font-size: 28rpx;
  520. font-weight: bold;
  521. border: none;
  522. transition: all 0.3s ease;
  523. &.edit-btn {
  524. background-color: #fff;
  525. color: #4CAF50;
  526. border: 2rpx solid #4CAF50;
  527. &:active {
  528. background-color: #f0fdf4;
  529. }
  530. }
  531. &.remove-btn {
  532. background-color: #fff;
  533. color: #ff4757;
  534. border: 2rpx solid #ff4757;
  535. &:active {
  536. background-color: #fff5f5;
  537. }
  538. }
  539. &.cancel-btn {
  540. background-color: #fff;
  541. color: #fa8c16;
  542. border: 2rpx solid #fa8c16;
  543. &:active {
  544. background-color: #fff7e6;
  545. }
  546. }
  547. &.contact-btn {
  548. background-color: #4CAF50;
  549. color: #fff;
  550. &:active {
  551. background-color: #45a049;
  552. }
  553. }
  554. }
  555. // 防止按钮点击状态样式被覆盖
  556. button[disabled] {
  557. opacity: 0.6;
  558. }
  559. button::after {
  560. border: none;
  561. }
  562. </style>