|
|
@@ -0,0 +1,106 @@
|
|
|
+import {Refresh} from '@components';
|
|
|
+import Item from './item';
|
|
|
+import {View, Image} from '@tarojs/components';
|
|
|
+import classNames from 'classnames';
|
|
|
+import filterIcon from '@assets/filter.svg';
|
|
|
+import plusIcon from '@assets/plus.svg';
|
|
|
+import Filter from './filter';
|
|
|
+import Put from './put';
|
|
|
+import {useInfiniteFetch} from '@hooks';
|
|
|
+import {getCustomerList} from '@apis';
|
|
|
+import {useState} from 'react';
|
|
|
+import {useBoolean} from 'ahooks';
|
|
|
+import {useDelete, usePut} from './hooks';
|
|
|
+
|
|
|
+export default function Customer() {
|
|
|
+ const [params, setParams] = useState({name: '', code: ''});
|
|
|
+ function onChange(key) {
|
|
|
+ return function (val) {
|
|
|
+ setParams(prev => ({...prev, [key]: val}));
|
|
|
+ };
|
|
|
+ }
|
|
|
+ function onReset() {
|
|
|
+ setParams({name: '', code: ''});
|
|
|
+ }
|
|
|
+ const [filterVisible, {setTrue: showFilter, setFalse: closeFilter}] =
|
|
|
+ useBoolean();
|
|
|
+
|
|
|
+ const [
|
|
|
+ {data, isFetching, isFetchingNextPage, hasNextPage, isEmpty},
|
|
|
+ {fetchNextPage, refresh},
|
|
|
+ ] = useInfiniteFetch({
|
|
|
+ key: [getCustomerList.name],
|
|
|
+ fn: getCustomerList,
|
|
|
+ limit: '10',
|
|
|
+ params,
|
|
|
+ });
|
|
|
+
|
|
|
+ const [{putVisible, id}, {onPutClose, onAdd, onEdit, onConfirm}] =
|
|
|
+ usePut(refresh);
|
|
|
+ const onDelte = useDelete(refresh);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <Refresh
|
|
|
+ background='#eee'
|
|
|
+ className='bg-[#eee] h-screen'
|
|
|
+ isRefreshing={isFetching && !isFetchingNextPage}
|
|
|
+ onRefresh={refresh}
|
|
|
+ isLoading={isFetchingNextPage}
|
|
|
+ onLoading={fetchNextPage}
|
|
|
+ noMore={!hasNextPage}
|
|
|
+ empty={isEmpty}
|
|
|
+ endClassName='pb-16'
|
|
|
+ >
|
|
|
+ <View className='h-3' />
|
|
|
+ {(data?.pages ?? []).map(function (el) {
|
|
|
+ return (
|
|
|
+ <Item
|
|
|
+ key={el.id}
|
|
|
+ {...el}
|
|
|
+ onEdit={onEdit}
|
|
|
+ onDel={onDelte(el.id, el.name)}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ <View className='h-3' />
|
|
|
+ </Refresh>
|
|
|
+
|
|
|
+ <View
|
|
|
+ className={classNames(
|
|
|
+ 'fixed right-3 bottom-8 flex items-center justify-center bg-white rounded-3xl',
|
|
|
+ 'w-10 h-10 shadow-lg z-10',
|
|
|
+ )}
|
|
|
+ onClick={showFilter}
|
|
|
+ >
|
|
|
+ <Image src={filterIcon} mode='widthFix' className='w-5' />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <View
|
|
|
+ className={classNames(
|
|
|
+ 'fixed right-3 bottom-20 flex items-center justify-center bg-white rounded-3xl',
|
|
|
+ 'w-10 h-10 shadow-lg z-10',
|
|
|
+ )}
|
|
|
+ onClick={onAdd}
|
|
|
+ >
|
|
|
+ <Image src={plusIcon} mode='widthFix' className='w-5' />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <Filter
|
|
|
+ fields={params}
|
|
|
+ onChange={onChange}
|
|
|
+ onReset={onReset}
|
|
|
+ onConfirm={refresh}
|
|
|
+ visible={filterVisible}
|
|
|
+ onClose={closeFilter}
|
|
|
+ />
|
|
|
+
|
|
|
+ <Put
|
|
|
+ visible={putVisible}
|
|
|
+ onClose={onPutClose}
|
|
|
+ id={id}
|
|
|
+ onConfirm={onConfirm}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ );
|
|
|
+}
|