index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div class="ns-groupbuy">
  3. <div class="ns-groupbuy-head">
  4. <el-carousel height="420px" v-loading="loadingAd" v-if="adList.length">
  5. <el-carousel-item v-for="item in adList" :key="item.adv_id"><el-image :src="$img(item.adv_image)" fit="cover" @click="$util.pushToTab(item.adv_url.url)" /></el-carousel-item>
  6. </el-carousel>
  7. </div>
  8. <!-- 商品列表 -->
  9. <div class="ns-groupbuy-box" v-loading="loading">
  10. <div class="ns-groupbuy-title" v-if="goodsList.length">
  11. <span class="groupbuy-title-left">团购专区</span>
  12. </div>
  13. <div class="goods-list" v-if="goodsList.length">
  14. <div class="goods" v-for="item in goodsList" :key="item.id" @click="$router.push('/promotion/groupbuy/' + item.groupbuy_id)">
  15. <!-- 商品图片区 -->
  16. <div class="img"><el-image fit="scale-down" :src="$img(item.goods_image, { size: 'mid' })" lazy @error="imageError(index)"></el-image></div>
  17. <!-- 商品名称 -->
  18. <div class="name">
  19. <p :title="item.goods_name">{{ item.goods_name }}</p>
  20. </div>
  21. <!-- 价格展示区 -->
  22. <div class="price">
  23. <div class="curr-price">
  24. <span>团购价</span>
  25. <span>¥</span>
  26. <span class="main_price">{{ item.groupbuy_price }}</span>
  27. </div>
  28. <span class="primary_price">¥{{ item.price }}</span>
  29. </div>
  30. <el-button>立即拼购</el-button>
  31. </div>
  32. </div>
  33. <div v-else-if="!loading" class="empty-wrap">
  34. <img src="~assets/images/goods_empty.png" >
  35. <span>暂无正在进行团购的商品,<router-link to="/" class="ns-text-color">去首页</router-link>看看吧</span>
  36. </div>
  37. <div class="pager">
  38. <el-pagination
  39. background
  40. :pager-count="5"
  41. :total="total"
  42. prev-text="上一页"
  43. next-text="下一页"
  44. :current-page.sync="currentPage"
  45. :page-size.sync="pageSize"
  46. @size-change="handlePageSizeChange"
  47. @current-change="handleCurrentPageChange"
  48. hide-on-single-page
  49. ></el-pagination>
  50. </div>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import { goodsPage } from '@/api/groupbuy';
  56. import { mapGetters } from 'vuex';
  57. import { adList } from '@/api/website';
  58. export default {
  59. name: 'groupbuy',
  60. components: {},
  61. data: () => {
  62. return {
  63. loading: true,
  64. goodsList: [],
  65. total: 0,
  66. currentPage: 1,
  67. pageSize: 25,
  68. loadingAd: true,
  69. adList: []
  70. };
  71. },
  72. created() {
  73. if (this.addonIsExit && this.addonIsExit.groupbuy != 1) {
  74. this.$message({
  75. message: '团购插件未安装',
  76. type: 'warning',
  77. duration: 2000,
  78. onClose: () => {
  79. this.$route.push('/');
  80. }
  81. });
  82. } else {
  83. this.getAdList();
  84. this.getGoodsList();
  85. }
  86. },
  87. computed: {
  88. ...mapGetters(['defaultGoodsImage', 'addonIsExit'])
  89. },
  90. head() {
  91. return {
  92. title: '团购专区-' + this.$store.state.site.siteInfo.site_name,
  93. meta: [{
  94. name: 'description',
  95. content: this.$store.state.site.siteInfo.seo_description
  96. },
  97. {
  98. name: 'keyword',
  99. content: this.$store.state.site.siteInfo.seo_keywords
  100. }
  101. ]
  102. }
  103. },
  104. watch: {
  105. addonIsExit() {
  106. if (this.addonIsExit.groupbuy != 1) {
  107. this.$message({
  108. message: '团购插件未安装',
  109. type: 'warning',
  110. duration: 2000,
  111. onClose: () => {
  112. this.$route.push('/');
  113. }
  114. });
  115. }
  116. }
  117. },
  118. methods: {
  119. getAdList() {
  120. adList({ keyword: 'NS_PC_GROUPBUY' })
  121. .then(res => {
  122. this.adList = res.data.adv_list;
  123. for (let i = 0; i < this.adList.length; i++) {
  124. if (this.adList[i].adv_url) this.adList[i].adv_url = JSON.parse(this.adList[i].adv_url);
  125. }
  126. this.loadingAd = false;
  127. })
  128. .catch(err => {
  129. this.loadingAd = false;
  130. });
  131. },
  132. /**
  133. * 团购商品
  134. */
  135. getGoodsList() {
  136. goodsPage({
  137. page_size: this.pageSize,
  138. page: this.currentPage
  139. })
  140. .then(res => {
  141. this.goodsList = res.data.list;
  142. this.total = res.data.count;
  143. this.loading = false;
  144. })
  145. .catch(err => {
  146. this.loading = false;
  147. this.$message.error(err.message);
  148. });
  149. },
  150. handlePageSizeChange(size) {
  151. this.pageSize = size;
  152. this.refresh();
  153. },
  154. handleCurrentPageChange(page) {
  155. this.currentPage = page;
  156. this.refresh();
  157. },
  158. refresh() {
  159. this.loading = true;
  160. this.getGoodsList();
  161. },
  162. /**
  163. * 图片加载失败
  164. */
  165. imageError(index) {
  166. this.goodsList[index].goods_image = this.defaultGoodsImage;
  167. }
  168. }
  169. };
  170. </script>
  171. <style lang="scss" scoped>
  172. .ns-groupbuy {
  173. .ns-groupbuy-box {
  174. padding: 48px 0;
  175. width: $width;
  176. margin: 0 auto;
  177. .ns-groupbuy-title {
  178. display: flex;
  179. align-items: center;
  180. border-bottom: 1px solid #e8e8e8;
  181. .groupbuy-title-left{
  182. font-size: 30px;
  183. color: #333;
  184. border-bottom: 4px solid #F42424;
  185. }
  186. }
  187. }
  188. .goods-list {
  189. display: flex;
  190. flex-direction: row;
  191. flex-wrap: wrap;
  192. justify-content: flex-start;
  193. margin-top: 32px;
  194. .goods {
  195. margin-right: 17px;
  196. margin-bottom: 18px;
  197. width: 228px;
  198. background-color: #ffffff;
  199. overflow: hidden;
  200. color: #303133;
  201. transition: 0.3s;
  202. padding: 18px;
  203. box-sizing: border-box;
  204. cursor: pointer;
  205. &:nth-child(5n+5){
  206. margin-right: 0;
  207. }
  208. }
  209. .img {
  210. width: 192px;
  211. height: 192px;
  212. .el-image{
  213. max-width: 100%;
  214. max-height: 100%;
  215. }
  216. }
  217. .price {
  218. display: flex;
  219. align-items: baseline;
  220. .curr-price {
  221. display: flex;
  222. align-items: baseline;
  223. height: 24px;
  224. font-weight: bold;
  225. color: $base-color;
  226. span:first-child {
  227. font-size: 14px;
  228. margin-right: 1px;
  229. }
  230. span:nth-child(2) {
  231. font-size: 12px;
  232. }
  233. }
  234. .main_price {
  235. color: $base-color;
  236. font-size: 14px;
  237. line-height: 24px;
  238. }
  239. .primary_price {
  240. text-decoration: line-through;
  241. color: $base-color-info;
  242. margin-left: 5px;
  243. font-size: 12px;
  244. }
  245. }
  246. .el-button {
  247. width: 100%;
  248. height: 42px;
  249. line-height: 42px;
  250. background: $base-color;
  251. color: #ffffff;
  252. margin-top: 10px;
  253. border: none;
  254. border-radius: 0;
  255. padding: 0;
  256. font-size: 16px;
  257. }
  258. .name {
  259. margin-top: 12px;
  260. font-size: 14px;
  261. line-height: 1.4;
  262. margin-bottom: 5px;
  263. white-space: normal;
  264. overflow: hidden;
  265. p {
  266. line-height: 24px;
  267. display: -webkit-box;
  268. -webkit-box-orient: vertical;
  269. -webkit-line-clamp: 2;
  270. overflow: hidden;
  271. height: 50px;
  272. }
  273. }
  274. }
  275. .empty-wrap{
  276. padding: 50px 0 60px;
  277. display: flex;
  278. flex-direction: column;
  279. align-items: center;
  280. justify-content: center;
  281. box-sizing: border-box;
  282. img{
  283. width: 400px;
  284. height: 244px;
  285. }
  286. span{
  287. font-size: 14px;
  288. color: #4A4A4A;
  289. }
  290. }
  291. }
  292. </style>
  293. <style lang="scss">
  294. .ns-groupbuy {
  295. .ns-groupbuy-head{
  296. width: $width;
  297. margin: auto;
  298. }
  299. .el-carousel {
  300. .el-image{
  301. height: 100%;
  302. }
  303. .el-image__inner {
  304. width: auto;
  305. }
  306. }
  307. .el-carousel__arrow--right{
  308. right: 60px;
  309. }
  310. }
  311. </style>