123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- <template>
- <s-layout :title="t('confirm.confirm_order')">
- <!-- TODO:这个判断先删除 v-if="state.orderInfo.need_address === 1" -->
- <view class="bg-white address-box ss-m-b-14 ss-r-b-10" @tap="onSelectAddress">
- <s-address-item :item="state.addressInfo" :spuType="state.orderPayload.spuType" :hasBorderBottom="false">
- <view class="ss-rest-button">
- <text class="_icon-forward" />
- </view>
- </s-address-item>
- </view>
- <!-- 商品信息 -->
- <!-- {{shopsByNames}} -->
- <view class="order-card-box ss-m-b-14" v-for="(items, name) in shopsByNames" :key="name">
- <view class="title-text ss-p-x-20 ss-p-t-20">
- {{name}}
- </view>
- <s-goods-item v-for="item in items.items" :key="item?.skuId" :img="item?.picUrl" :title="item?.spuName"
- :skuText="item?.properties?.map((property) => property.valueName).join(' ')"
- :price="item.highPrecisionPrice ? item?.highPrecisionPrice :item?.price " :num="item?.count"
- :virtualPirce="item.highPrecisionPrice ? true :false " />
- <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10">
- <view class="item-title">{{ t('confirm.shipping_fee') }}</view>
- <view class="ss-flex ss-col-center">
- {{items.price.deliveryPrice?"¥"+fen2yuan(items.price.deliveryPrice):t('confirm.free_shipping')}}
- </view>
- </view>
- <!-- 暂不做开发票 -->
- <!-- <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10">
- <view class="item-title">开具发票</view>
- <view class="ss-flex ss-col-center">
- <text class="item-value" :class="state.couponInfo.length > 0 ? 'text-red' : 'text-disabled'">
- {{
- state.couponInfo.length > 0 ? state.couponInfo.length + ' 张可用' : '不开具发票'
- }}
- </text>
- <text class="_icon-forward item-icon" />
- </view>
- </view> -->
- <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10">
- <view class="item-title">{{ t('confirm.order_note') }}</view>
- <view class="ss-flex ss-col-center">
- <uni-easyinput maxlength="20" :placeholder="t('confirm.communication_advice')" v-model="items.remark" :inputBorder="false"
- :clearable="false" />
- </view>
- </view>
- <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10"
- v-if="state.orderPayload.spuType == 0">
- <view class="item-title">{{ t('confirm.quantity') }}</view>
- <view class="ss-flex ss-col-center">
- {{totalItemCount}}
- </view>
- </view>
- <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10" v-else>
- <view class="item-title">{{ t('common.total') }}</view>
- <view class="ss-flex ss-col-center">
- <image src="@/static/icon/points.png" v-if="state.orderPayload.spuPayType == 2"
- style="width:30rpx;height:30rpx"></image>
- <text v-else>¥</text>
- {{fen2yuan(items.price.payPrice)}}
- </view>
- </view>
- </view>
- <!-- 价格信息 -->
- <view class="bg-white total-card-box ss-p-20 ss-m-b-14 ss-r-10">
- <view class="title-text">
- {{ t('confirm.price_details') }}
- </view>
- <view class="total-box-content border-bottom">
- <view class="order-item ss-flex ss-col-center ss-row-between">
- <view class="item-title">{{ t('confirm.total_price') }} {{ t('confirm.total_items',{count:totalItemCount}) }}</view>
- <view class="ss-flex ss-col-center">
- <text class="item-value ss-m-r-24">
- <image src="@/static/icon/points.png" v-if="state.orderPayload.spuPayType == 2"
- style="width:30rpx;height:30rpx"></image>
- <text v-else>¥</text>
- <text
- v-if="state.orderPayload.highPrecision">{{ fen2yuan6(state.orderInfo.price.virtualTotalPrice) }}
- </text>
- <text v-else>
- {{ fen2yuan(state.orderInfo.price.totalPrice) }}
- </text>
- </text>
- </view>
- </view>
- <!-- TODO 非繁人:接入佣金 -->
- <view class="order-item ss-flex ss-col-center ss-row-between">
- <view class="item-title">{{ t('confirm.shipping_fee') }}</view>
- <view class="ss-flex ss-col-center">
- <text class="item-value ss-m-r-24">
- <image src="@/static/icon/points.png" v-if="state.orderPayload.spuPayType == 2"
- style="width:30rpx;height:30rpx"></image>
- <text v-else>¥</text>
- {{ fen2yuan(state.orderInfo.price.deliveryPrice) }}
- </text>
- </view>
- </view>
- <view class="order-item ss-flex ss-col-center ss-row-between" v-if="state.orderPayload.spuPayType != 2">
- <view class="item-title">{{ t('confirm.commission_deduction') }}</view>
- <view class="ss-flex ss-col-center" @tap="state.showPoints = true">
- <!-- <text class="item-value text-red">
-
- </text> -->
- <text class="item-value" :class="state.usedPoint > 0 ? 'text-red' : 'text-disabled'">
- {{ state.usedPoint > 0 ? t('confirm.deduction',{count:state.usedPoint}) : t('confirm.no_commission') }}
- </text>
- <text class="_icon-forward item-icon" />
- </view>
- </view>
- <view class="order-item ss-flex ss-col-center ss-row-between" v-if="state.orderPayload.spuPayType != 2">
- <view class="item-title">{{ t('confirm.consumption_point_deduction') }}</view>
- <view class="ss-flex ss-col-center" @tap="state.showConsumptionPoints = true">
- <!-- <text class="item-value text-red">
- </text> -->
-
- <text class="item-value" :class="state.usedConsumptionPoints > 0 ? 'text-red' : 'text-disabled'">
- {{ state.usedConsumptionPoints > 0 ? t('confirm.deduction',{count:state.usedConsumptionPoints}) : t('confirm.no_consumption_points') }}
- </text>
- <text class="_icon-forward item-icon" />
- </view>
- </view>
- <!-- 优惠劵:只有 type = 0 普通订单(非拼团、秒杀、砍价),才可以使用优惠劵 -->
- <!-- 暂时隐藏优惠卷 -->
- <!-- <view
- class="order-item ss-flex ss-col-center ss-row-between"
- v-if="state.orderInfo.type === 0"
- >
- <view class="item-title">优惠券</view>
- <view class="ss-flex ss-col-center" @tap="state.showCoupon = true">
- <text class="item-value text-red" v-if="state.orderPayload.couponId > 0">
- -¥{{ fen2yuan(state.orderInfo.price.couponPrice) }}
- </text>
- <text
- class="item-value"
- :class="state.couponInfo.length > 0 ? 'text-red' : 'text-disabled'"
- v-else
- >
- {{
- state.couponInfo.length > 0 ? state.couponInfo.length + ' 张可用' : '暂无可用优惠券'
- }}
- </text>
- <text class="_icon-forward item-icon" />
- </view>
- </view> -->
- <!-- <view
- class="order-item ss-flex ss-col-center ss-row-between"
- v-if="state.orderInfo.price.discountPrice > 0"
- >
- <view class="item-title">活动优惠</view>
- <view class="ss-flex ss-col-center">
- @tap="state.showDiscount = true" TODO 非繁人:后续要把优惠信息打进去
- <text class="item-value text-red">
- -¥{{ fen2yuan(state.orderInfo.price.discountPrice) }}
- </text>
- <text class="_icon-forward item-icon" />
- </view>
- </view> -->
- </view>
- <view class="total-box-footer ss-font-28 ss-flex ss-row-right ss-col-center ss-m-r-28">
- <view class="total-num ss-m-r-20">
- {{ t('confirm.total_items_count',{count:totalItemCount}) }}
- </view>
- <view>{{ t('common.total') }}:</view>
- <view class="total-num text-red ss-flex">
- <image src="@/static/icon/points.png" class='ss-m-r-10' v-if="state.orderPayload.spuPayType == 2"
- style="width:30rpx;height:30rpx"></image>
- <text v-else>¥</text>
- <text
- v-if="state.orderPayload.highPrecision">{{ fen2yuan6(state.orderInfo.price.virtualTotalPrice) }}
- </text>
- <text
- v-else-if="state.orderPayload.spuPayType == 2">{{ fen2yuan(state.orderInfo.price.payPrice) - 0.01 }}
- </text>
- <text v-else>{{ fen2yuan(state.orderInfo.price.payPrice) }} </text>
- </view>
- </view>
- </view>
- <!-- 佣金-->
- <s-points-pop v-model="state.couponInfo" :currentMemberPoints="state.currentMemberPoints"
- :currentTotalPrice="state.currentTotalPrice" :currentDeliveryPrice="state.currentDeliveryPrice"
- :show="state.showPoints" @confirm="onInputPoints" @close="state.showPoints = false" />
-
- <!-- 消费分 -->
- <s-consumptionPoints-pop v-model="state.couponInfo" :currentMemberConsumptionPoints="state.currentMemberConsumptionPoints"
- :currentTotalPrice="state.currentTotalPrice" :currentDeliveryPrice="state.currentDeliveryPrice"
- :show="state.showConsumptionPoints" @confirm="onInputConsumptionPoints" @close="state.showConsumptionPoints = false" />
-
- <!-- 满额折扣弹框 TODO 非繁人:后续要把优惠信息打进去 -->
- <!-- <s-discount-list
- v-model="state.orderInfo"
- :show="state.showDiscount"
- @close="state.showDiscount = false"
- /> -->
-
- <!-- 底部 -->
- <su-fixed bottom :opacity="false" bg="bg-white" placeholder :noFixed="false" :index="200">
- <view class="footer-box border-top ss-flex ss-row-between ss-p-x-20 ss-col-center">
- <view class="total-box-footer ss-flex ss-col-center">
- <view v-if="state.orderPayload.highPrecision">
- <image src="@/static/icon/points.png" v-if="state.orderPayload.spuPayType == 2"
- style="width:30rpx;height:30rpx"></image>
- {{ fen2yuan6(state.orderInfo.price.virtualPayPrice) - 0.01 }}
- ¥0.01
- </view>
- <view class="total-num ss-font-30 text-red " v-else-if="state.orderPayload.spuPayType == 2">
- <image src="@/static/icon/points.png" v-if="state.orderPayload.spuPayType == 2"
- style="width:30rpx;height:30rpx"></image>
- {{ state.usedPoint }}
- ¥0.01
- </view>
- <view class="total-num ss-font-30 text-red" v-else>
- ¥{{ finalPrice }}
- </view>
- </view>
- <button class="ss-reset-button ui-BG-Main-Gradient ss-r-40 submit-btn ui-Shadow-Main" @tap="onConfirm" v-if="!Android || (Android && finalPrice == 0)">
- {{ t('confirm.submit_order') }}
- </button>
- </view>
- </su-fixed>
- </s-layout>
- </template>
- <script setup>
- import {
- reactive,
- computed
- } from 'vue';
- import {
- onLoad
- } from '@dcloudio/uni-app';
- import sheep from '@/sheep';
- import {
- isEmpty
- } from 'lodash';
- import OrderApi from '@/sheep/api/trade/order';
- import CouponApi from '@/sheep/api/promotion/coupon';
- import {
- fen2yuan,
- points2point,
- fen2yuan6
- } from '@/sheep/hooks/useGoods';
- import { t } from '@/locale'
- import {
- isAndroid,
- } from '@/sheep/hooks/useApp'
- const Android = isAndroid();
- const state = reactive({
- orderPayload: {},
- orderInfo: {
- items: [], // 商品项列表
- price: {}, // 价格信息
- },
- addressInfo: {}, // 选择的收货地址
- showPoints: false, // 是否佣金抵扣
- showConsumptionPoints: false, // 是否消费分抵扣
- couponInfo: [], // 优惠劵列表
- showDiscount: false, // 是否展示营销活动
- currentMemberPoints: 0, //用户当前可用佣金
- currentMemberConsumptionPoints: 0, //用户当前可用消费分
- usedPoint: 0, //用户使用的佣金
- usedConsumptionPoints:0,//用户使用的消费分
- currentTotalPrice: 0, //当前的整个订单的总价格
- currentDeliveryPrice: 0 // 当前订单的总运费
- });
- const finalPrice = computed(() => {
- return fen2yuan(state.orderInfo.price.payPrice - (100 * state.usedPoint) - (100 * state.usedConsumptionPoints));
- });
- // 返回来的数据根据店铺名过滤 TODO
- const shopsByNames = computed(() => {
- // console.log(state.orderInfo.shopRespVOMap)
- const shops = {};
- try {
- Object.keys(state.orderInfo.shopRespVOMap).forEach(shopId => {
- const shopName = state.orderInfo.shopNameMap[shopId];
- if (shopName) {
- shops[shopName] = state.orderInfo.shopRespVOMap[shopId];
- shops[shopName].remark = ""
- shops[shopName].shopId = shopId
- }
- });
- } catch (e) {
- // console.log(e)
- }
- return shops;
- });
- // 计算所有商品的总数
- const totalItemCount = computed(() => {
- let totalCount = 0;
- Object.values(shopsByNames.value).forEach(shop => {
- shop.items.forEach(item => {
- totalCount += item.count;
- });
- });
- return totalCount;
- });
- // 选择地址
- function onSelectAddress() {
- uni.$once('SELECT_ADDRESS', (e) => {
- changeConsignee(e.addressInfo);
- });
- // console.log(state.orderPayload.spuType)
- // 如果是虚拟商品 进入选虚拟地址
- if (state.orderPayload.spuType) {
- sheep.$router.go('/pages/user/address/list');
- } else {
- sheep.$router.go('/pages/user/dummyAddress/list');
- }
- }
- // 更改收货人地址&计算订单信息
- async function changeConsignee(addressInfo = {}) {
- if (!isEmpty(addressInfo)) {
- state.addressInfo = addressInfo;
- }
- await getOrderInfo();
- }
- // 使用佣金
- async function onInputPoints(points) {
- if (points == undefined) {
- points = 0
- }
- const payprice = state.currentTotalPrice
- console.log(points,payprice)
- // state.orderInfo.price.payPrice = (payprice - points) * 100
- state.usedPoint = points
- // 与消费分互斥
- state.usedConsumptionPoints = 0
- state.showPoints = false;
- }
- // 使用消费分
- function onInputConsumptionPoints(points) {
- if (points == undefined) {
- points = 0
- }
- const payprice = state.currentTotalPrice
- // state.orderInfo.price.payPrice = (payprice - points) * 100
- state.usedConsumptionPoints = points
- // 与佣金互斥
- state.usedPoint = 0
- state.showConsumptionPoints = false;
- }
- // 提交订单
- function onConfirm() {
- if (!state.addressInfo.id) {
- sheep.$helper.toast(t('confirm.select_shipping_address'))
- return;
- }
- // 如果使用的佣金为0 那就不需要提示
- if (parseFloat(state.usedPoint) && parseFloat(state.usedPoint) > parseFloat(state.currentMemberPoints)) {
- sheep.$helper.toast(t('confirm.insufficient_commission'));
- return;
- }
- if (parseFloat(state.usedConsumptionPoints) && parseFloat(state.usedConsumptionPoints) > parseFloat(state.currentMemberConsumptionPoints)) {
- sheep.$helper.toast(t('confirm.insufficient_consumption_points'));
- return;
- }
- if (parseFloat(state.usedPoint) && parseFloat(state.usedConsumptionPoints) ) {
- sheep.$helper.toast(t('confirm.commission_points_no_mix'));
- return;
- }
- submitOrder();
- }
- // 截取小数 不保留四舍五入
- /**
- * @param number 数字
- * @param decimals 小数点位数
- *
- */
- function customRound(number, decimals) {
- let factor = Math.pow(10, decimals);
- let tempNumber = Math.floor(number * factor) / factor;
- return tempNumber.toFixed(decimals);
- }
-
- // 创建订单&跳转
- async function submitOrder() {
-
- // 处理每个店铺的留言 以{店铺id:留言}的形式返回
- const shops = shopsByNames.value;
- const shopRemarks = {};
- Object.keys(shops).forEach(shopName => {
- const shop = shops[shopName];
- shopRemarks[shop.shopId] = shop.remark;
- });
- // 如果不是高精度商品 就走原来的程序,如果是高精度的商品,就拿到高精度返回的商品总价 / 100 然后保留四位小数再干掉两位,实现佣金可以刚好大于当前佣金的0.01
- const usedPoint = state.orderPayload.highPrecision ? customRound((state.orderInfo.price.virtualPayPrice / 100 ), 2): state.usedPoint;
-
- const {
- code,
- data
- } = await OrderApi.createOrder({
- items: state.orderPayload.items,
- couponId: state.orderPayload.couponId,
- addressId: state.addressInfo.id,
- deliveryType: state.orderPayload.spuType == 1 ? 1 : 3, // TODO 非繁人:需要支持【门店自提】
- pointStatus: false, // TODO 非繁人:需要支持【佣金选择】
- combinationActivityId: state.orderPayload.combinationActivityId,
- combinationHeadId: state.orderPayload.combinationHeadId,
- seckillActivityId: state.orderPayload.seckillActivityId,
- payIntegral: usedPoint,
- payConsumptionPoints:state.usedConsumptionPoints,
- shopRemarks: shopRemarks
- });
- if (code !== 0) {
- return;
- }
- // 更新购物车列表,如果来自购物车
- if (state.orderPayload.items[0].cartId > 0) {
- sheep.$store('cart').getList();
- }
- // 跳转到支付页面
- sheep.$router.redirect('/pages/pay/index', {
- id: data.payOrderId,
- type:1
- });
- }
- // 检查库存 & 计算订单价格
- async function getOrderInfo() {
- // 每次查询设置订单之前 看有没有评论 如果有评论就存到shopRemarks
- const shops = shopsByNames.value
- let shopRemarks = {};
- if (Object.keys(shops).length !== 0) {
- Object.keys(shops).forEach(shopName => {
- const shop = shops[shopName];
- shopRemarks[shopName] = shop.remark;
- });
- }
- const {
- data,
- code
- } = await OrderApi.settlementOrder({
- items: state.orderPayload.items,
- couponId: state.orderPayload.couponId,
- addressId: state.addressInfo.id,
- deliveryType: state.orderPayload.spuType == 1 ? 1 : 3, // TODO 非繁人:需要支持【门店自提】
- pointStatus: false, // TODO 非繁人:需要支持【佣金选择】
- combinationActivityId: state.orderPayload.combinationActivityId,
- combinationHeadId: state.orderPayload.combinationHeadId,
- seckillActivityId: state.orderPayload.seckillActivityId,
- usedPoint: state.usedPoint,
- addressType: state.orderPayload.spuType == 1 ? 1 : 2 //如果是虚拟产品
- });
- if (code !== 0) {
- return;
- }
- state.orderInfo = data;
- // 如果shopRemarks有评论的话 就放回shopsByNames
- if (Object.keys(shopRemarks).length !== 0) {
- Object.keys(shopRemarks).forEach(shopName => {
- shopsByNames.value[shopName].remark = shopRemarks[shopName]
- });
- }
- // 设置收货地址
- if (state.orderInfo.address) {
- state.addressInfo = state.orderInfo.address;
- }
- // console.log(state.orderInfo)/
- state.currentMemberPoints = state.orderInfo.currentQuota > 0 ? points2point(state.orderInfo.currentQuota) : 0
- state.currentMemberConsumptionPoints = state.orderInfo.consumePoints > 0 ? points2point(state.orderInfo.consumePoints) : 0
-
- state.currentTotalPrice = fen2yuan(state.orderInfo.price.payPrice)
- state.currentDeliveryPrice = fen2yuan(state.orderInfo.price.deliveryPrice)
- // console.log("父",state.currentTotalPrice)
- if (state.orderPayload.spuPayType == 2) {
- state.usedPoint = state.currentTotalPrice - 0.01
- // console.log(state.spuType)
- }
- }
- // 获取可用优惠券
- // async function getCoupons() {
- // const {
- // code,
- // data
- // } = await CouponApi.getMatchCouponList(
- // state.orderInfo.price.payPrice,
- // state.orderInfo.items.map((item) => item.spuId),
- // state.orderPayload.items.map((item) => item.skuId),
- // state.orderPayload.items.map((item) => item.categoryId),
- // );
- // if (code === 0) {
- // state.couponInfo = data;
- // }
- // }
- onLoad(async (options) => {
- if (!options.data) {
- sheep.$helper.toast('参数不正确,请检查!');
- return;
- }
- state.orderPayload = JSON.parse(options.data);
- // console.log(state.orderPayload)
- await getOrderInfo();
- });
- </script>
- <style lang="scss" scoped>
- :deep() {
- .uni-input-wrapper {
- width: 320rpx;
- }
- .uni-easyinput__content-input {
- font-size: 28rpx;
- height: 72rpx;
- text-align: right !important;
- padding-right: 0 !important;
- .uni-input-input {
- font-weight: 500;
- color: #333333;
- font-size: 26rpx;
- height: 32rpx;
- margin-top: 4rpx;
- }
- }
- .uni-easyinput__content {
- display: flex !important;
- align-items: center !important;
- justify-content: right !important;
- }
- }
- .order-card-box,
- .address-box,
- .total-card-box {
- background: white;
- margin: 20rpx;
- border-radius: 20rpx;
- }
- .title-text {
- font-size: 30rpx;
- font-weight: bold;
- line-height: 42rpx;
- }
- .score-img {
- width: 36rpx;
- height: 36rpx;
- margin: 0 4rpx;
- }
- .order-item {
- height: 80rpx;
- .item-title {
- font-size: 28rpx;
- font-weight: 400;
- }
- .item-value {
- font-size: 28rpx;
- font-weight: 500;
- font-family: OPPOSANS;
- }
- .text-disabled {
- color: #bbbbbb;
- }
- .item-icon {
- color: $dark-9;
- }
- .remark-input {
- text-align: right;
- }
- .item-placeholder {
- color: $dark-9;
- font-size: 26rpx;
- text-align: right;
- }
- }
- .total-box-footer {
- height: 90rpx;
- .total-num {
- color: #333333;
- font-family: OPPOSANS;
- }
- }
- .footer-box {
- height: 100rpx;
- .submit-btn {
- width: 230rpx;
- height: 70rpx;
- font-size: 28rpx;
- font-weight: 500;
- .goto-pay-text {
- line-height: 28rpx;
- }
- }
- .cancel-btn {
- width: 230rpx;
- height: 80rpx;
- font-size: 26rpx;
- background-color: #e5e5e5;
- color: $dark-9;
- }
- }
- .title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333333;
- }
- .subtitle {
- font-size: 28rpx;
- color: #999999;
- }
- .cicon-checkbox {
- font-size: 36rpx;
- color: var(--ui-BG-Main);
- }
- .cicon-box {
- font-size: 36rpx;
- color: #999999;
- }
- </style>
|