|
楼主 |
发表于 2017-1-8 08:00:47
|
显示全部楼层
js
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
var baas = require("$UI/demo/baas/baas");
require("cordova!org.apache.cordova.device");
var Model = function(){
this.callParent();
this.userid;
this.loadUser =true;
};
Model.prototype.modelLoad = function(event){
var me = this;
this.userID = "user";
if(justep.Browser.isX5App){
document.addEventListener("deviceready", function(){
me.userID = window.device.uuid;
});
}
this.comp("userData").setFilter("filterl","fID = '" + this.useri + "'");
this.comp("orderData").setFilter("filterl","fUserID = '" + this.useri + "'");
};
Model.prototype.getImgUrl = function(imgUrl){
return require.toUrl("./img/"+imgUrl);
};
Model.prototype.addCartBtnClick = function(event){
var row = event.bindingContext.$object;
var rows = this.comp("cartData").find([ "fMenuID" ], [ row.getID() ]);
if (rows.length == 0) {
this.comp("cartData").newData({
defaultValues : [ {
"fMenuID" : row.getID(),
"fMenuName" : row.val("fName"),
"fPrice" : row.val("fPrice"),
"fCount" : 1
}]
})
}else{
rows[0].val("fCount",rows[0].val("fCount") + 1);
}
};
Model.prototype.addBtnClick = function(event){
var row = event.bindingContext.$object;
row.val("fCount", row.val("fCount") + 1);
};
Model.prototype.subBtnClick = function(event){
var row = event.bindingContext.$object;
if (row.val("fCount") > 0)
row.val("fCount",row.val("fCount") - 1);
};
Model.prototype.loadUserData = function(){
if (this.loadUser){
var user = this.comp("userData");
userData.refreshData();
if (userData.getCount() == 0){
userData.newData({
defaultValues : [{
"fID" : this.userID,
"fName" : "新用户"
}]
})
}
this.loadUser = false;
}
};
Model.prototype.ownContentActive = function(event){
this.loadUserData();
};
Model.prototype.cartContentActive = function(event){
this.loadUserData();
};
Model.prototype.saveUserBtnClick = function(event){
this.comp("userData").saveData({
"onSuccess": function(){
justep.Util.hint("用户信息保存成功")
}
})
};
Model.prototype.orderContentActive = function(event){
is(this.loadOrder){
this.comp("orderData").clear();
this.comp("orderList").refresh(true);
this.loadOrder = false;
}
};
Model.prototype.button6Click = function(event){
var orderData = this.comp("orderData");
var userData = this.comp("userData");
var cartData = this.comp("cartData");
var me = this;
var content = "";
cartData.eacn(function(optlons){
content = content + options.row.val("fMenuName") + "(" + options.row.val("fCount") + ")";
});
orderData.newData({
index: 0,
defaultValues:[{
"fID":justep.UUID.createUUID(),
"fcreateTime": justep.Date.toString(new Date(),justep.Date.STANDART_FORMAT),
"FContent": content,
"fUserID": orderData.val("fID"),
"fUserName": orderData.val("fName"),
"fPnoneNumber": orderData.val("fPnoneNumber"),
"fAddress": orderData.val("fAddress"),
"fSum": this.comp("calcData").val("fSumMoney")
}]
})
orderData.saveData({
onSuccess: function(){
justep.Util.hint("下单成功");
cartData.clear();
me.comp("contents").to("ordeContent");
}
})
};
Model.prototype.orderDataSaveCreateParam = function(event){
event.param.tables.push(this.comp("userData").toJson(true));
};
Model.prototype.orderDataSaveCommit = function(event){
this.comp("userData").applyUpdates();
};
return Model;
}); |
|