liuxiaolong
2019-05-06 d380e76ec9783bcd80eb42e495d6f8e1af0827b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<template>
  <b-modal
    :title="title"
    ref="myModalRef"
    ok-title="保存"
    @ok="handleOk"
    @cancel="clearName"
    cancel-title="取消"
    :hide-header="true"
    footer-class="flex-center"
    :hide-footer="isShowFooter"
  >
    <div>
      <h4 slot="modal-title" class="modal-title text-center pb-4">{{title}}</h4>
      <h5 class="title-hander">布控来源</h5>
      <el-form>
        <el-form-item class="mb-0" label="平台">
          <div class="library-list clearfix pt-1">
            <h6 class="m-0 float-left">
              <span class="px-1">></span>
            </h6>
            <div class="clearfix library-content">
              <div
                class="float-left pl-1 alarm-item"
                v-for="(item,index) in platDbList"
                :key="index"
              >
                <span class="border-left px-1 ml-1 title"></span>
                <el-checkbox class="alarm-checkBox mb-0" v-model="item.status">{{item.name}}</el-checkbox>
              </div>
            </div>
          </div>
        </el-form-item>
        <el-form-item
          class="mb-0"
          :label="data.name"
          v-for="(data,dataIndex) in cluDbList"
          :key="dataIndex"
        >
          <div class="library-list clearfix pt-1">
            <h6 class="m-0 float-left">
              <span class="px-1">></span>
            </h6>
            <div class="clearfix library-content">
              <div class="float-left pl-1 alarm-item" v-for="item in data.child" :key="item.id">
                <span class="border-left px-1 ml-1 title"></span>
                <el-checkbox
                  class="alarm-checkBox mb-0"
                  v-model="item.status"
                  :title="`集群节点:${item.nodeName}`"
                >{{item.name}}</el-checkbox>
              </div>
            </div>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </b-modal>
</template>
 
<script>
import { Form, FormItem, Checkbox } from 'element-ui'
import { getAddToCtlTree } from '@/server/ctrl.js'
export default {
  props: {
    title: String,
    item: Object,
    isShowFooter: {
      default: false
    }
  },
  data: () => ({
    dataJson: null,
    cluDbList: [],
    platDbList: [],
    isShowModel: false
  }),
  methods: {
    async getAddToCtlTree() {
      const res = await getAddToCtlTree()
      if (res && res.success && res.data) {
        this.cluDbList = res.data.cluDbList
        this.platDbList = res.data.platDbList
      }
    },
    // * 打开modal
    showModel(data) {
      this.dataJson = data
      this.$refs.myModalRef.show()
      // 初始化
      this.init()
    },
    hideModel() {
      this.isShowModel = false
      this.$refs.myModalRef.hide()
    },
    // 初始化
    init() {
      this.platDbList.map(item => {
        // item.status = false
        this.$set(item, 'status', false)
        return item
      })
      this.cluDbList.map(data => {
        if (data.child) {
          data.child.map(item => {
            this.$set(item, 'status', false)
            return item
          })
        }
        return data
      })
    },
    // * 提交表单
    handleOk(e) {
      e.preventDefault()
      // 获取平台ids
      const platDbListIds = this.platDbList
        .filter(item => item.status)
        .map(item => item.id)
      let cluDbListIds = []
      this.cluDbList.map(data => {
        if (data.child) {
          const ids = data.child
            .filter(item => item.status)
            .map(item => item.id)
          cluDbListIds = [...cluDbListIds, ...ids]
        }
      })
      if (!platDbListIds.length && !cluDbListIds.length) {
        this.$toast({
          type: 'error',
          message: '您还没有选择布控来源!'
        })
        return
      }
      this.$emit('submit', {
        platDbListIds,
        cluDbListIds,
        data: this.dataJson
      })
    },
    // * 取消
    clearName() {}
  },
  created() {
    this.getAddToCtlTree()
  },
  components: {
    elForm: Form,
    elFormItem: FormItem,
    elCheckbox: Checkbox
  }
}
</script>
<style lang="scss" scoped>
.modal-title {
  font-size: 18px;
  font-weight: 900;
}
.title-hander {
  font-size: 16px;
  font-weight: 600;
  color: #8c8c8c;
}
.library-list {
  h6 {
    height: 30px;
    line-height: 30px;
    width: 20px;
    cursor: pointer;
    .title {
      display: block;
      width: 60px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .library-content {
    margin-left: 55px;
  }
  .alarm-item {
    line-height: 30px;
    .alarm-icon {
      display: inline-block;
      vertical-align: middle;
      width: 15px;
      height: 15px;
      line-height: 15px;
      background: #d9534f;
      border-radius: 50%;
      overflow: hidden;
      text-align: center;
      color: #fff;
    }
    .alarm-name {
      display: inline-block;
      vertical-align: middle;
      line-height: 15px;
      padding: 2px 4px;
      max-width: 100px;
      cursor: pointer;
    }
    .alarm-name.active {
      background: #35bde7;
      color: #fff;
    }
  }
}
</style>