feat: 推荐商品

feature/task1.0.0__0514__ch
向文可 3 years ago
parent d04facca0b
commit 5067f42478

@ -0,0 +1,22 @@
import request from '@/utils/request.js';
export const search = (params) => {
return request({
url: '/mall/marketing/activityProduct',
method: 'get',
params,
});
};
export const create = (data) => {
return request({
url: '/mall/marketing/activityProduct',
method: 'post',
data,
});
};
export const remove = (idList) => {
return request({
url: '/mall/marketing/activityProduct',
method: 'delete',
params: { idList },
});
};

@ -0,0 +1,29 @@
import request from '@/utils/request.js';
export const search = (params) => {
return request({
url: '/mall/marketing/productRecommended',
method: 'get',
params,
});
};
export const create = (data) => {
return request({
url: '/mall/marketing/productRecommended',
method: 'post',
data,
});
};
export const enable = (data) => {
return request({
url: '/mall/marketing/productRecommended',
method: 'put',
data,
});
};
export const remove = (idList) => {
return request({
url: '/mall/marketing/productRecommended',
method: 'delete',
params: { idList },
});
};

@ -41,9 +41,9 @@ export default [
], ],
}, },
{ {
path: 'recommand', path: 'recommend',
name: 'RecommandActivity', name: 'RecommandActivity',
component: () => import('@/views/operation/recommand/index.vue'), component: () => import('@/views/operation/recommend/index.vue'),
meta: { meta: {
title: '商品推荐', title: '商品推荐',
icon: 'Checked', icon: 'Checked',

@ -1,11 +1,11 @@
import * as api from '@/api/sales/category.js'; import * as api from '@/api/operation/limit/limitProduct.js';
import * as limitTimeAPI from '@/api/operation/limit/limitTime.js';
import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus';
const state = () => ({ const state = () => ({
code: 'LimitActivity', code: 'LimitProduct',
condition: {}, condition: {},
list: [], list: [],
total: 0, total: 0,
summary: [],
opts: { opts: {
init: false, init: false,
timeRange: [], timeRange: [],
@ -18,37 +18,28 @@ const mutations = {
setCondition: (state, data) => (state.condition = data), setCondition: (state, data) => (state.condition = data),
setList: (state, data) => (state.list = data), setList: (state, data) => (state.list = data),
setTotal: (state, data) => (state.total = data), setTotal: (state, data) => (state.total = data),
setSummary: (state, data) => (state.summary = data),
setOpts: (state, data) => (state.opts = data), setOpts: (state, data) => (state.opts = data),
}; };
const actions = { const actions = {
search: async ({ state, commit }) => { search: async ({ state, commit, rootGetters }) => {
let res = await api.search(state.condition); let data = { ...state.condition };
commit('setList', res); let res = await api.search({ ...rootGetters['local/page'](state.code), ...data });
commit('setList', res?.records || []);
commit('setTotal', res?.total || 0);
if (!res) { if (!res) {
ElMessage.error('查询商品分类列表失败'); ElMessage.error('查询秒杀商品列表失败');
} }
return res; return res;
}, },
load: async ({ commit, state }) => { load: async ({ commit, state }, activityId) => {
commit('setOpts', { commit('setOpts', {
...state.opts, ...state.opts,
init: true, init: true,
timeRange: await limitTimeAPI.search({ activityId }),
}); });
}, },
detail: async ({ state, dispatch }, id) => {
if (!state.list.length) {
await dispatch('search');
}
let res = state.list.find((item) => item.id === id);
if (!res) {
ElMessage.error('加载详情失败');
}
return res;
},
save: async ({ dispatch }, data) => { save: async ({ dispatch }, data) => {
let save = data.id ? api.update : api.create; let res = await api.create(data);
let res = await save(data);
if (res) { if (res) {
ElMessage.success('保存成功'); ElMessage.success('保存成功');
dispatch('search'); dispatch('search');
@ -57,22 +48,13 @@ const actions = {
} }
return res; return res;
}, },
sort: async (context, data) => {
let res = await api.sort(data);
if (res) {
ElMessage.success(`移动前序号:${data.oldSort + 1};移动后序号:${data.currentSort + 1}`);
} else {
ElMessage.error('保存排序失败');
}
return res;
},
remove: async ({ dispatch }, ids) => { remove: async ({ dispatch }, ids) => {
if (!ids.length) { if (!ids.length) {
ElMessage.warning('请选择要删除的数据'); ElMessage.warning('请选择要删除的数据');
} else { } else {
try { try {
await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作');
let res = await api.remove({ id: ids.join(',') }); let res = await api.remove(ids.join(','));
if (res) { if (res) {
ElMessage.success('删除成功'); ElMessage.success('删除成功');
dispatch('search'); dispatch('search');

@ -1,7 +1,7 @@
import * as api from '@/api/sales/category.js'; import * as api from '@/api/operation/recommend/recommendProduct.js';
import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus';
const state = () => ({ const state = () => ({
code: 'LimitActivity', code: 'RecommendProductManagement',
condition: {}, condition: {},
list: [], list: [],
total: 0, total: 0,
@ -24,11 +24,13 @@ const mutations = {
setOpts: (state, data) => (state.opts = data), setOpts: (state, data) => (state.opts = data),
}; };
const actions = { const actions = {
search: async ({ state, commit }) => { search: async ({ state, commit, rootGetters }) => {
let res = await api.search(state.condition); let data = { ...state.condition };
commit('setList', res); let res = await api.search({ ...rootGetters['local/page'](state.code), ...data });
commit('setList', res?.records || []);
commit('setTotal', res?.total || 0);
if (!res) { if (!res) {
ElMessage.error('查询商品分类列表失败'); ElMessage.error('查询推荐商品列表失败');
} }
return res; return res;
}, },
@ -38,13 +40,13 @@ const actions = {
init: true, init: true,
}); });
}, },
detail: async ({ state, dispatch }, id) => { enable: async ({ dispatch }, data) => {
if (!state.list.length) { let res = await api.enable({ id: data.id, isEnable: data.isEnable });
await dispatch('search'); if (res) {
} ElMessage.success('保存成功');
let res = state.list.find((item) => item.id === id); dispatch('search');
if (!res) { } else {
ElMessage.error('加载详情失败'); ElMessage.error('保存失败');
} }
return res; return res;
}, },
@ -59,22 +61,13 @@ const actions = {
} }
return res; return res;
}, },
sort: async (context, data) => {
let res = await api.sort(data);
if (res) {
ElMessage.success(`移动前序号:${data.oldSort + 1};移动后序号:${data.currentSort + 1}`);
} else {
ElMessage.error('保存排序失败');
}
return res;
},
remove: async ({ dispatch }, ids) => { remove: async ({ dispatch }, ids) => {
if (!ids.length) { if (!ids.length) {
ElMessage.warning('请选择要删除的数据'); ElMessage.warning('请选择要删除的数据');
} else { } else {
try { try {
await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作');
let res = await api.remove({ id: ids.join(',') }); let res = await api.remove(ids.join(','));
if (res) { if (res) {
ElMessage.success('删除成功'); ElMessage.success('删除成功');
dispatch('search'); dispatch('search');

@ -3,15 +3,10 @@
<ul class="time-range"> <ul class="time-range">
<li v-for="(item, index) in opts.timeRange" :key="index"> <li v-for="(item, index) in opts.timeRange" :key="index">
<el-button <el-button
:type="state.condition.orderStatus.includes(item.value) ? 'primary' : 'default'" :type="state.condition.activityTimeId === item.id ? 'primary' : 'default'"
@click="handleTimeRange(item.value)" @click="state.condition.activityTimeId = item.id"
> >
<span> {{ item.timeName }}
{{ item.label }}
</span>
<span>(</span>
<span class="num">{{ summary[index] || 0 }}</span>
<span>)</span>
</el-button> </el-button>
</li> </li>
</ul> </ul>
@ -29,38 +24,53 @@
> >
<template #search> <template #search>
<el-form inline> <el-form inline>
<el-form-item label="商品名称" prop="name"> <el-form-item label="商品名称" prop="productName">
<el-input v-model="state.condition.name" /> <el-input v-model="state.condition.productName" />
</el-form-item> </el-form-item>
<el-form-item label="商品分类" prop="category"> <el-form-item label="商品分类" prop="categoryId">
<el-select v-model="state.condition.category" :opts="opts.category" /> <el-select v-model="state.condition.categoryId" :opts="opts.category" />
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
</TableList> </TableList>
<ProductPicker ref="refsPicker" />
</div> </div>
</template> </template>
<script setup lang="jsx"> <script setup lang="jsx">
import ElButton from '@/components/extra/ElButton.vue'; import ElButton from '@/components/extra/ElButton.vue';
import ProductPicker from './picker.vue';
const store = useStore(); const store = useStore();
const route = useRoute();
const loading = ref(false); const loading = ref(false);
const code = computed(() => store.state.limitProduct.code); const code = computed(() => store.state.limitProduct.code);
const list = computed(() => store.state.limitProduct.list); const list = computed(() => store.state.limitProduct.list);
const total = computed(() => store.state.limitProduct.total); const total = computed(() => store.state.limitProduct.total);
const summary = computed(() => store.state.limitProduct.summary);
const opts = computed(() => store.state.limitProduct.opts); const opts = computed(() => store.state.limitProduct.opts);
if (!unref(opts).init) { if (!unref(opts).init) {
store.dispatch('limitProduct/load'); store.dispatch('limitProduct/load', route.params.id);
} }
/* 查询订单 */ /* 查询订单 */
const state = reactive({ const state = reactive({
condition: { condition: {
name: null, productName: null,
category: null, categoryId: null,
activityTimeId: null,
}, },
}); });
const handleReset = () => {
state.condition = {
productName: null,
categoryId: null,
activityTimeId: null,
};
};
const handleSearch = async () => {
loading.value = true;
await store.dispatch('limitProduct/search');
loading.value = false;
};
watch( watch(
() => state.condition, () => state.condition,
(value) => { (value) => {
@ -69,50 +79,29 @@
{ immediate: true, deep: true } { immediate: true, deep: true }
); );
watch( watch(
() => state.condition.orderStatus, () => state.condition.activityTimeId,
() => { () => {
handleSearch(); handleSearch();
}, },
{ deep: true } { deep: true }
); );
const handleReset = () => { watch(
state.condition = { () => unref(opts).timeRange,
name: null, () => {
category: null, state.condition.activityTimeId = unref(opts).timeRange[0]?.id;
}; },
}; { deep: true }
const handleTimeRange = (status) => { );
let index = state.condition.orderStatus.indexOf(status);
if (index === -1) {
if (status === 0) {
state.condition.orderStatus = [0];
} else {
state.condition.orderStatus.push(status);
state.condition.orderStatus = state.condition.orderStatus.filter((item) => item > 0);
}
} else {
if (status !== 0) {
state.condition.orderStatus.splice(index, 1);
if (state.condition.orderStatus.length) {
state.condition.orderStatus = state.condition.orderStatus.filter((item) => item > 0);
} else {
state.condition.orderStatus = [0];
}
}
}
};
const handleSearch = async () => {
loading.value = true;
await store.dispatch('limitProduct/search');
loading.value = false;
};
/* 导出订单 */ const refsPicker = ref(null);
const handleCreate = async () => { const handleCreate = async () => {
console.info('create'); unref(refsPicker).show();
}; };
const handleRemove = (row, index) => { const handleRemove = async (rows) => {
console.info(row, index); await store.dispatch(
'limitProduct/remove',
rows.map((item) => item.id)
);
}; };
const handleSku = (row) => { const handleSku = (row) => {
console.info(row); console.info(row);
@ -123,30 +112,25 @@
columns: [ columns: [
{ {
label: '编号', label: '编号',
prop: 'orderNo', prop: 'productId',
minWidth: 100, minWidth: 100,
}, },
{ {
label: '商品图片', label: '商品图片',
width: 100, width: 100,
slots: { slots: {
default: ({ row }) => <ElImage src={row.photo} alt={row.name} height="100px" />, default: ({ row }) => <ElImage src={row.productMainPicture} alt={row.productName} height="100px" />,
}, },
}, },
{ {
label: '商品名称', label: '商品名称',
prop: 'payAmount', prop: 'productName',
minWidth: 240, minWidth: 240,
}, },
{ {
label: '商品价格', label: '商品价格',
prop: 'payTypeDesc', prop: 'productStartingPrice',
width: 120,
},
{
label: '活动已售数量',
width: 120, width: 120,
prop: 'orderSourceDesc',
}, },
{ {
label: 'SKU商品配置', label: 'SKU商品配置',
@ -162,10 +146,10 @@
{ {
label: '操作', label: '操作',
fixed: 'right', fixed: 'right',
width: 160, width: 100,
slots: { slots: {
default: ({ row, $index }) => ( default: ({ row }) => (
<ElButton type="text" onClick={() => handleRemove(row, $index)}> <ElButton type="text" onClick={() => handleRemove([row])}>
移除 移除
</ElButton> </ElButton>
), ),

@ -1,195 +0,0 @@
<template>
<div class="list-container">
<ul class="time-range">
<li v-for="(item, index) in opts.timeRange" :key="index">
<el-button
:type="state.condition.orderStatus.includes(item.value) ? 'primary' : 'default'"
@click="handleTimeRange(item.value)"
>
<span>
{{ item.label }}
</span>
<span>(</span>
<span class="num">{{ summary[index] || 0 }}</span>
<span>)</span>
</el-button>
</li>
</ul>
<TableList
v-loading="loading"
:code="code"
:config="config"
:data="list"
:operation="['search', 'create']"
:reset="handleReset"
title="活动商品"
:total="total"
@create="handleCreate"
@search="handleSearch"
>
<template #search>
<el-form inline>
<el-form-item label="商品名称" prop="name">
<el-input v-model="state.condition.name" />
</el-form-item>
<el-form-item label="商品分类" prop="category">
<el-select v-model="state.condition.category" :opts="opts.category" />
</el-form-item>
</el-form>
</template>
</TableList>
</div>
</template>
<script setup lang="jsx">
import ElButton from '@/components/extra/ElButton.vue';
const store = useStore();
const loading = ref(false);
const code = computed(() => store.state.limitProduct.code);
const list = computed(() => store.state.limitProduct.list);
const total = computed(() => store.state.limitProduct.total);
const summary = computed(() => store.state.limitProduct.summary);
const opts = computed(() => store.state.limitProduct.opts);
if (!unref(opts).init) {
store.dispatch('limitProduct/load');
}
/* 查询订单 */
const state = reactive({
condition: {
name: null,
category: null,
},
});
watch(
() => state.condition,
(value) => {
store.commit('limitProduct/setCondition', _.cloneDeep(value));
},
{ immediate: true, deep: true }
);
watch(
() => state.condition.orderStatus,
() => {
handleSearch();
},
{ deep: true }
);
const handleReset = () => {
state.condition = {
name: null,
category: null,
};
};
const handleTimeRange = (status) => {
let index = state.condition.orderStatus.indexOf(status);
if (index === -1) {
if (status === 0) {
state.condition.orderStatus = [0];
} else {
state.condition.orderStatus.push(status);
state.condition.orderStatus = state.condition.orderStatus.filter((item) => item > 0);
}
} else {
if (status !== 0) {
state.condition.orderStatus.splice(index, 1);
if (state.condition.orderStatus.length) {
state.condition.orderStatus = state.condition.orderStatus.filter((item) => item > 0);
} else {
state.condition.orderStatus = [0];
}
}
}
};
const handleSearch = async () => {
loading.value = true;
await store.dispatch('limitProduct/search');
loading.value = false;
};
/* 导出订单 */
const handleCreate = async () => {
console.info('create');
};
const handleRemove = (row, index) => {
console.info(row, index);
};
const handleSku = (row) => {
console.info(row);
};
/* 列表配置 */
const config = reactive({
columns: [
{
label: '编号',
prop: 'orderNo',
minWidth: 100,
},
{
label: '商品图片',
width: 100,
slots: {
default: ({ row }) => <ElImage src={row.photo} alt={row.name} height="100px" />,
},
},
{
label: '商品名称',
prop: 'payAmount',
minWidth: 240,
},
{
label: '商品价格',
prop: 'payTypeDesc',
width: 120,
},
{
label: '活动已售数量',
width: 120,
prop: 'orderSourceDesc',
},
{
label: 'SKU商品配置',
width: 120,
slots: {
default: ({ row }) => (
<ElButton type="text" onClick={() => handleSku(row)}>
<ElIcon name="Edit" />
</ElButton>
),
},
},
{
label: '操作',
fixed: 'right',
width: 160,
slots: {
default: ({ row, $index }) => (
<ElButton type="text" onClick={() => handleRemove(row, $index)}>
移除
</ElButton>
),
},
},
],
});
</script>
<style lang="less" scoped>
.list-container {
display: flex;
flex-direction: column;
.common-list {
flex-shrink: 1;
}
.time-range {
display: flex;
margin-bottom: @layout-space;
li {
+ li {
margin-left: @layout-space;
}
}
}
}
</style>

@ -1,150 +0,0 @@
<template>
<div class="list-container">
<TableList
v-loading="loading"
:code="code"
:config="config"
:data="list"
:operation="['create']"
:reset="handleReset"
title="时间段"
:total="total"
@create="handleCreate"
@search="handleSearch"
>
<template #operation>
<el-button type="success" @click="handleProduct"></el-button>
</template>
</TableList>
</div>
</template>
<script setup lang="jsx">
import ElButton from '@/components/extra/ElButton.vue';
import ElSwitch from '@/components/extra/ElSwitch.vue';
const route = useRoute();
const router = useRouter();
const store = useStore();
const loading = ref(false);
const code = computed(() => store.state.limitTime.code);
const list = computed(() => _.cloneDeep(store.state.limitTime.list));
const total = computed(() => store.state.limitTime.total);
const opts = computed(() => store.state.limitTime.opts);
if (!unref(opts).init) {
store.dispatch('limitTime/load');
}
/* 列表查询 */
const state = reactive({
condition: {
name: null,
status: null,
},
});
watch(
() => state.condition,
(value) => {
store.commit('limitTime/setCondition', _.cloneDeep(value));
},
{ immediate: true, deep: true }
);
const handleReset = () => {
state.condition = {
name: null,
status: null,
};
};
const handleSearch = async () => {
loading.value = true;
await store.dispatch('limitTime/search');
loading.value = false;
};
/* 操作 */
//
const handleCreate = () => {
store.commit('limitTime/setList', [
...unref(list),
{ edit: true, name: null, startTime: null, endTime: null, enabled: true },
]);
};
//
const handleProduct = () => {
router.push({ name: 'UpdateLimitProduct', params: { id: route.params.id } });
};
//
const handleEnable = (row, value) => {
row.enabled = value;
};
//
const handleUpdate = (row) => {
row.edit = !row.edit;
};
//
const handleRemove = async (rows) => {
await store.dispatch(
'limitTime/remove',
rows.map((item) => item.id)
);
};
/* 列表配置 */
const config = reactive({
page: false,
columns: [
{
label: '秒杀时段名称',
minWidth: 160,
slots: {
default: ({ row }) => (row.edit ? <ElInput v-model={row.name} /> : row.name),
},
},
{
label: '开始时间',
width: 160,
slots: {
default: ({ row }) => (row.edit ? <ElTimePicker v-model={row.startTime} /> : row.startTime),
},
},
{
label: '活动状态',
width: 160,
slots: {
default: ({ row }) => (row.edit ? <ElTimePicker v-model={row.endTime} /> : row.endTime),
},
},
{
label: '启用',
width: 100,
slots: {
default: ({ row }) => (
<ElSwitch value={row.enabled} onChange={(enabled) => handleEnable(row, enabled)} />
),
},
},
{
label: '操作',
fixed: 'right',
width: 120,
slots: {
default: ({ row }) => (
<div>
<ElButton type="text" onClick={() => handleUpdate(row)}>
{row.edit ? '保存' : '编辑'}
</ElButton>
<ElButton type="text" onClick={() => handleRemove([row])}>
删除
</ElButton>
</div>
),
},
},
],
});
</script>
<style lang="less" scoped>
:deep(.el-date-editor--time) {
width: 100%;
}
</style>

@ -33,12 +33,12 @@
import ProductPicker from '@/views/sales/product/picker.vue'; import ProductPicker from '@/views/sales/product/picker.vue';
const store = useStore(); const store = useStore();
const loading = ref(false); const loading = ref(false);
const code = computed(() => store.state.recommandActivity.code); const code = computed(() => store.state.recommendProduct.code);
const list = computed(() => store.state.recommandActivity.list); const list = computed(() => _.cloneDeep(store.state.recommendProduct.list));
const total = computed(() => store.state.recommandActivity.total); const total = computed(() => store.state.recommendProduct.total);
const opts = computed(() => store.state.recommandActivity.opts); const opts = computed(() => store.state.recommendProduct.opts);
if (!unref(opts).init) { if (!unref(opts).init) {
store.dispatch('recommandActivity/load'); store.dispatch('recommendProduct/load');
} }
/* 列表查询 */ /* 列表查询 */
@ -51,7 +51,7 @@
watch( watch(
() => state.condition, () => state.condition,
(value) => { (value) => {
store.commit('recommandActivity/setCondition', _.cloneDeep(value)); store.commit('recommendProduct/setCondition', _.cloneDeep(value));
}, },
{ immediate: true, deep: true } { immediate: true, deep: true }
); );
@ -63,9 +63,10 @@
}; };
const handleSearch = async () => { const handleSearch = async () => {
loading.value = true; loading.value = true;
await store.dispatch('recommandActivity/search'); await store.dispatch('recommendProduct/search');
loading.value = false; loading.value = false;
}; };
onActivated(handleSearch);
const refsPicker = ref(null); const refsPicker = ref(null);
// / // /
@ -78,14 +79,16 @@
}; };
/* 操作 */ /* 操作 */
// //
const handleEnable = (row, value) => { const handleEnable = async (row) => {
row.enabled = value; loading.value = true;
await store.dispatch('recommendProduct/enable', row);
loading.value = false;
}; };
// //
const handleRemove = async (rows) => { const handleRemove = (rows) => {
await store.dispatch( store.dispatch(
'recommandActivity/remove', 'recommendProduct/remove',
rows.map((item) => item.id) rows.map((item) => item.id)
); );
}; };
@ -115,9 +118,7 @@
label: '是否推荐', label: '是否推荐',
width: 120, width: 120,
slots: { slots: {
default: ({ row }) => ( default: ({ row }) => <ElSwitch v-model={row.isEnable} onChange={() => handleEnable(row)} />,
<ElSwitch value={row.isEnable} onChange={(visible) => handleEnable(row, visible)} />
),
}, },
}, },
{ {

@ -209,8 +209,8 @@
<div> <div>
<ElSwitch value={row.hot} onInput={() => handleTag(row, 'hot')} active-text="" /> <ElSwitch value={row.hot} onInput={() => handleTag(row, 'hot')} active-text="" />
<ElSwitch <ElSwitch
value={row.recommand} value={row.recommend}
onInput={() => handleTag(row, 'recommand')} onInput={() => handleTag(row, 'recommend')}
active-text="推荐" active-text="推荐"
/> />
<ElSwitch <ElSwitch

Loading…
Cancel
Save