|
[mw_shl_code=html,true]var app = getApp();
Page({
data: {
restaurants : [],
component : {
scrollHeight : 0,
addRestaurantInput : ''
}
},
setComponentParam : function(k,v) {
var componentParams = this.data.component;
componentParams[k] = v;
this.setData({component : componentParams});
},
unshiftRestaurant : function(restaurantName) {
var crl = this.data.restaurants;
crl.unshift(restaurantName);
this.setData({restaurants : crl});
this.setComponentParam('addRestaurantInput','');
wx.setStorageSync('restaurants', crl);
},
onLoad: function () {
this.setComponentParam('scrollHeight',app.getSystemInfo().windowHeight - 65 - 54 - 8);
var rStroage = wx.getStorageSync('restaurants') || [];
this.setData({restaurants : rStroage});
wx.request({ url : 'https://jazzcai.larkapp.com/appVersion/check',
success : function(res){
console.log('ver number:' + res.data.ver + ' des:' + res.data.des);
}
});
},
onAddRestaurantInputBlur : function (e) {
this.setComponentParam('addRestaurantInput',e.detail.value);
},
onAddRestaurant : function (e) {
var restaurantName = this.data.component.addRestaurantInput;
if(!restaurantName || restaurantName == '') {
wx.showModal({ title : 'Tips', content : '没填你瞎点个毛线啊', showCancel : false });
return;
}
var that = this;
if(restaurantName.length < 1) {
wx.showModal({ title : 'Tips', content : '你确定就写这么点?',
success : function (res) {
if(!res.confirm) {
return;
}
that.unshiftRestaurant(that.data.component.addRestaurantInput);
}
});
} else {
this.unshiftRestaurant(this.data.component.addRestaurantInput);
}
},
onRandom : function(e) {
if(this.data.restaurants.length <= 0) {
wx.showModal({ title : '错误', content : '餐厅列表为空,请多加一个选项吧!', showCancel : false});
return;
}
var randomIndex = Math.floor(Math.random() * this.data.restaurants.length);
wx.showModal({ title : '随机结果', content : '"' + this.data.restaurants[randomIndex] + '" 要去么?'});
},
onDelete : function(e) {
var crl = this.data.restaurants;
crl.splice(e.target.dataset.itemIndex,1);
this.setData({restaurants:crl});
wx.setStorageSync('restaurants', crl);
}
})[/mw_shl_code]
|
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|