sales-detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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 === 0 ? 'sale' : 'purchase'">
  31. {{ productInfo.type === 0 ? '出售' : '收购' }}
  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">{{ getDictLabel('agricultural_category',productInfo.categoryId) }}</text>
  40. </view>
  41. <view class="info-row">
  42. <text class="info-label">{{ productInfo.type === 0 ? '单价' : '收购价' }}</text>
  43. <text class="info-value price">¥{{ productInfo.price }}/{{ getDictLabel('agricultural_unit',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. <LocationPicker class="info-value location"
  53. v-model="productInfo.location"
  54. mode="view"
  55. />
  56. </view>
  57. </view>
  58. <!-- 补充说明区域 -->
  59. <view class="description-card">
  60. <view class="card-title">
  61. <text>{{ productInfo.type === 0 ? '产品详情' : '收购要求' }}</text>
  62. </view>
  63. <view class="description-content">
  64. <text class="description-text">
  65. {{ productInfo.description || '无补充说明' }}
  66. </text>
  67. </view>
  68. </view>
  69. <!-- 发布者信息卡片 -->
  70. <view class="publisher-card">
  71. <view class="card-title">
  72. <text>发布者信息</text>
  73. </view>
  74. <view class="publisher-info">
  75. <view class="info-row">
  76. <text class="info-label">联系人</text>
  77. <text class="info-value">{{ productInfo.contactName }}</text>
  78. </view>
  79. <view class="info-row">
  80. <text class="info-label">联系电话</text>
  81. <text class="info-value phone">{{ productInfo.contactPhone }}</text>
  82. </view>
  83. <view class="info-row">
  84. <text class="info-label">发布时间</text>
  85. <text class="info-value">{{ productInfo.publishTime }}</text>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 审批意见 -->
  90. <view class="description-card" v-if="productInfo.status === 4">
  91. <view class="card-title">
  92. <text>审核结果</text>
  93. </view>
  94. <view class="description-content" style="border-left: 2px solid red">
  95. <text class="description-text" >
  96. {{ productInfo.remark || '无' }}
  97. </text>
  98. </view>
  99. </view>
  100. <!-- 底部操作按钮 -->
  101. <view class="action-buttons" v-if="shouldShowActionButtons">
  102. <!-- 当前用户发布的内容
  103. <!-- <template v-if="isOwnProduct">
  104. <!-- 已上架状态:显示编辑和下架
  105. <template v-if="productStatus === '2'">
  106. <!-- <button class="action-btn edit-btn" @click="editProduct">
  107. 编辑
  108. </button>
  109. <button class="action-btn remove-btn" @click="removeProduct">
  110. 下架
  111. </button>
  112. </template>
  113. <!-- 审核中状态:显示编辑和撤销
  114. <template v-else-if="productStatus === '1'">
  115. <!-- <button class="action-btn edit-btn" @click="editProduct">
  116. 编辑
  117. </button>
  118. <button class="action-btn cancel-btn" @click="cancelProduct">
  119. 撤销
  120. </button>
  121. </template>
  122. <!-- 已下架状态:不显示任何按钮
  123. <template v-else-if="productStatus === '3'">
  124. <button class="action-btn edit-btn" @click="editProduct">
  125. 编辑
  126. </button>
  127. <button class="action-btn cancel-btn" @click="cancelProduct">
  128. 发布
  129. </button>
  130. </template>
  131. <!-- 未通过
  132. <template v-else-if="productStatus === '4'">
  133. <button class="action-btn edit-btn" @click="editProduct">
  134. 编辑
  135. </button>
  136. <button class="action-btn cancel-btn" @click="cancelProduct">
  137. 删除
  138. </button>
  139. </template>
  140. </template> -->
  141. <!-- 当前用户发布的内容 -->
  142. <template v-if="isOwnProduct">
  143. <button
  144. v-for="(btn, index) in actionMap[productStatus] || []"
  145. :key="index"
  146. class="action-btn"
  147. :class="btn.class"
  148. @click="handleAction(btn.action)"
  149. >
  150. {{ btn.label }}
  151. </button>
  152. </template>
  153. <!-- 他人发布的内容 -->
  154. <template v-else>
  155. <button class="action-btn contact-btn" @click="contactPublisher">
  156. 立即联系
  157. </button>
  158. </template>
  159. </view>
  160. </view>
  161. </template>
  162. <script setup>
  163. import { ref, computed, onMounted } from 'vue'
  164. import { onShow, onLoad } from '@dcloudio/uni-app'
  165. import LocationPicker from "@/components/common/LocationPicker.vue"
  166. import { getProductInfoById, editProductInfo } from '@/api/services/productInfo.js'
  167. import { useDict } from '@/utils/composables/useDict'
  168. // 使用字典
  169. const { dictData } = useDict(['agricultural_category', 'agricultural_unit'])
  170. const currentImageIndex = ref(0)
  171. const source = ref('') // 页面来源,myPublish表示来自我的发布页面
  172. const productStatus = ref('') // 产品状态:1-pending, 2-approved, 3-rejected
  173. const productInfo = ref({
  174. id: '',
  175. type: '0', // 0-sale: 出售, 1-purchase: 收购
  176. title: '',
  177. categoryId: '',
  178. price: '',
  179. quantity: '',
  180. unit: '',
  181. location: '',
  182. description: '',
  183. contactName: '',
  184. contactPhone: '',
  185. publishTime: '',
  186. images: [],
  187. remark: ''
  188. })
  189. const imageList = ref([])
  190. const isOwnProduct = ref(false) // 是否为当前用户发布的产品
  191. // 状态按钮映射
  192. const actionMap = {
  193. '1': [], // 审核中
  194. '2': [ // 已上架
  195. { label: '下架', class: 'remove-btn', action: 'removeProduct' }
  196. ],
  197. '3': [ // 已下架
  198. { label: '编辑', class: 'edit-btn', action: 'editProduct' },
  199. { label: '发布', class: 'cancel-btn', action: 'publishProduct' }
  200. ],
  201. '4': [ // 未通过
  202. { label: '编辑', class: 'edit-btn', action: 'editProduct' }
  203. ]
  204. }
  205. // 判断是否显示操作按钮
  206. const shouldShowActionButtons = computed(() => {
  207. if (!isOwnProduct.value) {
  208. // 他人发布的内容始终显示联系按钮
  209. return true
  210. } else {
  211. // 自己发布的内容,已下架状态不显示任何按钮
  212. return productStatus.value !== 'rejected'
  213. }
  214. })
  215. // 页面显示时刷新数据
  216. onShow(() => {
  217. if (productInfo.value.id) {
  218. loadProductDetail(productInfo.value.id)
  219. }
  220. })
  221. onLoad((options)=>{
  222. // 获取页面参数
  223. if (options.id) {
  224. source.value = options.source || '';
  225. productStatus.value = options.status || '';
  226. loadProductDetail(options.id, options.type);
  227. }
  228. })
  229. // 页面加载
  230. onMounted(() => {
  231. const pages = getCurrentPages()
  232. const currentPage = pages[pages.length - 1]
  233. const options = currentPage.options
  234. if (options.id) {
  235. source.value = options.source || ''
  236. productStatus.value = options.status || ''
  237. loadProductDetail(options.id, options.type)
  238. }
  239. })
  240. const handleAction = (action) => {
  241. const actions = {
  242. editProduct,
  243. removeProduct,
  244. publishProduct,
  245. cancelProduct
  246. }
  247. actions[action] && actions[action]()
  248. }
  249. const getDictLabel = (dictKey, value) => {
  250. if (!dictData[dictKey]) {
  251. return ''
  252. }
  253. const list = dictData[dictKey] || []
  254. const item = list.find(u => u.dictValue == value)
  255. return item ? item.dictLabel : ''
  256. }
  257. // 加载产品详情
  258. const loadProductDetail = (id) => {
  259. uni.showLoading({
  260. title: '加载中'
  261. })
  262. getProductInfoById(id).then(res => {
  263. if (res.data.code === 200) {
  264. const { data } = res.data
  265. productInfo.value = data
  266. // 处理图片数据
  267. if (productInfo.value.imageUrl) {
  268. try {
  269. imageList.value = productInfo.value.imageUrl.split(',')
  270. } catch (e) {
  271. console.error('解析图片数据失败:', e)
  272. imageList.value = []
  273. }
  274. } else {
  275. imageList.value = []
  276. }
  277. uni.hideLoading()
  278. } else {
  279. uni.showToast({
  280. title: res.data.msg || '获取农品信息失败',
  281. icon: 'none'
  282. })
  283. }
  284. })
  285. // 判断是否为当前用户发布的产品
  286. isOwnProduct.value = source.value === 'myPublish'
  287. }
  288. // 轮播图切换
  289. const onSwiperChange = (e) => {
  290. currentImageIndex.value = e.detail.current
  291. }
  292. // 预览图片
  293. const previewImage = (index) => {
  294. uni.previewImage({
  295. current: index,
  296. urls: imageList.value
  297. })
  298. }
  299. // 编辑产品
  300. const editProduct = () => {
  301. if (productInfo.value.type === 1) {
  302. // 收购信息跳转到收购编辑页面
  303. uni.navigateTo({
  304. url: `/pages/service/purchase-publish?action=edit&id=${productInfo.value.id}`
  305. })
  306. } else {
  307. // 销售信息跳转到销售编辑页面
  308. uni.navigateTo({
  309. url: `/pages/service/sales-publish?action=edit&id=${productInfo.value.id}&type=${productInfo.value.type}`
  310. })
  311. }
  312. }
  313. const publishProduct = () => {
  314. uni.showModal({
  315. title: '确认发布审核',
  316. content: `确定要发布这条信息吗?审核通过后将在${productInfo.value.type === 0 ? '销售' : '收购'}页面展示`,
  317. confirmText: '确认发布',
  318. cancelText: '取消',
  319. success: (res) => {
  320. if (res.confirm) {
  321. handlePublishProduct()
  322. }
  323. }
  324. })
  325. }
  326. // 处理发布操作
  327. const handlePublishProduct = () => {
  328. uni.showLoading({ title: '发布中...' })
  329. const data = {
  330. id: productInfo.value.id,
  331. status: 1 // 审核中
  332. }
  333. editProductInfo(data).then(res => {
  334. uni.hideLoading()
  335. if (res.data.code === 200) {
  336. uni.showToast({
  337. title: '发布成功',
  338. icon: 'success'
  339. })
  340. setTimeout(() => {
  341. uni.navigateBack()
  342. }, 1000)
  343. } else {
  344. uni.showToast({
  345. title: res.data.msg || '发布失败,请稍后重试',
  346. icon: 'none'
  347. })
  348. }
  349. })
  350. }
  351. // 下架产品
  352. const removeProduct = () => {
  353. uni.showModal({
  354. title: '确认下架',
  355. content: '确定要下架这条信息吗?下架后其他用户将无法查看。',
  356. confirmText: '确认下架',
  357. cancelText: '取消',
  358. success: (res) => {
  359. if (res.confirm) {
  360. handleRemoveProduct()
  361. }
  362. }
  363. })
  364. }
  365. // 处理下架操作
  366. const handleRemoveProduct = () => {
  367. uni.showLoading({ title: '下架中...' })
  368. const data = {
  369. id: productInfo.value.id,
  370. status: 3 // 下架
  371. }
  372. editProductInfo(data).then(res => {
  373. uni.hideLoading()
  374. if (res.data.code === 200) {
  375. uni.showToast({
  376. title: '下架成功',
  377. icon: 'success'
  378. })
  379. setTimeout(() => {
  380. uni.navigateBack()
  381. }, 1500)
  382. } else {
  383. uni.showToast({
  384. title: res.data.msg || '下架失败,请稍后重试',
  385. icon: 'none'
  386. })
  387. }
  388. })
  389. }
  390. // 联系发布者
  391. const contactPublisher = () => {
  392. const realPhone = getRealPhoneNumber()
  393. uni.showModal({
  394. title: '联系发布者',
  395. content: `确定要拨打 ${realPhone} 吗?`,
  396. confirmText: '拨打',
  397. cancelText: '取消',
  398. success: (res) => {
  399. if (res.confirm) {
  400. uni.makePhoneCall({
  401. phoneNumber: realPhone,
  402. fail: () => {
  403. uni.showToast({
  404. title: '拨号失败',
  405. icon: 'none'
  406. })
  407. }
  408. })
  409. }
  410. }
  411. })
  412. }
  413. // 撤销产品(审核中状态)
  414. const cancelProduct = () => {
  415. uni.showModal({
  416. title: '确认撤销',
  417. content: '确定要撤销这条发布信息吗?撤销后需要重新提交审核。',
  418. confirmText: '确认撤销',
  419. cancelText: '取消',
  420. success: (res) => {
  421. if (res.confirm) {
  422. handleCancelProduct()
  423. }
  424. }
  425. })
  426. }
  427. // 处理撤销操作
  428. const handleCancelProduct = () => {
  429. uni.showLoading({ title: '撤销中...' })
  430. setTimeout(() => {
  431. uni.hideLoading()
  432. uni.showToast({
  433. title: '撤销成功',
  434. icon: 'success'
  435. })
  436. setTimeout(() => {
  437. uni.navigateBack()
  438. }, 1500)
  439. }, 1000)
  440. }
  441. // 获取真实电话号码
  442. const getRealPhoneNumber = () => {
  443. return '13379508760'
  444. }
  445. // 导出 onShow 供 uni-app 使用
  446. defineExpose({
  447. onShow
  448. })
  449. </script>
  450. <style lang="scss">
  451. .detail-container {
  452. min-height: 100vh;
  453. background-color: #f5f5f5;
  454. padding-bottom: 120rpx;
  455. }
  456. // 顶部封面图轮播
  457. .image-section {
  458. position: relative;
  459. margin: 20rpx;
  460. border-radius: 16rpx;
  461. overflow: hidden;
  462. background-color: #fff;
  463. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  464. }
  465. .image-swiper {
  466. width: 100%;
  467. height: 500rpx;
  468. }
  469. swiper-item {
  470. display: flex;
  471. align-items: center;
  472. justify-content: center;
  473. width: 100%;
  474. height: 100%;
  475. }
  476. .cover-image {
  477. width: 100%;
  478. height: 100%;
  479. }
  480. .custom-dots {
  481. position: absolute;
  482. bottom: 20rpx;
  483. left: 50%;
  484. transform: translateX(-50%);
  485. display: flex;
  486. gap: 12rpx;
  487. }
  488. .dot {
  489. width: 12rpx;
  490. height: 12rpx;
  491. border-radius: 6rpx;
  492. background-color: rgba(255, 255, 255, 0.5);
  493. transition: all 0.3s ease;
  494. &.active {
  495. background-color: #fff;
  496. width: 24rpx;
  497. }
  498. }
  499. // 标题和类型标签
  500. .title-section {
  501. margin: 0 20rpx 20rpx;
  502. background-color: #fff;
  503. border-radius: 16rpx;
  504. padding: 30rpx;
  505. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  506. }
  507. .title-content {
  508. display: flex;
  509. justify-content: space-between;
  510. align-items: flex-start;
  511. gap: 20rpx;
  512. }
  513. .product-title {
  514. flex: 1;
  515. font-size: 32rpx;
  516. font-weight: bold;
  517. color: #333;
  518. line-height: 1.4;
  519. }
  520. .type-tag {
  521. padding: 8rpx 16rpx;
  522. border-radius: 20rpx;
  523. font-size: 24rpx;
  524. font-weight: bold;
  525. flex-shrink: 0;
  526. &.sale {
  527. background-color: #e8f5e8;
  528. color: #4CAF50;
  529. }
  530. &.purchase {
  531. background-color: #e6f7ff;
  532. color: #1890ff;
  533. }
  534. }
  535. // 信息卡片通用样式
  536. .info-card, .description-card, .publisher-card {
  537. margin: 0 20rpx 20rpx;
  538. background-color: #fff;
  539. border-radius: 16rpx;
  540. padding: 30rpx;
  541. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  542. }
  543. .card-title {
  544. font-size: 28rpx;
  545. font-weight: bold;
  546. color: #333;
  547. margin-bottom: 24rpx;
  548. padding-bottom: 16rpx;
  549. border-bottom: 2rpx solid #f5f5f5;
  550. }
  551. // 核心信息展示
  552. .info-row {
  553. display: flex;
  554. justify-content: space-between;
  555. align-items: center;
  556. padding: 16rpx 0;
  557. border-bottom: 1rpx solid #f8f8f8;
  558. &:last-child {
  559. border-bottom: none;
  560. }
  561. }
  562. .info-label {
  563. font-size: 28rpx;
  564. color: #666;
  565. flex-shrink: 0;
  566. width: 120rpx;
  567. }
  568. .info-value {
  569. font-size: 28rpx;
  570. color: #333;
  571. font-weight: 500;
  572. text-align: right;
  573. flex: 1;
  574. &.price {
  575. color: #ff6b35;
  576. font-weight: bold;
  577. font-size: 30rpx;
  578. }
  579. &.location {
  580. color: #4CAF50;
  581. }
  582. &.phone {
  583. color: #1890ff;
  584. }
  585. }
  586. // 补充说明区域
  587. .description-content {
  588. padding: 20rpx;
  589. background-color: #f8f9fa;
  590. border-radius: 12rpx;
  591. border-left: 4rpx solid #4CAF50;
  592. }
  593. .description-text {
  594. font-size: 26rpx;
  595. color: #666;
  596. line-height: 1.6;
  597. }
  598. // 发布者信息
  599. .publisher-info {
  600. .info-row {
  601. padding: 20rpx 0;
  602. }
  603. }
  604. // 底部操作按钮
  605. .action-buttons {
  606. position: fixed;
  607. bottom: 0;
  608. left: 0;
  609. right: 0;
  610. padding: 20rpx 30rpx;
  611. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  612. background-color: #fff;
  613. border-top: 1rpx solid #f0f0f0;
  614. display: flex;
  615. gap: 20rpx;
  616. z-index: 100;
  617. }
  618. .action-btn {
  619. flex: 1;
  620. height: 80rpx;
  621. border-radius: 40rpx;
  622. font-size: 28rpx;
  623. font-weight: bold;
  624. border: none;
  625. transition: all 0.3s ease;
  626. &.edit-btn {
  627. background-color: #fff;
  628. color: #4CAF50;
  629. border: 2rpx solid #4CAF50;
  630. &:active {
  631. background-color: #f0fdf4;
  632. }
  633. }
  634. &.remove-btn {
  635. background-color: #fff;
  636. color: #ff4757;
  637. border: 2rpx solid #ff4757;
  638. &:active {
  639. background-color: #fff5f5;
  640. }
  641. }
  642. &.cancel-btn {
  643. background-color: #fff;
  644. color: #fa8c16;
  645. border: 2rpx solid #fa8c16;
  646. &:active {
  647. background-color: #fff7e6;
  648. }
  649. }
  650. &.contact-btn {
  651. background-color: #4CAF50;
  652. color: #fff;
  653. &:active {
  654. background-color: #45a049;
  655. }
  656. }
  657. }
  658. // 防止按钮点击状态样式被覆盖
  659. button[disabled] {
  660. opacity: 0.6;
  661. }
  662. button::after {
  663. border: none;
  664. }
  665. </style>