const app = getApp() Page({ /** * 页面的初始数据 */ data: { lists:[{type:'',maxCount:'',maxTemp:'',minTemp:'',name:''}], seleteType:[{type:2,name:'报警'},{type:'1',name:'预警'}], name:'' }, /** * name, childList:[{ maxCount:policFrequency, maxTemp:max, minTemp:min, type:2 },{ maxCount:earlyFrequency, maxTemp:earlyMax, minTemp:earlyMin, type:1 }] * */ setName(e){ this.setData({name:e.detail.value}) }, submit(){ var that = this; var lists = that.data.lists; var name = that.data.name; this.isList(lists).then(res=>{ app.requestP({ url:'/tempRule/add', method:'post', contentType:'application/json', data:{ name, childList:lists } }).then(res=>{ wx.navigateBack({ delta:1 }) app.showToptip(that, "success",res.data.msg) }).catch(err=>{ app.showToptip(that, "error",err.data.msg); }) }).catch(err=>{ app.showToptip(that, "error",err.text); }) }, getValue(e){ var that = this; //下标 var index = e.currentTarget.dataset.index; //数据 var value = e.detail.value; //类型 var type = e.currentTarget.dataset.type; value = value.replace(/[^\d\.-]/g,'') that.setValue(index,value,type); }, setValue(index,value,type){ var that = this; //动态设置属性值 var type = "lists["+index+"]."+type; that.setData({ [type] : value, }) }, addList: function(){ var that = this; var lists = this.data.lists; this.isList(lists).then(res=>{ var newData={type:'',maxCount:'',maxTemp:'',minTemp:''}; lists.push(newData); that.setData({lists}); }).catch(err=>{ app.showToptip(that, "error",err.text); }) }, isList(lists){ let flag; // var reg = /[0-9]$/; var reg = /^(\-|\+)?\d+(\.\d+)?$/; var text; return new Promise((resolve,reject)=>{ for(var i =0;i