Files
peiwan-uniapp/pages/order/worker/components/layout.vue

183 lines
6.0 KiB
Vue
Raw Normal View History

2025-01-21 01:46:34 +08:00
<!-- 虚拟列表演示(不使用内置列表)(vue) -->
<!-- 写法较简单在页面中对当前需要渲染的虚拟列表数据进行for循环在vue3中兼容性良好 -->
<!-- 在各平台兼容性请查阅https://z-paging.zxlee.cn/module/virtual-list.html -->
<template>
<view class="content">
<!-- 如果页面中的cell高度是固定不变的则不需要设置cell-height-mode如果页面中高度是动态改变的则设置cell-height-mode="dynamic" -->
<!-- 原先的v-model修改为@virtualListChange="virtualListChange"并赋值处理后的虚拟列表 -->
<z-paging ref="paging" :auto="false" use-virtual-list :force-close-inner-list="true" :paging-style="{ paddingTop: 0 + 'px', paddingBottom: paddingBottom + 'rpx' }" cell-height-mode="dynamic" @scroll="scroll" @virtualListChange="virtualListChange" @query="queryList">
<!-- 需要固定在顶部不滚动的view放在slot="top"的view中如果需要跟着滚动则不要设置slot="top" -->
<template #top>
<su-navbar :title="title" statusBar></su-navbar>
<tab-box :tabList="tabList" :currentValue="currentIndex" @change="tabChange"></tab-box>
</template>
<!-- :id="`zp-id-${item.zp_index}`":key="item.zp_index" 必须写必须写 -->
<!-- 这里for循环的index不是数组中真实的index了请使用item.zp_index获取真实的index -->
<order-list @onCancel="onCancel" @onConfirm="onConfirm" @onOrderConfirm="onOrderConfirm" :virtualList="virtualList"></order-list>
</z-paging>
</view>
</template>
<script>
import TabBox from '@/pages/order/worker/components/tabBox.vue';
import OrderList from '@/pages/order/worker/components/orderList.vue';
import OrderApi from '@/sheep/api/trade/order';
import { WxaSubscribeTemplate } from '@/sheep/util/const';
import sheep from '@/sheep';
import {
formatWorkerOrderStatus,
handleWorkerOrderButtons,
fen2yuan,
} from '@/sheep/hooks/useGoods';
export default {
components: {
TabBox,
OrderList,
},
props: {
title: {
type: String,
default: '接单中心',
},
},
data() {
return {
// 虚拟列表数组,通过@virtualListChange监听获得最新数组
virtualList: [],
scrollTop: 0,
paddingTop: 0,
paddingBottom: 0,
height: 0,
tabList: [{
name: '全部',
}, {
name: '待接单',
value: 10,
}, {
name: '服务中',
value: 20,
}, {
name: '已完成',
value: 30,
}],
currentIndex: 0,
}
},
methods: {
scroll(e) {
this.scrollTop = e.detail.scrollTop;
},
// 监听虚拟列表数组改变并赋值给virtualList进行重新渲染
virtualListChange(vList) {
this.virtualList = vList;
},
queryList(pageNo, pageSize) {
// 组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用
// 这里的pageNo和pageSize会自动计算好直接传给服务器即可
// 模拟请求服务器获取分页数据,请替换成自己的网络请求
const params = {
pageNo: pageNo,
pageSize: pageSize,
status: this.tabList[this.currentIndex].value,
//commentStatus: this.tabList[this.currentIndex].value === 30 ? false : null,
}
OrderApi.getWorkerOrderPage(params).then(res => {
// 将请求的结果数组传递给z-paging
res.data.list.forEach((order) => handleWorkerOrderButtons(order));
res.data.list.forEach((order) => formatWorkerOrderStatus(order));
res.data.list.forEach((order) => order.brokeragePrice = fen2yuan(order.brokeragePrice));
this.$refs.paging.complete(res.data.list);
}).catch(res => {
// 如果请求失败写this.$refs.paging.complete(false);
// 注意每次都需要在catch中写这句话很麻烦z-paging提供了方案可以全局统一处理
// 在底层的网络请求抛出异常时写uni.$emit('z-paging-error-emit');即可
this.$refs.paging.complete(false);
})
},
tabChange(e) {
this.currentIndex = e;
this.$refs.paging.reload();
},
// 取消订单
async onCancel(orderId) {
var that = this;
uni.showModal({
title: '提示',
content: '确定要取消订单吗?',
success: async function (res) {
if (!res.confirm) {
return;
}
const { code } = await OrderApi.cancelOrder(orderId);
if (code === 0) {
that.$refs.paging.reload();
}
},
});
},
// 开始接单
async onOrderConfirm(order) {
var that = this;
uni.showModal({
title: '是否开始接单',
content: '请确认已经联系到老板',
success: async function (res) {
if (!res.confirm) {
return;
}
// 正常的确认收货流程
const { code } = await OrderApi.deliveryOrder(order.id);
if (code === 0) {
that.$refs.paging.reload();
}
},
});
},
// 确认收货
async onConfirm(order) {
// #ifdef MP
// 订阅只能由用户主动触发,只能包一层 showModal 诱导用户点击
this.subscribeMessage();
// #endif
var that = this;
uni.showModal({
title: '确定要结束服务么?',
content: '请确认经过老板同意',
success: async function (res) {
if (!res.confirm) {
return;
}
// 正常的确认收货流程
const { code } = await OrderApi.receiveOrder(order.id);
if (code === 0) {
that.$refs.paging.reload();
}
},
});
},
subscribeMessage() {
const event = [WxaSubscribeTemplate.CLERK_ORDER];
event.push(WxaSubscribeTemplate.REWARD_SUCCESS);
sheep.$platform.useProvider('wechat').subscribeMessage(event, () => {
// 订阅后记录一下订阅状态
uni.removeStorageSync(WxaSubscribeTemplate.CLERK_ORDER);
uni.setStorageSync(WxaSubscribeTemplate.CLERK_ORDER, '已订阅');
});
},
}
}
</script>
<style lang="scss" scoped>
</style>