代码更新

This commit is contained in:
GaoHao
2025-02-26 19:46:20 +08:00
parent 7519ffced3
commit b4a0393d2d
413 changed files with 7483 additions and 60762 deletions

View File

@@ -3,33 +3,10 @@
</template>
<script setup>
import {
ref, warn, watch, watchEffect,
onMounted,reactive
} from 'vue';
import {$tbShopCategory} from '@/http/yskApi/goods.js'
import { ref, watch, onMounted,reactive } from 'vue';
import { categoryPage } from '@/api/cateGory.js'
const emite=defineEmits(['change','update:isShow','confirm'])
const props = defineProps({
showAllText:{
type:Boolean,
default:true
},
width: {
type: [Number, String],
default: 264
},
height: {
type: [Number, String],
default: 420
},
right: {
type: [Number, String],
default: 30
},
bottom: {
type: [Number, String],
default: 0
},
isShow:{
type:Boolean,
default:false
@@ -38,54 +15,35 @@
let show = ref(props.isShow)
const category=reactive({
list:[],
})
onMounted(()=>{
categoryPage({
page:1,size:200
}).then(res=>{
res.records.unshift({
name:'全部',
id:'',
})
category.list = [res.records]
})
})
watch(()=>show.value,(newval)=>{
emite('change',newval)
emite('update:isShow',newval)
})
watch(()=>props.isShow,(newval)=>{
console.log(newval);
show.value=newval
})
function confirm(e){
console.log(e.value[0]);
show.value = false
emite('confirm',e.value[0])
}
function close() {
console.log('close');
show.value = false
}
const category=reactive({
list:[],
})
onMounted(()=>{
$tbShopCategory({
page:0,size:200
}).then(res=>{
res.content.unshift({
name:'全部',
id:'',
childrenList:[]
})
category.list=[res.content.reduce((prve, cur) => {
prve.push(...[{
...cur,
name: '' + cur.name,
childrenList:undefined
}, ...cur.childrenList.map(v => {
return {
...v,
name: '' + v.name
}
})])
return prve
}, [])]
console.log(category.list);
})
})
</script>
<style lang="scss" scoped>

View File

@@ -1,166 +0,0 @@
<template>
<view class="control" :style="getComputedStyle()">
<view class="u-flex control1" v-if="showControl1">
<view class="btn" @click="changeShowControl1">批量管理</view>
<view class="btn" @tap="go.to('PAGES_PRODUCT_ADD')">商品添加</view>
<!-- <view class="color-999 btn u-flex u-row-center" @click="emitToggleCategory">
<text class="u-m-r-10">{{categoryName||'选择分类'}}</text>
<view class="arrow-down" :class="{'up':categoryShow}">
<uni-icons type="right" size="16" color="#999"></uni-icons>
</view>
</view> -->
</view>
<view class="u-flex control2 u-row-between" v-else>
<view class="u-flex u-flex-1 btn " @click="changeIsSelectAll">
<view class="u-m-l-28">
<my-radio v-model="isSelectAll" >
<view class="color-fff">全选</view>
</my-radio>
</view>
<!-- <label class="radio u-m-l-28" >
<radio class="scale7" @tap.stop="changeIsSelectAll" :color="ColorMain" value="" :checked="isSelectAll" />
<text>全选</text>
</label> -->
</view>
<view class=" btn u-flex-1 my-bg-main" @click="changeShowControl1">取消</view>
</view>
</view>
</template>
<script setup>
import {$tbShopCategory} from '@/http/yskApi/goods.js'
import go from '@/commons/utils/go.js';
import {ColorMain} from '@/commons/color.js'
import {
onMounted,
reactive,
ref
} from 'vue';
const props = defineProps({
bottom: {
type: [Number, String],
default: 30
},
categoryName:{
type:String,
default:''
},
categoryShow:{
type:Boolean,
default:false
}
})
let showControl1 = ref(true)
const emits = defineEmits(['toggleCategory','controlChange','allCheckedChange','offShelf','categoryChange'])
function emitToggleCategory() {
emits('toggleCategory')
}
function changeShowControl1() {
showControl1.value = !showControl1.value
if(!showControl1.value){
isSelectAll.value=false
}
emits('controlChange',!showControl1.value)
}
let isSelectAll = ref(false)
function changeIsSelectAll() {
console.log('changeIsSelectAll');
isSelectAll.value = !isSelectAll.value
emits('allCheckedChange',isSelectAll.value)
}
function getComputedStyle() {
return {
bottom: props.bottom + 'rpx'
}
}
//设置是否全选
function setisSelectAll(checked){
isSelectAll.value =checked
}
defineExpose({
setisSelectAll
})
//下架
function offShelf(){
emits('offShelf')
}
</script>
<style lang="scss" scoped>
.scale7 {
transform: scale(0.7);
}
.borde-r {
position: relative;
&::after {
display: block;
content: '';
position: absolute;
top: 20rpx;
bottom: 20rpx;
width: 2px;
background-color: #fff;
right: 0;
}
}
.control {
position: fixed;
left: 110rpx;
right: 110rpx;
z-index: 100;
background: #3E3A3A;
border-radius: 100rpx;
overflow: hidden;
.btn{
color: #fff;
box-sizing: border-box;
}
.control1 {
.arrow-down {
transform: rotate(90deg);
transition: all .2s ease-in-out;
&.up{
transform: rotate(-90deg);
}
}
}
.control1 .btn:not(:last-child)::after {
display: block;
content: '';
position: absolute;
top: 20rpx;
bottom: 20rpx;
width: 2px;
background-color: #fff;
right: 0;
}
.control1 .btn {
flex: 1;
}
.control1 .btn,
.control2 .btn{
position: relative;
line-height: 76rpx;
text-align: center;
}
.control2 {
overflow: hidden;
// padding: 0 28rpx;
}
}
</style>

View File

@@ -2,27 +2,7 @@
<view>
<template v-if="isBind">
<view class="goods">
<view class="u-flex u-row-between">
<view class="u-flex">
<view class="color-333">
<text class="">排序</text>
<text class="u-m-l-20">{{data.sort}}</text>
</view>
<view class="color-333 u-m-l-42 u-flex">
<text class="stock u-m-l-4">库存:{{data.stockNumber}}</text>
</view>
</view>
</view>
<view class="u-m-t-24 u-flex u-col-top u-relative">
<view v-if="props.showChecked">
<label class="radio">
<radio :color="ColorMain" style="transform: scale(0.7);" @click="radioClick"
:checked="props.data.checked" /><text></text>
</label>
</view>
<view class="img">
<up--image :width="63" :height="63" :radius="3" :src="data.coverImg"></up--image>
</view>
@@ -31,11 +11,6 @@
<view class="u-flex">
<text class="u-m-r-24">{{data.name}}</text>
</view>
<view class="u-font-32 u-m-r-8">
<!-- <text v-if="data.typeEnum=='单规格'||data.typeEnum=='normal'">¥</text> -->
<text >¥</text>
<text>{{data.lowPrice}}</text>
</view>
</view>
<view class="u-flex u-m-t-10 u-row-right">
<view class="btn-default btn" @tap="del">删除</view>
@@ -58,24 +33,9 @@
</template>
<script setup>
import {
ref,
watch,
watchEffect
} from 'vue';
import {
$goodsIsHot,
$tbProskuConV2,
$updateProductData
} from '@/http/yskApi/goods.js'
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(['goodsClick', 'changeClick', 'xiajia', 'del', 'changePrice', 'baosun', 'guigeClick',
'editStock'
])
import { ColorMain } from '@/commons/color.js'
const emits = defineEmits(['goodsClick', 'del'])
const props = defineProps({
isBind: {
type: Boolean,
@@ -92,10 +52,6 @@
}
}
},
showChecked: {
type: Boolean,
default: false
},
showDetail: {
type: Boolean,
default: false
@@ -105,69 +61,15 @@
function goodsClick(){
emits('goodsClick',props.index)
}
async function upDateGoods(par) {
const res = await $updateProductData([{
id: props.data.id,
isSku: 0,
shopId: uni.getStorageSync('shopId'),
...par
}])
uni.showToast({
title: '修改成功',
icon: 'none'
})
}
function radioClick() {
console.log(props.index);
emits('radioClick', props.index)
}
function changeClick() {
emits('changeClick', props.index)
}
function xiajia() {
emits('xiajia', props.index)
}
function del() {
emits('del', props.index)
}
function changePrice() {
emits('changePrice', props.index)
}
function baosun() {
emits('baosun', props.index)
}
function guigeClick(guigeIndex) {
emits('guigeClick', props.index, guigeIndex)
}
function editStock() {
emits('editStock', props.index)
}
//携带参数type edit跳转到商品添加页面编辑与添加同一页面根据type值来判断
function toEdit() {
go.to('PAGES_PRODUCT_ADD', {
type: 'edit',
productId: props.data.id
})
}
</script>
<style lang="scss" scoped>
$imgSize: 126rpx;
$price-color: #F02C45;
.btn {
padding: 6rpx 28rpx;
@@ -175,62 +77,16 @@
border: 2rpx solid transparent;
}
.gap-10 {
gap: 10rpx;
}
.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;
}
.info-p-l {
padding-left: 71px;
}
.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;
}
.color-red {
color: #F0465B;
}
.goods {
border-radius: 10rpx 10rpx 10rpx 10rpx;
background-color: #fff;
@@ -254,34 +110,4 @@
}
}
.skd {
padding: 14rpx 40rpx 14rpx 20rpx;
background: #F0F2F5;
border-radius: 4rpx;
position: relative;
color: #666;
overflow: hidden;
margin-bottom: 10rpx;
font-size: 24rpx;
.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;
}
.tag-gray {
background-color: rgb(144, 147, 153);
color: #fff;
}
}
</style>

View File

@@ -2,9 +2,7 @@
<view class="safe-page min-page">
<up-sticky>
<view class="bg-fff u-p-l-30 u-p-b-24">
<!-- <view class="myTabs ">
<myTabs :list="tabsList" @change="tabsChange"></myTabs>
</view> -->
<view class="input-wrapper">
<view class="input-main">
<view class="u-flex u-p-r-30 u-font-28" @click="onCategoryShowChange(true)">
@@ -39,8 +37,8 @@
<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 @radioClick="goodsRadioClick" :index="index" :data="item" @del="goodsDel"
:showChecked="showChecked" :showDetail="pageData.showGoodsDetail"></my-goods>
<my-goods isBind :index="index" :data="item" @del="goodsDel"
:showDetail="pageData.showGoodsDetail"></my-goods>
</view>
</template>
<template v-if="pageData.hasAjax&&!pageData.bindGoodsList.length">
@@ -54,8 +52,7 @@
<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" @radioClick="goodsRadioClick" :index="index" :data="item"
@del="goodsDel" :showChecked="showChecked"
<my-goods @goodsClick="goodsClick" :index="index" :data="item"
:showDetail="pageData.showGoodsDetail"></my-goods>
</view>
</template>
@@ -67,15 +64,9 @@
<my-button shape="circle" @click="save">确定</my-button>
</view>
<view style="height: 100rpx;"></view>
<!-- <my-pagination :totalElements="pageData.totalElements" :size="pageData.query.size"
@change="pageChange"></my-pagination> -->
<!-- <my-control></my-control> -->
</view>
</template>
<!-- 分类 -->
<my-category v-model:isShow="pageData.categoryShow" @confirm="setCategory"></my-category>
</view>
@@ -83,64 +74,22 @@
</template>
<script setup>
import {
onLoad,
onReady,
onShow,
onPageScroll,
onPullDownRefresh
} from '@dcloudio/uni-app';
import {
reactive,
ref,
watch
} from 'vue';
import go from '@/commons/utils/go.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 infoBox from "@/commons/utils/infoBox.js"
import myControl from './components/control.vue'
import {
$tbProduct,
$upProSort,
$updateProduct,
$getProductDetail,
$delProduct,
$tbShopCategory,
$updateProductStatus,
$tbProductV2,
$updateProductData
} from "@/http/yskApi/goods.js"
import {
productListGet,
tbProductGroupGet,
tbProductGroupDelete,
tbProductGroupPut,
upGroupSort,
tbProductGroupPost
} from "@/http/yskApi/shop.js"
import {
hasPermission
} from '@/commons/utils/hasPermission.js';
import {
returnAllCategory
} from '@/pageProduct/util.js'
import { hasPermission } from '@/commons/utils/hasPermission.js';
import { categoryPage } from '@/api/cateGory.js'
import { getProductList,getProdGroupDetail,updateProdGroup } from '@/api/product.js'
const pageData = reactive({
modelDesc: '是否下架',
stateCurrent: 0,
componentBottom: 45,
search: {
value: '',
placeholder: '输入搜索的商品'
},
showGoodsDetail: false,
selGoodsIndex: '',
selGoods: {},
totalElements: 0,
totalPage: 0,
bindGoodsList: [],
goodsList: [],
query: {
@@ -148,9 +97,7 @@
size: 999,
categoryId: '',
name: '',
createdAt: [],
id: "",
sort: "createdAt,desc"
},
category: '',
categoryList: [], //分类列表
@@ -159,262 +106,22 @@
hasAjax: false
})
function isGroundingChange(e) {
const {
goodsIndex,
guigeIndex
} = popup.guige
pageData.goodsList[goodsIndex].skuList[guigeIndex].isGrounding = e
}
function isPauseSaleChange(e) {
const {
goodsIndex,
guigeIndex
} = popup.guige
pageData.goodsList[goodsIndex].skuList[guigeIndex].isPauseSale = e
}
function onCategoryShowChange(show) {
console.log(show);
pageData.categoryShow = show
}
function goodsClick(e) {
console.log(e);
pageData.goodsList[e].checked = !pageData.goodsList[e].checked
}
function setCategory(category) {
pageData.query.categoryId = category.id
console.log(pageData.query.categoryId );
pageData.categoryName = category.name
}
let $goodsList = []
function setGoodsList() {
pageData.goodsList = $goodsList.filter(v => {
return !pageData.bindGoodsList.find(bindGoods => bindGoods.id == v.id)
})
}
function getGoodsList() {
$tbProductV2(pageData.query).then(res => {
pageData.hasAjax = true
pageData.totalElements = res.totalElements
$goodsList = res.content.map(v => {
return {
...v,
checked: false
}
})
setGoodsList()
})
}
onShow(() => {
// getGoodsList()
})
async function getGroupBindGoods() {
const res = await productListGet(option.id)
pageData.bindGoodsList = res.filter(v=>{
return pageData.query.categoryId===''?true:(v.categoryId==pageData.query.categoryId)&&(v.name.includes(pageData.query.name))
})
}
const option = reactive({})
async function init() {
await getGroupBindGoods()
getGoodsList()
}
onLoad((opt) => {
Object.assign(option, opt)
init()
// $tbShopCategory({
// page: 0,
// size: 200
// }).then(res => {
// pageData.categoryList = returnAllCategory(res.content)
// console.log(pageData.categoryList);
// })
})
const statesTabsList = ['已添加', '未添加']
const control = ref(null)
const model = ref(null)
const goodsStockModel = ref(null)
function returnGoodsStockData() {
return reactive({
sort: 0,
isStock: false,
isDistribute: false,
isPauseSale: false,
isGrounding: false,
stockNumber: 0,
})
}
async function save() {
const res = await hasPermission('允许修改分组')
if (!res) {
return
}
console.log(pageData.goodsList);
await tbProductGroupPut({
...option,
shopId: uni.getStorageSync('shopId'),
productIds: [...pageData.bindGoodsList.map(v => v.id), ...pageData.goodsList.filter(v => v.checked)
.map(v => v.id)
]
})
pageData.stateCurrent = 0
}
function updateGroup() {
}
//删除商品
async function goodsDel(index) {
const res = await hasPermission('允许修改分组')
if (!res) {
return
}
const goods = pageData.bindGoodsList[index]
uni.showModal({
title: '提示',
content: '是否确认将' + goods.name + '从该分组中移除',
success: function(res) {
if (res.confirm) {
pageData.bindGoodsList.splice(index, 1)
tbProductGroupPut({
...option,
shopId: uni.getStorageSync('shopId'),
productIds: pageData.bindGoodsList.map(v => v.id)
})
} else if (res.cancel) {}
}
});
}
function statesTableClick(index) {
pageData.stateCurrent = index
console.log(pageData.stateCurrent);
}
function tabsChange(i) {
console.log(i);
pageData.showGoodsDetail = i ? true : false
}
//改变商品的选中状态
function changeGoodsChecked(checked, index) {
if (index !== undefined) {
pageData.goodsList[index].checked = checked
} else {
pageData.goodsList.map(v => {
v.checked = checked
})
}
control.value.setisSelectAll(isAllChecked() ? true : false)
}
// 获取已经选中的商品
function getChechkedGoodsList() {
return pageData.goodsList.filter(v => v.checked)
}
//是否全部选中
function isAllChecked() {
return getChechkedGoodsList().length === pageData.goodsList.length
}
// 是否有商品选中
function isHasChekdGoods() {
return getChechkedGoodsList().length ? true : false
}
let isSearch=ref(false)
async function searchFunc() {
isSearch.value=true
console.log('searchFunc');
if (pageData.stateCurrent) {
getGoodsList()
} else {
const res = await productListGet(option.id)
pageData.bindGoodsList = res.filter(v=>{
return v.name.includes(pageData.query.name)&&(pageData.query.categoryId===''?true:v.categoryId==pageData.query.categoryId)
})
}
}
let showChecked = ref(false)
//商品start
function goodsRadioClick(index) {
var checked = !pageData.goodsList[index].checked
changeGoodsChecked(checked, index)
}
//下架
function offShelf() {
const hasCheckedArr = getChechkedGoodsList()
const hasChecked = isHasChekdGoods()
if (!hasChecked) {
return infoBox.showToast('您还没有选中商品!')
}
model.value.open()
}
//下架确认
function modelConfirm() {
console.log('confirm');
model.value.close()
}
//商品end
//控制条
function controlChange(bol) {
showChecked.value = bol
}
// 全选
function allCheckedChange(checked) {
changeGoodsChecked(checked)
}
// 页数改变事件
function pageChange(page) {
console.log(page);
pageData.query.page = page - 1
getGoodsList()
}
const statesTabsList = ['已添加', '未添加']
const control = ref(null)
const model = ref(null)
const option = reactive({})
//分类
const category = ref(null)
function toggleCategory() {
category.value.toggle()
}
function cateClick(cate) {
console.log(cate);
pageData.query.categoryId = cate.id
pageData.categoryName = cate.name
pageData.category = cate
getGoodsList()
}
onLoad((opt) => {
Object.assign(option, opt)
init()
})
onShow(() => {
})
watch(() => pageData.query.categoryId, (newval) => {
if(pageData.stateCurrent==1){
getGoodsList()
@@ -430,6 +137,131 @@
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() {
getProductList(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)
console.log(res)
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
console.log(pageData.query.categoryId );
pageData.categoryName = category.name
}
/**
* 绑定商品
*/
async function save() {
const res = await hasPermission('允许修改分组')
if (!res) {
return
}
console.log(pageData.goodsList);
await updateProdGroup({
...option,
productIds: [...pageData.bindGoodsList.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.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) {}
}
});
}
function goodsClick(e) {
pageData.goodsList[e].checked = !pageData.goodsList[e].checked
}
</script>
<style scoped>
page {

View File

@@ -1,8 +0,0 @@
<template>
</template>
<script>
</script>
<style>
</style>

View File

@@ -6,10 +6,10 @@
label-position="top" label-width="350">
<view class="block">
<view class="input-padding-b-0 ">
<uni-forms-item label="分名称" required name="name">
<uni-forms-item label="分名称" required name="name">
<view class="u-m-t-16 u-m-b-24">
<uni-easyinput paddingNone :placeholderStyle="placeholderStyle"
:inputBorder="inputBorder" v-model="category.name" placeholder="输入分名称" />
:inputBorder="inputBorder" v-model="category.name" placeholder="输入分名称" />
</view>
</uni-forms-item>
</view>
@@ -24,7 +24,7 @@
<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>
<my-switch v-model="category.status"></my-switch>
</view>
</view>
</uni-forms-item>
@@ -100,6 +100,8 @@
tbProductGroupPost
} from '@/http/yskApi/shop.js'
import { addProdGroup, updateProdGroup } from '@/api/product.js'
const $productCategory = {
add: tbProductGroupPost,
del: tbProductGroupDelete,
@@ -107,26 +109,27 @@
get: tbProductGroupGet
}
const refAddChilCate = ref(null)
const refAddChilCateTitle = ref('添加子分类')
function refAddChilCateClose() {
refAddChilCate.value.close()
categoryChild.value = {
...categoryBasicData
}
const option = reactive({
type: ''
})
// 构造分类的基础数据
const categoryBasicData = {
id: '',
name: '',
status: 1,
sort: 0,
useTime: 0,
saleEndTime:'',
saleStartTime:'',
}
let refMoreSheet = ref(null)
let selItem = {
data: '',
index: ''
}
// 分类列表
const category = reactive({
...categoryBasicData,
childrenList: []
})
// 表单样式
const placeholderStyle = ref('font-size:28rpx;')
//表单边框
@@ -148,242 +151,49 @@
}]
}
}
const refFiles = ref([])
function setRefFile(index) {
refFiles.value[index] = null;
return (el) => {
if (el) {
refFiles.value[index] = el;
}
};
}
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.show=true;
}
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 = {
id: '',
name: '',
isShow: 1,
sort: 0,
productIds: [],
saleTime: [],
useTime: 0,
saleEndTime:'',
saleStartTime:'',
shopId: uni.getStorageSync('shopId')
}
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);
onLoad(option => {
uni.setNavigationBarTitle({
title: option.type === 'add' ? '添加分组' : '编辑分组'
})
})
function emitcategorySave() {
// emitcategorySave 触发规格保存事件将数据给到添加商品页面
// guigeEdit 触发规格保存事件将数据给到添加规格页面
uni.removeStorageSync('guige')
triggerEvent(emitName, category.list)
/**
* 打开时间弹窗
* @param {Object} key
*/
function changeTime(key) {
time.key=key;
time.show=true;
}
/**
* 关闭时间弹窗
*/
function timeCancel(){
time.show=false
}
/**
* 时间设置确定
* @param {Object} e
*/
function timeConfirm(e){
console.log(e);
if(time.key=='start'){
category.saleStartTime=e.value+':00'
}else{
category.saleEndTime=e.value+':00'
}
time.val=''
time.show=false
}
@@ -421,31 +231,22 @@
}
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({
const res = await updateProdGroup({
...category,
childrenList: ''
})
} else {
const res = await $productCategory.add({
const res = await addProdGroup({
...category,
childrenList: ''
})
@@ -456,9 +257,7 @@
clearTimeout(timer)
go.back()
}, 1500);
// const res = await form.value.validate().then(res => {
// go.back()
// })
}
</script>

View File

@@ -1,213 +0,0 @@
<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

@@ -12,7 +12,7 @@
</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>
<up-switch :activeValue="1" :inactiveValue="0" v-model="data.status" @change="isShowChange" :size="18"></up-switch>
</view>
</view>
<view class="u-m-t-24 u-p-l-54 ">
@@ -63,19 +63,16 @@
type: Object,
default: () => {
return {
isShow:true
status:true
}
}
},
})
let isShow = ref(props.data.isShow)
function isShowChange() {
console.log(isShow.value);
emits('isShowChange', {
...props.data,
isShow: isShow.value
})
}
@@ -89,18 +86,12 @@
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)
}
@@ -113,10 +104,6 @@
}
function toEdit() {
emits('edit', props.index)
// uni.setStorageSync('cateItem', props.data)
// go.to('PAGES_CATEGORY_EDIT', {
// type: 'edit',
// })
}
</script>

View File

@@ -32,30 +32,13 @@
</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'
import { reactive, ref, watch } from 'vue';
const props = defineProps({
show: {
type: Boolean,
default: false
},
category: {
type: Array,
default: () => []
},
item: {
type: Object,
default: () => {
@@ -64,15 +47,9 @@
}
})
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('')
@@ -86,10 +63,7 @@
data.value = props.item
}
})
const isSku = computed(() => {
// return data.value.typeEnum == '多规格'
return false
})
watch(() => popShow.value, (newval) => {
emits('update:show', newval)
})
@@ -103,6 +77,7 @@
}
function save() {
console.log(data)
emits('save', {
...data.value,
name:name.value

View File

@@ -45,19 +45,13 @@
</view>
</view>
</view>
<up-datetime-picker @cancel="timeCancel" @confirm="timeConfirm" :show="time.show" v-model="time.val" mode="time"></up-datetime-picker>
<up-datetime-picker @cancel="timeCancel" @confirm="timeConfirm" format="HH:mm" :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 { reactive, ref, watch, computed } from 'vue';
import infoBox from '@/commons/utils/infoBox.js'
const props = defineProps({
show: {
@@ -78,21 +72,20 @@
saleStartTime:'',
})
const time=reactive({
show:false,
val:'',
key:''
})
function timeCancel(){
time.show=false
time.show = false
}
function timeConfirm(e){
console.log(e);
if(time.key=='start'){
category.saleStartTime=e.value
category.saleStartTime=e.value+':00'
}else{
category.saleEndTime=e.value
category.saleEndTime=e.value+':00'
}
time.val=''
time.show=false
@@ -102,22 +95,11 @@
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
})
let popShow = ref(props.show)
watch(() => props.show, (newval) => {
popShow.value = newval

View File

@@ -1,483 +0,0 @@
<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

@@ -1,25 +1,25 @@
<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"
<my-category
@del="groupDel"
@editName="popupShow($event,'name',true)"
@editSort="popupShow($event,'sort',true)"
@edit="actionsShow"
@isShowChange="isSHowChange" :index="index" :data="item"
:showDetail="pageData.showGoodsDetail"></my-category>
</view>
<view class="u-m-t-44" v-if="pageData.list.length>0">
<my-pagination :page="pageData.query.page+1" :size="pageData.query.size" :totalElements="pageData.totalElements"
<my-pagination :page="pageData.query.page" :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>
<my-button :height="80" shape="circle" font-weight="700" @tap="toAddGroup">新建分组</my-button>
</view>
</view>
@@ -32,33 +32,31 @@
</template>
<script setup>
import {
reactive,
ref,
watch
} from 'vue';
import {
onShow
} from '@dcloudio/uni-app'
import { reactive, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app'
import go from '@/commons/utils/go.js';
import myCategory from './components/category.vue'
import infoBox from "@/commons/utils/infoBox.js"
import myCategory from './components/category.vue'
import editSort from './components/edit-sort.vue';
import editName from './components/edit-name.vue';
import editTime from './components/edit-time.vue';
import {
tbProductGroupGet,
tbProductGroupDelete,
tbProductGroupPut,
upGroupSort,
tbProductGroupPost
} from '@/http/yskApi/shop.js'
const $productCategory = {
add: tbProductGroupPost,
del: tbProductGroupDelete,
update: tbProductGroupPut,
get: tbProductGroupGet
}
import { getProdGroupPage, addProdGroup, updateProdGroup, delProdGroup } from '@/api/product.js'
const pageData = reactive({
showGoodsDetail: false,
query: {
page: 1,
size: 10,
orderBy: 'create_time desc',
},
totalElements: 0,
list: [],
selCategory: ''
})
/**
* 编辑列表
*/
const actions = reactive({
list: [{
name: '排序',
@@ -77,36 +75,11 @@
],
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: {
@@ -122,26 +95,95 @@
show: false
}
})
function popupShow(e, key, show) {
onShow(() => {
getList()
})
/**
* 获取分组数据
*/
async function getList() {
const res = await getProdGroupPage(pageData.query)
pageData.list = res.records
pageData.totalElements = res.totalRow
}
/**
* 编辑列表显示
* @param {Object} e
*/
function actionsShow(e) {
console.log(e)
popup.selData = pageData.list[e]
popup.selIndex = e
popup[key].show = show
actions.show = true
}
/**
* 编辑列表隐藏
*/
function actionsHide() {
actions.show = false
}
/**
* 编辑列表选择
* @param {Object} e
*/
function actionSelect(e) {
if (e.name == '排序') {
return popupShow(popup.selIndex, 'sort', true)
}
if (e.name == '管理商品') {
const {id,status,name,sort}=popup.selData
return go.to('PAGES_GOODS_GROUP_EDIT_GOODS', {
id,status,name,sort
})
}
if (e.name == '售卖时间') {
return popupShow(popup.selIndex, 'time', true)
}
}
/**
* 编辑打开
* @param {Object} e
* @param {Object} key
* @param {Object} show
*/
function popupShow(e, key, show) {
popup[key].show = show
popup.selIndex = e
popup.selData = pageData.list[e]
}
/**
* 编辑确认
* @param {Object} e
*/
async function updataGroup(e) {
console.log(e);
const res = await $productCategory.update(e)
const res = await updateProdGroup(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)
/**
* 状态修改
* @param {Object} data
*/
async function isSHowChange(data) {
const res = await updateProdGroup({
...data
})
infoBox.showToast('修改成功')
// init()
}
const goodsSortModel = ref(null)
const goodsTypeModel = ref(null)
let sort = ref(0)
@@ -167,220 +209,44 @@
}
]
})
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() {
/**
* 新增分组
*/
function toAddGroup() {
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()
/**
* 删除分组
* @param {Object} index
*/
function groupDel(index) {
uni.showModal({
title: '提示',
content: '请确保此分下没有任何商品确认删除?',
content: '请确保此分下没有任何商品确认删除?',
success: res => {
if (res.confirm) {
const islast = pageData.list.length === 1
$productCategory.del([pageData.list[index].id]).then(res => {
delProdGroup(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()
getList()
})
}
},
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()
pageData.query.page = page
getList()
}
//分类
const category = ref(null)
function toggleCategory() {
category.value.toggle()
}
function cateClick(cate) {
console.log(cate);
}
</script>
<style scoped>
page {