first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1 @@
78d512f5-620a-4401-a282-deb524f96e49

View File

@@ -0,0 +1,230 @@
export default {
state:{
list:[
{
checked:false,
id:11,
title:"商品标题111",
cover:"/static/images/demo/list/1.jpg",
// 选中商品属性
attrs:[
{
title:"颜色",
selected:0,
list: [
{ name:'火焰红', },
{ name:'炭黑', },
{ name:'冰川兰', }
]
},
{
title:"容量",
selected:0,
list: [
{ name:'64GB', },
{ name:'128GB', },
]
},
{
title:"套餐",
selected:0,
list: [
{ name:'标配', },
{ name:'套餐一', },
{ name:'套餐二', }
]
},
],
pprice:336,
num:1,
minnum:1,
maxnum:10, // 该商品最大商品数,跟库存有关
},
{
checked:false,
id:12,
title:"商品标题111",
cover:"/static/images/demo/list/1.jpg",
// 选中商品属性
attrs:[
{
title:"颜色",
selected:0,
list: [
{ name:'火焰红', },
{ name:'炭黑', },
{ name:'冰川兰', }
]
},
{
title:"容量",
selected:0,
list: [
{ name:'64GB', },
{ name:'128GB', },
]
},
{
title:"套餐",
selected:0,
list: [
{ name:'标配', },
{ name:'套餐一', },
{ name:'套餐二', }
]
},
],
pprice:336,
num:1,
minnum:1,
maxnum:10, // 该商品最大商品数,跟库存有关
},
{
checked:false,
id:13,
title:"商品标题111",
cover:"/static/images/demo/list/1.jpg",
// 选中商品属性
attrs:[
{
title:"颜色",
selected:0,
list: [
{ name:'火焰红', },
{ name:'炭黑', },
{ name:'冰川兰', }
]
},
{
title:"容量",
selected:0,
list: [
{ name:'64GB', },
{ name:'128GB', },
]
},
{
title:"套餐",
selected:0,
list: [
{ name:'标配', },
{ name:'套餐一', },
{ name:'套餐二', }
]
},
],
pprice:336,
num:1,
minnum:1,
maxnum:10, // 该商品最大商品数,跟库存有关
},
],
// 选中列表存放选中的id
selectedList:[],
// popup显示
popupShow:"none",
popupIndex:-1
},
getters:{
// 判断是否全选
checkedAll:(state)=>{
return state.list.length === state.selectedList.length
},
// 合计
totalPrice:(state)=>{
var total = 0
state.list.forEach(v=>{
if (state.selectedList.indexOf(v.id) > -1) {
total += v.pprice*v.num
}
})
return total
},
// 禁用全选
disableSelectAll:(state)=>{
return state.list.length === 0
},
// 拿到当前需要修改属性的商品
popupData:(state)=>{
return state.popupIndex > -1 ? state.list[state.popupIndex] : {}
}
},
mutations:{
// 选中/取消选中某个商品
selectItem(state,index){
let id = state.list[index].id
let i = state.selectedList.indexOf(id)
// 之前是选中,取消选中
if (i > -1) {
// 取消当前商品选中状态
state.list[index].checked = false
// 移除选中列表中的当前商品
return state.selectedList.splice(i,1)
}
// 选中
state.list[index].checked = true
state.selectedList.push(id)
},
// 全选
selectAll(state){
state.selectedList = state.list.map(v=>{
// 设置选中状态
v.checked = true
return v.id
})
},
// 取消全选
unSelectAll(state){
state.list.forEach(v=>{
// 设置选中状态
v.checked = false
})
state.selectedList = []
},
// 删除选中
delGoods(state){
state.list = state.list.filter(v=>{
return state.selectedList.indexOf(v.id) === -1
})
},
// 初始化popupIndex
initPopupIndex(state,index){
state.popupIndex = index
},
// 加入购物车
addGoodsToCart(state,goods){
state.list.unshift(goods)
}
},
actions:{
// 显示popup
doShowPopup({state,commit},index){
commit('initPopupIndex',index)
state.popupShow = 'show'
},
// 隐藏popup
doHidePopup({state}){
state.popupShow = 'hide'
setTimeout(()=>{
state.popupShow = 'none'
commit('initPopupIndex',-1)
},200)
},
doSelectAll({commit,getters}){
getters.checkedAll ? commit('unSelectAll') : commit('selectAll')
},
doDelGoods({commit}){
uni.showModal({
content: '是否删除选中',
success: (res)=>{
if (res.confirm) {
commit('delGoods')
uni.showToast({
title: '删除成功'
});
}
}
});
}
}
}

View File

@@ -0,0 +1,66 @@
export default {
state:{
list:[
{
name:"金壶医药",
phone:"158****531",
path:"安徽省合肥市肥东县经济开发区临泉路",
detailPath:"六号楼五楼",
isdefault:false
},
{
name:"小崔",
phone:"158****531",
path:"地球村",
detailPath:"哈哈哈...",
isdefault:false
}
],
},
getters:{
// 获取默认地址
defaultPath:(state)=>{
return state.list.filter(v=> v.isdefault)
}
},
mutations:{
// 创建收货地址
createPath(state,item){
state.list.unshift(item)
},
// 删除收货地址
delPath(state,index){
state.list.splice(index,1)
},
// 修改收货地址
updatePath(state,{index,item}){
for (let key in item) {
state.list[index][key] = item[key]
}
},
// 取消默认地址
removeDefault(state){
state.list.forEach((v)=>{
if (v.isdefault) {
v.isdefault = false
}
})
}
},
actions:{
// 修改地址
updatePathAction({commit},obj){
if (obj.item.isdefault) {
commit('removeDefault');
}
commit('updatePath',obj)
},
// 增加地址
createPathAction({commit},item){
if (item.isdefault) {
commit('removeDefault');
}
commit('createPath',item)
}
}
}