2019-11-24 13:16:24 +00:00
|
|
|
<template>
|
2021-01-16 20:09:11 +00:00
|
|
|
<div class="control repeat-after-input">
|
|
|
|
<div class="buttons has-addons is-centered mt-2">
|
2022-07-21 13:06:17 +00:00
|
|
|
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'days')">
|
|
|
|
{{ $t('task.repeat.everyDay') }}
|
|
|
|
</x-button>
|
|
|
|
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'weeks')">
|
|
|
|
{{ $t('task.repeat.everyWeek') }}
|
|
|
|
</x-button>
|
|
|
|
<x-button variant="secondary" class="is-small" @click="() => setRepeatAfter(1, 'months')">
|
|
|
|
{{ $t('task.repeat.everyMonth') }}
|
|
|
|
</x-button>
|
2021-01-16 20:09:11 +00:00
|
|
|
</div>
|
2021-04-14 08:24:07 +00:00
|
|
|
<div class="is-flex is-align-items-center mb-2">
|
|
|
|
<label for="repeatMode" class="is-fullwidth">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('task.repeat.mode') }}:
|
2021-04-14 08:24:07 +00:00
|
|
|
</label>
|
|
|
|
<div class="control">
|
|
|
|
<div class="select">
|
|
|
|
<select @change="updateData" v-model="task.repeatMode" id="repeatMode">
|
2022-06-23 01:14:58 +00:00
|
|
|
<option :value="TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT">{{ $t('misc.default') }}</option>
|
|
|
|
<option :value="TASK_REPEAT_MODES.REPEAT_MODE_MONTH">{{ $t('task.repeat.monthly') }}</option>
|
|
|
|
<option :value="TASK_REPEAT_MODES.REPEAT_MODE_FROM_CURRENT_DATE">{{ $t('task.repeat.fromCurrentDate') }}</option>
|
2021-04-14 08:24:07 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-23 01:14:58 +00:00
|
|
|
<div class="is-flex" v-if="task.repeatMode !== TASK_REPEAT_MODES.REPEAT_MODE_MONTH">
|
2021-04-14 08:24:07 +00:00
|
|
|
<p class="pr-4">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('task.repeat.each') }}
|
2021-04-14 08:24:07 +00:00
|
|
|
</p>
|
|
|
|
<div class="field has-addons is-fullwidth">
|
|
|
|
<div class="control">
|
|
|
|
<input
|
2022-05-14 14:58:21 +00:00
|
|
|
:disabled="disabled || undefined"
|
2021-04-14 08:24:07 +00:00
|
|
|
@change="updateData"
|
|
|
|
class="input"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('task.repeat.specifyAmount')"
|
2021-04-14 08:24:07 +00:00
|
|
|
v-model="repeatAfter.amount"
|
|
|
|
type="number"
|
2022-07-21 13:06:17 +00:00
|
|
|
min="0"
|
2021-04-14 08:24:07 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="control">
|
|
|
|
<div class="select">
|
2022-05-14 14:58:21 +00:00
|
|
|
<select
|
|
|
|
v-model="repeatAfter.type"
|
|
|
|
@change="updateData"
|
|
|
|
:disabled="disabled || undefined"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
<option value="hours">{{ $t('task.repeat.hours') }}</option>
|
|
|
|
<option value="days">{{ $t('task.repeat.days') }}</option>
|
|
|
|
<option value="weeks">{{ $t('task.repeat.weeks') }}</option>
|
|
|
|
<option value="months">{{ $t('task.repeat.months') }}</option>
|
|
|
|
<option value="years">{{ $t('task.repeat.years') }}</option>
|
2021-04-14 08:24:07 +00:00
|
|
|
</select>
|
2020-11-28 15:02:38 +00:00
|
|
|
</div>
|
2020-06-14 12:43:01 +00:00
|
|
|
</div>
|
2019-11-24 13:16:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-05-14 14:58:21 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import {ref, reactive, watch} from 'vue'
|
2022-07-21 13:06:17 +00:00
|
|
|
import {error} from '@/message'
|
|
|
|
import {useI18n} from 'vue-i18n'
|
2022-06-23 01:14:58 +00:00
|
|
|
import type TaskModel from '@/models/task'
|
|
|
|
import {TASK_REPEAT_MODES, type RepeatAfter} from '@/models/task'
|
2020-06-14 12:43:01 +00:00
|
|
|
|
2022-05-14 14:58:21 +00:00
|
|
|
const props = defineProps({
|
|
|
|
modelValue: {
|
2022-05-20 22:16:29 +00:00
|
|
|
default: () => ({}),
|
2022-05-14 14:58:21 +00:00
|
|
|
required: true,
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2022-05-14 14:58:21 +00:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2022-02-15 12:07:59 +00:00
|
|
|
})
|
2022-05-14 14:58:21 +00:00
|
|
|
|
2022-08-04 19:55:02 +00:00
|
|
|
const {t} = useI18n({useScope: 'global'})
|
2022-07-21 13:06:17 +00:00
|
|
|
|
2022-05-14 14:58:21 +00:00
|
|
|
const emit = defineEmits(['update:modelValue', 'change'])
|
|
|
|
|
2022-05-20 22:16:29 +00:00
|
|
|
const task = ref<TaskModel>()
|
2022-05-14 14:58:21 +00:00
|
|
|
const repeatAfter = reactive({
|
|
|
|
amount: 0,
|
|
|
|
type: '',
|
|
|
|
})
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
|
|
|
(value) => {
|
|
|
|
task.value = value
|
|
|
|
if (typeof value.repeatAfter !== 'undefined') {
|
|
|
|
Object.assign(repeatAfter, value.repeatAfter)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{immediate: true},
|
|
|
|
)
|
|
|
|
|
|
|
|
function updateData() {
|
2022-06-23 01:14:58 +00:00
|
|
|
if (!task.value || task.value.repeatMode !== TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT && repeatAfter.amount === 0) {
|
2022-05-14 14:58:21 +00:00
|
|
|
return
|
|
|
|
}
|
2022-07-21 13:06:17 +00:00
|
|
|
|
|
|
|
if (repeatAfter.amount < 0) {
|
|
|
|
error({message: t('task.repeat.invalidAmount')})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-14 14:58:21 +00:00
|
|
|
Object.assign(task.value.repeatAfter, repeatAfter)
|
|
|
|
emit('update:modelValue', task.value)
|
|
|
|
emit('change')
|
|
|
|
}
|
|
|
|
|
2022-06-23 01:14:58 +00:00
|
|
|
function setRepeatAfter(amount: number, type: RepeatAfter['type']) {
|
|
|
|
Object.assign(repeatAfter, { amount, type})
|
2022-05-14 14:58:21 +00:00
|
|
|
updateData()
|
|
|
|
}
|
2019-11-24 13:16:24 +00:00
|
|
|
</script>
|
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
p {
|
|
|
|
padding-top: 6px;
|
|
|
|
}
|
2020-06-14 12:43:01 +00:00
|
|
|
|
2021-01-16 20:09:11 +00:00
|
|
|
.input {
|
|
|
|
min-width: 2rem;
|
|
|
|
}
|
2019-11-24 13:16:24 +00:00
|
|
|
</style>
|