Input.vue 4.04 KB
Newer Older
liuxin committed
1
<template>
2 3
  <el-input :class="{ 'greenClass': isGreen && isDisplay, 'yellowClass': isYellow && isDisplay, 'redClass': isRed && isDisplay }"
    v-storeModify :id="id" ref="form-item" v-model="model" v-bind="attrs" v-on="$listeners" v-bind:disabled="isDisable">
liushikai committed
4 5 6 7
    <template v-slot:suffix>
      <slot name="suffix"></slot>
    </template>
  </el-input>
liuxin committed
8 9 10 11
</template>

<script>
export default {
12
  inject: ["root"],
liuxin committed
13 14 15 16 17 18 19 20 21 22 23
  props: {
    value: {
      type: [String, Number],
      default: undefined
    },
    disabled: {
      type: Boolean,
      default: false
    },
    id: {
      type: String,
fukai committed
24
      default: undefined
liuxin committed
25 26
    }
  },
27
  data() {
28
    return {
29 30 31
      isRed: false,
      isGreen: false,
      isYellow: false
32 33
    }
  },
34 35 36
  directives: {
    storeModify: {
      update(el, bind, vnode) {
37 38 39
        let _this = vnode.context
        let key = vnode.parent.data.model.expression
        let keyArray = key.split('.')
40
        let curKey = keyArray.pop()
41
        let resultKey = keyArray.join(".")
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

        let deepData = _this.getProperty(resultKey, _this.root)
        if (deepData && Array.isArray(deepData.modifySet)) {
          if (deepData.modifySet.includes(curKey)) {
            _this.isRed = true
          }
        }
        if (deepData && Array.isArray(deepData.ebankSet)) {
          if (deepData.ebankSet.includes(curKey)) {
            _this.isYellow = true

          }
        }
        if (deepData && Array.isArray(deepData.incSet)) {
          if (deepData.incSet.includes(curKey)) {
            _this.isGreen = true
58 59
          }
        }
60 61 62 63 64 65 66
        el.onchange = (...args) => {
          if (deepData.modifySet) {
            if (Array.isArray(deepData.modifySet)) {
              if (deepData.modifySet.includes(curKey)) {
                return
              }
              deepData.modifySet.push(curKey)
67 68
            }
          } else {
69
            deepData.modifySet = [curKey]
70 71 72 73 74
          }
        }
      }
    }
  },
liuxin committed
75 76
  computed: {
    model: {
77
      get() {
liuxin committed
78 79
        return this.value
      },
80
      set(newVal) {
liuxin committed
81 82 83
        this.$emit('input', newVal)
      }
    },
84
    mode() {
liuxin committed
85 86 87
      return this.$store.state.Status.mode
    },
    isDisable: {
88
      get() {
liuxin committed
89 90 91
        return this.mode === 'display' || this.disabled
      }
    },
92
    isDisplay: {
93
      get() {
94 95 96
        return this.mode === 'display'
      }
    },
97
    highlight() {
liuxin committed
98 99
      return this.$store.state.Status.highlights.indexOf(this.id) !== -1
    },
100
    highlightChanges() {
liuxin committed
101
      return this.$store.state.Status.highlightChanges.indexOf(this.id) !== -1
fukai committed
102
    },
103 104 105
    attrs() {
      if (this.mode === 'display' || this.disabled) {
        let { placeholder, ...rest } = this.$attrs
fukai committed
106 107 108
        return rest
      }
      return this.$attrs
liuxin committed
109
    }
110
  },
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  methods: {
    isIncludeType(data) {
      if (data && Array.isArray(data.modifySet)) {
        if (data.modifySet.includes(curKey)) {
          _this.isRed = true
        }
      }
      if (data && Array.isArray(data.ebankSet)) {
        if (data.ebankSet.includes(curKey)) {
          _this.isYellow = true

        }
      }
      if (data && Array.isArray(data.incSet)) {
        if (data.incSet.includes(curKey)) {
          _this.isGreen = true
        }
      }
    },
130 131 132 133 134 135 136 137 138
    getProperty(str, value) {
      let keys = str?.split('.')
      for (let key of keys) {
        if (value) {
          value = value[key]
        }
      }
      return value
    }
liuxin committed
139 140 141 142
  }
}
</script>

143
<style lang="less" scoped>
144 145
.greenClass /deep/ .el-input__inner {
  border-color: green;
wangguangchao committed
146
  border-width: medium;
147 148 149 150
}

.greenClass /deep/ .el-textarea__inner {
  border-color: green;
wangguangchao committed
151
  border-width: medium;
152 153 154 155
}

.yellowClass /deep/ .el-input__inner {
  border-color: blue;
wangguangchao committed
156
  border-width: medium;
157 158 159 160
}

.yellowClass /deep/ .el-textarea__inner {
  border-color: blue;
wangguangchao committed
161
  border-width: medium;
162 163 164
}

.redClass /deep/ .el-input__inner {
liuxin committed
165
  border-color: red;
wangguangchao committed
166
  border-width: medium;
liuxin committed
167
}
168 169

.redClass /deep/ .el-textarea__inner {
liuxin committed
170
  border-color: red;
wangguangchao committed
171
  border-width: medium;
liuxin committed
172
}
173

174
/*
liuxin committed
175 176 177 178 179
.el-input.change-light .el-input__inner{
  border-color: #E6A23C;
}
.el-textarea.change-light .el-textarea__inner {
  border-color: #E6A23C;
180
} */</style>