goodDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <view class="d-content">
  3. <!-- 01. 轮播区 -->
  4. <view class="swiper-area w-full">
  5. <swiper class="h-full pos-r" indicator-dots circular="true" duration="400">
  6. <swiper-item v-for="(item, index) in goods.imgList" :key="index">
  7. <view class="wh-full">
  8. <image :src="item.url" class="wh-full loaded" lazy-load="true" mode="aspectFill"></image>
  9. </view>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <view class="d-content">
  14. <!-- 02. 商品数据区 -->
  15. <view class="goods-area bg-main padding">
  16. <view class="price-box dflex-b">
  17. <view>
  18. <text class="price fwb fs-big">{{ goods.minPrice || '' }} ~ {{ goods.maxPrice || ''}}</text>
  19. </view>
  20. <!-- <view class="dflex fs-sm ft-dark">
  21. <view class="margin-right-sm dflex" @click="">
  22. <uni-icons type="headphones" size="24" color="#999"></uni-icons>
  23. </view>
  24. <view class="margin-right-sm dflex">
  25. <uni-icons type="heart" size="24" color="#999"></uni-icons>
  26. </view>
  27. <view class="margin-right-sm dflex" @click="">
  28. <uni-icons type="redo" size="24" color="#999"></uni-icons>
  29. </view>
  30. </view> -->
  31. </view>
  32. <view class="container">
  33. <u-tag type="error" icon="coupon"></u-tag>
  34. <u-tag text="平台活动" type="error" plain plainFill></u-tag>
  35. </view>
  36. <!-- <view class="coupon">
  37. <view class="mj-tag">
  38. <view class="mj-icon padding-lr-xs">
  39. <u-icon name="rmb-circle" color="#FFF"></u-icon>
  40. </view>
  41. <text class="padding-lr-xs">优惠满减</text>
  42. </view>
  43. <text class="coupon-name">满30减20</text>
  44. </view> -->
  45. <view class="title fs">{{goods.spuName}}</view>
  46. <view class="sale">月销量:236</view>
  47. </view>
  48. <!-- 06. 详情区 -->
  49. <view class="gap"></view>
  50. <view class="spec-cell">
  51. <u-cell title="已选" isLink clickable @click="clickSpec" :border="false">
  52. <text slot="value" class="u-slot-value">{{specValue}}</text>
  53. </u-cell>
  54. </view>
  55. <!-- <view class="gap"></view>
  56. <view class="spec-cell">
  57. <u-cell title="发货" isLink clickable :border="false">
  58. <text slot="value" class="u-slot-value">预计5天内发货</text>
  59. </u-cell>
  60. </view> -->
  61. <view class="gap"></view>
  62. <view class="detail-area bg-main">
  63. <view class="d-header padding dflex-c"><text>图文详情</text>
  64. </view>
  65. <rich-text class="pro-detail" :nodes="goods.desc"></rich-text>
  66. <image mode="aspectFit" :src="goods.imgList[0].url"></image>
  67. </view>
  68. </view>
  69. <my-gap :height="130" bg="#f5f5f5" />
  70. <!-- 07. 操作区 -->
  71. <view class="cart-bottom padding-sm dflex-b">
  72. <view style="width: 60px;">
  73. <u-icon :name="service" label="客服" labelPos="bottom" size="32" @click="call"></u-icon>
  74. </view>
  75. <view style="width: 60px;">
  76. <uni-badge size="small" :text="buyCount" absolute="rightTop">
  77. <u-icon :name="shoppingCart" label="购物车" labelPos="bottom" size="32" @click="showCart"></u-icon>
  78. </uni-badge>
  79. </view>
  80. <view class="go-cart dflex-c" @click="toShop">加入购物车</view>
  81. <view class="go-buy dflex-c background-gradient" @click="toBuy">立即购买</view>
  82. </view>
  83. <!-- 置顶 -->
  84. <use-totop ref="usetop" bottom="120"></use-totop>
  85. <specPopup ref="specPopup" :cardMsg="cardMsg" @seChanged="seChanged" @addShop="carListMeg"></specPopup>
  86. <cartPopupVue ref="cartPopup" @selected-changed="handleSelectedChanged" />
  87. <u-toast ref="uToast"></u-toast>
  88. </view>
  89. </template>
  90. <script>
  91. import specPopup from '@/components/specPopup.vue'
  92. import cartPopupVue from '../../components/cartPopup.vue'
  93. import shoppingCart from '../../static/shoppingCart.png'
  94. import service from '../../static/service.png'
  95. export default {
  96. components: {
  97. specPopup,
  98. cartPopupVue
  99. },
  100. data() {
  101. return {
  102. cardMsg: {},
  103. buyCount: 0,
  104. total: 0,
  105. carList: {},
  106. detailMsg: {},
  107. shoppingCart: shoppingCart,
  108. service: service,
  109. specValue: '',
  110. // 商品ID
  111. id: 0,
  112. // 商品数据
  113. goods: {},
  114. // 轮播图
  115. scrollTop: 0,
  116. count: 1,
  117. dataDel: {},
  118. toList: []
  119. }
  120. },
  121. onLoad(option) {
  122. // 解码 URL 编码的字符串
  123. var dataString = decodeURIComponent(option.data);
  124. // 尝试将字符串转换为 JSON 对象
  125. var data = JSON.parse(dataString);
  126. this.dataDel = data
  127. // 打印解码后的数据
  128. console.log('eeeeeeeeeeeee============data', data);
  129. this.fatchDate()
  130. const e = uni.getStorageSync('carl')
  131. this.cList = e
  132. this.buyCount = data.tobyC
  133. },
  134. methods: {
  135. call() {
  136. console.log('eeeeeeeeeeeeeeee===============', this.cPhone)
  137. const e = uni.getStorageSync('info')
  138. this.cPhone = e
  139. if (this.cPhone.customerPhone) {
  140. uni.makePhoneCall({
  141. phoneNumber: this.cPhone.customerPhone
  142. })
  143. } else {
  144. uni.showToast({
  145. icon: 'none',
  146. title: '暂无商家电话'
  147. })
  148. }
  149. },
  150. handleSelectedChanged(selectedItems) {
  151. console.log('选中的数据:', selectedItems)
  152. //this.carList = selectedItems
  153. this.carListMeg()
  154. },
  155. clickSpec() {
  156. this.cardMsg = this.goods
  157. this.$nextTick(() => {
  158. this.$refs.specPopup.open(true);
  159. });
  160. },
  161. showCart() {
  162. this.$refs.cartPopup.setShow(true)
  163. this.$refs.cartPopup.openShop(true)
  164. },
  165. toShop() {
  166. const e = uni.getStorageSync('carl')
  167. const userId = uni.getStorageSync('appUserId')
  168. const params = {
  169. storeId: e.id,
  170. storeName: e.name,
  171. skuId: this.detailMsg.skuId,
  172. basePrice: this.detailMsg.retailPrice,
  173. price: this.detailMsg.retailPrice,
  174. quantity: this.count,
  175. extendProps: userId
  176. }
  177. console.log('params', params)
  178. this.$request('post', `/front/shoppingCart`, params, true).then(response => {
  179. // 请求成功
  180. console.log('response', response)
  181. if (response.code = 200) {
  182. // 弹出消息
  183. // uni.showToast({
  184. // title: '加入购物车成功',
  185. // icon: 'success',
  186. // duration: 2000
  187. // })
  188. this.$refs.uToast.show({
  189. type: 'success',
  190. title: '默认主题',
  191. message: "加入购物车成功",
  192. position: 'center'
  193. })
  194. this.carListMeg()
  195. } else if (response.code = 500) {
  196. uni.showToast({
  197. title: response.msg,
  198. icon: 'warning',
  199. duration: 2000
  200. })
  201. }
  202. }).catch(error => {
  203. // 请求失败
  204. console.error('请求失败:', response.msg);
  205. })
  206. },
  207. async carListMeg() {
  208. const res = await this.$request('get', `/front/shoppingCart/list`, {
  209. storeId: this.cList.id
  210. })
  211. console.log('res.data==============', res.data)
  212. if (res) {
  213. this.carList = res.data
  214. this.buyCount = this.carList.length
  215. }
  216. },
  217. //获取详情列表
  218. async fatchDate() {
  219. const id = this.dataDel.spuId
  220. const res = await this.$request('get', `/item/spu/queryProduct/${id}`)
  221. if (res) {
  222. this.goods = res.data
  223. }
  224. console.log('res', res.data)
  225. },
  226. //根据skuid获取选择商品信息
  227. async seChanged(e) {
  228. // console.log('==================3e', e)
  229. this.specValue = e.item
  230. this.count = e.count
  231. const res = await this.$request('get', `/item/sku/queryItem/${e.id}`)
  232. this.detailMsg = res.data
  233. console.log('this.detailMsg', this.detailMsg)
  234. },
  235. totalPrice() {
  236. const e = uni.getStorageSync('carl')
  237. const userId = uni.getStorageSync('appUserId')
  238. const toList = {
  239. storeId: e.id,
  240. storeName: e.name,
  241. skuId: this.detailMsg.skuId,
  242. basePrice: this.detailMsg.retailPrice,
  243. price: this.detailMsg.retailPrice,
  244. quantity: this.count,
  245. extendProps: userId,
  246. imgUrl: this.detailMsg.img,
  247. spuId: this.detailMsg.spuId,
  248. skuName: this.detailMsg.skuName,
  249. skuProperties: this.detailMsg.skuProperties,
  250. skuTitle: this.detailMsg.title,
  251. }
  252. let total = 0;
  253. // 如果 selected 属性不存在,直接计算所有商品
  254. let priceInCents = Math.round(toList.price * 100);
  255. let quant = toList.quantity;
  256. total += priceInCents * quant;
  257. this.toList.push(toList)
  258. // 将总价格转换回浮点数(以元为单位)
  259. this.total = (total / 100).toFixed(2);
  260. },
  261. // 去购买
  262. toBuy() {
  263. this.totalPrice()
  264. const carlist = {
  265. carlist: this.toList,
  266. total: this.total
  267. }
  268. uni.navigateTo({
  269. url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
  270. })
  271. this.toList = []
  272. // uni.navigateTo({
  273. // url: `/pages/order/submitOrder/submitOrder`
  274. // })
  275. }
  276. }
  277. }
  278. </script>
  279. <style scoped lang="scss">
  280. .d-content {
  281. background: $page-color-base;
  282. width: 100%;
  283. }
  284. .fixed-top {
  285. bottom: 230rpx;
  286. }
  287. /* 01. 轮播区 */
  288. .swiper-area {
  289. height: 500rpx;
  290. z-index: -1;
  291. width: 100%;
  292. }
  293. /* 02. 商品数据区 */
  294. .goods-area {
  295. // margin-top: 720rpx;
  296. .price-box {
  297. display: flex;
  298. align-items: baseline;
  299. }
  300. .title {
  301. color: $font-color-dark;
  302. // height: 46rpx;
  303. // line-height: 46rpx;
  304. font-weight: 700;
  305. }
  306. }
  307. /* 06. 详情区 */
  308. .detail-area {
  309. .d-header {
  310. font-size: $font-base + 2upx;
  311. color: $font-color-dark;
  312. position: relative;
  313. text {
  314. padding: 0 20rpx;
  315. background: #fff;
  316. position: relative;
  317. z-index: 1;
  318. }
  319. &:after {
  320. position: absolute;
  321. left: 50%;
  322. top: 50%;
  323. transform: translateX(-50%);
  324. width: 300rpx;
  325. height: 0;
  326. content: '';
  327. border-bottom: 1px solid #ccc;
  328. }
  329. }
  330. /* 产品详情 */
  331. .pro-detail {
  332. width: 100%;
  333. overflow: hidden;
  334. -webkit-touch-callout: none;
  335. img {
  336. width: 100%;
  337. max-width: 100%;
  338. overflow: hidden;
  339. }
  340. }
  341. }
  342. /* 优惠券区 */
  343. .coupon-area {
  344. max-height: 60vh;
  345. min-height: 30vh;
  346. .coupon-item {
  347. margin-bottom: 20rpx;
  348. &:last-child {
  349. margin-bottom: 0;
  350. }
  351. .content {
  352. &:after {
  353. position: absolute;
  354. left: 0;
  355. bottom: 0;
  356. content: '';
  357. width: 100%;
  358. height: 0;
  359. border-bottom: 1px dashed #f3f3f3;
  360. transform: scaleY(50%);
  361. }
  362. }
  363. .circle {
  364. position: absolute;
  365. bottom: -10rpx;
  366. z-index: 10;
  367. width: 20rpx;
  368. height: 20rpx;
  369. background: #f5f5f5;
  370. border-radius: 50%;
  371. &.r {
  372. right: -6rpx;
  373. }
  374. &.l {
  375. left: -6rpx;
  376. }
  377. }
  378. }
  379. }
  380. .sale {
  381. color: #999;
  382. font-size: 12px;
  383. padding-top: 10upx;
  384. }
  385. .spec-cell {
  386. background: #FFF;
  387. }
  388. .u-slot-value {
  389. font-size: 12px;
  390. }
  391. .cart-bottom {
  392. width: 100%;
  393. position: fixed;
  394. left: 0;
  395. bottom: 0;
  396. height: 130rpx;
  397. box-sizing: border-box;
  398. background-color: #FFF;
  399. z-index: 10;
  400. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  401. .go-cart {
  402. height: 80%;
  403. box-sizing: border-box;
  404. border: solid 1px #FF0000;
  405. font-size: 14px;
  406. color: #FF0000;
  407. border-radius: 50upx;
  408. margin: 0 10px;
  409. width: 45%;
  410. }
  411. .go-buy {
  412. height: 80%;
  413. width: 45%;
  414. background-color: #FF0000;
  415. color: #FFF;
  416. border-radius: 50upx;
  417. font-size: 14px;
  418. }
  419. }
  420. .container {
  421. display: flex;
  422. // justify-content: space-between;
  423. margin: 10px 0;
  424. /* 添加一些外边距以便查看 */
  425. }
  426. </style>