settings.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // pages/waterabnormal/settings/settings.js
  2. const app = getApp();
  3. const warningTypes = [{
  4. value: 3,
  5. label:'单日用水量少于0.01吨'
  6. },{
  7. value:4,
  8. label:'单日用水量超过2吨'
  9. }];
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. error: '',
  16. warningTypes,
  17. formData: {
  18. warningType: '',
  19. },
  20. rules: [],
  21. selectShow: false
  22. },
  23. selectHide() {
  24. this.setData({
  25. selectShow: false
  26. })
  27. },
  28. formChange(e) {
  29. const {
  30. file
  31. } = e.currentTarget.dataset;
  32. let label = e.detail.label || '';
  33. this.setData({
  34. [`formData.${file}`]: e.detail.value,
  35. [`formData.${file}Txt`]: label,
  36. })
  37. },
  38. submit() {
  39. const {
  40. warningType
  41. } = this.data.formData;
  42. let error = '';
  43. if (!warningType) {
  44. error = '请选择预警类型';
  45. }
  46. if (error) {
  47. this.setData({
  48. error
  49. })
  50. return;
  51. }
  52. this.addWarningList(warningType);
  53. },
  54. remove(e) {
  55. const {
  56. index
  57. } = e.currentTarget.dataset;
  58. this.deleteWarningList(index);
  59. },
  60. //获取预警规则 /warningRule/getList
  61. getWarningList() {
  62. app.$http.get('/warningRule/getList').then(({
  63. status,
  64. data = {}
  65. }) => {
  66. if (status == 0) {
  67. this.setData({
  68. rules: data
  69. })
  70. }
  71. }).catch(() => {})
  72. },
  73. //添加预警规则 warningType,
  74. addWarningList(warningType) {
  75. app.$http.postForm('/warningRule/add', {
  76. warningType: warningType
  77. }).then(({
  78. status,
  79. msg,
  80. data = {}
  81. }) => {
  82. if (status == 0) {
  83. wx.showToast({
  84. title: '添加成功',
  85. icon: 'none'
  86. })
  87. this.getWarningList();
  88. } else {
  89. wx.showToast({
  90. title: msg,
  91. icon: 'none'
  92. })
  93. }
  94. }).catch(() => {})
  95. },
  96. //删除预警规则
  97. deleteWarningList(id) {
  98. app.$http.deleteForm('/warningRule/del', {
  99. id
  100. }).then(({
  101. status,
  102. data = {}
  103. }) => {
  104. if (status == 0) {
  105. wx.showToast({
  106. title: '删除成功',
  107. icon: 'none'
  108. })
  109. this.getWarningList();
  110. }
  111. }).catch(() => {})
  112. },
  113. /**
  114. * 生命周期函数--监听页面加载
  115. */
  116. onLoad: function (options) {
  117. this.getWarningList();
  118. },
  119. /**
  120. * 生命周期函数--监听页面初次渲染完成
  121. */
  122. onReady: function () {
  123. }
  124. })