3 Star 1 Fork 1

王风/小程序拼团

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.49 KB
一键复制 编辑 原始数据 按行查看 历史
王风 提交于 2018-07-07 10:30 . 线上版本
//app.js
App({
data: {
//url: "https://webapidvp.ruemall.com/rongxun-gateway-services/",
//url: "http://47.95.145.231:8090/rongxun-gateway-services/",
url: "https://webapi.ruemall.com/rongxun-gateway-services/",
//url: "http://192.168.1.57:8080/rongxun-gateway-services/",
//reUrl: "https://dvp.rongxwy.com/base/rest/v3.1.0/"
reUrl: "https://www.rongxwy.com/base/rest/v3.1.0/"
},
wxAjax: function (fun, url, bodyObj, obj) {
var servername = url.split("/")[url.split("/").length - 1];
var myDate = new Date();
var timestamp = myDate.getTime();
var year = myDate.getFullYear();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var hour = myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours();
var minute = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();
var second = myDate.getSeconds() < 10 ? "0" + myDate.getSeconds() : myDate.getSeconds();
var num = Math.random();
num = Math.ceil(num * 9999);
var messageid = year.toString() + month.toString() + day.toString() + hour.toString() + minute.toString() + second.toString() + num;
var headerObj = {
"terminal": 4,
"transaction_type": servername,
"token": wx.getStorageSync('token'),
"loginTime": wx.getStorageSync('loginTime'),
"time_stamp": timestamp,
"message_id": messageid,
"mobile": wx.getStorageSync('userid')
}
var headerStr = JSON.stringify(headerObj);
var bodyStr = JSON.stringify(bodyObj);
var dataObj = {
msg: '{"header":' + headerStr + ',"body":' + bodyStr + '}'
}
wx.request({
url: url,
data: dataObj,
success: function (res) {
fun(res, obj)
},
fail: function (res) {
fun(res, obj)
}
})
},
//获取购物车数量
getCartNum(obj) {
var url = getApp().data.url + 'shoppingcart/getCartCount';
var body = {
supermarket_id: wx.getStorageSync('supermarket_id'),
is_check: '2'
};
getApp().wxAjax(this.returnCartNum, url, body, obj);
},
returnCartNum(res, obj) {
obj.setData({
num: res.data.body.num
})
},
//增加商品
addPro(obj){
console.log(obj)
var url = getApp().data.url + 'shoppingcart/addShoppingCart';
var body = {
quantity: '1',
supermarket_id: wx.getStorageSync('supermarket_id'),
sku: obj.data.sku
};
if (obj.data.addflage == 1) {
obj.setData({
addflage: 2
})
getApp().wxAjax(this.addProSug, url, body,obj);
}
},
addProSug(res,obj) {
var resObj = res.data;
if (resObj.header.res_code == 0) {
obj.setData({
addflage: 1
})
wx.showToast({
title: '添加成功',
})
getApp().getCartNum(obj);
} else {
wx.showToast({
title: resObj.header.message,
icon: 'none'
})
obj.setData({
addflage: 1
})
}
},
//底部导航
bottomNav(e) {
var kind = e.currentTarget.dataset.kind;
var isPgae = e.currentTarget.dataset.ispage;
var url;
if (kind == "index" && isPgae == "1") {
wx.redirectTo({
url: '../eIndex/eIndex'
})
} else if (kind == "calss" && isPgae == "1") {
wx.redirectTo({
url: '../classification/classification'
})
} else if (kind == "cart" && isPgae == "1") {
wx.redirectTo({
url: '../cart/cart'
})
} else if (kind == "my" && isPgae == "1") {
wx.redirectTo({
url: '../my/my'
})
}
},
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chrisWF/small_program_collage.git
git@gitee.com:chrisWF/small_program_collage.git
chrisWF
small_program_collage
小程序拼团
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385