product-details.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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.navigateTo({
  193. url: "/pages/order/cashier?order_no="+res.data.data
  194. })
  195. }
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .carousel-wrapper {
  203. .carousel {
  204. margin: auto;
  205. overflow: hidden;
  206. transform: translateY(0);
  207. width: 750rpx;
  208. height: 750rpx;
  209. .image {
  210. width: 750rpx;
  211. height: 750rpx;
  212. }
  213. }
  214. }
  215. .title {
  216. font-size: 30upx;
  217. font-weight: bold;
  218. color: #333333;
  219. display: inline-block;
  220. white-space: normal;
  221. display: -webkit-box;
  222. -webkit-box-orient: vertical;
  223. -webkit-line-clamp: 2;
  224. overflow: hidden;
  225. }
  226. .sxzg-icon {
  227. color: $primary-color;
  228. font-size: 20rpx;
  229. width: 120rpx;
  230. text-align: center;
  231. line-height: normal;
  232. border: 2rpx solid $primary-color;
  233. border-radius: 20rpx;
  234. display: inline-block;
  235. position: relative;
  236. top: -4rpx;
  237. margin-right: 10upx;
  238. // transform: scale(0.9);
  239. }
  240. .sxj-icon {
  241. background: $primary-color;
  242. color: white;
  243. font-size: 20upx;
  244. padding: 0 5upx;
  245. border-radius: 5upx;
  246. vertical-align: middle;
  247. }
  248. .row {
  249. margin: 20upx;
  250. display: flex;
  251. align-items: center;
  252. }
  253. .row-2 {
  254. justify-content: space-between;
  255. }
  256. .org-price,
  257. .stock {
  258. font-size: 28rpx;
  259. color: #999999;
  260. }
  261. .org-price {
  262. text-decoration: line-through;
  263. }
  264. .price {
  265. font-size: 28rpx;
  266. color: $primary-color;
  267. font-weight: bold;
  268. }
  269. .details {
  270. background: white;
  271. margin-top: 20upx;
  272. font-size: 30upx;
  273. .btn {
  274. padding: 20upx;
  275. display: flex;
  276. justify-content: space-between;
  277. }
  278. }
  279. .col-img-title {
  280. text-align: center;
  281. background: white;
  282. height: 80upx;
  283. line-height: 80upx;
  284. margin-bottom: 10upx;
  285. }
  286. .like .product-item {
  287. margin: 5rpx;
  288. &:first-child {
  289. margin-left: 10upx;
  290. }
  291. &:last-child {
  292. margin-right: 10upx;
  293. }
  294. }
  295. .content {
  296. max-height: 0;
  297. overflow: hidden;
  298. transition: max-height 0.5s;
  299. &.show {
  300. max-height: 10000upx;
  301. }
  302. }
  303. .arrow {
  304. transform: rotate(0deg);
  305. transition: all 0.5s;
  306. }
  307. .arrow.rotate {
  308. transform: rotate(90deg);
  309. // animation:myRotate 10s linear infinite;
  310. }
  311. .footer {
  312. display: flex;
  313. position: fixed;
  314. height: 100upx;
  315. background: white;
  316. bottom: 0;
  317. width: 100%;
  318. box-shadow: 0 0 10upx #999999;
  319. align-items: center;
  320. // color: white;
  321. padding: 0upx 20upx;
  322. box-sizing: border-box;
  323. justify-content: space-between;
  324. .btn-group {
  325. background: $primary-color;
  326. display: flex;
  327. color: white;
  328. width: 580upx;
  329. border-radius: 50upx;
  330. height: 80upx;
  331. align-items: center;
  332. .btn {
  333. flex: 1;
  334. text-align: center;
  335. font-size: 30upx;
  336. font-weight: bold;
  337. }
  338. .line {
  339. background: white;
  340. width: 1upx;
  341. height: 60upx;
  342. }
  343. }
  344. .collect {
  345. margin-left: 20upx;
  346. display: flex;
  347. flex-direction: column;
  348. align-items: center;
  349. & :last-child {
  350. margin-top: -8upx;
  351. }
  352. }
  353. }
  354. .popup {
  355. position: fixed;
  356. top: 0;
  357. left: 0;
  358. bottom: 0;
  359. width: 750upx;
  360. background: rgba(0, 0, 0, 0.6);
  361. overflow: hidden;
  362. .popup-wrapper {
  363. .close {
  364. position: absolute;
  365. right: 5upx;
  366. top: 0;
  367. transform: scale(0.6);
  368. }
  369. background: white;
  370. position: absolute;
  371. bottom: 0;
  372. width: 750upx;
  373. min-height: 300upx;
  374. border-radius: 20upx 20upx 0 0;
  375. }
  376. .spec-image {
  377. margin-right: 20upx;
  378. .image {
  379. width: 180upx;
  380. height: 180upx;
  381. background: #EEEEEE;
  382. }
  383. }
  384. .row-1 {
  385. align-items: flex-start;
  386. .org-price {
  387. margin-top: 20upx;
  388. }
  389. }
  390. .label {
  391. font-size: 28upx;
  392. }
  393. .spec-list {
  394. display: flex;
  395. justify-content: flex-start;
  396. flex-wrap: wrap;
  397. margin-bottom: 0;
  398. .spec-item {
  399. text-align: center;
  400. background: #CCCCCC;
  401. color: white;
  402. padding: 5upx 30upx;
  403. margin: 0 20upx 20upx 20upx;
  404. font-size: 28upx;
  405. border-radius: 10upx;
  406. &.active {
  407. background: $primary-color;
  408. }
  409. }
  410. }
  411. .row-4 {
  412. justify-content: space-between;
  413. }
  414. .counter {
  415. margin-right: 40upx;
  416. display: flex;
  417. border: 2upx solid #CCCCCC;
  418. font-size: 28upx;
  419. align-items: center;
  420. border-radius: 10upx;
  421. .sub,
  422. .plus {
  423. // transform: scale(0.5);
  424. font-weight: 0;
  425. width: 42upx;
  426. text-align: center;
  427. &:active {
  428. background: rgba(0, 0, 0, .1);
  429. }
  430. }
  431. .num {
  432. text-align: center;
  433. font-size: 24upx;
  434. border-left: 2upx solid #EEEEEE;
  435. border-right: 2upx solid #EEEEEE;
  436. width: 50upx;
  437. }
  438. }
  439. .total-price {
  440. font-size: 30upx;
  441. justify-content: flex-end;
  442. margin-right: 60upx;
  443. .total-price-text {
  444. color: $primary-color;
  445. font-weight: bold;
  446. }
  447. }
  448. .option {
  449. .btn {
  450. width: 600upx;
  451. line-height: 80upx;
  452. font-size: 30upx;
  453. background: $primary-color;
  454. color: white;
  455. border-radius: 40upx;
  456. font-weight: bold;
  457. }
  458. }
  459. }
  460. </style>