同步代码

This commit is contained in:
GaoHao
2025-02-07 14:49:20 +08:00
commit 0740c3f349
1141 changed files with 167372 additions and 0 deletions

View File

@@ -0,0 +1,231 @@
<template>
<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>
</view>
<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>
<view class="u-flex">
<view class="u-m-r-14 color-999">是否启用</view>
<up-switch :activeValue="1" :inactiveValue="0" v-model="isShow" @change="isShowChange" :size="18"></up-switch>
</view>
</view>
<view class="u-m-t-24 u-p-l-54 ">
<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">
<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>
</view>
</view>
<view class="u-m-t-24 u-flex u-row-right">
<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 {
ColorMain
} from '@/commons/color.js'
const emits = defineEmits(['changeClick','edit', 'editName','editSort', 'del', 'isShowChange'])
const props = defineProps({
index: {
type: Number
},
data: {
type: Object,
default: () => {
return {
isShow:true
}
}
},
})
let isShow = ref(props.data.isShow)
function isShowChange() {
console.log(isShow.value);
emits('isShowChange', {
...props.data,
isShow: isShow.value
})
}
let isSellNone = ref(true)
isSellNone.value = props.isSellNone
function isSellNoneChange() {
console.log(isSellNone.value);
console.log('isSellNoneChange');
}
let checked = ref(false)
function radioClick() {
console.log(props.index);
emits('radioClick', props.index)
}
function changeClick() {
emits('changeClick', props.index)
}
function useTypeClick() {
emits('useTypeClick', 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)
// uni.setStorageSync('cateItem', props.data)
// go.to('PAGES_CATEGORY_EDIT', {
// type: 'edit',
// })
}
</script>
<style lang="scss" scoped>
$imgSize: 126rpx;
$price-color: #F02C45;
.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-default {
border-color: #999;
color: #999;
}
.price {
color: $price-color;
}
.h-100 {
height: $imgSize;
}
.img {
width: $imgSize;
height: $imgSize;
}
.icon-arrow-right {
width: 32rpx;
height: 32rpx;
}
.stock {
padding-right: 46rpx;
position: relative;
}
.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;
}
.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;
.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;
}
.tag-primary {
background-color: $my-main-color;
color: #fff;
}
}
}
}
</style>

View File

@@ -0,0 +1,128 @@
<template>
<up-popup :show="popShow" @close="close" @open="open" mode="center" :round="9">
<view class="u-p-32 box u-font-28">
<view class="u-flex u-relative u-row-center">
<view class="u-font-32">编辑</view>
<view class="u-absolute close">
<up-icon @click="close" :size="16" color="#000" name="close-circle-fill"></up-icon>
</view>
</view>
<view class="u-m-t-36">
<view>修改分组名称</view>
<view class="u-m-t-38">
<view class="u-m-b-32">
<view class="u-m-t-16">
<up-input v-model="name">
</up-input>
</view>
</view>
<view class="u-m-t-60">
<my-button type="primary" shape="circle" @tap="save">
<view class="u-font-32">
保存
</view>
</my-button>
</view>
</view>
</view>
</view>
</up-popup>
</template>
<script setup>
import {
reactive,
ref,
watch,
onMounted,
computed
} from 'vue';
import {
returnSkuSnap,
returnTypeEnum,
returnCategory
} from '@/pageProduct/util.js'
import {
$tbShopUnit
} from '@/http/yskApi/goods.js'
const props = defineProps({
show: {
type: Boolean,
default: false
},
category: {
type: Array,
default: () => []
},
item: {
type: Object,
default: () => {
name:''
}
}
})
function changeShowRecoders(show) {
recoders.show = show
}
const data = ref(props.item)
const emits = defineEmits(['update:show', 'save'])
const form = reactive({
note: ''
})
let popShow = ref(props.show)
let name=ref('')
watch(()=>props.item.name,(newval)=>{
name.value=newval
})
watch(() => props.show, (newval) => {
popShow.value = newval
if (newval) {
data.value = props.item
}
})
const isSku = computed(() => {
// return data.value.typeEnum == '多规格'
return false
})
watch(() => popShow.value, (newval) => {
emits('update:show', newval)
})
function close() {
popShow.value = false
}
function open() {
}
function save() {
emits('save', {
...data.value,
name:name.value
})
}
</script>
<style lang="scss" scoped>
.box {
width: 556rpx;
border-radius: 18rpx 18rpx 18rpx 18rpx;
box-sizing: border-box;
}
.close {
position: absolute;
right: 0;
}
.number {
color: #EE4646;
}
</style>

View File

@@ -0,0 +1,128 @@
<template>
<up-popup :show="popShow" @close="close" @open="open" mode="center" :round="9">
<view class="u-p-32 box u-font-28">
<view class="u-flex u-relative u-row-center">
<view class="u-font-32">编辑</view>
<view class="u-absolute close">
<up-icon @click="close" :size="16" color="#000" name="close-circle-fill"></up-icon>
</view>
</view>
<view class="u-m-t-36">
<view>修改排序</view>
<view class="u-m-t-38">
<view class="u-m-b-32">
<view class="u-m-t-16">
<up-input v-model="sort">
</up-input>
</view>
</view>
<view class="u-m-t-60">
<my-button type="primary" shape="circle" @tap="save">
<view class="u-font-32">
保存
</view>
</my-button>
</view>
</view>
</view>
</view>
</up-popup>
</template>
<script setup>
import {
reactive,
ref,
watch,
onMounted,
computed
} from 'vue';
import {
returnSkuSnap,
returnTypeEnum,
returnCategory
} from '@/pageProduct/util.js'
import {
$tbShopUnit
} from '@/http/yskApi/goods.js'
const props = defineProps({
show: {
type: Boolean,
default: false
},
category: {
type: Array,
default: () => []
},
item: {
type: Object,
default: () => {
sort:''
}
}
})
function changeShowRecoders(show) {
recoders.show = show
}
const data = ref(props.item)
const emits = defineEmits(['update:show', 'save'])
const form = reactive({
note: ''
})
let popShow = ref(props.show)
let sort=ref('')
watch(()=>props.item.sort,(newval)=>{
sort.value=newval
})
watch(() => props.show, (newval) => {
popShow.value = newval
if (newval) {
data.value = props.item
}
})
const isSku = computed(() => {
// return data.value.typeEnum == '多规格'
return false
})
watch(() => popShow.value, (newval) => {
emits('update:show', newval)
})
function close() {
popShow.value = false
}
function open() {
}
function save() {
emits('save', {
...data.value,
sort:sort.value
})
}
</script>
<style lang="scss" scoped>
.box {
width: 556rpx;
border-radius: 18rpx 18rpx 18rpx 18rpx;
box-sizing: border-box;
}
.close {
position: absolute;
right: 0;
}
.number {
color: #EE4646;
}
</style>

View File

@@ -0,0 +1,183 @@
<template>
<up-popup :show="popShow" @close="close" @open="open" mode="center" :round="9">
<view class="u-p-32 box u-font-28">
<view class="u-flex u-relative u-row-center">
<view class="u-font-32">编辑</view>
<view class="u-absolute close">
<up-icon @click="close" :size="16" color="#000" name="close-circle-fill"></up-icon>
</view>
</view>
<view class="u-m-t-36">
<view class="u-flex u-row-between">
<view class="">
售卖时间管控
</view>
<my-switch v-model="category.useTime"></my-switch>
</view>
<view v-if="category.useTime" class="u-flex u-row-between u-col-center u-m-t-30 u-p-b-12">
<view class="u-flex timesel" @click="changeTime('start')">
<up-icon name="clock" size="14"></up-icon>
<view class="u-m-l-20">
<text v-if="!category.saleStartTime" class="color-999">起始时间</text>
<text v-else>{{category.saleStartTime}}</text>
</view>
</view>
<view class="u-p-l-30 u-p-r-30"></view>
<view class="u-flex timesel" @click="changeTime('end')">
<up-icon name="clock" size="14"></up-icon>
<view class="u-m-l-20">
<text v-if="!category.saleEndTime" class="color-999">结束时间</text>
<text>{{category.saleEndTime}}</text>
</view>
</view>
</view>
<view class="u-m-t-38">
<view class="u-m-b-32">
</view>
<view class="u-m-t-60">
<my-button type="primary" shape="circle" @tap="save">
<view class="u-font-32">
保存
</view>
</my-button>
</view>
</view>
</view>
<up-datetime-picker @cancel="timeCancel" @confirm="timeConfirm" :show="time.show" v-model="time.val" mode="time"></up-datetime-picker>
</view>
</up-popup>
</template>
<script setup>
import {
reactive,
ref,
watch,
onMounted,
computed
} from 'vue';
import infoBox from '@/commons/utils/infoBox.js'
const props = defineProps({
show: {
type: Boolean,
default: false
},
item: {
type: Object,
default: () => {
name: ''
}
}
})
const category =reactive({
useTime: 0,
saleEndTime:'',
saleStartTime:'',
})
const time=reactive({
show:false,
val:'',
key:''
})
function timeCancel(){
time.show=false
}
function timeConfirm(e){
console.log(e);
if(time.key=='start'){
category.saleStartTime=e.value
}else{
category.saleEndTime=e.value
}
time.val=''
time.show=false
}
function changeTime(key) {
time.key=key;
time.val=key=='start'?category.saleStartTime:category.saleEndTime
time.show=true;
}
function changeShowRecoders(show) {
recoders.show = show
}
const data = ref(props.item)
const emits = defineEmits(['update:show', 'save'])
const form = reactive({
note: ''
})
let popShow = ref(props.show)
let name = ref('')
watch(() => props.item.name, (newval) => {
name.value = newval
})
watch(() => props.show, (newval) => {
popShow.value = newval
if (newval) {
data.value = props.item
console.log(props.item);
Object.assign(category,props.item)
console.log(props.item);
}
})
const isSku = computed(() => {
// return data.value.typeEnum == '多规格'
return false
})
watch(() => popShow.value, (newval) => {
emits('update:show', newval)
})
function close() {
popShow.value = false
}
function open() {
}
function save() {
if(category.useTime){
if(!category.saleStartTime){
return infoBox.showToast('请选择起始时间')
}
if(!category.saleEndTime){
return infoBox.showToast('请选择结束时间')
}
}
emits('save', {
...data.value,...category
})
}
</script>
<style lang="scss" scoped>
.box {
width: 600rpx;
border-radius: 18rpx 18rpx 18rpx 18rpx;
box-sizing: border-box;
}
.timesel {
border: 1px solid #eee;
border-radius: 10rpx;
padding: 10rpx 20rpx;
flex: 1;
}
.close {
position: absolute;
right: 0;
}
.number {
color: #EE4646;
}
</style>

View File

@@ -0,0 +1,483 @@
<template>
<view class="safe-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="categoryDel" @useTypeClick="categoryUseTypeClick"
@editSort="popupShow($event,'sort',true)" @edit="actionsShow" @radioClick="goodsRadioClick"
@isShowChange="isSHowChange" :index="index" :data="item" :showChecked="showChecked"
:showDetail="pageData.showGoodsDetail"></my-category>
</view>
<view class="u-m-t-44">
<my-pagination :size="pageData.query.size" :totalElements="pageData.totalElements"
@change="pageChange"></my-pagination>
<view style="height: 200rpx;"></view>
</view>
</view>
<!-- 删除弹窗 -->
<my-model desc="请确保此分类下没有任何商品确认删除?" ref="delModel" @confirm="delModelConfirm"></my-model>
<view class="fixed-b">
<my-button :height="80" shape="circle" showShadow @tap="toAddCategory">新建分组</my-button>
</view>
</view>
<edit-sort @save="updataGroup" :item="popup.selData" v-model:show="popup.sort.show"></edit-sort>
<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,
watch
} from 'vue';
import {
onShow
} from '@dcloudio/uni-app'
import go from '@/commons/utils/go.js';
import myCategory from './components/category.vue'
import infoBox from "@/commons/utils/infoBox.js"
import editSort from './components/edit-sort.vue';
import {
tbProductGroupGet,
tbProductGroupDelete,
tbProductGroupPut,
upGroupSort,
tbProductGroupPost
} from '@/http/yskApi/shop.js'
const $productCategory = {
add: tbProductGroupPost,
del: tbProductGroupDelete,
update: tbProductGroupPut,
get: tbProductGroupGet
}
const actions = reactive({
list: [{
name: '排序',
color: '#333',
fontSize: '16'
}, {
name: '管理商品',
color: '#333',
fontSize: '16'
}],
show: false,
})
function actionSelect(e) {
console.log(e);
if (e.name == '排序') {
return popupShow(actions.selIndex, 'sort', true)
}
if (e.name == '管理商品') {
const {id,isShow,name,sort}=actions.selData
return go.to('PAGES_GOODS_GROUP_EDIT_GOODS', {
id,isShow,name,sort
})
}
}
function actionsHide() {
actions.show = false
}
function actionsShow(e) {
console.log(e);
actions.selData = pageData.list[e]
actions.selIndex = e
actions.show = true
}
const popup = reactive({
selIndex: -1,
selData: {
sort: ''
},
sort: {
show: false
}
})
function popupShow(e, key, show) {
popup.selData = pageData.list[e]
popup.selIndex = e
popup[key].show = show
}
async function updataGroup(e) {
console.log(e);
const res = await $productCategory.update(e)
popup.sort.show = false;
pageData.list[popup.selIndex] = e
infoBox.showToast('更新成功')
}
const tabsList = ['简洁', '详情']
const statesTabsList = ['在售中', '已下架']
const states1TabsList = ['全部', '已售罄']
const control = ref(null)
const delModel = ref(null)
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
}
]
})
const pageData = reactive({
stateCurrent: 0,
stateCurrent1: 0,
componentBottom: 264,
search: {
value: '',
placeholder: '输入搜索的商品'
},
showGoodsDetail: false,
query: {
page: 0,
size: 10,
sort: 'id',
shopId: uni.getStorageSync('shopId')
},
totalElements: 0,
list: [],
selCategory: ''
})
async function init() {
const res = await $productCategory.get(pageData.query)
pageData.list = res.content
pageData.totalElements = res.totalElements
}
onShow(() => {
init()
})
function toAddCategory() {
go.to('PAGES_GOODS_GROUP_EDIT', {
type: 'add'
})
}
function goodsSortModelCancel() {
console.log('goodsSortModelCancel');
goodsSortModel.value.close()
}
async function goodsSortModelSave() {
console.log('goodsSortModelSave');
const res = await $productCategory.update({
...pageData.selCategory,
sort: sort.value
})
infoBox.showToast('修改成功')
goodsSortModelCancel()
init()
}
async function isSHowChange(data) {
const res = await $productCategory.update({
...data
})
infoBox.showToast('修改成功')
// init()
}
function categoryUseTypeClick(index) {
goodsTypeModelData.index = index
// goodsTypeModelData.useTypes=pageData.list[index].useTypes
const cateItem = pageData.list[index]
console.log(cateItem);
goodsTypeModelData.selCategory = cateItem
goodsTypeModelData.title = cateItem.name
goodsTypeModel.value.open()
}
//点击修改按钮弹出修改商品弹窗
function goodsChangeClick(index) {
console.log(index);
const goods = pageData.list[index]
sort.value = goods.sort
pageData.selCategory = goods
goodsSortModel.value.open()
}
function statesTableClick(index) {
pageData.stateCurrent = index
}
function states1TableClick(index) {
pageData.stateCurrent1 = index
}
let test = ref(false)
function tabsChange(i) {
console.log(i);
pageData.showGoodsDetail = i ? true : false
}
//改变商品的选中状态
function changeGoodsChecked(checked, index) {
if (index !== undefined) {
pageData.list[index].checked = checked
} else {
pageData.list.map(v => {
v.checked = checked
})
}
control.value.setisSelectAll(isAllChecked() ? true : false)
}
// 获取已经选中的商品
function getChechkedlist() {
return pageData.list.filter(v => v.checked)
}
//是否全部选中
function isAllChecked() {
return getChechkedlist().length === pageData.list.length
}
// 是否有商品选中
function isHasChekdGoods() {
return getChechkedlist().length ? true : false
}
function searchFunc() {
console.log('searchFunc');
}
let showChecked = ref(false)
//商品start
function goodsRadioClick(index) {
var checked = !pageData.list[index].checked
changeGoodsChecked(checked, index)
}
//下架
function offShelf() {
const hasCheckedArr = getChechkedlist()
const hasChecked = isHasChekdGoods()
if (!hasChecked) {
return infoBox.showToast('您还没有选中商品!')
}
model.value.open()
}
let nowCateIndex = null
function categoryDel(index) {
// nowCateIndex=index
// delModel.value.open()
uni.showModal({
title: '提示',
content: '请确保此分类下没有任何商品确认删除?',
success: res => {
if (res.confirm) {
const islast = pageData.list.length === 1
$productCategory.del([pageData.list[index].id]).then(res => {
infoBox.showToast('删除成功')
// if(islast&&pageData.query.page>=1){
// pageData.query.page--
// }
init()
})
}
},
fail: () => {},
complete: () => {}
});
}
//删除分类确认
function delModelConfirm() {
console.log('confirm');
pageData.list.splice(nowCateIndex, 1)
delModel.value.close()
}
//商品end
//控制条
function controlChange(bol) {
console.log(bol);
showChecked.value = bol
}
// 全选
function allCheckedChange(checked) {
changeGoodsChecked(checked)
}
// 页数改变事件
function pageChange(page) {
pageData.query.page = page - 1
init()
}
//分类
const category = ref(null)
function toggleCategory() {
category.value.toggle()
}
function cateClick(cate) {
console.log(cate);
}
</script>
<style scoped>
page {
background: #F9F9F9;
}
</style>
<style lang="scss" scoped>
.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;
align-items: center;
height: 64rpx;
image {
padding: 22rpx;
width: 26rpx;
height: 26rpx;
}
input {
flex: 1;
font-size: 27rpx;
}
::v-deep uni-button {
font-size: 28rpx;
color: $my-main-color;
background: rgba(255, 255, 255, 1);
}
::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-placeholder {
font-size: 27rpx;
}
.uni-icons {
color: rgba(230, 230, 230, 1) !important;
}
}
}
}
}
.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;
}
.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>

View File

@@ -0,0 +1,509 @@
<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="categoryDel" @useTypeClick="categoryUseTypeClick"
@editName="popupShow($event,'name',true)"
@editSort="popupShow($event,'sort',true)" @edit="actionsShow" @radioClick="goodsRadioClick"
@isShowChange="isSHowChange" :index="index" :data="item" :showChecked="showChecked"
:showDetail="pageData.showGoodsDetail"></my-category>
</view>
<view class="u-m-t-44" v-if="pageData.list.length>0">
<my-pagination :page="pageData.query.page+1" :size="pageData.query.size" :totalElements="pageData.totalElements"
@change="pageChange"></my-pagination>
<view style="height: 200rpx;"></view>
</view>
</view>
<!-- 删除弹窗 -->
<my-model desc="请确保此分类下没有任何商品确认删除?" ref="delModel" @confirm="delModelConfirm"></my-model>
<view class="fixed-b">
<my-button :height="80" shape="circle" font-weight="700" @tap="toAddCategory">新建分组</my-button>
</view>
</view>
<edit-sort @save="updataGroup" :item="popup.selData" v-model:show="popup.sort.show"></edit-sort>
<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>
</template>
<script setup>
import {
reactive,
ref,
watch
} from 'vue';
import {
onShow
} from '@dcloudio/uni-app'
import go from '@/commons/utils/go.js';
import myCategory from './components/category.vue'
import infoBox from "@/commons/utils/infoBox.js"
import editSort from './components/edit-sort.vue';
import editName from './components/edit-name.vue';
import editTime from './components/edit-time.vue';
import {
tbProductGroupGet,
tbProductGroupDelete,
tbProductGroupPut,
upGroupSort,
tbProductGroupPost
} from '@/http/yskApi/shop.js'
const $productCategory = {
add: tbProductGroupPost,
del: tbProductGroupDelete,
update: tbProductGroupPut,
get: tbProductGroupGet
}
const actions = reactive({
list: [{
name: '排序',
color: '#333',
fontSize: '16'
}, {
name: '管理商品',
color: '#333',
fontSize: '16'
},
{
name: '售卖时间',
color: '#333',
fontSize: '16'
}
],
show: false,
})
function actionSelect(e) {
console.log(e);
if (e.name == '排序') {
return popupShow(actions.selIndex, 'sort', true)
}
if (e.name == '管理商品') {
const {id,isShow,name,sort}=actions.selData
return go.to('PAGES_GOODS_GROUP_EDIT_GOODS', {
id,isShow,name,sort
})
}
if (e.name == '售卖时间') {
return popupShow(actions.selIndex, 'time', true)
}
}
function actionsHide() {
actions.show = false
}
function actionsShow(e) {
console.log(e);
actions.selData = pageData.list[e]
actions.selIndex = e
actions.show = true
}
const popup = reactive({
selIndex: -1,
selData: {
sort: ''
},
sort: {
show: false
},
name:{
show: false
},
time:{
show: false
}
})
function popupShow(e, key, show) {
popup.selData = pageData.list[e]
popup.selIndex = e
popup[key].show = show
}
async function updataGroup(e) {
console.log(e);
const res = await $productCategory.update(e)
popup.sort.show = false;
popup.name.show = false;
popup.time.show = false;
pageData.list[popup.selIndex] = e
infoBox.showToast('更新成功')
}
const tabsList = ['简洁', '详情']
const statesTabsList = ['在售中', '已下架']
const states1TabsList = ['全部', '已售罄']
const control = ref(null)
const delModel = ref(null)
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
}
]
})
const pageData = reactive({
stateCurrent: 0,
stateCurrent1: 0,
componentBottom: 264,
search: {
value: '',
placeholder: '输入搜索的商品'
},
showGoodsDetail: false,
query: {
page: 0,
size: 10,
sort: 'id',
shopId: uni.getStorageSync('shopId')
},
totalElements: 0,
list: [],
selCategory: ''
})
async function init() {
const res = await $productCategory.get(pageData.query)
pageData.list = res.content
pageData.totalElements = res.totalElements
}
onShow(() => {
init()
})
function toAddCategory() {
go.to('PAGES_GOODS_GROUP_EDIT', {
type: 'add'
})
}
function goodsSortModelCancel() {
console.log('goodsSortModelCancel');
goodsSortModel.value.close()
}
async function goodsSortModelSave() {
console.log('goodsSortModelSave');
const res = await $productCategory.update({
...pageData.selCategory,
sort: sort.value
})
infoBox.showToast('修改成功')
goodsSortModelCancel()
init()
}
async function isSHowChange(data) {
const res = await $productCategory.update({
...data
})
infoBox.showToast('修改成功')
// init()
}
function categoryUseTypeClick(index) {
goodsTypeModelData.index = index
// goodsTypeModelData.useTypes=pageData.list[index].useTypes
const cateItem = pageData.list[index]
console.log(cateItem);
goodsTypeModelData.selCategory = cateItem
goodsTypeModelData.title = cateItem.name
goodsTypeModel.value.open()
}
//点击修改按钮弹出修改商品弹窗
function goodsChangeClick(index) {
console.log(index);
const goods = pageData.list[index]
sort.value = goods.sort
pageData.selCategory = goods
goodsSortModel.value.open()
}
function statesTableClick(index) {
pageData.stateCurrent = index
}
function states1TableClick(index) {
pageData.stateCurrent1 = index
}
let test = ref(false)
function tabsChange(i) {
console.log(i);
pageData.showGoodsDetail = i ? true : false
}
//改变商品的选中状态
function changeGoodsChecked(checked, index) {
if (index !== undefined) {
pageData.list[index].checked = checked
} else {
pageData.list.map(v => {
v.checked = checked
})
}
control.value.setisSelectAll(isAllChecked() ? true : false)
}
// 获取已经选中的商品
function getChechkedlist() {
return pageData.list.filter(v => v.checked)
}
//是否全部选中
function isAllChecked() {
return getChechkedlist().length === pageData.list.length
}
// 是否有商品选中
function isHasChekdGoods() {
return getChechkedlist().length ? true : false
}
function searchFunc() {
console.log('searchFunc');
}
let showChecked = ref(false)
//商品start
function goodsRadioClick(index) {
var checked = !pageData.list[index].checked
changeGoodsChecked(checked, index)
}
//下架
function offShelf() {
const hasCheckedArr = getChechkedlist()
const hasChecked = isHasChekdGoods()
if (!hasChecked) {
return infoBox.showToast('您还没有选中商品!')
}
model.value.open()
}
let nowCateIndex = null
function categoryDel(index) {
// nowCateIndex=index
// delModel.value.open()
uni.showModal({
title: '提示',
content: '请确保此分类下没有任何商品确认删除?',
success: res => {
if (res.confirm) {
const islast = pageData.list.length === 1
$productCategory.del([pageData.list[index].id]).then(res => {
infoBox.showToast('删除成功')
if(islast&&pageData.query.page>=1){
pageData.query.page-=1
}
// if(islast&&pageData.query.page>=1){
// pageData.query.page--
// }
init()
})
}
},
fail: () => {},
complete: () => {}
});
}
//删除分类确认
function delModelConfirm() {
console.log('confirm');
pageData.list.splice(nowCateIndex, 1)
delModel.value.close()
}
//商品end
//控制条
function controlChange(bol) {
console.log(bol);
showChecked.value = bol
}
// 全选
function allCheckedChange(checked) {
changeGoodsChecked(checked)
}
// 页数改变事件
function pageChange(page) {
pageData.query.page = page - 1
init()
}
//分类
const category = ref(null)
function toggleCategory() {
category.value.toggle()
}
function cateClick(cate) {
console.log(cate);
}
</script>
<style scoped>
page {
background: #F9F9F9;
}
</style>
<style lang="scss" scoped>
.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;
align-items: center;
height: 64rpx;
image {
padding: 22rpx;
width: 26rpx;
height: 26rpx;
}
input {
flex: 1;
font-size: 27rpx;
}
::v-deep uni-button {
font-size: 28rpx;
color: $my-main-color;
background: rgba(255, 255, 255, 1);
}
::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-placeholder {
font-size: 27rpx;
}
.uni-icons {
color: rgba(230, 230, 230, 1) !important;
}
}
}
}
}
.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;
}
.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>