product-details.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <view style="padding-bottom: 100upx;">
  3. <view style="background: white;padding-bottom: 10upx;">
  4. <view class="section carousel-wrapper">
  5. <swiper class="carousel" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
  6. circular>
  7. <swiper-item v-for="image in product.images">
  8. <view class="swiper-item">
  9. <image class="image" :src="image|imagesFilter" mode=""></image>
  10. </view>
  11. </swiper-item>
  12. </swiper>
  13. </view>
  14. <view class="row row-1">
  15. <text class="title"><text class="sxzg-icon">省心直供</text>{{product.name}}</text>
  16. </view>
  17. <view class="row row-2">
  18. <text class="org-price">¥{{product.org_price}}</text>
  19. <text class="stock">剩余库存{{product.stock}}</text>
  20. </view>
  21. <view class="row row-3">
  22. <text class="sxj-icon">省心价</text>
  23. <text class="price">¥{{product.price}}</text>
  24. </view>
  25. </view>
  26. <view class="details">
  27. <view class="btn" @tap="detailsIsOpen=!detailsIsOpen">
  28. <view>点击查看商品详情</view>
  29. <view class="arrow" :class="{'rotate':detailsIsOpen}">
  30. <uni-icons type="arrowright"></uni-icons>
  31. </view>
  32. </view>
  33. <view class="content" :class="{'show':detailsIsOpen}">
  34. <rich-text :nodes="product.details"></rich-text>
  35. </view>
  36. </view>
  37. <view class="section" style="margin-top: 20upx;">
  38. <view class="col-img-title">
  39. <image src="../../static/images/like.png" mode="scaleToFill" style="height: 28rpx;width: 363rpx;">
  40. </image>
  41. </view>
  42. <view class="like">
  43. <scroll-view scroll-x="true" :show-scrollbar="false" :enable-flex="true" style="white-space: nowrap;">
  44. <template v-for="product in likeProducts">
  45. <product-item type="swiper" :id="product.id" :image="product.images|imagesFilter"
  46. :title="product.name" :org-price="product.org_price" :price="product.price"></product-item>
  47. </template>
  48. </scroll-view>
  49. </view>
  50. </view>
  51. <view class="footer">
  52. <view class="collect">
  53. <view>
  54. <uni-icons type="heart" size="24"></uni-icons>
  55. </view>
  56. <view style="font-size: 24upx;">收藏</view>
  57. </view>
  58. <view class="btn-group">
  59. <view class="btn" @tap="option = 'addcart',popupVisible=true">
  60. <uni-icons type="cart" color="white" style="margin-right: 10upx;"></uni-icons>加入购物车
  61. </view>
  62. <view class="line"></view>
  63. <view class="btn" @tap="option = 'buy',popupVisible=true">立即下单</view>
  64. </view>
  65. </view>
  66. <view class="popup" v-if="popupVisible" @touchmove.stop.prevent>
  67. <view class="popup-wrapper">
  68. <view class="close" @tap="popupVisible=false">
  69. <uni-icons type="closeempty" size="30"></uni-icons>
  70. </view>
  71. <view class="row row-1">
  72. <view class="spec-image">
  73. <image class="image" :src="product.specs[curSpecIndex].image|imagesFilter" mode=""></image>
  74. </view>
  75. <view class="">
  76. <view class="title">
  77. 已选择 {{product.specs[curSpecIndex].name}}
  78. </view>
  79. <view class="org-price">
  80. ¥{{product.specs[curSpecIndex].org_price|priceFilter}}
  81. </view>
  82. <view>
  83. <text class="sxj-icon">省心价</text>
  84. <text class="price">¥{{product.specs[curSpecIndex].price|priceFilter}}</text>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="row row-2">
  89. <view class="label">
  90. 选择规格
  91. </view>
  92. </view>
  93. <view class="row row-3 spec-list">
  94. <template v-for="(spec,i) in product.specs">
  95. <view class="spec-item" :class="{'active':curSpecIndex===i}" @tap="curSpecIndex=i">{{spec.name}}
  96. </view>
  97. </template>
  98. </view>
  99. <view class="row row-4">
  100. <view class="label">
  101. 选择数量
  102. </view>
  103. <view class="counter">
  104. <view class="sub" @tap="num>1?num--:0">-</view>
  105. <input class="num" type="text" v-model="num" />
  106. <view class="plus" @tap="num++">+</view>
  107. </view>
  108. </view>
  109. <view class="row row-5 total-price">
  110. 合计:<text class="total-price-text">¥{{totalPrice}}</text>
  111. </view>
  112. <view class="row row-6 option">
  113. <button v-if="option === 'addcart'" class="btn" type="default" @tap="addCart">加入购物车</button>
  114. <button v-if="option === 'buy'" class="btn" type="default" @tap="buy">立即购买</button>
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. export default {
  122. data() {
  123. return {
  124. popupVisible: false,
  125. option: "addcart",
  126. likeProducts: [],
  127. product: {
  128. id: 0
  129. },
  130. detailsIsOpen: false,
  131. curSpecIndex: 0,
  132. num: 1,
  133. }
  134. },
  135. computed: {
  136. totalPrice() {
  137. return (this.product.specs[this.curSpecIndex].price * this.num).toFixed(2);
  138. }
  139. },
  140. onLoad(option) {
  141. this.getLikeProductsData();
  142. this.product.id = option.id;
  143. this.getProductData();
  144. },
  145. methods: {
  146. getLikeProductsData() {
  147. this.$http.get({
  148. url: "/product/rand",
  149. data: {
  150. limit: 10
  151. },
  152. success: (res) => {
  153. this.likeProducts = res.data.data
  154. }
  155. })
  156. },
  157. getProductData() {
  158. this.$http.get({
  159. url: "/product",
  160. data: {
  161. id: this.product.id
  162. },
  163. success: (res) => {
  164. this.product = res.data.data
  165. this.product.images = this.product.images.split(",")
  166. this.product.specs = JSON.parse(this.product.specs)
  167. }
  168. })
  169. },
  170. addCart() {
  171. this.$store.dispatch("cart/add", {
  172. id: this.product.id,
  173. num: this.num,
  174. specIndex: this.curSpecIndex
  175. }).then(uni.showToast({
  176. title: "加入购物车成功",
  177. icon: "none"
  178. }))
  179. },
  180. buy() {
  181. let data = {
  182. id: this.product.id,
  183. spec_index: this.curSpecIndex,
  184. num: this.num
  185. }
  186. this.$http.post({
  187. url: '/order/create',
  188. data: {
  189. 'products[]':JSON.stringify(data)
  190. },
  191. success: (res) => {
  192. uni.showModal({
  193. content: "下单成功",
  194. success: (res) => {
  195. if (res.confirm) {
  196. uni.navigateTo({
  197. url: "/pages/order/order"
  198. })
  199. }
  200. }
  201. })
  202. }
  203. })
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. .carousel-wrapper {
  210. .carousel {
  211. margin: auto;
  212. overflow: hidden;
  213. transform: translateY(0);
  214. width: 750rpx;
  215. height: 750rpx;
  216. .image {
  217. width: 750rpx;
  218. height: 750rpx;
  219. }
  220. }
  221. }
  222. .title {
  223. font-size: 30upx;
  224. font-weight: bold;
  225. color: #333333;
  226. display: inline-block;
  227. white-space: normal;
  228. display: -webkit-box;
  229. -webkit-box-orient: vertical;
  230. -webkit-line-clamp: 2;
  231. overflow: hidden;
  232. }
  233. .sxzg-icon {
  234. color: $primary-color;
  235. font-size: 22rpx;
  236. width: 120rpx;
  237. text-align: center;
  238. line-height: normal;
  239. border: 2rpx solid $primary-color;
  240. border-radius: 20rpx;
  241. display: inline-block;
  242. position: relative;
  243. top: -4rpx;
  244. margin-right: 10upx;
  245. // transform: scale(0.9);
  246. }
  247. .sxj-icon {
  248. background: $primary-color;
  249. color: white;
  250. font-size: 20upx;
  251. padding: 0 5upx;
  252. border-radius: 5upx;
  253. vertical-align: middle;
  254. }
  255. .row {
  256. margin: 20upx;
  257. display: flex;
  258. align-items: center;
  259. }
  260. .row-2 {
  261. justify-content: space-between;
  262. }
  263. .org-price,
  264. .stock {
  265. font-size: 28rpx;
  266. color: #999999;
  267. }
  268. .org-price {
  269. text-decoration: line-through;
  270. }
  271. .price {
  272. font-size: 28rpx;
  273. color: $primary-color;
  274. font-weight: bold;
  275. }
  276. .details {
  277. background: white;
  278. margin-top: 20upx;
  279. font-size: 30upx;
  280. .btn {
  281. padding: 20upx;
  282. display: flex;
  283. justify-content: space-between;
  284. }
  285. }
  286. .col-img-title {
  287. text-align: center;
  288. background: white;
  289. height: 80upx;
  290. line-height: 80upx;
  291. margin-bottom: 10upx;
  292. }
  293. .like .product-item {
  294. margin: 5rpx;
  295. &:first-child {
  296. margin-left: 10upx;
  297. }
  298. &:last-child {
  299. margin-right: 10upx;
  300. }
  301. }
  302. .content {
  303. max-height: 0;
  304. overflow: hidden;
  305. transition: max-height 0.5s;
  306. &.show {
  307. max-height: 10000upx;
  308. }
  309. }
  310. .arrow {
  311. transform: rotate(0deg);
  312. transition: all 0.5s;
  313. }
  314. .arrow.rotate {
  315. transform: rotate(90deg);
  316. // animation:myRotate 10s linear infinite;
  317. }
  318. .footer {
  319. display: flex;
  320. position: fixed;
  321. height: 100upx;
  322. background: white;
  323. bottom: 0;
  324. width: 100%;
  325. box-shadow: 0 0 10upx #999999;
  326. align-items: center;
  327. // color: white;
  328. padding: 0upx 20upx;
  329. box-sizing: border-box;
  330. justify-content: space-between;
  331. .btn-group {
  332. background: $primary-color;
  333. display: flex;
  334. color: white;
  335. width: 580upx;
  336. border-radius: 50upx;
  337. height: 80upx;
  338. align-items: center;
  339. .btn {
  340. flex: 1;
  341. text-align: center;
  342. font-size: 30upx;
  343. font-weight: bold;
  344. }
  345. .line {
  346. background: white;
  347. width: 1upx;
  348. height: 60upx;
  349. }
  350. }
  351. .collect {
  352. margin-left: 20upx;
  353. display: flex;
  354. flex-direction: column;
  355. align-items: center;
  356. & :last-child {
  357. margin-top: -8upx;
  358. }
  359. }
  360. }
  361. .popup {
  362. position: fixed;
  363. top: 0;
  364. left: 0;
  365. bottom: 0;
  366. width: 750upx;
  367. background: rgba(0, 0, 0, 0.6);
  368. overflow: hidden;
  369. .popup-wrapper {
  370. .close {
  371. position: absolute;
  372. right: 5upx;
  373. top: 0;
  374. transform: scale(0.6);
  375. }
  376. background: white;
  377. position: absolute;
  378. bottom: 0;
  379. width: 750upx;
  380. min-height: 300upx;
  381. border-radius: 20upx 20upx 0 0;
  382. }
  383. .spec-image {
  384. margin-right: 20upx;
  385. .image {
  386. width: 180upx;
  387. height: 180upx;
  388. background: #EEEEEE;
  389. }
  390. }
  391. .row-1 {
  392. align-items: flex-start;
  393. .org-price {
  394. margin-top: 20upx;
  395. }
  396. }
  397. .label {
  398. font-size: 28upx;
  399. }
  400. .spec-list {
  401. display: flex;
  402. justify-content: flex-start;
  403. flex-wrap: wrap;
  404. margin-bottom: 0;
  405. .spec-item {
  406. text-align: center;
  407. background: #CCCCCC;
  408. color: white;
  409. padding: 5upx 30upx;
  410. margin: 0 20upx 20upx 20upx;
  411. font-size: 28upx;
  412. border-radius: 10upx;
  413. &.active {
  414. background: $primary-color;
  415. }
  416. }
  417. }
  418. .row-4 {
  419. justify-content: space-between;
  420. }
  421. .counter {
  422. margin-right: 40upx;
  423. display: flex;
  424. border: 2upx solid #CCCCCC;
  425. font-size: 28upx;
  426. align-items: center;
  427. border-radius: 10upx;
  428. .sub,
  429. .plus {
  430. // transform: scale(0.5);
  431. font-weight: 0;
  432. width: 42upx;
  433. text-align: center;
  434. &:active {
  435. background: rgba(0, 0, 0, .1);
  436. }
  437. }
  438. .num {
  439. text-align: center;
  440. font-size: 24upx;
  441. border-left: 2upx solid #EEEEEE;
  442. border-right: 2upx solid #EEEEEE;
  443. width: 50upx;
  444. }
  445. }
  446. .total-price {
  447. font-size: 30upx;
  448. justify-content: flex-end;
  449. margin-right: 60upx;
  450. .total-price-text {
  451. color: $primary-color;
  452. font-weight: bold;
  453. }
  454. }
  455. .option {
  456. .btn {
  457. width: 600upx;
  458. line-height: 80upx;
  459. font-size: 30upx;
  460. background: $primary-color;
  461. color: white;
  462. border-radius: 40upx;
  463. font-weight: bold;
  464. }
  465. }
  466. }
  467. </style>