保誠-保戶業務員媒合平台
wayne
2022-01-26 6fa4bba623713c396432ba8b863846883d6a1906
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
<template>
  <div>
    <el-checkbox-group class="pam-multi-select-btn" v-model="syncMutiSelect">
      <el-checkbox
        v-for="(option, index) in options"
        :key="index"
        :label="option.label">
          {{ option.title }}
        </el-checkbox>
      <template v-if="nameOfSelectAll">
        <button class="pam-selectAll-btn cursor--pointer fix-chrome-click--issue" :class="{'selected':isSelectAll}" :model="isSelectAll" @click="selectAll">
         <span>{{nameOfSelectAll}}</span>
       </button>
      </template>
      <template v-if="nameOfOtherOption">
        <button class="pam-selectAll-btn cursor--pointer fix-chrome-click--issue" :class="{'selected':isSelectOtherOption}" :model="isSelectOtherOption" @click="selectOther">
         {{ nameOfOtherOption }}
        </button>
        <div>
          <input class="pam-muti-select-other cursor--pointer " v-if="isSelectOtherOption" v-model="syncOtherSelect" placeholder="請輸入,限20字">
        </div>
      </template>
    </el-checkbox-group>
  </div>
</template>
 
<script lang="ts">
  import { Vue, Component, Prop, PropSync, Watch} from 'vue-property-decorator';
import { OptionBtnDto } from '~/shared/models/optionBtnDto.model';
 
  @Component
  export default class MultiSelectBtn extends Vue {
 
    @PropSync('mutiSelect',{type:Array,default:()=>[]})
    syncMutiSelect!:string[];
 
    @Prop({default:()=>[]})
    options!:OptionBtnDto[];
 
    @Prop({default:''})
    nameOfSelectAll!:string;
 
    @PropSync('otherSelect',{default:''})
    syncOtherSelect!:string;
 
    @Prop({type:String,default:''})
    nameOfOtherOption!:string;
 
    @Prop()
    maxLength? : number;
 
    @Watch('syncMutiSelect')
    onMutiSelectChange(): void {
      if (!this.maxLength) return;
      if (this.syncMutiSelect.length > this.maxLength) {
        this.syncMutiSelect.shift();
      }
    }
 
    isSelectOtherOption=false;
    isSelectAll=false;
 
    //////////////////////////////////////////////////////////////////////
 
    updated() {
      this.isSelectAll = this.syncMutiSelect.length === this.options.length;
    }
 
    //////////////////////////////////////////////////////////////////////
 
    selectAll():void {
      this.isSelectAll= !this.isSelectAll;
      this.syncMutiSelect = this.isSelectAll ? this.optionsFormat(this.options):[];
    }
 
    optionsFormat(options:OptionBtnDto[]): string[] {
      return options.map((option)=> option.title );
    }
 
    selectOther(): void {
      this.isSelectOtherOption = !this.isSelectOtherOption;
      if(!this.isSelectOtherOption){
        this.syncOtherSelect = '';
      }
    }
  }
</script>
 
<style lang="scss" scoped>
  .pam-selectAll-btn{
    padding         : 6px 20px;
    border          : 1px $LIGHT_GREY solid;
    background-color: $PRIMARY_WHITE;
    border-radius   : 30px;
    color           : $PRIMARY_BLACK;
    font-size       : 20px;
    margin-right    : 10px;
    margin-bottom   : 10px;
    &.selected{
      background-color: $CORAL;
      color           : $PRIMARY_WHITE;
    }
  }
  .pam-muti-select-other {
    height            : 50px;
    padding           : 5px;
    -webkit-box-sizing: border-box;         /* Safari/Chrome, other WebKit */
    -moz-box-sizing   : border-box;         /* Firefox, other Gecko */
    box-sizing        : border-box;
    width             : 316px;
    border            : 1px solid #CCCCCC;
  }
</style>