<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="1" :max="12" controls-position="right"></el-input-number>
		<span style="padding:0 15px;">-</span>
		<el-input-number v-model="form.range.end" :min="1" :max="12" 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="1" :max="12" controls-position="right"></el-input-number>
		月开始，每
		<el-input-number v-model="form.loop.end" :min="1" :max="12" 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 data.month" :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: []
			},
			data: {
				month: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
			}
		}
	},
	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>