goodDetail.vue 11 KB

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