import { useInfiniteLoading } from '@12333/hooks';
|
import { OrderInputType, Gender } from '@12333/constants';
|
import * as flexWorkerServices from '@12333/services/api/FlexWorker';
|
import _ from 'lodash';
|
import { trim } from '@12333/utils';
|
import { MaybeRef } from 'vue';
|
|
export enum HomeOrderType {
|
Recommend = 'Recommend',
|
LastShelfTime = 'LastShelfTime',
|
}
|
|
type UseTaskListOptions = {
|
cityName?: MaybeRef<string>;
|
};
|
|
export function useTaskList(options: UseTaskListOptions = {}) {
|
const { cityName = '' } = options;
|
|
const searchValue = ref('');
|
|
const queryMenuState = reactive({
|
gender: '' as any as Gender,
|
});
|
|
const queryState = reactive({
|
searchValueTrim: '',
|
orderType: HomeOrderType.Recommend,
|
companyId: '',
|
});
|
|
const handleSearch = _.debounce(function () {
|
queryState.searchValueTrim = trim(searchValue.value);
|
}, 300);
|
|
const { infiniteLoadingProps } = useInfiniteLoading(
|
({ pageParam }) => {
|
let params: API.GetFlexTaskListInput = {
|
pageModel: {
|
rows: 20,
|
page: pageParam,
|
orderInput: [
|
queryState.orderType === HomeOrderType.Recommend
|
? { property: 'isRecommend', order: OrderInputType.Desc }
|
: { property: 'lastShelfTime', order: OrderInputType.Desc },
|
],
|
},
|
};
|
|
return flexWorkerServices.getFlexTaskByArrange(params, {
|
showLoading: false,
|
});
|
},
|
{
|
queryKey: ['flexWorkerServices/getFlexTaskByArrange', queryState, queryMenuState, cityName],
|
}
|
);
|
|
return {
|
searchValue,
|
queryState,
|
queryMenuState,
|
handleSearch,
|
infiniteLoadingProps,
|
};
|
}
|