<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-rate
        v-model="dataModel"
        :count="count"
        :size="size"
        :gutter="gutter"
        :color="color"
        :void-color="voidColor"
        :disabled-color="disabledColor"
        :icon="icon"
        :void-icon="voidIcon"
        :icon-prefix="iconPrefix"
        :allow-half=" allowHalf"

        :disabled="disabled"
        :readonly="readonly"
        :touchable="touchable"

        v-on="$listeners"
      />
    </template>
  </van-field>
</template>
<script>
import FieldMixin from '@/mixins/field'

export default {
  name: 'ibps-rate',
  mixins: [FieldMixin],
  props: {
    count: [String, Number],
    gutter: [String, Number],
    color: String,
    voidColor: String,
    disabledColor: String,
    icon: String,
    voidIcon: String,
    allowHalf: Boolean,
    touchable: 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>

