<template>
	<view class="main padding-lr-sm">
		<u-form-item label="服务开通" label-width="130">
			<u-switch slot="right" @change="servace" v-model="switchVal" active-color="#FBC600" inactive-color="#eee">
			</u-switch>
		</u-form-item>
		<!-- <view class="" v-if="switchVal">
			<u-form-item label="上午服务时间 (8:00 ~ 12:00)" label-width="500">
				<u-switch slot="right" @change="amSelect" v-model="morningTime" active-color="#FBC600" inactive-color="#eee"></u-switch>
			</u-form-item>
			<u-form-item label="下午服务时间 (14:00 ~ 18:00)" label-width="500">
				<u-switch slot="right" @change="pmSelect" v-model="afternoonTime" active-color="#FBC600" inactive-color="#eee"></u-switch>
			</u-form-item>
			<u-form-item label="晚上服务时间 (18:00 ~ 24:00)" label-width="500">
				<u-switch slot="right" @change="evSelect" v-model="nightTime" active-color="#FBC600" inactive-color="#eee"></u-switch>
			</u-form-item>
		</view> -->
		<!-- <mx-date-picker :show="showPicker" type="time" :value="value" @confirm="ed" @cancel="ed" /> -->
	</view>
</template>

<script>
	import mxDatePicker from '@/components/mx-datepicker/mx-datepicker.vue'
	export default {
		components: {
			mxDatePicker
		},
		data() {
			return {
				switchVal: false,
				showPicker: false,
				value: '',
				morningTime: false,
				afternoonTime: false,
				nightTime: false,
				typeTime: null
			}
		},
		onLoad() {
			this.switchVal = this.vuex_user.is_schedule == 0 ? false : true
			this.morningTime = JSON.parse(this.vuex_user.schedule_setting).am
			this.afternoonTime = JSON.parse(this.vuex_user.schedule_setting).pm
			this.nightTime = JSON.parse(this.vuex_user.schedule_setting).ev
		},
		methods: {
			selectTime(num) {
				this.showPicker = true
				this.typeTime = num
			},
			ed(e) { //选择
				this.showPicker = false;
				console.log(e)
			},
			servace(e) {
				this.switchVal = e
				this.setSchedule_setting()
			},
			amSelect(e){
				this.morningTime = e
				this.setSchedule_setting()
			},
			pmSelect(e){
				this.afternoonTime = e
				this.setSchedule_setting()
			},
			evSelect(e){
				this.nightTime = e
				this.setSchedule_setting()
			},
			async setSchedule_setting() {
				let obj = {
					'am': this.morningTime,
					'pm': this.afternoonTime,
					'ev': this.nightTime
				}
				let res = await this.$u.post("manager/managerSchedule", {
					is_schedule: this.switchVal ? 1 : 0,
					schedule_setting: JSON.stringify(obj)
				})
				console.log(res)
			}
		}
	}
</script>

<style>
	.main {
		min-height: 100vh;
		background: #fff;
	}
</style>
