优化分组商品编辑

This commit is contained in:
gyq
2025-05-07 17:48:13 +08:00
parent b69b5dbf31
commit d6e1c83f88
10 changed files with 2599 additions and 2527 deletions

View File

@@ -1,12 +1,12 @@
<template>
<view class=" goods">
<view class="goods">
<view class="u-flex u-font-24 u-col-center u-row-between u-p-b-16 border-bottom">
<view class="u-flex u-col-center">
<view class="u-font-24">
<text>排序</text>
<text class="u-m-l-12">{{data.sort}}</text>
<text class="u-m-l-12">{{ data.sort }}</text>
</view>
<view class="u-flex u-m-l-16 " @click="editSort">
<view class="u-flex u-m-l-16" @click="editSort">
<image src="/pageGoodsGroup/static/image/icon-edit.svg" class="icon-edit" mode=""></image>
</view>
</view>
@@ -15,20 +15,23 @@
<up-switch :activeValue="1" :inactiveValue="0" v-model="data.status" @change="isShowChange" :size="18"></up-switch>
</view>
</view>
<view class="u-m-t-24 u-p-l-54 ">
<view class="u-m-t-24">
<view class="u-flex-1 u-flex u-col-top">
<view class="color-666 no-wrap">分组名</view>
<view class="color-333 u-m-l-60">{{data.name}}</view>
<view class="u-flex u-m-l-16 " @click="editName">
<view class="color-333 u-m-l-60">{{ data.name }}</view>
<view class="u-flex u-m-l-16" @click="editName">
<image src="/pageGoodsGroup/static/image/icon-edit.svg" class="icon-edit" mode=""></image>
</view>
</view>
<view class="u-flex u-m-t-24">
<view class="color-666">售卖时间</view>
<view class="color-main u-m-l-32" v-if="data.saleStartTime&&data.saleEndTime">
<text>{{data.saleStartTime}}</text>
<text>-</text>
<text>{{data.saleEndTime}}</text>
<view class="color-main u-m-l-32" v-if="data.saleStartTime && data.saleEndTime">
<text>{{ data.saleStartTime }}</text>
<text> - </text>
<text>{{ data.saleEndTime }}</text>
</view>
<view class="color-main u-m-l-32" v-else>
<text>00:00:00 - 23:59:59</text>
</view>
</view>
</view>
@@ -37,176 +40,169 @@
<view class="btn-default btn" @click="del">删除</view>
<view class="btn-primary btn u-m-l-38" @click="toEdit">编辑</view>
</view>
</view>
</template>
<script setup>
import { computed, ref, watchEffect } from 'vue';
import mySwitch from '@/components/my-components/my-switch.vue'
import go from '@/commons/utils/go.js';
import { computed, ref, watchEffect } from 'vue';
import mySwitch from '@/components/my-components/my-switch.vue';
import go from '@/commons/utils/go.js';
const emits = defineEmits(['changeClick', 'edit', 'editName', 'editSort', 'del', 'isShowChange']);
const emits = defineEmits(['changeClick','edit', 'editName','editSort', 'del', 'isShowChange'])
const props = defineProps({
index: {
type: Number
},
data: {
type: Object,
default: () => {
return {
status:true
}
}
},
})
function isShowChange() {
emits('isShowChange', {
...props.data,
})
const props = defineProps({
index: {
type: Number
},
data: {
type: Object,
default: () => {
return {
status: true
};
}
}
});
let isSellNone = ref(true)
isSellNone.value = props.isSellNone
function isShowChange() {
emits('isShowChange', {
...props.data
});
}
function isSellNoneChange() {
console.log(isSellNone.value);
console.log('isSellNoneChange');
}
let isSellNone = ref(true);
isSellNone.value = props.isSellNone;
let checked = ref(false)
function isSellNoneChange() {
console.log(isSellNone.value);
console.log('isSellNoneChange');
}
let checked = ref(false);
function changeClick() {
emits('changeClick', props.index)
}
function changeClick() {
emits('changeClick', props.index);
}
function del() {
emits('del', props.index)
}
function editName() {
emits('editName', props.index)
}
//携带参数type edit跳转到商品添加页面编辑与添加同一页面根据type值来判断
function editSort() {
emits('editSort', props.index)
}
function toEdit() {
emits('edit', props.index)
}
function del() {
emits('del', props.index);
}
function editName() {
emits('editName', props.index);
}
//携带参数type edit跳转到商品添加页面编辑与添加同一页面根据type值来判断
function editSort() {
emits('editSort', props.index);
}
function toEdit() {
emits('edit', props.index);
}
</script>
<style lang="scss" scoped>
$imgSize: 126rpx;
$price-color: #F02C45;
$imgSize: 126rpx;
$price-color: #f02c45;
.btn {
padding: 6rpx 28rpx;
border-radius: 100rpx;
font-size: 24rpx;
border: 1px solid transparent;
}
.btn {
padding: 6rpx 28rpx;
border-radius: 100rpx;
font-size: 24rpx;
border: 1px solid transparent;
}
.btn-primary {
border-color: $my-main-color;
color: $my-main-color;
}
.btn-primary {
border-color: $my-main-color;
color: $my-main-color;
}
.btn-default {
border-color: #999;
color: #999;
}
.btn-default {
border-color: #999;
color: #999;
}
.price {
color: $price-color;
}
.price {
color: $price-color;
}
.h-100 {
height: $imgSize;
}
.h-100 {
height: $imgSize;
}
.img {
width: $imgSize;
height: $imgSize;
}
.img {
width: $imgSize;
height: $imgSize;
}
.icon-arrow-right {
width: 32rpx;
height: 32rpx;
}
.icon-arrow-right {
width: 32rpx;
height: 32rpx;
}
.stock {
padding-right: 46rpx;
position: relative;
}
.stock {
padding-right: 46rpx;
position: relative;
}
.icon-edit {
width: 24rpx;
height: 24rpx;
}
.icon-edit {
width: 24rpx;
height: 24rpx;
}
.stock::after {
content: '';
position: absolute;
right: 10rpx;
top: 50%;
transform: translateY(-50%);
display: block;
width: 16rpx;
border: 2rpx solid #333333;
}
.stock::after {
content: '';
position: absolute;
right: 10rpx;
top: 50%;
transform: translateY(-50%);
display: block;
width: 16rpx;
border: 2rpx solid #333333;
}
.goods {
border-radius: 10rpx 10rpx 10rpx 10rpx;
background-color: #fff;
padding: 32rpx 28rpx 32rpx 28rpx;
font-size: 28rpx;
.goods {
border-radius: 10rpx 10rpx 10rpx 10rpx;
background-color: #fff;
padding: 32rpx 28rpx 32rpx 28rpx;
font-size: 28rpx;
.skus {
background: #F9F9F9;
border-radius: 14rpx 14rpx 14rpx 14rpx;
padding: 28rpx 42rpx;
.skus {
background: #f9f9f9;
border-radius: 14rpx 14rpx 14rpx 14rpx;
padding: 28rpx 42rpx;
.sku {
color: #000;
font-weight: 700;
padding: 6rpx 40rpx;
.sku {
color: #000;
font-weight: 700;
padding: 6rpx 40rpx;
}
.skds {
gap: 10rpx 50rpx;
}
.skd {
padding: 14rpx 40rpx;
background: #f0f2f5;
border-radius: 4rpx;
position: relative;
color: #666;
overflow: hidden;
.tag {
position: absolute;
right: 0;
top: 0;
font-size: 12rpx;
right: 0;
padding: 2rpx 4rpx;
border-radius: 0rpx 4rpx 4rpx 4rpx;
}
.skds {
gap: 10rpx 50rpx;
.tag-primary {
background-color: $my-main-color;
color: #fff;
}
.skd {
padding: 14rpx 40rpx;
background: #F0F2F5;
border-radius: 4rpx;
position: relative;
color: #666;
overflow: hidden;
.tag {
position: absolute;
right: 0;
top: 0;
font-size: 12rpx;
right: 0;
padding: 2rpx 4rpx;
border-radius: 0rpx 4rpx 4rpx 4rpx;
}
.tag-primary {
background-color: $my-main-color;
color: #fff;
}
}
}
}
</style>
}
</style>

View File

@@ -1,23 +1,24 @@
<template>
<view class="safe-page min-page">
<view class="goods-list u-p-30">
<view class="u-m-b-32" v-for="(item,index) in pageData.list" :key="index">
<my-category
@del="groupDel"
@editName="popupShow($event,'name',true)"
@editSort="popupShow($event,'sort',true)"
@edit="actionsShow"
@isShowChange="isSHowChange" :index="index" :data="item"
:showDetail="pageData.showGoodsDetail"></my-category>
<view class="u-m-b-32" v-for="(item, index) in pageData.list" :key="index">
<my-category
@del="groupDel"
@editName="popupShow($event, 'name', true)"
@editSort="popupShow($event, 'sort', true)"
@edit="actionsShow"
@isShowChange="isSHowChange"
:index="index"
:data="item"
:showDetail="pageData.showGoodsDetail"
></my-category>
</view>
<view class="u-m-t-44" v-if="pageData.list.length>0">
<my-pagination :page="pageData.query.page" :size="pageData.query.size" :totalElements="pageData.totalElements"
@change="pageChange"></my-pagination>
<view style="height: 200rpx;"></view>
<view class="u-m-t-44" v-if="pageData.list.length > 0">
<my-pagination :page="pageData.query.page" :size="pageData.query.size" :totalElements="pageData.totalElements" @change="pageChange"></my-pagination>
<view style="height: 200rpx"></view>
</view>
</view>
<view class="fixed-b">
<my-button :height="80" shape="circle" font-weight="700" @tap="toAddGroup">新建分组</my-button>
</view>
@@ -27,40 +28,41 @@
<edit-name @save="updataGroup" :item="popup.selData" v-model:show="popup.name.show"></edit-name>
<edit-time @save="updataGroup" :item="popup.selData" v-model:show="popup.time.show"></edit-time>
<up-action-sheet :round="10" @select="actionSelect" @close="actionsHide" cancelText="取消" :actions="actions.list"
:show="actions.show"></up-action-sheet>
<up-action-sheet :round="10" @select="actionSelect" @close="actionsHide" cancelText="取消" :actions="actions.list" :show="actions.show"></up-action-sheet>
</template>
<script setup>
import { reactive, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app'
import go from '@/commons/utils/go.js';
import myCategory from './components/category.vue'
import editSort from './components/edit-sort.vue';
import editName from './components/edit-name.vue';
import editTime from './components/edit-time.vue';
import { getProdGroupPage, addProdGroup, updateProdGroup, delProdGroup,editProdGroup } from '@/http/api/product.js'
const pageData = reactive({
showGoodsDetail: false,
query: {
page: 1,
size: 10,
},
totalElements: 0,
list: [],
selCategory: ''
})
/**
* 编辑列表
*/
const actions = reactive({
list: [{
import { reactive, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import go from '@/commons/utils/go.js';
import myCategory from './components/category.vue';
import editSort from './components/edit-sort.vue';
import editName from './components/edit-name.vue';
import editTime from './components/edit-time.vue';
import { getProdGroupPage, addProdGroup, updateProdGroup, delProdGroup, editProdGroup } from '@/http/api/product.js';
const pageData = reactive({
showGoodsDetail: false,
query: {
page: 1,
size: 10
},
totalElements: 0,
list: [],
selCategory: ''
});
/**
* 编辑列表
*/
const actions = reactive({
list: [
{
name: '排序',
color: '#333',
fontSize: '16'
}, {
},
{
name: '管理商品',
color: '#333',
fontSize: '16'
@@ -70,311 +72,310 @@
color: '#333',
fontSize: '16'
}
],
show: false,
})
/**
* 编辑数据
*/
const popup = reactive({
selIndex: -1,
selData: {
sort: ''
},
sort: {
show: false
},
name:{
show: false
},
time:{
show: false
}
})
onShow(() => {
getList()
})
/**
* 获取分组数据
*/
async function getList() {
const res = await getProdGroupPage(pageData.query)
pageData.list = res.records
pageData.totalElements = res.totalRow
if(res.records.length <= 0&&res.totalPage>1) {
pageData.query.page = res.totalPage
getList()
}
}
/**
* 编辑列表显示
* @param {Object} e
*/
function actionsShow(e) {
popup.selData = pageData.list[e]
popup.selIndex = e
actions.show = true
}
/**
* 编辑列表隐藏
*/
function actionsHide() {
actions.show = false
}
/**
* 编辑列表选择
* @param {Object} e
*/
function actionSelect(e) {
if (e.name == '排序') {
return popupShow(popup.selIndex, 'sort', true)
}
if (e.name == '管理商品') {
const {id,status,name,sort}=popup.selData
return go.to('PAGES_GOODS_GROUP_EDIT_GOODS', {
id,status,name,sort
})
}
if (e.name == '售卖时间') {
return popupShow(popup.selIndex, 'time', true)
}
}
/**
* 编辑打开
* @param {Object} e
* @param {Object} key
* @param {Object} show
*/
function popupShow(e, key, show) {
popup[key].show = show
popup.selIndex = e
popup.selData = pageData.list[e]
}
],
show: false
});
/**
* 编辑确认
* @param {Object} e
*/
async function updataGroup(e) {
console.log(e)
const res = await editProdGroup(e)
popup.sort.show = false;
popup.name.show = false;
popup.time.show = false;
pageData.list[popup.selIndex] = e
uni.$utils.showToast('更新成功')
getList()
/**
* 编辑数据
*/
const popup = reactive({
selIndex: -1,
selData: {
sort: ''
},
sort: {
show: false
},
name: {
show: false
},
time: {
show: false
}
/**
* 状态修改
* @param {Object} data
*/
async function isSHowChange(data) {
const res = await editProdGroup({
...data
})
uni.$utils.showToast('更新成功')
}
});
const goodsSortModel = ref(null)
const goodsTypeModel = ref(null)
let sort = ref(0)
const goodsTypeModelData = reactive({
selCategory: '',
title: '',
index: null,
useTypes: [{
name: '堂食',
isOpen: true
},
{
name: '自取',
isOpen: true
},
{
name: '外卖',
isOpen: true
},
{
name: '快递',
isOpen: true
}
]
})
/**
* 新增分组
*/
function toAddGroup() {
go.to('PAGES_GOODS_GROUP_EDIT', {
type: 'add'
})
}
onShow(() => {
getList();
});
/**
* 删除分组
* @param {Object} index
*/
function groupDel(index) {
uni.showModal({
title: '提示',
content: '请确保此分组下没有任何商品确认删除?',
success: res => {
if (res.confirm) {
delProdGroup(pageData.list[index].id).then(res => {
uni.$utils.showToast('删除成功')
setTimeout(()=>{
getList()
},1500)
})
}
},
fail: () => {},
complete: () => {}
/**
* 获取分组数据
*/
async function getList() {
const res = await getProdGroupPage(pageData.query);
pageData.list = res.records;
pageData.totalElements = res.totalRow;
if (res.records.length <= 0 && res.totalPage > 1) {
pageData.query.page = res.totalPage;
getList();
}
}
/**
* 编辑列表显示
* @param {Object} e
*/
function actionsShow(e) {
popup.selData = pageData.list[e];
popup.selIndex = e;
actions.show = true;
}
/**
* 编辑列表隐藏
*/
function actionsHide() {
actions.show = false;
}
/**
* 编辑列表选择
* @param {Object} e
*/
function actionSelect(e) {
if (e.name == '排序') {
return popupShow(popup.selIndex, 'sort', true);
}
if (e.name == '管理商品') {
const { id, status, name, sort } = popup.selData;
return go.to('PAGES_GOODS_GROUP_EDIT_GOODS', {
id,
status,
name,
sort
});
}
// 页数改变事件
function pageChange(page) {
pageData.query.page = page
getList()
if (e.name == '售卖时间') {
return popupShow(popup.selIndex, 'time', true);
}
}
/**
* 编辑打开
* @param {Object} e
* @param {Object} key
* @param {Object} show
*/
function popupShow(e, key, show) {
popup[key].show = show;
popup.selIndex = e;
popup.selData = pageData.list[e];
}
/**
* 编辑确认
* @param {Object} e
*/
async function updataGroup(e) {
console.log(e);
const res = await editProdGroup(e);
popup.sort.show = false;
popup.name.show = false;
popup.time.show = false;
pageData.list[popup.selIndex] = e;
uni.$utils.showToast('更新成功');
getList();
}
/**
* 状态修改
* @param {Object} data
*/
async function isSHowChange(data) {
const res = await editProdGroup({
...data
});
uni.$utils.showToast('更新成功');
}
const goodsSortModel = ref(null);
const goodsTypeModel = ref(null);
let sort = ref(0);
const goodsTypeModelData = reactive({
selCategory: '',
title: '',
index: null,
useTypes: [
{
name: '堂食',
isOpen: true
},
{
name: '自取',
isOpen: true
},
{
name: '外卖',
isOpen: true
},
{
name: '快递',
isOpen: true
}
]
});
/**
* 新增分组
*/
function toAddGroup() {
go.to('PAGES_GOODS_GROUP_EDIT', {
type: 'add'
});
}
/**
* 删除分组
* @param {Object} index
*/
function groupDel(index) {
uni.showModal({
title: '提示',
content: '请确保此分组下没有任何商品确认删除?',
success: (res) => {
if (res.confirm) {
delProdGroup(pageData.list[index].id).then((res) => {
uni.$utils.showToast('删除成功');
setTimeout(() => {
getList();
}, 1500);
});
}
},
fail: () => {},
complete: () => {}
});
}
// 页数改变事件
function pageChange(page) {
pageData.query.page = page;
getList();
}
</script>
<style scoped>
page {
background: #F9F9F9;
}
page {
background: #f1f1f1;
}
</style>
<style lang="scss" scoped>
.stock-btns {
padding: 0 100rpx;
.stock-btns {
padding: 0 100rpx;
display: flex;
flex-direction: column;
gap: 20rpx;
}
.safe-page {
background: #f1f1f1;
}
.icon-guige {
width: 42rpx;
height: 42rpx;
}
.bg-fff {
background-color: #fff;
}
.myTabs {
margin: 0 auto;
width: 434rpx;
height: 64rpx;
}
.input-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 26rpx;
background-color: $J-bg-ff;
.input-main {
flex: 1;
display: flex;
flex-direction: column;
gap: 20rpx;
}
.safe-page {
background: #F9F9F9;
}
.icon-guige {
width: 42rpx;
height: 42rpx;
}
.bg-fff {
background-color: #fff;
}
.myTabs {
margin: 0 auto;
width: 434rpx;
height: 64rpx;
}
.input-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 26rpx;
background-color: $J-bg-ff;
height: 64rpx;
.input-main {
image {
padding: 22rpx;
width: 26rpx;
height: 26rpx;
}
input {
flex: 1;
display: flex;
align-items: center;
height: 64rpx;
font-size: 27rpx;
}
image {
padding: 22rpx;
width: 26rpx;
height: 26rpx;
}
::v-deep uni-button {
font-size: 28rpx;
color: $my-main-color;
background: rgba(255, 255, 255, 1);
}
input {
flex: 1;
font-size: 27rpx;
}
::v-deep.uni-easyinput {
.uni-easyinput__content {
background-color: $J-bg-f5 !important;
border-radius: $J-b-r12;
::v-deep uni-button {
font-size: 28rpx;
color: $my-main-color;
background: rgba(255, 255, 255, 1);
}
.uni-easyinput__content-input {
padding-left: 0 !important;
::v-deep.uni-easyinput {
.uni-easyinput__content {
background-color: $J-bg-f5 !important;
border-radius: $J-b-r12;
.uni-easyinput__content-input {
padding-left: 0 !important;
.uni-input-input {
border-radius: $J-b-r12 !important;
overflow: hidden !important;
}
.uni-input-input {
border-radius: $J-b-r12 !important;
overflow: hidden !important;
}
}
.uni-input-placeholder {
font-size: 27rpx;
}
.uni-input-placeholder {
font-size: 27rpx;
}
.uni-icons {
color: rgba(230, 230, 230, 1) !important;
}
.uni-icons {
color: rgba(230, 230, 230, 1) !important;
}
}
}
}
}
.input-icon {
position: relative;
z-index: 10;
.input-icon {
position: relative;
z-index: 10;
}
.search-button {
position: absolute;
right: 0;
background-color: transparent !important;
color: transparent !important;
}
.states1 {
margin-top: 78rpx;
.item {
font-size: 24rpx;
color: #666;
margin-right: 70rpx;
background: #f4f4f4;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
.search-button {
position: absolute;
right: 0;
background-color: transparent !important;
color: transparent !important;
.item.active {
background: #e6f0ff;
color: $my-main-color;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
}
.states1 {
margin-top: 78rpx;
.item {
font-size: 24rpx;
color: #666;
margin-right: 70rpx;
background: #F4F4F4;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
.item.active {
background: #E6F0FF;
color: $my-main-color;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
}
.fixed-b {
position: fixed;
left: 110rpx;
right: 110rpx;
bottom: 110rpx;
}
</style>
.fixed-b {
position: fixed;
left: 110rpx;
right: 110rpx;
bottom: 110rpx;
}
</style>