first commit
This commit is contained in:
1
金壶/appV1/store/.pydio
Normal file
1
金壶/appV1/store/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
96dbc788-dcfe-4983-a8f2-c73c262bc9fe
|
||||
34
金壶/appV1/store/index.js
Normal file
34
金壶/appV1/store/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import Vue from "vue"
|
||||
import Vuex from "vuex"
|
||||
|
||||
import cart from "@/store/modules/cart.js"
|
||||
import path from "@/store/modules/path.js"
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
state:{
|
||||
goods_id:'',
|
||||
shooppingCar_num: 0
|
||||
},
|
||||
getters: {
|
||||
// 获取购物车数量
|
||||
GetShopCarNums: (state) => {
|
||||
return state.shooppingCar_num
|
||||
}
|
||||
},
|
||||
mutations:{
|
||||
goodid(state,data){
|
||||
state.goods_id = data
|
||||
},
|
||||
SetShopCarNums: (state, Nums = null) => {
|
||||
Nums == null ? state.shooppingCar_num += 1 : state.shooppingCar_num = Nums
|
||||
// 本地保存购买数量
|
||||
uni.setStorageSync('GoodNums', state.shooppingCar_num);
|
||||
}
|
||||
},
|
||||
modules:{
|
||||
cart,
|
||||
path,
|
||||
}
|
||||
})
|
||||
1
金壶/appV1/store/modules/.pydio
Normal file
1
金壶/appV1/store/modules/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
78d512f5-620a-4401-a282-deb524f96e49
|
||||
230
金壶/appV1/store/modules/cart.js
Normal file
230
金壶/appV1/store/modules/cart.js
Normal 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: '删除成功'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
66
金壶/appV1/store/modules/path.js
Normal file
66
金壶/appV1/store/modules/path.js
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user