<template>
  <div>
    <div class="default-filter">
      <div class="f-type">
        <s-radio v-model="option.data.type" name="fType" label="contain">包含</s-radio>
        <s-radio v-model="option.data.type" name="fType" label="eq">等于</s-radio>
        <s-radio v-model="option.data.type" name="fType" label="gt">大于</s-radio>
        <s-radio v-model="option.data.type" name="fType" label="lt">小于</s-radio>
      </div>
      <div class="f-name">
        <s-input v-model="option.data.name" type="text" placeholder="请输入名称" @input="changeOptionEvent()"></s-input>
      </div>
      <div class="f-iscase">
        <s-checkbox v-model="option.data.case">区分大小写</s-checkbox>
      </div>
      <div class="f-footer">
        <s-button status="primary" @click="confirmEvent">确认</s-button>
        <s-button @click="resetEvent">重置</s-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DefaultFilter',
  props: {
    params: Object
  },
  data () {
    return {
      types: [
        { value: 'contain', label: '包含' },
        { value: 'notContain', label: '不包含' },
        { value: 'eq', label: '等于' },
        { value: 'ne', label: '不等于' },
        { value: 'gt', label: '大于' },
        { value: 'ge', label: '大于等于' },
        { value: 'lt', label: '小于' },
        { value: 'le', label: '小于等于' },
        { value: 'start', label: '以...开头' },
        { value: 'end', label: '以...结尾' },
        { value: 'null', label: '为空' },
        { value: 'notNull', label: '不为空' }
      ],
      size: 'mini', // 被所有子组件继承 size
      column: null,
      option: null
    }
  },
  created () {
    // filters 可以配置多个，实际只用一个就可以满足需求了
    const { column } = this.params
    this.column = column
    this.option = column.filters[0]
  },
  methods: {
    changeOptionEvent () {
      const { params, option } = this
      const { $panel } = params
      const checked = !!option.data.name
      $panel.changeOption(null, checked, option)
    },
    confirmEvent () {
      const { $panel } = this.params
      $panel.confirmFilter()
    },
    resetEvent () {
      const { $panel } = this.params
      $panel.resetFilter()
    }
  }
}
</script>

<style scoped>
.default-filter {
  width: 260px;
  padding: 0 8px;
}
.default-filter .f-type {
  padding: 8px 0;
}
.default-filter .f-iscase {
  padding: 12px 0;
}
.default-filter .f-footer {
  text-align: center;
}
</style>
