oil-station/gasStation-uni/pagesHome/order/order.vue

773 lines
17 KiB
Vue
Raw Normal View History

2023-11-27 09:24:16 +08:00
<template>
<view class="content">
<view class="container">
<view class="my-header">
<view class="my-icons" @click="goback"> <uni-icons type="left" size="16"></uni-icons> </view>
<view class="my-text">提交订单</view>
<view class="my-icons"></view>
</view>
<!-- 顶部区域 -->
<scroll-view scroll-x="true" class="tap-top">
<view class="sz" v-for="(item,index) in tapList" :key="index" @click="transferIndex(index) ">
<view class="box" :class="{'xztap': qhindex == index}">{{item.text }}</view>
<view class="gang" v-if="qhindex == index"></view>
</view>
</scroll-view>
<view class="box-bai" v-if="qhindex == 0">
<view class="dis">
<!-- <uni-icons type="location-filled" size="20"></uni-icons> -->
<view class="boximg">
<image src="../../static/logo.png" mode=""></image>
</view>
<view class="">
2023-12-07 10:22:52 +08:00
<view class="">{{storeName}}</view>
2023-11-27 09:24:16 +08:00
<view class="hui-time">
2023-12-07 10:22:52 +08:00
{{storeAddress}}
2023-11-27 09:24:16 +08:00
</view>
</view>
</view>
<view class="">
2023-12-14 13:38:01 +08:00
<!-- <uni-icons type="right" size="20"></uni-icons> -->
2023-11-27 09:24:16 +08:00
</view>
</view>
<view class="box-bai" v-if="qhindex == 1" @click="goAdd()">
<view class="dis">
<uni-icons type="location-filled" color="#666666" size="30" style="margin-right: 5px;"></uni-icons>
<view class="">
<view class="">家庭住址</view>
<view class="hui-time">
2023-12-01 15:29:00 +08:00
<!-- 山东省济南市槐荫区兴福路 -->
{{addrInfo.address}}
2023-11-27 09:24:16 +08:00
</view>
</view>
</view>
<view class="">
<uni-icons type="right" size="20"></uni-icons>
</view>
</view>
<view class="box-bait">
<view class="dis-box">
<view class="goodsimg">
2023-11-30 18:11:49 +08:00
<image :src='baseUrl+goodsInfo.coverImage' mode=""></image>
2023-11-27 09:24:16 +08:00
</view>
<view class="">
2023-11-30 18:11:49 +08:00
<view class="">{{goodsInfo.giftName}}</view>
<view class="huyi">市场价{{goodsInfo.market}}</view>
2023-11-27 09:24:16 +08:00
<view class="btwo">
2023-11-30 18:11:49 +08:00
<view class="">
<span
v-if="goodsInfo.exchangeMethod == '积分' || goodsInfo.exchangeMethod == '积分+金额' || goodsInfo.exchangeMethod == '积分+加钱购'">{{goodsInfo.exchangePoints}}积分</span>
<span v-if="goodsInfo.exchangeMethod == '积分+金额'">+</span>
2023-11-30 18:11:49 +08:00
<span
v-if="goodsInfo.exchangeMethod == '金额' || goodsInfo.exchangeMethod == '积分+金额'">{{goodsInfo.exchangeAmount}}</span>
</view>
2023-11-27 09:24:16 +08:00
<view class="">
2023-12-05 10:38:56 +08:00
<u-number-box v-model="value" @change="valChange" button-size="18"
:disablePlus="flag"></u-number-box>
2023-11-27 09:24:16 +08:00
</view>
</view>
</view>
</view>
<view class="endbox">
2023-11-30 18:11:49 +08:00
<view style="color: #666666;font-size: 14px;">{{value}}件商品合计:</view>
<view v-if="allPoints>0" style="color: red;"> <text
style="font-weight: bold;font-size: 20px;">{{allPoints}}</text> 积分
2023-12-01 15:29:00 +08:00
</view>
<span v-if="allAmout>0 && allPoints>0">+</span>
2023-12-05 10:38:56 +08:00
<view v-if="allAmout>0" style="color: red;"> <text
style="font-weight: bold;font-size: 20px;">{{allAmout}}</text>
2023-12-01 15:29:00 +08:00
</view>
2023-11-27 09:24:16 +08:00
</view>
2024-01-04 09:09:58 +08:00
<view
v-if="shippingType == '物流配送' && goodsInfo.expressShippingFee == '统一运费' && goodsInfo.shippingFeeAmount && goodsInfo.shippingFeeAmount>0"
class="endbox">
<view style="color: #666666;font-size: 14px;">统一运费: </view>
<view style="color: red;"> <text
style="font-weight: bold;font-size: 18px;">{{goodsInfo.shippingFeeAmount}}</text>
</view>
</view>
2023-11-27 09:24:16 +08:00
</view>
<view class="beizhu">
<view style="margin-right: 15px;">备注</view>
<input type="text" placeholder="选填,请输入备注信息" />
</view>
<view class="bottom-box">
<view class="">
2023-12-01 15:29:00 +08:00
<view style="color: red;">
<text v-if="allPoints>0" style="font-weight: bold;font-size: 20px;">{{allPoints}}</text> 积分
<span v-if="allAmout>0 && allPoints>0">+</span>
<text v-if="allAmout>0" style="font-weight: bold;font-size: 20px;">{{allAmout}}</text>
2023-12-01 15:29:00 +08:00
</view>
<view style="color: #9d9d9d; font-size: 12px; ">积分账户{{myPoints}}</view>
2023-11-27 09:24:16 +08:00
</view>
<view @click="choose()" class="andeniu">
<text>选择</text>
2023-11-27 09:24:16 +08:00
</view>
</view>
</view>
</view>
</template>
<script>
2023-11-30 18:11:49 +08:00
import config from '@/config'
import request from '../../utils/request'
2024-01-02 14:24:47 +08:00
import BigNumber from 'bignumber.js'
2023-11-27 09:24:16 +08:00
export default {
2023-11-30 18:11:49 +08:00
2023-12-01 16:40:20 +08:00
2023-11-27 09:24:16 +08:00
data() {
return {
2023-12-08 17:01:33 +08:00
myPoints: 0, //我的积分
2023-11-30 18:11:49 +08:00
goodsInfo: '',
2023-12-07 10:22:52 +08:00
storeName: '',
storeAddress: '',
2023-12-05 10:38:56 +08:00
flag: false, // 禁用
2023-11-27 09:24:16 +08:00
title: '',
qhindex: 0,
2023-11-30 18:11:49 +08:00
value: 1,
baseUrl: config.baseUrl,
2023-12-01 15:29:00 +08:00
allPoints: 0,
allAmout: 0,
2023-12-22 18:18:21 +08:00
orderInfo: {},
2023-12-01 15:29:00 +08:00
addrInfo: {
2023-12-05 10:38:56 +08:00
address: ''
2023-12-01 15:29:00 +08:00
},
2024-01-04 09:09:58 +08:00
shippingType: '',
2023-12-22 18:18:21 +08:00
paymentType: '',
storeId: uni.getStorageSync('storeId'),
2024-01-02 11:21:12 +08:00
chainStoreId: uni.getStorageSync('chainStoreId'),
2023-11-27 09:24:16 +08:00
tapList: [{
text: '到店自提'
},
{
text: '快递配送'
}
]
}
},
components: {
},
2023-11-30 18:11:49 +08:00
onLoad() {
uni.$on('goodsInfo', (data) => {
this.goodsInfo = data
2023-12-05 10:38:56 +08:00
console.log("from 11", data)
2023-11-30 18:11:49 +08:00
if (this.goodsInfo != null) {
this.dataProcessing()
2023-12-01 15:29:00 +08:00
this.allData()
2023-11-30 18:11:49 +08:00
}
})
uni.$emit('un')
2023-12-09 15:23:37 +08:00
// 根据storeId查询店铺信息
this.getInfoByStoreId()
2023-12-01 15:29:00 +08:00
},
2023-12-05 10:38:56 +08:00
2023-12-01 15:29:00 +08:00
onShow() {
uni.$on('chooseAddr', (data) => {
this.addrInfo = data
})
uni.$emit('unChooseAddr')
2023-12-05 10:38:56 +08:00
if (this.addrInfo.address == '' || this.addrInfo == null) {
2023-12-01 15:29:00 +08:00
this.getAddr()
}
2023-12-05 10:38:56 +08:00
this.transferIndex(0)
2023-12-07 10:22:52 +08:00
// 根据storeId查询店铺信息
this.getInfoByStoreId()
2024-01-04 09:09:58 +08:00
// 查询剩余积分
this.getUserInfoList()
2023-12-07 10:22:52 +08:00
2023-11-30 18:11:49 +08:00
},
2023-11-27 09:24:16 +08:00
methods: {
2024-01-02 11:21:12 +08:00
// 创建订单并 付款
2023-12-22 18:18:21 +08:00
async choose() {
let _this = this
let integralOrdersList = []
2024-01-04 15:52:02 +08:00
if (_this.value <= 0) {
uni.showToast({
title: "请选择商品!",
icon: "error"
})
return
}
2023-12-22 18:18:21 +08:00
let integralOrders = {
giftId: this.goodsInfo.id,
amount: _this.allAmout,
2024-01-04 09:09:58 +08:00
integral: _this.allPoints,
storeId: _this.storeId,
chainStoreId: _this.chainStoreId,
2023-12-22 18:18:21 +08:00
exchangeQuantity: _this.value,
orderType: 1,
2024-01-04 09:09:58 +08:00
paymentType: _this.paymentType,
shippingType: _this.shippingType,
2023-12-22 18:18:21 +08:00
}
2024-01-04 15:52:02 +08:00
if (this.shippingType == "物流配送") {
if (addrInfo) {
integralOrders.addressId = addrInfo.id
} else {
uni.showToast({
title: "请填写配送信息!",
icon: "error"
})
}
}
let check = await this.checkTheRedemptionLimit(this.goodsInfo.id)
if (check) {
uni.showToast({
title: "达到兑换上限!",
icon: "error"
})
return
}
2023-12-22 18:18:21 +08:00
integralOrdersList.push(integralOrders)
request({
url: "business/integral/integralOrders/integralOrdersProcessingUni",
method: 'post',
data: {
integralOrdersList: integralOrdersList,
// authCode:this_.authCode,
// paymentType: _this.paymentType,
paymentType: "WECHAT",
allAmout: _this.allAmout,
2024-01-04 09:09:58 +08:00
allPoints: _this.allPoints,
2023-12-22 18:18:21 +08:00
chainStoreId: _this.chainStoreId,
storeId: _this.storeId,
},
}).then(res => {
2024-01-02 11:21:12 +08:00
// if (res.data.code === "error") {
2024-01-04 09:09:58 +08:00
if (_this.allAmout == 0) {
uni.reLaunch({
url: '/pagesRefuel/orderSuccess/index'
})
} else if (res.data.code === "success") {
2023-12-22 18:18:21 +08:00
console.log(res)
let payProvider = "wxpay"
_this.orderInfo = JSON.parse(res.data.data.reservedPayInfo);
uni.requestPayment({
// 微信支付provider: 'wxpay' 支付宝支付 'alipay'
provider: payProvider,
timeStamp: _this.orderInfo.timeStamp,
nonceStr: _this.orderInfo.nonceStr,
package: _this.orderInfo.package,
signType: 'MD5',
paySign: _this.orderInfo.paySign,
success: function(res) {
console.log('success:', res);
uni.reLaunch({
url: '/pagesRefuel/orderSuccess/index'
})
},
fail: function(err) {
request({
url: "business/integral/integralOrders/editPayStatus",
2024-01-02 14:24:47 +08:00
method: 'get',
data: {
"orderNo": res.data.data.orderNo,
"status": "payFail",
"storeId": -1
},
}).then((res) => {
uni.showToast({
title: "支付失败!",
icon: "error"
})
})
console.log('fail:', err);
2023-12-22 18:18:21 +08:00
}
});
} else {
uni.showToast({
title: "支付失败!",
icon: "error"
})
2023-12-22 18:18:21 +08:00
}
})
},
2023-11-30 18:11:49 +08:00
dataProcessing() {
if (this.goodsInfo.deliveryMethod != null && this.goodsInfo.deliveryMethod != undefined) {
const deliveryData = JSON.parse(this.goodsInfo.deliveryMethod);
this.deliveryMethod = deliveryData.join('+');
} else {
this.deliveryMethod = '无配送信息'
}
},
2024-01-04 09:09:58 +08:00
async valChange(e) {
// 判断是否达到领取上限
// let flag = await this.checkTheRedemptionLimit(this.goodsInfo.id)
let flag = await this.enquiryForCollection(this.goodsInfo.id)
let num = e.value + Number(flag)
console.log("123123", num);
//判断库存
if (num > this.goodsInfo.exchangeTimes) {
uni.showToast({
title: "已达到兑换上限!",
icon: "none"
})
2023-12-05 10:38:56 +08:00
2024-01-04 09:09:58 +08:00
console.log("exchangeTimes", this.goodsInfo.exchangeTimes)
console.log("flag", flag)
e.value = this.goodsInfo.exchangeTimes - flag
this.value = this.goodsInfo.exchangeTimes - flag
2023-12-09 15:23:37 +08:00
2024-01-04 09:09:58 +08:00
this.flag = true
this.allData()
return
} else if (e.value >= this.goodsInfo.remainingInventory && this
.goodsInfo.remainingInventory != -
2023-12-22 18:18:21 +08:00
1) { // -1为无限库存
2024-01-04 09:09:58 +08:00
uni.showToast({
title: "库存不足!",
icon: "none"
})
2023-12-05 10:38:56 +08:00
e.value = this.goodsInfo.remainingInventory
this.value = this.goodsInfo.remainingInventory
this.flag = true
this.allData()
} else {
this.value = e.value
this.allData()
}
2023-11-27 09:24:16 +08:00
},
transferIndex(index) {
2023-12-05 10:38:56 +08:00
// this.qhindex = index
const deliveryData = JSON.parse(this.goodsInfo.deliveryMethod);
console.log("deliveryData", deliveryData)
if (deliveryData.length >= 2) {
2024-01-04 09:09:58 +08:00
this.shippingType = deliveryData[index]
2023-12-05 10:38:56 +08:00
this.qhindex = index
} else if (deliveryData[0] == '门店自提') {
2024-01-04 09:09:58 +08:00
this.shippingType = "门店自提"
if (index == 1) {
uni.showToast({
title: "该商品只支持到店自提!",
icon: "none"
})
}
2023-12-05 10:38:56 +08:00
this.qhindex = 0
2023-12-05 10:38:56 +08:00
} else if (deliveryData[0] == '物流配送') {
2024-01-04 09:09:58 +08:00
this.shippingType = "物流配送"
2023-12-05 10:38:56 +08:00
this.qhindex = 1
if (index == 0) {
uni.showToast({
title: "该商品只支持物流配送!",
icon: "none"
})
}
2023-12-05 10:38:56 +08:00
}
2024-01-04 09:09:58 +08:00
this.allData()
2023-11-27 09:24:16 +08:00
},
goAdd() {
uni.navigateTo({
url: '/pagesHome/Address/Address'
})
},
goback() {
uni.navigateBack()
2023-12-01 15:29:00 +08:00
},
// 金额计算
allData() {
this.allPoints = 0
this.allAmout = 0
2024-01-04 09:09:58 +08:00
console.log("this.shippingType", this.shippingType)
if (this.shippingType == "物流配送" &&
this.goodsInfo.expressShippingFee == '统一运费' && this.goodsInfo
.shippingFeeAmount &&
this.goodsInfo.shippingFeeAmount >
0
) {
console.log("11111111")
this.allAmout = this.goodsInfo.shippingFeeAmount
}
console.log("allAmout", this.allAmout)
console.log("shippingFeeAmount", this.goodsInfo
.shippingFeeAmount)
let allPoints = new BigNumber(0)
if (this.goodsInfo.exchangePoints) {
allPoints = new BigNumber(this.goodsInfo.exchangePoints)
}
2023-12-01 15:29:00 +08:00
let value = new BigNumber(this.value)
2023-12-01 16:40:20 +08:00
allPoints = allPoints.times(value)
2023-12-05 10:38:56 +08:00
console.log("allPoints", allPoints)
if (this.goodsInfo.exchangeMethod == '积分+金额' || this.goodsInfo.exchangeMethod == '金额') {
2023-12-05 10:38:56 +08:00
let allAmout = new BigNumber(this.goodsInfo.exchangeAmount)
2023-12-01 16:40:20 +08:00
allAmout = allAmout.times(value)
2023-12-05 10:38:56 +08:00
if (this.goodsInfo.exchangePoints < 0) {
allAmout = 0
}
2024-01-04 09:09:58 +08:00
let all = allAmout.plus(this.allAmout)
this.allAmout = Number(all).toFixed(2);
2023-12-01 15:29:00 +08:00
}
2023-12-05 10:38:56 +08:00
// 计算加钱购
2023-12-01 15:29:00 +08:00
2023-12-05 10:38:56 +08:00
2024-01-04 09:09:58 +08:00
if (this.goodsInfo.exchangeMethod === '积分+加钱购') {
2023-12-05 10:38:56 +08:00
// 拿到总的积分
2024-01-02 14:24:47 +08:00
this.myPoints = this.myPoints ? this.myPoints : 0
2023-12-05 10:38:56 +08:00
let points = this.myPoints - allPoints; // 使用 toNumber() 获取 BigNumber 的数值
2024-01-04 09:09:58 +08:00
2023-12-05 10:38:56 +08:00
// 以及分等一多少
2024-01-02 14:24:47 +08:00
if (points <= 0) {
2023-12-05 10:38:56 +08:00
// 计算需要的金额
points = Math.abs(points);
2024-01-04 09:09:58 +08:00
let sum = points * this.goodsInfo.moneyRatio.toFixed(2); // 直接使用 JavaScript 中的乘法
this.allAmout = this.allAmout + sum
2024-01-02 14:24:47 +08:00
this.allPoints = this.myPoints;
2023-12-05 10:38:56 +08:00
} else {
2024-01-04 09:09:58 +08:00
// this.allAmout = 0
this.allPoints = Number(allPoints).toFixed(2);
2023-12-05 10:38:56 +08:00
}
return
}
2023-12-01 15:29:00 +08:00
// 更新组件的值
this.allPoints = Number(allPoints).toFixed(2);
},
getAddr() {
request({
url: 'business/userManager/mtUserExpressAddress/getList',
method: 'get',
}).then((res) => {
if (res.code == 200) {
console.log("res", res.data)
if (res.data.length > 0) {
this.addrInfo = res.data[0]
} else {
this.addrInfo.address = '请填写地址'
}
}
})
},
// 查询我的积分
getUserInfoList() {
request({
url: '/business/userManager/user/getByUniApp',
method: 'get',
2023-12-05 10:38:56 +08:00
params: {
2023-12-22 18:18:21 +08:00
chainStoreId: this.chainStoreId
2023-12-05 10:38:56 +08:00
}
2023-12-01 15:29:00 +08:00
}).then((res) => {
if (res.code == 200) {
this.myPoints = res.data.points
2024-01-02 14:24:47 +08:00
this.allData()
2023-12-01 15:29:00 +08:00
}
})
},
2023-12-05 10:38:56 +08:00
// 根据storeid 查找店铺信息
getStroeById() {
request({
2023-12-05 13:33:30 +08:00
url: 'business/storeInformation/store/storeInfoUni',
2023-12-05 10:38:56 +08:00
method: 'get',
2023-12-05 13:33:30 +08:00
params: {
storeId: uni.getStorageSync('storeId')
}
2023-12-05 10:38:56 +08:00
}).then((res) => {
if (res.code == 200) {
this.myPoints = res.data.points
}
})
2023-12-07 10:22:52 +08:00
},
// 根据storeId查询店铺信息
getInfoByStoreId() {
request({
url: '/business/storeInformation/store/storeInfoUni',
method: 'get',
params: {
storeId: uni.getStorageSync('storeId')
}
}).then((res) => {
if (res.code == 200) {
this.storeName = res.data.name
this.storeAddress = res.data.address
}
})
2024-01-04 09:09:58 +08:00
},
// 查询该商品是否达到个人的兑换上限
async checkTheRedemptionLimit(giftId) {
let flag = false;
await request({
url: 'business/integral/integralOrders/checkTheRedemptionLimit',
method: 'get',
params: {
giftId: giftId
}
}).then((res) => {
if (res.code == 200) {
flag = res.data
}
})
return flag
},
// 查询该商品是否达到个人的兑换上限
async enquiryForCollection(giftId) {
let flag = 0;
await request({
url: 'business/integral/integralOrders/enquiryForCollection',
method: 'get',
params: {
giftId: giftId
}
}).then((res) => {
if (res.code == 200) {
flag = res.data
}
})
return flag
2023-12-05 10:38:56 +08:00
}
2023-11-27 09:24:16 +08:00
}
}
</script>
<style scoped lang="scss">
.content {
background: #f4f5f6;
}
.container {
width: 100%;
height: 100vh;
box-sizing: border-box;
padding-top: 88px;
}
.my-header {
width: 100%;
height: 88px;
background: #ffffff;
display: flex;
align-items: center;
justify-content: space-between;
color: #000;
box-sizing: border-box;
padding: 0px 15px;
padding-top: 40px;
.my-icons {
width: 20px;
}
position: fixed;
top: 0px;
}
.dis {
display: flex;
align-items: center;
}
.tap-top {
box-sizing: border-box;
padding-top: 10px;
width: 100%;
// padding-bottom: 22rpx;
padding-bottom: 10px;
background: #ffffff;
border-bottom: 1px solid #EEEEEE;
white-space: nowrap;
.sz {
width: 50%;
display: inline-block;
}
.box {
// margin: 0 auto;
text-align: center;
font-size: 32rpx;
margin-right: 50rpx;
line-height: 32rpx;
text-align: center;
// font-weight: bold;
color: #666666;
margin: 0 auto;
margin-bottom: 20rpx;
}
}
.xztap {
color: #333333 !important;
font-weight: bold !important;
}
.gang {
width: 128rpx;
height: 8rpx;
margin: 0 auto;
background: #1678ff;
border-radius: 14rpx;
}
.box-bai {
width: 100%;
height: 60px;
background: #ffffff;
display: flex;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
padding: 0px 20px;
}
.box-bait {
width: 100%;
background: #ffffff;
box-sizing: border-box;
padding: 15px;
margin: 20px auto;
}
.boximg {
width: 40px;
height: 40px;
border-radius: 8px;
background-color: #1678ff;
margin-right: 10px;
image {
width: 100%;
height: 100%;
}
}
.hui-time {
font-size: 14px;
color: #666666;
}
.dis-box {
display: flex;
}
.goodsimg {
width: 75px;
height: 75px;
overflow: hidden;
margin-right: 10px;
image {
width: 100%;
height: 100%;
}
}
.endbox {
margin-top: 15px;
width: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
}
.btwo {
width: 240px;
display: flex;
justify-content: space-between;
}
.huyi {
font-size: 14px;
margin: 5px auto;
color: #999999;
}
.red {
color: red;
}
.beizhu {
background-color: #ffffff;
display: flex;
align-items: center;
box-sizing: border-box;
padding: 15px 20px;
}
.bottom-box {
width: 100%;
height: 88px;
background: white;
box-sizing: border-box;
padding: 20px;
display: flex;
align-items: center;
justify-content: space-between;
position: fixed;
bottom: 0px;
z-index: 99999;
}
.andeniu {
width: 100px;
height: 45px;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff;
border-radius: 4px;
background: #1678ff;
}
2023-12-14 13:38:01 +08:00
</style>