product-details.vue 12 KB

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