zjf
2023-02-24 2126cd24b8a0174ac0597340917c0a4595f72254
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
<template>
  <div class='max-container'>
    <!--<div class='i-types' v-if='!isEdit'>
        <div class='type-button ' :class="typeBtn===0?'isType':''" @click='getType(0)'>写跟进</div>
        <div class='type-button ' :class="typeBtn===1?'isType':''" @click='getType(1)'>创建商机</div>
        <div class='type-button ' :class="typeBtn===2?'isType':''" @click='getType(2)'>创建报价单</div>
        <div class='type-button ' :class="typeBtn===3?'isType':''" @click='getType(3)'>创建合同</div>
        <div class='type-button ' :class="typeBtn===4?'isType':''" @click='getType(4)'>创建订单</div>
    </div> -->
    <div class="mix-container">
      <flexbox class="se-section"  v-if='isOpen'>
        <!--<el-dropdown
          style="margin-right: 20px;"
          trigger="click"
          @command="handleTypeDrop">
          <flexbox class="se-select">
            <div class="se-select-name">{{ followType ? followType : '跟进类别' }}</div>
            <i
              class="el-icon-arrow-down el-icon--right"
              style="color:#ccc;"/>
          </flexbox>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="(item, index) in followTypes"
              :key="index"
              :command="item.type">{{ item.name }}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>-->
        <el-dropdown
          style="margin-right: 20px;"
          trigger="click"
          @command="handleTypeDropContact">
          <flexbox class="se-select">
            <div class="se-select-name">{{ contactType ? contactType : '联系人' }}</div>
            <i
              class="el-icon-arrow-down el-icon--right"
              style="color:#ccc;"/>
          </flexbox>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="(item, index) in contactTypes"
              :key="index"
              :command="item.type">{{ item.name }}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown
          style="margin-right: 20px;"
          trigger="click"
          @command="handleTypeDropWay">
          <flexbox class="se-select">
            <div class="se-select-name">{{ wayType ? wayType : '跟进方式' }}</div>
            <i
              class="el-icon-arrow-down el-icon--right"
              style="color:#ccc;"/>
          </flexbox>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="(item, index) in wayTypes"
              :key="index"
              :command="item.type">{{ item.name }}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <!--<div class="se-name">下次联系时间</div> -->
        <el-date-picker
          v-model="nextTime"
          :default-value="new Date"
          :editable="false"
          class="se-datepicker"
          type="date"
          placeholder="当前联系时间"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"/>
        <!--<el-checkbox
          v-if="showOAPermission"
          v-model="isEvent">是否完成跟进</el-checkbox>-->
      </flexbox>
      <div class="i-cont">
        <!--<el-input
          ref="text"
          v-model="title"
          type="text"
          clearable
          resize="none"
          placeholder="请输入标题"/> -->
        <el-input
          ref="textarea"
          v-model="content"
          :autosize="inputAutosize"
          type="textarea"
          clearable
          resize="none"
          placeholder="请输入内容"
          :class="!isOpen?'singleInput':''"
          @focus="inputFocus"/>
      </div>
      <section
        v-if="imgFiles.length > 0"
        class="img-cont">
        <flexbox wrap="wrap">
          <div
            v-for="(item, index) in imgFiles"
            :key="index"
            :style="{ 'background-image': 'url('+ headUrl + item.path +')' }"
            class="img-item"
            @mouseover="mouseImgOver(item, index)"
            @mouseleave="mouseImgLeave(item, index)">
            <div
              v-if="item.showDelete"
              class="img-delete"
              @click="deleteImgOrFile('image', item, index)">×</div>
          </div>
          <div class="img-item-add">
            <input
              type="file"
              class="img-item-iput"
              accept="image/*"
              multiple
              @change="uploadFile">
          </div>
        </flexbox>
        <div
          class="img-bar"
          @click="deleteAllImg">全部删除</div>
      </section>
      <section
        v-if="files.length > 0"
        class="file-cont">
        <flexbox class="f-header">
          <img
            class="f-logo"
            src="@/assets/img/send_file.png">
          <div class="f-name">附件</div>
        </flexbox>
        <div class="f-body">
          <flexbox
            v-for="(item, index) in files"
            :key="index"
            class="f-item">
            <img
              :src="item.icon"
              class="f-img">
            <div class="f-name">{{ item.name +'('+item.size+')' }}</div>
            <!--{{ item.name+'('+item.size+')' }}-->
            <div
              class="close-button"
              @click="deleteImgOrFile('file', item, index)">×</div>
          </flexbox>
        </div>
        <div
          class="img-bar"
          @click="files=[]">全部删除</div>
      </section>
      <section
        v-if="business.length > 0"
        class="c-cont">
        <flexbox class="c-header">
          <img
            class="c-logo"
            src="@/assets/img/send_business.png">
          <div class="c-name">商机</div>
        </flexbox>
        <div class="c-body">
          <flexbox wrap="wrap">
            <flexbox
              v-for="(item, index) in business"
              :key="index"
              class="c-item">
              <div class="c-item-name">{{ item.businessName }}</div>
              <div
                class="c-item-close"
                @click="business.splice(index, 1)">×</div>
            </flexbox>
          </flexbox>
        </div>
      </section>
      <section
        v-if="contacts.length > 0"
        class="c-cont">
        <flexbox class="c-header">
          <img
            class="c-logo"
            src="@/assets/img/send_contacts.png">
          <div class="c-name">联系人</div>
        </flexbox>
        <div class="c-body">
          <flexbox wrap="wrap">
            <flexbox
              v-for="(item, index) in contacts"
              :key="index"
              class="c-item">
              <div class="c-item-name">{{ item.name }}</div>
              <div
                class="c-item-close"
                @click="contacts.splice(index, 1)">×</div>
            </flexbox>
          </flexbox>
        </div>
      </section>
      <flexbox class="bar-cont" v-if='isOpen'>
        <template v-for="(item, index) in barItems">
          <flexbox
            v-if="item.type=='img'||item.type=='file'"
            :key="index"
            class="bar-item"
            @click.native="barClick(item)">
            <input
              :accept="item.data"
              type="file"
              class="bar-input"
              multiple
              @change="uploadFile">
            <img
              :src="item.img"
              class="bar-img">
            <div class="bar-title">{{ item.title }}</div>
          </flexbox>
        </template>
        <el-button
          class="se-collect"
          @click.native="inputBlur">收起</el-button>
        <el-button
          class="se-send"
          type="primary"
          @click.native="sendInfo">发布</el-button>
      </flexbox>
    </div>
  </div>
</template>
 
<script>
import { fileSize, getFileTypeIcon } from '@/utils/index'
import { UploadImageAsync, UploadFileAsync } from '@/api/common'
import CrmRelative from '@/components/CreateCom/CrmRelative'
import followLogType from '@/views/clients/mixins/followLogType'
import { ResouceUrl } from '@/utils/baseconfig'
export default {
  /** 跟进记录 下的 添加 有添加框的都需要 */
  name: 'MixAdd',
  components: {
    CrmRelative
  },
  mixins: [followLogType],
  props: {
    /** 展示相关商机关联 */
    showRelativeBusiness: {
      type: Boolean,
      default: false
    },
    /** 跟进记录编辑 */
    isEdit: {
      type: Boolean,
      default: false
    },
    /** 展示相关商机关联 */
    showRelativeContacts: {
      type: Boolean,
      default: false
    },
    /** 模块ID */
    id: [String, Number],
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    },
    detail: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      /** 输入法 */
      title: '',
      content: '',
      inputAutosize: { minRows: 1, maxRows: 10 }, // 默认1 聚焦是 变成10
      isOpen: false,
      /** 快捷添加 */
      barItems: [
        {
          img: require('@/assets/img/send_img.png'),
          title: '图片',
          type: 'img',
          data: 'image/*'
        },
        {
          img: require('@/assets/img/send_file.png'),
          title: '附件',
          type: 'file',
          data: '*.*'
        }
      ],
      /** 图片信息 */
      imgFiles: [],
      /** 图片信息 */
      files: [],
      /** 关联商机信息 */
      business: [],
      /** 关联联系人信息 */
      contacts: [],
      /** 展示关联弹窗 */
      showRelativeType: '',
      batchId: '', // 批次ID
      typeBtn: 0,
      /** 下次联系时间 */
      nextTime: '',
      /** 是否添加日程提醒 */
      isEvent: false,
      wayTypeId: 0,
      followTypeId: 0,
      contactTypeId: '',
      pickerOptions: {
        // disabledDate (time) {
        //   return time.getTime() < Date.now()
        // }
      }
    }
  },
  watch: {
    detail: function (val) {
      if (val && this.crmType === 'business') {
        this.getContact()
      }
    }
  },
  computed: {},
  mounted () {
    this.headUrl = ResouceUrl
    /** 控制展示关联商机 和 联系人 */
    if (this.showRelativeBusiness) {
      this.barItems.push({
        img: require('@/assets/img/send_business.png'),
        title: '关联商机',
        type: 'business',
        show: false
      })
    }
 
    // if (this.showRelativeContacts) {
    //   this.barItems.push({
    //     img: require('@/assets/img/send_contacts.png'),
    //     title: '关联联系人',
    //     type: 'contacts',
    //     show: false
    //   })
    // }
    /** 父组件通知子组件提交数据 */
    /** 将拼接好的数据回调父组件 this.$refs.child.$emit('submit-info');  调用 */
    // this.$on('submit-info', function () {
    //   this.$emit('mixadd-info', {
    //     title: this.title,
    //     content: this.content,
    //     files: this.files,
    //     images: this.imgFiles,
    //     business: this.business,
    //     contacts: this.contacts,
    //     batchId: this.batchId
    //   })
    // })
  },
 
  beforeDestroy () {
    this.$off('submit-info')
  },
  methods: {
    getType (type) {
      this.typeBtn = type
    },
    /** 发布 时候的类型选择 */
    handleTypeDrop (command) {
      this.followType = this.followTypes[command].name
      this.followTypeId = command
    },
    handleTypeDropWay (command) {
      this.wayType = this.wayTypes[command - 1].name
      this.wayTypeId = command
    },
    handleTypeDropContact (command) {
      this.contactType = this.contactTypes.filter(item => item.type === command)[0].name
      this.contactTypeId = command
    },
    close () {
      this.$refs.popover[0].doClose()
      this.resetInfo()
    },
    sendInfo () {
      console.log(this.files, this.contactTypeId)
      this.$emit('mixadd-info', {
        content: this.content,
        files: this.files,
        images: this.imgFiles,
        // files: [this.imgFiles, this.files],
        contacts: this.contactTypeId,
        // batchId: this.batchId,
        followTypeId: this.followTypeId,
        wayTypeId: this.wayTypeId,
        // isEvent: this.isEvent,
        nextTime: this.nextTime
        // followType: this.followType
      })
      this.resetInfo()
    },
    resetInfo () {
      /** 输入法 */
      this.title = ''
      this.content = ''
      /** 图片信息 */
      this.imgFiles = []
      /** 图片信息 */
      this.files = []
      /** 关联商机信息 */
      this.business = []
      /** 关联联系人信息 */
      this.contactType = this.contactTypes[0].name
      this.contactTypeId = this.contactTypes[0].type
      this.wayType = this.wayTypes[0].name
      this.wayTypeId = this.wayTypes[0].type
      this.contacts = []
      /** 展示关联弹窗 */
      this.showRelativeType = ''
      this.batchId = ''
    },
    /** 快捷添加按钮 */
    checkRelativeInfos (data) {
      if (this.showRelativeType === 'business') {
        this.business = data.data
      } else if (this.showRelativeType === 'contacts') {
        this.contacts = data.data
      }
    },
    barClick (item) {
      this.showRelativeType = item.type
      if (item.type === 'business') {
        item.show = true
      } else if (item.type === 'contacts') {
        item.show = true
      }
    },
    /** 图片选择出发 */
    uploadFile (event) {
      var files = event.target.files
      if (files.length) {
        for (let index = 0; index < files.length; index++) {
          const file = files[index]
          if (
            file.type.indexOf('image') === -1 &&
            this.showRelativeType === 'img'
          ) {
            this.$message.error('请上传正确的文件类型')
            return
          }
        }
 
        var type = event.target.accept === 'image/*' ? 'img' : 'file'
        var firstFile = files[0]
        this.sendFileRequest(firstFile, type, () => {
          for (let index = 1; index < files.length; index++) {
            const file = files[index]
            this.sendFileRequest(file, type)
          }
          event.target.value = ''
        })
      }
    },
    // 发送请求
    sendFileRequest (file, type, result) {
      var params = { file: file, type: type }
      if (this.batchId) {
        params.batchId = this.batchId
      }
      let request = {
        'img': UploadImageAsync,
        'file': UploadFileAsync
      }[type]
      request(params)
        .then(res => {
          // if (this.batchId === '') {
          //   this.batchId = res.batchId
          // }
          if (res.data.ErrorCode === 200) {
            let list = []
            list['size'] = fileSize(file.size)
            if (type === 'img') {
              list['name'] = res.data.Message
              list['path'] = res.data.Result
              console.log(list)
              this.imgFiles.push(list)
            } else {
              list['icon'] = getFileTypeIcon(file)
              list['name'] = res.data.Message
              list['path'] = res.data.Result
              this.files.push(list)
            }
            this.$message.success('上传成功')
          } else {
            this.$message.fail('res.data.Message')
          }
 
          if (result) {
            result()
          }
        })
        .catch(() => {})
    },
    /** 删除全部图片 */
    deleteAllImg () {
      this.imgFiles = []
    },
    deleteImgOrFile (type, item, index) {
      if (type === 'image') {
        this.imgFiles.splice(index, 1)
      } else {
        this.files.splice(index, 1)
      }
      this.$message.success('操作成功')
      // crmFileDelete({
      //   id: item.fileId
      // })
      //   .then(res => {
      //     if (type === 'image') {
      //       this.imgFiles.splice(index, 1)
      //     } else {
      //       this.files.splice(index, 1)
      //     }
      //     this.$message.success('操作成功')
      //   })
      //   .catch(() => {})
    },
    /** 鼠标移入和移除 图片区域 */
    mouseImgOver (item, index) {
      item.showDelete = true
      this.$set(this.imgFiles, index, item)
    },
    mouseImgLeave (item, index) {
      item.showDelete = false
      this.$set(this.imgFiles, index, item)
    },
    inputFocus () {
      this.isOpen = true
      this.inputAutosize = { minRows: 8, maxRows: 12 }
      this.$nextTick(() => {
        this.$refs.textarea.resizeTextarea()
      })
    },
    inputBlur () {
      this.isOpen = false
      this.inputAutosize = { minRows: 1, maxRows: 10 }
      this.$nextTick(() => {
        this.$refs.textarea.resizeTextarea()
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
@import '../styles/followlog.scss';
.max-container{
  .i-types{
    display: flex;
    flex-direction: row;
    margin-bottom: 20px;
    .type-button{
      cursor: pointer;
      height: 28px;
      background: #EBF1FF;
      border-radius: 3px;
      padding: 4px 8px 4px 24px;
      font-size: 14px;
      color: #666;
      margin-right: 24px;
      background-image: url('../../../assets/img/button_add_black.png');
      background-repeat: no-repeat;
      background-size: 11px 11px;
      background-position: 8px 8px;
    }
    .isType{
      cursor: pointer;
      background: #4D88FF;
      color: #FFFFFF;
      background-image: url('../../../assets/img/button_add_white.png');
      background-repeat: no-repeat;
      background-size: 11px 11px;
      background-position: 8px 8px;
    }
  }
 
  .mix-container {
    position: relative;
    // width: 1000px;
    border-radius: 4px;
    border: 1px solid #D9D9D9;
    .i-cont {
      padding: 0 12px;
    }
  }
}
.singleInput /deep/ .el-textarea__inner {
    min-height: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
  }
 
.i-cont /deep/ .el-textarea__inner {
  border: none;
  padding: 0;
}
/** 图片  */
.img-cont {
  padding: 0 10px;
  margin-bottom: 15px;
  .img-item {
    width: 98px;
    height: 98px;
    border: 1px solid #ccc;
    display: inline-block;
    margin: 0 4px 4px 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    position: relative;
    .img-delete {
      position: absolute;
      cursor: pointer;
      top: 0;
      right: 0;
      width: 20px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      font-size: 17px;
      background-color: #666;
      color: white;
    }
  }
  .img-item-add {
    width: 98px;
    height: 98px;
    line-height: 98px;
    font-size: 60px;
    color: #ccc;
    text-align: center;
    margin: 0 4px 4px 0;
    cursor: pointer;
    display: inline-block;
    border-width: 1px;
    border-style: dashed;
    border-color: #ddd;
    position: relative;
    font-weight: 100;
    .img-item-iput {
      position: absolute;
      top: 0;
      right: 0;
      height: 98px;
      width: 98px;
      opacity: 0;
      cursor: pointer;
    }
  }
  .img-item-add:before {
    width: 2px;
    height: 39.5px;
    content: ' ';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #2888e4;
  }
  .img-item-add:after {
    width: 39.5px;
    height: 2px;
    content: ' ';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #2888e4;
  }
  .img-bar {
    color: #5a8ae2;
    font-size: 12px;
    padding: 5px 0;
    cursor: pointer;
  }
}
/** 附件  */
.file-cont {
  padding: 0 10px;
  margin: 0 10px 15px;
  border: 1px dashed #dfdfdf;
  .f-header {
    padding: 8px 0 15px;
    .f-logo {
      position: block;
      width: 15px;
      height: 15px;
      margin-right: 8px;
    }
    .f-name {
      color: #777;
      font-size: 12px;
    }
  }
 
  .f-body {
    .f-item {
      padding: 3px 0;
      height: 25px;
      .f-img {
        position: block;
        width: 15px;
        height: 15px;
        margin-right: 8px;
      }
      .f-name {
        color: #666;
        font-size: 12px;
      }
    }
  }
 
  .img-bar {
    color: #5a8ae2;
    font-size: 12px;
    padding: 5px 0;
    cursor: pointer;
  }
}
/** CRM  */
.c-cont {
  padding: 0 10px;
  margin: 0 10px 15px;
  border: 1px dashed #dfdfdf;
  .c-header {
    padding: 8px 0 15px;
    .c-logo {
      position: block;
      width: 15px;
      height: 15px;
      margin-right: 8px;
    }
    .c-name {
      color: #777;
      font-size: 12px;
    }
  }
 
  .c-body {
    margin-bottom: 10px;
    .c-item {
      height: 24px;
      border-radius: 12px;
      padding: 0 8px;
      margin: 0 5px 5px 0;
      background-color: #3487e2;
      color: white;
      width: auto;
      .c-item-name {
        font-size: 12px;
      }
      .c-item-close {
        padding-left: 5px;
        font-size: 17px;
      }
    }
  }
}
/** 底部bar  */
.bar-cont {
  // background-color: #f9f9f9;
  padding: 24px;
  .bar-item {
    width: auto;
    padding-right: 20px;
    position: relative;
    cursor: pointer;
    .bar-input {
      position: absolute;
      top: 0;
      right: 0;
      height: 10px;
      width: 68px;
      opacity: 0;
      font-size: 0;
      cursor: pointer;
    }
    .bar-img {
      display: block;
      margin-right: 8px;
      &:hover{
      }
    }
    .bar-title {
      color: #999;
      font-size: 12px;
      &:hover{
        color: #333;
      }
    }
  }
}
/** 关闭按钮  */
.close-button {
  width: 30px;
  line-height: 16px;
  cursor: pointer;
  color: #ccc;
  height: 16px;
  font-size: 17px;
  text-align: center;
}
// .el-date-editor /deep/ .el-input__prefix{
//   right: -165px;
// }
</style>