BookPage.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div class="book-container">
  3. <div class="swiper-content">
  4. <van-swipe
  5. v-if="dataList.length > 0"
  6. class="my-swipe"
  7. :autoplay="3000"
  8. indicator-color="white"
  9. >
  10. <van-swipe-item
  11. v-for="item in dataList[0].data.banner"
  12. :key="item.image"
  13. >
  14. <img :src="'https://images.weserv.nl/?url=' + item.image" />
  15. </van-swipe-item>
  16. </van-swipe>
  17. </div>
  18. <div class="nav-content">
  19. <van-grid :border="false" :clickable="true">
  20. <van-grid-item icon="fire" text="豆瓣经典" />
  21. <van-grid-item icon="shop-collect" text="家居生活" />
  22. <van-grid-item icon="photograph" text="外出旅行" />
  23. <van-grid-item icon="gift-card" text="文具小物" />
  24. </van-grid>
  25. </div>
  26. <div class="new-product" v-if="dataList.length > 0">
  27. <div class="new-product-title">新品首发</div>
  28. <div
  29. class="product-item"
  30. v-for="item in dataList[3].data.product_items"
  31. :key="item.id"
  32. >
  33. <div class="product-img-content">
  34. <van-image
  35. width="100%"
  36. height="4rem"
  37. :src="'https://images.weserv.nl/?url=' + item.image"
  38. />
  39. </div>
  40. <div class="product-info-content">
  41. <van-row gutter="20">
  42. <van-col span="18">
  43. <div class="product-name">
  44. {{ item.title }}
  45. </div>
  46. <div class="product-info">{{ item.desc }}</div>
  47. <div class="product-tag">
  48. <van-tag
  49. style="margin-right: 0.1rem"
  50. type="danger"
  51. v-for="val in item.tags"
  52. :key="val"
  53. >{{ val }}</van-tag
  54. >
  55. </div>
  56. </van-col>
  57. <van-col span="6">
  58. <div class="product-price">
  59. <span class="new-price">¥{{ item.promote_price }}</span>
  60. <span class="old-price">¥{{ item.price }}</span>
  61. </div>
  62. <div class="btn-content">
  63. <van-button size="small" round type="danger"
  64. >立即购买</van-button
  65. >
  66. </div>
  67. </van-col>
  68. </van-row>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="type-product">
  73. <van-tabs @click="tabChange" swipe-threshold="4" color="#191919">
  74. <van-tab title="全部商品"></van-tab>
  75. <van-tab title="豆瓣经典"></van-tab>
  76. <van-tab title="家居生活"></van-tab>
  77. <van-tab title="外出旅行"></van-tab>
  78. <van-tab title="文具小物"></van-tab>
  79. </van-tabs>
  80. <div class="type-product-list">
  81. <van-row gutter="10">
  82. <van-col span="12" v-for="item in typeProductList" :key="item.id">
  83. <ProductItem :val="item"></ProductItem>
  84. </van-col>
  85. </van-row>
  86. </div>
  87. </div>
  88. </div>
  89. </template>
  90. <style scoped>
  91. /* 商品分类 */
  92. .type-product {
  93. margin-top: 1rem;
  94. padding: 0 0.2rem;
  95. }
  96. /* 新品区域 */
  97. .new-product {
  98. padding: 0.2rem;
  99. }
  100. .new-product .product-item {
  101. margin-bottom: 0.2rem;
  102. }
  103. .new-product .new-product-title {
  104. font-size: 0.3rem;
  105. font-weight: 700;
  106. margin-bottom: 0.3rem;
  107. }
  108. .new-product .product-name {
  109. font-size: 0.3rem;
  110. font-weight: 700;
  111. width: 100%;
  112. white-space: nowrap;
  113. overflow: hidden;
  114. text-overflow: ellipsis;
  115. margin-bottom: 0.1rem;
  116. }
  117. .new-product .product-info {
  118. font-size: 0.25rem;
  119. color: #999;
  120. margin-bottom: 0.06rem;
  121. }
  122. .new-product .product-tag {
  123. line-height: 0;
  124. }
  125. .new-product .product-price {
  126. margin-bottom: 0.3rem;
  127. }
  128. .new-product .product-price .new-price {
  129. font-size: 0.3rem;
  130. color: #dd1944;
  131. font-weight: 700;
  132. }
  133. .new-product .product-price .old-price {
  134. font-size: 0.2rem;
  135. color: #999;
  136. text-decoration: line-through;
  137. }
  138. .new-product .product-price,
  139. .new-product .btn-content {
  140. line-height: 0;
  141. }
  142. /* 轮播图 */
  143. .my-swipe .van-swipe-item img {
  144. width: 100%;
  145. }
  146. .nav-content {
  147. border-bottom: 0.2rem solid #f9f9f9;
  148. }
  149. </style>
  150. <script>
  151. import Vue from "vue";
  152. import { Toast } from "vant";
  153. Vue.use(Toast);
  154. import ProductItem from "@/components/ProductItem.vue";
  155. import axios from "axios";
  156. export default {
  157. data() {
  158. return {
  159. dataList: [],
  160. typeProductList: [],
  161. };
  162. },
  163. created() {
  164. Toast.loading({
  165. message: "加载中...",
  166. forbidClick: true,
  167. duration: 0,
  168. });
  169. Promise.all([this.getDataList(), this.getTyepProduct()]).then(() => {
  170. Toast.clear();
  171. });
  172. },
  173. methods: {
  174. // tab切换
  175. tabChange(name) {
  176. let _typeUrl = "";
  177. switch (name) {
  178. case 0:
  179. _typeUrl = "products";
  180. break;
  181. case 1:
  182. _typeUrl = "category/classic";
  183. break;
  184. case 2:
  185. _typeUrl = "category/homelife";
  186. break;
  187. case 3:
  188. _typeUrl = "category/travel";
  189. break;
  190. case 4:
  191. _typeUrl = "category/stationery";
  192. break;
  193. }
  194. this.getTyepProduct(_typeUrl);
  195. },
  196. // 获取分类商品数据
  197. getTyepProduct(_typeUrl = "products") {
  198. return new Promise((resolve, reject) => {
  199. let url = "/market/market/" + _typeUrl;
  200. axios
  201. .get(url, {
  202. params: {
  203. start: 0,
  204. count: 10,
  205. },
  206. })
  207. .then((res) => {
  208. this.typeProductList = res.data.data.products;
  209. resolve(res);
  210. })
  211. .catch((error) => {
  212. reject(error);
  213. });
  214. });
  215. },
  216. // 获取轮播图及新品发布数据
  217. getDataList() {
  218. return new Promise((resolve, reject) => {
  219. axios
  220. .get("/market/market/home/modules")
  221. .then((res) => {
  222. this.dataList = res.data.data.modules;
  223. resolve(res);
  224. })
  225. .catch((error) => {
  226. reject(error);
  227. });
  228. });
  229. },
  230. },
  231. mounted() {
  232. this.$emit("changePage", "1002");
  233. },
  234. components: {
  235. ProductItem,
  236. },
  237. };
  238. </script>