同步代码

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,8 @@
<template>
</template>
<script>
</script>
<style>
</style>

View File

@@ -0,0 +1,565 @@
<template>
<view class="page">
<view class="box">
<view>
<uni-forms :model="category" :rules="rules" err-show-type="toast" validateTrigger="blur" ref="form"
:border="true" label-position="top" label-width="350">
<view class="block">
<view class="border-top-0">
<uni-forms-item ref="fileItem" label="图标">
<my-upload-file ref="refFile" :images="category.images"></my-upload-file>
</uni-forms-item>
</view>
<view class="">
<uni-forms-item label="分类名称" required name="categoryName">
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
v-model="category.categoryName" placeholder="输入分类名称" />
</uni-forms-item>
</view>
<template v-if="option.type==='edit'">
<uni-forms-item label="排序" required name="sort">
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
v-model="category.sort" type="number" placeholder="排序越小越靠前" />
</uni-forms-item>
</template>
<uni-forms-item label="" name="categoryName">
<view class="u-flex u-row-between u-col-center">
<view class="label-title">开关</view>
<view class="u-flex">
<my-switch v-model="category.required"></my-switch>
</view>
</view>
</uni-forms-item>
<!-- <uni-forms-item>
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">必选分类</view>
<view class="u-flex">
<my-switch v-model="category.required"></my-switch>
</view>
</view>
</template>
<view class="u-m-t-20">
<uni-easyinput :disabled="!category.required" :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="category.requiredNumber"
:placeholder="category.required?'输入必选商品数量':'开启后必选一个以上商品才能下单'" />
</view>
</uni-forms-item> -->
<!-- <uni-forms-item @tap="toTimer(category.timers,-1)">
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">定时上下架</view>
<view class="u-flex">
<uni-icons type="right"></uni-icons>
</view>
</view>
</template>
<view class="u-m-t-20">
<template v-if=" category.timers.length">
<view class="u-m-b-20" v-for="(item,index) in category.timers" :key="index">
{{returnTimers(item)}}
</view>
</template>
<template v-else>
<view></view>
</template>
</view>
</uni-forms-item> -->
</view>
<view class="block" v-for="(item,index) in category.childrens" :key="index">
<view class="border-top-0">
<uni-forms-item label="子分类名称" required name="categoryName">
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
v-model="item.categoryName" placeholder="输入子分类名称" />
</uni-forms-item>
</view>
<template v-if="option.type==='edit'">
<uni-forms-item label="排序" required name="sort">
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
v-model="item.sort" type="number" placeholder="排序越小越靠前" />
</uni-forms-item>
</template>
<uni-forms-item>
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">必选分类</view>
<view class="u-flex">
<my-switch v-model="item.required"></my-switch>
</view>
</view>
</template>
<view class="u-m-t-20">
<uni-easyinput :disabled="!item.required" :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="item.requiredNumber"
:placeholder="item.required?'输入必选商品数量':'开启后必选一个以上商品才能下单'" />
</view>
</uni-forms-item>
<uni-forms-item @tap="toTimer(item.timers,index)">
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">定时上下架</view>
<view class="u-flex">
<uni-icons type="right"></uni-icons>
</view>
</view>
</template>
<view class="u-m-t-20">
<template v-if="item.timers.length">
<view class="u-m-b-20" v-for="(item,index) in item.timers" :key="index">
{{returnTimers(item)}}
</view>
</template>
<template v-else>
<view></view>
</template>
</view>
</uni-forms-item>
</view>
</uni-forms>
</view>
<view class="u-flex block u-p-l-20 u-p-r-20 u-p-t-28 u-p-b-28" @click="addcategoryChildren">
<view class="icon icon-add u-m-r-22 ">
</view>
<view class="color-main">添加子分类</view>
</view>
<view class="save-btn-box">
<button class="save-btn" hover-class="btn-hover-class" @click="save">保存</button>
</view>
</view>
<view class="bottom" ref="bottom"></view>
</view>
</template>
<script setup>
import tColorPicker from '@/components/t-color-picker/t-color-picker'
import go from '@/commons/utils/go.js';
import infoBox from '@/commons/utils/infoBox.js';
import mySwitch from '@/components/my-components/my-switch.vue'
import myUploadFile from '@/components/my-components/my-upload-file'
import {
onLoad,
onReady
} from '@dcloudio/uni-app';
import {
onMounted,
reactive,
nextTick,
ref,
onBeforeMount
} from 'vue';
// 表单样式
const placeholderStyle = ref('font-size:28rpx;')
//表单边框
const inputBorder = ref(false)
const form = ref(null)
const bottom = ref(null)
//表单验证
const rules = {
categoryName: {
rules: [{
required: true,
errorMessage: '输入分类名称'
}]
},
sort: {
rules: [{
required: true,
errorMessage: '输入排序'
}]
}
}
function toTimer(timer, index) {
console.log(timer);
uni.setStorageSync('timer', timer.map(v => {
return {
...v,
cycleChecked: v.cycleChecked.map(v => v.value)
}
}))
go.to('PAGES_CATEGORY_TIMER', {
index: index
})
}
function returnTimers(timers) {
const {
listingTime,
offShelf,
cycleChecked
} = timers
let len = cycleChecked.length
if (len === 7) {
return `每天 ${listingTime.value} - ${offShelf.value}`
}
let result = cycleChecked.reduce((prve, cur) => {
return prve + cur.text.replace('星期', '周')
}, '')
return `${result} ${listingTime.value} - ${offShelf.value}`
}
//图片上传
function FileUploadprogress() {
}
function FileUploadsuccess() {
}
function FileUploadail() {
}
function FileUploadselect(e) {
// TEST
// FormData.images.push(e)
}
function returnOptionsBasicData() {
return {
...categoryOptionsBasicData
}
}
// 构造分类的基础数据
const categoryBasicData = {
categoryName: '',
sort: 0,
required: false,
requiredNumber: '',
timers: []
}
function onFieldChange(e) {
console.log(e);
}
// 分类列表
const category = reactive({
...categoryBasicData,
childrens: []
})
//添加子分类
function addcategoryChildren() {
category.childrens.push({
...categoryBasicData
})
scrollPageBottom()
}
//页面滚动到最底部
function scrollPageBottom() {
nextTick(() => {
uni.pageScrollTo({
duration: 100, // 过渡时间
scrollTop: 100000, // 滚动的实际距离
})
})
}
//设置表单验证规则
function setFormRules() {
form.value.setRules(rules)
}
const formRefs = ref([]);
//绑定表单元素
function setFormRef(index) {
formRefs.value[index] = null;
return (el) => {
if (el) {
formRefs.value[index] = el;
}
};
}
// 绑定option input元素
const refFormInput = ref([])
function setFormInputRef(index, index1) {
const newIndex = index * 10000 + index1
return (el) => {
if (el) {
if (!refFormInput.value[newIndex]) {
refFormInput.value[newIndex] = el;
}
}
}
}
// 当表单内容输入变化根据配置的rules进行验证
function inpuChange(index, index1) {
const newIndex = index * 10000 + index1
console.log(refFormInput.value[newIndex]);
refFormInput.value[newIndex].onFieldChange()
}
function triggerEvent(emitName, data) {
if (emitName) {
uni.$emit(emitName, data)
}
}
const option = reactive({
type: ''
})
function isEmpty(obj) {
return obj && JSON.stringify(obj) !== '{}'
}
/**
* 监听定时器保存,拿到数据
* @param {Boolean} open //控制开启或关闭监听
*/
function watchTimerSave(open = true) {
if (open) {
uni.$on('timerSave', function(res) {
const {
index,
data
} = res
console.log('timerSave get');
console.log(res);
if (index == -1) {
category.timers = data
} else {
category.childrens[index].timers = data
}
})
} else {
uni.$off('timerSave', function(data) {
console.log('timerSave remove');
})
}
}
watchTimerSave()
onLoad(params => {
// const arr = uni.getStorageSync('guige')
// if (arr.length) {
// category.list = arr
// console.log(arr);
// }
if (isEmpty(params)) {
option.type = params.type ? params.type : 'add'
}
console.log(option.type);
uni.setNavigationBarTitle({
title: option.type === 'add' ? '添加分类' : '编辑分类'
})
})
function emitcategorySave() {
// emitcategorySave 触发规格保存事件将数据给到添加商品页面
// guigeEdit 触发规格保存事件将数据给到添加规格页面
uni.removeStorageSync('guige')
triggerEvent(emitName, category.list)
}
function returnValidateResult(obj) {
const validateFuncObj = {
categoryName: (value) => {
return {
pass:value.length >= 1,
errMeessage:'请输入分类名称'
}
},
sort: (value) => {
return {
pass:value!=='',
errMeessage:'请输入排序'
}
}
}
function validateFunc(key, value) {
if (validateFuncObj.hasOwnProperty(key)) {
const func = validateFuncObj[key]
return func(value)
}
return {pass:true}
}
let resultArr = []
for (let key in obj) {
resultArr.push(validateFunc(key, category[key]))
}
resultArr=resultArr.filter(v => !v.pass)
return resultArr
}
async function save() {
let isAllPassForm = 0
const formRules = {}
const result=[]
result.push(...returnValidateResult(category))
for(let obj of category.childrens){
const res = returnValidateResult(obj)
result.push(...res)
}
if(result.length){
return infoBox.showToast(result[0].errMeessage)
}
go.back()
// const res = await form.value.validate().then(res => {
// go.back()
// })
}
</script>
<style scoped>
page {
background: #F9F9F9;
}
</style>
<style lang="scss" scoped>
$icon-size: 34rpx;
$icon-line-width: 20rpx;
$icon-line-height: 4rpx;
.page {
background: #F9F9F9;
padding: 30rpx;
padding-bottom: 200rpx;
}
.my-switch {
transform: scale(0.7);
}
::v-deep .uni-forms-item__error {
display: none !important;
}
::v-deep .option .uni-forms-item {
padding: 0;
min-height: inherit;
background-color: transparent;
border-top: none;
}
.icon {
width: $icon-size;
height: $icon-size;
position: relative;
border-radius: 50%;
&:before,
&::after {
position: absolute;
display: block;
content: '';
background-color: #fff;
}
}
.icon-add {
background-color: $my-main-color;
&::before {
width: $icon-line-height;
height: $icon-line-width;
top: calc(($icon-size /2) - ($icon-line-width / 2));
left: calc(($icon-size /2) - ($icon-line-height / 2));
}
&::after {
width: $icon-line-width;
height: 4rpx;
top: calc(($icon-size /2) - ($icon-line-height / 2));
left: calc(($icon-size /2) - ($icon-line-width / 2));
}
}
.icon-reduce {
background-color: $my-red-color;
&::after {
width: $icon-line-width;
height: $icon-line-height;
top: calc(($icon-size /2) - ($icon-line-height / 2));
left: calc(($icon-size /2) - ($icon-line-width / 2));
}
}
.label-title {
font-size: 28rpx;
font-weight: bold;
font-family: Source Han Sans CN, Source Han Sans CN;
}
.lh40 {
line-height: 40rpx;
}
.box {
font-size: 28rpx;
.block {
background: #FFFFFF;
border-radius: 18rpx 18rpx 18rpx 18rpx;
padding: 12rpx 24rpx;
margin-bottom: 32rpx;
}
}
.save-btn-box {
position: fixed;
left: 30rpx;
right: 30rpx;
bottom: 60rpx;
}
::v-deep.uni-forms-item {
align-items: inherit;
}
::v-deep .uni-forms-item .uni-forms-item__label {
text-indent: 0;
font-size: 28rpx !important;
font-weight: bold;
color: #333;
}
::v-deep .border-top-0 .uni-forms-item.is-direction-top {
border-color: transparent !important;
}
.save-btn {
background-color: $my-main-color;
color: #fff;
border-radius: 12rpx;
font-size: 28rpx;
}
.btn-hover-class {
opacity: .6;
}
.zuofa {
padding: 28rpx 0;
background: #F9F9F9;
padding-left: 42rpx;
border-radius: 14rpx 14rpx 14rpx 14rpx;
}
::v-deep .uni-input-placeholder {
font-size: 28rpx;
}
.option {
padding: 26rpx 30rpx 24rpx 24rpx;
background: #F9F9F9;
}
.option-item {
margin-bottom: 34rpx;
}
</style>

View File

@@ -0,0 +1,865 @@
<template>
<view class="page min-page">
<view class="box">
<view>
<uni-forms :model="category" :rules="rules" err-show-type="toast" ref="form" :border="true"
label-position="top" label-width="350">
<view class="block">
<view class="border-top-0">
<uni-forms-item label="图标">
<my-upload-file ref="refFile" :limit="1" @change="onfileChange($event,category,'pic')"
:images="category.pic"></my-upload-file>
</uni-forms-item>
</view>
<view class="">
<uni-forms-item label="分类名称" required name="name">
<uni-easyinput padding-none :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="category.name" placeholder="输入分类名称" />
</uni-forms-item>
</view>
<template v-if="option.type==='edit'">
<uni-forms-item label="排序" required name="sort">
<uni-easyinput padding-none :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="category.sort" type="number"
placeholder="排序越小越靠前" />
</uni-forms-item>
</template>
<uni-forms-item label="">
<view class="u-flex u-row-between u-col-center">
<view class="label-title">开关</view>
<view class="u-flex">
<my-switch v-model="category.isShow"></my-switch>
</view>
</view>
</uni-forms-item>
<!-- <uni-forms-item>
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">必选分类</view>
<view class="u-flex">
<my-switch v-model="category.required"></my-switch>
</view>
</view>
</template>
<view class="u-m-t-20">
<uni-easyinput :disabled="!category.required" :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="category.requiredNumber"
:placeholder="category.required?'输入必选商品数量':'开启后必选一个以上商品才能下单'" />
</view>
</uni-forms-item> -->
<!-- <uni-forms-item @tap="toTimer(category.timers,-1)">
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">定时上下架</view>
<view class="u-flex">
<uni-icons type="right"></uni-icons>
</view>
</view>
</template>
<view class="u-m-t-20">
<template v-if=" category.timers.length">
<view class="u-m-b-20" v-for="(item,index) in category.timers" :key="index">
{{returnTimers(item)}}
</view>
</template>
<template v-else>
<view></view>
</template>
</view>
</uni-forms-item> -->
</view>
<!-- <template v-if="option.type==='edit'"> -->
<template v-if="false">
<view class="font-bold u-m-t-32 u-m-b-32">子分类</view>
<view class="block u-p-t-32 u-p-b-32" v-if=" category.childrenList.length">
<view class="u-flex u-text-center u-font-24">
<view class="u-flex-1 ">名称</view>
<view class="u-flex-1">图片</view>
<view class="u-flex-1">状态</view>
<view class="u-flex-1">颜色</view>
<view class="u-flex-1">操作</view>
</view>
<view class="bg-gray u-p-t-20 u-m-t-24">
<view class="u-flex u-p-t-10 u-p-b-10" v-for="(item,index) in category.childrenList"
:key="index">
<view class="u-flex-1 u-flex u-p-l-24 ">
{{item.name}}
</view>
<view class="u-flex-1 u-flex u-row-center">
<image class="category-icon" :src="item.pic" mode=""></image>
</view>
<view class="u-flex-1 u-flex u-row-center">
<my-switch @change="" v-model="item.isShow"></my-switch>
</view>
<view class="u-flex-1 u-flex u-row-center">
{{item.style}}
</view>
<view class="u-flex-1 u-flex u-row-right u-p-r-24 u-flex ">
<my-button @tap="moreShow(item,index)" :width="100" :height="40">
<view class="u-font-24 no-wrap">更多</view>
</my-button>
</view>
</view>
</view>
<!-- <view class="border-top-0">
<uni-forms-item label="图标">
<my-upload-file :limit="1" @change="onfileChange($event,item,pic)" :images="item.pic"></my-upload-file>
</uni-forms-item>
</view>
<view class="border-top-0">
<uni-forms-item label="子分类名称" required name="name">
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
v-model="item.name" placeholder="输入子分类名称" />
</uni-forms-item>
</view>
<template v-if="option.type==='edit'">
<uni-forms-item label="排序" required name="sort">
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
v-model="item.sort" type="number" placeholder="排序越小越靠前" />
</uni-forms-item>
</template>
<uni-forms-item label="">
<view class="u-flex u-row-between u-col-center">
<view class="label-title">开关</view>
<view class="u-flex">
<my-switch v-model="item.isShow"></my-switch>
</view>
</view>
</uni-forms-item> -->
<!-- <uni-forms-item>
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">必选分类</view>
<view class="u-flex">
<my-switch v-model="item.required"></my-switch>
</view>
</view>
</template>
<view class="u-m-t-20">
<uni-easyinput :disabled="!item.required" :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="item.requiredNumber"
:placeholder="item.required?'输入必选商品数量':'开启后必选一个以上商品才能下单'" />
</view>
</uni-forms-item>
<uni-forms-item @tap="toTimer(item.timers,index)">
<template #label>
<view class="u-flex u-row-between u-col-center">
<view class="label-title">定时上下架</view>
<view class="u-flex">
<uni-icons type="right"></uni-icons>
</view>
</view>
</template>
<view class="u-m-t-20">
<template v-if="item.timers.length">
<view class="u-m-b-20" v-for="(item,index) in item.timers" :key="index">
{{returnTimers(item)}}
</view>
</template>
<template v-else>
<view></view>
</template>
</view>
</uni-forms-item> -->
</view>
</template>
</uni-forms>
</view>
<!-- <template v-if="option.type==='edit'">
<view class="u-flex block u-p-l-20 u-p-r-20 u-p-t-28 u-p-b-28" @click="addcategoryChildren">
<view class="icon icon-add u-m-r-22 ">
</view>
<view class="color-main">添加子分类</view>
</view>
</template> -->
<view class="save-btn-box">
<button class="save-btn" hover-class="btn-hover-class" @click="save">保存</button>
</view>
</view>
<view class="bottom" ref="bottom"></view>
<!-- 更多操作 -->
<my-action-sheet @itemClick="actionSheetClick" ref="refMoreSheet" :list="actionSheet.list"></my-action-sheet>
<!-- 添加/编辑子分类 -->
<my-model ref="refAddChilCate" :title="refAddChilCateTitle">
<template #desc>
<view class="u-p-l-32 u-m-t-8 u-p-r-32 u-text-left">
<uni-forms :model="categoryChild" :rules="rules" err-show-type="toast" :border="true"
label-position="top" label-width="350">
<view class="border-top-0">
<uni-forms-item label="图标">
<my-upload-file ref="refFile" :limit="1"
@change="onfileChange($event,categoryChild,'pic')"
:images="categoryChild.pic"></my-upload-file>
</uni-forms-item>
</view>
<view class="">
<uni-forms-item label="分类名称" required name="name">
<uni-easyinput padding-none :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="categoryChild.name" placeholder="输入分类名称" />
</uni-forms-item>
</view>
<template v-if="option.type==='edit'">
<uni-forms-item label="排序" required name="sort">
<uni-easyinput padding-none :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="categoryChild.sort" type="number"
placeholder="排序越小越靠前" />
</uni-forms-item>
</template>
<uni-forms-item label="">
<view class="u-flex u-row-between u-col-center">
<view class="label-title">开关</view>
<view class="u-flex">
<my-switch v-model="categoryChild.isShow"></my-switch>
</view>
</view>
</uni-forms-item>
</uni-forms>
</view>
</template>
<template #btn>
<view class="u-flex u-p-30">
<view class="u-flex-1 u-p-r-16">
<my-button shape="circle" type="default" @tap="refAddChilCateClose">取消</my-button>
</view>
<view class="u-flex-1 u-p-l-16">
<my-button shape="circle" @tap="refAddChilCateConfirm">确认</my-button>
</view>
</view>
</template>
</my-model>
<up-modal title="提示" content="确认删除该分类吗?" :show="modal.del" showCancelButton closeOnClickOverlay
@confirm="confirmModelConfirm" @cancel="setModalShow('del',false)" @close="setModalShow('del',false)"
width="300px"></up-modal>
</view>
</template>
<script setup>
import tColorPicker from '@/components/t-color-picker/t-color-picker'
import go from '@/commons/utils/go.js';
import infoBox from '@/commons/utils/infoBox.js';
import mySwitch from '@/components/my-components/my-switch'
import myButton from '@/components/my-components/my-button'
import myActionSheet from '@/components/my-components/my-action-sheet';
import myUploadFile from '@/components/my-components/my-upload-file'
import {
$productCategory
} from '@/http/yskApi/goods.js'
import {
onLoad,
onReady
} from '@dcloudio/uni-app';
import {
onMounted,
reactive,
nextTick,
ref,
onBeforeMount,
watch
} from 'vue';
const modal = reactive({
key: '',
del: false
})
function confirmModelConfirm() {
if (modal.key == 'del') {
$productCategory.del([selItem.data.id]).then(res => {
category.childrenList.splice(selItem.index, 1)
infoBox.showToast('删除成功')
uni.setStorageSync('cateItem', category)
})
modal.del=false
return
}
}
function setModalShow(key = 'show', show = true) {
modal.key = key
modal[key] = show
console.log(modal);
}
const refAddChilCate = ref(null)
const refAddChilCateTitle = ref('添加子分类')
function refAddChilCateClose() {
refAddChilCate.value.close()
categoryChild.value = {
...categoryBasicData
}
}
async function refAddChilCateConfirm() {
let isAllPassForm = 0
const formRules = {}
const result = []
console.log(categoryChild.value);
console.log(returnValidateResult(categoryChild.value));
result.push(...returnValidateResult(categoryChild.value))
// for (let obj of category.childrenList) {
// const res = returnValidateResult(obj)
// result.push(...res)
// }
if (result.length) {
return infoBox.showToast(result[0].errMeessage)
}
let res = ''
if (refAddChilCateTitle.value === '编辑子分类') {
res = await $productCategory.update({
...categoryChild.value,
pid: category.id
})
categoryChild[selItem.index] = res
} else {
res = await $productCategory.add({
...categoryChild.value,
pid: category.id
})
category.childrenList.push(res)
}
uni.setStorageSync('cateItem', category)
infoBox.showToast(refAddChilCateTitle.value === '编辑子分类' ? '修改成功' : '添加成功')
refAddChilCateClose()
}
let refMoreSheet = ref(null)
let selItem = {
data: '',
index: ''
}
const actionSheet = reactive({
list: ['编辑', '删除']
})
function moreShow(item, index) {
refMoreSheet.value.open()
selItem.data = item
selItem.index = index
}
function actionSheetClick(index) {
console.log(index);
if (index === 0) {
refAddChilCateTitle.value = '编辑子分类'
categoryChild.value = selItem.data
refAddChilCate.value.open()
return
}
if (index === 1) {
setModalShow('del', true)
return
// return uni.showModal({
// title: '提示',
// content: '确认删除该分类吗?',
// success(res) {
// if (res.confirm) {
// $productCategory.del([selItem.data.id]).then(res => {
// category.childrenList.splice(selItem.index, 1)
// infoBox.showToast('删除成功')
// uni.setStorageSync('cateItem', category)
// })
// }
// }
// })
}
}
//文件上传
const refFile = ref(null)
// 表单样式
const placeholderStyle = ref('font-size:28rpx;')
//表单边框
const inputBorder = ref(false)
const form = ref(null)
const bottom = ref(null)
//表单验证
const rules = {
name: {
rules: [{
required: true,
errorMessage: '输入分类名称'
}]
},
sort: {
rules: [{
required: true,
errorMessage: '输入排序'
}]
}
}
const refFiles = ref([])
function setRefFile(index) {
refFiles.value[index] = null;
return (el) => {
if (el) {
refFiles.value[index] = el;
}
};
}
function toTimer(timer, index) {
console.log(timer);
uni.setStorageSync('timer', timer.map(v => {
return {
...v,
cycleChecked: v.cycleChecked.map(v => v.value)
}
}))
go.to('PAGES_CATEGORY_TIMER', {
index: index
})
}
function returnTimers(timers) {
const {
listingTime,
offShelf,
cycleChecked
} = timers
let len = cycleChecked.length
if (len === 7) {
return `每天 ${listingTime.value} - ${offShelf.value}`
}
let result = cycleChecked.reduce((prve, cur) => {
return prve + cur.text.replace('星期', '周')
}, '')
return `${result} ${listingTime.value} - ${offShelf.value}`
}
//图片上传
function FileUploadprogress() {
}
function FileUploadsuccess() {
}
function FileUploadail() {
}
function FileUploadselect(e) {
// TEST
// FormData.images.push(e)
}
function returnOptionsBasicData() {
return {
...categoryOptionsBasicData
}
}
// 构造分类的基础数据
const categoryBasicData = {
name: '',
sort: 0,
pic: '',
style: '',
isShow: 1,
// requiredNumber: '',
// timers: []
}
const categoryChild = ref({
...categoryBasicData
})
function onFieldChange(e) {
console.log(e);
}
// 分类列表
const category = reactive({
...categoryBasicData,
childrenList: []
})
//添加子分类
function addcategoryChildren() {
refAddChilCate.value.open()
// category.childrenList.push({
// ...categoryBasicData
// })
// scrollPageBottom()
}
//页面滚动到最底部
function scrollPageBottom() {
nextTick(() => {
uni.pageScrollTo({
duration: 100, // 过渡时间
scrollTop: 100000, // 滚动的实际距离
})
})
}
//设置表单验证规则
function setFormRules() {
form.value.setRules(rules)
}
const formRefs = ref([]);
//绑定表单元素
function setFormRef(index) {
formRefs.value[index] = null;
return (el) => {
if (el) {
formRefs.value[index] = el;
}
};
}
// 绑定option input元素
const refFormInput = ref([])
function setFormInputRef(index, index1) {
const newIndex = index * 10000 + index1
return (el) => {
if (el) {
if (!refFormInput.value[newIndex]) {
refFormInput.value[newIndex] = el;
}
}
}
}
// 当表单内容输入变化根据配置的rules进行验证
function inpuChange(index, index1) {
const newIndex = index * 10000 + index1
console.log(refFormInput.value[newIndex]);
refFormInput.value[newIndex].onFieldChange()
}
function triggerEvent(emitName, data) {
if (emitName) {
uni.$emit(emitName, data)
}
}
const option = reactive({
type: ''
})
function isNoEmpty(obj) {
return obj && JSON.stringify(obj) !== '{}'
}
/**
* 监听定时器保存,拿到数据
* @param {Boolean} open //控制开启或关闭监听
*/
function watchTimerSave(open = true) {
if (open) {
uni.$on('timerSave', function(res) {
const {
index,
data
} = res
console.log('timerSave get');
console.log(res);
if (index == -1) {
category.timers = data
} else {
category.childrenList[index].timers = data
}
})
} else {
uni.$off('timerSave', function(data) {
console.log('timerSave remove');
})
}
}
watchTimerSave()
onLoad(params => {
let cateItem = uni.getStorageSync('cateItem')
if (isNoEmpty(params)) {
option.type = params.type
}
if (option.type === 'edit' && isNoEmpty(cateItem)) {
console.log(cateItem);
for (let i in cateItem) {
if (i.substring(0, 2) === 'is' && i.length > 2) {
cateItem[i] = cateItem[i] * 1
} else {
cateItem[i] = cateItem[i] === 'null' ? '' : cateItem[i]
}
}
Object.assign(category, cateItem)
}
console.log(category);
uni.setNavigationBarTitle({
title: option.type === 'add' ? '添加分类' : '编辑分类'
})
})
function emitcategorySave() {
// emitcategorySave 触发规格保存事件将数据给到添加商品页面
// guigeEdit 触发规格保存事件将数据给到添加规格页面
uni.removeStorageSync('guige')
triggerEvent(emitName, category.list)
}
function returnValidateResult(obj) {
const validateFuncObj = {
name: (value) => {
return {
pass: value.length >= 1,
errMeessage: '请输入分类名称'
}
},
sort: (value) => {
return {
pass: value !== '',
errMeessage: '请输入排序'
}
}
}
function validateFunc(key, value) {
if (validateFuncObj.hasOwnProperty(key)) {
const func = validateFuncObj[key]
return func(value)
}
return {
pass: true
}
}
let resultArr = []
for (let key in obj) {
resultArr.push(validateFunc(key, obj[key]))
}
resultArr = resultArr.filter(v => !v.pass)
return resultArr
}
let timer = null
function onfileChange(val, data, key) {
data[key] = val
}
async function save() {
let isAllPassForm = 0
const formRules = {}
const result = []
result.push(...returnValidateResult(category))
for (let obj of category.childrenList) {
const res = returnValidateResult(obj)
result.push(...res)
}
if (result.length) {
return infoBox.showToast(result[0].errMeessage)
}
if (option.type === 'edit') {
const res = await $productCategory.update({
...category,
childrenList: ''
})
} else {
const res = await $productCategory.add({
...category,
childrenList: ''
})
}
infoBox.showToast(option.type === 'edit' ? '修改成功' : '添加成功')
timer = setTimeout(() => {
clearTimeout(timer)
uni.$emit('update:pageCategoryIndex')
go.back()
}, 500);
// const res = await form.value.validate().then(res => {
// go.back()
// })
}
</script>
<style scoped>
page {
background: #F9F9F9;
}
</style>
<style lang="scss" scoped>
$icon-size: 34rpx;
$icon-line-width: 20rpx;
$icon-line-height: 4rpx;
@import '@/commons/style/reset-uni-form.scss';
::v-deep .uni-forms-item--border {
padding-top: 24rpx;
padding-bottom: 24rpx;
}
::v-deep .uni-forms-item.is-direction-top .uni-forms-item__label {
padding-bottom: 16rpx;
}
.category-icon {
width: 60rpx;
height: 60rpx;
}
.page {
background: #F9F9F9;
padding: 30rpx;
padding-bottom: 200rpx;
}
.my-switch {
transform: scale(0.7);
}
::v-deep .uni-forms-item__content {
min-height: inherit;
}
::v-deep .uni-forms-item__error {
display: none !important;
}
::v-deep .option .uni-forms-item {
padding: 0;
min-height: inherit;
background-color: transparent;
border-top: none;
}
.icon {
width: $icon-size;
height: $icon-size;
position: relative;
border-radius: 50%;
&:before,
&::after {
position: absolute;
display: block;
content: '';
background-color: #fff;
}
}
.icon-add {
background-color: $my-main-color;
&::before {
width: $icon-line-height;
height: $icon-line-width;
top: calc(($icon-size /2) - ($icon-line-width / 2));
left: calc(($icon-size /2) - ($icon-line-height / 2));
}
&::after {
width: $icon-line-width;
height: 4rpx;
top: calc(($icon-size /2) - ($icon-line-height / 2));
left: calc(($icon-size /2) - ($icon-line-width / 2));
}
}
.icon-reduce {
background-color: $my-red-color;
&::after {
width: $icon-line-width;
height: $icon-line-height;
top: calc(($icon-size /2) - ($icon-line-height / 2));
left: calc(($icon-size /2) - ($icon-line-width / 2));
}
}
.label-title {
font-size: 28rpx;
font-weight: bold;
font-family: Source Han Sans CN, Source Han Sans CN;
}
.lh40 {
line-height: 40rpx;
}
.box {
font-size: 28rpx;
.block {
background: #FFFFFF;
border-radius: 18rpx;
padding: 8rpx 24rpx;
margin-bottom: 32rpx;
}
}
.save-btn-box {
position: fixed;
left: 30rpx;
right: 30rpx;
bottom: 60rpx;
}
::v-deep.uni-forms-item {
align-items: inherit;
}
::v-deep .uni-forms-item .uni-forms-item__label {
text-indent: 0;
font-size: 28rpx !important;
font-weight: bold;
color: #333;
}
::v-deep .border-top-0 .uni-forms-item.is-direction-top {
border-color: transparent !important;
}
.save-btn {
background-color: $my-main-color;
color: #fff;
border-radius: 12rpx;
font-size: 28rpx;
border-radius: 100rpx;
}
.btn-hover-class {
opacity: .6;
}
.zuofa {
padding: 28rpx 0;
background: #F9F9F9;
padding-left: 42rpx;
border-radius: 14rpx 14rpx 14rpx 14rpx;
}
::v-deep .uni-input-placeholder {
font-size: 28rpx;
}
.option {
padding: 26rpx 30rpx 24rpx 24rpx;
background: #F9F9F9;
}
.option-item {
margin-bottom: 34rpx;
}
</style>

View File

@@ -0,0 +1,213 @@
<template>
<view class="u-p-30 min-page">
<view class="u-flex">
<view style="width: 210rpx;">
<my-button shape="circle" @click="addTimer">添加定时器</my-button>
</view>
</view>
<view class="list u-m-t-20" v-if="list.length">
<view class="block" v-for="(item,index) in list" :key="index">
<view class="u-flex u-row-between">
<view>定时器{{index+1}}</view>
<uni-icons @click="delTimer(index)" type="trash"></uni-icons>
</view>
<view class="u-flex u-m-t-20 u-row-between">
<view>周期</view>
<view @click="selectAllClick(index)">全选</view>
</view>
<view class="u-m-t-20">
<uni-data-checkbox multiple v-model="item.cycleChecked" :localdata="cycle"></uni-data-checkbox>
</view>
<view class="u-m-t-20">
<view class="u-flex">
<view>上架时间:</view>
<view class="u-flex-1 u-m-l-10">
<picker mode="multiSelector" @change="listingTimeChange($event,index)"
:value="item.listingTime.index" :range="times">
<view class="bg-gray u-p-l-20 u-p-t-6 u-p-b-6 u-p-r-20 ">
{{item.listingTime.value}}
</view>
</picker>
</view>
</view>
<view class="u-flex u-m-t-20">
<view>下架时间:</view>
<view class="u-flex-1 u-m-l-10">
<picker mode="multiSelector" @change="offShelfChange($event,index)"
:value="item.offShelf.index" :range="times">
<view class="bg-gray u-p-l-20 u-p-t-6 u-p-b-6 u-p-r-20 ">
{{item.offShelf.value}}
</view>
</picker>
</view>
</view>
</view>
</view>
</view>
<view class="u-flex u-row-center u-m-t-60">
<my-button width="580" shape="circle" @click="save">保存</my-button>
</view>
</view>
</template>
<script setup>
import {
onLoad,
onReady
} from '@dcloudio/uni-app';
import {
ref
} from 'vue';
import go from '@/commons/utils/go.js';
import myButton from '@/components/my-components/my-button.vue'
//返回一天的时间 时分格式
function returnDayTime() {
return new Array(2).fill(1).map((v, index) => {
if (index === 0) {
return new Array(24).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
if (index === 1) {
return new Array(60).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
})
}
const times = ref(returnDayTime())
let defaultTimeIndex = ref(0)
function getTime(indexArr) {
const hour = times.value[0][indexArr[0]]
const month = times.value[1][indexArr[1]]
return `${hour}:${month}`
}
//获取$event.detail.value
function getEnentDetailValue(e) {
return e.detail.value
}
function setListTimeValue(index, key, time) {
list.value[index][key].value = time
}
function listingTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'listingTime', time)
}
function offShelfChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'offShelf', time)
}
const cycle = [{
value: 0,
text: '星期一'
},
{
value: 1,
text: '星期二'
},
{
value: 2,
text: '星期三'
},
{
value: 3,
text: '星期四'
},
{
value: 4,
text: '星期五'
},
{
value: 5,
text: '星期六'
},
{
value: 6,
text: '星期日'
}
]
const ListDataconstructor = {
cycleChecked: [0, 1, 2, 3, 4, 5, 6],
}
function returnBasicTimeConstructor() {
return {
listingTime: {
value: '09:00',
index: [9, 0]
},
offShelf: {
value: '18:00',
index: [18, 0]
}
}
}
const list = ref([returnBasicDataConstructor()])
function returnBasicDataConstructor() {
return {
...ListDataconstructor,
...returnBasicTimeConstructor()
}
}
function addTimer() {
list.value.push(returnBasicDataConstructor())
}
function delTimer(index) {
list.value.splice(index,1)
}
function selectAllClick(index){
list.value[index].cycleChecked=ListDataconstructor.cycleChecked
}
let index=null
// 触发定时器保存事件将数据给到添加商品页面
function emitTimerSave(){
uni.$emit('timerSave',{
data:list.value.map(v=>{
return {
...v,
cycleChecked:v.cycleChecked.map(index=>{
return {value:index,text:cycle[index].text}
})
}
}),
index:index
})
go.back()
}
function save(){
console.log(list.value);
emitTimerSave()
}
onLoad((opt)=>{
index=opt.index
const arr=uni.getStorageSync('timer')
if(arr.length){
list.value=arr
}
})
</script>
<style lang="scss">
.min-page {
background-color: #F9F9F9;
}
.block {
background: #FFFFFF;
border-radius: 18rpx 18rpx 18rpx 18rpx;
padding: 30rpx;
margin-bottom: 20rpx;
}
</style>

View File

@@ -0,0 +1,253 @@
<template>
<view class=" goods">
<view class=" u-flex">
<view v-if="showChecked">
<label class="radio">
<radio :color="ColorMain" style="transform: scale(0.7);" @click="radioClick"
:checked="data.checked" /><text></text>
</label>
</view>
<up-image width="126rpx" height="126rpx" :src="data.pic" :radius="6"></up-image>
<!-- <image mode="aspectFill" :src="data.pic" class="img"></image> -->
<view class=" u-p-l-16 u-flex u-p-r-16 u-flex-1 u-col-top">
<view class="u-flex-1">
<view class="color-333 font-bold">{{data.name}}</view>
<view class="color-999 u-m-t-20">
<text class="">排序:</text>
<text class="u-m-l-10">{{data.sort}}</text>
</view>
</view>
<view class="u-flex">
<text class="u-font-28 color-666" @click="changeClick">修改排序</text>
</view>
</view>
</view>
<view class="u-m-t-24 u-flex u-row-between">
<view>
<!-- <template v-if="data.childrenList.length">
<view class="u-flex color-999 u-flex u-col-center" @tap="useTypeClick">
<text class="u-font-24">{{computedUserType}} </text>
<view class="u-flex">
<uni-icons type="right" color="#999"></uni-icons>
</view>
</view>
</template> -->
<view class="u-flex">
<view class="u-m-r-18 color-999">是否启用</view>
<my-switch v-model="isShow" @change="isShowChange"></my-switch>
</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 class="u-flex no-wrap">
<view class="btn-default btn" @click="del">删除</view>
<view class="btn-primary btn u-m-l-38" @click="toEdit">编辑</view>
</view> -->
</view>
</view>
</template>
<script setup>
import {
computed,
ref,
watch,
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(['radioClick', 'changeClick', 'useTypeClick', 'del', 'isShowChange'])
const props = defineProps({
index: {
type: Number
},
data: {
type: Object,
default: () => {
return {
isShow: true
}
}
},
showChecked: {
type: Boolean,
default: false
}
})
let isShow = ref(props.data.isShow)
watch(() => props.data.isShow, (newval) => {
isShow.value = newval
})
function isShowChange() {
console.log(isShow.value);
emits('isShowChange', {
...props.data,
isShow: isShow.value
})
}
const computedUserType = computed(() => {
const len = props.data.useTypes.length
const openArr = props.data.useTypes.filter(v => v.isOpen)
if (openArr.length <= 0) {
return '全部隐藏'
}
if (openArr.length >= len) {
return '全部显示'
}
let openStr = openArr.reduce((prve, cur) => {
return prve + cur.name + '、'
}, '')
return '显示(' + openStr.slice(0, -1) + ')'
})
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)
}
//携带参数type edit跳转到商品添加页面编辑与添加同一页面根据type值来判断
function toEdit() {
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;
}
.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: 24rpx 28rpx 16rpx 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,414 @@
<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"
@changeClick="goodsChangeClick"
@radioClick="goodsRadioClick"
: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>
<!-- 分类修改排序弹窗 -->
<my-model ref="goodsSortModel" title="修改排序" @close="goodsSortModelClose">
<template #desc>
<view class="u-p-40 u-text-left">
<view>
<view class="">排序:</view>
<view class="u-m-t-24">
<uni-easyinput v-model="sort" placeholder="请输入排序"></uni-easyinput>
</view>
</view>
</view>
</template>
<template #btn>
<view class="stock-btns u-p-b-40">
<my-button shape="circle" @tap="goodsSortModelSave">确认修改</my-button>
<my-button shape="circle" type="default" @tap="goodsSortModelCancel">取消</my-button>
</view>
</template>
</my-model>
<!-- 分类修改排序弹窗 -->
<my-model mode="bottom" ref="goodsTypeModel" :title="goodsTypeModelData.title" >
<template #desc>
<view class="u-p-30 u-m-t-30">
<view class="u-flex u-m-b-20 u-row-between u-p-t-10 u-p-b-10" v-for="(item,index) in goodsTypeModelData.useTypes" :key="index">
<view class="font-bold color-000">{{item.name}}</view>
<my-switch v-model="item.isOpen"></my-switch>
</view>
</view>
</template>
<template #btn>
<view class="u-flex gap-20 u-p-30 u-p-b-40 ">
<view class="u-flex-1">
<my-button shape="circle" color="#000" type="default" @tap="hideAllUseTypes">一键隐藏</my-button>
</view>
<view class="u-flex-1">
<my-button shape="circle" @tap="showAllUseTypes">一键显示</my-button>
</view>
</view>
</template>
</my-model>
<view class="fixed-b">
<my-button :height="80" shape="circle" showShadow @tap="toAddCategory">新建分类</my-button>
</view>
</view>
</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 myPagination from '@/components/my-components/my-pagination.vue'
import myModel from "@/components/my-components/my-model.vue"
import myButton from "@/components/my-components/my-button.vue"
import mySwitch from "@/components/my-components/my-switch.vue"
import {$productCategory} from '@/http/yskApi/goods.js'
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({
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
},
totalElements:0,
list:[]
})
async function init() {
const res=await $productCategory.get(pageData.query)
pageData.list=res.content.map(v=>{
return {
...v,
isSellNone:false,
checked:false,
showDetail:false,
useTypes:[
{name:'堂食',isOpen:true},
{name:'自取',isOpen:true},
{name:'外卖',isOpen:true},
{name:'快递',isOpen:true}
]
}
})
pageData.totalElements=res.totalElements
}
onShow(()=>{
init()
})
function toAddCategory(){
go.to('PAGES_CATEGORY_EDIT',{type:'add'})
}
function hideAllUseTypes(){
goodsTypeModelData.useTypes.map(v=>{
v.isOpen=false
})
pageData.list[goodsTypeModelData.index].useTypes.map(v=>{
v.isOpen=false
})
}
function showAllUseTypes(){
goodsTypeModelData.useTypes.map(v=>{
v.isOpen=true
})
pageData.list[goodsTypeModelData.index].useTypes.map(v=>{
v.isOpen=true
})
}
function goodsSortModelCancel(){
console.log('goodsSortModelCancel');
goodsSortModel.value.close()
}
function goodsSortModelSave(){
console.log('goodsSortModelSave');
// $productCategory.update()
}
function categoryUseTypeClick(index){
goodsTypeModelData.index=index
goodsTypeModelData.useTypes=pageData.list[index].useTypes
goodsTypeModel.value.open()
}
//点击修改按钮弹出修改商品弹窗
function goodsChangeClick(index){
console.log(index);
sort.value=pageData.list[index].sort
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()
}
//删除分类确认
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,479 @@
<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"
@changeClick="goodsChangeClick"
@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>
<!-- 分类修改排序弹窗 -->
<my-model ref="goodsSortModel" title="修改排序" @close="goodsSortModelClose">
<template #desc>
<view class="u-p-40 u-text-left">
<view>
<view class="">排序:</view>
<view class="u-m-t-24">
<uni-easyinput v-model="sort" placeholder="请输入排序"></uni-easyinput>
</view>
</view>
</view>
</template>
<template #btn>
<view class="stock-btns u-p-b-40">
<my-button shape="circle" @tap="goodsSortModelSave">确认修改</my-button>
<my-button shape="circle" bgColor="#fff" type="default" @tap="goodsSortModelCancel">取消</my-button>
</view>
</template>
</my-model>
<!-- 全部分类修改弹窗 -->
<my-model mode="bottom" ref="goodsTypeModel" :title="goodsTypeModelData.title" >
<template #desc>
<view class="u-p-30 u-m-t-30">
<view class="u-flex u-m-b-20 u-row-between u-p-t-10 u-p-b-10" v-for="(item,index) in goodsTypeModelData.selCategory.childrenList" :key="index">
<view class="font-bold color-000">{{item.name}}</view>
<my-switch v-model="item.isOpen"></my-switch>
</view>
</view>
</template>
<template #btn>
<view class="u-flex gap-20 u-p-30 u-p-b-40 ">
<view class="u-flex-1">
<my-button shape="circle" color="#000" type="default" @tap="hideAllUseTypes">一键隐藏</my-button>
</view>
<view class="u-flex-1">
<my-button shape="circle" @tap="showAllUseTypes">一键显示</my-button>
</view>
</view>
</template>
</my-model>
<!-- <my-model mode="bottom" ref="goodsTypeModel" :title="goodsTypeModelData.title" >
<template #desc>
<view class="u-p-30 u-m-t-30">
<view class="u-flex u-m-b-20 u-row-between u-p-t-10 u-p-b-10" v-for="(item,index) in goodsTypeModelData.useTypes" :key="index">
<view class="font-bold color-000">{{item.name}}</view>
<my-switch v-model="item.isOpen"></my-switch>
</view>
</view>
</template>
<template #btn>
<view class="u-flex gap-20 u-p-30 u-p-b-40 ">
<view class="u-flex-1">
<my-button shape="circle" color="#000" type="default" @tap="hideAllUseTypes">一键隐藏</my-button>
</view>
<view class="u-flex-1">
<my-button shape="circle" @tap="showAllUseTypes">一键显示</my-button>
</view>
</view>
</template>
</my-model> -->
<view class="fixed-b">
<my-button :height="80" shape="circle" showShadow @tap="toAddCategory">新建分类</my-button>
</view>
</view>
</template>
<script setup>
import {
reactive, ref, watch
} from 'vue';
import {onShow,onLoad} 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 {$productCategory} from '@/http/yskApi/goods.js'
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
},
totalElements:0,
list:[],
selCategory:''
})
async function init() {
const res=await $productCategory.get(pageData.query)
pageData.list=res.content.map(v=>{
return {
...v,
isSellNone:false,
checked:false,
showDetail:false,
useTypes:[
{name:'堂食',isOpen:true},
{name:'自取',isOpen:true},
{name:'外卖',isOpen:true},
{name:'快递',isOpen:true}
]
}
})
pageData.totalElements=res.totalElements
}
onLoad(()=>{
init()
})
function watchEvent(){
uni.$off('update:pageCategoryIndex')
uni.$on('update:pageCategoryIndex',(data)=>{
init()
})
}
onShow(()=>{
watchEvent()
})
function toAddCategory(){
go.to('PAGES_CATEGORY_EDIT',{type:'add'})
}
function hideAllUseTypes(){
goodsTypeModelData.useTypes.map(v=>{
v.isOpen=false
})
pageData.list[goodsTypeModelData.index].useTypes.map(v=>{
v.isOpen=false
})
}
function showAllUseTypes(){
goodsTypeModelData.useTypes.map(v=>{
v.isOpen=true
})
pageData.list[goodsTypeModelData.index].useTypes.map(v=>{
v.isOpen=true
})
}
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>