<template>
  <!-- 过滤客户资料表格 -->
  <Filter @update="update">
    <!-- <FilterOption :selectList="selectList"
                    :inputList="[]"
                    :fixedBtnList="fixedBtnList" /> -->
  </Filter>
</template>

<script lang="ts">
import FilterOption from '@/common/components/filter/index.vue';
import { defineComponent } from 'vue';
import { ref } from 'vue';
import { handleFilter, SelectList } from '@/common/setup/filter';
import { handlerManagerList } from '@/common/setup/user';
import { QueryMiddleGoodsDetail } from '@/services/go/ermcp/goodsInfo';
import { SelectOption } from '@/common/setup/filter/interface';
import Filter from '../../../components/filter/index.vue';
import { TypeAndTime } from '@/views/report/interface';

export default defineComponent({
    name: 'exposure-filter-table',
    components: { FilterOption, Filter },
    setup(props, context) {
        function update(value: TypeAndTime) {
            context.emit('update', value);
        }
        const select: SelectList[] = [
            {
                value: undefined,
                key: 'userId',
                placeholder: '全部交易用户',
                list: [],
            },
            {
                value: undefined,
                key: 'warehousetype',
                placeholder: '全部套保品种',
                list: [],
            },
        ];
        const loading = ref<boolean>(false);
        // 交易用户
        const { tableList: userList, queryTable } = handlerManagerList(loading, 2);
        const { selectList, inputList, fixedBtnList, updateSelected } = handleFilter(select, [], context);
        // 获取交易用户
        function getUserList() {
            return queryTable().then(() => {
                const result: SelectOption[] = [];
                userList.value.forEach((e) => {
                    e.userlist.forEach((el) => {
                        result.push({ value: el.loginid, lable: `${el.loginname}-${el.logincode}` });
                    });
                });
                return result;
            });
        }
        // 获取套保品种
        function getTBList() {
            return QueryMiddleGoodsDetail().then((res) => {
                const result: SelectOption[] = [];
                res.forEach((e) => {
                    const { isvalid, middlegoodsname, middlegoodsid } = e.mg;
                    if (isvalid) {
                        result.push({ value: middlegoodsid, lable: middlegoodsname });
                    }
                });
                return result;
            });
        }
        // initData(() => {
        //     Promise.all([getUserList(), getTBList()]).then((res) => {
        //         select[0].list = res[0]; // 交易用户
        //         select[1].list = res[1]; // 套保品种
        //         updateSelected(select);
        //     });
        // });
        return {
            selectList,
            inputList,
            fixedBtnList,
        };
    },
});
</script>

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

