| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 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<lists.length;i++){
- if(String(lists[i].type).length==0 || String(lists[i].maxCount).length==0 || String(lists[i].maxTemp).length==0 || String(lists[i].minTemp).length==0){
- reject({status:false,text:'温度不能为空'})
- break;
- }
- if(lists[i].maxTemp < lists[i].minTemp){
- reject({status:false,text:'最高温度不能小于最低温度'})
- break;
- }
- resolve({status:true,text:'输入正确'})
- }
- })
- },
- setType(e){
- var that = this;
- //下标
- var index = e.currentTarget.dataset.index;
- //数据
- var value = e.detail.value;
- var type = "lists["+index+"].type";
- var name = "lists["+index+"].name";
- var seleteType = this.data.seleteType;
- this.setData({
- [type] : seleteType[value].type,
- [name] : seleteType[value].name,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|