保誠-保戶業務員媒合平台
wayne
2022-02-17 a3716f72066d25d745f4d5103ff23a553c3e102b
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
 
 
<template>
  <div>
    <div class="mt-10" v-for="(scheduleDto,index) in scheduleList" :key="index">
      <div class="mdTxt">{{index | titleFormatByIndex}}</div>
      <div class="pam-contact-schedule cursor--pointer fix-chrome-click--issue" @click="openPopUp(scheduleDto,index)">
        <div class="pam-contact-schedule__text">
          <template v-if="checkFormHasDone(scheduleDto)">
            <p>{{ scheduleDto.selectWeekOptions | optionsFormat(weekOptions)}}</p>
            <p>{{ scheduleDto.selectTimesOptions| optionsFormat(timesOfDayOptions)}}</p>
          </template>
          <template v-else>
            請選擇
          </template>
        </div>
        <div class="pam-contact-schedule__icon">
          <i v-if="checkFormHasDone(scheduleDto)"
            class="icon-delet"
            :class="{'disable':scheduleList.length===1}"
            @click.stop="deleteScheduleByIndex(index)">
          </i>
          <i v-else class="icon-calender"></i>
        </div>
      </div>
    </div>
    <div class="pam-add-schedule cursor--pointer"
      :class="{'disable': !checkFormHasDone(scheduleList[scheduleList.length && scheduleList.length - 1]) || scheduleList.length===7 }"
      @click="addNewSchedule">
      <i class="icon-add"></i>
      新增時段
    </div>
 
    <PopUpFrame class="pam-popUpFrame"
      dialogWidth="376px"
      :isOpen.sync="isOpenByDayPopUp">
        <div class="pam-popUp-title">{{scheduleIndex | titleFormatByIndex}}</div>
          <MultiSelectBtn class="mt-30"
            :mutiSelect.sync="initPickerControl.selectWeekOptions"
            :options="weekOptions.options"
            :nameOfSelectAll="weekOptions.selectAll">
          </MultiSelectBtn>
          <div class="pam-popUp-confirm-block  mt-30">
            <button class="pam-select-confirm"
              :class="[initPickerControl.selectWeekOptions.length?'el-button--primary' :'is-disabled']"
              @click="confirmBySelectDay">
              確定
            </button>
          </div>
    </PopUpFrame>
 
    <PopUpFrame class="pam-popUpFrame"
      dialogWidth="376px"
      :isOpen.sync="isOpenByTimePopUp">
        <div class="pam-popUp-title">{{scheduleIndex | titleFormatByIndex}}</div>
        <MultiSelectBtn class="mt-30"
          :mutiSelect.sync="initPickerControl.selectTimesOptions"
          :options="timesOfDayOptions.options"
          :nameOfSelectAll="timesOfDayOptions.selectAll">
        </MultiSelectBtn>
        <div class="pam-popUp-confirm-block  mt-30">
          <button class="pam-select-confirm"
            :class="[initPickerControl.selectTimesOptions.length ?'el-button--primary' :'is-disabled']"
            @click="confirmBySelectTime">
            確定
          </button>
        </div>
    </PopUpFrame>
  </div>
</template>
 
<script lang="ts">
  import { Component, Prop, PropSync, Vue } from "nuxt-property-decorator";
  import { dayTimeFrames } from "~/shared/const/day-time-frames";
  import { OptionBtnDto, OptionDto } from "~/shared/models/optionBtnDto.model";
  import { weekDays } from "~/shared/const/week-days";
  import * as _ from "lodash";
  @Component({
    filters:{
      titleFormatByIndex(index:number):string{
        const chineseNumber = ['一','二','三','四','五','六','七','八','九','十'];
        return '時段'+chineseNumber[index];
      },
      optionsFormat(selectedOptions:string[]|[], compareOptions:OptionDto): string{
        return _.isEqual(selectedOptions.length,compareOptions.options.length)
                ? compareOptions.selectAll
                : _.join(selectedOptions,',');
      },
    }
  })
  export default class PhoneContactTimePicker extends Vue {
    @Prop({type:Array,default:()=>[]})
    scheduleList!:scheduleDto[];
 
    weekOptions = {
      selectAll: '每天',
      options  : weekDays,
    };
    timesOfDayOptions = {
      selectAll: '全天',
      options  : dayTimeFrames,
    };
    initPickerControl:scheduleDto = {
      selectWeekOptions : [],
      selectTimesOptions: [],
    }
    popUpMode     : TimePickerMode = TimePickerMode.NONE;
    scheduleIndex : number         = 0;
 
    //////////////////////////////////////////////////////////////////////
 
    get isOpenByDayPopUp(): boolean{
      return _.isEqual(this.popUpMode , TimePickerMode.SELECT_DAY)
    }
 
    set isOpenByDayPopUp(value:boolean){
      this.popUpMode = TimePickerMode.NONE;
    }
 
    get isOpenByTimePopUp(): boolean{
      return _.isEqual(this.popUpMode , TimePickerMode.SELECT_TIME);
    }
 
    set isOpenByTimePopUp(value:boolean){
      this.popUpMode = TimePickerMode.NONE;
    }
 
    //////////////////////////////////////////////////////////////////////
 
    openPopUp(schedule:scheduleDto,index:number):void{
      this.initPickerControl = _.cloneDeep(schedule);
      this.popUpMode = TimePickerMode.SELECT_DAY;
      this.scheduleIndex = index;
    }
 
    confirmBySelectDay(): void {
      this.popUpMode = TimePickerMode.SELECT_TIME;
    }
 
    confirmBySelectTime(): void {
      this.popUpMode = TimePickerMode.NONE;
      // detect array change to parent
      this.$set( this.scheduleList, this.scheduleIndex, this.initPickerFormatSort(this.initPickerControl) );
    }
 
    private initPickerFormatSort(initPickerControl:scheduleDto):scheduleDto{
      _.keys(initPickerControl).forEach(keyName=>{
        const options = _.isEqual(keyName,'selectWeekOptions') ? weekDays : dayTimeFrames;
        initPickerControl[keyName] = this.getOptionsBySort(initPickerControl[keyName],options);
      })
      return initPickerControl;
    }
 
    // 資料重新排序,回復一開始清單順序
    private getOptionsBySort( selectedOptions:string[] , options:OptionBtnDto[]): string[] {
      return options.map( o => _.includes(selectedOptions , o.label) ? o.label as string : '').filter(String);
    }
 
    addNewSchedule(): void {
      const newScheduleDto={
        selectWeekOptions:[],
        selectTimesOptions:[],
      }
      this.scheduleList.push(newScheduleDto)
    }
 
    deleteScheduleByIndex(index:number): void {
      this.scheduleList.splice(index,1);
    }
    checkFormHasDone(item:scheduleDto): boolean {
      return item&&item.selectWeekOptions?.length > 0
          && item.selectTimesOptions?.length > 0;
    }
  }
  enum TimePickerMode{
    SELECT_DAY="selectDay",
    SELECT_TIME="selectTime",
    NONE=""
  }
  interface scheduleDto {
    selectWeekOptions : string[]|[];
    selectTimesOptions: string[]|[];
  }
</script>
 
<style lang="scss" scoped>
  .pam-popUp-title{
    font-size      : 24px;
    color          : $PRIMARY_BLACK;
    display        : flex;
    justify-content: center;
  }
  .pam-popUp-confirm-block {
    display        : flex;
    justify-content: center;
  }
  .pam-contact-schedule{
    width          : inherit;
    background     : $PRIMARY_WHITE;
    border         : 1px solid $LIGHT_GREY;
    padding        : 12px 20px;
    border-radius  : 10px;
    display        : flex;
    justify-content: space-between;
    margin-top     : 10px;
  }
  .pam-contact-schedule__text{
    align-self: center;
    font-size : 20px;
    width     : 85%;
    word-break: break-all;
    color     : $PRUDENTIAL_GREY;
  }
  .pam-contact-schedule__icon{
    width          : 15%;
    display        : flex;
    align-items    : center;
    justify-content: flex-end;
    color          : $PRIMARY_RED;
    font-size      : 25px;
    .disable{
      color         : $LIGHT_GREY;
      pointer-events: none;
    }
  }
  .pam-add-schedule{
    color     : $PRIMARY_RED;
    margin-top: 10px;
    font-size : 20px;
     &.disable{
        color         : $LIGHT_GREY;
        pointer-events: none;
    }
  }
</style>