WXL
2025-12-28 40bd04c1299a0edf63771b90b5f9e78bfb943474
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
<template>
  <div class="business-trip-table">
    <div class="table-header">
      <div class="header-actions">
        <el-button type="primary" size="small" icon="el-icon-plus" @click="handleAddTrip">
          新增出差
        </el-button>
        <el-button size="small" icon="el-icon-download" @click="exportData">
          导出数据
        </el-button>
      </div>
 
      <div class="header-filters">
        <el-input
          v-model="filters.employeeName"
          placeholder="搜索员工姓名"
          prefix-icon="el-icon-search"
          style="width: 200px"
          clearable
        />
        <el-select v-model="filters.status" placeholder="状态筛选" clearable>
          <el-option label="进行中" value="进行中" />
          <el-option label="已完成" value="已完成" />
        </el-select>
      </div>
    </div>
 
    <el-table
      :data="filteredData"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column prop="tripNumber" label="出差单号" width="140" />
      <el-table-column prop="employeeName" label="员工姓名"  />
      <el-table-column prop="startCity" label="出发城市"  />
      <el-table-column prop="endCity" label="目的城市"  />
      <el-table-column prop="startDate" label="开始日期"  sortable />
      <el-table-column prop="endDate" label="结束日期"  sortable />
      <el-table-column prop="duration" label="出差天数" >
        <template #default="scope">
          <el-tag size="small">{{ calculateDuration(scope.row) }}天</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="distance" label="里程(km)"  sortable />
      <el-table-column prop="status" label="状态" >
        <template #default="scope">
          <el-tag
            :type="scope.row.status === '已完成' ? 'success' : 'primary'"
            effect="light"
          >
            {{ scope.row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" fixed="right">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleViewDetail(scope.row)"
            icon="el-icon-view"
          >
            详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleEdit(scope.row)"
            icon="el-icon-edit"
          >
            编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            icon="el-icon-delete"
            style="color: #f56c6c;"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <div class="pagination-container">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'BusinessTripTable',
  props: {
    data: {
      type: Array,
      default: () => []
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      filters: {
        employeeName: '',
        status: ''
      }
    }
  },
  computed: {
    filteredData() {
      let data = this.data.filter(item => {
        const nameMatch = !this.filters.employeeName ||
          item.employeeName.includes(this.filters.employeeName)
        const statusMatch = !this.filters.status ||
          item.status === this.filters.status
        return nameMatch && statusMatch
      })
 
      const start = (this.currentPage - 1) * this.pageSize
      const end = start + this.pageSize
      return data.slice(start, end)
    },
    total() {
      return this.data.filter(item => {
        const nameMatch = !this.filters.employeeName ||
          item.employeeName.includes(this.filters.employeeName)
        const statusMatch = !this.filters.status ||
          item.status === this.filters.status
        return nameMatch && statusMatch
      }).length
    }
  },
  methods: {
    calculateDuration(row) {
      const start = new Date(row.startDate)
      const end = new Date(row.endDate)
      const duration = Math.ceil((end - start) / (1000 * 60 * 60 * 24)) + 1
      return duration
    },
 
    handleViewDetail(row) {
      this.$emit('view-detail', row)
    },
 
    handleAddTrip() {
      this.$message.info('打开新增出差对话框')
    },
 
    handleEdit(row) {
      this.$message.info(`编辑出差记录: ${row.tripNumber}`)
    },
 
    handleDelete(row) {
      this.$confirm('确定要删除这条出差记录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message.success('删除成功')
      }).catch(() => {})
    },
 
    exportData() {
      this.$message.success('导出功能开发中')
    },
 
    handleSizeChange(size) {
      this.pageSize = size
      this.currentPage = 1
    },
 
    handleCurrentChange(page) {
      this.currentPage = page
    }
  }
}
</script>
 
<style scoped>
.business-trip-table {
  padding: 20px;
}
 
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 16px;
}
 
.header-actions {
  display: flex;
  gap: 10px;
}
 
.header-filters {
  display: flex;
  gap: 10px;
  align-items: center;
}
 
.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
 
@media (max-width: 768px) {
  .table-header {
    flex-direction: column;
    align-items: stretch;
  }
 
  .header-actions {
    justify-content: space-between;
  }
}
</style>