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

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

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