sales-detail.vue 17 KB

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