Commit a2a76c59 authored by 何毅恒's avatar 何毅恒

优化立即购买时未登录逻辑

parent 31b8e911
......@@ -11,7 +11,7 @@
:src="goods.cover"
mode="aspectFit"
/>
<view class="font-28 font-bold">{{goods.title}}</view>
<view class="font-28 font-bold">{{ goods.title }}</view>
</view>
<scroll-view scroll-y class="sku-list w-100 font-28">
......@@ -22,7 +22,7 @@
:key="index"
>
<view class="w-100 flex j-between a-center mb-2">
<view class="flex-1">{{item.spec_str}}</view>
<view class="flex-1">{{ item.spec_str }}</view>
<view class="step-wrap">
<!-- <input-number
:defaultVal="item.counts"
......@@ -48,17 +48,17 @@
<text>询价</text>
</template>
<template v-else>
<text>{{item.price}}</text>
<text class="originPrice ml-1">{{item.original_price || 0}}</text>
<text>{{ item.price }}</text>
<text class="originPrice ml-1">{{ item.original_price || 0 }}</text>
</template>
</view>
<view class="flex-1 text-center">
<text v-if="item.inventory > 0">{{'库存:' + item.inventory}}</text>
<text v-if="item.inventory > 0">{{ '库存:' + item.inventory }}</text>
<text v-else class="primaryColor">库存需咨询商家</text>
</view>
<view class="payCount text-center">
<text v-if="~~item.origin_number_sku">{{item.origin_number_sku + item.unit}}起购</text>
<text v-if="~~item.origin_number_sku">{{ item.origin_number_sku + item.unit }}起购</text>
</view>
</view>
......@@ -68,7 +68,8 @@
v-for="tiered_pri in item.tiered_pri"
:key="tiered_pri.num"
>
¥{{tiered_pri.price }}<text class="ml-1">≥{{tiered_pri.num + item.unit}}</text>
¥{{ tiered_pri.price }}
<text class="ml-1">≥{{ tiered_pri.num + item.unit }}</text>
</view>
</view>
</view>
......@@ -77,8 +78,10 @@
<view class="flex w-100 a-center flex-column font-28 mt-2">
<view class="as-end">
<text class="primaryColor">{{totalCounts}}</text>{{goods.unit || ''}}
<text class=" ml-2 price primaryColor">¥{{~~goods.is_inquiry ? '--' : totalPrice}}</text>
<text class="primaryColor">{{ totalCounts }}</text>
{{ goods.unit || '' }}
<text class=" ml-2 price primaryColor">¥{{ ~~goods.is_inquiry ? '--' : totalPrice }}</text>
</view>
</view>
......@@ -92,12 +95,14 @@
</template>
<script>
import uniPopup from '@/components/uni-popup/index.vue'
import price from '@/components/price/index.vue'
import inputNumber from '@/components/inputNumber/index.vue'
import { addCart } from '@/apis/carts.js'
import {addCart} from '@/apis/carts.js'
import common from './common.js'
import { mapActions, mapState } from 'vuex'
import {mapActions, mapState} from 'vuex'
export default {
name: 'goods-popup',
props: {
......@@ -125,15 +130,19 @@ export default {
...mapState({
isIphoneX: state => state.systemInfo.isIphoneX
}),
...mapState({
hasToken: state => state.user.token
}),
btnBottom() {
if(this.fitIphoneX) {
if (this.fitIphoneX) {
return `bottom: ${this.isIphoneX}px`
} else {
return 'bottom: 0'
}
},
warpFIt() {
if(this.fitIphoneX) {
if (this.fitIphoneX) {
return `padding-bottom: 186rpx`
} else {
return 'padding-bottom: 118rpx'
......@@ -160,8 +169,8 @@ export default {
goodsSku sku
*/
async show(params) {
try{
if(!params.skuData) return this.$toast({title: '该商品暂无规格'})
try {
if (!params.skuData) return this.$toast({title: '该商品暂无规格'})
this.goods = params.goodsInfo
this.skuData = JSON.parse(JSON.stringify(params.skuData))
this.skuData.forEach(item => {
......@@ -170,7 +179,7 @@ export default {
})
this.total()
this.$refs.goodsPopup.open()
}catch(e){
} catch (e) {
console.log(e)
this.$toast({title: e.msg || '程序错误'})
}
......@@ -181,7 +190,7 @@ export default {
},
popchange(e) {
if(!e.show) {
if (!e.show) {
this.init()
}
},
......@@ -195,16 +204,18 @@ export default {
total() {
const skuData = this.skuData
this.totalCounts = skuData.reduce((pre, cur) => { return pre + ~~cur.counts}, 0)
this.totalCounts = skuData.reduce((pre, cur) => {
return pre + ~~cur.counts
}, 0)
this.totalPrice = skuData.reduce((pre, cur) => {
const price = +cur.price
const counts = +cur.counts
if(cur.is_tiered === '1') { // 阶梯价 询价不管,不展示,按固定价计算
if (cur.is_tiered === '1') { // 阶梯价 询价不管,不展示,按固定价计算
const tiered_pri = cur.tiered_pri
for(let i = 0, j = tiered_pri.length; i < j; i ++) {
if(counts >= tiered_pri[j-1].num) {
return pre + tiered_pri[j-1].price * counts
} else if(tiered_pri[i].num > counts) {
for (let i = 0, j = tiered_pri.length; i < j; i++) {
if (counts >= tiered_pri[j - 1].num) {
return pre + tiered_pri[j - 1].price * counts
} else if (tiered_pri[i].num > counts) {
return pre + (i - 1 >= 0 ? tiered_pri[i - 1].price : price) * counts
}
}
......@@ -217,11 +228,11 @@ export default {
// 加入购物车
handleCart() {
const skuData = this.skuData
if(this.totalCounts === 0) return this.$toast({title: '请选择购买数量'})
if (this.totalCounts === 0) return this.$toast({title: '请选择购买数量'})
// if(!this.judgePay(skuData)) return this.$toast({title: '购买数量不能少于起购数量'})
const fn = []
for(let i = 0, j = skuData.length; i < j; i ++) {
if(skuData[i].counts) {
for (let i = 0, j = skuData.length; i < j; i++) {
if (skuData[i].counts) {
fn.push(addCart({
goods_id: skuData[i].goods_id,
cart_number: skuData[i].counts,
......@@ -242,15 +253,15 @@ export default {
// 下单
handlePay() {
try{
try {
const skuData = this.skuData
if(!skuData.length) return
if(!this.totalCounts) return this.$toast({title: '请选择购买数量'})
if(!this.judgePay(skuData)) return this.$toast({title: '购买数量不能少于起购数量'})
if (!skuData.length) return
if (!this.totalCounts) return this.$toast({title: '请选择购买数量'})
if (!this.judgePay(skuData)) return this.$toast({title: '购买数量不能少于起购数量'})
const sku_ids = []
const cart_numbers = []
for(let i = 0, j = skuData.length; i < j; i ++) {
if(skuData[i].counts) {
for (let i = 0, j = skuData.length; i < j; i++) {
if (skuData[i].counts) {
sku_ids.push(skuData[i].sku_id)
cart_numbers.push(skuData[i].counts)
}
......@@ -260,11 +271,22 @@ export default {
sku_ids: sku_ids.join(','),
cart_numbers: cart_numbers.join(',')
}
// 判断有无登录
if(!this.hasToken){
uni.navigateTo({
url: "/pages/login/index"
})
}else{
uni.navigateTo({
url: `/pages/order/confirm-order?params=${encodeURIComponent(JSON.stringify(params))}`
})
this.hide()
}catch(e){
}
} catch (e) {
console.log(e)
}
}
......@@ -287,9 +309,11 @@ export default {
.sku-list {
height: 372rpx;
@include borderBox(0, 20rpx);
.sku-item {
border-bottom: 1rpx solid $line;
}
.step-wrap {
flex: 0 0 224rpx;
width: 224rpx;
......@@ -304,6 +328,7 @@ export default {
.price-txt {
color: $primary;
.originPrice {
color: $desc;
text-decoration: line-through;
......@@ -319,14 +344,17 @@ export default {
bottom: 0;
z-index: 2;
height: 98rpx;
.btn-cart, .btn-pay {
color: #fff;
font-weight: bold;
line-height: 98rpx;
}
.btn-cart {
background-color: #FFBB33;
}
.btn-pay {
background-color: $primary;
}
......
......@@ -249,6 +249,7 @@ export default {
async supportCashOnDelivery(shop_id){
const {code,data} = await isSupportCashOnDelivery(shop_id);
this.isSupportCOD = data;
console.log(this.isSupportCOD)
},
......@@ -385,7 +386,6 @@ export default {
const { status, data } = await confirmOrder(form)
if(status) {
cb && typeof cb === 'function' && cb(data.order_sn)
console.log(data)
// const a = await pay({order_sn: data.order_sn, openid: this.openid})
// console.log(a)
// wxPay({params: a.data, })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment