代码更新
This commit is contained in:
@@ -4,16 +4,13 @@
|
||||
<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"
|
||||
@statusChange="statusChange"
|
||||
:index="index" :data="item"
|
||||
:showChecked="showChecked"
|
||||
:showDetail="pageData.showGoodsDetail"></my-category>
|
||||
: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>
|
||||
<my-pagination :page="pageData.query.page" :size="pageData.query.size" :totalElements="pageData.totalElements" @change="pageChange"></my-pagination>
|
||||
<view style="height: 200rpx;"></view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -41,49 +38,6 @@
|
||||
</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>
|
||||
@@ -101,264 +55,140 @@
|
||||
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 = ['全部', '已售罄']
|
||||
import { categoryPage,putCategory,delCategory } from '@/api/cateGory.js'
|
||||
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
|
||||
page: 1,
|
||||
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()
|
||||
})
|
||||
|
||||
onShow(()=>{
|
||||
watchEvent()
|
||||
})
|
||||
|
||||
function watchEvent(){
|
||||
uni.$off('update:pageCategoryIndex')
|
||||
uni.$on('update:pageCategoryIndex',(data)=>{
|
||||
init()
|
||||
})
|
||||
}
|
||||
onShow(()=>{
|
||||
watchEvent()
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
*/
|
||||
async function init() {
|
||||
const res= await categoryPage(pageData.query)
|
||||
pageData.list=res.records.map(v=>{
|
||||
return { ...v }
|
||||
})
|
||||
pageData.totalElements=res.totalRow
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建分类
|
||||
*/
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
//点击修改按钮弹出修改商品弹窗
|
||||
/**
|
||||
* 编辑
|
||||
* @param {Object} index
|
||||
*/
|
||||
function goodsChangeClick(index){
|
||||
console.log(index);
|
||||
const goods=pageData.list[index]
|
||||
sort.value=goods.sort
|
||||
pageData.selCategory=goods
|
||||
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
|
||||
/**
|
||||
* 编辑返回
|
||||
*/
|
||||
function goodsSortModelCancel(){
|
||||
goodsSortModel.value.close()
|
||||
}
|
||||
|
||||
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
|
||||
/**
|
||||
* 分类删除
|
||||
* @param {Object} index
|
||||
*/
|
||||
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=>{
|
||||
delCategory(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
|
||||
/**
|
||||
* 排序确认修改
|
||||
*/
|
||||
async function goodsSortModelSave(){
|
||||
const res=await putCategory({...pageData.selCategory,sort:sort.value})
|
||||
infoBox.showToast('修改成功')
|
||||
goodsSortModelCancel()
|
||||
init()
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用修改
|
||||
* @param {Object} datas
|
||||
*/
|
||||
async function statusChange(data){
|
||||
const res = await putCategory({...data})
|
||||
infoBox.showToast('修改成功')
|
||||
}
|
||||
|
||||
/**
|
||||
* 页数改变事件
|
||||
* @param {Object} page
|
||||
*/
|
||||
function pageChange(page) {
|
||||
pageData.query.page = page
|
||||
init()
|
||||
}
|
||||
|
||||
//分类
|
||||
const category=ref(null)
|
||||
function toggleCategory(){
|
||||
category.value.toggle()
|
||||
}
|
||||
function cateClick(cate){
|
||||
console.log(cate);
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
<style scoped>
|
||||
page{
|
||||
|
||||
Reference in New Issue
Block a user