product-details.vue 11 KB

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