hanbaoshan
2020-08-08 98a44e94ecc76abd72b9817648ca4b91469b936a
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<template>
  <div class="out-div">
    <div class="flex-center left-list">
      <el-input placeholder="请输入内容" v-model="eventName" size="mini" style="width: 280px">
        <i slot="suffix" class="el-input__icon el-icon-search"></i>
      </el-input>
 
      <div class="icon-btn" @click="add" style="margin-left:10px">
        <i class="el-icon-circle-plus-outline"></i>
        <span>&nbsp;新增</span>
      </div>
    </div>
    <div class="max-height" style="overflow-y:auto;overflow-x:hidden">
      <el-row
        class="cursor-pointer"
        v-for="(item, index) in eventList"
        :key="item.id"
        @click.native="clickCategory(index, item)"
        :class="{activeRow:categoryIndex==index}"
      >
        <div class="event-name">
          <b>{{item.name}}</b>
          <p style="margin-top:8px; color:#9e9e9e">{{item.time_start}} ~ {{item.time_end}}</p>
        </div>
 
        <div class="event-btn">
          <el-switch
            v-model="item.enable"
            @change="enabled(item)"
            :inactive-value="false"
            :active-value="true"
            style="margin-top:-5px"
          ></el-switch>
          <span
            class="iconfont iconshanchu iconStyle1"
            style="color:#E74C3C"
            @click.stop="deleteBase(item)"
          ></span>
        </div>
      </el-row>
    </div>
  </div>
</template>
<script>
import { findAll, changeStatus, deleteByid } from "@/api/event";
export default {
  name: "leftList",
 
  props: {
    listWidth: {
      default: "350px",
      type: String
    },
    title: {
      default: "",
      type: String
    },
    isSelected: {
      default: false,
      type: Boolean
    },
    type: {
      default: "",
      type: String
    },
    activeId: {
      default: "",
      type: String
    }
  },
  data() {
    return {
      activeNames: ["1"],
      categoryIndex: -1,
      eventList: [],
      // 当前点击的事件对象
      clickBase: {},
      // 事件名称
      eventName: ""
    };
  },
  mounted() {
    this.findAll();
  },
  methods: {
    async enabled(item) {
      let json = {
        id: item.id,
        enable: item.enable
      };
      let res = await changeStatus(json);
      if (res && res.success) {
        // console.log(res, "更新状态");
        this.$emit("enabled", item)
      }
      // this.$emit("getEvents", item);
    },
    async searchSyncTables() {
      // let res = await selectSyncTables()
      // this.data = res.data.datalist
    },
    async searchLocalTables() {
      // let res = await selectLocalTables()
      // this.data = res.data.datalist
    },
    add() {
      this.$emit("add");
      this.categoryIndex = -1;
    },
    clickCategory(index, item) {
      // 这里我们传入一个当前值
      this.categoryIndex = index;
      // 调用切换右侧面板的函数并且切换父组件中isSelected的值让另一个组件清除被选中状态
      this.clickBase = item;
      this.$emit("getEvents", item);
    },
    edit(item) {
      this.$emit("changeShow", item, this.type);
    },
    async deleteBase(data) {
      // console.log(data, "要删除的事件推送");
      this.$confirm("确定要删除该条推送任务吗?", {
        center: true,
        cancelButtonClass: "comfirm-class-cancle",
        confirmButtonClass: "comfirm-class-sure"
      }).then(() => {
        let json = {
          type: "formData",
          id: data.id
        };
        deleteByid(json).then(res => {
          if (res && res.success) {
            this.$emit("del-list");
            this.$notify({
              type: "success",
              message: "删除成功"
            })
          }
        });
      })
    },
    // 查询事件列表
    async findAll() {
      let json = {
        name: this.eventName
      };
      let res = await findAll(json);
      if (res && res.success) {
        // console.log(res, "查询所有事件列表");
        if (this.activeId !== "") {
          res.data.forEach((element, index) => {
            if (element.id === this.activeId) {
              this.categoryIndex = index;
            }
          });
        }
        this.eventList = res.data;
 
 
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.flex-center {
  justify-content: left;
}
.iconStyle1 {
  font-size: 18px;
  margin-left: 15px;
  cursor: pointer;
}
.activeRow {
  background: #f8f8f8;
}
.cursor-pointer {
  cursor: pointer;
  height: 75px;
}
.max-height {
  position: absolute;
  left: 0px;
  width: 355px;
  height: 100%;
  
  margin-top: 20px;
  border-top: 1px solid #e0e0e0;
  border-bottom: 1px solid #e0e0e0;
}
.out-div {
  width: 350px;
  text-align: left;
  padding-top: 20px;
  //height: 50em;
  .left-list {
    position: absolute;
    left: 15px;
    top: 10px;
  }
}
.event-name {
  padding: 17px;
  font-size: 14px;
}
.event-btn {
  position: absolute;
  left: 79%;
  top: 18%;
}
.icon-btn {
  i {
    font-size: 18px;
    position: relative;
    top: 2px;
  }
  span {
    font-size: 14px;
  }
  display: inline;
  color: #3d68e1;
  line-height: 38px;
  margin-left: 10px;
  cursor: pointer;
}
</style>