huangyinfeng
4 天以前 db42d08c39ae6129e2b95cd24c0d57c6769282e5
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
<!-- TooltipAndDropdown.vue -->
<template>
  <div style="display: flex; justify-content: space-around">
    <!-- Tooltip -->
 
    <!-- Dropdown -->
    <a-dropdown v-model:open="dropdownOpen" :trigger="['click']" placement="bottomLeft">
      <a-tooltip v-if="showTooltip" v-model:open="tooltipOpen" placement="bottomLeft">
        <template #title>
          <div class="p-1" style="width: 210px">
            <span>{{ tooltipTitle }}</span>
            <div class="p-2" style="font-size: 18px; font-weight: 600">{{ formattedTime }}</div>
            <div class="p-2" style="text-align: center">
              <CButton size="small" shape="round" type="success" @click="onUpdate">修改</CButton>
              <a-button
                style="margin-left: 10px"
                size="small"
                shape="round"
                type="primary"
                @click="onComplete"
                >完成</a-button
              >
            </div>
          </div>
        </template>
        <FieldTimeOutlined v-if="showTooltip" class="color-handle" />
      </a-tooltip>
      <FieldTimeOutlined v-else @click.stop="toggleDropdown" />
      <template #overlay>
        <a-card title="选择稍后处理时间:" style="width: 250px" size="small">
          <div
            class="date p-1"
            v-for="item in dateList"
            :key="item.key"
            @click="fnSelectDate(item)"
          >
            <div class="date-left">{{ item.name }}</div>
            <div class="date-right">
              <span v-if="item.key !== 'today'">{{ item.dayOfWeek }}</span>
              <span style="margin-left: 5px">{{ item.time }}</span>
            </div>
          </div>
          <a-divider style="margin: 5px 0" />
          <div class="date p-1">
            <a-popover
              :trigger="trigger"
              title="自定义时间"
              v-model:open="customTimeDropdownOpen"
              @confirm="onSubmitCustomTime"
            >
              <template #content>
                <a-form :model="form" ref="formRef">
                  <a-form-item
                    label="日期"
                    name="date"
                    :rules="[{ required: true, message: '请选择日期' }]"
                  >
                    <a-date-picker
                      format="YYYY/MM/DD"
                      :disabledDate="disabledDate"
                      v-model:value="form.date"
                    />
                  </a-form-item>
                  <a-form-item
                    label="时间"
                    name="time"
                    :rules="[{ required: true, message: '请选择时间' }]"
                  >
                    <a-time-picker v-model:value="form.time" />
                  </a-form-item>
                  <a-form-item>
                    <a-button @click="cancelCustomTime">取消</a-button>
                    <a-button style="margin-left: 10px" type="primary" @click="submitCustomTime"
                      >确定</a-button
                    >
                  </a-form-item>
                </a-form>
              </template>
              <div class="date-left" @click="toggleCustomTime">自定义时间</div>
            </a-popover>
          </div>
        </a-card>
      </template>
    </a-dropdown>
  </div>
</template>
 
<script lang="ts" setup>
  import { ref, reactive, defineProps, defineEmits, computed, inject, nextTick } from 'vue';
  import { FieldTimeOutlined, PushpinOutlined } from '@ant-design/icons-vue';
  import dayjs from 'dayjs';
  import CButton from '@/components/CButton/index.vue';
  const getDataList = inject('getDataList');
 
  function processDateList() {
    const dateList = [
      { name: '今天稍晚', key: 'today' },
      { name: '明天', key: 'tomorrow' },
      { name: '本周稍晚', key: 'thisWeek' },
      { name: '本周末', key: 'thisWeekend' },
      { name: '下周', key: 'nextWeek' },
    ];
 
    const now = new Date();
 
    const dateArray = dateList.map((item) => {
      let date = new Date(); // 初始化当前日期
      let dayOfWeekString = ''; // 初始化星期几
      let timeString = ''; // 初始化时间
 
      switch (item.key) {
        case 'today':
          // 今天稍晚是今天的 16:00
          date.setHours(16, 0, 0, 0);
          break;
        case 'tomorrow':
          // 明天 08:00
          date.setDate(now.getDate() + 1);
          date.setHours(8, 0, 0, 0);
          break;
        case 'thisWeek':
          // 本周稍晚:周五 08:00
          const dayOfWeek = now.getDay();
          const daysUntilFriday = (5 - dayOfWeek + 7) % 7; // 计算到周五的天数
          date.setDate(now.getDate() + daysUntilFriday);
          date.setHours(8, 0, 0, 0);
          break;
        case 'thisWeekend':
          // 本周末:周日 08:00
          const daysUntilSunday = (7 - now.getDay()) % 7; // 计算到周日的天数
          date.setDate(now.getDate() + daysUntilSunday);
          date.setHours(8, 0, 0, 0);
          break;
        case 'nextWeek':
          // 下周一 08:00
          const daysUntilNextMonday = ((1 - now.getDay() + 7) % 7) + 7; // 计算到下周一的天数
          date.setDate(now.getDate() + daysUntilNextMonday);
          date.setHours(8, 0, 0, 0);
          break;
        default:
          break;
      }
 
      // 获取星期几的字符串表示
      dayOfWeekString = date.toLocaleDateString('zh-CN', { weekday: 'long' });
 
      // 获取仅时间部分
      timeString = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
 
      // 返回日期、星期几和时间信息
      return {
        name: item.name,
        key: item.key,
        date: date,
        dayOfWeek: dayOfWeekString,
        time: timeString, // 保存仅时间部分
      };
    });
 
    return dateArray;
  }
  const dateList = processDateList();
  const props = defineProps({
    tooltipTitle: String, // Tooltip 标题
    initialDropdownOpen: Boolean, // Dropdown 初始打开状态
    showTooltip: Boolean, // 是否展示 Tooltip
    initialTooltipOpen: Boolean, // Tooltip 初始打开状态
    row: Object, // 当前行对象
    docCodeS: Array,
    trigger: {
      type: String,
      default: 'click',
    },
  });
 
  const emit = defineEmits(['updateHandleTime', 'completeAction', 'customTimeSubmit', 'tagRow']);
 
  import { useMessage } from '@/hooks/web/useMessage';
  import { formatToDateDay } from '@/utils/dateUtil';
  import { updateHandleAPi } from '@/api/email/userList';
 
  const { createMessage } = useMessage();
  function fnSelectDate(item) {
    dropdownOpen.value = false;
    const date = formatToDateDay(new Date(item.date));
    const data = {
      handleTime: date,
      docCode: props.docCodeS,
    };
 
    pushUpdateHandle(data);
  }
  function pushUpdateHandle(data) {
    updateHandleAPi(data)
      .then((res) => {
        if (res.code == 0) {
          createMessage.success(res.msg);
          getDataList({});
        }
      })
      .catch((err) => {});
  }
 
  // Dropdown 和 Tooltip 状态管理
  const dropdownOpen = ref(props.initialDropdownOpen);
  const tooltipOpen = ref(props.initialTooltipOpen);
  const customTimeDropdownOpen = ref(false);
 
  // 表单数据
  const form = reactive({
    date: '',
    time: '',
  });
  const onUpdate = () => {
    dropdownOpen.value = true;
    tooltipOpen.value = false;
  };
  // 事件处理
  const toggleDropdown = () => {
    dropdownOpen.value = !dropdownOpen.value;
  };
 
  const toggleTooltip = () => {
    tooltipOpen.value = !tooltipOpen.value;
  };
 
  const toggleCustomTime = () => {
    customTimeDropdownOpen.value = !customTimeDropdownOpen.value;
    dropdownOpen.value = false;
  };
 
  const onComplete = () => {
    const data = {
      docCode: props.docCodeS,
    };
    pushUpdateHandle(data);
  };
  const formRef = ref();
  const submitCustomTime = () => {
    formRef.value.validate().then((valid) => {
      if (valid) {
        customTimeDropdownOpen.value = false;
        const date = form.date ? dayjs(form.date).format('YYYY-MM-DD') : '';
        const time = form.time ? dayjs(form.time).format('HH:mm') : '';
        const data = {
          handleTime: date + ' ' + time,
          docCode: props.docCodeS,
        };
        pushUpdateHandle(data);
      } else {
        return false;
      }
    });
  };
 
  const cancelCustomTime = () => {
    customTimeDropdownOpen.value = false;
    dropdownOpen.value = true;
  };
 
  // 处理时间格式化
  const formattedTime = computed(() =>
    props.row.handleTime ? dayjs(props.row.handleTime).format('YYYY-MM-DD HH:mm') : '',
  );
 
  // 日期禁用处理
  const disabledDate = (currentDate) => {
    return currentDate && currentDate < dayjs().startOf('day');
  };
 
  function TooltipAndDropdown() {}
 
  function onSubmitCustomTime() {
    customTimeDropdownOpen.value = true;
  }
</script>
 
<style scoped lang="less">
  .display-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
 
  .date {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
 
  .date-left {
    flex-grow: 1;
  }
 
  .color-handle {
    cursor: pointer;
  }
 
  .date:hover {
    transition: all 0.2s;
    background-color: #0000000a;
  }
 
  .color-handle {
    color: #0a6aff;
  }
</style>