import { SelectList } from "@/common/setup/filter";
import { queryTableList } from "@/common/setup/table";
import { getGoodsList } from '@/services/bus/goods';
import { queryParentAreaList } from "@/services/go/ermcp/qhj";
import { QhjParentAreaList } from "@/services/go/ermcp/qhj/interface";
import { ref } from "vue";

/**
 * 获取单据 select 过滤数据
 * @returns 
 */
export function handleSelectOption() {
    const select = ref<SelectList[]>([
        {
            value: undefined,
            key: 'userinfotype',
            placeholder: '账号类型',
            list: [
                { value: 1, lable: '个人' },
                { value: 2, lable: '企业' },
            ],
        },
        {
            value: undefined,
            key: 'goodsid',
            placeholder: '选择商品',
            list: [],
        },
        {
            value: undefined,
            key: 'userid',
            placeholder: '请选择子机构',
            list: [],
        },
    ]);
    const { queryTable } = queryTableList<QhjParentAreaList>();
    function getSelectList() {
        // 商品列表
        select.value[1].list = getGoodsList().map((e) => {
            return { value: e.goodsid, lable: e.goodsname };
        });
        // 机构列表
        queryTable(queryParentAreaList).then((res) => {
            select.value[2].list = res.map((e) => {
                return { value: e.userid, lable: e.accountname };
            });
        });
    }
    return { select, getSelectList }
}