|

楼主 |
发表于 2018-10-30 16:28:47
|
显示全部楼层
Model.prototype.addDishClick = function(event) {
var self = this;
var row = event.bindingContext.$object;
row.val("fCount", row.val("fCount") + 1);
self.getElementByXid('iconShoppingTrolley').style.color = "#0085d0";
self.getElementByXid('button9').style.color = "#fff";// zty
// 2018.10.9
self.getElementByXid('button9').style.backgroundColor = "#0085d0";// zty
// 2018.10.9
self.getElementByXid('totalPrice').style.color = "#ff6600";
self.getElementByXid('nothing').style.display = "none";
self.getElementByXid('rmb').style.display = "block";
self.getElementByXid('papawNum').style.display = "block";
// self.getElementByXid('totalPriceValue').innerHTML =
// "200"
var row = event.bindingContext.$object;
var dishesName = row.val("foodName");// 获取菜品名称
var dishesPrice = row.val("price");// 获取菜品价格
var typeId = row.val("typeId");// 获取菜品类别id
var pac = 0;
if (typeId == 0) {
pac = 1;
} else {
pac = 2;
}
var carData = self.comp("carData");// 获取carData组件
// 当carData中的不存在此菜品时
if (carData.find([ 'dishesName' ], [ dishesName ]).length === 0) {
carData.newData({
index : 0,
defaultValues : [ {
"typeId" : typeId,
"pac" : pac,
"dishesName" : dishesName,
"dishesPrice" : dishesPrice,
"guige" : " ",
"number" : 1
} ]
});
var pattern = new RegExp("[.]"); //
var rs = "";
var floatPrice;
for (var i = 0; i < dishesPrice.toString().length; i++) {
rs += dishesPrice.toString().substr(i, 1).replace(pattern, '');
}
if (rs == dishesPrice) {// dishesPrice是int类型
floatPrice = parseFloat(dishesPrice).toFixed(2);
} else {// dishesPrice是float类型
floatPrice = dishesPrice;
}
// self.carAllPrice =
// number.accAdd(self.carAllPrice, floatPrice);
self.carAllPrice = globlaData.add(self.carAllPrice, floatPrice, 2);
// alert(10.01+12+"cccccc")
var totalPriceData = self.comp("totalPriceData");
totalPriceData.newData({
index : 0,
defaultValues : [ {
"totalPrice" : self.carAllPrice.toFixed(2)
} ]
});
// 获取carData中菜品的个数
var carSize = self.comp("carData").count();
// 获取carSizeData组件
var carSizeData = self.comp("carSizeData");
carSizeData.newData({
index : 0,
defaultValues : [ {
"carSize" : carSize
} ]
});
} else {
var rows = carData.find([ 'dishesName' ], [ dishesName ]);
rows.val("number", rows.val("number") + 1);
}
};
我这么写咋提示我rows.val is not a function。前面咋没事 |
|