|
本帖最后由 四根木头人 于 2016-5-8 16:40 编辑
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
//手机ID插件
require("cordova!cordova-plugin-device")
var Model = function(){
this.callParent();
this.userID;
this.loadUser = true;
this.loadOrder = true;
};
//菜单页
//图片的绝对路径
Model.prototype.getImgUrl = function(imgUrl){
return require.toUrl("./img/"+imgUrl);
};
//来一份
Model.prototype.laiyifenClick = function(event){
var row = event.bindingContext.$object;
var rows = this.comp("gouwucheData").find(["dgID"],[row.getID()]);
if(rows.length == 0){
this.comp("gouwucheData").newData({
defaultValues:[{
"dgID":row.getID(),
"dgMc":row.val("fName"),
"dgDj":row.val("fPrice"),
"dgSl":1
}]
})
}
else{
rows[0].val("dgSl",rows[0].val("dgSl") + 1);
}
};
//购物车页
//加
Model.prototype.jiaClick = function(event){
var row = event.bindingContext.$object;
row.val("dgSl",row.val("dgSl") + 1);;
};
//减
Model.prototype.jianClick = function(event){
var row = event.bindingContext.$object;
if(row.val("dgSl")>0)
row.val("dgSl",row.val("dgSl") - 1);
};
//我的联系方式获取用户ID
Model.prototype.modelLoad = function(event){
var me = this;
this.userID = "user";
//过滤条件
this.comp("yonghuData").setFilter("filter1","fID = '" + this.userID + "'");
this.comp("dingdanData").setFilter("filter1","fUserID = '" + this.userID + "'");
//判别浏览方式
if(justep.Browser.isX5App){
document.addEventListener("deviceready", function(){
me.userID = window.device.uuid;
});
}
};
//我的信息页
Model.prototype.loadUserData = function(event){
if(this.loadUser){
var yonghuData = this.comp("yonghuData");
yonghuData.refreshData();
if(yonghuData.getCount() == 0){
yonghuData.newData({
defaulValues:[{
"fID":this.userID,
"fName":"新用户"
}]
})
}
}
this.loadUser = false;
};
Model.prototype.wodeContentActive = function(event){
this.loadUserData()
};
Model.prototype.guowucheContentActive = function(event){
this.loadUserData()
};
//保存
Model.prototype.baocunClick = function(event){
this.comp("yonghuData").saveData({
"onSuccess":function(){
justep.Util.hint("用户信息保存成功");
}
})
};
//订单页
Model.prototype.dingdanContentActive = function(event){
if(this.loadOrder){
this.comp("dingdanData").clear();
this.comp("dingdanList").refresh(true);
this.loadOrder = false;
}
};
//下单
Model.prototype.xiadanClick = function(event){
var dingdanData = this.comp("dingdanData");
var yonghuData = this.comp("yonghuData");
var gouwucheData = this.comp("gouwucheData");
var me =this;
var content = "";
gouwucheData.each(function(options){
content = content + options.row.val("dgMc") + "(" + options.row.val("dgSl") + ")";
});
dingdanData.newData({
index:0,
defaultValues:[{
"fID":justep.UUID.createUUID(),
"fCreataTime":justep.Date.toString(new Date(),justep.Date.STANDART_FORMAT),
"fContent":content,
"fUserID":yonghuData.val("fID"),
"fUserName":yonghuData.val("fUserName"),
"fPhoneNumber":yonghuData.val("fPhoneNumber"),
"fAddress":yonghuData.val("fAddress"),
"fSum":this.comp("hejiData").val("dgHj"),
}]
})
dingdanData.saveData({
onSuccess:function(){
justep.Util.hint("下单成功");
guowucheData.clear();
me.comp("contents").to("dingdanContent");
}
})
};
Model.prototype.dingdanDataSaveCreateParam = function(event){
event.param.tables.push(this.comp("yonghuData").toJson(true));
};
//提交成功
Model.prototype.dingdanDataSaveCommit = function(event){
this.comp("yonghuData").applyUpdates();
};
return Model;
});
打开一直显示老用户信息,user换成user1的话无法保存,下单提示购物车Data is not defind,订单页新订单不显示下单时间 |
|