goodsDetails.vue 14 KB

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