<template>
<div>
  <el-slider 
    v-model ="currentVal"
    :disabled="disabled || readonly"
    :step="step"
    :min="min"
    :max="max"
    @change="change">
  </el-slider >
</div>
</template>

<script lang='ts'>
import { Component, Vue, Prop, Model, Watch } from "vue-property-decorator";

@Component({})
export default class AppSlider extends Vue {
    /**
    * 传入值
    * @type {any}
    * @memberof AppSlider
    */
    @Prop() value?:any;

    /**
    * 是否禁用
    * @type {boolean}
    * @memberof AppSlider
    */
    @Prop() disabled?: boolean;

    /**
    * 属性项名称
    *
    * @type {string}
    * @memberof AppPicker
    */
    @Prop() name!: string;

    /**
    * 步长
    * @type {number}
    * @memberof AppSlider
    */
    @Prop({default:1}) step!: number;

    /**
    * 最小值
    * @type {number}
    * @memberof AppSlider
    */
    @Prop({default:0}) min!: number;

    /**
    * 最大值
    * @type {number}
    * @memberof AppSlider
    */
    @Prop({default:100}) max!: number;
    
	/**
	 * 只读模式
	 * 
	 * @type {boolean}
	 */
	@Prop({default: false}) readonly?: boolean;

    /**
    * 当前值
    *
    * @memberof AppSlider
    */
    currentVal: number = 0;

    /**
     * 值变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppPicker
     */
    @Watch('value')
    onValueChange(newVal: any, oldVal: any) {
        newVal = (newVal === null) ? 0 : newVal;
        this.currentVal = parseInt(newVal);
    }

    /**
     * change事件
     *
     * @param {*} val
     * @memberof AppPicker
     */
    change(val: any) {
        this.$emit('change', { name: this.name, value: val });
    }


}
</script>

<style lang='less'>
@import "./app-slider.less";
</style>