123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /**
- * 订单列表业务逻辑
- */
- import { reactive, ref, watch,nextTick, onMounted } from "vue";
- import {request} from "@/utils/network/request.js";
- import { stringToJson } from "@/utils/network/encryption";
- import {onLoad,onUnload,onReachBottom,onPullDownRefresh} from "@dcloudio/uni-app";
- import { getItem, StorageKeys } from "@/utils/storage";
- import { hasLogin, msg } from "@/utils/utils";
- import { orderList } from "@/utils/network/api";
- import {PageData} from "@/datas/enum";
-
- export default function useOrderListItem(props) {
- //搜索关键字
- const searchKeyWords = ref('');
-
- //订单列表数据
- const ordersList = ref([]);
-
- const config = {
- emptyHint:{
- hint:'~ 暂无订单数据 ~',
- icon:'',
- mode:'order'
- },
- contentTxt:{
- contentdown: '~上拉加载更多~',
- contentrefresh: '努力加载中...',
- contentnomore: '-- 我是有底线的 --'
- }
- }
-
- //请求参数
- const params = reactive({
- pageNum: PageData.NUM,
- pageSize:PageData.SIZE,
- total: 0,
- status: 'more',
- reload: false,
- })
-
- //搜索
- const doSearch = () => {
- if(!searchKeyWords.value){
- msg('请输入需要搜索的车牌号!');
- return;
- }
- refreshList(true);
- }
-
- //订单车牌号输入
- const onKeyInput = (event) =>{
- searchKeyWords.value = event.target.value;
- if(searchKeyWords.value == ''){
- refreshList(true);
- }
- }
-
- /* 刷新列表 */
- const refreshList = (isLoading) =>{
- params.pageNum = 1;
- params.total = 0;
- params.status = 'more';
- params.reload = false;
- getList();
- }
-
- /* 加载更多 */
- const loadMore = () =>{
- if(params.total > ordersList.value.length){
- params.status = 'loading';
- params.pageNum++;
- getList();
- }else{
- params.status = 'noMore';
- }
- }
-
- /* 获取列表数据 */
- const getList = async(isLoading = true) =>{
- if(!hasLogin()){
- uni.stopPullDownRefresh();
- uni.$emit('refreshFinish');
- return;
- }
-
- let res: any = null;
- const options = {
- type:2,
- data:{
- "opId": getItem(StorageKeys.OpenId),
- "source":"WECHAT",
- "vehiclePlate":searchKeyWords.value,
- "tabIndex":props.index + '',
- "pageNo":params.pageNum,
- "pageSize":params.pageSize
- },
- method:'POST',
- // showLoading: isLoading ? (params.pageNum === 1 ? true : false) : false ,
- }
-
- try{
- res = await request(orderList,options);
- const data = stringToJson(res.bizContent);
- params.total = data.totalCount;
-
- if(params.pageNum === 1){
- ordersList.value = [];
- }
- if(params.total > 0){
- const curList = data.data || [];
- ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
- params.reload = false;
- }
-
- if(params.total === ordersList.value.length){
- params.reload = false;
- params.status = 'noMore';
- }
-
- if(params.pageNum === 1){
- uni.stopPullDownRefresh();
- }
- uni.$emit('refreshFinish');
- }catch(e){
- uni.stopPullDownRefresh();
- uni.$emit('refreshFinish');
- }
- }
-
- watch(()=>props.index,()=>{
- refreshList(true);
- });
- watch(()=>props.refresh,(nv)=>{
- if(nv){
- refreshList(false);
- }
- });
- onMounted(()=>{
- if(props.refresh){
- refreshList(false);
- }
- })
- onPullDownRefresh(()=>{
- refreshList(true);
- });
-
- onReachBottom(()=>{
- loadMore();
- });
-
- return {
- config,
- params,
- ordersList,
- doSearch,
- onKeyInput
- };
- }
|