wlzboy
3 天以前 40a8157440e3b906da8f52e07d939d78c3f4c313
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
<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>车辆同步管理</span>
        <el-button
          style="float: right; padding: 3px 0"
          type="text"
          @click="handleRefresh"
        >
          <i class="el-icon-refresh"></i> 刷新
        </el-button>
      </div>
 
      <!-- 说明提示 -->
      <el-alert
        title="功能说明"
        type="info"
        :closable="false"
        style="margin-bottom: 15px"
      >
        <div>
          本页面用于查看旧系统中的车辆数据,并手动同步未同步的车辆到新系统。<br/>
          <strong>已同步</strong>:车辆已存在于新系统中;<strong>未同步</strong>:车辆还未同步,可手动添加到新系统。
        </div>
      </el-alert>
 
      <!-- 筛选条件 -->
      <el-form :inline="true" class="filter-form">
        <el-form-item label="同步状态">
          <el-select v-model="filterSynced" placeholder="请选择" @change="handleFilter" clearable>
            <el-option label="全部" :value="null" />
            <el-option label="未同步" :value="false" />
            <el-option label="已同步" :value="true" />
          </el-select>
        </el-form-item>
      </el-form>
 
      <!-- 数据表格 -->
      <el-table
        v-loading="loading"
        :data="filteredVehicleList"
        style="width: 100%"
        border
      >
        <el-table-column label="车辆ID(CarID)" prop="carId" width="120" align="center" />
        <el-table-column label="车牌号" prop="vehicleNo" width="150" align="center">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.vehicleNo }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="单据类型编码" prop="carOrdClass" width="120" align="center" />
        <el-table-column label="归属分公司" prop="deptName" width="150" align="center" />
        <el-table-column label="同步状态" prop="synced" width="120" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.synced ? 'success' : 'warning'">
              {{ scope.row.synced ? '已同步' : '未同步' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="新系统车辆ID" prop="vehicleId" width="130" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.vehicleId">{{ scope.row.vehicleId }}</span>
            <span v-else style="color: #909399">-</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              v-if="!scope.row.synced"
              size="mini"
              type="primary"
              icon="el-icon-plus"
              @click="handleSync(scope.row)"
              v-hasPermi="['system:vehicleSync:sync']"
            >
              同步
            </el-button>
            <el-tag v-else type="info">已同步</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
 
    <!-- 同步对话框 -->
    <el-dialog
      title="手动同步车辆"
      :visible.sync="syncDialogVisible"
      width="500px"
      append-to-body
    >
      <el-form ref="syncForm" :model="syncForm" :rules="syncRules" label-width="100px">
        <el-form-item label="旧系统ID" prop="carId">
          <el-input v-model="syncForm.carId" disabled />
        </el-form-item>
        <el-form-item label="车牌号" prop="vehicleNo">
          <el-input v-model="syncForm.vehicleNo" disabled />
        </el-form-item>
        <el-form-item label="归属分公司" prop="deptId">
          <el-select v-model="syncForm.deptId" placeholder="请选择归属分公司" clearable style="width: 100%">
            <el-option
              v-for="dept in deptOptions"
              :key="dept.deptId"
              :label="dept.deptName"
              :value="dept.deptId"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="syncDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitSync" :loading="syncLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { listVehicleSync, syncVehicle } from "@/api/system/vehicleSync";
import { listDept } from "@/api/system/dept";
 
export default {
  name: "VehicleSync",
  data() {
    return {
      // 加载状态
      loading: true,
      // 车辆列表(原始数据)
      vehicleList: [],
      // 筛选后的车辆列表
      filteredVehicleList: [],
      // 筛选条件:同步状态
      filterSynced: null,
      // 同步对话框显示状态
      syncDialogVisible: false,
      // 同步加载状态
      syncLoading: false,
      // 同步表单
      syncForm: {
        carId: null,
        vehicleNo: null,
        deptId: null
      },
      // 部门树选项
      deptOptions: [],
      // 表单校验规则
      syncRules: {
        deptId: [
          { required: true, message: "请选择归属分公司", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDeptList();
  },
  methods: {
    /** 查询车辆同步列表 */
    getList() {
      this.loading = true;
      listVehicleSync().then(response => {
        this.vehicleList = response.rows;
        this.applyFilter();
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    /** 应用筛选条件 */
    applyFilter() {
      if (this.filterSynced === null) {
        // 显示全部
        this.filteredVehicleList = this.vehicleList;
      } else {
        // 根据同步状态筛选
        this.filteredVehicleList = this.vehicleList.filter(
          item => item.synced === this.filterSynced
        );
      }
    },
    /** 筛选条件变化 */
    handleFilter() {
      this.applyFilter();
    },
    /** 获取部门列表(只显示分公司:parent_id=100) */
    getDeptList() {
      listDept({ parentId: 100 }).then(response => {
        // 过滤出分公司(parent_id=100的部门)
        if (response.data) {
          this.deptOptions = response.data.filter(dept => dept.parentId === "100");
        } else {
          this.deptOptions = [];
        }
      });
    },
    /** 刷新列表 */
    handleRefresh() {
      this.getList();
      this.$modal.msgSuccess("刷新成功");
    },
    /** 同步按钮操作 */
    handleSync(row) {
      this.syncForm = {
        carId: row.carId,
        vehicleNo: row.vehicleNo,
        deptId: row.deptId || null
      };
      this.syncDialogVisible = true;
      this.$nextTick(() => {
        this.$refs["syncForm"].clearValidate();
      });
    },
    /** 提交同步 */
    submitSync() {
      this.$refs["syncForm"].validate(valid => {
        if (valid) {
          this.syncLoading = true;
          syncVehicle(this.syncForm).then(response => {
            this.$modal.msgSuccess("同步成功");
            this.syncDialogVisible = false;
            this.syncLoading = false;
            this.getList();
          }).catch(() => {
            this.syncLoading = false;
          });
        }
      });
    }
  }
};
</script>
 
<style scoped>
.box-card {
  margin-bottom: 20px;
}
 
.filter-form {
  margin-bottom: 15px;
  padding: 10px;
  background-color: #f5f7fa;
  border-radius: 4px;
}
</style>