<template>
  <!-- 过滤 -->
  <div class="filterTable">
    <a-space>
      <a-range-picker v-model:value="date"
                      class="commonPicker"
                      style="width: 200px"
                      :show-time="{hideDisabledOptions: true}"
                      format="YYYY-MM-DD" />
    </a-space>
    <FilterOption :selectList="selectList"
                  :inputList="inputList"
                  :fixedBtnList="fixedBtnList" />
    <slot></slot>
  </div>
</template>

<script lang="ts">
import FilterOption from '@/common/components/filter/index.vue';
import { defineComponent, ref } from 'vue';
import { handleFilter, handleTimeFilter, InputList, SelectList } from '@/common/setup/filter';
import { Moment } from 'moment';
import { initData } from '@/common/methods';
import { getGoodsList } from '@/services/bus/goods';

export default defineComponent({
    name: 'filter-flow',
    components: { FilterOption },
    setup(props, context) {
        const date = ref<Moment[]>([]);
        const select = ref<SelectList[]>([
            {
                value: undefined,
                key: 'goodsid',
                placeholder: '选择商品',
                list: [],
            },
        ]);
        const input: InputList[] = [{ value: '', placeholder: '模糊搜索账号', key: 'accountid' }];
        // 范围时间内过滤
        const { getFilterRangeTime } = handleTimeFilter('triggertime');

        const { selectList, inputList, fixedBtnList } = handleFilter(select, input, context, getFilterRangeTime(date));
        initData(() => {
            // 选择商品
            select.value[0].list = getGoodsList().map((e) => {
                return { value: e.goodsid, lable: e.goodsname };
            });
        });
        return {
            date,
            selectList,
            inputList,
            fixedBtnList,
        };
    },
});
</script>

<style lang="less">
.filterTable {
    .commonPicker.ant-calendar-picker {
        display: inline-flex;
        padding-top: 9px;
        padding-bottom: 6px;
        margin-right: 10px;
        .ant-input {
            border: 0;
            background: @m-grey9;
        }
    }
}
</style>;
