This commit is contained in:
liu 2023-03-24 11:28:05 +08:00
parent b1bffc6967
commit 313e0c4963
5 changed files with 913 additions and 0 deletions

View File

@ -0,0 +1,317 @@
var a = require("../utils/public");
var app = getApp();
var status = require('../utils/index.js');
var util = require('../utils/util.js');
module.exports = {
data: {
visible: false,
stopClick: false
},
vipModal: function(t) {
this.setData(t.detail)
},
authModal: function () {
if (this.data.needAuth) {
this.setData({ showAuthModal: !this.data.showAuthModal });
return false;
}
return true;
},
openSku: function(t) {
if (!this.authModal()) return;
var that = this;
let idx = t.currentTarget.dataset.idx;
let rushList = this.data.list;
let spuItem = rushList[idx];
var goods_id = spuItem.actId;
var options = spuItem.skuList;
that.setData({
addCar_goodsid: goods_id
})
let list = options.list || [];
let arr = [];
if (list.length > 0) {
for (let i = 0; i < list.length; i++) {
let sku = list[i]['option_value'][0];
let temp = {
name: sku['name'],
id: sku['option_value_id'],
index: i,
idx: 0
};
arr.push(temp);
}
//把单价剔除出来begin
var id = '';
for (let i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
id = id + arr[i]['id'];
} else {
id = id + arr[i]['id'] + "_";
}
}
var cur_sku_arr = options.sku_mu_list[id];
cur_sku_arr.oneday_limit_count = spuItem.oneday_limit_count || 0;
cur_sku_arr.total_limit_count = spuItem.total_limit_count || 0;
cur_sku_arr.one_limit_count = spuItem.one_limit_count || 0;
cur_sku_arr.goods_start_count = spuItem.goods_start_count || 1;
that.setData({
sku: arr,
sku_val: 1,
cur_sku_arr: cur_sku_arr,
skuList: spuItem.skuList,
visible: true,
showSku: true
});
} else {
let goodsInfo = spuItem;
that.setData({
sku: [],
sku_val: 1,
skuList: [],
cur_sku_arr: goodsInfo
})
let formIds = {
detail: {
formId: ""
}
};
formIds.detail.formId = "the formId is a mock one";
that.gocarfrom(formIds, idx);
}
},
/**
* 确认加入购物车
*/
gocarfrom: function (e, idx=0) {
var that = this;
wx.showLoading();
a.collectFormIds(e.detail.formId);
that.goOrder(idx);
},
goOrder: function (idx) {
let that = this;
let tdata = that.data;
if (tdata.can_car) {
tdata.can_car = false;
}
var token = wx.getStorageSync('token');
var community = wx.getStorageSync('community');
var community_id = community.communityId;
var goods_id = tdata.addCar_goodsid;
var quantity = tdata.sku_val;
var cur_sku_arr = tdata.cur_sku_arr;
let list = tdata.list;
var sku_str = '';
var is_just_addcar = 1;
if (cur_sku_arr && cur_sku_arr.option_item_ids) {
sku_str = cur_sku_arr.option_item_ids;
}
let data= {
goods_id,
community_id,
quantity,
sku_str,
buy_type: 'dan',
pin_id: 0,
is_just_addcar
}
util.addCart(data).then(res=>{
if(res.showVipModal==1) {
wx.hideLoading();
let { pop_vipmember_buyimage } = res.data;
that.setData({ pop_vipmember_buyimage, showVipModal: true, visible: false });
} else {
if (res.data.code == 3) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else if (res.data.code == 4) {
wx.showToast({
title: '您未登录',
duration: 2000,
success: () => {
that.setData({
needAuth: true
})
}
})
} else if (res.data.code == 6 || res.data.code == 7) {
let max_quantity = res.data.max_quantity || '';
(max_quantity > 0) && that.setData({
sku_val: max_quantity
})
var msg = res.data.msg;
wx.showToast({
title: msg,
icon: 'none',
duration: 2000
})
} else {
if (is_just_addcar == 1) {
list[idx].car_count = res.data.cur_count || 0;
that.setData({
cartNum: res.data.total || 0,
list
})
that.closeSku();
status.indexListCarCount(goods_id, res.data.cur_count);
wx.showToast({
title: "已加入购物车",
image: "../../images/addShopCart.png"
})
} else {
var pages_all = getCurrentPages();
if (pages_all.length > 3) {
wx.redirectTo({
url: '/eaterplanet_ecommerce/pages/buy/index?type=' + tdata.order.buy_type
})
} else {
wx.navigateTo({
url: '/eaterplanet_ecommerce/pages/buy/index?type=' + tdata.order.buy_type
})
}
}
}
}
})
},
changeCartNum(e) {
let cartNum = e.detail || 0;
cartNum && this.setData({ cartNum })
},
/**
* 关闭购物车选项卡
*/
closeSku: function() {
this.setData({
visible: false,
stopClick: false
});
},
changeNumber: function (t) {
var e = t.detail;
e && this.addCart(e);
},
outOfMax: function (t) {
console.log(t)
// var e = t.detail, canBuyNum = this.data.spuItem.spuCanBuyNum;
// if (this.data.number >= canBuyNum) {
wx.showToast({
title: "不能购买更多啦",
icon: "none"
})
// }
},
addCart: function (t) {
// {value: 2, type: "plus/minus"}
let idx = t.idx;
let list = this.data.list;
var token = wx.getStorageSync('token');
var community = wx.getStorageSync('community');
var goods_id = list[idx].actId;
var community_id = community.communityId;
let that = this;
if (t.type == 'plus') {
let data= {
goods_id,
community_id,
quantity: 1,
sku_str: '',
buy_type: 'dan',
pin_id: 0,
is_just_addcar: 1
}
util.addCart(data).then(res=>{
if(res.showVipModal==1) {
let { pop_vipmember_buyimage } = res.data;
that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
} else {
if (res.data.code == 3) {
let max_quantity = res.data.max_quantity || '';
list[idx].car_count = max_quantity;
(max_quantity > 0) && that.setData({ list })
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else if (res.data.code == 6 || res.data.code == 7) {
let max_quantity = res.data.max_quantity || '';
list[idx].car_count = max_quantity;
(max_quantity > 0) && that.setData({ cartNum: res.data.total || 0, list })
var msg = res.data.msg;
wx.showToast({
title: msg,
icon: 'none',
duration: 2000
})
} else {
list[idx].car_count = res.data.cur_count;
that.setData({ cartNum: res.data.total || 0, list })
wx.showToast({
title: "已加入购物车",
image: "../../images/addShopCart.png"
})
status.indexListCarCount(goods_id, res.data.cur_count);
}
}
})
} else {
app.util.request({
url: 'entry/wxapp/user',
data: {
controller: 'car.reduce_car_goods',
token: token,
goods_id: goods_id,
community_id: community_id,
quantity: 1,
sku_str: '',
buy_type: 'dan',
pin_id: 0,
is_just_addcar: 1
},
dataType: 'json',
method: 'POST',
success: function (res) {
if (res.data.code == 3) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else {
list[idx].car_count = res.data.cur_count;
that.setData({ list, cartNum: res.data.total || 0 })
status.indexListCarCount(goods_id, res.data.cur_count);
}
}
})
}
}
}

View File

@ -0,0 +1,20 @@
module.exports = {
data: {
visible: false,
stopClick: false
},
authModal: function () {
if (this.data.needAuth) {
this.setData({
showAuthModal: !this.data.showAuthModal
});
return false;
}
return true;
},
vipModal: function(t) {
this.setData(t.detail)
},
}

View File

@ -0,0 +1,342 @@
var a = require("../utils/public");
var app = getApp();
var status = require('../utils/index.js');
var util = require('../utils/util.js');
module.exports = {
data: {
visible: false,
stopClick: false,
updateCart: 0
},
authModal: function (t=false) {
t.detail && this.setData({needAuth: true});
if (this.data.needAuth) {
this.setData({ showAuthModal: !this.data.showAuthModal });
return false;
}
return true;
},
vipModal: function(t) {
this.setData(t.detail)
},
openSku: function (t) {
if (!this.authModal()) return;
var that = this,
e = t.detail;
var goods_id = e.actId;
var options = e.skuList;
that.setData({
addCar_goodsid: goods_id
})
let list = options.list || [];
let arr = [];
if (list.length > 0) {
for (let i = 0; i < list.length; i++) {
let sku = list[i]['option_value'][0];
let temp = {
name: sku['name'],
id: sku['option_value_id'],
index: i,
idx: 0
};
arr.push(temp);
}
//把单价剔除出来begin
var id = '';
for (let i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
id = id + arr[i]['id'];
} else {
id = id + arr[i]['id'] + "_";
}
}
var cur_sku_arr = {};
if(options.sku_mu_list[id]) {
cur_sku_arr = options.sku_mu_list[id];
} else {
let idArr = id.split("_");
idArr = idArr.reverse();
id = idArr.join("_");
cur_sku_arr = options.sku_mu_list[id];
}
cur_sku_arr.oneday_limit_count = e.allData && e.allData.oneday_limit_count || 0;
cur_sku_arr.total_limit_count = e.allData && e.allData.total_limit_count || 0;
cur_sku_arr.one_limit_count = e.allData && e.allData.one_limit_count || 0;
cur_sku_arr.goods_start_count = e.allData && e.allData.goods_start_count || 1;
let { car_quantity, goods_start_count } = cur_sku_arr;
if(car_quantity && car_quantity>=goods_start_count) goods_start_count=1;
that.setData({
sku: arr,
sku_val: goods_start_count || 1,
cur_sku_arr: cur_sku_arr,
skuList: e.skuList,
visible: true,
showSku: true
});
} else {
let goodsInfo = e.skuList;
that.setData({
sku: [],
sku_val: 1,
skuList: [],
cur_sku_arr: goodsInfo
})
let formIds = {
detail: {
formId: ""
}
};
formIds.detail.formId = "the formId is a mock one";
that.gocarfrom(formIds);
}
},
/**
* 确认加入购物车
*/
gocarfrom: function (e) {
var that = this;
wx.showLoading();
a.collectFormIds(e.detail.formId);
that.goOrder();
},
goOrder: function () {
let that = this;
let tdata = that.data;
if (tdata.can_car) {
tdata.can_car = false;
}
var community = wx.getStorageSync('community');
var community_id = community.communityId;
var goods_id = tdata.addCar_goodsid;
var quantity = tdata.sku_val;
var cur_sku_arr = tdata.cur_sku_arr;
var sku_str = '';
var is_just_addcar = 1;
let updateCart = that.data.updateCart || 0;
if (cur_sku_arr && cur_sku_arr.option_item_ids) {
sku_str = cur_sku_arr.option_item_ids;
}
// 接龙
let soli_info = this.data.soli_info || '';
let soli_id = (soli_info && soli_info.id) || '';
let buy_type = this.data.buy_type || 'dan';
let data= {
goods_id,
community_id,
quantity,
sku_str,
buy_type,
pin_id: 0,
is_just_addcar,
soli_id
}
util.addCart(data).then(res=>{
if(res.showVipModal==1) {
wx.hideLoading();
let { pop_vipmember_buyimage } = res.data;
that.setData({ pop_vipmember_buyimage, showVipModal: true, visible: false });
} else {
if (res.data.code == 3) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else if (res.data.code == 4) {
wx.showToast({
title: '您未登录',
duration: 2000,
success: () => {
that.setData({
needAuth: true
})
}
})
} else if (res.data.code == 6 || res.data.code == 7) {
let max_quantity = res.data.max_quantity || '';
(max_quantity > 0) && that.setData({
sku_val: max_quantity
})
var msg = res.data.msg;
wx.showToast({
title: msg,
icon: 'none',
duration: 2000
})
} else {
if (is_just_addcar == 1) {
that.closeSku();
status.indexListCarCount(goods_id, res.data.cur_count);
that.setData({
cartNum: res.data.total || 0,
updateCart: updateCart+1
})
wx.showToast({
title: "已加入购物车",
image: "../../images/addShopCart.png"
})
} else {
var pages_all = getCurrentPages();
if (pages_all.length > 3) {
wx.redirectTo({
url: '/eaterplanet_ecommerce/pages/buy/index?type=' + tdata.order.buy_type
})
} else {
wx.navigateTo({
url: '/eaterplanet_ecommerce/pages/buy/index?type=' + tdata.order.buy_type
})
}
}
}
}
})
},
changeCartNum(e) {
let cartNum = e.detail || 0;
cartNum>=0 && this.setData({ cartNum })
},
/**
* 关闭购物车选项卡
*/
closeSku: function () {
this.setData({
visible: false,
stopClick: false
});
},
changeNumber: function (t) {
var e = t.detail;
e && this.addCart(e);
},
outOfMax: function (t) {
console.log(t)
var e = t.detail, canBuyNum = this.data.spuItem.spuCanBuyNum;
if (this.data.number >= canBuyNum) {
wx.showToast({
title: "不能购买更多啦",
icon: "none"
})
}
},
addCart: function (t) {
// {value: 2, type: "plus/minus"}
let idx = t.idx;
let list = this.data.list;
var token = wx.getStorageSync('token');
var community = wx.getStorageSync('community');
var goods_id = list[idx].actId;
var community_id = community.communityId;
// 接龙
let soli_info = this.data.soli_info || '';
let soli_id = (soli_info && soli_info.id) || '';
let buy_type = this.data.buy_type || 'dan';
let that = this;
if (t.type == 'plus') {
let data = {
goods_id: goods_id,
community_id: community_id,
quantity: 1,
sku_str: '',
buy_type,
pin_id: 0,
is_just_addcar: 1,
soli_id
}
util.addCart(data).then(res=>{
if(res.showVipModal==1) {
let { pop_vipmember_buyimage } = res.data;
that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
} else {
if (res.data.code == 3) {
let max_quantity = res.data.max_quantity || '';
list[idx].car_count = max_quantity;
(max_quantity > 0) && that.setData({ list })
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else if (res.data.code == 6 || res.data.code == 7) {
let max_quantity = res.data.max_quantity || '';
list[idx].car_count = max_quantity;
(max_quantity > 0) && that.setData({ cartNum: res.data.total || 0, list })
var msg = res.data.msg;
wx.showToast({
title: msg,
icon: 'none',
duration: 2000
})
} else {
let cartNum = res.data.total || 0;
if(soli_id>0) cartNum = res.data.goods_total_count || 0;
list[idx].car_count = res.data.cur_count;
that.setData({ cartNum, list })
wx.showToast({
title: "已加入购物车",
image: "../../images/addShopCart.png"
})
status.indexListCarCount(goods_id, res.data.cur_count);
}
}
})
} else {
app.util.request({
url: 'entry/wxapp/user',
data: {
controller: 'car.reduce_car_goods',
token: token,
goods_id: goods_id,
community_id: community_id,
quantity: 1,
sku_str: '',
buy_type,
pin_id: 0,
is_just_addcar: 1,
soli_id
},
dataType: 'json',
method: 'POST',
success: function (res) {
if (res.data.code == 3) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else {
let cartNum = res.data.total || 0;
if(soli_id>0) cartNum = res.data.goods_total_count || 0;
list[idx].car_count = res.data.cur_count;
that.setData({ list, cartNum})
status.indexListCarCount(goods_id, res.data.cur_count);
}
}
})
}
}
}

View File

@ -0,0 +1,49 @@
let app = getApp();
module.exports = {
data: {
// skin: app.globalData.skin,
isIpx: app.globalData.isIpx,
isblack: app.globalData.isblack,
goods_sale_unit: '件',
isparse_formdata: 0
},
onReady: function() {
let that = this;
app.getConfig().then(res=>{
let common_header_backgroundimage = res.data.common_header_backgroundimage || '';
app.globalData.common_header_backgroundimage = common_header_backgroundimage;
let skin = {};
let primaryColor = res.data.skin || '#4facfe';
let goods_sale_unit = res.data.goods_sale_unit;
skin.color = primaryColor;
if(primaryColor) {
skin.light = app.util.getLightColor(skin.color, 0.4);
skin.lighter = app.util.getLightColor(skin.color, 0.8);
}
let h = {};
let isparse_formdata = res.data.isparse_formdata;
let token = wx.getStorageSync('token');
if(token){
console.log('mixinsisparse_formdata', isparse_formdata)
h.isparse_formdata = isparse_formdata;
} else {
isparse_formdata = 0;
h.isparse_formdata = 0;
}
console.log(h)
wx.setStorageSync('isparse_formdata', isparse_formdata);
that.setData({ skin, goods_sale_unit, ...h })
app.globalData.skin = skin;
app.globalData.goods_sale_unit = goods_sale_unit;
}).catch(()=>{
that.setData({
skin: {
color: '#4facfe',
subColor: '#00f2fe',
lighter: '#fff9f4'
}
})
})
}
}

View File

@ -0,0 +1,185 @@
var a = require("../utils/public");
var app = getApp();
var status = require('../utils/index.js');
var util = require('../utils/util.js');
module.exports = {
data: {
visible: false,
stopClick: false,
updateCart: 0
},
vipModal: function(t) {
this.setData(t.detail)
},
authModal: function (t = false) {
t.detail && this.setData({ needAuth: true });
if (this.data.needAuth) {
this.setData({ showAuthModal: !this.data.showAuthModal });
return false;
}
return true;
},
openSku: function (t) {
if (!this.authModal()) return;
var that = this,
e = t.detail;
var goods_id = e.actId;
var options = e.skuList;
that.setData({
addCar_goodsid: goods_id
})
let list = options.list || [];
let arr = [];
if (list.length > 0) {
for (let i = 0; i < list.length; i++) {
let sku = list[i]['option_value'][0];
let temp = {
name: sku['name'],
id: sku['option_value_id'],
index: i,
idx: 0
};
arr.push(temp);
}
//把单价剔除出来begin
var id = '';
for (let i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
id = id + arr[i]['id'];
} else {
id = id + arr[i]['id'] + "_";
}
}
var cur_sku_arr = options.sku_mu_list[id];
that.setData({
sku: arr,
sku_val: 1,
cur_sku_arr: cur_sku_arr,
skuList: e.skuList,
visible: true,
showSku: true
});
} else {
let goodsInfo = e.skuList;
that.setData({
sku: [],
sku_val: 1,
skuList: [],
cur_sku_arr: goodsInfo
})
let formIds = {
detail: {
formId: ""
}
};
formIds.detail.formId = "the formId is a mock one";
that.gocarfrom(formIds);
}
},
/**
* 确认加入购物车
*/
gocarfrom: function (e) {
var that = this;
var is_just_addcar = 1;
wx.showLoading();
a.collectFormIds(e.detail.formId);
that.goOrder();
},
goOrder: function () {
let that = this;
let tdata = that.data;
if (tdata.can_car) {
tdata.can_car = false;
}
var token = wx.getStorageSync('token');
var community = wx.getStorageSync('community');
var community_id = community.communityId;
var goods_id = tdata.addCar_goodsid;
var quantity = tdata.sku_val;
var cur_sku_arr = tdata.cur_sku_arr;
var sku_str = '';
var is_just_addcar = 1;
if (cur_sku_arr && cur_sku_arr.option_item_ids) {
sku_str = cur_sku_arr.option_item_ids;
}
let data = {
goods_id,
community_id,
quantity,
sku_str,
buy_type: 'integral',
pin_id: 0,
is_just_addcar
}
util.addCart(data).then(res=>{
if(res.showVipModal==1) {
let { pop_vipmember_buyimage } = res.data;
that.triggerEvent("vipModal", { pop_vipmember_buyimage, showVipModal: true, visible: false });
} else {
if (res.data.code == 3 || res.data.code == 7) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else if (res.data.code == 4) {
wx.showToast({
title: '您未登录',
duration: 2000,
success: () => {
that.setData({
needAuth: true
})
}
})
} else if (res.data.code == 6) {
var msg = res.data.msg;
wx.showToast({
title: msg,
icon: 'none',
duration: 2000
})
} else {
if (is_just_addcar == 1) {
that.closeSku();
var pages_all = getCurrentPages();
if (pages_all.length > 3) {
wx.redirectTo({
url: `/eaterplanet_ecommerce/pages/order/placeOrder?type=integral`,
})
} else {
wx.navigateTo({
url: `/eaterplanet_ecommerce/pages/order/placeOrder?type=integral`,
})
}
}
}
}
})
},
/**
* 关闭购物车选项卡
*/
closeSku: function () {
this.setData({
visible: false,
stopClick: false
});
}
}