lilishop-uniapp/pages/order/myOrder.vue

817 lines
20 KiB
Vue
Raw Normal View History

2021-05-13 11:03:32 +08:00
<template>
<view class="content">
<view class="navbar">
2022-03-31 15:23:31 +08:00
<view
v-for="(item, index) in navList"
:key="index"
class="nav-item"
:class="{ current: tabCurrentIndex === index }"
@click="tabClick(index)"
>{{ item.text }}</view
>
2021-05-13 11:03:32 +08:00
</view>
2022-03-31 15:23:31 +08:00
<swiper
:current="tabCurrentIndex"
class="swiper-box"
duration="300"
@change="changeTab"
>
<swiper-item
class="tab-content"
v-for="(tabItem, tabIndex) in navList"
:key="tabIndex"
>
<scroll-view
class="list-scroll-content"
scroll-y
@scrolltolower="loadData(tabIndex)"
>
2021-05-13 11:03:32 +08:00
<!-- 空白页 -->
2022-03-31 15:23:31 +08:00
<u-empty
text="暂无订单"
mode="list"
v-if="tabItem.loaded === true && tabItem.orderList.length === 0"
></u-empty>
2021-05-13 11:03:32 +08:00
<!-- 订单列表 -->
2022-03-31 15:23:31 +08:00
<view
class="seller-view"
:key="oderIndex"
v-for="(order, oderIndex) in tabItem.orderList"
>
2021-05-13 11:03:32 +08:00
<!-- 店铺名称 -->
<view class="seller-info u-flex u-row-between">
2021-05-17 18:19:26 +08:00
<view class="seller-name" @click="navigateToStore(order)">
2021-05-13 11:03:32 +08:00
<view class="name">{{ order.storeName }}</view>
</view>
<view class="order-sn">{{
2021-05-17 18:19:26 +08:00
order.orderStatus | orderStatusList
2021-05-13 11:03:32 +08:00
}}</view>
</view>
<view>
<view>
2022-03-31 15:23:31 +08:00
<view
class="goods-item-view"
@click="navigateToOrderDetail(order.sn)"
>
<view
class="goods-img"
v-for="(goods, goodsIndex) in order.orderItems"
:key="goodsIndex"
>
<u-image
border-radius="6"
width="100%"
height="100%"
:src="goods.image"
></u-image>
2021-05-13 11:03:32 +08:00
</view>
<view class="goods-info">
2022-03-31 15:23:31 +08:00
<view
v-if="order.orderItems.length <= 1"
class="goods-title u-line-2"
>{{ order.groupName }}</view
>
<view
v-if="order.orderItems.length <= 1"
class="goods-price"
>
2021-05-13 11:03:32 +08:00
{{ order.flowPrice | unitPrice }}
</view>
</view>
<view v-if="order.orderItems.length <= 1" class="goods-num">
<view>x{{ order.groupNum }}</view>
</view>
</view>
</view>
<view class="btn-view u-flex u-row-between">
<view class="description">
<!-- 等待付款 -->
2021-07-15 15:10:27 +08:00
<div v-if="order.payStatus === 'PAID'">:</div>
<div v-else>:</div>
<div class="price">{{ order.flowPrice | unitPrice }}</div>
2021-05-13 11:03:32 +08:00
</view>
<view>
<!-- 全部 -->
2022-03-31 15:23:31 +08:00
<u-button
ripple
class="pay-btn"
shape="circle"
size="mini"
v-if="order.allowOperationVO.pay"
@click="waitPay(order)"
>立即付款</u-button
>
2021-05-13 11:03:32 +08:00
<!-- 取消订单 -->
2022-03-31 15:23:31 +08:00
<u-button
ripple
class="cancel-btn"
shape="circle"
size="mini"
v-if="order.allowOperationVO.cancel"
@click="onCancel(order.sn)"
>
2021-05-13 11:03:32 +08:00
取消订单
</u-button>
<!-- 等待收货 -->
2022-03-31 15:23:31 +08:00
<u-button
ripple
shape="circle"
class="rebuy-btn"
size="mini"
v-if="order.allowOperationVO.showLogistics"
@click="navigateToLogistics(order)"
>
2021-05-13 11:03:32 +08:00
查看物流
</u-button>
2022-03-31 15:23:31 +08:00
<u-button
ripple
:customStyle="{ background: lightColor, color: '#fff' }"
shape="circle"
class="pay-btn"
size="mini"
v-if="order.allowOperationVO.rog"
@click="onRog(order.sn)"
>
2021-05-13 11:03:32 +08:00
确认收货
</u-button>
2022-03-31 15:23:31 +08:00
<u-button
ripple
shape="circle"
class="cancel-btn"
size="mini"
v-if="order.groupAfterSaleStatus && order.groupAfterSaleStatus.includes('NOT_APPLIED')"
2022-03-31 15:23:31 +08:00
@click="applyService(order)"
>
退款/售后
</u-button>
<!-- TODO 后续完善 -->
<!-- <u-button ripple shape="circle" class="rebuy-btn" size="mini" v-if="
2021-05-13 11:03:32 +08:00
order.orderStatus === 'CANCELLED' ||
order.orderStatus === 'COMPLETE'
" @click="reBuy(order)">
再次购买
</u-button> -->
2021-05-13 11:03:32 +08:00
</view>
</view>
</view>
</view>
<uni-load-more :status="tabItem.loadStatus"></uni-load-more>
</scroll-view>
</swiper-item>
</swiper>
2022-03-31 15:23:31 +08:00
<u-popup
class="cancel-popup"
v-model="cancelShow"
mode="bottom"
length="60%"
>
2021-05-13 11:03:32 +08:00
<view class="header">取消订单</view>
<view class="body">
2022-03-31 15:23:31 +08:00
<view class="title"
>取消订单后本单享有的优惠可能会一并取消是否继续</view
>
2021-05-13 11:03:32 +08:00
<view>
<u-radio-group v-model="reason">
<view class="value">
2022-03-31 15:23:31 +08:00
<view
class="radio-view"
:key="index"
v-for="(item, index) in cancelList"
>
<u-radio
:active-color="lightColor"
label-size="25"
shape="circle"
:name="item.reason"
@change="reasonChange"
>{{ item.reason }}</u-radio
>
2021-05-13 11:03:32 +08:00
</view>
</view>
</u-radio-group>
</view>
</view>
<view class="footer">
2022-03-31 15:23:31 +08:00
<u-button
size="medium"
ripple
v-if="reason"
shape="circle"
@click="submitCancel"
>提交</u-button
>
2021-05-13 11:03:32 +08:00
</view>
</u-popup>
<u-toast ref="uToast" />
2022-03-31 15:23:31 +08:00
<u-modal
:confirm-color="lightColor"
v-model="rogShow"
:show-cancel-button="true"
:content="'是否确认收货?'"
@confirm="confirmRog"
></u-modal>
2021-05-13 11:03:32 +08:00
</view>
</template>
<script>
import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
import { getOrderList, cancelOrder, confirmReceipt } from "@/api/order.js";
import { getClearReason } from "@/api/after-sale.js";
import LiLiWXPay from "@/js_sdk/lili-pay/wx-pay.js";
export default {
components: {
uniLoadMore,
},
data() {
return {
lightColor: this.$lightColor,
2021-05-17 18:19:26 +08:00
tabCurrentIndex: 0, //导航栏索引
2021-05-13 11:03:32 +08:00
navList: [
2021-05-17 18:19:26 +08:00
//导航栏list
2021-05-13 11:03:32 +08:00
{
state: 0,
text: "全部",
loadStatus: "more",
orderList: [],
pageNumber: 1,
},
{
state: 1,
text: "待付款",
loadStatus: "more",
orderList: [],
pageNumber: 1,
},
{
state: 2,
text: "待发货",
loadStatus: "more",
orderList: [],
pageNumber: 1,
},
{
state: 3,
text: "待收货",
loadStatus: "more",
orderList: [],
pageNumber: 1,
},
{
state: 4,
text: "已完成",
loadStatus: "more",
orderList: [],
pageNumber: 1,
},
{
state: 5,
text: "已取消",
loadStatus: "more",
orderList: [],
pageNumber: 1,
},
],
2021-05-17 18:19:26 +08:00
status: "", //接收导航栏状态
2021-05-13 11:03:32 +08:00
params: {
pageNumber: 1,
pageSize: 10,
tag: "ALL",
},
orderStatus: [
2021-05-17 18:19:26 +08:00
//订单状态
2021-05-13 11:03:32 +08:00
{
orderStatus: "ALL", //全部
},
{
orderStatus: "WAIT_PAY", //代付款
},
{
orderStatus: "WAIT_SHIP",
},
{
orderStatus: "WAIT_ROG", //待收货
},
{
orderStatus: "COMPLETE", //已完成
},
{
orderStatus: "CANCELLED", //已取消
},
],
2021-05-17 18:19:26 +08:00
cancelShow: false, //是否显示取消
orderSn: "", //ordersn
2021-05-13 11:03:32 +08:00
reason: "", //取消原因
2021-05-17 18:19:26 +08:00
cancelList: "", //取消列表
rogShow: false, //显示是否收货
2021-05-13 11:03:32 +08:00
};
},
2021-05-17 18:19:26 +08:00
/**
* 跳转到个人中心
*/
2021-05-13 11:03:32 +08:00
onBackPress(e) {
if (e.from == "backbutton") {
uni.reLaunch({
url: "/pages/tabbar/user/my",
});
return true; //阻止默认返回行为
}
},
2021-05-17 18:19:26 +08:00
onPullDownRefresh() {
2022-03-31 15:23:31 +08:00
if (this.tabCurrentIndex) {
this.initData(this.tabCurrentIndex);
} else {
this.initData(0);
}
2022-04-21 11:50:13 +08:00
// this.loadData(this.status);
2022-03-31 15:23:31 +08:00
},
onShow() {
if(this.$options.filters.tipsToLogin()){
if (!this.tabCurrentIndex) {
this.initData(0);
}
2022-03-31 15:23:31 +08:00
}
this.loadData(this.status);
2021-05-13 11:03:32 +08:00
},
2021-05-13 11:03:32 +08:00
onLoad(options) {
/**
* 修复app端点击除全部订单外的按钮进入时不加载数据的问题
* 替换onLoad下代码即可
*/
let status = Number(options.status);
this.status = status;
2022-05-18 15:30:17 +08:00
2021-05-13 11:03:32 +08:00
this.tabCurrentIndex = status;
2022-04-21 11:50:13 +08:00
// if (status == 0) {
// this.loadData(status);
// }
2021-05-13 11:03:32 +08:00
},
watch: {
2021-05-17 18:19:26 +08:00
/**监听更改请求数据 */
2021-05-13 11:03:32 +08:00
tabCurrentIndex(val) {
this.params.tag = this.orderStatus[val].orderStatus;
//切换标签页将所有的页数都重置为1
this.navList.forEach((res) => {
res.pageNumber = 1;
res.loadStatus = "more";
res.orderList = [];
});
this.loadData(val);
},
},
methods: {
// 售后
2022-03-31 15:23:31 +08:00
applyService(order) {
uni.navigateTo({
2022-03-31 15:23:31 +08:00
url: `/pages/order/afterSales/afterSales?orderSn=${order.sn}`,
});
},
2021-05-13 11:03:32 +08:00
// 店铺详情
2021-05-17 18:19:26 +08:00
navigateToStore(val) {
uni.navigateTo({
2021-05-13 11:03:32 +08:00
url: "/pages/product/shopPage?id=" + val.storeId,
});
},
2021-05-17 18:19:26 +08:00
/**
* 取消订单
*/
2021-05-13 11:03:32 +08:00
onCancel(sn) {
this.orderSn = sn;
this.cancelShow = true;
uni.showLoading({
title: "加载中",
});
getClearReason().then((res) => {
if (res.data.result.length >= 1) {
this.cancelList = res.data.result;
}
uni.hideLoading();
});
},
2021-05-17 18:19:26 +08:00
/**
* 初始化数据
*/
2021-05-13 11:03:32 +08:00
initData(index) {
this.navList[index].pageNumber = 1;
this.navList[index].loadStatus = "more";
this.navList[index].orderList = [];
this.loadData(index);
},
2021-05-17 18:19:26 +08:00
/**
* 等待支付
*/
2021-05-13 11:03:32 +08:00
waitPay(val) {
2021-05-17 18:19:26 +08:00
this.$u.debounce(this.pay(val), 3000);
2021-05-13 11:03:32 +08:00
},
2021-05-17 18:19:26 +08:00
/**
* 支付
*/
pay(val) {
if (val.sn) {
2021-05-13 11:03:32 +08:00
// #ifdef MP-WEIXIN
2021-05-17 18:19:26 +08:00
new LiLiWXPay({
sn: val.sn,
price: val.flowPrice,
orderType: "ORDER",
}).pay();
2021-05-13 11:03:32 +08:00
// #endif
// #ifndef MP-WEIXIN
uni.navigateTo({
2021-05-17 18:19:26 +08:00
url: "/pages/cart/payment/payOrder?order_sn=" + val.sn,
});
2021-05-13 11:03:32 +08:00
// #endif
}
},
2021-05-17 18:19:26 +08:00
/**
* 获取订单列表
*/
2021-05-13 11:03:32 +08:00
loadData(index) {
this.params.pageNumber = this.navList[index].pageNumber;
2022-05-18 15:30:17 +08:00
// this.params.tag = this.orderStatus[index].orderStatus;
2021-05-13 11:03:32 +08:00
getOrderList(this.params).then((res) => {
2021-05-17 18:19:26 +08:00
uni.stopPullDownRefresh();
2021-05-13 11:03:32 +08:00
if (!res.data.success) {
this.navList[index].loadStatus = "noMore";
return false;
}
let orderList = res.data.result.records;
if (orderList.length == 0) {
this.navList[index].loadStatus = "noMore";
} else if (orderList.length < 10) {
this.navList[index].loadStatus = "noMore";
}
if (orderList.length > 0) {
this.navList[index].orderList =
this.navList[index].orderList.concat(orderList);
2021-05-13 11:03:32 +08:00
this.navList[index].pageNumber += 1;
}
});
},
//swiper 切换监听
changeTab(e) {
this.tabCurrentIndex = e.target.current;
},
//顶部tab点击
tabClick(index) {
this.tabCurrentIndex = index;
},
//删除订单
deleteOrder(index) {
uni.showLoading({
title: "请稍后",
});
setTimeout(() => {
this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
uni.hideLoading();
}, 600);
},
//取消订单
cancelOrder(item) {
uni.showLoading({
title: "请稍后",
});
setTimeout(() => {
let { stateTip, stateTipColor } = this.orderStateExp(9);
item = Object.assign(item, {
state: 9,
stateTip,
stateTipColor,
});
//取消订单后删除待付款中该项
let list = this.navList[1].orderList;
let index = list.findIndex((val) => val.id === item.id);
index !== -1 && list.splice(index, 1);
uni.hideLoading();
}, 600);
},
//订单状态文字和颜色
orderStateExp(state) {
let stateTip = "",
stateTipColor = this.$lightColor;
switch (+state) {
case 1:
stateTip = "待付款";
break;
case 2:
stateTip = "待发货";
break;
case 9:
stateTip = "订单已关闭";
stateTipColor = "#909399";
break;
//更多自定义
}
return {
stateTip,
stateTipColor,
};
},
2021-05-17 18:19:26 +08:00
/**
* 跳转到订单详情
*/
navigateToOrderDetail(sn) {
uni.navigateTo({
2021-05-13 11:03:32 +08:00
url: "./orderDetail?sn=" + sn,
});
},
2021-05-17 18:19:26 +08:00
/**
* 选择取消原因
*/
2021-05-13 11:03:32 +08:00
reasonChange(reason) {
this.reason = reason;
},
2021-05-17 18:19:26 +08:00
/**
* 提交取消订单未付款
*/
2021-05-13 11:03:32 +08:00
submitCancel() {
cancelOrder(this.orderSn, { reason: this.reason }).then((res) => {
if (res.statusCode == 200) {
uni.showToast({
title: "订单已取消",
duration: 2000,
icon: "none",
});
this.initData(0);
this.cancelShow = false;
2021-05-17 18:19:26 +08:00
} else {
2021-05-13 11:03:32 +08:00
uni.showToast({
title: res.data.message,
duration: 2000,
icon: "none",
});
2021-05-17 18:19:26 +08:00
this.cancelShow = false;
2021-05-13 11:03:32 +08:00
}
});
},
2021-05-17 18:19:26 +08:00
/**
* 确认收货显示
*/
2021-05-13 11:03:32 +08:00
onRog(sn) {
this.orderSn = sn;
this.rogShow = true;
},
2021-05-17 18:19:26 +08:00
/**
* 点击确认收货
*/
2021-05-13 11:03:32 +08:00
confirmRog() {
confirmReceipt(this.orderSn).then((res) => {
if (res.data.code == 200) {
uni.showToast({
title: "已确认收货",
duration: 2000,
icon: "none",
});
this.initData(this.tabCurrentIndex);
this.rogShow = false;
}
});
},
2021-05-17 18:19:26 +08:00
/**
* 评价商品
*/
2021-05-13 11:03:32 +08:00
onComment(sn) {
uni.navigateTo({
2021-05-13 11:03:32 +08:00
url: "./evaluate/myEvaluate",
});
},
2021-05-17 18:19:26 +08:00
/**
* 重新购买
*/
2021-05-13 11:03:32 +08:00
reBuy(order) {
console.log(order);
return;
uni.navigateTo({
2021-05-17 18:19:26 +08:00
url:
"/pages/product/goods?id=" + order.id + "&goodsId=" + order.goodsId,
2021-05-13 11:03:32 +08:00
});
},
2021-05-17 18:19:26 +08:00
/**
* 查看物流
*/
navigateToLogistics(order) {
uni.navigateTo({
2021-05-17 18:19:26 +08:00
url:
"/pages/mine/msgTips/packageMsg/logisticsDetail?order_sn=" + order.sn,
2021-05-13 11:03:32 +08:00
});
},
},
};
</script>
2021-05-17 18:19:26 +08:00
<style lang="scss" scoped>
2021-05-13 11:03:32 +08:00
page,
.content {
background: $page-color-base;
height: 100%;
}
.swiper-box {
height: calc(100vh - 40px);
// #ifdef H5
height: calc(100vh - 40px - 44px);
// #endif
2021-05-13 11:03:32 +08:00
}
.list-scroll-content {
height: 100%;
}
.navbar {
display: flex;
height: 40px;
padding: 0 5px;
background: #fff;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
position: relative;
z-index: 10;
.nav-item {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 26rpx;
color: $font-color-light;
position: relative;
&.current {
color: $main-color;
&:after {
content: "";
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 44px;
height: 0;
border-bottom: 2px solid $main-color;
}
}
}
}
.uni-swiper-item {
height: auto;
}
.seller-view {
border-radius: 20rpx;
background-color: #fff;
margin: 20rpx 0rpx;
.seller-info {
height: 70rpx;
padding: 0 20rpx;
.seller-name {
font-size: 28rpx;
font-weight: 600;
display: flex;
flex-direction: row;
.name {
margin-left: 15rpx;
margin-top: -2rpx;
}
}
.order-sn {
color: $aider-light-color;
font-size: 26rpx;
}
}
.goods-item-view {
display: flex;
flex-wrap: wrap;
flex-direction: row;
padding: 10rpx 20rpx;
.goods-img {
width: 131rpx;
height: 131rpx;
margin-right: 10rpx;
margin-bottom: 10rpx;
}
.goods-info {
padding-left: 30rpx;
flex: 1;
.goods-title {
margin-bottom: 10rpx;
color: #333333;
}
.goods-specs {
font-size: 24rpx;
margin-bottom: 10rpx;
color: #cccccc;
}
.goods-price {
font-size: 28rpx;
margin-bottom: 10rpx;
color: $aider-light-color;
}
}
.goods-num {
width: 60rpx;
color: $main-color;
}
}
.btn-view {
padding: 25rpx 30rpx;
font-size: 26rpx;
.description {
2021-07-15 15:10:27 +08:00
display: flex;
2021-05-13 11:03:32 +08:00
color: #909399;
2021-07-15 15:10:27 +08:00
size: 24rpx;
flex: 1;
2021-05-13 11:03:32 +08:00
.price {
color: $main-color;
}
}
}
}
.cancel-popup {
.header {
display: flex;
flex-direction: row;
justify-content: center;
margin: 15rpx 0rpx;
}
.body {
padding: 30rpx;
.title {
font-weight: 600;
}
.value {
display: flex;
flex-direction: column;
margin: 20rpx 0;
.radio-view {
margin: 20rpx 0rpx;
}
}
}
.footer {
text-align: center;
}
}
.cancel-btn {
color: #999999 !important;
border-color: #999999 !important;
margin-left: 15rpx;
height: 60rpx;
}
.pay-btn {
// #ifndef MP-WEIXIN
background-color: $light-color !important;
// #endif
color: #ffffff !important;
margin-left: 15rpx;
height: 60rpx;
}
.rebuy-btn {
color: $light-color !important;
border-color: $light-color !important;
background-color: #ffffff !important;
margin-left: 15rpx;
height: 60rpx;
}
</style>