123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <!-- 订单列表 -->
- <template>
- <s-layout :title="t('order.my_orders')">
- <su-sticky bgColor="#fff">
- <su-tabs :list="tabMaps" :scrollable="false" @change="onTabsChange" :current="state.currentTab" :badge="true"/>
- </su-sticky>
- <s-empty v-if="state.pagination.total === 0" icon="/static/order-empty.png" :text="t('order.no_orders')" />
- <view v-if="state.pagination.total > 0">
- <view class="bg-white order-list-card-box ss-r-10 ss-m-t-14 ss-m-20" v-for="(order,index) in state.pagination.list"
- :key="order.id" @tap="onOrderDetail(order.id)">
- <view class="order-card-header ss-flex ss-col-center ss-row-between ss-p-x-20">
- <view class="order-no">{{ t('order.order_number') }}:{{ order.no }}</view>
- <view class="order-state ss-font-26" :class="formatOrderColor(order)">
-
- {{ formatOrderStatus(order) }}
- </view>
- </view>
- <!-- {{order.deliveryType}} -->
- <view class="border-bottom" v-for="item in order.items" :key="item.id">
-
- <s-goods-item :img="item.picUrl" :title="item.spuName"
- :skuText="item.properties.map((property) => property.valueName).join(' ')" :price="item.spuPayType === 2? item.highPrecisionPrice: item.price"
- :num="item.count" :virtualPirce="item.spuPayType === 2"
- />
- </view>
- <view class="pay-box ss-m-t-30 ss-flex ss-row-right ss-p-r-20">
- <view class="ss-flex ss-col-center">
- <view class="discounts-title pay-color"> {{ t('order.total_items',{count:order.productCount})}} ,</view>
- <view class="discounts-money pay-color">
- {{ t('order.total_amount') }}:¥{{ fen2yuan(order.payPrice) }}
- </view>
- </view>
- </view>
-
- <view class="order-card-footer ss-flex ss-col-center ss-p-x-20"
- :class="order.buttons.length > 3 ? 'ss-row-between' : 'ss-row-right'">
- <view class="ss-flex ss-col-center">
- <button v-if="order.buttons.includes('combination')" class="tool-btn ss-reset-button"
- @tap.stop="onOrderGroupon(order)">
- {{ t('order.group_details') }}
- </button>
- <button v-if="order.buttons.length === 0" class="tool-btn ss-reset-button"
- @tap.stop="onOrderDetail(order.id)">
- {{ t('order.view_details') }}
- </button>
- <button v-if="order.buttons.includes('express')" class="tool-btn ss-reset-button"
- @tap.stop="onExpress(order.id)">
- {{ t('order.view_logistics') }}
- </button>
- <button v-if="order.buttons.includes('confirm')" class="tool-btn ss-reset-button"
- @tap.stop="onConfirm(order)">
- {{ t('order.confirm_receipt') }}
- </button>
-
- <button v-if="order.buttons.includes('cancel')" class="tool-btn ss-reset-button"
- @tap.stop="onCancel(order.id)">
- {{ t('order.cancel_order') }}
- </button>
- <button v-if="order.buttons.includes('comment')" class="tool-btn ss-reset-button"
- @tap.stop="onComment(order.id)">
- {{ t('order.review_order') }}
- </button>
- <button v-if="order.buttons.includes('delete')" class="delete-btn ss-reset-button"
- @tap.stop="onDelete(order.id)">
- {{ t('order.delete_order') }}
- </button>
-
- <button v-if="order.buttons.includes('pay')"
- class="tool-btn ss-reset-button ui-BG-Main-Gradient" @tap.stop="onPay(order.payOrderId)">
- {{ t('order.continue_payment') }}
- </button>
- </view>
- </view>
- </view>
- </view>
- <!-- 加载更多 -->
- <uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{
- contentdown: '上拉加载更多',
- }" @tap="loadmore" />
- </s-layout>
- </template>
- <script setup>
- import {
- reactive,
- computed,
- watchEffect,
- } from 'vue';
- import {
- onLoad,
- onShow,
- onReachBottom,
- onPullDownRefresh
- } from '@dcloudio/uni-app';
- import {
- fen2yuan,
- formatOrderColor,
- formatOrderStatus,
- handleOrderButtons,
- } from '@/sheep/hooks/useGoods';
- import sheep from '@/sheep';
- import _ from 'lodash';
- import {
- isEmpty
- } from 'lodash';
- import OrderApi from '@/sheep/api/trade/order';
- import {
- showWalletModal,
- colseWalletModal
- } from '@/sheep/hooks/useModal';
- import { t } from '@/locale'
- const pagination = {
- list: [],
- current_page: 1,
- total: 1,
- last_page: 1,
- };
- // 数据
- const state = reactive({
- currentTab: 0, // 选中的 tabMaps 下标
- pagination: {
- list: [],
- current_page: 1,
- total: 1,
- last_page: 1,
- },
- loadStatus: ''
- });
- const tabMaps = reactive([
- {
- name: t('order.all_orders'),
- num: 0,
- isShow:false
- },
- {
- name: t('order.pending_payment'),
- value: 0,
- num: 0,
- isShow:true
- },
- {
- name: t('order.pending_shipment'),
- value: 10,
- num:0,
- isShow:true
- },
- {
- name: t('order.pending_receipt'),
- value: 20,
- num: 0,
- isShow:true
- },
- {
- name: t('order.pending_review'),
- value: 30,
- num: 0,
- isShow:true
- },
- ]);
- // 切换选项卡
- function onTabsChange(e) {
- if (state.currentTab === e.index) {
- return;
- }
- // 重头加载代码
- state.pagination.list = []
- state.pagination.current_page = 1
- state.pagination.total = 1
- state.pagination.last_page = 1
- state.currentTab = e.index;
- getOrderList();
- }
- // 订单详情
- function onOrderDetail(id) {
- sheep.$router.go('/pages/order/detail', {
- id,
- });
- }
- // 分享拼团 TODO 非繁人:待测试
- function onOrderGroupon(order) {
- sheep.$router.go('/pages/activity/groupon/detail', {
- id: order.ext.groupon_id,
- });
- }
-
- // 继续支付
- function onPay(id) {
- sheep.$router.go('/pages/pay/index', {
- id: id,
- type:1,
- openType:2
- });
- }
- // 评价
- function onComment(id) {
- sheep.$router.go('/pages/goods/comment/add', {
- id,
- });
- }
- // 确认收货
- async function onConfirm(order, ignore = false) {
- // 需开启确认收货组件
- // todo: 非繁人:需要后续接入微信收货组件
- // 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
- // 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
- let isOpenBusinessView = true;
- uni.showModal({
- title: t('setting.prompt'),
- content: t('order.confirm_receipt_question'),
- success: async function(res) {
- if (res.confirm) {
- if (
- sheep.$platform.name === 'WechatMiniProgram' &&
- !isEmpty(order.wechat_extra_data) &&
- isOpenBusinessView &&
- !ignore
- ) {
- mpConfirm(order);
- return;
- }
-
- // 正常的确认收货流程
- const {
- code
- } = await OrderApi.receiveOrder(order.id);
- if (code === 0) {
- state.pagination = pagination;
- await getOrderList();
- }
- }
- },
- });
-
-
- }
- // #ifdef MP-WEIXIN
- // 小程序确认收货组件
- function mpConfirm(order) {
- if (!wx.openBusinessView) {
- sheep.$helper.toast(t('order.upgrade_wechat'));
- return;
- }
- wx.openBusinessView({
- businessType: 'weappOrderConfirm',
- extraData: {
- merchant_id: '1481069012',
- merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
- transaction_id: order.wechat_extra_data.transaction_id,
- },
- success(response) {
- console.log('success:', response);
- if (response.errMsg === 'openBusinessView:ok') {
- if (response.extraData.status === 'success') {
- onConfirm(order, true);
- }
- }
- },
- fail(error) {
- console.log('error:', error);
- },
- complete(result) {
- console.log('result:', result);
- },
- });
- }
- // #endif
- // 查看物流
- async function onExpress(id) {
- sheep.$router.go('/pages/order/express/log', {
- id,
- });
- }
- // 取消订单
- async function onCancel(orderId) {
- uni.showModal({
- title:t('setting.prompt'),
- content: t('order.confirm_cancel_order'),
- success: async function(res) {
- if (!res.confirm) {
- return;
- }
- const {
- code
- } = await OrderApi.cancelOrder(orderId);
- if (code === 0) {
- // 修改数据的状态
- let index = state.pagination.list.findIndex((order) => order.id === orderId);
- const orderInfo = state.pagination.list[index];
- orderInfo.status = 40;
- handleOrderButtons(orderInfo);
- state.pagination = pagination;
- await getOrderList()
- }
- },
- });
- }
- // 删除订单
- function onDelete(orderId) {
- uni.showModal({
- title: t('setting.prompt'),
- content:t('order.confirm_delete_order'),
- success: async function(res) {
- if (res.confirm) {
- const {
- code
- } = await OrderApi.deleteOrder(orderId);
- if (code === 0) {
- // 删除数据
- let index = state.pagination.list.findIndex((order) => order.id === orderId);
- state.pagination.list.splice(index, 1);
- await getOrderList()
- }
- }
- },
- });
- }
- async function getOrderCount(){
- let { data } = await OrderApi.getOrderCount()
- tabMaps[0].num = data.allCount
- tabMaps[1].num = data.unpaidCount
- tabMaps[2].num = data.undeliveredCount
- tabMaps[3].num = data.deliveredCount
- tabMaps[4].num = data.uncommentedCount
- }
- // 获取订单列表
- async function getOrderList(page = 1, list_rows = 5) {
- state.loadStatus = 'loading';
- let {
- code,
- data
- } = await OrderApi.getOrderPage({
- pageNo: page,
- pageSize: list_rows,
- status: tabMaps[state.currentTab].value,
- commentStatus: tabMaps[state.currentTab].value === 30 ? false : null
- });
- getOrderCount()
-
- if (code !== 0) {
- return;
- }
- let orderList = _.concat(state.pagination.list, data.list);
- data.list.forEach(order => handleOrderButtons(order));
- state.pagination.list = orderList
- state.pagination.total = data.total;
- state.pagination.last_page = Math.ceil(data.total / 5)
- if (state.pagination.current_page < state.pagination.last_page) {
- state.loadStatus = 'more';
- } else {
- state.loadStatus = 'noMore';
- }
- }
- onLoad(async (options) => {
- // 支付成功回到订单列表,佣金弹窗
- if(options.points !== undefined || options.scoialStatus !== undefined){
- showWalletModal({points: options.points , socialStatus: options.socialStatus})
- }
- if (options.type) {
- state.currentTab = options.type;
- }
- await getOrderList();
-
- });
- onShow(async () => {
- // 如果loadStatus == loading时 证明已经有加载了
- if(state.loadStatus == 'loading'){
- return
- }
- state.pagination.list = []
- state.pagination.current_page = 1
- state.pagination.total = 1
- state.pagination.last_page = 1
- await getOrderList();
- });
- // 加载更多
- function loadMore() {
- if (state.loadStatus !== 'noMore') {
- state.pagination.current_page += 1
- getOrderList(state.pagination.current_page);
- }
- }
- // 上拉加载更多
- onReachBottom(() => {
- loadMore();
- });
- // 下拉刷新
- onPullDownRefresh(() => {
-
- state.pagination.list = []
- state.pagination.current_page = 1
- state.pagination.total = 1
- state.pagination.last_page = 1
- getOrderList();
- setTimeout(function() {
- uni.stopPullDownRefresh();
- }, 800);
- });
- </script>
- <style lang="scss" scoped>
- .score-img {
- width: 36rpx;
- height: 36rpx;
- margin: 0 4rpx;
- }
- .tool-btn {
- // width: 160rpx;
- padding:0 10rpx;
- height: 60rpx;
- background: #f6f6f6;
- font-size: 26rpx;
- border-radius: 30rpx;
- margin-right: 10rpx;
- &:last-of-type {
- margin-right: 0;
- }
- }
- .delete-btn {
- width: 160rpx;
- height: 56rpx;
- color: #ff3000;
- background: #fee;
- border-radius: 28rpx;
- font-size: 26rpx;
- margin-right: 10rpx;
- line-height: normal;
- &:last-of-type {
- margin-right: 0;
- }
- }
- .apply-btn {
- width: 140rpx;
- height: 50rpx;
- border-radius: 25rpx;
- font-size: 24rpx;
- border: 2rpx solid #dcdcdc;
- line-height: normal;
- margin-left: 16rpx;
- }
- .swiper-box {
- flex: 1;
- .swiper-item {
- height: 100%;
- width: 100%;
- }
- }
- .order-list-card-box {
- .order-card-header {
- height: 80rpx;
- .order-no {
- font-size: 26rpx;
- font-weight: 500;
- }
- .order-state {}
- }
- .pay-box {
- .discounts-title {
- font-size: 24rpx;
- line-height: normal;
- color: #999999;
- }
- .discounts-money {
- font-size: 24rpx;
- line-height: normal;
- color: #999;
- font-family: OPPOSANS;
- }
- .pay-color {
- color: #333;
- }
- }
- .order-card-footer {
- height: 100rpx;
- .more-item-box {
- padding: 20rpx;
- .more-item {
- height: 60rpx;
- .title {
- font-size: 26rpx;
- }
- }
- }
- .more-btn {
- color: $dark-9;
- font-size: 24rpx;
- }
- .content {
- width: 154rpx;
- color: #333333;
- font-size: 26rpx;
- font-weight: 500;
- }
- }
- }
- :deep(.uni-tooltip-popup) {
- background: var(--ui-BG);
- }
- .warning-color {
- color: #faad14;
- }
- .danger-color {
- color: #ff3000;
- }
- .success-color {
- color: #52c41a;
- }
- .info-color {
- color: #999999;
- }
- </style>
|