ZhangXianQiang
2024-05-06 72f13e697d40c8fffc7aa0197fec4509bbe41569
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
<template>
  <div class="row">
    <el-row type="flex" justify="left">
      <el-col :span="24" style="position: relative">
        <el-menu :default-active="activeIndex" class="el-menu" mode="horizontal" @select="handleSelect">
          <el-menu-item index="0" @click="changeUnit(null, '全部')">
            全部单位({{ totalWorkOrders }})
          </el-menu-item>
          <el-menu-item :index="index + 1" v-for="(item, index) in unitList" :key="index" @click="changeUnit(item.id, item.value)">
            {{ item.unitName }}({{ item.workOrderCount }})
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
 
    <el-row class="op-warp" type="flex" justify="left" >
      <el-col :span="24">
        <el-button size="small" type="info" @click="selectedDistribute" class="op">下发选中工单</el-button>
        <el-popconfirm
          @confirm="allDistribute"
          title="确定要下发所有工单吗?"
        >
          <el-button size="small" type="danger"  class="op" slot="reference">全部下发</el-button>
        </el-popconfirm>
 
        <el-popover
          class="op"
          placement="right"
          width="300px"
          trigger="click">
          <span style="font-weight: bold;font-size: 16px">快捷下发</span>
          <el-form ref="fastDistributeForm" :model="fastDistributeForm" :rules="fastDistributeRules" label-width="80px">
            <el-form-item label="快捷方式" prop="fastWay">
              <el-radio v-model="fastDistributeForm.fastWay" label="LAST_HALF_HOUR">最近30分钟</el-radio>
              <el-radio v-model="fastDistributeForm.fastWay" label="LAST_HOUR">最近1小时</el-radio>
              <el-radio v-model="fastDistributeForm.fastWay" label="LAST_TWO_HOUR">最近2小时</el-radio>
              <el-radio v-model="fastDistributeForm.fastWay" label="LAST_DAY">最近1天</el-radio>
              <el-radio v-model="fastDistributeForm.fastWay" label="CUSTOM">自定义</el-radio>
            </el-form-item>
            <el-form-item v-if="fastDistributeForm.fastWay === 'CUSTOM'" label="时间范围">
              <el-date-picker
                style="width: 100%"
                v-model="fastTimeRange"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="故障类型" prop="errorType">
              <el-select v-model="fastDistributeForm.errorType">
                <el-option label="市政施工" value="市政施工"/>
                <el-option label="设备故障" value="设备故障"/>
                <el-option label="设备遗失" value="设备遗失"/>
              </el-select>
            </el-form-item>
            <el-form-item label="数量限制" prop="fastNumLimit">
              <el-input v-model="fastDistributeForm.fastNumLimit" size="small" type="number" placeholder="此次工单下发最大数量"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="small" @click="fastDistribute">立即下发</el-button>
            </el-form-item>
          </el-form>
          <el-button slot="reference" type="primary" size="small">快捷下发</el-button>
        </el-popover>
        <el-button size="small" type="primary" @click="page">刷新</el-button>
        <el-button size="small" type="primary" @click="handleAdd">新增</el-button>
      </el-col>
    </el-row>
 
    <el-row class="content-warp" type="flex" justify="left">
      <el-col :span="24">
        <el-table v-loading="loading" :data="workOrderList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="工单号" align="center" prop="workOrderNo"/>
          <el-table-column label="运维单位" align="center" prop="unitName"/>
          <el-table-column label="工单来源" align="center" prop="source"/>
          <el-table-column label="故障类型" align="center" prop="errorType"/>
          <el-table-column label="产生时间" align="center" prop="createTime"/>
        </el-table>
 
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
 
    </el-row>
 
    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="detailName" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="运维单位" prop="unitId">
          <el-select v-model="form.unitId" placeholder="请选择">
            <el-option
              v-for="item in unitList"
              :key="item.id"
              :label="item.unitName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工单来源" prop="source">
          <el-select
            v-model="form.source"
            filterable
            remote
            reserve-keyword
            placeholder="请选择来源"
            :remote-method="remoteGetPoints"
            @change="setPointId"
            :loading="selectLoading">
            <el-option
              v-for="item in pointList"
              :key="item.id"
              :label="item.value"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="故障类型" prop="errorType">
          <el-select v-model="form.errorType">
            <el-option label="市政施工" value="市政施工"/>
            <el-option label="设备故障" value="设备故障"/>
            <el-option label="设备遗失" value="设备遗失"/>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
 
  </div>
</template>
 
<script>
import {distributeWorkOrder, fastDistribute, addWorkOrder, updateWorkOrder, selectedIdsDistribute} from '@/api/platform/work-order'
import {workList} from "@/api/platform/unit";
import { pointSelectData } from "@/api/platform/point";
export default {
  name: 'index',
  data() {
    return {
      selectedIdsDistributeForm: {
        ids: [],
        unitId: null
      },
      unitList: [],
      settingForm: {
        // 离线
        outLine: null,
        // 视频可用
        videoQuality: "",
        // 视频标注
        videoLabel: ""
      },
      // 当前运维单位
      unitId: null,
      unitName: "",
      // 多选
      multipleSelection: [],
      // 下发时间范围
      fastTimeRange: [],
      // 下发
      fastDistributeForm: {
        fastWay: null,
        fastNumLimit: null,
        start: null,
        end: null,
        unitId: null
      },
      // 自动生成工单规则
      settingRules: {
        outLine: [
          { required: true, message: "请填写点位离线时长", trigger: "blur" }
        ],
        videoQuality: [
          { required: true, message: "请填写视频可用程度", trigger: "change" }
        ],
        videoLabel: [
          { required: true, message: "请填写点视频标注准确率", trigger: "blur" }
        ],
      },
      // 下发表单验证
      fastDistributeRules: {
        fastWay: [
          { required: true, message: "请选择快速分发方式", trigger: "blur" }
        ],
        fastNumLimit: [
          { required: true, message: "请输入快速分发数量限制", trigger: "blur" }
        ],
        errorType: [
          { required: true, message: "请故障类型", trigger: "blur" }
        ],
      },
      queryParams: {
        unitId: null,
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      // 非多个禁用
      multiple: true,
      activeIndex: '0',
      loading: false,
      workOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
      },
      // 下拉加载
      selectLoading: false,
      // 点位list
      pointList: [],
      // 表单校验
      rules: {
        source: [
          { required: true, message: "工单来源不能为空", trigger: "blur" }
        ],
        workOrderNo: [
          { required: true, message: "工单号不能为空", trigger: "blur" }
        ],
        unitId: [
          { required: true, message: "运维单位不能为空", trigger: "blur" }
        ],
        errorType: [
          { required: true, message: "请选择故障类型", trigger: "blur" }
        ],
      }
    }
  },
  mounted() {
    this.page();
  },
  computed: {
    totalWorkOrders() {
      return this.unitList.reduce((total, item) => total + item.workOrderCount, 0);
    },
  },
  methods: {
    setPointId(selectedValue) {
      const selectedItem = this.pointList.find(item => item.value === selectedValue);
      this.form.pointId = selectedItem.id
    },
    submitSetting() {
      this.$refs['settingForm'].validate((valid) => {
        if (valid) {
          this.$modal.msgSuccess("保存成功")
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    page() {
      this.loading = true;
      this.selectUnit();
      distributeWorkOrder(this.queryParams).then(res => {
        this.workOrderList = res.data.records;
        this.total = res.total;
        this.loading = false;
      })
    },
    changeUnit(unitId, unitName) {
      this.unitId = unitId;
      this.queryParams.unitId = unitId;
      this.unitName = unitName;
      this.page()
    },
    clearFastDistributeForm() {
      this.fastDistributeForm.fastWay = ''
      this.fastDistributeForm.start = null
      this.fastDistributeForm.end = null
      this.fastDistributeForm.fastNumLimit = null
      this.fastTimeRange = []
      this.fastDistributeForm.errorType = null
    },
    // 全部下发
    allDistribute() {
      this.selectedIdsDistributeForm.unitId = this.unitId
      selectedIdsDistribute(this.selectedIdsDistributeForm).then(res => {
        this.$message.success("工单下发成功")
        this.page();
      })
    },
    // 快速下发
    fastDistribute() {
      this.$refs['fastDistributeForm'].validate((valid) => {
        if (valid) {
          this.fastDistributeForm.start = this.fastTimeRange[0]
          this.fastDistributeForm.end = this.fastTimeRange[1]
          this.fastDistributeForm.unitId = this.unitId
          fastDistribute(this.fastDistributeForm).then(res => {
            res.code == 200 ? this.$message.success(res.msg) : this.$message.warning(res.msg)
            this.clearFastDistributeForm();
            this.page();
          })
        }
      })  
    },
    // 选中工单下发
    selectedDistribute() {
      if (this.multipleSelection.length < 1) {
        this.$message.warning("请先选择要下发的工单")
        return
      } 
      this.selectedIdsDistributeForm.unitId = this.unitId;
      this.selectedIdsDistributeForm.ids = this.multipleSelection;
      selectedIdsDistribute(this.selectedIdsDistributeForm).then(res => {
        this.$message.success("工单下发成功")
        this.selectedIdsDistributeForm.ids = [];
        this.page();
      })
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    getList() {
 
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.multipleSelection = selection.map(item => item.id)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加合同";
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWorkOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.page();
            });
          } else {
            addWorkOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.page();
            });
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 运维公司下拉数据
    selectUnit() {
      workList().then(res => {
        this.unitList = res.data;
      })
    },
    // 远程搜索点位
    remoteGetPoints(query) {
      if (query !== '') {
        this.selectLoading = true;
        let data = {
          "keyword": query
        }
        pointSelectData(data).then(res => {
          this.pointList = res.data;
          this.selectLoading = false;
        })
      } else {
        this.pointList = [];
      }
    },
  }
}
</script>
 
<style scoped>
.row {
  padding: 0 20px;
}
.op-warp {
  margin-top: 10px;
}
.content-warp {
  margin-top: 10px;
}
.op {
  margin-right: 5px;
}
.setting {
  position: absolute;
  top: 10px;
  right:5px
}
 
</style>