addwarning.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. lists:[{type:'',maxCount:'',maxTemp:'',minTemp:'',name:''}],
  8. seleteType:[{type:2,name:'报警'},{type:'1',name:'预警'}],
  9. name:''
  10. },
  11. /**
  12. * name,
  13. childList:[{
  14. maxCount:policFrequency,
  15. maxTemp:max,
  16. minTemp:min,
  17. type:2
  18. },{
  19. maxCount:earlyFrequency,
  20. maxTemp:earlyMax,
  21. minTemp:earlyMin,
  22. type:1
  23. }]
  24. *
  25. */
  26. setName(e){
  27. this.setData({name:e.detail.value})
  28. },
  29. submit(){
  30. var that = this;
  31. var lists = that.data.lists;
  32. var name = that.data.name;
  33. this.isList(lists).then(res=>{
  34. app.requestP({
  35. url:'/tempRule/add',
  36. method:'post',
  37. contentType:'application/json',
  38. data:{
  39. name,
  40. childList:lists
  41. }
  42. }).then(res=>{
  43. wx.navigateBack({
  44. delta:1
  45. })
  46. app.showToptip(that, "success",res.data.msg)
  47. }).catch(err=>{
  48. app.showToptip(that, "error",err.data.msg);
  49. })
  50. }).catch(err=>{
  51. app.showToptip(that, "error",err.text);
  52. })
  53. },
  54. getValue(e){
  55. var that = this;
  56. //下标
  57. var index = e.currentTarget.dataset.index;
  58. //数据
  59. var value = e.detail.value;
  60. //类型
  61. var type = e.currentTarget.dataset.type;
  62. value = value.replace(/[^\d\.-]/g,'')
  63. that.setValue(index,value,type);
  64. },
  65. setValue(index,value,type){
  66. var that = this;
  67. //动态设置属性值
  68. var type = "lists["+index+"]."+type;
  69. that.setData({
  70. [type] : value,
  71. })
  72. },
  73. addList: function(){
  74. var that = this;
  75. var lists = this.data.lists;
  76. this.isList(lists).then(res=>{
  77. var newData={type:'',maxCount:'',maxTemp:'',minTemp:''};
  78. lists.push(newData);
  79. that.setData({lists});
  80. }).catch(err=>{
  81. app.showToptip(that, "error",err.text);
  82. })
  83. },
  84. isList(lists){
  85. let flag;
  86. // var reg = /[0-9]$/;
  87. var reg = /^(\-|\+)?\d+(\.\d+)?$/;
  88. var text;
  89. return new Promise((resolve,reject)=>{
  90. for(var i =0;i<lists.length;i++){
  91. 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){
  92. reject({status:false,text:'温度不能为空'})
  93. break;
  94. }
  95. if(lists[i].maxTemp < lists[i].minTemp){
  96. reject({status:false,text:'最高温度不能小于最低温度'})
  97. break;
  98. }
  99. resolve({status:true,text:'输入正确'})
  100. }
  101. })
  102. },
  103. setType(e){
  104. var that = this;
  105. //下标
  106. var index = e.currentTarget.dataset.index;
  107. //数据
  108. var value = e.detail.value;
  109. var type = "lists["+index+"].type";
  110. var name = "lists["+index+"].name";
  111. var seleteType = this.data.seleteType;
  112. this.setData({
  113. [type] : seleteType[value].type,
  114. [name] : seleteType[value].name,
  115. })
  116. },
  117. /**
  118. * 生命周期函数--监听页面加载
  119. */
  120. onLoad: function (options) {
  121. },
  122. /**
  123. * 生命周期函数--监听页面初次渲染完成
  124. */
  125. onReady: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面显示
  129. */
  130. onShow: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面隐藏
  134. */
  135. onHide: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面卸载
  139. */
  140. onUnload: function () {
  141. },
  142. /**
  143. * 页面相关事件处理函数--监听用户下拉动作
  144. */
  145. onPullDownRefresh: function () {
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. onReachBottom: function () {
  151. },
  152. /**
  153. * 用户点击右上角分享
  154. */
  155. onShareAppMessage: function () {
  156. }
  157. })