|
@@ -1,53 +1,52 @@
|
|
|
<template>
|
|
|
<view class="container order clearfix" :style="{ paddingBottom: isIphoneX ? '170rpx' : '134rpx' }">
|
|
|
- <!-- 地址选择 v-if="isAddress" -->
|
|
|
- <choice-address ref="choiceAddress" :addressData="addressData"></choice-address>
|
|
|
- <!-- 商品 -->
|
|
|
- <goodsList
|
|
|
- ref="goods"
|
|
|
- v-if="isRequest"
|
|
|
- :goodsData="goodsData"
|
|
|
- @handleGoodList="handChangeInputGoodsList"
|
|
|
- ></goodsList>
|
|
|
- <!-- 选择优惠券 TODO-->
|
|
|
- <view class="select-coupon" @click="couponVisible = true" v-if="receiveCouponList.length > 0">
|
|
|
- <view class="left-title">优惠券</view>
|
|
|
- <view class="right-content">
|
|
|
- <view class="coupon-amount">-¥{{ couponAmount | NumFormat }}</view>
|
|
|
- <view class="iconfont icon-chakangengduo"></view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
- <!-- 优惠券列表 TODO-->
|
|
|
- <cm-coupon-list
|
|
|
- title="优惠券"
|
|
|
- listType="use"
|
|
|
- :visible="couponVisible"
|
|
|
- @close="closeCouponList"
|
|
|
- :chooseAble="true"
|
|
|
- :showStatus="false"
|
|
|
- :couponList="receiveCouponList"
|
|
|
- @chooseCoupon="chooseCoupon"
|
|
|
- :currentId="currentCouponId"
|
|
|
- ></cm-coupon-list>
|
|
|
- <!-- 运费 -->
|
|
|
- <seller-freight ref="freight" v-if="isRequest" :freightDatas="freightData"> </seller-freight>
|
|
|
- <!-- 底部 -->
|
|
|
- <view class="footer" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0rpx' }">
|
|
|
- <view class="footer-le">
|
|
|
- <view class="footer-count">
|
|
|
- <text>共{{ allCount }}件商品</text>
|
|
|
+ <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
|
|
|
+ <template v-else>
|
|
|
+ <!-- 地址选择 v-if="isAddress" -->
|
|
|
+ <choice-address ref="choiceAddress" :addressData="addressData"></choice-address>
|
|
|
+ <!-- 商品 -->
|
|
|
+ <goodsList ref="goods" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goodsList>
|
|
|
+ <!-- 选择优惠券 TODO-->
|
|
|
+ <view class="select-coupon" @click="couponVisible = true" v-if="receiveCouponList.length > 0">
|
|
|
+ <view class="left-title">优惠券</view>
|
|
|
+ <view class="right-content">
|
|
|
+ <view class="coupon-amount">-¥{{ couponAmount | NumFormat }}</view>
|
|
|
+ <view class="iconfont icon-chakangengduo"></view>
|
|
|
</view>
|
|
|
- <view class="footer-price">
|
|
|
- <view class="sum" :class="totalFullReduction == 0 ? 'none' : ''">
|
|
|
- <view class="price">总价:¥{{ payAllPrice | NumFormat }}</view>
|
|
|
- <view class="discount">共减 ¥{{ discountedPrice | NumFormat }}</view>
|
|
|
+ </view>
|
|
|
+ <!-- 优惠券列表 TODO-->
|
|
|
+ <cm-coupon-list
|
|
|
+ title="优惠券"
|
|
|
+ listType="use"
|
|
|
+ :visible="couponVisible"
|
|
|
+ @close="closeCouponList"
|
|
|
+ :chooseAble="true"
|
|
|
+ :showStatus="false"
|
|
|
+ :couponList="receiveCouponList"
|
|
|
+ @chooseCoupon="chooseCoupon"
|
|
|
+ :currentId="currentCouponId"
|
|
|
+ ></cm-coupon-list>
|
|
|
+ <!-- 运费 -->
|
|
|
+ <seller-freight ref="freight" :freightDatas="freightData"> </seller-freight>
|
|
|
+ <!-- 底部 -->
|
|
|
+ <view class="footer" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0rpx' }">
|
|
|
+ <view class="footer-le">
|
|
|
+ <view class="footer-count">
|
|
|
+ <text>共{{ allCount }}件商品</text>
|
|
|
+ </view>
|
|
|
+ <view class="footer-price">
|
|
|
+ <view class="sum" :class="totalFullReduction == 0 ? 'none' : ''">
|
|
|
+ <view class="price">总价:¥{{ payAllPrice | NumFormat }}</view>
|
|
|
+ <view class="discount">共减 ¥{{ discountedPrice | NumFormat }}</view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
+ <view class="footer-submit" @click.stop="orderSubmitMit">
|
|
|
+ <view class="btn" :class="isSubLoading ? 'disabled' : ''">提交订单</view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
- <view class="footer-submit" @click.stop="orderSubmitMit">
|
|
|
- <view class="btn" :class="isSubLoading ? 'disabled' : ''">提交订单</view>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
+ </template>
|
|
|
+ <cm-loading :visible="isSubLoading" :text="loadingText"></cm-loading>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
@@ -57,33 +56,34 @@ import choiceAddress from '@/components/cm-module/createOrder/address'
|
|
|
import goodsList from '@/components/cm-module/createOrder/goodsList'
|
|
|
import sellerFreight from '@/components/cm-module/createOrder/sellerFreight'
|
|
|
import CmCouponList from '@/components/cm-module/cm-coupon-list/cm-coupon-list'
|
|
|
+import CmLoading from '@/components/cm-module/cm-loading/cm-loading.vue'
|
|
|
+import { allProdoceUseCheck, someProductUseCheck, couponSort } from '@/common/couponUtil.js'
|
|
|
import { mapGetters } from 'vuex'
|
|
|
+import wechatPay from '@/mixins/wechatPay.js'
|
|
|
export default {
|
|
|
components: {
|
|
|
choiceAddress,
|
|
|
goodsList,
|
|
|
sellerFreight,
|
|
|
- CmCouponList
|
|
|
+ CmCouponList,
|
|
|
+ CmLoading
|
|
|
},
|
|
|
+ // 混入
|
|
|
+ mixins: [wechatPay],
|
|
|
data() {
|
|
|
return {
|
|
|
couponVisible: false,
|
|
|
- isSubLoading: false,
|
|
|
productIds: '', //获取上一级页面商品信息
|
|
|
productCount: '', //获取上一级页面商品数量
|
|
|
allCount: 1, //订单提交总数量
|
|
|
- totalOriginalPrice: 0, //订单总原价(划线部分)
|
|
|
totalFullReduction: 0, //满减金额
|
|
|
allPrice: 0.0, //订单总金额
|
|
|
townId: '', //区ID
|
|
|
- isRequest: false, //是否加载完成渲染子组件
|
|
|
- isFreight: false, //是否加载完成渲染子组件
|
|
|
+ isRequest: true, //是否加载完成渲染子组件
|
|
|
isAddress: false, //是否加载完成地址
|
|
|
- ischecked: false, //是否勾选余额
|
|
|
addressData: {}, //初始化地址信息
|
|
|
goodsData: [], //初始化商品信息
|
|
|
freightData: {}, //邮费数据
|
|
|
- isIphoneX: this.$store.getters.isIphoneX,
|
|
|
productsList: [],
|
|
|
params: {
|
|
|
userId: 0
|
|
@@ -100,7 +100,8 @@ export default {
|
|
|
orderInfo: '',
|
|
|
receiveCouponList: [],
|
|
|
currentCouponId: -1,
|
|
|
- currentCoupon: null
|
|
|
+ currentCoupon: null,
|
|
|
+ loadingText: '正在创建订单'
|
|
|
}
|
|
|
},
|
|
|
onLoad(option) {
|
|
@@ -123,7 +124,7 @@ export default {
|
|
|
this.getInitCrearOrder(this.params)
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters(['userId']),
|
|
|
+ ...mapGetters(['userId', 'isIphoneX']),
|
|
|
// 选中的优惠券的金额
|
|
|
couponAmount() {
|
|
|
return this.currentCoupon ? this.currentCoupon.couponAmount : 0
|
|
@@ -135,6 +136,11 @@ export default {
|
|
|
// 支付金额
|
|
|
payAllPrice() {
|
|
|
return this.allPrice - this.couponAmount
|
|
|
+ },
|
|
|
+ hanldOrder() {
|
|
|
+ return {
|
|
|
+ order: this.orderInfo
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
filters: {
|
|
@@ -158,13 +164,13 @@ export default {
|
|
|
filterCouponList() {
|
|
|
const productList = []
|
|
|
this.goodsData.forEach(shop => productList.push(...shop.productList.map(prod => prod)))
|
|
|
- let canUseCouponList = []
|
|
|
- let notUseCouponList = []
|
|
|
- this.list = this.receiveCouponList.forEach(coupon => {
|
|
|
+ let canUseCouponList = [] // 可以使用的优惠券
|
|
|
+ let notUseCouponList = [] // 需要凑单使用的优惠券
|
|
|
+ this.receiveCouponList.forEach(coupon => {
|
|
|
if (
|
|
|
coupon.noThresholdFlag === 1 ||
|
|
|
- (coupon.productType === 1 && this.allProdoceUseCheck(productList, coupon)) ||
|
|
|
- (coupon.productType === 2 && this.someProductUseCheck(productList, coupon))
|
|
|
+ (coupon.productType === 1 && allProdoceUseCheck(productList, coupon)) ||
|
|
|
+ (coupon.productType === 2 && someProductUseCheck(productList, coupon))
|
|
|
) {
|
|
|
coupon.canSelect = true
|
|
|
canUseCouponList.push(coupon)
|
|
@@ -173,27 +179,15 @@ export default {
|
|
|
notUseCouponList.push(coupon)
|
|
|
}
|
|
|
})
|
|
|
- // 金额高的拍前面
|
|
|
- canUseCouponList = canUseCouponList.sort((a, b) => b.couponAmount - a.couponAmount)
|
|
|
- notUseCouponList = notUseCouponList.sort((a, b) => b.couponAmount - a.couponAmount)
|
|
|
- this.receiveCouponList = [...canUseCouponList, ...notUseCouponList]
|
|
|
+ // 金额高的排前面
|
|
|
+ this.receiveCouponList = [...couponSort(canUseCouponList), ...couponSort(notUseCouponList)]
|
|
|
// 当有可用优惠券时 默认选取第一个最优惠的
|
|
|
if (this.receiveCouponList.length > 0) {
|
|
|
this.currentCouponId = this.receiveCouponList[0].couponId
|
|
|
this.currentCoupon = this.receiveCouponList[0]
|
|
|
}
|
|
|
- },
|
|
|
- // 判断全部商品可用 是否可勾选使用
|
|
|
- allProdoceUseCheck(productList, coupon) {
|
|
|
- return productList.some(prod => prod.price * prod.productCount >= coupon.couponAmount)
|
|
|
- },
|
|
|
- // 判断指定商品可用 是否可勾选使用
|
|
|
- someProductUseCheck(productList, coupon) {
|
|
|
- return productList.some(
|
|
|
- prod =>
|
|
|
- coupon.productIds.indexOf(prod.productId.toString()) > -1 &&
|
|
|
- prod.price * prod.productCount >= coupon.couponAmount
|
|
|
- )
|
|
|
+ // 显示界面
|
|
|
+ this.isRequest = false
|
|
|
},
|
|
|
// 选中优惠券
|
|
|
chooseCoupon(coupon) {
|
|
@@ -205,17 +199,14 @@ export default {
|
|
|
this.currentCouponId = -1
|
|
|
}
|
|
|
this.couponVisible = false
|
|
|
- console.log(coupon)
|
|
|
},
|
|
|
//确认订单初始化信息
|
|
|
getInitCrearOrder(params) {
|
|
|
this.OrderService.QueryOrderConfirm(params)
|
|
|
.then(response => {
|
|
|
let data = response.data
|
|
|
- this.isRequest = true
|
|
|
this.goodsData = data.shopList
|
|
|
this.allPrice = data.totalPrice
|
|
|
-
|
|
|
this.fetchCouponList()
|
|
|
})
|
|
|
.catch(error => {
|
|
@@ -243,6 +234,8 @@ export default {
|
|
|
orderSubmitMit() {
|
|
|
//提交订单
|
|
|
if (this.isSubLoading) return
|
|
|
+ this.isSubLoading = true
|
|
|
+ this.loadingText = '正在创建订单...'
|
|
|
if (this.subParams.addressId == '') return this.$util.msg('请先添加收货地址~', 2000)
|
|
|
// 选中的优惠券id
|
|
|
this.subParams.couponId = this.currentCouponId === -1 ? '' : this.currentCouponId
|
|
@@ -259,62 +252,16 @@ export default {
|
|
|
})
|
|
|
return { shopId: el.shopId, note: el.note ? el.note : '', productInfo: productInfo }
|
|
|
})
|
|
|
- debugger
|
|
|
- this.isSubLoading = true
|
|
|
this.OrderService.CreatedOrderSubmit(this.subParams)
|
|
|
.then(response => {
|
|
|
const data = response.data
|
|
|
this.orderInfo = response.data
|
|
|
- setTimeout(() => {
|
|
|
- this.isSubLoading = false
|
|
|
- }, 2000)
|
|
|
- this.MiniWxPayFor(data)
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- this.$util.msg(error.msg, 2000)
|
|
|
- })
|
|
|
- },
|
|
|
- MiniWxPayFor(data) {
|
|
|
- this.PayService.PayOrderOnLineSwitch().then(response => {
|
|
|
- if (response.data === 1) {
|
|
|
- this.WeChatMiniWxPay(data)
|
|
|
- } else {
|
|
|
- this.$api.navigateTo(`/pages/user/order/order-payment?money=${data.payableAmount}`)
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- async WeChatMiniWxPay(data) {
|
|
|
- const wechatCode = await authorize.getCode('weixin')
|
|
|
- this.PayService.WeChatMiniWxPay({
|
|
|
- payAmount: data.payableAmount * 100,
|
|
|
- payWay: 'WEIXIN',
|
|
|
- code: wechatCode,
|
|
|
- orderId: data.orderId
|
|
|
- })
|
|
|
- .then(response => {
|
|
|
- let PayInfo = JSON.parse(response.data.data.payInfo)
|
|
|
- this.WxRequestPayment(PayInfo)
|
|
|
+ this.miniWxPayFor(data)
|
|
|
})
|
|
|
.catch(error => {
|
|
|
this.$util.msg(error.msg, 2000)
|
|
|
+ this.isSubLoading = false
|
|
|
})
|
|
|
- },
|
|
|
- WxRequestPayment(data) {
|
|
|
- let self = this
|
|
|
- wx.requestPayment({
|
|
|
- timeStamp: data.timeStamp,
|
|
|
- nonceStr: data.nonceStr,
|
|
|
- package: data.package,
|
|
|
- signType: data.signType,
|
|
|
- paySign: data.paySign,
|
|
|
- success: function(res) {
|
|
|
- wx.reLaunch({ url: '/pages/tabBar/index/index' })
|
|
|
- },
|
|
|
- fail: function(res) {
|
|
|
- self.$api.redirectTo(`/pages/user/order/success?data=${JSON.stringify({ data: self.orderInfo })}`)
|
|
|
- },
|
|
|
- complete: function(res) {}
|
|
|
- })
|
|
|
}
|
|
|
},
|
|
|
onShow() {
|