goodDetail.vue 9.3 KB

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