mixins.js 3.2 KB
Newer Older
yanzhongrong's avatar
yanzhongrong committed
1
// 公共文件
yanzhongrong's avatar
yanzhongrong committed
2 3 4 5 6 7
import { formInit } from '../const'

export const DetailMixins = {
  data() {
    return {
      form: {},
neogcg's avatar
neogcg committed
8
      flag: true,
yanzhongrong's avatar
yanzhongrong committed
9
      formFunc: null,
neogcg's avatar
neogcg committed
10
      isOpenSelect: [{
yanzhongrong's avatar
yanzhongrong committed
11 12
        key: 0,
        label: "未开通"
neogcg's avatar
neogcg committed
13
      },
yanzhongrong's avatar
yanzhongrong committed
14 15 16
      {
        key: 1,
        label: "已开通"
neogcg's avatar
neogcg committed
17
      }],
yanzhongrong's avatar
yanzhongrong committed
18 19 20 21
      defaultList: [{
        name: '设备状态',
        value: '正常'
      }]
yanzhongrong's avatar
yanzhongrong committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    }
  },
  watch: {
    type: {
      immediate: true,
      handler(newV) {
        this.formFunc = formInit(newV)
      },
    },
    curInfo: {
      immediate: true,
      handler(newV) {
        this.form = this.formFunc(newV)
      },
    },
  },
  props: {
    curInfo: {
      type: Object,
neogcg's avatar
neogcg committed
41
      default: () => { },
yanzhongrong's avatar
yanzhongrong committed
42 43
    },
    type: {
yanzhongrong's avatar
yanzhongrong committed
44
      type: [Number, String],
yanzhongrong's avatar
yanzhongrong committed
45 46
      defualt: null,
    },
yanzhongrong's avatar
yanzhongrong committed
47 48 49 50 51 52 53 54
    curId: {
      type: [Number, String],
      defualt: null,
    },
    selectId: {
      type: [Number, String],
      defualt: null,
    }
yanzhongrong's avatar
yanzhongrong committed
55
  },
neogcg's avatar
neogcg committed
56 57
  computed: {
    statusList() {
yanzhongrong's avatar
yanzhongrong committed
58
      if (this.form.status.length) {
neogcg's avatar
neogcg committed
59 60 61 62 63 64
        for (let i = 0; i < this.form.status.length; i++) {
          if (i % 2 != 0) {
            this.form.status[i].value = this.dateFormat(this.form.status[i].value, 'yyyy-MM-dd HH:mm:ss')
          }
        }
        return this.form.status
yanzhongrong's avatar
yanzhongrong committed
65 66
      } else {
        return this.defaultList
neogcg's avatar
neogcg committed
67 68 69
      }
    }
  },
yanzhongrong's avatar
yanzhongrong committed
70
  methods: {
neogcg's avatar
neogcg committed
71 72 73 74 75 76 77 78 79 80
    info() {
      let params = {
        id: this.form.baseInfo.id,
        isOpen: this.form.baseInfo.isOpen
      }
      return params
    },
    editbtn() {
      this.flag = false
    },
neogcg's avatar
neogcg committed
81 82 83
    levelcolor() {
      let la = document.getElementsByClassName("levelData");
      for (var i = 0; i < this.statusList.length; i++) {
neogcg's avatar
neogcg committed
84
        if (this.statusList[i].value == "连接正常") {
neogcg's avatar
neogcg committed
85
          la[i].style.color = "green";
neogcg's avatar
neogcg committed
86 87
          la[i].innerHTML = "连接正常"
        }  if (this.statusList[i].value == "连接异常") {
neogcg's avatar
neogcg committed
88
          la[i].style.color = "#f00";
neogcg's avatar
neogcg committed
89
          la[i].innerHTML = "告警"
neogcg's avatar
neogcg committed
90
        }  if (this.statusList[i].value == "正常") {
neogcg's avatar
neogcg committed
91
          la[i].style.color = "green";
neogcg's avatar
neogcg committed
92 93
          la[i].innerHTML = "正常"
        } if (this.statusList[i].value == "紧急") {
neogcg's avatar
neogcg committed
94
          la[i].style.color = "#f00";
neogcg's avatar
neogcg committed
95
          la[i].innerHTML = "紧急告警"
neogcg's avatar
neogcg committed
96
        }  if (this.statusList[i].value == "重要") {
neogcg's avatar
neogcg committed
97
          la[i].style.color = "#f89850";
neogcg's avatar
neogcg committed
98
          la[i].innerHTML = "重要告警"
neogcg's avatar
neogcg committed
99
        } if (this.statusList[i].value == "一般") {
neogcg's avatar
neogcg committed
100
          la[i].style.color = "#ead906";
neogcg's avatar
neogcg committed
101 102
          la[i].innerHTML = "一般告警"
        } 
neogcg's avatar
neogcg committed
103 104
      }
    },
neogcg's avatar
neogcg committed
105
    dateFormat(date, format) {
yanzhongrong's avatar
yanzhongrong committed
106 107 108
      if(date == null || date == '-') {
        return '-'
      }
neogcg's avatar
neogcg committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
      date = new Date(date);
      var o = {
        'M+': date.getMonth() + 1, //month
        'd+': date.getDate(), //day
        'H+': date.getHours(), //hour
        'm+': date.getMinutes(), //minute
        's+': date.getSeconds(), //second
        'S': date.getMilliseconds() //millisecond
      };
      if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));

      for (var k in o)
        if (new RegExp('(' + k + ')').test(format))
          format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));

      return format;
neogcg's avatar
neogcg committed
126
    },
yanzhongrong's avatar
yanzhongrong committed
127 128
  },
}