<template>
<el-form>
	<el-form-item label="类型">
		<el-radio-group v-model="form.type">
			<el-radio-button label="任意值" :value="0"></el-radio-button>
			<el-radio-button label="范围" :value="1"></el-radio-button>
			<el-radio-button label="间隔" :value="2"></el-radio-button>
			<el-radio-button label="指定" :value="3"></el-radio-button>
		</el-radio-group>
	</el-form-item>
	<el-form-item label="范围" v-if="form.type==1">
		<el-input-number v-model="form.range.start" :min="0" :max="23" controls-position="right"></el-input-number>
		<span style="padding:0 15px;">-</span>
		<el-input-number v-model="form.range.end" :min="0" :max="23" controls-position="right"></el-input-number>
	</el-form-item>
	<el-form-item label="间隔" v-if="form.type==2">
		<el-input-number v-model="form.loop.start" :min="0" :max="23" controls-position="right"></el-input-number>
		分钟开始，每
		<el-input-number v-model="form.loop.end" :min="0" :max="23" controls-position="right"></el-input-number>
		分钟执行一次
	</el-form-item>
	<el-form-item label="指定" v-if="form.type==3">
		<el-select v-model="form.appoint" multiple style="width: 100%;">
			<el-option v-for="(item, index) in minute" :key="index" :label="item" :value="item"></el-option>
		</el-select>
	</el-form-item>
</el-form>
</template>

<script>
export default {
	emits: ['update:modelValue'],
	props: {
		modelValue: { type: String, default: "*" },
	},
	data(){
		return {
			form: {
				type: '0',
				range: {
					start: 1,
					end: 1
				},
				loop: {
					start: 1,
					end: 1
				},
				appoint: []
			},
			minute: [0, 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]
		}
	},
	watch:{
		modelValue:{
			handler(val){
				if(val == '*'){
					this.form.type = 0
				}else if(val.indexOf('-') > -1){
					this.form.type = 1
				}else if(val.indexOf('/') > -1){
					this.form.type = 2
				}else if(val.indexOf(',') > -1){
					this.form.type = 3
				}else{
					this.form.type = 3
				}
			},
			immediate: true
		},
		"form": {
			handler(val){
				let data = ''
				if(val.type == 0){
					data = '*'
				}else if(val.type==1){
					data = this.form.range.start + '-' + this.form.range.end
				}else if(val.type==2){
					data = this.form.loop.start + '/' + this.form.loop.end
				}else if(val.type==3){
					data = this.form.appoint.length>0 ? this.form.appoint.join(',') : '1'
				}else{
					data = '*'
				}
				this.$emit('update:modelValue', data)
			},
			deep: true
		}
	},
	mounted(){
	},
	methods:{
	}
}
</script>

<style scoped>
</style>