enrecipes/app/components/modal/ListPicker.vue

140 lines
3.1 KiB
Vue
Raw Normal View History

2020-11-02 11:36:53 +00:00
<template>
<Page>
2020-11-10 18:28:48 +00:00
<StackLayout class="dialogContainer" :class="appTheme">
2020-11-02 11:36:53 +00:00
<Label class="dialogTitle orkm" :text="title" />
<StackLayout
class="dialogListPicker"
orientation="horizontal"
horizontalAlignment="center"
>
<ListPicker
ref="hrPicker"
:items="hrs"
:selectedIndex="hrIndex"
@selectedIndexChange="setHrs"
></ListPicker>
<ListPicker
ref="minPicker"
:items="mins"
:selectedIndex="minIndex"
@selectedIndexChange="setMins"
></ListPicker>
</StackLayout>
2020-11-10 18:28:48 +00:00
<GridLayout rows="auto" columns="*, auto, auto" class="actionsContainer">
<MDButton
:rippleColor="rippleColor"
variant="text"
2020-11-02 11:36:53 +00:00
col="1"
class="action orkm"
text="CANCEL"
@tap="$modal.close(false)"
/>
2020-11-10 18:28:48 +00:00
<MDButton
:rippleColor="rippleColor"
variant="text"
col="2"
2020-11-02 11:36:53 +00:00
class="action orkm"
:text="action"
@tap="$modal.close(selectedTime)"
/>
</GridLayout>
</StackLayout>
</Page>
</template>
<script>
import { Application } from "@nativescript/core"
export default {
props: ["title", "selectedHr", "selectedMin", "action"],
data() {
return {
hrs: [
2020-11-11 13:50:33 +00:00
"0 hr",
"1 hr",
"2 hr",
"3 hr",
"4 hr",
"5 hr",
"6 hr",
"7 hr",
"8 hr",
"9 hr",
"10 hr",
"11 hr",
"12 hr",
"13 hr",
"14 hr",
"15 hr",
"16 hr",
"17 hr",
"18 hr",
"19 hr",
"20 hr",
"21 hr",
"22 hr",
"23 hr",
2020-11-02 11:36:53 +00:00
],
mins: [
2020-11-11 13:50:33 +00:00
"0 min",
"1 min",
"2 min",
"3 min",
"4 min",
"5 min",
"6 min",
"7 min",
"8 min",
"9 min",
"10 min",
"15 min",
"20 min",
"25 min",
"30 min",
"35 min",
"40 min",
"45 min",
"50 min",
"55 min",
2020-11-02 11:36:53 +00:00
],
selectedHrs: "00",
selectedMins: "00",
}
},
computed: {
hrIndex() {
2020-11-10 18:28:48 +00:00
let hr = this.selectedHr
2020-11-11 13:50:33 +00:00
if (hr.charAt(0) == "0") hr = hr.slice(-1) + " hr"
else hr = hr + " hr"
2020-11-10 18:28:48 +00:00
return this.hrs.indexOf(hr)
2020-11-02 11:36:53 +00:00
},
minIndex() {
2020-11-10 18:28:48 +00:00
let min = this.selectedMin
2020-11-11 13:50:33 +00:00
if (min.charAt(0) == "0") min = min.slice(-1) + " min"
else min = min + " min"
2020-11-10 18:28:48 +00:00
return this.mins.indexOf(min)
2020-11-02 11:36:53 +00:00
},
2020-11-10 18:28:48 +00:00
appTheme() {
2020-11-02 11:36:53 +00:00
return Application.systemAppearance()
},
2020-11-10 18:28:48 +00:00
rippleColor() {
return this.appTheme == "light"
? "rgba(134,142,150,0.2)"
: "rgba(206,212,218,0.1)"
},
2020-11-02 11:36:53 +00:00
selectedTime() {
return this.selectedHrs + ":" + this.selectedMins
},
},
methods: {
setHrs(args) {
2020-11-10 18:28:48 +00:00
let hr = "0" + this.hrs[args.object.selectedIndex]
2020-11-11 13:50:33 +00:00
this.selectedHrs = hr.slice(-5).slice(0, -3)
2020-11-02 11:36:53 +00:00
},
setMins(args) {
2020-11-10 18:28:48 +00:00
let min = "0" + this.mins[args.object.selectedIndex]
2020-11-11 13:50:33 +00:00
this.selectedMins = min.slice(-6).slice(0, -4)
2020-11-02 11:36:53 +00:00
},
},
}
</script>