| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <template>
- <div class="recommend" ref="container">
- <div class="title acea-row row-center-wrapper">
- <span class="iconfont icon-zhuangshixian"></span>
- <span class="name">为你推荐</span>
- <span class="iconfont icon-zhuangshixian lefticon"></span>
- </div>
- <div class="recommendList acea-row row-between-wrapper">
- <!--<router-link-->
- <!--:to="{ path: '/detail/' + item.id }"-->
- <!--class="item"-->
- <!--v-for="(item, index) in hostProduct"-->
- <!--:key="index"-->
- <!-->-->
- <div
- @click="goDetail(item)"
- v-for="(item, index) in hostProduct"
- :key="index"
- class="item"
- >
- <div class="pictrue">
- <img :src="item.image" class="image" />
- <span
- class="pictrue_log_big pictrue_log_class"
- v-if="item.activity && item.activity.type === '1'"
- >秒杀</span
- >
- <span
- class="pictrue_log_big pictrue_log_class"
- v-if="item.activity && item.activity.type === '2'"
- >砍价</span
- >
- <span
- class="pictrue_log_big pictrue_log_class"
- v-if="item.activity && item.activity.type === '3'"
- >拼团</span
- >
- </div>
- <div class="name line1">{{ item.store_name }}</div>
- <div class="money font-color-red">
- ¥<span class="num">{{ item.price }}</span>
- </div>
- </div>
- </div>
- <Loading :loaded="loadend" :loading="loading"></Loading>
- </div>
- </template>
- <script>
- import { getHostProducts } from "@api/store";
- import Loading from "@components/Loading";
- export default {
- name: "Recommend",
- props: {},
- components: {
- Loading
- },
- data: function() {
- return {
- hostProduct: [],
- page: 1,
- limit: 20,
- loadTitle: "",
- loading: false,
- loadend: false
- };
- },
- mounted: function() {
- this.hostProducts();
- this.$scroll(this.$refs.container.parentElement, () => {
- !this.loading && this.hostProducts();
- });
- },
- methods: {
- // 商品详情跳转
- goDetail(item) {
- if (item.activity && item.activity.type === "1") {
- this.$router.push({
- path:
- "/activity/seckill_detail/" +
- item.activity.id +
- "/" +
- item.activity.time +
- "/1"
- });
- } else if (item.activity && item.activity.type === "2") {
- this.$router.push({
- path: "/activity/dargain_detail/" + item.activity.id
- });
- } else if (item.activity && item.activity.type === "3") {
- this.$router.push({
- path: "/activity/group_detail/" + item.activity.id
- });
- } else {
- this.$router.push({ path: "/detail/" + item.id });
- }
- },
- hostProducts: function() {
- let that = this;
- if (that.loading) return; //阻止下次请求(false可以进行请求);
- if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
- that.loading = true;
- getHostProducts(that.page, that.limit).then(res => {
- that.loading = false;
- //apply();js将一个数组插入另一个数组;
- that.hostProduct.push.apply(that.hostProduct, res.data);
- that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
- that.page = that.page + 1;
- });
- }
- }
- };
- </script>
|