purchase-let/pagesOrder/order/order.vue

275 lines
7.9 KiB
Vue
Raw Normal View History

2024-04-26 18:04:56 +08:00
<template>
2024-05-10 09:09:20 +08:00
<view class="wrap">
<up-navbar placeholder style="z-index: 100800;" @leftClick="navBack">
<template #center>
<view>订单</view>
</template>
2024-05-07 19:02:43 +08:00
</up-navbar>
2024-04-26 18:04:56 +08:00
<up-sticky bgColor="#fff">
<view style="padding: 10rpx 20rpx 0 20rpx;">
2024-05-07 13:39:08 +08:00
<up-search shape="round" v-model="keyword" @custom="searchOn" @search="searchOn" @clear="searchOn"
:actionStyle="{color: '#20b128'}"></up-search>
2024-04-26 18:04:56 +08:00
</view>
2024-05-07 13:39:08 +08:00
<up-tabs :current="tabsActive" :list="tablist" lineColor="#20b128" :scrollable="false"
:activeStyle=" { color: '#20b128', fontWeight: 'bold' }" @change="changeTab"></up-tabs>
2024-04-26 18:04:56 +08:00
</up-sticky>
<swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish">
2024-04-30 16:24:55 +08:00
<swiper-item class="swiper-item" v-for="(list, k) in orderList" :key="k">
2024-05-07 13:39:08 +08:00
<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="loadMoreGood">
2024-04-26 18:04:56 +08:00
<view class="page-box">
2024-05-06 14:54:47 +08:00
<view v-if="list.length>0" class="list">
2024-05-10 09:09:20 +08:00
<good v-for="(item, index) in list" :datas="item" :key="index" :type="k" @cancleOrder="cancleOrder"
@takeOrder="takeOrder" @rePay="rePay" @purchaseAgain="purchaseAgain"></good>
2024-04-26 18:04:56 +08:00
</view>
2024-05-07 13:39:08 +08:00
<view v-if="!where[k].loading&&list.length==0" style="padding-top: 100rpx;">
2024-04-26 18:04:56 +08:00
<up-empty text="订单空空如也"
icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png">
</up-empty>
</view>
2024-05-07 13:39:08 +08:00
<view v-else-if="where[k].loadend" style="padding-top: 100rpx;">
<view style="text-align: center;color: #999;">没有更多了</view>
</view>
2024-05-10 09:09:20 +08:00
<view v-if="where[k].loading"
style="padding-top: 100rpx;display: flex;flex-direction: column;align-items: center;">
2024-05-07 13:39:08 +08:00
<up-loading-icon mode="circle"></up-loading-icon>
<view style="margin-top: 20rpx;color: #999;">加载中</view>
</view>
2024-05-10 09:09:20 +08:00
<view style="width: 100%;height: 300rpx;"></view>
2024-04-26 18:04:56 +08:00
</view>
</scroll-view>
</swiper-item>
</swiper>
2024-05-06 17:58:41 +08:00
<orderCanclePopup :show="showCancel" @close="showCancel=false" @change="submitCancel" />
2024-05-08 14:50:27 +08:00
<modal :show="showTake" title="确认收货" content="请确认您已收到货" @close="showTake=false" @change="confirmReceipt"></modal>
2024-04-26 18:04:56 +08:00
</view>
</template>
<script setup>
2024-05-08 14:50:27 +08:00
import { onLoad, onUnload } from "@dcloudio/uni-app"
2024-04-26 18:04:56 +08:00
import { ref } from 'vue';
import good from "./component/good.vue";
2024-05-06 17:58:41 +08:00
import orderCanclePopup from "@/components/orderCanclePopup.vue"
2024-05-08 14:50:27 +08:00
import modal from "@/components/modal.vue"
2024-05-08 15:25:03 +08:00
import { cancelOrderApi, rePaymentApi, confirmReceiptApi, orderListApi, purchaseAgainApi } from "@/api/order.js"
2024-04-26 18:04:56 +08:00
const tabsActive = ref(0)
2024-05-07 13:39:08 +08:00
const changeTab = ({ index }) => {
2024-04-26 18:04:56 +08:00
tabsActive.value = index;
swiperCurrent.value = index;
}
const tablist = ref([
{ name: '全部' },
{ name: '待付款' },
{ name: '待收货' },
2024-04-27 18:02:43 +08:00
// { name: '退款/售后' },
2024-04-26 18:04:56 +08:00
]);
const swiperCurrent = ref(0);
const animationfinish = ({ detail: { current } }) => {
swiperCurrent.value = current;
tabsActive.value = current;
2024-05-07 13:39:08 +08:00
if (swiperCurrent.value == 0 && orderList.value[0].length == 0) getOrderList(0);
if (swiperCurrent.value == 1 && orderList.value[1].length == 0) getOrderList(1, '', 0);
2024-05-08 14:50:27 +08:00
if (swiperCurrent.value == 2 && orderList.value[2].length == 0) getOrderList(2, 1);
2024-04-26 18:04:56 +08:00
}
2024-05-07 13:39:08 +08:00
2024-05-08 14:50:27 +08:00
// 取消订单
2024-05-06 17:58:41 +08:00
const showCancel = ref(false);
2024-05-07 13:39:08 +08:00
let cancelId = '';
2024-05-06 17:58:41 +08:00
const submitCancel = (e) => {
showCancel.value = false;
2024-05-07 13:39:08 +08:00
cancelOrderApi({
order_id: cancelId,
value: e.value
}).then(res => {
uni.showToast({
title: '取消成功',
icon: 'none'
})
orderList.value[1] = orderList.value[1].filter(item => item.id !== cancelId)
2024-05-06 17:58:41 +08:00
})
}
2024-05-07 13:39:08 +08:00
const cancleOrder = (e) => {
cancelId = e.id;
2024-05-06 17:58:41 +08:00
showCancel.value = true;
}
2024-05-10 09:09:20 +08:00
2024-05-08 14:50:27 +08:00
// 确认收货
const showTake = ref(false);
let takeId = "";
const takeOrder = (e) => {
takeId = e.id;
showTake.value = true;
}
2024-05-10 09:09:20 +08:00
const confirmReceipt = () => {
2024-05-08 14:50:27 +08:00
confirmReceiptApi({
order_id: takeId
2024-05-10 09:09:20 +08:00
}).then(res => {
2024-05-08 14:50:27 +08:00
showTake.value = false;
uni.$u.toast('确认收货成功');
reloadAll();
})
}
2024-05-10 09:09:20 +08:00
2024-05-08 15:25:03 +08:00
// 再次购买
2024-05-10 09:09:20 +08:00
const purchaseAgain = (e) => {
2024-05-08 15:25:03 +08:00
purchaseAgainApi({
order_id: e.id
2024-05-10 09:09:20 +08:00
}).then(res => {
2024-05-08 15:25:03 +08:00
uni.$u.toast('已加入购物车');
})
}
2024-05-07 13:39:08 +08:00
const rePay = (e) => {
rePaymentApi({
order_id: e.id,
2024-05-08 14:50:27 +08:00
address_id: e.address_id,
mer_id: e.merchant,
2024-05-07 13:39:08 +08:00
pay_type: 1
}).then(res => {
if (!res.data?.nonceStr) return uni.$u.toast('支付失败!');
uni.requestPayment({
provider: 'wxpay',
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: (e) => {
if (e.errMsg == 'requestPayment:ok') {
uni.showToast({
title: '订单支付成功',
icon: 'success'
})
2024-05-08 14:50:27 +08:00
reloadAll();
2024-05-07 13:39:08 +08:00
} else uni.$u.toast('支付失败')
},
fail: (e) => {
uni.$u.toast('用户取消支付')
}
})
}).catch(err => {
uni.$u.toast('网络错误')
})
}
2024-04-30 16:24:55 +08:00
// 订单
2024-05-07 13:39:08 +08:00
const where = ref([{
page_no: 1,
page_size: 25,
loading: false,
loadend: false
}, {
page_no: 1,
page_size: 25,
loading: false,
loadend: false
},
{
page_no: 1,
page_size: 25,
loading: false,
loadend: false
}
])
const keyword = ref('')
const orderList = ref([
2024-04-30 16:24:55 +08:00
[],
[],
[],
])
2024-05-07 13:39:08 +08:00
const getOrderList = (type = 0, status = '', paid = 1) => {
2024-05-10 09:09:20 +08:00
if (where.value[type].loadend) return;
2024-05-07 13:39:08 +08:00
where.value[type].loading = true;
2024-04-30 16:24:55 +08:00
orderListApi({
2024-05-07 15:12:40 +08:00
page_no: where.value[type].page_no,
page_size: where.value[type].page_size,
2024-05-07 19:02:43 +08:00
number: keyword.value,
2024-04-30 18:08:36 +08:00
status: status,
2024-05-06 14:26:18 +08:00
paid: paid
2024-05-07 13:39:08 +08:00
}).then(res => {
2024-05-10 09:09:20 +08:00
if (where.value[type].page_no == 1) orderList.value[type] = [];
2024-05-07 13:39:08 +08:00
orderList.value[type] = [...orderList.value[type], ...res.data.lists];
2024-05-10 09:09:20 +08:00
if (res.data.lists.length < where.value[type].page_size) where.value[type].loadend = true;
2024-05-07 13:39:08 +08:00
where.value[type].page_no++;
where.value[type].loading = false;
2024-05-10 09:09:20 +08:00
}).catch(err => {
2024-05-07 13:39:08 +08:00
where.value[type].loading = false;
2024-04-30 16:24:55 +08:00
})
}
2024-05-10 09:09:20 +08:00
const loadMoreGood = () => {
2024-05-07 13:39:08 +08:00
if (swiperCurrent.value == 0) getOrderList(0);
if (swiperCurrent.value == 1) getOrderList(1, '', 0);
2024-05-08 14:50:27 +08:00
if (swiperCurrent.value == 2) getOrderList(2, 1);
2024-05-07 13:39:08 +08:00
}
2024-05-06 17:58:41 +08:00
// 搜索
2024-05-07 13:39:08 +08:00
const searchOn = () => {
2024-05-06 17:58:41 +08:00
orderList.value[+swiperCurrent.value] = [];
2024-05-07 13:39:08 +08:00
where.value[+swiperCurrent.value].page_no = 1;
2024-05-07 19:02:43 +08:00
where.value[+swiperCurrent.value].loadend = false;
2024-05-07 13:39:08 +08:00
if (swiperCurrent.value == 0) getOrderList(0);
if (swiperCurrent.value == 1) getOrderList(1, '', 0);
2024-05-08 14:50:27 +08:00
if (swiperCurrent.value == 2) getOrderList(2, 1);
2024-05-06 17:58:41 +08:00
}
2024-05-07 13:39:08 +08:00
2024-05-07 19:02:43 +08:00
let back = 0;
2024-05-10 09:09:20 +08:00
const navBack = () => {
2024-05-07 19:02:43 +08:00
uni.navigateBack({
delta: back ? +back : 0
})
}
2024-05-10 09:09:20 +08:00
2024-05-08 14:50:27 +08:00
const reloadAll = () => { //对订单进行操作时刷新页面
2024-05-10 09:09:20 +08:00
where.value.forEach(item => {
item.page_no = 1;
item.loadend = false;
});
getOrderList(1, '', 0);
getOrderList(0);
getOrderList(2, 1);
}
2024-05-07 19:02:43 +08:00
2024-05-07 13:39:08 +08:00
onLoad((options) => {
if (options.type) {
2024-04-27 18:02:43 +08:00
tabsActive.value = +options.type;
swiperCurrent.value = +options.type;
2024-05-07 13:39:08 +08:00
searchOn();
2024-04-27 18:02:43 +08:00
}
2024-05-10 09:09:20 +08:00
if (options.back) back = options.back;
2024-05-07 13:39:08 +08:00
// getOrderList(0);
// getOrderList(1, '', 0);
2024-05-08 14:50:27 +08:00
// getOrderList(2, 1);
2024-05-07 13:39:08 +08:00
2024-05-08 14:50:27 +08:00
uni.$on('reLoadOrderList', reloadAll);
})
2024-05-10 09:09:20 +08:00
onUnload(() => {
2024-05-08 14:50:27 +08:00
uni.$off('reLoadOrderList', reloadAll)
2024-04-27 18:02:43 +08:00
})
2024-04-26 18:04:56 +08:00
</script>
<style lang="scss">
2024-05-10 09:09:20 +08:00
.wrap {
display: flex;
flex-direction: column;
height: calc(100vh - var(--window-top));
width: 100%;
}
2024-04-26 18:04:56 +08:00
.swiper-box {
flex: 1;
2024-05-10 09:09:20 +08:00
}
2024-04-26 18:04:56 +08:00
2024-05-10 09:09:20 +08:00
.swiper-item {
height: 100%;
2024-04-26 18:04:56 +08:00
}
2024-05-07 13:39:08 +08:00
.page-box {
2024-04-26 18:04:56 +08:00
margin: 20rpx;
2024-05-07 13:39:08 +08:00
.list {}
2024-04-26 18:04:56 +08:00
}
</style>