zxl
2026-03-25 2f63f26c3240f9d8f9e8696df7037d2ac5c744a6
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<template>
  <div class="depart-label-container">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="标签名称">
              <a-select v-model="queryParam.labelName" placeholder="请选择标签" allowClear @change="searchQuery">
                <a-select-option value="">全部</a-select-option>
                <a-select-option v-for="label in labelList" :key="label" :value="label">
                  {{ label }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
 
    <div class="table-operator">
      <div class="data-overview-ct">
        <div class="block-title" style="display: flex; align-items: center">
          <div style="margin-right: 12px">数据对比</div>
          <a-switch v-model="isContrast" />
          <a-range-picker 
            style="width: 300px; margin: 0 12px" 
            v-if="isContrast" 
            v-model="contrastTimeRange"
            @change="contrastTimeChange"
            :placeholder="['开始时间', '结束时间']"
          />
        </div>
      </div>
    </div>
 
    <div class="chart-container" v-if="isContrast && lineChartData.xData && lineChartData.xData.length > 0">
      <div class="chart-block">
        <div class="block-title">数据对比柱状图</div>
        <DataReLineChart 
          ref="lineChart"
          :chartData="lineChartData"
          :showpercent="true"
          :domId="'departLabelLineChart'"
        ></DataReLineChart>
      </div>
    </div>
 
    <a-table
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :scroll="{ y: 350 }"
    >
      <span slot="action" slot-scope="text, record">
        <a @click="handleAdd(record)" style="margin-right: 8px">添加标签</a>
        <a-dropdown>
          <a-menu slot="overlay">
            <a-menu-item v-for="label in getLabels(record)" :key="label" @click="() => handleMenuClick(record, label)">
              删除{{ label }}
            </a-menu-item>
          </a-menu>
          <a slot="default">删除标签</a>
        </a-dropdown>
      </span>
    </a-table>
 
    <DepartLabelModal 
      ref="modalForm" 
      @ok="modalFormOk"
      :parentCode="queryParam.parentCode"
      :parentId="queryParam.parentId"
    ></DepartLabelModal>
  </div>
</template>
 
<script>
import { getAction, deleteAction, putAction, postAction } from '@tievd/cube-block/lib/api/manage'
import DepartLabelModal from './DepartLabelModal'
import DataReLineChart from './DataReLineChart'
 
export default {
  name: 'DepartLabel',
  components: {
    DepartLabelModal,
    DataReLineChart
  },
  data() {
    return {
      queryParam: {
        labelName: '',
        parentCode: JSON.parse(localStorage.getItem("userDepartInfo")).orgCode,
        parentId: JSON.parse(localStorage.getItem("userDepartInfo")).id
      },
      labelList: [],
      dataSource: [],
      loading: false,
      isContrast: false,
      statisTotalObj: {},
      contrastObj: {},
      contrastStartTime: '',
      contrastEndTime: '',
      contrastTimeRange: [],
      lineChartData: {},
      currentOrgData: [],
      contrastOrgData: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showSizeChanger: true,
        showTotal: (total) => `共 ${total} 条`
      },
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (text, record, index) {
            return index + 1
          }
        },
        {
          title: '站点名称',
          align: 'center',
          dataIndex: 'depart_name'
        },
        {
          title: '站点编码',
          align: 'center',
          dataIndex: 'org_code'
        },
        {
          title: '标签名称',
          align: 'center',
          dataIndex: 'label_name'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'create_time',
          customRender: function (text) {
            if (!text) return ''
            return text.replace('T', ' ')
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/jyz/departLabel/list',
        listLabels: '/jyz/departLabel/listLabels',
        listDeparts: '/jyz/custom/sys/depart/tables',
        delete: '/jyz/departLabel/delete',
        update: '/jyz/departLabel/update',
        queryOrgOilCount: '/jyz/departLabel/queryOrgOilCount'
      }
    }
  },
  watch: {
    isContrast(newVal) {
      if (newVal) {
        this.setDefaultMonthTime()
      }
    }
  },
  created() {
    this.loadLabelList()
    this.loadData()
  },
  methods: {
    loadLabelList() {
      const params = {
        parentCode: this.queryParam.parentCode,
        parentId: this.queryParam.parentId
      }
      getAction(this.url.listLabels, params).then((res) => {
        if (res.success) {
          this.labelList = res.result
          console.log('标签列表:', this.labelList)
        } else {
          console.error('加载标签列表失败:', res.message)
        }
      })
    },
    loadData() {
      this.loading = true
      const params = {
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        labelName: this.queryParam.labelName,
        parentCode: this.queryParam.parentCode,
        parentId: this.queryParam.parentId
      }
      
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records || []
          this.pagination.total = Number(res.result.total) || 0
          this.getOrgData()
        } else {
          this.$message.error(res.message || '查询失败')
        }
      }).catch(() => {
        this.$message.error('查询失败')
      }).finally(() => {
        this.loading = false
      })
    },
    updateChartData() {
      if (this.dataSource.length === 0) {
        this.lineChartData = {}
        return
      }
      
      console.log('updateChartData - dataSource:', this.dataSource)
      console.log('updateChartData - currentOrgData:', this.currentOrgData)
      console.log('updateChartData - contrastOrgData:', this.contrastOrgData)
      
      const xData = this.dataSource.map(item => item.depart_name)
      
      const currentCarData = this.dataSource.map(item => {
        const orgData = this.currentOrgData.find(d => d.org_code === item.org_code)
        console.log(`Matching ${item.org_code}:`, orgData)
        return orgData ? (orgData.carCount || 0) : 0
      })
      
      const currentOilData = this.dataSource.map(item => {
        const orgData = this.currentOrgData.find(d => d.org_code === item.org_code)
        return orgData ? (orgData.oilCount || 0) : 0
      })
      
      const currentStationData = this.dataSource.map(item => {
        const orgData = this.currentOrgData.find(d => d.org_code === item.org_code)
        return orgData ? (orgData.stationCount || 0) : 0
      })
      
      const currentVolumeData = this.dataSource.map(item => {
        const orgData = this.currentOrgData.find(d => d.org_code === item.org_code)
        return orgData ? (orgData.oilVolume || 0) : 0
      })
      
      console.log('Final data - xData:', xData)
      console.log('Final data - currentCarData:', currentCarData)
      console.log('Final data - currentOilData:', currentOilData)
      console.log('Final data - currentStationData:', currentStationData)
      console.log('Final data - currentVolumeData:', currentVolumeData)
      
      this.lineChartData = {
        xData: xData,
        barData: currentCarData,
        lineData: currentOilData,
        barName: '车流量',
        lineName: '加油数',
        barData2: currentStationData,
        lineData2: currentVolumeData,
        barName2: '进站数',
        lineName2: '油品销量'
      }
      
      this.$nextTick(() => {
        if (this.$refs.lineChart && this.$refs.lineChart.setChart) {
          this.$refs.lineChart.setChart()
        }
      })
    },
    contrastTimeChange(e, t) {
      this.contrastStartTime = t[0]
      this.contrastEndTime = t[1]
      this.getContrastData()
    },
    setDefaultMonthTime() {
      const now = new Date()
      const year = now.getFullYear()
      const month = now.getMonth() + 1
      const day = now.getDate()
      
      const startTime = `${year}-${String(month).padStart(2, '0')}-01 00:00:00`
      const endTime = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} 23:59:59`
      
      this.contrastStartTime = startTime
      this.contrastEndTime = endTime
      
      this.getContrastData()
    },
    getOrgData() {
      postAction(this.url.queryOrgOilCount, {
        orgCode: this.queryParam.parentCode
      }).then((res) => {
        if (res.success) {
          console.log('getOrgData result:', res.result)
          this.currentOrgData = res.result || []
          this.updateChartData()
        }
      })
    },
    getContrastData() {
      postAction(this.url.queryOrgOilCount, {
        orgCode: this.queryParam.parentCode,
        startTime: this.contrastStartTime,
        endTime: this.contrastEndTime
      }).then((res) => {
        if (res.success) {
          console.log('getContrastData result:', res.result)
          this.contrastOrgData = res.result || []
          this.updateChartData()
        }
      })
    },
    searchQuery() {
      this.pagination.current = 1
      this.loadData()
    },
    searchReset() {
      this.queryParam.labelName = ''
      this.pagination.current = 1
      this.loadData()
    },
    handleTableChange(pagination) {
      this.pagination = pagination
      this.loadData()
    },
    handleAdd(record) {
      this.$refs.modalForm.add(record)
    },
    handleDelete(record) {
      this.$confirm({
        title: '确认删除',
        content: '确定要删除该标签吗?',
        onOk: () => {
          deleteAction(this.url.delete, { 
            departId: record.depart_id,
            labelName: record.label_name
          }).then((res) => {
            if (res.success) {
              this.$message.success('删除成功')
              this.loadData()
              this.loadLabelList()
            } else {
              this.$message.error(res.message || '删除失败')
            }
          })
        }
      })
    },
    modalFormOk() {
      this.loadData()
      this.loadLabelList()
    },
    getLabels(record) {
      if (!record.label_name) return []
      return record.label_name.split(',').map(label => label.trim()).filter(label => label)
    },
    handleMenuClick(record, label) {
      this.$confirm({
        title: '确认删除',
        content: `确定要删除"${label}"标签吗?`,
        onOk: () => {
          deleteAction(this.url.delete, {
            departId: record.depart_id,
            labelName: label
          }).then((res) => {
            if (res.success) {
              this.$message.success('删除成功')
              this.loadData()
              this.loadLabelList()
            } else {
              this.$message.error(res.message || '删除失败')
            }
          })
        }
      })
    }
  }
}
</script>
 
<style scoped lang="less">
.depart-label-container {
  padding: 24px;
  background: linear-gradient(135deg, #1a1f2e 0%, #0f1219 100%);
  min-height: 100vh;
}
 
.table-page-search-wrapper {
  margin-bottom: 24px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}
 
.table-operator {
  margin-bottom: 24px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}
 
.data-overview-ct {
  .block-title {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
  }
}
 
.chart-container {
  margin: 24px 0;
  padding: 24px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  
  .chart-block {
    width: 100%;
    
    .block-title {
      font-size: 18px;
      font-weight: 600;
      margin-bottom: 20px;
      color: #fff;
      padding-bottom: 12px;
      border-bottom: 2px solid rgba(91, 129, 249, 0.5);
    }
  }
}
 
:deep(.ant-table) {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  
  .ant-table-thead > tr > th {
    background: rgba(91, 129, 249, 0.2);
    color: #fff;
    font-weight: 600;
    border-bottom: 2px solid rgba(91, 129, 249, 0.5);
  }
  
  .ant-table-tbody > tr > td {
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .ant-table-tbody > tr:hover > td {
    background: rgba(91, 129, 249, 0.1);
  }
}
 
:deep(.ant-btn-primary) {
  background: linear-gradient(135deg, #5b81f9 0%, #3d5cc9 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(91, 129, 249, 0.3);
  
  &:hover {
    background: linear-gradient(135deg, #6d92ff 0%, #4d6ee0 100%);
    box-shadow: 0 6px 16px rgba(91, 129, 249, 0.4);
  }
}
 
:deep(.ant-select) {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  
  .ant-select-selection {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
  }
}
 
:deep(.ant-form-item-label > label) {
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}
 
:deep(.a-switch) {
  background: rgba(91, 129, 249, 0.3);
}
</style>