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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<template>
  <basic-container
    :class="[
      $store.state.control.screenSize == 1366 ? 'smallSize' : 'normalSize',
      $store.state.control.windowWidth >= 1024 ? 'tooRowSearch1' : '',
    ]"
  >
    <avue-crud
      class="tablesss"
      :option="option1"
      :data="data1"
      :page.sync="page1"
      ref="crudrec1"
      v-model="form"
      :table-loading="loading1"
      :before-open="beforeOpen"
      @row-save="rowSave1"
      @search-change="searchChange1"
      @search-reset="searchReset1"
      @row-update="rowUpdate1"
      @row-del="rowDel1"
      @selection-change="selectionChange1"
      @refresh-change="refreshChange1"
      @on-load="onLoad1"
    >
    </avue-crud>
  </basic-container>
</template>
 
<script>
import {
  getdata1,
  adddata1,
  update1,
  remove1,
  getDispatcherUnitByDeptId,
  overDispatcher,
} from "@/api/dispatch/dispatch";
import { update, getListByDeptId } from "@/api/system/user";
import { mapState } from "vuex";
 
export default {
  data() {
    return {
      deptCategory: "",
      deptId: "",
 
      loading1: true, //派遣记录
      selectionList1: [],
      page1: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        ...this.$store.state.control.changePageSize,
      },
      form: {},
      query1: {},
      data1: [],
      option1: {
        // card: true,
        tip: false,
        index: true,
        // menu: false,
        addBtn: false,
        menu: false,
        searchSize: "mini",
        searchMenuSpan: 8,
        height: 623,
        cellBtn: false,
        delBtnText: "结束派遣",
        editBtnText: "变更派遣",
        // addBtn: false,
        // menuWidth: 160,
        align: "center",
        selection: true,
        ...this.$store.state.control.clearOtherBut,
        column: [
          // },
          {
            label: "派遣单位",
            prop: "dispatcherCompany",
            // addDisplay: false,
            // editDisplay: false,
            // search: true,
            // labelWidth: 120,
            // searchSpan: 4,
            minWidth: 110,
            addDisplay: false,
            editDisplay: false,
          },
          {
            label: "保安公司",
            prop: "deptId",
            search: true,
            overHidden: true,
            labelWidth: 120,
            type: "tree",
            searchSpan: 4,
            searchLabelWidth: 75,
            cascaderItem: ["userIds"],
            props: {
              label: "title",
              value: "id",
            },
            width: 180,
            dicUrl: `/api/blade-system/dept/security_lazy-tree?parentId=1413470343230877697`,
            rules: [
              {
                required: true,
                message: "请输入保安公司",
                trigger: "blur",
              },
            ],
          },
          {
            label: "派遣单位",
            prop: "dispatcherUnitId",
            labelWidth: 120,
            searchLabelWidth: 80,
            // dicUrl: "/api/dispatcherUnit/page-tree?deptId={{key}}",
            props: {
              label: "name",
              value: "id",
            },
            hide: true,
            searchSpan: 4,
            search: true,
            overHidden: true,
            type: "tree",
            rules: [
              {
                required: true,
                message: "请输入派遣单位",
                trigger: "blur",
              },
            ],
          },
          {
            label: "保安员",
            prop: "userIds",
            type: "tree",
            width: 65,
            labelWidth: 120,
            searchLabelWidth: 62,
            searchSpan: 4,
            search: true,
            hide: true,
            props: {
              label: "realName",
              value: "id",
            },
            // dicUrl: `/api/blade-user/page-security-units?dispatch=1&deptId={{key}}`,
            dicUrl: `/api/blade-user/page-security-units?status=1&deptId={{key}}`,
            dicData: [],
            rules: [
              {
                required: true,
                message: "请选择保安",
                trigger: "blur",
              },
            ],
          },
          {
            label: "保安员",
            prop: "securityName",
            type: "tree",
            width: 70,
            labelWidth: 120,
            addDisplay: false,
            editDisplay: false,
            // hide: true,
            // props: {
            //   label: "realName",
            //   value: "id",
            // },
            // dicUrl: `/api/blade-user/page-security-units?dispatch=1&deptId={{key}}`,
            dicData: [],
            rules: [
              {
                required: true,
                message: "请选择保安",
                trigger: "blur",
              },
            ],
          },
 
          {
            label: "身份证",
            prop: "idCardNo",
            labelWidth: 120,
            overHidden: true,
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                required: true,
                message: "请输入身份证",
                trigger: "click",
              },
            ],
            // search: true,
            // searchSpan: 4,
            // overHidden: true
          },
          // {
          //     label: "派遣人",
          //     prop: "dispatcher",
          //     // search: true,
          //     // searchSpan: 4,
          //     // overHidden: true
          // },
 
          {
            label: "开始时间",
            prop: "dispatchertime",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            labelWidth: 120,
            searchSpan: 5,
            // search: true,
            overHidden: true,
            rules: [
              {
                required: true,
                message: "请输入派遣时间",
                trigger: "click",
              },
            ],
            // overHidden: true
          },
          {
            label: "结束时间",
            prop: "endTime",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            labelWidth: 120,
            overHidden: true,
            rules: [
              {
                required: true,
                message: "请输入结束时间",
                trigger: "click",
              },
            ],
            // search: true,
            // searchSpan: 4,
            // overHidden: true
          },
          {
            label: "派遣时间",
            prop: "releaseTimeRange",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            searchValue: [this.getStartTime(), this.getEndTime()],
            searchRange: true,
            searchLabelWidth: 75,
            searchSpan: 5,
            hide: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入时间",
                trigger: "blur",
              },
            ],
          },
          {
            label: "派遣地址",
            prop: "dispatcheraddress",
            overHidden: true,
            labelWidth: 120,
            rules: [
              {
                required: true,
                message: "请输入派遣地址",
                trigger: "click",
              },
            ],
            // search: true,
            // searchSpan: 4,
            // overHidden: true
          },
        ],
      },
    };
  },
  created() {
    if (this.userInfo.role_name == "保安公司管理员") {
      // console.log("保安公司管理员登入");
      const deptColumn = this.findObject(this.option1.column, "deptId");
      deptColumn.search = false;
    } else {
      const deptColumn = this.findObject(
        this.option1.column,
        "dispatcherUnitId"
      );
      deptColumn.search = false;
    }
  },
  computed: {
    // },
    ids1() {
      let ids1 = [];
      this.selectionList1.forEach((ele) => {
        ids1.push(ele.id);
      });
      return ids1.join(",");
    },
    ...mapState({
      userInfo: (state) => state.user.userInfo,
    }),
    deps() {
      return this.form.deptId;
    },
  },
 
  methods: {
    handleChangeTABS(column) {
      this.typeTABS = column;
      if (column.prop == "tab1") {
        this.loading1 = false;
        // this.onLoad(this.page);
      } else if (column.prop == "tab2") {
        // this.loading = false;
        // console.log(document.getElementsByClassName("el-card__body")[0]);
        this.onLoad1(this.page1); //第二个表格不会自动执行
      }
      // this.$message.success(JSON.stringify(column));
    },
 
    //派遣记录
    sizeChange1(val) {
      this.page1.currentPage = 1;
      this.page1.pageSize = val;
      // this.getData();
      this.onLoad1(this.page1, this.query1);
    },
    currentChange1(val) {
      this.page1.currentPage = val;
      // this.getData();
      this.onLoad1(this.page1, this.query1);
    },
    rowSave1(form, done, loading) {
      // if(this.userInfo.role_name=="保安公司管理员"){
      //   const userColumn = this.findObject(this.option1.column, "userIds");
      //   userColumn.dicUrl = "/api/blade-user/page-security-units?deptId="+this.userInfo.dept_id;
      // }
 
      adddata1(form).then(
        (res) => {
          this.onLoad1(this.page1);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
      // }
    },
    searchChange1(params, done) {
      this.query1 = params;
      this.page1.currentPage = 1;
      this.onLoad1(this.page1, params);
      done();
    },
    searchReset1() {
      this.query = {};
      this.onLoad1(this.page1);
    },
    rowUpdate1(row, index, done, loading) {
      // if(this.userInfo.role_name=="保安公司管理员"){
      //   const userColumn = this.findObject(this.option1.column, "userIds");
      //   userColumn.dicUrl = "/api/blade-user/page-security-units?deptId="+this.userInfo.dept_id;
      // }
      update1(row).then(
        () => {
          this.onLoad1(this.page1);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowDel1(row) {
      this.$confirm("确定结束当前派遣?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return overDispatcher(row);
        })
        .then(() => {
          this.onLoad1(this.page1);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    selectionChange1(list) {
      this.selectionList1 = list;
      // console.log(this.selectionList1.length);
    },
    handleDelete1() {
      // console.log(this.selectionList1);
      if (this.selectionList1.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove1(this.ids1);
        })
        .then(() => {
          this.onLoad1(this.page1);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crudrec1.toggleSelection();
        });
    },
    refreshChange1() {
      // console.log(4534)
      this.onLoad1(this.page1, this.query1);
    },
 
    beforeOpen(done, type) {
      this.initFlag = true;
      done();
    },
 
    getStartTime() {
      if (
        this.$route.query.startTime != undefined &&
        this.$route.query.startTime != null &&
        this.$route.query.startTime != ""
      ) {
        return this.$route.query.startTime;
      }
      return "";
    },
    getEndTime() {
      if (
        this.$route.query.endTime != undefined &&
        this.$route.query.endTime != null &&
        this.$route.query.endTime != ""
      ) {
        return this.$route.query.endTime;
      }
      return "";
    },
    //
    onLoad1(page, params = {}) {
      this.loading1 = true;
      var values;
      //默认查询已派遣的,派遣结束,未派遣的不显示
      params["dispatch"] = 0;
      const { releaseTimeRange } = this.query1;
      if (releaseTimeRange) {
        values = {
          ...params,
          beginTime: releaseTimeRange[0],
          overTime: releaseTimeRange[1],
          ...this.query,
        };
        values.releaseTimeRange = null;
      } else {
        values = {
          ...params,
          ...this.query,
        };
      }
 
      if (this.userInfo.role_name == "保安公司管理员") {
        const deptColumn = this.findObject(this.option1.column, "deptId");
        deptColumn.disabled = true;
        // deptColumn.search = false; //会报错
        deptColumn.value = this.userInfo.dept_id;
        this.initData(2);
      } else {
        this.initData(1);
      }
 
      getdata1(
        page.currentPage,
        page.pageSize,
        // Object.assign(params, this.query)
        values
      ).then((res) => {
        const data = res.data.data;
        this.page1.total = data.total;
        this.data1 = data.records;
        this.$store.commit("setWindowSizeHeightAdd");
        this.loading1 = false;
        // this.$nextTick(() => this.$refs.crudrec1.dicInit("cascader"));
        // console.log(this.form, 111111);
      });
    },
    initData(type) {
      var that = this;
      if (type == 1) {
        getDispatcherUnitByDeptId(null).then((res) => {
          const dispatcherUnitIdColumn = that.findObject(
            this.option1.column,
            "dispatcherUnitId"
          );
          // console.log(res.data.data, 111);
          dispatcherUnitIdColumn.dicData = res.data.data;
        });
      }
      if (type == 2) {
        getDispatcherUnitByDeptId(that.userInfo.dept_id).then((res) => {
          const dispatcherUnitIdColumn = that.findObject(
            this.option1.column,
            "dispatcherUnitId"
          );
          dispatcherUnitIdColumn.dicData = res.data.data;
        });
        getListByDeptId(that.userInfo.dept_id, 1).then((res) => {
          const userIdsColumn = that.findObject(this.option1.column, "userIds");
          userIdsColumn.dicData = res.data.data;
        });
      }
    },
  },
  //  watch: {
  //   // "form.deptId"() {
  //   //   this.initData();
  //   // }
  //   deps(){
  //     console.log(this.deps,5646646)
  //   }
  // },
  mounted() {
    // this.onLoad1(this.page1, this.query1);
    this.$store.commit("setWindowSizeHeightAdd");
  },
};
</script>
 
<style lang="scss" scoped>
.dispatch {
  width: 100%;
  height: 100%;
  //   border: 1px solid #000;
  box-sizing: border-box;
}
.el-collapse-item {
  padding-top: 15px !important;
}
</style>