zjf
2023-03-03 bafa9dff4d9880c562f4d3a7b83bd4c1129240c5
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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
<template>
  <el-dialog
    :visible.sync="visible"
    :append-to-body="true"
    title="场景管理"
    width="700px"
    @close="handleCancel">
    <div class="scene-name">您可通过拖拽管理标签</div>
    <flexbox class="scene-list">
      <div class="scene-list-box">
        <flexbox class="scene-list-head">
          <el-checkbox
            :indeterminate="isleftIndeterminate"
            v-model="checkleftAll"
            @change="handleleftCheckAllChange"/>
          <div class="scene-list-head-name">显示的标签</div>
          <div class="scene-list-head-detail">{{ leftCheckItems.length + '/' + checkedLeftData.length }}</div>
        </flexbox>
        <div class="scene-list-body">
          <flexbox
            v-for="(item, index) in checkedLeftData"
            v-if="item.isSystem === 1"
            :key="index"
            class="list-item">
            <div
              :class="{'default-mark-active': item.sceneId === defaultId}"
              class="default-mark"/>
            <el-checkbox
              v-model="item.check"
              :disabled="true"
              class="list-item-check"
              @change="leftCheckItemChange"/>
            <div class="list-item-name">{{ item.name }}</div>
            <div class="list-item-handle">
              <el-dropdown
                trigger="click"
                @command="defaultHandle">
                <i
                  class="el-icon-arrow-down"
                  @click="itemHandle('default', item, index)"/>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>设置为默认标签</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </flexbox>
          <draggable
            v-model="checkedLeftData"
            :move="leftMove"
            :options="{group: 'list',forceFallback:false, fallbackClass:'draggingStyle'}"
            style="min-height: 100px;"
            @end="leftMoveEnd">
            <flexbox
              v-for="(item, index) in checkedLeftData"
              v-if="item.isSystem !== 1"
              :key="index"
              class="list-item">
              <div
                :class="{'default-mark-active': item.sceneId === defaultId}"
                class="default-mark"/>
              <el-checkbox
                v-model="item.check"
                class="list-item-check"
                @change="leftCheckItemChange"/>
              <div class="list-item-name">{{ item.name }}</div>
              <div class="list-item-handle">
                <i
                  class="el-icon-edit"
                  @click="itemHandle('edit', item, index)"/>
                <i
                  class="el-icon-delete"
                  @click="itemHandle('delete', item, index)"/>
                <el-dropdown @command="defaultHandle">
                  <i
                    class="el-icon-arrow-down"
                    @click="itemHandle('default', item, index)"/>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>设置为默认标签</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </flexbox>
          </draggable>
 
        </div>
      </div>
      <div class="scene-middle-list">
        <el-button
          :class="{'scene-middle-button-select':rightCheckItems.length > 0}"
          :disabled="rightCheckItems.length === 0"
          class="scene-middle-left-button"
          @click="changePositon('left')">
          <i class="el-icon-arrow-left scene-middle-icon"/>
        </el-button>
        <el-button
          :class="{'scene-middle-button-select':leftCheckItems.length > 0}"
          :disabled="leftCheckItems.length === 0"
          class="scene-middle-right-button"
          @click="changePositon('right')">
          <i class="el-icon-arrow-right scene-middle-icon"/>
        </el-button>
      </div>
      <div class="scene-list-box">
        <flexbox class="scene-list-head">
          <el-checkbox
            :indeterminate="isrightIndeterminate"
            v-model="checkrightAll"
            @change="handlerightCheckAllChange"/>
          <div class="scene-list-head-name">隐藏的标签</div>
          <div class="scene-list-head-detail">{{ rightCheckItems.length + '/' + checkedRightData.length }}</div>
        </flexbox>
        <div class="scene-list-body">
          <draggable
            v-model="checkedRightData"
            :move="rightMove"
            :options="{group: 'list',forceFallback:false, fallbackClass:'draggingStyle'}"
            style="min-height: 100px;"
            @end="rightMoveEnd">
            <flexbox
              v-for="(item, index) in checkedRightData"
              :key="index"
              class="list-item">
              <el-checkbox
                v-model="item.check"
                style="margin-left:9px;"
                class="list-item-check"
                @change="rightCheckItemChange"/>
              <div class="list-item-name">{{ item.name }}</div>
            </flexbox>
          </draggable>
        </div>
      </div>
    </flexbox>
    <div class="handle-bar">
      <div
        class="handle-bar-add"
        @click="addAndEditScene('add',{})">+ 新建场景</div>
      <div class="handle-bar-save">
        <el-button @click.native="handleCancel">取消</el-button>
        <el-button
          type="primary"
          @click.native="handleConfirm">保存</el-button>
      </div>
    </div>
    <scene-create
      :field-list="fieldList"
      :crm-type="crmType"
      :dialog-visible.sync="showCreateScene"
      :obj="filterObj"
      :name="filterName"
      :edit_id="filterEditId"
      :is-default="filterDefault"
      @saveSuccess="getSceneList"/>
  </el-dialog>
</template>
 
<script type="text/javascript">
// import crmTypeModel from '@/views/clients/model/crmTypeModel'
// import {
//   crmSceneSetIndex,
//   crmSceneSort,
//   crmSceneDefaults,
//   crmSceneDelete,
//   filterIndexfields
// } from '@/api/clients/common'
import draggable from 'vuedraggable'
import SceneCreate from './SceneCreate' // 新建编辑场景
 
export default {
  name: 'SceneSet', // 场景 设置
  components: {
    draggable,
    SceneCreate
  },
  props: {
    dialogVisible: {
      type: Boolean,
      required: true,
      default: false
    },
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      defaultId: '', // 默认场景id
      visible: false, // 控制展示
      isleftIndeterminate: false, // 标注头部是多选框效果
      checkleftAll: false, // 关联全选操作多选框
 
      checkedLeftData: [], // 数据源
      leftCheckItems: [], // 选择的数据源
 
      isrightIndeterminate: false,
      checkrightAll: false,
 
      checkedRightData: [],
      rightCheckItems: [],
 
      moveItem: {}, // 移动中的item
      handlDefaultItem: {}, // 设置默认的中间item
 
      /** 添加 编辑 场景 */
      showCreateScene: false, // 展示场景添加
      fieldList: [],
      filterObj: { form: [] }, // 筛选确定数据
      filterName: '',
      filterDefault: false,
      filterEditId: '' // 编辑id
    }
  },
  computed: {},
  watch: {
    dialogVisible: {
      handler (val) {
        this.visible = val
        if (val) {
          this.getSceneList()
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted () {},
  methods: {
    getSceneList () {
      // crmSceneSetIndex({
      //   type: crmTypeModel[this.crmType]
      // })
      //   .then(res => {
      //     this.checkedLeftData = res.data.value.map(function (item, index) {
      //       item.check = false
      //       return item
      //     })
      //     this.checkedRightData = res.data.hide_value.map(function (
      //       item,
      //       index
      //     ) {
      //       item.check = false
      //       return item
      //     })
      //     var defaultScene = this.checkedLeftData.filter(function (item, index) {
      //       return item.isDefault === 1
      //     })
      //     // 如果有默认场景
      //     if (defaultScene && defaultScene.length > 0) {
      //       this.defaultId = defaultScene[0].sceneId
      //     } else {
      //       this.defaultId = ''
      //     }
      //   })
      //   .catch(() => {})
    },
    /**
     * 确定选择
     */
    handleConfirm () {
      // 如果选择默认的 不包含在左侧列表 重置为没有默认
      var self = this
      var leftTemps = this.checkedLeftData.filter(function (item, index) {
        return item.sceneId === self.defaultId
      })
      if (leftTemps.length === 0) {
        this.defaultId = ''
      }
      // crmSceneSort({
      //   type: crmTypeModel[this.crmType],
      //   noHideIds: this.checkedLeftData
      //     .map(function (item, index, array) {
      //       return item.sceneId
      //     })
      //     .join(','),
      //   hideIds: this.checkedRightData
      //     .map(function (item, index, array) {
      //       return item.sceneId
      //     })
      //     .join(',')
      // })
      //   .then(res => {
      //     this.$message({
      //       type: 'success',
      //       message: '操作成功'
      //     })
      //     this.handleCancel()
      //     this.$emit('save-success')
      //   })
      //   .catch(() => {})
    },
    /** 事项操作 */
    itemHandle (type, item, index) {
      if (type === 'edit') {
        this.addAndEditScene('edit', item)
      } else if (type === 'delete') {
        this.$confirm('您确定要删除这一条数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            // crmSceneDelete({
            //   sceneId: item.sceneId
            // })
            //   .then(res => {
            //     this.$message({
            //       type: 'success',
            //       message: '删除成功'
            //     })
            //     this.checkedLeftData.splice(index, 1)
            //     this.leftCheckItemChange()
            //     this.$emit('save-success')
            //   })
            //   .catch(() => {})
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else if (type === 'default') {
        this.handlDefaultItem = item
      }
    },
    /** 操作默认 */
    defaultHandle () {
      // crmSceneDefaults({
      //   sceneId: this.handlDefaultItem.sceneId
      // })
      //   .then(res => {
      //     this.$message({
      //       type: 'success',
      //       message: '操作成功'
      //     })
      //     this.defaultId = this.handlDefaultItem.sceneId
      //   })
      //   .catch(() => {})
    },
    /** 添加编辑场景 */
    addAndEditScene (type, data) {
      // filterIndexfields({
      //   label: crmTypeModel[this.crmType]
      // })
      //   .then(res => {
      //     this.fieldList = res.data
      //     if (type === 'edit') {
      //       this.filterObj = { form: [], obj: data.data }
      //       this.filterName = data.name
      //       this.filterDefault = data.isDefault === 1
      //       this.filterEditId = data.sceneId.toString()
      //     } else {
      //       this.filterObj = { form: [] }
      //       this.filterEditId = ''
      //       this.filterName = ''
      //       this.filterDefault = false
      //     }
      //     this.showCreateScene = true
      //   })
      //   .catch(() => {})
    },
    /**
     * 取消选择
     */
    handleCancel () {
      this.visible = false
      this.$emit('update:dialogVisible', false)
    },
    /** 拖拽操作 */
    rightMoveEnd (evt) {
      this.moveItem.check = false
      this.leftCheckItemChange()
      this.rightCheckItemChange()
    },
    rightMove (obj) {
      this.moveItem = obj.draggedContext.element
    },
    leftMoveEnd (evt) {
      this.moveItem.check = false
      this.leftCheckItemChange()
      this.rightCheckItemChange()
    },
    leftMove (obj) {
      this.moveItem = obj.draggedContext.element
    },
    // 选择全部
    handleleftCheckAllChange (value) {
      if (value) {
        this.isleftIndeterminate = false
      }
      this.checkedLeftData = this.checkedLeftData.filter(function (
        item,
        index,
        array
      ) {
        item.check = value
        return item
      })
      this.leftCheckItems = value ? this.checkedLeftData : []
    },
    leftCheckItemChange () {
      this.leftCheckItems = this.checkedLeftData.filter(function (
        item,
        index,
        array
      ) {
        return item.check === true
      })
      if (this.leftCheckItems.length > 0) {
        if (this.leftCheckItems.length === this.checkedLeftData.length) {
          this.checkleftAll = true
          this.isleftIndeterminate = false
        } else {
          this.checkleftAll = false
          this.isleftIndeterminate = true
        }
      } else {
        this.checkleftAll = false
        this.isleftIndeterminate = false
      }
    },
    // 选择全部
    handlerightCheckAllChange (value) {
      if (value) {
        this.isrightIndeterminate = false
      }
      this.checkedRightData = this.checkedRightData.filter(function (
        item,
        index,
        array
      ) {
        item.check = value
        return item
      })
      this.rightCheckItems = value ? this.checkedRightData : []
    },
    rightCheckItemChange () {
      this.rightCheckItems = this.checkedRightData.filter(function (
        item,
        index,
        array
      ) {
        return item.check === true
      })
      if (this.rightCheckItems.length > 0) {
        if (this.rightCheckItems.length === this.checkedRightData.length) {
          this.checkrightAll = true
          this.isrightIndeterminate = false
        } else {
          this.checkrightAll = false
          this.isrightIndeterminate = true
        }
      } else {
        this.checkrightAll = false
        this.isrightIndeterminate = false
      }
    },
    // 按钮操作
    changePositon (type) {
      var self = this
      // 从右往左
      if (type === 'left') {
        this.checkedRightData = this.checkedRightData.filter(function (
          item,
          index,
          array
        ) {
          var remove = false
          self.rightCheckItems.forEach(function (element, index) {
            if (item.sceneId === element.sceneId) {
              remove = true
            }
          })
          return !remove
        })
 
        this.rightCheckItems.forEach(function (element, index) {
          element.check = false
          self.checkedLeftData.push(element)
        })
 
        this.rightCheckItems = []
        this.isrightIndeterminate = false
        this.checkrightAll = false
 
        // 刷新左侧效果
        this.leftCheckItemChange()
        this.rightCheckItemChange()
      } else {
        this.checkedLeftData = this.checkedLeftData.filter(function (
          item,
          index,
          array
        ) {
          var remove = false
          self.leftCheckItems.forEach(function (element, index) {
            if (item.sceneId === element.sceneId) {
              remove = true
            }
          })
          return !remove
        })
 
        this.leftCheckItems.forEach(function (element, index) {
          element.check = false
          self.checkedRightData.push(element)
        })
 
        this.leftCheckItems = []
        this.isleftIndeterminate = false
        this.checkleftAll = false
 
        // 刷新右侧效果
        this.leftCheckItemChange()
        this.rightCheckItemChange()
      }
    }
  }
}
</script>
<style rel="stylesheet/less" lang="less" scoped>
.scene-name {
  font-size: 12px;
  padding-bottom: 5px;
  color: #aaa;
}
 
.default-mark {
  width: 4px;
  height: 4px;
  border-radius: 2px;
  margin-right: 5px;
}
.default-mark-active {
  // background-color: #4D88FF;
}
 
.scene-list {
  .scene-list-box {
    flex: 1;
    border: 1px solid #e6e6e6;
    border-radius: 2px;
    height: 300px;
    position: relative;
    padding: 15px;
  }
  .scene-middle-list {
    width: 50px;
    text-align: center;
    button {
      border: 1px solid #cccccc;
      width: 34px;
      height: 34px;
      border-radius: 17px;
      background-color: #f5f7fa;
    }
    .scene-middle-icon {
      color: #cccccc;
      font-size: 14px;
    }
    .scene-middle-left-button {
    }
    .scene-middle-right-button {
      margin-top: 15px;
      margin-left: 0;
    }
 
    .scene-middle-button-select {
      border: 1px solid #4D88FF !important;
      background-color: #4D88FF !important;
      .scene-middle-icon {
        color: white !important;
      }
    }
  }
  .scene-list-head {
    padding-bottom: 15px;
    padding-left: 9px;
    border-bottom: 1px dashed #e6e6e6;
    font-size: 13px;
    .scene-list-head-name {
      color: #333;
      flex: 1;
      margin: 0 8px;
    }
 
    .scene-list-head-detail {
      color: #aaa;
    }
  }
  .scene-list-body {
    padding: 5px 0;
    height: 240px;
    position: relative;
    overflow-y: auto;
  }
 
  .list-item {
    padding: 5px 0;
    cursor: pointer;
    .list-item-check {
      margin-right: 8px;
    }
    .list-item-name {
      font-size: 13px;
      color: #333;
      flex: 1;
    }
    .list-item-handle {
      flex-shrink: 0;
      display: none;
      i {
        color: #aaa;
        font-size: 12px;
        margin-right: 5px;
      }
      i:hover {
        color: #4D88FF;
      }
    }
  }
 
  .list-item:hover {
    .list-item-handle {
      display: block;
    }
  }
}
 
.handle-bar {
  font-size: 12px;
  .handle-bar-add {
    cursor: pointer;
    color: #4D88FF;
    padding: 20px 10px;
  }
  .handle-bar-save {
    position: relative;
    height: 30px;
    button {
      float: right;
      margin-right: 10px;
    }
  }
}
</style>