enrecipes/app/components/modal/TimePicker.vue

98 lines
2.4 KiB
Vue
Raw Normal View History

2020-11-02 11:36:53 +00:00
<template>
2021-04-12 18:09:48 +00:00
<Page
@loaded="transparentPage"
backgroundColor="transparent"
:class="appTheme"
>
2021-04-01 10:55:35 +00:00
<GridLayout rows="auto, auto, auto" class="modal">
<Label class="title" :text="title | L" />
2021-02-28 15:10:26 +00:00
<StackLayout
2021-04-01 10:55:35 +00:00
row="1"
2021-02-28 15:10:26 +00:00
class="dialogListPicker"
orientation="horizontal"
horizontalAlignment="center"
>
<ListPicker
2021-04-12 18:09:48 +00:00
@loaded="onLPLoad"
2021-02-28 15:10:26 +00:00
ref="hrPicker"
:items="hrsList"
:selectedIndex="hrIndex"
@selectedIndexChange="setHrs"
></ListPicker>
<ListPicker
2021-04-12 18:09:48 +00:00
@loaded="onLPLoad"
2021-02-28 15:10:26 +00:00
ref="minPicker"
:items="minsList"
:selectedIndex="minIndex"
@selectedIndexChange="setMins"
></ListPicker>
</StackLayout>
2021-04-01 10:55:35 +00:00
<GridLayout row="2" columns="*, auto, auto" class="actions">
<Button
2021-02-28 15:10:26 +00:00
col="1"
2021-04-01 10:55:35 +00:00
class="text sm"
2021-02-28 15:10:26 +00:00
:text="'cBtn' | L"
@tap="$modal.close(false)"
/>
2021-04-01 10:55:35 +00:00
<Button
2021-02-28 15:10:26 +00:00
col="2"
2021-04-01 10:55:35 +00:00
class="text sm"
:text="action | L"
2021-02-28 15:10:26 +00:00
@tap="$modal.close(selectedTime)"
/>
</GridLayout>
2021-04-01 10:55:35 +00:00
</GridLayout>
2021-02-28 15:10:26 +00:00
</Page>
2020-11-02 11:36:53 +00:00
</template>
<script>
2021-02-28 15:10:26 +00:00
import { mapState } from "vuex";
import { localize } from "@nativescript/localize";
2020-11-02 11:36:53 +00:00
export default {
2021-02-28 15:10:26 +00:00
props: ["title", "selectedHr", "selectedMin", "action"],
2020-11-02 11:36:53 +00:00
data() {
return {
hrs: [],
mins: [],
2020-11-02 11:36:53 +00:00
selectedHrs: "00",
selectedMins: "00",
2021-02-28 15:10:26 +00:00
};
2020-11-02 11:36:53 +00:00
},
computed: {
2021-04-01 10:55:35 +00:00
...mapState(["icon", "appTheme"]),
hrsList() {
2021-02-28 15:10:26 +00:00
let h = [...Array(24).keys()];
this.hrs = h;
return h.map((e) => `${e} ${localize("hr")}`);
},
minsList() {
2021-05-22 08:56:31 +00:00
let m = [...Array(60).keys()];
2021-02-28 15:10:26 +00:00
this.mins = m;
return m.map((e) => `${e} ${localize("min")}`);
},
2020-11-02 11:36:53 +00:00
hrIndex() {
2021-02-28 15:10:26 +00:00
return this.hrs.indexOf(parseInt(this.selectedHr));
2020-11-02 11:36:53 +00:00
},
minIndex() {
2021-02-28 15:10:26 +00:00
return this.mins.indexOf(parseInt(this.selectedMin));
2020-11-02 11:36:53 +00:00
},
selectedTime() {
2021-02-28 15:10:26 +00:00
return this.selectedHrs + ":" + this.selectedMins;
2020-11-02 11:36:53 +00:00
},
},
methods: {
2021-04-12 18:09:48 +00:00
onLPLoad({ object }) {
object.android.setWrapSelectorWheel(true);
2021-03-10 15:59:50 +00:00
},
2021-02-28 15:10:26 +00:00
setHrs(args) {
let hr = "0" + this.hrs[args.object.selectedIndex];
this.selectedHrs = hr.slice(-2);
2020-11-02 11:36:53 +00:00
},
2021-02-28 15:10:26 +00:00
setMins(args) {
let min = "0" + this.mins[args.object.selectedIndex];
this.selectedMins = min.slice(-2);
2020-11-02 11:36:53 +00:00
},
},
2021-02-28 15:10:26 +00:00
};
2020-11-02 11:36:53 +00:00
</script>