import { shallowRef } from 'vue'
import { useDataTable } from '@/hooks/datatable'
import { querySpotGoodsPrice, querySpotgoodsPrice } from '@/services/api/market'

// 现货行情
export function useSpotGoodsPrice() {
    const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.SpotGoodsPriceRsp>()
    const loading = shallowRef(false)

    const getSpotGoodsPrice = () => {
        loading.value = true
        return querySpotGoodsPrice({
            data: {
                page: pageIndex.value,
                pagesize: pageSize.value,
            },
            success: (res) => {
                total.value = res.total
                dataList.value = res.data
            },
            complete: () => {
                loading.value = false
            }
        })
    }

    return {
        loading,
        dataList,
        total,
        pageIndex,
        pageSize,
        pageCount,
        getSpotGoodsPrice,
    }
}

// 现货行情列表
export function useSpotGoodsPriceList() {
    const { dataList, pageCount } = useDataTable<Model.SpotgoodsPriceRsp>()
    const loading = shallowRef(false)

    const getSpotGoodsPriceList = () => {
        loading.value = true
        return querySpotgoodsPrice({
            success: (res) => {
                dataList.value = res.data
            },
            complete: () => {
                loading.value = false
            }
        })
    }

    return {
        loading,
        dataList,
        pageCount,
        getSpotGoodsPriceList,
    }
}