<template>
  <!-- 过滤客户资料表格 -->
  <div class="filterTable">
    <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, InputList, SelectList } from '@/common/setup/filter';
import { initData } from '@/common/methods';
import APP from '@/services';
import { Ermcp3Brand, Ermcp3Wrstandard, ErmcpDeliveryGoodsDetailEx } from '@/services/go/ermcp/goodsInfo/interface';
import { getWarehouseTypeEnumList } from '@/common/constants/enumsList';

export default defineComponent({
    name: 'filter-spot-contract-table',
    components: { FilterOption },
    setup(props, context) {
        const select = ref<SelectList[]>([
            {
                value: undefined,
                key: 'deliverygoodsid',
                placeholder: '全部现货品种',
                list: [],
                change: DGChange,
            },
            {
                value: undefined,
                key: 'wrstandardid',
                placeholder: '全部商品',
                list: [],
            },
            {
                value: undefined,
                key: 'spotgoodsbrandid',
                placeholder: '全部品牌',
                list: [],
            },
            {
                value: undefined,
                key: 'warehouseinfoid',
                placeholder: '全部仓库',
                list: [],
            },
        ]);
        const input: InputList[] = [];
        initData(() => {
            // 现货品种列表
            select.value[0].list = APP.get('DeliveryGoodsList')
                .filter((e: ErmcpDeliveryGoodsDetailEx) => {
                    return e.data.isvalid === 1;
                })
                .map((el: ErmcpDeliveryGoodsDetailEx) => {
                    const { deliverygoodsid, deliverygoodsname } = el.data;
                    return { value: deliverygoodsid, lable: deliverygoodsname };
                });
        });
        function DGChange(id: number) {
            select.value[1].value = undefined;
            select.value[2].value = undefined;
            const temp = APP.get('DeliveryGoodsList').find((el: ErmcpDeliveryGoodsDetailEx) => el.data.deliverygoodsid === id);
            if (temp) {
                select.value[1].list = temp.gmlist.map((e: Ermcp3Wrstandard) => {
                    const { wrstandardid, wrstandardname } = e;
                    return { value: wrstandardid, lable: wrstandardname };
                });
                select.value[2].list = temp.gblist.map((e: Ermcp3Brand) => {
                    const { brandid, brandname } = e;
                    return { value: brandid, lable: brandname };
                });
            }
        }
        select.value[3].list = getWarehouseTypeEnumList().map((e) => {
            const { enumitemname, enumdicname } = e;
            return { value: enumitemname, lable: enumdicname };
        });
        return {
            ...handleFilter(select, input, context),
        };
    },
});
</script>

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