activeList.vue 5.87 KB
Newer Older
xd's avatar
xd committed
1
<template>
xd's avatar
xd committed
2
  <div class="container">
leiqingsong's avatar
leiqingsong committed
3
    <div v-if="wheelList.length > 0" class="title">
leiqingsong's avatar
leiqingsong committed
4
      <span>大转盘抽奖</span>
xd's avatar
xd committed
5 6
    </div>
    <div class="active">
leiqingsong's avatar
leiqingsong committed
7
      <template v-for="(item, index) in wheelList">
leiqingsong's avatar
leiqingsong committed
8
        <van-swipe-cell v-if="index < wheelActive_limit" :key="index">
leiqingsong's avatar
leiqingsong committed
9 10 11 12 13 14 15 16
          <div class="list" @click="toDetail(item.id, item.activityType)">
            <div class="left">
              <img :src="item.logo" alt="logo" style="width:100%;height:100%;" />
            </div>
            <div class="right">
              <h3>{{ item.activityName }}</h3>
              <p>{{ item.des }}</p>
            </div>
17
          </div>
leiqingsong's avatar
leiqingsong committed
18 19 20 21
          <template #right v-if="flag == 1">
            <van-button square type="danger" text="删除" @click="deleteWheelAct(item.id, index)" />
          </template>
        </van-swipe-cell>
22 23 24
      </template>
      <span
        class="more"
leiqingsong's avatar
leiqingsong committed
25 26
        v-if="wheelList.length && !wheelList_finished"
        @click="handleActiveMore('wheel')"
27 28 29 30
      >
        查看更多
        <span class="icon">></span>
      </span>
xd's avatar
xd committed
31
    </div>
leiqingsong's avatar
leiqingsong committed
32
    <div v-if="couponList.length > 0" class="fg">送券活动</div>
xd's avatar
xd committed
33
    <div class="active">
leiqingsong's avatar
leiqingsong committed
34
      <template v-for="(item, index) in couponList">
leiqingsong's avatar
leiqingsong committed
35
        <van-swipe-cell v-if="index < couponActive_limit" :key="index">
leiqingsong's avatar
leiqingsong committed
36 37 38 39 40 41 42 43
          <div class="list" @click="toDetail(item.id, item.activityType)">
            <div class="left">
              <img :src="item.logo" alt="logo" style="width:100%;height:100%;" />
            </div>
            <div class="right">
              <h3>{{ item.activityName }}</h3>
              <p>{{ item.des }}</p>
            </div>
leiqingsong's avatar
leiqingsong committed
44
          </div>
leiqingsong's avatar
leiqingsong committed
45 46 47 48
          <template #right v-if="flag == 1">
            <van-button square type="danger" text="删除" @click="deleteCouponAct(item.id, index)" />
          </template>
        </van-swipe-cell>
leiqingsong's avatar
leiqingsong committed
49 50 51 52 53 54 55 56 57
      </template>
      <span
        class="more"
        v-if="couponList.length && !couponList_finished"
        @click="handleActiveMore('coupon')"
      >
        查看更多
        <span class="icon">></span>
      </span>
xd's avatar
xd committed
58 59 60 61 62
    </div>
  </div>
</template>

<script>
63
import * as API_Active from "@/api/active";
64 65 66
export default {
  data() {
    return {
leiqingsong's avatar
leiqingsong committed
67
      flag: 2,
68
      wheelActive_limit: 3,
leiqingsong's avatar
leiqingsong committed
69 70 71 72 73 74 75
      wheelList_finished: false,
      couponActive_limit: 3,
      couponList_finished: false,
      wheelList: [],
      couponList: [],
      wheel_params: {
        pageNo: 1,
76 77
        pageSize: 3,
        oyStallCode: sessionStorage.getItem("oyStallCode")
leiqingsong's avatar
leiqingsong committed
78 79
      },
      coupon_params: {
leiqingsong's avatar
leiqingsong committed
80
        pageNo: 1,
81 82
        pageSize: 3,
        oyStallCode: sessionStorage.getItem("oyStallCode")
leiqingsong's avatar
leiqingsong committed
83
      }
84
    };
85
  },
leiqingsong's avatar
leiqingsong committed
86
  mounted() {
leiqingsong's avatar
leiqingsong committed
87 88
    this.getWheelActive();
    this.getCouponActive();
leiqingsong's avatar
leiqingsong committed
89
    this.flag = sessionStorage.getItem("role");
leiqingsong's avatar
leiqingsong committed
90
  },
91
  methods: {
leiqingsong's avatar
leiqingsong committed
92 93 94
    deleteCouponAct(id, index) {
      API_Active.deleteActive(id).then(res => {
        if (res.result === "success") {
leiqingsong's avatar
leiqingsong committed
95
          this.couponList.splice(index, 1);
leiqingsong's avatar
leiqingsong committed
96 97 98 99 100 101 102 103 104 105 106 107 108
          this.$toast("删除成功!");
        }
      });
    },
    deleteWheelAct(id, index) {
      API_Active.deleteActive(id).then(res => {
        if (res.result === "success") {
          this.wheelList.splice(index, 1);
          this.$toast("删除成功!");
        }
      });
    },
    async getCouponActive() {
leiqingsong's avatar
leiqingsong committed
109 110 111
      let res = await this.getActiveList("coupon");
      this.couponList.push.apply(this.couponList, res.data.list);
      if (res.data.list === []) {
leiqingsong's avatar
leiqingsong committed
112
        this.couponList_finished = true;
leiqingsong's avatar
leiqingsong committed
113 114 115 116 117 118
      }
    },
    async getWheelActive() {
      let res = await this.getActiveList("wheel");
      this.wheelList.push.apply(this.wheelList, res.data.list);
      if (res.data.list === []) {
leiqingsong's avatar
leiqingsong committed
119
        this.wheelList_finished = true;
leiqingsong's avatar
leiqingsong committed
120 121 122 123 124 125 126 127 128 129
      }
    },
    handleActiveMore(type) {
      if (type === "wheel") {
        this.wheelActive_limit += 3;
        this.wheel_params.pageNo += 1;
        this.getWheelActive();
      } else if (type === "coupon") {
        this.couponActive_limit += 3;
        this.coupon_params.pageNo += 1;
leiqingsong's avatar
leiqingsong committed
130
        this.getCouponActive();
131 132
      }
    },
leiqingsong's avatar
leiqingsong committed
133
    // 获取 活动列表
leiqingsong's avatar
leiqingsong committed
134 135
    async getActiveList(type) {
      let page_params = {};
leiqingsong's avatar
leiqingsong committed
136
      if (type === "wheel") {
leiqingsong's avatar
leiqingsong committed
137
        page_params = this.wheel_params;
leiqingsong's avatar
leiqingsong committed
138
      } else if (type === "coupon") {
leiqingsong's avatar
leiqingsong committed
139 140 141 142 143 144 145 146
        page_params = this.coupon_params;
      }
      let params = {
        activityType: type,
        ...page_params
      };
      let res = await API_Active.getActiveList(params);
      return res;
147 148
    },
    // 跳转到 活动详情
149 150
    toDetail(active_id, type) {
      this.$router.push({
151
        path: "/activeDetail",
152 153
        query: {
          id: active_id,
leiqingsong's avatar
leiqingsong committed
154
          active_type: type
155
        }
156
      });
157 158 159
    }
  }
};
xd's avatar
xd committed
160 161 162
</script>

<style scoped>
163 164 165 166 167
.more {
  float: right;
  margin-bottom: 5px;
  font-size: 12px;
}
xd's avatar
xd committed
168
.container {
xd's avatar
xd committed
169
  height: auto;
xd's avatar
xd committed
170
  background-color: rgba(248, 248, 248, 1);
xd's avatar
xd committed
171 172 173
  min-height: 100%;
  display: flex;
  flex-direction: column;
174
  justify-content: flex-start;
xd's avatar
xd committed
175
}
xd's avatar
xd committed
176 177 178
.title {
  height: 44px;
  background: rgba(248, 248, 248, 1);
xd's avatar
xd committed
179 180 181
  display: flex;
  justify-content: space-between;
  align-items: center;
xd's avatar
xd committed
182 183 184 185
  padding: 0 16px;
  font-size: 12px;
  color: rgba(45, 71, 106, 1);
}
xd's avatar
xd committed
186 187 188 189 190
.fg {
  padding: 0 16px;
  font-size: 12px;
  color: rgba(45, 71, 106, 1);
  height: 44px;
191
  line-height: 44px;
xd's avatar
xd committed
192
}
xd's avatar
xd committed
193 194 195 196
.icon {
  font-weight: 800;
}
.active {
xd's avatar
xd committed
197 198
  background-color: #fff;
  padding: 12px 12px 0 12px;
199
  box-shadow: 0px 2px 4px 0px rgba(221, 221, 221, 1);
xd's avatar
xd committed
200 201
}
.list {
xd's avatar
xd committed
202
  height: 94px;
xd's avatar
xd committed
203 204 205
  width: 100%;
  background-color: #fff;
  display: flex;
xd's avatar
xd committed
206
  justify-content: space-between;
207
  border-bottom: 1px solid rgba(238, 238, 238, 1);
xd's avatar
xd committed
208 209 210 211 212
  margin-bottom: 14px;
}
.list3 {
  border-bottom: none;
  margin-bottom: 0;
xd's avatar
xd committed
213
}
214 215
.left,
.right {
xd's avatar
xd committed
216
  height: 80px;
xd's avatar
xd committed
217 218
}
.left {
219 220
  width: 80px;
  background: rgba(248, 248, 248, 1);
xd's avatar
xd committed
221 222
}
.right {
xd's avatar
xd committed
223
  width: 76%;
xd's avatar
xd committed
224
  padding-left: 10px;
xd's avatar
xd committed
225 226 227 228
  background-color: #fff;
}
h3 {
  font-size: 14px;
229 230
  font-weight: bold;
  color: rgba(45, 71, 106, 1);
xd's avatar
xd committed
231 232 233
}
p {
  margin-top: 10px;
234 235
  font-size: 12px;
  color: rgba(45, 71, 106, 0.8);
xd's avatar
xd committed
236 237
}
</style>