goodsDetails.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <template>
  2. <view class="container">
  3. <uv-navbar title="商品详情" placeholder @leftClick="goBack"></uv-navbar>
  4. <view class="swiperBox">
  5. <uv-swiper
  6. :list="details.images"
  7. height="100vw"
  8. indicator
  9. indicatorMode="dot"
  10. ></uv-swiper>
  11. </view>
  12. <view class="priceBox">
  13. <view class="priceBox_l" v-if="details.productPaymentMode == 1">
  14. <!-- <text class="iconfont2">&#xe669;</text> -->
  15. <text>{{ details.minPoints }}</text>
  16. +
  17. <view>
  18. <rich-text
  19. :nodes="$mUtil.priceBigSmallTwo(details.minSalePrice)"
  20. ></rich-text>
  21. </view>
  22. </view>
  23. <view class="priceBox_l" v-if="details.productPaymentMode == 0">
  24. <view>
  25. <rich-text
  26. :nodes="$mUtil.priceBigSmallTwo(details.minSalePrice)"
  27. ></rich-text>
  28. <!-- <rich-text :nodes="$mUtil.priceBigSmall('100')"></rich-text> -->
  29. </view>
  30. </view>
  31. <text class="discount">¥{{ details.maxMarketPrice }}</text>
  32. <!-- <text v-if="details.canGivePoint" class="u-font24 u-ml15" style="flex: 1;text-align: right;">
  33. 赠送:10 积分
  34. </text> -->
  35. </view>
  36. <view class="titleBox">
  37. <view class="titleBox_t">
  38. <text>{{ details.title }}</text>
  39. </view>
  40. <view class="titleBox_b">
  41. <view class="titleBox_b_l">
  42. 已售
  43. <text>{{ details.showSales }}</text>
  44. 件,仅剩
  45. <text>{{ details.stock }}</text>
  46. </view>
  47. <view class="titleBox_b_r">
  48. <view @click="collect" v-if="!collectStatus" class="iconfont"
  49. >&#xe757;</view
  50. >
  51. <view @click="collect" v-else class="iconfont collectionActive"
  52. >&#xe613;</view
  53. >
  54. </view>
  55. </view>
  56. </view>
  57. <view class="shopBox" @click.stop="goShop">
  58. <view class="shopBox_l">
  59. <view class="shopBox_l_img">
  60. <image :src="shopDetails.image"></image>
  61. </view>
  62. <view class="shopBox_l_content">
  63. <view class="shopBox_l_content_name uv-line-1">{{
  64. shopDetails.businessName
  65. }}</view>
  66. <view class="shopBox_l_content_address uv-line-2">
  67. <text class="iconfont" style="color: #fa6138" @click.stop="goLocal"
  68. >&#xe990;</text
  69. >
  70. {{ shopDetails.address }}
  71. </view>
  72. </view>
  73. </view>
  74. <view>
  75. <uv-icon name="arrow-right" size="24rpx" color="#000"></uv-icon>
  76. </view>
  77. </view>
  78. <uv-sticky :offsetTop="tabTop" z-index="100">
  79. <view class="tab">
  80. <view @tap="change(0)" :class="{ active: isChecked == 0 }"
  81. >商品详情</view
  82. >
  83. <view @tap="change(1)" :class="{ active: isChecked == 1 }"
  84. >用户评论<span v-if="commentTotal > 0"
  85. >({{ commentTotal }})</span
  86. ></view
  87. >
  88. </view>
  89. </uv-sticky>
  90. <view v-if="isChecked == 0">
  91. <view class="richText ql-editor-box">
  92. <uv-parse class="custom-parse" :content="details.content"></uv-parse>
  93. </view>
  94. </view>
  95. <view class="commentBox u-plr30" v-else>
  96. <comment :value="commentList"></comment>
  97. <uv-load-more v-if="commentList.length > 0" :status="status" />
  98. </view>
  99. <view class="btnBox">
  100. <view class="btnBox_l">
  101. <!-- <button open-type="share" class="btnBox_l_share">
  102. <view class="iconfont">&#xe625;</view>
  103. <view class="btnBox_l_text">分享</view>
  104. </button> -->
  105. <view class="btnBox_l_chat" @click="goChat">
  106. <image :src="$handleImageUrl('/kefu.png')" mode="aspectFill"></image>
  107. <view class="btnBox_l_text">客服</view>
  108. </view>
  109. <view class="btnBox_l_cart" @click="goTocart">
  110. <view class="">
  111. <view class="iconfont">&#xe752;</view>
  112. <view class="btnBox_l_text">购物车</view>
  113. </view>
  114. </view>
  115. </view>
  116. <!--普通商品-->
  117. <view class="btnBox_r">
  118. <button
  119. class="btnBox_r_car"
  120. v-if="details.productPaymentMode != 1"
  121. @click="buy(0)"
  122. >
  123. 加入购物车
  124. </button>
  125. <button
  126. v-if="details.productPaymentMode != 1"
  127. class="btnBox_r_buy"
  128. :class="{ btnBox_r_buy_active: details.productPaymentMode == 1 }"
  129. @click="buy(1)"
  130. >
  131. 立即购买
  132. </button>
  133. <button
  134. v-if="details.productPaymentMode == 1"
  135. class="btnBox_r_buy"
  136. :class="{ btnBox_r_buy_active: details.productPaymentMode == 1 }"
  137. @click="buy(2)"
  138. >
  139. 立即兑换
  140. </button>
  141. </view>
  142. </view>
  143. <!-- 规格选择组件 -->
  144. <skuSelect ref="shoppingCartRef" :details="details" />
  145. </view>
  146. </template>
  147. <script setup>
  148. import {
  149. productInfo,
  150. getBusinessInfo,
  151. getUserCollect,
  152. userCollectAdd,
  153. userCollectDel,
  154. shopOrderCommentPage,
  155. } from "@/api/shop.js";
  156. import { ref, getCurrentInstance } from "vue";
  157. import comment from "@/components/ld-comment/ld-comment.vue";
  158. import { onLoad, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
  159. const { proxy } = getCurrentInstance();
  160. const mUtil = proxy.$mUtil;
  161. const list = ref([]);
  162. const isChecked = ref(0);
  163. const commentList = ref([]);
  164. const commentTotal = ref(0);
  165. const shoppingCartRef = ref(null);
  166. const details = ref({});
  167. const shopDetails = ref({});
  168. const tabTop = ref(0);
  169. const collectObj = ref({});
  170. const collectStatus = ref(false);
  171. const timer = ref(null);
  172. const status = ref("nomore"); //loadmore - 加载前,loading - 加载中,nomore - 没有数据
  173. const queryParams = ref({
  174. pageNum: 1,
  175. pageSize: 10,
  176. });
  177. const goBack = () => {
  178. uni.navigateBack();
  179. };
  180. const goShop = () => {
  181. uni.navigateTo({
  182. url: "/pages/shop/index?businessId=" + shopDetails.value.businessId,
  183. });
  184. };
  185. const goTocart = () => {
  186. uni.switchTab({
  187. url: "/pages/tabtar/shoppingCart",
  188. });
  189. };
  190. onLoad((options) => {
  191. if (options.id) {
  192. queryParams.value.productId = options.id;
  193. getDetails(options.id);
  194. getCommentList();
  195. }
  196. uni.getSystemInfo({
  197. success: (res) => {
  198. tabTop.value = res.statusBarHeight + 44;
  199. },
  200. });
  201. });
  202. // 下拉刷新
  203. onPullDownRefresh(() => {
  204. queryParams.value.pageNum = 1;
  205. getDetails(queryParams.value.productId);
  206. getCommentList();
  207. });
  208. // 上拉加载更多
  209. onReachBottom(() => {
  210. if (status.value == "loadmore" && isChecked.value == 1) {
  211. queryParams.value.pageNum++;
  212. getCommentList();
  213. }
  214. });
  215. // 获取收藏状态
  216. const getCollectStatus = () => {
  217. let params = {
  218. entityId: details.value.productId,
  219. entityType: 1,
  220. };
  221. getUserCollect(params).then((res) => {
  222. collectObj.value = res.data || {};
  223. collectStatus.value = res.data ? true : false;
  224. });
  225. };
  226. // 收藏
  227. const collect = () => {
  228. console.log(timer.value);
  229. if (timer.value) {
  230. uni.$uv.toast("操作过于频繁,请稍后再试");
  231. return;
  232. }
  233. if (collectStatus.value) {
  234. userCollectDel(collectObj.value.id).then((res) => {
  235. collectStatus.value = false;
  236. uni.showToast({
  237. title: "取消收藏成功!",
  238. duration: 1500,
  239. });
  240. timer.value = setTimeout(() => {
  241. clearTimeout(timer.value);
  242. timer.value = null;
  243. }, 2000);
  244. });
  245. } else {
  246. let param = {
  247. entityType: 1,
  248. entityId: details.value.productId,
  249. };
  250. userCollectAdd(param).then((res) => {
  251. collectStatus.value = true;
  252. uni.showToast({
  253. title: "收藏成功!",
  254. duration: 1500,
  255. });
  256. timer.value = setTimeout(() => {
  257. clearTimeout(timer.value);
  258. timer.value = null;
  259. }, 2000);
  260. getCollectStatus();
  261. });
  262. }
  263. };
  264. // 获取评论列表
  265. const getCommentList = () => {
  266. status.value = "loading";
  267. shopOrderCommentPage(queryParams.value)
  268. .then((res) => {
  269. // commentList.value = res.rows;
  270. commentTotal.value = res.total;
  271. if (queryParams.value.pageNum == 1) {
  272. commentList.value = res.rows;
  273. } else {
  274. commentList.value = [...list.value, ...res.rows];
  275. }
  276. if (commentList.value.length < res.total) {
  277. status.value = "loadmore";
  278. } else {
  279. status.value = "noMore";
  280. }
  281. uni.stopPullDownRefresh();
  282. })
  283. .catch(() => {
  284. status.value = "loadmore";
  285. uni.stopPullDownRefresh();
  286. });
  287. };
  288. const getDetails = (id) => {
  289. productInfo(id)
  290. .then((res) => {
  291. if (res.data.videoUrl) {
  292. res.data.images = [...res.data.images, res.data.videoUrl];
  293. }
  294. details.value = res.data;
  295. getCollectStatus();
  296. getShopDetails(res.data.businessId);
  297. })
  298. .catch((err) => {
  299. // console.log(err);
  300. setTimeout(() => {
  301. uni.navigateBack();
  302. }, 500);
  303. });
  304. };
  305. const getShopDetails = (businessId) => {
  306. // let id = uni.getStorageSync("businessId");
  307. getBusinessInfo({ businessId: businessId }).then((res) => {
  308. shopDetails.value = res.data || {};
  309. });
  310. };
  311. const goLocal = () => {
  312. uni.openLocation({
  313. latitude: Number(shopDetails.value.latitude),
  314. longitude: Number(shopDetails.value.longitude),
  315. name: shopDetails.value.businessName,
  316. address: shopDetails.value.address,
  317. success: function () {
  318. console.log("success");
  319. },
  320. });
  321. };
  322. const change = (index) => {
  323. isChecked.value = index;
  324. };
  325. //点购物车/立即购买
  326. const buy = (i, id) => {
  327. let name = "";
  328. if (i == 0) {
  329. name = "加入购物车";
  330. } else if (i == 1) {
  331. name = "立即购买";
  332. } else {
  333. name = "立即兑换";
  334. }
  335. shoppingCartRef.value.open(name);
  336. };
  337. // 跳转到客服页面
  338. const goChat = () => {
  339. if (!shopDetails.value.customerServicePhone) {
  340. uni.showToast({
  341. title: "暂无客服热线",
  342. duration: 2000,
  343. icon: "none",
  344. });
  345. return;
  346. }
  347. mUtil.callup(shopDetails.value.customerServicePhone);
  348. };
  349. </script>
  350. <style lang="scss" scoped>
  351. .container {
  352. padding-bottom: 150rpx;
  353. }
  354. .swiperBox {
  355. width: 100%;
  356. height: 100vw;
  357. }
  358. .priceBox {
  359. padding: 24rpx;
  360. display: flex;
  361. align-items: baseline;
  362. background: #fa6138;
  363. color: #fff;
  364. font-size: 36rpx;
  365. .iconfont2 {
  366. font-size: 50rpx;
  367. vertical-align: bottom;
  368. }
  369. .discount {
  370. margin-left: 20rpx;
  371. font-size: 24rpx;
  372. text-decoration: line-through;
  373. }
  374. .priceBox_l {
  375. display: flex;
  376. align-items: center;
  377. }
  378. }
  379. .titleBox {
  380. padding: 8rpx 30rpx 40rpx;
  381. .titleBox_t {
  382. .tipsStatus {
  383. display: inline-block;
  384. padding: 6rpx 10rpx;
  385. background: #ff0000;
  386. border-radius: 10rpx 0px 10rpx 0px;
  387. line-height: 28rpx;
  388. text-align: center;
  389. margin-right: 10rpx;
  390. color: #fff;
  391. font-size: 20rpx;
  392. }
  393. > text {
  394. font-size: 34rpx;
  395. font-weight: bold;
  396. color: #1a1a1a;
  397. }
  398. }
  399. .titleBox_b {
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. .titleBox_b_l {
  404. font-size: 24rpx;
  405. margin-top: 15rpx;
  406. color: #999999;
  407. text {
  408. color: #ff6600;
  409. }
  410. }
  411. .titleBox_b_r {
  412. .iconfont {
  413. font-size: 40rpx;
  414. color: #999;
  415. }
  416. .collectionActive {
  417. color: #ff0000;
  418. // -webkit-transform: scale(1.2);
  419. // transform: scale(1.2);
  420. }
  421. }
  422. }
  423. }
  424. .shopBox {
  425. border-top: 10rpx solid #f5f5f5;
  426. border-bottom: 10rpx solid #f5f5f5;
  427. display: flex;
  428. align-items: center;
  429. justify-content: space-between;
  430. padding: 35rpx 30rpx;
  431. .shopBox_l {
  432. display: flex;
  433. align-items: center;
  434. image {
  435. width: 104rpx;
  436. height: 104rpx;
  437. border-radius: 50%;
  438. margin-right: 25rpx;
  439. }
  440. .shopBox_l_content {
  441. .shopBox_l_content_name {
  442. font-size: 28rpx;
  443. color: #1a1a1a;
  444. font-weight: bold;
  445. }
  446. .shopBox_l_content_address {
  447. font-size: 24rpx;
  448. color: #999;
  449. margin-top: 5rpx;
  450. }
  451. }
  452. }
  453. }
  454. .tab {
  455. position: sticky;
  456. top: 0;
  457. background-color: #fff;
  458. padding-top: 38rpx;
  459. z-index: 9;
  460. font-size: 30rpx;
  461. color: #1a1a1a;
  462. display: flex;
  463. align-items: center;
  464. justify-content: space-around;
  465. > view {
  466. padding-bottom: 30rpx;
  467. position: relative;
  468. &::before {
  469. content: "";
  470. position: absolute;
  471. left: 50%;
  472. bottom: 0;
  473. transform: translateX(-50%);
  474. width: 0;
  475. height: 2px;
  476. background: #fa6138;
  477. transition: all 0.3s;
  478. }
  479. &.active {
  480. font-size: 30rpx;
  481. color: #fa6138;
  482. font-weight: 700;
  483. &::before {
  484. width: 100%;
  485. }
  486. }
  487. }
  488. }
  489. .btnBox {
  490. display: flex;
  491. align-items: center;
  492. justify-content: space-between;
  493. padding: 30rpx;
  494. width: 100%;
  495. position: fixed;
  496. bottom: 0;
  497. z-index: 999;
  498. border-top: 1rpx solid #e6e6e6;
  499. background: #fff;
  500. box-sizing: border-box;
  501. .btnBox_l {
  502. display: flex;
  503. align-items: center;
  504. height: 84rpx;
  505. > view,
  506. > button {
  507. display: flex;
  508. flex-direction: column;
  509. justify-content: flex-end;
  510. height: 84rpx;
  511. line-height: 42rpx;
  512. margin-right: 20rpx;
  513. .iconfont {
  514. color: #999;
  515. font-size: 40rpx;
  516. }
  517. .btnBox_l_text {
  518. color: #1a1a1a;
  519. font-size: 28rpx;
  520. }
  521. image {
  522. width: 40rpx;
  523. height: 40rpx;
  524. margin: 0 auto;
  525. }
  526. }
  527. // .btnBox_l_chat {
  528. // }
  529. .btnBox_l_cart {
  530. text-align: center;
  531. margin-right: 0;
  532. }
  533. }
  534. .btnBox_r {
  535. display: flex;
  536. > button {
  537. width: 200rpx;
  538. height: 85rpx;
  539. line-height: 85rpx;
  540. background: #fa6138;
  541. color: white;
  542. border-radius: 40rpx;
  543. font-size: 30rpx;
  544. }
  545. .btnBox_r_car {
  546. background: #ff9651;
  547. margin-right: 20rpx;
  548. }
  549. .btnBox_r_buy {
  550. background: #fa6138;
  551. }
  552. .btnBox_r_buy.btnBox_r_buy_active {
  553. width: 400rpx !important;
  554. }
  555. }
  556. }
  557. button {
  558. border: none;
  559. padding: 0;
  560. margin: 0;
  561. background-color: transparent;
  562. background: transparent;
  563. }
  564. button::after {
  565. border: none;
  566. }
  567. .richText {
  568. padding: 20rpx;
  569. min-height: 50vh;
  570. }
  571. .commentBox {
  572. min-height: 50vh;
  573. }
  574. </style>