优化分组商品编辑

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

@@ -7,106 +7,111 @@
<up--image :width="63" :height="63" :radius="3" :src="data.coverImg"></up--image>
</view>
<view class="w-full info u-p-l-30">
<view class=" color-333 u-flex u-row-between">
<view class="color-333 u-flex u-row-between">
<view class="u-flex">
<text class="u-m-r-24">{{data.name}}</text>
<text class="u-m-r-24">{{ data.name }}</text>
</view>
</view>
<view class="u-flex u-m-t-10 u-row-right">
<view class="u-flex u-m-t-10 u-row-right">
<view class="btn-default btn" @tap="del">删除</view>
</view>
</view>
</view>
</view>
</template>
<template v-else>
<view class=" u-flex u-p-l-30 u-p-r-30 u-p-t-16 u-p-b-16" @click="goodsClick">
<my-radio disabled @click.stop="goodsClick" :modelValue="data.checked"></my-radio>
<view class="u-flex u-m-l-32">
<text class="">{{data.name}}</text>
<view class="goods-wrap">
<view class="goods-item u-flex" @click="goodsClick">
<my-radio @click="goodsClick" :modelValue="data.checked"></my-radio>
<view class="u-flex u-m-l-10">
<text class="">{{ data.name }}</text>
</view>
</view>
</view>
</template>
</view>
</template>
<script setup>
const emits = defineEmits(['goodsClick', 'del'])
const emits = defineEmits(['goodsClick', 'del']);
const props = defineProps({
isBind: {
type: Boolean,
default: false
},
index: {
type: Number
},
data: {
type: Object,
default: () => {
return {
checked:false,
}
}
},
showDetail: {
type: Boolean,
default: false
const props = defineProps({
isBind: {
type: Boolean,
default: false
},
index: {
type: Number
},
data: {
type: Object,
default: () => {
return {
checked: false
};
}
})
function goodsClick(){
emits('goodsClick',props.index)
}
function del() {
emits('del', props.index)
},
showDetail: {
type: Boolean,
default: false
}
});
function goodsClick() {
emits('goodsClick', props.index);
}
function del() {
emits('del', props.index);
}
</script>
<style lang="scss" scoped>
$imgSize: 126rpx;
$imgSize: 126rpx;
.btn {
padding: 6rpx 28rpx;
border-radius: 100rpx;
border: 2rpx solid transparent;
}
.btn {
padding: 6rpx 28rpx;
border-radius: 100rpx;
border: 2rpx solid transparent;
}
.btn-default {
border-color: #999;
color: #999;
}
.btn-default {
border-color: #999;
color: #999;
}
.img {
width: $imgSize;
height: $imgSize;
}
.img {
width: $imgSize;
height: $imgSize;
}
.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: 20rpx;
.skus {
background: #f9f9f9;
border-radius: 14rpx 14rpx 14rpx 14rpx;
padding: 20rpx;
.sku {
color: #000;
font-weight: 700;
padding: 6rpx 40rpx;
}
.sku {
color: #000;
font-weight: 700;
padding: 6rpx 40rpx;
}
.skds {
gap: 10rpx 50rpx;
}
.skds {
gap: 10rpx 50rpx;
}
}
</style>
}
.goods-wrap {
padding: 0 20upx;
.goods-item {
padding: 20upx 0;
border-bottom: 1px solid #ececec;
}
}
</style>

View File

@@ -1,19 +1,22 @@
<template>
<view class="safe-page min-page">
<up-sticky>
<view class="bg-fff u-p-l-30 u-p-b-24">
<view class="bg-fff u-p-l-30 u-p-b-24">
<view class="input-wrapper">
<view class="input-main">
<view class="u-flex u-p-r-30 u-font-28" @click="onCategoryShowChange(true)">
<text class="u-m-r-10 u-line-1"
style="max-width: 100rpx;">{{pageData.categoryName||'全部' }}</text>
<text class="u-m-r-10 u-line-1" style="max-width: 100rpx">{{ pageData.categoryName || '全部' }}</text>
<up-icon name="arrow-down" size="16"></up-icon>
</view>
<uni-easyinput clearable class='jeepay-search' :inputBorder="false"
:placeholder="pageData.search.placeholder" v-model="pageData.query.name"
<uni-easyinput
clearable
class="jeepay-search"
:inputBorder="false"
:placeholder="pageData.search.placeholder"
v-model="pageData.query.name"
@clear="searchFunc"
@confirm="searchFunc">
@confirm="searchFunc"
>
<template #prefixIcon>
<image src="@/static/iconImg/icon-search.svg" class="input-icon" />
</template>
@@ -23,393 +26,390 @@
</view>
</view>
</view>
<view class="u-flex states1 u-row-between u-font-28">
<view class=" u-flex-1 item u-flex u-row-center tranistion u-text-center color-333"
:class="{'active':pageData.stateCurrent==index}" @tap="statesTableClick(index)"
v-for="(item,index) in statesTabsList" :key="index">
<view class="text">{{item}}</view>
<view class="u-flex states1 u-row-between u-font-28">
<view
class="u-flex-1 item u-flex u-row-center tranistion u-text-center color-333"
:class="{ active: pageData.stateCurrent == index }"
@tap="statesTableClick(index)"
v-for="(item, index) in statesTabsList"
:key="index"
>
<view class="text">{{ item }}</view>
</view>
</view>
</view>
</up-sticky>
<template v-if="pageData.stateCurrent==0">
<view class="goods-list u-p-30">
<template v-if="pageData.stateCurrent == 0">
<view class="goods-list u-p-30">
<template v-if="pageData.bindGoodsList.length">
<view class="u-m-b-32" v-for="(item,index) in pageData.bindGoodsList" :key="index">
<my-goods isBind :index="index" :data="item" @del="goodsDel"
:showDetail="pageData.showGoodsDetail"></my-goods>
<view class="u-m-b-32" v-for="(item, index) in pageData.bindGoodsList" :key="index">
<my-goods isBind :index="index" :data="item" @del="goodsDel" :showDetail="pageData.showGoodsDetail"></my-goods>
</view>
</template>
<template v-if="pageData.hasAjax&&!pageData.bindGoodsList.length">
<my-img-empty :tips="isSearch?'未搜索到相关绑定商品':'暂无绑定商品' "></my-img-empty>
<template v-if="pageData.hasAjax && !pageData.bindGoodsList.length">
<my-img-empty :tips="isSearch ? '未搜索到相关绑定商品' : '暂无绑定商品'"></my-img-empty>
</template>
<view style="height: 100rpx;"></view>
<view style="height: 100rpx"></view>
</view>
</template>
<template v-else>
<view class="goods-list u-p-30">
<view class="goods-list u-p-30">
<view class="bg-fff border-r-18 u-p-t-16 u-p-b-16 box-shadow">
<template v-if="pageData.goodsList.length">
<view class="" v-for="(item,index) in pageData.goodsList" :key="index">
<my-goods @goodsClick="goodsClick" :index="index" :data="item"
:showDetail="pageData.showGoodsDetail"></my-goods>
<view class="" v-for="(item, index) in pageData.goodsList" :key="index">
<my-goods @goodsClick="goodsClick" :index="index" :data="item" :showDetail="pageData.showGoodsDetail"></my-goods>
</view>
</template>
<template v-if="pageData.hasAjax&&!pageData.goodsList.length">
<template v-if="pageData.hasAjax && !pageData.goodsList.length">
<my-img-empty tips="未找到相关商品"></my-img-empty>
</template>
</view>
<view class="fixed-b">
<my-button shape="circle" @click="save">确定</my-button>
</view>
<view style="height: 100rpx;"></view>
<view style="height: 100rpx"></view>
</view>
</template>
<!-- 分类 -->
<my-category v-model:isShow="pageData.categoryShow" @confirm="setCategory"></my-category>
</view>
</template>
<script setup>
import { onLoad, onShow } from '@dcloudio/uni-app';
import { reactive, ref, watch } from 'vue';
import myGoods from './components/goods.vue'
import myCategory from './components/category.vue'
import { hasPermission } from '@/commons/utils/hasPermission.js';
import { onLoad, onShow } from '@dcloudio/uni-app';
import { reactive, ref, watch } from 'vue';
import myGoods from './components/goods.vue';
import myCategory from './components/category.vue';
import { hasPermission } from '@/commons/utils/hasPermission.js';
import { categoryPage } from '@/http/api/cateGory.js'
import { getProductPage,getProdGroupDetail,updateProdGroup } from '@/http/api/product.js'
const pageData = reactive({
stateCurrent: 0,
search: {
value: '',
placeholder: '输入搜索的商品'
},
showGoodsDetail: false,
bindGoodsList: [],
goodsList: [],
query: {
page: 1,
size: 999,
categoryId: '',
name: '',
id: "",
},
category: '',
categoryList: [], //分类列表
categoryShow: false,
categoryName: '',
hasAjax: false
})
let isSearch=ref(false)
const statesTabsList = ['已添加', '未添加']
const control = ref(null)
const model = ref(null)
const option = reactive({})
//分类
const category = ref(null)
onLoad((opt) => {
Object.assign(option, opt)
init()
})
onShow(() => {
})
watch(() => pageData.query.categoryId, (newval) => {
if(pageData.stateCurrent==1){
getGoodsList()
}else{
getGroupBindGoods()
}
})
watch(() => pageData.stateCurrent, (newval) => {
if (newval==1) {
getGoodsList()
} else {
getGroupBindGoods()
}
})
async function init() {
await getGroupBindGoods()
getGoodsList()
}
/**
* 搜索
*/
async function searchFunc() {
isSearch.value=true
if (pageData.stateCurrent) {
getGoodsList()
} else {
const res = await getProdGroupDetail(option.id)
pageData.bindGoodsList = res.productList.filter(v=>{
return v.name.includes(pageData.query.name)&&(pageData.query.categoryId==''?true:v.categoryId==pageData.query.categoryId)
})
}
}
/**
* 获取商品列表
*/
function getGoodsList() {
getProductPage(pageData.query).then(res => {
pageData.hasAjax = true
let goodsList = res.records.map(v => {
return {
...v,
checked: false
}
})
pageData.goodsList = goodsList.filter(v => {
return !pageData.bindGoodsList.find(bindGoods => bindGoods.id == v.id)
})
})
}
/**
* 获取分组详情
*/
async function getGroupBindGoods() {
let res = await getProdGroupDetail(option.id)
pageData.bindGoodsList = res.productList.filter(v=>{
return pageData.query.categoryId === '' ? true : (v.categoryId==pageData.query.categoryId)&&(v.name.includes(pageData.query.name))
})
}
/**
* 已添加/未添加切换
* @param {Object} index
*/
function statesTableClick(index) {
pageData.stateCurrent = index
}
/**
* 分类选择
* @param {Object} show
*/
function onCategoryShowChange(show) {
pageData.categoryShow = show
}
/**
* 分类选择确定
* @param {Object} category
*/
function setCategory(category) {
pageData.query.categoryId = category.id
pageData.categoryName = category.name
}
/**
* 绑定商品
*/
async function save() {
const res = await hasPermission('允许修改分组')
if (!res) {
return
}
await updateProdGroup({
...option,
productIds: [...pageData.bindGoodsList.map(v => v.id), ...pageData.goodsList.filter(v => v.checked)
.map(v => v.id)
]
})
pageData.stateCurrent = 0
}
import { categoryPage } from '@/http/api/cateGory.js';
import { getProductPage, getProdGroupDetail, updateProdGroup } from '@/http/api/product.js';
/**
* 删除商品
* @param {Object} index
*/
async function goodsDel(index) {
const res = await hasPermission('允许修改分组')
if (!res) {
return
const pageData = reactive({
stateCurrent: 0,
search: {
value: '',
placeholder: '输入搜索的商品'
},
showGoodsDetail: false,
bindGoodsList: [],
goodsList: [],
query: {
page: 1,
size: 999,
categoryId: '',
name: '',
id: ''
},
// 原始已绑定的上商品列表
bindOriginGoodsList: [],
category: '',
categoryList: [], //分类列表
categoryShow: false,
categoryName: '',
hasAjax: false
});
let isSearch = ref(false);
const statesTabsList = ['已添加', '未添加'];
const control = ref(null);
const model = ref(null);
const option = reactive({});
//分类
const category = ref(null);
onLoad((opt) => {
Object.assign(option, opt);
init();
});
onShow(() => {});
watch(
() => pageData.query.categoryId,
(newval) => {
if (pageData.stateCurrent == 1) {
getGoodsList();
} else {
getGroupBindGoods();
}
const goods = pageData.bindGoodsList[index]
uni.showModal({
title: '提示',
content: '是否确认将' + goods.name + '从该分组中移除',
success: function(res) {
if (res.confirm) {
pageData.bindGoodsList.splice(index, 1)
updateProdGroup({
...option,
productIds: pageData.bindGoodsList.map(v => v.id)
})
} else if (res.cancel) {}
}
}
);
watch(
() => pageData.stateCurrent,
(newval) => {
if (newval == 1) {
getGoodsList();
} else {
getGroupBindGoods();
}
}
);
async function init() {
await getGroupBindGoods();
getGoodsList();
}
/**
* 搜索
*/
async function searchFunc() {
isSearch.value = true;
if (pageData.stateCurrent) {
getGoodsList();
} else {
const res = await getProdGroupDetail(option.id);
pageData.bindGoodsList = res.productList.filter((v) => {
return v.name.includes(pageData.query.name) && (pageData.query.categoryId == '' ? true : v.categoryId == pageData.query.categoryId);
});
}
}
function goodsClick(e) {
pageData.goodsList[e].checked = !pageData.goodsList[e].checked
/**
* 获取商品列表
*/
function getGoodsList() {
getProductPage(pageData.query).then((res) => {
pageData.hasAjax = true;
let goodsList = res.records.map((v) => {
return {
...v,
checked: false
};
});
pageData.goodsList = goodsList.filter((v) => {
return !pageData.bindOriginGoodsList.find((bindGoods) => bindGoods.id == v.id);
});
});
}
/**
* 获取分组详情
*/
async function getGroupBindGoods() {
let res = await getProdGroupDetail(option.id);
pageData.bindOriginGoodsList = res.productList;
pageData.bindGoodsList = res.productList.filter((v) => {
return pageData.query.categoryId === '' ? true : v.categoryId == pageData.query.categoryId && v.name.includes(pageData.query.name);
});
}
/**
* 已添加/未添加切换
* @param {Object} index
*/
function statesTableClick(index) {
pageData.stateCurrent = index;
}
/**
* 分类选择
* @param {Object} show
*/
function onCategoryShowChange(show) {
pageData.categoryShow = show;
}
/**
* 分类选择确定
* @param {Object} category
*/
function setCategory(category) {
pageData.query.categoryId = category.id;
pageData.categoryName = category.name;
}
/**
* 绑定商品
*/
async function save() {
const res = await hasPermission('允许修改分组');
if (!res) {
return;
}
await updateProdGroup({
...option,
productIds: [...pageData.bindOriginGoodsList.map((v) => v.id), ...pageData.goodsList.filter((v) => v.checked).map((v) => v.id)]
});
pageData.stateCurrent = 0;
}
/**
* 删除商品
* @param {Object} index
*/
async function goodsDel(index) {
const res = await hasPermission('允许修改分组');
if (!res) {
return;
}
const goods = pageData.bindOriginGoodsList[index];
uni.showModal({
title: '提示',
content: '是否确认将' + goods.name + '从该分组中移除',
success: function (res) {
if (res.confirm) {
pageData.bindGoodsList.splice(index, 1);
pageData.bindOriginGoodsList.splice(index, 1);
updateProdGroup({
...option,
productIds: pageData.bindOriginGoodsList.map((v) => v.id)
});
} else if (res.cancel) {
}
}
});
}
function goodsClick(e) {
pageData.goodsList[e].checked = !pageData.goodsList[e].checked;
}
</script>
<style scoped>
page {
background: #F9F9F9;
}
page {
background: #f9f9f9;
}
</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: #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;
.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;
}
.search-button {
position: absolute;
right: 0;
background-color: transparent !important;
color: transparent !important;
}
.states1 {
margin-top: 24rpx;
.states1 {
margin-top: 24rpx;
.item {
font-size: 28rpx;
color: #666;
.item {
font-size: 28rpx;
color: #666;
.text {
position: relative;
padding-top: 14rpx;
padding-bottom: 16rpx;
&::after {
content: '';
display: block;
position: absolute;
transition: all 0.2s ease-in-out;
left: 10rpx;
right: 10rpx;
bottom: 0;
height: 4rpx;
background: transparent;
border-radius: 12rpx 12rpx 12rpx 12rpx;
}
}
&.active {
color: $my-main-color;
border-radius: 8rpx 8rpx 8rpx 8rpx;
.text {
position: relative;
padding-top: 14rpx;
padding-bottom: 16rpx;
&::after {
content: '';
display: block;
position: absolute;
transition: all .2s ease-in-out;
left: 10rpx;
right: 10rpx;
bottom: 0;
height: 4rpx;
background: transparent;
border-radius: 12rpx 12rpx 12rpx 12rpx;
background-color: $my-main-color;
}
}
&.active {
color: $my-main-color;
border-radius: 8rpx 8rpx 8rpx 8rpx;
.text {
&::after {
background-color: $my-main-color;
}
}
}
}
}
}
.fixed-b {
position: fixed;
bottom: calc(env(safe-area-inset-bottom) + 16rpx);
/* #ifdef H5 */
bottom: 50rpx;
/* #endif */
left: 110rpx;
right: 110rpx;
}
</style>
.fixed-b {
position: fixed;
bottom: calc(env(safe-area-inset-bottom) + 16rpx);
/* #ifdef H5 */
bottom: 50rpx;
/* #endif */
left: 110rpx;
right: 110rpx;
}
</style>