<template>
  <van-field
    ref="input"
    v-model="inputValue"
    :label="label"
    :name="name"
    :border="border"
    :disabled="disabled"
    :readonly="readonly"
    :required="required"
    :clearable="clearable"
    :clickable="clickable"
    :is-link="isLink"
    :error="error"
    :error-message="errorMessage"

    :arrow-direction="arrowDirection"
    :label-class="labelClass"
    :label-width="labelWidth"
    :label-align="labelAlign"
    :input-align="inputAlign"
    :error-message-align="errorMessageAlign"
    :autosize="autosize"
    :left-icon="leftIcon"
    :right-icon="rightIcon"
    :icon-prefix="iconPrefix"
    :rules="editable?rules:null"
  >
    <template #label>
      {{ label }}<van-icon v-if="desc && descPosition==='lableIcon'" name="warning" class="ibps-dialog-icon" @click="$action.descDialog({ title:label, message:desc })" />
    </template>
    <template #input>
      <van-slider
        v-model="dataModel"
        :max="max"
        :min="min"
        :step="step"
        :bar-height="barHeight"
        :button-size="buttonSize"

        :active-color="activeColor"
        :inactive-color="inactiveColor"
        :disabled="disabled"
        :vertical="vertical"
        v-on="$listeners"
      >
        <template #button>
          <div class="ibps-slider-custom-button">
            {{ value }}
          </div>
        </template>
      </van-slider>
    </template>
  </van-field>
</template>
<script>
import FieldMixin from '@/mixins/field'

export default {
  name: 'ibps-slider',
  mixins: [FieldMixin],
  props: {
    max: [String, Number],
    min: [String, Number],
    step: [String, Number],
    barHeight: [String, Number],
    buttonSize: [String, Number],
    activeColor: String,
    inactiveColor: String,
    vertical: Boolean,
    desc: String
  },
  data() {
    return {
      dataModel: 0
    }
  },
  watch: {
    value: {
      handler(val) {
        this.dataModel = val
        this.inputValue = val
      },
      immediate: true
    },
    dataModel: {
      handler(val) {
        this.$emit('update:value', val)
      },
      deep: true
    }
  }
}
</script>
<style lang="scss">
  .ibps-slider-custom-button {
    width: 26px;
    color: #fff;
    font-size: 10px;
    line-height: 18px;
    text-align: center;
    background-color: #1989fa;
    border-radius: 100px;
  }
</style>

