<template>
  <div class="module">
    <div :class="className">
      <span class="spanTitle1">{{ title }}</span>
      <van-checkbox-group
        v-model="internalValue"
        direction="horizontal"
        @input="ins"
      >
        <van-checkbox
          v-for="(item, index) in option"
          :key="index"
          :name="item.id"
          >{{ item.name }}</van-checkbox
        >
        <!-- <van-checkbox name="b">复选框 b</van-checkbox> -->
      </van-checkbox-group>
      <b v-if="verify" class="verify">*</b>
    </div>

    <p class="reminder" v-if="reminder">当前项为必填项</p>
  </div>
</template>

<script>
export default {
  props: ['title', 'value', 'verify', 'option'],
  name: 'Checkbox',
  data () {
    return {
      className: 'el_input_focus1',
      internalValue: this.value,
      reminder: false
    }
  },
  watch: {
    value (cur, old) {
      if (!cur.length) {
        this.reminder = true
        this.className = 'el_input_focusTrue1'
      } else {
        this.reminder = false
        this.className = 'el_input_focus1'
      }
    }
  },
  mounted () {},

  methods: {
    ins (val) {
      this.$emit('input', this.internalValue)
    },
    focus () {
      if (!this.internalValue || this.internalValue === '@#%__+!') {
        this.className = 'el_input_blur'
      }
    },
    blur () {
      if (this.verify) {
        if (this.internalValue) {
          this.className = 'el_input_focus1'
        } else {
          this.className = 'el_input_focusTrue1'
        }
      } else {
        if (this.internalValue) {
          this.className = 'el_input_focus1'
        } else {
          this.className = 'el_input_focus'
        }
      }
    }
  }
}
</script>

<style lang="less" scoped></style>
