Files
kangyuan-mobile/pages/order/list.vue
T

313 lines
7.6 KiB
Vue

<!-- 订单列表 -->
<template>
<s-layout title="我的订单">
<card_pages
ref="cardPages"
:navList="tabMaps"
:currentTab="state.currentTab"
@upCallback="getData"
:pageSize="state.pageSize"
:height="height"
:oneShow="true"
>
<template #nav>
<view class="nav">
<view class="order-list-nav-top">
<view class="type-tabs p-x-32">
<view
class="type-tab-item center"
v-for="(v, i) in typeArr"
:key="i"
@click="navChangeType(i)"
>
<view
class="type-tab-text size32"
:class="{ activeTypeItem: state.currentType === i, activeTypeUnderline: state.currentType === i }"
>
{{ v.name }}
</view>
</view>
</view>
</view>
<scroll-view scroll-x show-scrollbar="false" class="scroll-x-wrapper w100 nowrap p-x-32">
<view class="flex-center ju-flex-start nowrap" style="width: auto">
<view
class="center flex-center m-r-58"
v-for="(v, i) in tabMaps"
:key="i"
@click="navChange(i)"
>
<view class="navItem size32" :class="{ activeItem: state.currentTab === i }">
{{ v.name }}
</view>
</view>
</view>
</scroll-view>
<view class="search flex-center">
<view class="flex1" style="background-color: #fff; border-radius: 32rpx"
><uni-easyinput
prefixIcon="search"
v-model="state.obj.keyWord"
placeholder="搜索商品名称/订单编号"
@iconClick="iconClick"
>
</uni-easyinput
></view>
<view class="searchBtn size32 c0" @click="downCallback(state.currentTab)">搜索</view>
</view>
</view>
</template>
<template #content>
<view class="orderCon" id="orderCon">
<view class="orderItem" v-for="(v, i) in state.list[state.currentTab]" :key="i">
<orderItem
:data="v"
@downData="downCallback(state.currentTab)"
:index="state.currentTab"
>
</orderItem>
</view>
</view>
</template>
</card_pages>
</s-layout>
</template>
<script setup>
import { ref, reactive } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import orderItem from '@/components/orderItem/orderItem.vue';
import { handleOrderButtons } from '@/sheep/hooks/useGoods';
import OrderApi from '@/sheep/api/trade/order';
import AfterSaleApi from '@/sheep/api/trade/afterSale';
import { getOrderPage as getAiOrderPage } from '@/sheep/api/ai';
let cardPages = ref(null);
// 数据
const state = reactive({
currentTab: 0, // 选中的 tabMaps 下标
currentType: 0, // 选中的 typeArr 下标
list: {},
pageSize: 10,
loadStatus: '',
obj: {
keyWord: '',
},
});
const typeArr = [
{ id: 0, name: '商城订单' },
{ id: 1, name: '店铺订单' },
];
const tabMaps = [
{
id: 0,
name: '全部',
},
{
id: 1,
name: '待支付',
value: 0,
},
{
id: 10,
name: '待发货',
value: '10',
},
{
id: 2,
name: '待收货',
value: '20',
},
{
id: 3,
name: '已完成',
value: '30',
},
{
id: 4,
name: '退换/售后',
value: '50,60',
},
];
let dataList = ref([]);
async function getData(mescroll) {
let code = null;
dataList.value = [];
const status = tabMaps?.[mescroll?.dataObj?.i]?.value;
const obj = {
pageNo: mescroll.num,
pageSize: mescroll.size,
status,
...state.obj,
};
if (!obj.status && obj.status !== 0) delete obj.status;
if (!obj.keyWord) delete obj.keyWord;
const isAfterSaleTab = String(mescroll?.dataObj?.status) === '50,60';
if (state.currentType === 0 && isAfterSaleTab) {
const res = await AfterSaleApi.getAfterSalePage(obj);
code = res.code;
dataList.value[mescroll.dataObj.i] = res.data;
} else if (state.currentType === 1) {
const res = await getAiOrderPage(obj);
code = res.code;
dataList.value[mescroll.dataObj.i] = res.data;
} else {
const res = await OrderApi.getOrderPage(obj);
code = res.code;
dataList.value[mescroll.dataObj.i] = res.data;
}
if (code !== 0) {
if (cardPages.value) {
cardPages.value.getState(false);
}
return;
}
const pageData = dataList.value?.[mescroll.dataObj.i] || {};
const list = Array.isArray(pageData?.list) ? pageData.list : Array.isArray(pageData) ? pageData : [];
const nextList = state.currentType === 1 ? list.map((o) => ({ ...o, __source: 'aishop' })) : list;
nextList.forEach((order) => handleOrderButtons(order));
if (mescroll.num == 1) state.list[mescroll.dataObj.i] = [];
state.list[mescroll.dataObj.i] = state.list[mescroll.dataObj.i].concat(nextList);
if (cardPages.value) {
cardPages.value.getState(true, nextList.length);
}
}
onLoad(async (options) => {
if (options.type) {
state.currentTab = Number(options.type);
}
if (options.currentType !== undefined) {
state.currentType = Number(options.currentType);
}
});
let sysInfo = uni.getSystemInfoSync();
let height =
sysInfo.windowHeight - sysInfo.statusBarHeight - uni.upx2px(100) - uni.upx2px(320) + 'px';
const navChange = (i) => {
state.currentTab = i;
if (cardPages.value) {
cardPages.value.downCallback();
}
};
const navChangeType = (i) => {
state.currentType = i;
state.currentTab = 0;
state.list = {};
downCallback(state.currentTab);
};
const downCallback = () => {
if (cardPages.value) {
cardPages.value.downCallback();
}
};
const iconClick = (e) => {
if (e == 'preefix') {
state.obj.keyWord = '';
downCallback(state.currentTab);
}
};
onShow(() => {
if (cardPages.value) {
cardPages.value.downCallback();
}
});
</script>
<style lang="scss" scoped>
.scroll-x-wrapper {
width: 100%;
white-space: nowrap;
}
.navItem {
padding: 18rpx 0;
}
.activeItem {
color: #ff3c48;
border-bottom: 6rpx solid #ff3c48;
}
.nav {
height: 320rpx;
background-color: #fff;
}
.order-list-nav-top {
height: 100rpx;
display: flex;
align-items: center;
border-bottom: 1rpx solid #ffe1d9;
background-color: #fff5f2;
}
.type-tabs {
width: 100%;
display: flex;
align-items: center;
box-sizing: border-box;
}
.type-tab-item {
flex: 1;
height: 120rpx;
display: flex;
align-items: center;
justify-content: center;
}
.type-tab-text {
position: relative;
padding: 18rpx 0;
font-weight: 500;
color: #333;
}
.activeTypeItem {
color: #ff3c48;
}
.activeTypeUnderline {
border-bottom: 6rpx solid #ff3c48;
}
.search {
padding: 0 32rpx;
box-sizing: border-box;
margin-top: 32rpx;
margin-bottom: 16rpx;
}
.searchBtn {
margin-left: 16rpx;
}
:deep(.is-input-border) {
height: 72rpx;
border-radius: 36rpx;
background-color: #f7f8fa;
border: none;
}
:deep(.is-input-border) {
background: rgba(255, 255, 255, 0.34);
}
.orderCon {
padding: 32rpx 24rpx;
box-sizing: border-box;
// overflow: hidden;
}
.orderItem {
margin-bottom: 24rpx;
}
</style>