ruleManage.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. new Vue({
  2. el: '#app',
  3. data: function() {
  4. return {
  5. ruleLi: [],
  6. ruleVis: true,
  7. editVis: true,
  8. tabBar: 0,
  9. treeLi: [],
  10. defaultProps: {
  11. children: 'children',
  12. label: 'group_name'
  13. },
  14. ruleForm: {
  15. rule_name:"",
  16. text:"",
  17. speed: 0,
  18. rule_interval: 0,
  19. statusn: true,
  20. rule_describe:"",
  21. checkKey: []
  22. },
  23. rules: {
  24. rule_name: [{ required: true, message: '请输入规则名称', trigger: 'blur' },],
  25. text: [{ required: true, message: '请输入规则内容', trigger: 'blur' }],
  26. speed: [{ required: true, message: '请输入报警速度', trigger: 'blur' }],
  27. rule_interval: [{ required: true, message: '请输入报警间隔', trigger: 'blur' }],
  28. },
  29. }
  30. },
  31. created() {
  32. _this = this;
  33. _this.getList();
  34. _this.getTree();
  35. },
  36. mounted(){
  37. },
  38. methods:{
  39. getList(){
  40. const loading = this.$loading({
  41. background: 'rgba(0, 0, 0, 0.4)'
  42. })
  43. let _opts = {
  44. url: baseUrl + "/SelRuleConfig?add_userid=1&_t="+new Date().getTime(),
  45. type:"GET"
  46. };
  47. let _data = {};
  48. getAxios(_opts,_data,{}).then((res) => {
  49. if(res.result == "ok"){
  50. _this.ruleLi = res.data;
  51. _this.checkForm(_this.ruleLi[0]);
  52. }else{
  53. _this.ruleLi = [];
  54. }
  55. loading.close();
  56. })
  57. },
  58. getTree() {
  59. let _opts = {
  60. url: baseUrl + "/SelGroupConfig?add_userid=1&type=2&_t=" + new Date().getTime(),
  61. type:"GET"
  62. };
  63. let _data = {};
  64. getAxios(_opts, _data,{}).then((res) => {
  65. _this.treeLi = getTree(res.data, 0);
  66. })
  67. },
  68. changCheck(nodes,keys){
  69. let _obj = keys.checkedNodes;
  70. let _arr = [];
  71. _obj.forEach((item,index) => {
  72. if(item.type == 1){
  73. _arr.push(item.id);
  74. }
  75. })
  76. _this.ruleForm.checkKey = _arr;
  77. },
  78. changTab(id){
  79. let _obj = _this.ruleLi;
  80. _this.checkForm(_obj[id]);
  81. _this.tabBar = id;
  82. },
  83. checkForm(_dat){
  84. let _obj = JSON.parse(JSON.stringify(_dat));
  85. _obj["checkKey"] = JSON.parse(_obj.fence_ids).fence_ids;
  86. _obj["statusn"] = _obj.rule_status == 1?true:false;
  87. _this.ruleForm = _obj;
  88. _this.editVis = true;
  89. setTimeout(() => {
  90. _this.$nextTick(function() {
  91. _this.$refs.treeRef.setCheckedKeys(_this.ruleForm.checkKey);
  92. })
  93. }, 100)
  94. },
  95. newAdd(){
  96. _this.ruleForm = {
  97. rule_name:"",
  98. text:"",
  99. speed: 0,
  100. rule_interval: 0,
  101. statusn: true,
  102. rule_describe:"",
  103. checkKey: []
  104. };
  105. _this.editVis = false;
  106. _this.tabBar = -1;
  107. _this.$refs["form"].resetFields();
  108. setTimeout(() => {
  109. _this.$nextTick(function() {
  110. _this.$refs.treeRef.setCheckedKeys(_this.ruleForm.checkKey);
  111. })
  112. }, 100)
  113. },
  114. saveRule(){
  115. let _obj = _this.ruleForm;
  116. if(_obj.rule_name == ""&&_obj.text == ""&&_obj.spedd == ""&&_obj.rule_interval == ""){
  117. _this.$message({
  118. type: 'warning',
  119. message: '请先填写完内容!'
  120. });
  121. return;
  122. }
  123. _obj.rule_status = _obj.statusn?1:0;
  124. _obj.fence_ids = JSON.stringify({fence_ids: _obj.checkKey});
  125. _obj.add_userid = 1;
  126. const loading = this.$loading({
  127. background: 'rgba(0, 0, 0, 0.4)'
  128. })
  129. let _opts = {
  130. url: baseUrl + "/AddRuleConfig?_t=" + new Date().getTime(),
  131. type:"GET"
  132. };
  133. let _data = _obj;
  134. getAxios(_opts, _data,{}).then((res) => {
  135. if (res.result == "ok") {
  136. _this.$message({
  137. type: 'success',
  138. message: '操作成功!'
  139. });
  140. _this.getList();
  141. } else {
  142. _this.$message.error('操作失败');
  143. }
  144. loading.close();
  145. })
  146. },
  147. // 删除
  148. delRule(){
  149. if(_this.ruleForm.id != undefined){
  150. _this.$confirm('你确定要删除< '+(_this.ruleForm.rule_name)+' >吗?', '温馨提示', {
  151. confirmButtonText: '确定',
  152. cancelButtonText: '取消',
  153. type: 'warning'
  154. }).then(() => {
  155. _this.$message({
  156. type: 'success',
  157. message: '删除成功!'
  158. });
  159. }).catch(() => {});
  160. }
  161. },
  162. }
  163. })