Xxxu
2020-07-03 1ac6ef52a03f25f9def9f6a2594d2a8196aa77f6
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
<template>
  <el-dialog title="路灯定时列表"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <div>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          prop="timeId"
          header-align="center"
          align="center"
          label="ID">
        </el-table-column>
        <el-table-column
          prop="name"
          header-align="center"
          treeKey="timeId"
          width="150"
          label="名称">
        </el-table-column>
        <el-table-column
          prop="parentName"
          header-align="center"
          align="center"
          label="所属组别">
        </el-table-column>
        <el-table-column
          prop="beanName"
          header-align="center"
          align="center"
          label="执行名称">
        </el-table-column>
        <el-table-column
          prop="cron"
          header-align="center"
          align="center"
          label="定时时间">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.timeId)">修改</el-button>
            <el-button type="text" size="small" @click="updateTimeHandle(scope.row.timeId)">定时</el-button>
            <el-button type="text" size="small" @click="deleteHandle(scope.row.timeId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <!-- 新增按钮 -->
      <button class="btn-add"  type="primary" @click="addOrUpdateHandle()"></button>
    </span>
    <!-- 定时弹窗 -->
    <time-streetlight-handler ref="timeStreetlightHandler" v-if="timeStreetlightHandlerVisible" @refreshDataList="init"></time-streetlight-handler>
    <!-- 新增, 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="init"></add-or-update>
  </el-dialog>
</template>
 
<script>
import TimeStreetlightHandler from './time-streetlight-handler'
import AddOrUpdate from './time-add-or-update'
export default {
  data () {
    return {
      visible: false,
      timeStreetlightHandlerVisible: false,
      addOrUpdateVisible: false,
      dataListLoading: false,
      dataList: [],
      allDataList: []
    }
  },
  components: {
    TimeStreetlightHandler,
    AddOrUpdate
  },
  methods: {
    init () {
      this.visible = true
      this.dataListLoading = true
      this.dataList = []
      this.$http({
        url: this.$http.adornUrl('/pole/poletime/list'),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.allDataList = data.list
          data.list.forEach(element => {
            if (element.type === 0) {
              this.dataList.push(element)
            }
          })
        } else {
          this.allDataList = []
          this.dataList = []
        }
        this.dataListLoading = false
      })
    },
    updateTimeHandle (id) {
      this.timeStreetlightHandlerVisible = true
      var timeList = []
      this.allDataList.forEach(element => {
        if (element.parentId !== undefined && element.parentId !== null && element.parentId === id) {
          timeList.push(element)
        }
      })
      this.$nextTick(() => {
        this.$refs.timeStreetlightHandler.init(timeList, id)
      })
    },
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle (id) {
      // var ids = id ? [id] : this.dataListSelections.map(item => {
      //   return item.groupId
      // })
      this.$confirm(`确定删除操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/pole/poletime/deleteWithGroup'),
          method: 'post',
          data: this.$http.adornData(id, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.init()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
div {
  /deep/ .el-table{
    color: white;
    background-color: transparent;
    th{
      background-color: transparent;
    }
    tr {
      background-color: transparent;
      td {
        border-bottom: 1px solid #fff
      }
    };
    .el-button {
      span {
        color: #458aad
      }
    }
  }
  /deep/ .el-button--primary {
    background-color: #3da9fe;
    border-color: #3da9fe
  }
}
</style>