goodDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. </view>
  88. </template>
  89. <script>
  90. import specPopup from '@/components/specPopup.vue'
  91. import cartPopupVue from '../../components/cartPopup.vue'
  92. import shoppingCart from '../../static/shoppingCart.png'
  93. import service from '../../static/service.png'
  94. export default {
  95. components: {
  96. specPopup,
  97. cartPopupVue
  98. },
  99. data() {
  100. return {
  101. cardMsg: {},
  102. buyCount: 0,
  103. total: 0,
  104. carList: {},
  105. detailMsg: {},
  106. shoppingCart: shoppingCart,
  107. service: service,
  108. specValue: '',
  109. // 商品ID
  110. id: 0,
  111. // 商品数据
  112. goods: {},
  113. // 轮播图
  114. scrollTop: 0,
  115. count: 1,
  116. dataDel: {},
  117. toList:[]
  118. }
  119. },
  120. onLoad(option) {
  121. // 解码 URL 编码的字符串
  122. var dataString = decodeURIComponent(option.data);
  123. // 尝试将字符串转换为 JSON 对象
  124. var data = JSON.parse(dataString);
  125. this.dataDel = data
  126. // 打印解码后的数据
  127. console.log('eeeeeeeeeeeee============data', data);
  128. this.fatchDate()
  129. const e = uni.getStorageSync('carl')
  130. this.cList = e
  131. this.buyCount = data.tobyC
  132. },
  133. methods: {
  134. call() {
  135. console.log('eeeeeeeeeeeeeeee===============', this.cPhone)
  136. const e = uni.getStorageSync('info')
  137. this.cPhone = e
  138. if (this.cPhone.customerPhone) {
  139. uni.makePhoneCall({
  140. phoneNumber: this.cPhone.customerPhone
  141. })
  142. } else {
  143. uni.showToast({
  144. icon: 'none',
  145. title: '暂无商家电话'
  146. })
  147. }
  148. },
  149. handleSelectedChanged(selectedItems) {
  150. console.log('选中的数据:', selectedItems)
  151. //this.carList = selectedItems
  152. this.carListMeg()
  153. },
  154. clickSpec() {
  155. this.cardMsg = this.goods
  156. this.$nextTick(() => {
  157. this.$refs.specPopup.open(true);
  158. });
  159. },
  160. showCart() {
  161. this.$refs.cartPopup.setShow(true)
  162. this.$refs.cartPopup.openShop(true)
  163. },
  164. toShop() {
  165. const e = uni.getStorageSync('carl')
  166. const userId = uni.getStorageSync('appUserId')
  167. const params = {
  168. storeId: e.id,
  169. storeName: e.name,
  170. skuId: this.detailMsg.skuId,
  171. basePrice: this.detailMsg.retailPrice,
  172. price: this.detailMsg.retailPrice,
  173. quantity: this.count,
  174. extendProps: userId
  175. }
  176. console.log('params', params)
  177. this.$request('post', `/front/shoppingCart`, params, true).then(response => {
  178. // 请求成功
  179. console.log('response', response)
  180. if (response.code = 200) {
  181. // 弹出消息
  182. uni.showToast({
  183. title: '加入购物车成功',
  184. icon: 'success',
  185. duration: 2000
  186. })
  187. this.carListMeg()
  188. } else if (response.code = 500) {
  189. uni.showToast({
  190. title: response.msg,
  191. icon: 'warning',
  192. duration: 2000
  193. })
  194. }
  195. }).catch(error => {
  196. // 请求失败
  197. console.error('请求失败:', response.msg);
  198. })
  199. },
  200. async carListMeg() {
  201. const res = await this.$request('get', `/front/shoppingCart/list`, {
  202. storeId: this.cList.id
  203. })
  204. console.log('res.data==============', res.data)
  205. if (res) {
  206. this.carList = res.data
  207. this.buyCount = this.carList.length
  208. }
  209. },
  210. //获取详情列表
  211. async fatchDate() {
  212. const id = this.dataDel.spuId
  213. const res = await this.$request('get', `/item/spu/queryProduct/${id}`)
  214. if (res) {
  215. this.goods = res.data
  216. }
  217. console.log('res', res.data)
  218. },
  219. //根据skuid获取选择商品信息
  220. async seChanged(e) {
  221. console.log('==================3e', e)
  222. this.specValue = e.item
  223. this.count = e.count
  224. const res = await this.$request('get', `/item/sku/${e.id}`)
  225. this.detailMsg = res.data
  226. console.log('this.detailMsg', this.detailMsg)
  227. },
  228. totalPrice() {
  229. const e = uni.getStorageSync('carl')
  230. const userId = uni.getStorageSync('appUserId')
  231. const toList = {
  232. storeId: e.id,
  233. storeName: e.name,
  234. skuId: this.detailMsg.skuId,
  235. basePrice: this.detailMsg.retailPrice,
  236. price: this.detailMsg.retailPrice,
  237. quantity: this.count,
  238. extendProps: userId,
  239. imgUrl: this.detailMsg.img,
  240. spuId: this.detailMsg.spuId,
  241. skuName: this.detailMsg.skuName,
  242. skuProperties: this.detailMsg.skuProperties,
  243. skuTitle: this.detailMsg.title,
  244. }
  245. let total = 0;
  246. // 如果 selected 属性不存在,直接计算所有商品
  247. let priceInCents = Math.round(toList.price * 100);
  248. let quant = toList.quantity;
  249. total += priceInCents * quant;
  250. this.toList.push(toList)
  251. // 将总价格转换回浮点数(以元为单位)
  252. this.total = (total / 100).toFixed(2);
  253. },
  254. // 去购买
  255. toBuy() {
  256. this.totalPrice()
  257. const carlist = {
  258. carlist: this.toList,
  259. total: this.total
  260. }
  261. uni.navigateTo({
  262. url: `/pages/order/submitOrder/submitOrder?data=${encodeURIComponent(JSON.stringify(carlist))}`
  263. })
  264. this.toList = []
  265. // uni.navigateTo({
  266. // url: `/pages/order/submitOrder/submitOrder`
  267. // })
  268. }
  269. }
  270. }
  271. </script>
  272. <style scoped lang="scss">
  273. .d-content {
  274. background: $page-color-base;
  275. width: 100%;
  276. }
  277. .fixed-top {
  278. bottom: 230rpx;
  279. }
  280. /* 01. 轮播区 */
  281. .swiper-area {
  282. height: 500rpx;
  283. z-index: -1;
  284. width: 100%;
  285. }
  286. /* 02. 商品数据区 */
  287. .goods-area {
  288. // margin-top: 720rpx;
  289. .price-box {
  290. display: flex;
  291. align-items: baseline;
  292. }
  293. .title {
  294. color: $font-color-dark;
  295. // height: 46rpx;
  296. // line-height: 46rpx;
  297. font-weight: 700;
  298. }
  299. }
  300. /* 06. 详情区 */
  301. .detail-area {
  302. .d-header {
  303. font-size: $font-base + 2upx;
  304. color: $font-color-dark;
  305. position: relative;
  306. text {
  307. padding: 0 20rpx;
  308. background: #fff;
  309. position: relative;
  310. z-index: 1;
  311. }
  312. &:after {
  313. position: absolute;
  314. left: 50%;
  315. top: 50%;
  316. transform: translateX(-50%);
  317. width: 300rpx;
  318. height: 0;
  319. content: '';
  320. border-bottom: 1px solid #ccc;
  321. }
  322. }
  323. /* 产品详情 */
  324. .pro-detail {
  325. width: 100%;
  326. overflow: hidden;
  327. -webkit-touch-callout: none;
  328. img {
  329. width: 100%;
  330. max-width: 100%;
  331. overflow: hidden;
  332. }
  333. }
  334. }
  335. /* 优惠券区 */
  336. .coupon-area {
  337. max-height: 60vh;
  338. min-height: 30vh;
  339. .coupon-item {
  340. margin-bottom: 20rpx;
  341. &:last-child {
  342. margin-bottom: 0;
  343. }
  344. .content {
  345. &:after {
  346. position: absolute;
  347. left: 0;
  348. bottom: 0;
  349. content: '';
  350. width: 100%;
  351. height: 0;
  352. border-bottom: 1px dashed #f3f3f3;
  353. transform: scaleY(50%);
  354. }
  355. }
  356. .circle {
  357. position: absolute;
  358. bottom: -10rpx;
  359. z-index: 10;
  360. width: 20rpx;
  361. height: 20rpx;
  362. background: #f5f5f5;
  363. border-radius: 50%;
  364. &.r {
  365. right: -6rpx;
  366. }
  367. &.l {
  368. left: -6rpx;
  369. }
  370. }
  371. }
  372. }
  373. .sale {
  374. color: #999;
  375. font-size: 12px;
  376. padding-top: 10upx;
  377. }
  378. .spec-cell {
  379. background: #FFF;
  380. }
  381. .u-slot-value {
  382. font-size: 12px;
  383. }
  384. .cart-bottom {
  385. width: 100%;
  386. position: fixed;
  387. left: 0;
  388. bottom: 0;
  389. height: 130rpx;
  390. box-sizing: border-box;
  391. background-color: #FFF;
  392. z-index: 10;
  393. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  394. .go-cart {
  395. height: 80%;
  396. box-sizing: border-box;
  397. border: solid 1px #FF0000;
  398. font-size: 14px;
  399. color: #FF0000;
  400. border-radius: 50upx;
  401. margin: 0 10px;
  402. width: 45%;
  403. }
  404. .go-buy {
  405. height: 80%;
  406. width: 45%;
  407. background-color: #FF0000;
  408. color: #FFF;
  409. border-radius: 50upx;
  410. font-size: 14px;
  411. }
  412. }
  413. .container {
  414. display: flex;
  415. // justify-content: space-between;
  416. margin: 10px 0;
  417. /* 添加一些外边距以便查看 */
  418. }
  419. </style>