diff --git a/pages/coupon/detail.vue b/pages/coupon/detail.vue
index 71ccbe05..1bb102d0 100644
--- a/pages/coupon/detail.vue
+++ b/pages/coupon/detail.vue
@@ -63,29 +63,30 @@
- {{ state.list.use_scope_text }}
+ 全场通用
- {{ state.list.use_scope_text }}
+
+ {{ state.coupon.productScope === 2 ? '指定商品可用' : '指定分类可用' }}
+
+ v-if="state.coupon.productScope === 3"
+ />
-
-
+
+
+
-
-
+
+
+
-
+ />
@@ -146,64 +143,69 @@
import _ from 'lodash';
import CouponApi from '@/sheep/api/promotion/coupon';
import { fen2yuan } from '@/sheep/hooks/useGoods';
+ import SpuApi from '@/sheep/api/product/spu';
+ import CategoryApi from '@/sheep/api/product/category';
+ import { resetPagination } from '@/sheep/util';
- const pagination = {
- data: [],
- current_page: 1,
- total: 1,
- last_page: 1,
- };
const state = reactive({
id: 0, // 优惠劵模版编号 templateId
couponId: 0, // 用户优惠劵编号 couponId
coupon: {}, // 优惠劵信息
- list: {},
pagination: {
- data: [],
- current_page: 1,
- total: 1,
- last_page: 1,
+ list: [],
+ total: 0,
+ pageNo: 1,
+ pageSize: 1,
},
- tabMaps: [],
+ categoryId: 0, // 选中的商品分类编号
+ tabMaps: [], // 指定分类时,每个分类构成一个 tab
+ currentTab: 0, // 选中的 tabMaps 下标
loadStatus: '',
- categoryId: 0,
- });
-
- // 接收参数
- const props = defineProps({
- goodsFieldsStyle: {
- type: Object,
- default() {},
- }
});
function onTabsChange(e) {
- state.pagination = pagination;
+ resetPagination(state.pagination);
state.currentTab = e.index;
state.categoryId = e.value;
- getGoodsList(state.categoryId);
+ getGoodsListByCategory();
}
- async function getGoodsList(categoryId, page = 1, list_rows = 5) {
+ async function getGoodsListByCategory() {
state.loadStatus = 'loading';
- const res = await sheep.$api.goods.list({
- category_id: categoryId,
- list_rows,
- page,
- is_category_deep: false,
+ const { code, data } = await SpuApi.getSpuPage({
+ categoryId: state.categoryId,
+ pageNo: state.pagination.pageNo,
+ pageSize: state.pagination.pageSize
});
- if (res.error === 0) {
- let couponlist = _.concat(state.pagination.data, res.data.data);
- state.pagination = {
- ...res.data,
- data: couponlist,
- };
- if (state.pagination.current_page < state.pagination.last_page) {
- state.loadStatus = 'more';
- } else {
- state.loadStatus = 'noMore';
- }
+ if (code !== 0) {
+ return;
+ }
+ state.pagination.list = _.concat(state.pagination.list, data.list);
+ state.pagination.total = data.total;
+ state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
+ }
+
+ // 获得商品列表,指定商品范围
+ async function getGoodsListById() {
+ const { data, code } = await SpuApi.getSpuListByIds(state.coupon.productScopeValues.join(','));
+ if (code !== 0) {
+ return;
+ }
+ state.pagination.list = data;
+ }
+
+ // 获得分类列表
+ async function getCategoryList() {
+ const { data, code } = await CategoryApi.getCategoryListByIds(state.coupon.productScopeValues.join(','));
+ if (code !== 0) {
+ return;
+ }
+ state.tabMaps = data.map((category) => ({ name: category.name, value: category.id }));
+ // 加载第一个分类的商品列表
+ if (state.tabMaps.length > 0) {
+ state.categoryId = state.tabMaps[0].value;
+ await getGoodsListByCategory();
}
}
@@ -226,24 +228,21 @@
return;
}
state.coupon = data;
- if (true) {
- return;
- }
- state.list = data;
- data.items_value.forEach((i) => {
- state.tabMaps.push({ name: i.name, value: i.id });
- });
- state.pagination = pagination;
- if (state.list.use_scope == 'category') {
- getGoodsList(state.tabMaps[0].value);
+ // 不同指定范围,加载不同数据
+ if (state.coupon.productScope === 2) {
+ await getGoodsListById();
+ } else if (state.coupon.productScope === 3) {
+ await getCategoryList();
}
}
// 加载更多
function loadMore() {
- if (state.loadStatus !== 'noMore') {
- getGoodsList(state.categoryId, state.pagination.current_page + 1);
+ if (state.loadStatus === 'noMore') {
+ return;
}
+ state.pagination.pageNo++;
+ getGoodsListByCategory();
}
onLoad((options) => {
diff --git a/pages/coupon/list.vue b/pages/coupon/list.vue
index 566195bf..acd658e2 100644
--- a/pages/coupon/list.vue
+++ b/pages/coupon/list.vue
@@ -15,15 +15,11 @@
text="暂无优惠券"
/>
-
+
diff --git a/sheep/api/product/category.js b/sheep/api/product/category.js
index 6549acf5..4578e8aa 100644
--- a/sheep/api/product/category.js
+++ b/sheep/api/product/category.js
@@ -1,12 +1,21 @@
import request from '@/sheep/request';
const CategoryApi = {
- // 查询分类列表
- getCategoryList: () => {
- return request({
- url: '/app-api/product/category/list',
- method: 'GET'
- });
- }
+ // 查询分类列表
+ getCategoryList: () => {
+ return request({
+ url: '/app-api/product/category/list',
+ method: 'GET',
+ });
+ },
+ // 查询分类列表,指定编号
+ getCategoryListByIds: (ids) => {
+ return request({
+ url: '/app-api/product/category/list-by-ids',
+ method: 'GET',
+ params: { ids },
+ });
+ },
};
+
export default CategoryApi;