sales-detail.vue 18 KB

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