123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- new Vue({
- el: '#app',
- data: function() {
- return {
- ruleLi: [],
- ruleVis: true,
- editVis: true,
- tabBar: 0,
- treeLi: [],
- defaultProps: {
- children: 'children',
- label: 'group_name'
- },
- ruleForm: {
- rule_name:"",
- text:"",
- speed: 0,
- rule_interval: 0,
- statusn: true,
- rule_describe:"",
- checkKey: []
- },
- rules: {
- rule_name: [{ required: true, message: '请输入规则名称', trigger: 'blur' },],
- text: [{ required: true, message: '请输入规则内容', trigger: 'blur' }],
- speed: [{ required: true, message: '请输入报警速度', trigger: 'blur' }],
- rule_interval: [{ required: true, message: '请输入报警间隔', trigger: 'blur' }],
- },
- }
- },
- created() {
- _this = this;
- _this.getList();
- _this.getTree();
- },
- mounted(){
-
- },
- methods:{
- getList(){
- const loading = this.$loading({
- background: 'rgba(0, 0, 0, 0.4)'
- })
- let _opts = {
- url: baseUrl + "/SelRuleConfig?add_userid=1&_t="+new Date().getTime(),
- type:"GET"
- };
- let _data = {};
- getAxios(_opts,_data,{}).then((res) => {
- if(res.result == "ok"){
- _this.ruleLi = res.data;
- _this.checkForm(_this.ruleLi[0]);
- }else{
- _this.ruleLi = [];
- }
- loading.close();
- })
- },
- getTree() {
- let _opts = {
- url: baseUrl + "/SelGroupConfig?add_userid=1&type=2&_t=" + new Date().getTime(),
- type:"GET"
- };
- let _data = {};
- getAxios(_opts, _data,{}).then((res) => {
- _this.treeLi = getTree(res.data, 0);
- })
- },
- changCheck(nodes,keys){
- let _obj = keys.checkedNodes;
- let _arr = [];
- _obj.forEach((item,index) => {
- if(item.type == 1){
- _arr.push(item.id);
- }
- })
- _this.ruleForm.checkKey = _arr;
- },
- changTab(id){
- let _obj = _this.ruleLi;
- _this.checkForm(_obj[id]);
- _this.tabBar = id;
- },
- checkForm(_dat){
- let _obj = JSON.parse(JSON.stringify(_dat));
- _obj["checkKey"] = JSON.parse(_obj.fence_ids).fence_ids;
- _obj["statusn"] = _obj.rule_status == 1?true:false;
- _this.ruleForm = _obj;
- _this.editVis = true;
- setTimeout(() => {
- _this.$nextTick(function() {
- _this.$refs.treeRef.setCheckedKeys(_this.ruleForm.checkKey);
- })
- }, 100)
- },
- newAdd(){
- _this.ruleForm = {
- rule_name:"",
- text:"",
- speed: 0,
- rule_interval: 0,
- statusn: true,
- rule_describe:"",
- checkKey: []
- };
- _this.editVis = false;
- _this.tabBar = -1;
- _this.$refs["form"].resetFields();
- setTimeout(() => {
- _this.$nextTick(function() {
- _this.$refs.treeRef.setCheckedKeys(_this.ruleForm.checkKey);
- })
- }, 100)
- },
- saveRule(){
- let _obj = _this.ruleForm;
- if(_obj.rule_name == ""&&_obj.text == ""&&_obj.spedd == ""&&_obj.rule_interval == ""){
- _this.$message({
- type: 'warning',
- message: '请先填写完内容!'
- });
- return;
- }
- _obj.rule_status = _obj.statusn?1:0;
- _obj.fence_ids = JSON.stringify({fence_ids: _obj.checkKey});
- _obj.add_userid = 1;
- const loading = this.$loading({
- background: 'rgba(0, 0, 0, 0.4)'
- })
- let _opts = {
- url: baseUrl + "/AddRuleConfig?_t=" + new Date().getTime(),
- type:"GET"
- };
- let _data = _obj;
- getAxios(_opts, _data,{}).then((res) => {
- if (res.result == "ok") {
- _this.$message({
- type: 'success',
- message: '操作成功!'
- });
- _this.getList();
- } else {
- _this.$message.error('操作失败');
- }
- loading.close();
- })
- },
- // 删除
- delRule(){
- if(_this.ruleForm.id != undefined){
- _this.$confirm('你确定要删除< '+(_this.ruleForm.rule_name)+' >吗?', '温馨提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- _this.$message({
- type: 'success',
- message: '删除成功!'
- });
- }).catch(() => {});
- }
- },
- }
- })
|