代码更新

This commit is contained in:
GaoHao
2025-03-03 09:44:11 +08:00
parent b4a0393d2d
commit fd0c452a76
55 changed files with 2263 additions and 2658 deletions

View File

@@ -1,17 +1,17 @@
<template>
<view class="u-p-l-30 u-p-r-30 u-p-t-30 u-font-28 ">
<up-sticky offset-top="0">
<my-tabs v-model="myQuan.types.sel" :list="myQuan.types.list"></my-tabs>
<my-tabs v-model="pageData.types.sel" :list="pageData.types.list"></my-tabs>
</up-sticky>
<view class="u-m-t-32">
<template v-if="myQuan.types.sel==0">
<template v-if="pageData.types.sel==0">
<view class="" @click="changeFullReductionCouponSel(item)"
v-for="(item,index) in myQuan.res.fullReductionCoupon" :class="{filtergray:!item.use}" :key="index">
v-for="(item,index) in pageData.fullReductionCoupon" :class="{filtergray:!item.use}" :key="index">
<view class="quan u-row-between u-flex u-col-center u-m-b-32 border-r-10 ">
<view class="no-use" v-if="!item.use">
<image class="img" src="/pagesOrder/static/image/no-use.svg" mode=""></image>
</view>
<view class="sel u-abso" v-if="item.id==myQuan.fullReductionCouponSel.id ">
<view class="sel u-abso" v-if="item.id == pageData.fullReductionCouponSel.id ">
<up-icon name="checkbox-mark" color="#fff"></up-icon>
</view>
<view class="u-p-t-32 u-p-b-32 u-p-l-24 u-p-r-24 left">
@@ -41,13 +41,13 @@
</view>
</view>
</view>
<template v-if="myQuan.res.fullReductionCoupon.length<=0&&myQuan.hasAjax">
<template v-if="pageData.fullReductionCoupon.length <= 0 && pageData.hasAjax">
<my-img-empty tips="暂无可用优惠券"></my-img-empty>
</template>
</template>
<template v-if="myQuan.types.sel==1">
<view class="" @click="changeProductCoupon(item)" v-for="(item,index) in myQuan.res.productCoupon"
<template v-if="pageData.types.sel==1">
<view class="" @click="changeProductCoupon(item)" v-for="(item,index) in pageData.productCoupon"
:class="{filtergray:!item.use}" :key="index">
<view class="quan goods u-row-between u-flex u-col-center u-m-b-32 border-r-10 u-relative">
<view class="no-use" v-if="!item.use">
@@ -74,9 +74,6 @@
</view>
</view>
<view class="right u-flex u-flex-col u-col-bottom u-row-center">
<!-- <view class="u-flex u-row-center w-full">
<view class="color-red font-bold u-m-b-24 ">{{item.discountAmount}}</view>
</view> -->
<view class="u-flex ">
<view class="use-btn" @click.stop="toEmitChooseQuan(item)">去使用</view>
</view>
@@ -84,7 +81,7 @@
</view>
</view>
<template v-if="myQuan.res.productCoupon.length<=0&&myQuan.hasAjax">
<template v-if="pageData.productCoupon.length <= 0 && pageData.hasAjax">
<my-img-empty tips="暂无可用优惠券"></my-img-empty>
</template>
</template>
@@ -133,31 +130,13 @@
</template>
<script setup>
import {
ref,
reactive,
watch,
computed,
onMounted
} from 'vue';
import { onLoad, onReady } from '@dcloudio/uni-app'
import { ref, reactive, watch, computed, onMounted } from 'vue';
import color from '@/commons/color.js'
import dayjs from 'dayjs';
import {
getSafeBottomHeight
} from '@/commons/utils/safe-bottom.js'
import { getSafeBottomHeight } from '@/commons/utils/safe-bottom.js'
import go from '@/commons/utils/go.js'
import {
onLoad,
onReady
} from '@dcloudio/uni-app'
import * as orderApi from '@/http/yskApi/order.js'
import {
$activateByOrderId
} from '@/http/yskApi/Instead.js'
import infoBox from '@/commons/utils/infoBox.js'
import {
queryAllShopUser
} from '@/http/yskApi/shop-user.js'
import {
returnNewGoodsList,
returnCoupCanUse,
@@ -165,6 +144,10 @@
returnProductCoupon,
returnCanUseFullReductionCoupon
} from '../quan_util.js'
import { getHistoryOrder } from '@/api/order.js'
import { shopUserDetail } from '@/api/shopUser.js'
import { getCouponList } from '@/api/coupon.js'
const modal = reactive({
title: '提示',
@@ -176,20 +159,116 @@
data: ''
})
const option = reactive({
orderId: '',
userId: '',
orderPrice: 0
})
const pageData = reactive({
order: null,
user: null,
types: {
list: ['满减券(单选)', '商品券(多选)'],
sel: 0
},
fullReductionCouponSel: {
id: ''
},
fullReductionCoupon: [],
productCoupon: [],
hasAjax: false
})
let canDikouGoodsArr = []
let safebottomHeight = ref(0)
onLoad((opt) => {
Object.assign(option, opt)
getQuan()
})
watch(() => pageData.types.sel, (newval) => {
if (newval == 0) {
pageData.fullReductionCoupon = returnCanUseFullReductionCoupon(pageData.fullReductionCoupon, payPrice.value,
pageData.fullReductionCouponSel)
}
if (newval == 1) {
}
})
onReady(() => {
getSafeBottomHeight('bottom', 0).then(height => {
safebottomHeight.value = height
})
})
/**
* 抵扣金额
*/
const discountAmount = computed(() => {
const goodsQuan = pageData.productCoupon.filter(v => v.checked)
const fullReductionCoupon = pageData.fullReductionCouponSel.id ? [pageData.fullReductionCouponSel] : []
let coupArr = [...fullReductionCoupon, ...goodsQuan]
return returnCouponAllPrice(coupArr, canDikouGoodsArr, pageData.user)
})
const payPrice = computed(() => {
const pay = option.orderPrice - discountAmount.value
return (pay < 0 ? 0 : pay).toFixed(2)
})
/**
* 获取优惠券
*/
async function getQuan() {
shopUserDetail({ id: option.userId }).then(res=>{
pageData.user = res
})
pageData.order = await getHistoryOrder({orderId:option.orderId})
console.log(pageData.order);
const res = await getCouponList()
let fullReductionCoupon = res.filter(v => v.type == 1)
let productCoupon = res.filter(v => v.type == 2)
canDikouGoodsArr = returnNewGoodsList(pageData.order.detailMap || [])
fullReductionCoupon = fullReductionCoupon.map((v) => {
if(option.orderPrice<=0){
return {...v,use:false}
}else{
return{
...v,
use:v.use && option.orderPrice * 1 >= v
.fullAmount * 1
}
}
})
productCoupon = productCoupon.map(v => {
const calcCoup = returnProductCoupon(v, pageData.order.detailMap, pageData.user)
return {
...calcCoup,
checked: false,
use:option.orderPrice<=0?false:v.use
}
}).filter((v) => v.use);
pageData.fullReductionCoupon = fullReductionCoupon
pageData.productCoupon = productCoupon
console.log(pageData)
pageData.hasAjax = true;
}
function confirmModelCancel() {
setModalShow('clear', false, '')
}
async function confirmModelConfirm() {
if (modal.key == 'clear') {
myQuan.fullReductionCouponSel = {
pageData.fullReductionCouponSel = {
id: ''
}
const item = modal.data
item.checked = !item.checked
const CheckedArr = myQuan.res.productCoupon.filter(v => v.checked)
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
const CheckedArr = pageData.productCoupon.filter(v => v.checked)
const noCheckedArr = pageData.productCoupon.filter(v => !v.checked)
noCheckedArr.map(v => {
console.log(returnCoupCanUse(canDikouGoodsArr, v, CheckedArr));
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr)
})
setModalShow('clear', false, '')
@@ -207,36 +286,20 @@
function back() {
uni.navigateBack()
}
let order = ref({
})
let canDikouGoodsArr = []
const myQuan = reactive({
fullReductionCouponSel: {
id: ''
},
res: {
fullReductionCoupon: [],
productCoupon: []
},
types: {
list: ['满减券(单选)', '商品券(多选)'],
sel: 0
},
list: [],
sel: -1,
hasAjax: false
})
/**
* 商品券选择
* @param {Object} item
*/
function changeProductCoupon(item) {
if (!item.use) {
return
}
if (myQuan.fullReductionCouponSel.id && !item.checked) {
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : []
if (pageData.fullReductionCouponSel.id && !item.checked) {
const goodsQuan = pageData.productCoupon.filter(v => v.checked)
const fullReductionCoupon = pageData.fullReductionCouponSel.id ? [pageData.fullReductionCouponSel] : []
let coupArr = [...goodsQuan, item]
const payPrice = option.orderPrice - returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
const payPrice = option.orderPrice - returnCouponAllPrice(coupArr, canDikouGoodsArr, pageData.user)
if (payPrice<=0) {
modal.content = '选择该商品券后支付金额将为0继续选择将取消选择的满减券'
modal.cancelText = '取消'
@@ -244,7 +307,7 @@
setModalShow('clear', true, item)
return
}
if (myQuan.fullReductionCouponSel.fullAmount > payPrice) {
if (pageData.fullReductionCouponSel.fullAmount > payPrice) {
modal.content = '选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券'
modal.cancelText = '取消'
modal.confirmText = '继续选择'
@@ -254,142 +317,65 @@
}
item.checked = !item.checked
const CheckedArr = myQuan.res.productCoupon.filter(v => v.checked)
const CheckedArr = pageData.productCoupon.filter(v => v.checked)
if (CheckedArr.length <= 0) {
return myQuan.res.productCoupon.map(v => {
return pageData.productCoupon.map(v => {
v.use = true
})
}
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
const noCheckedArr = pageData.productCoupon.filter(v => !v.checked)
noCheckedArr.map(v => {
console.log(returnCoupCanUse(canDikouGoodsArr, v, CheckedArr));
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr)
})
}
/**
* 优惠券选择
* @param {Object} item
*/
function changeFullReductionCouponSel(item) {
if (!item.use) {
return
// return
}
console.log(item);
if (item.id == myQuan.fullReductionCouponSel.id) {
myQuan.fullReductionCouponSel = {
if (item.id == pageData.fullReductionCouponSel.id) {
pageData.fullReductionCouponSel = {
id: ''
}
} else {
myQuan.fullReductionCouponSel = item
pageData.fullReductionCouponSel = item
}
myQuan.res.fullReductionCoupon = returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value, myQuan
pageData.fullReductionCoupon = returnCanUseFullReductionCoupon(pageData.fullReductionCoupon, payPrice.value, pageData
.fullReductionCouponSel)
}
function formatStr(str) {
return str.replaceAll('"', '')
// return str.replaceAll('"', '')
}
function toUse(item) {
}
let user = reactive({
isVip: false
})
let $fullReductionCoupon = []
let $productCoupon = []
async function getQuan() {
order.value = await orderApi.tbOrderInfoDetail(option.orderId)
if (order.value.memberId) {
const userRes = await queryAllShopUser({
id: order.value.memberId
})
if (userRes.content[0]) {
user.value = userRes.content[0]
}
}
console.log(order.value);
const res = await $activateByOrderId({
orderId: option.orderId,
memberId: option.memberId
})
canDikouGoodsArr = returnNewGoodsList(order.value.detailList || [])
res.fullReductionCoupon = res.fullReductionCoupon.map((v) => {
if(option.orderPrice<=0){
return {...v,use:false}
}else{
return{
...v,
use:v.use && option.orderPrice * 1 >= v
.fullAmount * 1
}
}
})
res.productCoupon = res.productCoupon.map(v => {
const calcCoup = returnProductCoupon(v, canDikouGoodsArr, user.value)
return {
...calcCoup,
checked: false,
use:option.orderPrice<=0?false:v.use
}
}).filter((v) => v.use);
$fullReductionCoupon = res.fullReductionCoupon
$productCoupon = res.productCoupon
myQuan.res = res
myQuan.hasAjax = true;
}
const option = reactive({
orderId: '',
memberId: '',
orderPrice: 0
})
/**
* 优惠券选择确认
* @param {Object} item
*/
function toEmitChooseQuan(item) {
let arr = []
if (item) {
arr = [item]
} else {
if (myQuan.fullReductionCouponSel.id) {
arr.push(myQuan.fullReductionCouponSel)
if (pageData.fullReductionCouponSel.id) {
arr.push(pageData.fullReductionCouponSel)
}
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
const goodsQuan = pageData.productCoupon.filter(v => v.checked)
arr.push(...goodsQuan)
}
uni.$emit('choose-quan', arr)
back()
}
const discountAmount = computed(() => {
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : []
let coupArr = [...fullReductionCoupon, ...goodsQuan]
return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
})
const payPrice = computed(() => {
const pay = option.orderPrice - discountAmount.value
return (pay < 0 ? 0 : pay).toFixed(2)
})
watch(() => myQuan.types.sel, (newval) => {
if (newval == 0) {
myQuan.res.fullReductionCoupon = returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value,
myQuan.fullReductionCouponSel)
}
if (newval == 1) {
}
})
onLoad((opt) => {
Object.assign(option, opt)
getQuan()
})
let safebottomHeight = ref(0)
onReady(() => {
getSafeBottomHeight('bottom', 0).then(height => {
console.log(height);
safebottomHeight.value = height
})
})
</script>
<style lang="scss" scoped>