<template>
|
|
<view class="page">
|
|
<navbar title="下单支付" leftClick @leftClick="$utils.navigateBack" />
|
|
|
|
<view class="box">
|
|
<!-- 地址 -->
|
|
<view class="address" @click="openAddress">
|
|
<image src="../static/address/icon1.png" mode=""></image>
|
|
<view class="">
|
|
{{ address.name }}
|
|
</view>
|
|
<view class="">
|
|
{{ address.address }}
|
|
</view>
|
|
<view class="icon">
|
|
<uv-icon size="30rpx" name="arrow-right"></uv-icon>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="productList">
|
|
<view class="item"
|
|
:key="index"
|
|
v-for="(item, index) in productList">
|
|
<view class="item-image">
|
|
<image :src="item.image &&
|
|
item.image.split(',')[0]"
|
|
mode="aspectFill"></image>
|
|
</view>
|
|
|
|
<view class="info">
|
|
<view class="title">
|
|
{{ item.title }}
|
|
</view>
|
|
<view class="desc">
|
|
{{ item.sku }}
|
|
</view>
|
|
<view class="price">
|
|
<view class="">
|
|
<uv-number-box
|
|
v-model="item.num"
|
|
></uv-number-box>
|
|
</view>
|
|
<view class="">
|
|
¥{{ item.price }}
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="submit-box">
|
|
<view class="peis">
|
|
<view class="">
|
|
配送方式
|
|
</view>
|
|
<view class="">
|
|
商家自行配送
|
|
</view>
|
|
</view>
|
|
<view class="priceInfo">
|
|
<view class="">
|
|
付款金额
|
|
</view>
|
|
<view class="totalPrice">
|
|
¥{{ totalPrice }}
|
|
</view>
|
|
</view>
|
|
<view class="remark">
|
|
<input type="text"
|
|
placeholder="请输入备注"
|
|
v-model="remark"/>
|
|
</view>
|
|
</view>
|
|
|
|
|
|
<view class="uni-color-btn"
|
|
@click="submit">
|
|
确认下单
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 地址选择 -->
|
|
<uv-popup ref="addressPopup" :round="30">
|
|
<addressList ref="addressList" height="60vh" @select="selectAddress" />
|
|
</uv-popup>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import addressList from '../components/address/addressList.vue'
|
|
import { mapState } from 'vuex'
|
|
export default {
|
|
components: {
|
|
addressList,
|
|
},
|
|
data() {
|
|
return {
|
|
productList: [],
|
|
address: {
|
|
name: '请选择地址',
|
|
address: '',
|
|
},
|
|
addressTotal: 0,
|
|
remark : '',
|
|
num : 1,
|
|
}
|
|
},
|
|
computed : {
|
|
totalPrice(){
|
|
let price = 0
|
|
|
|
this.productList.forEach(n => {
|
|
price += n.price * n.num
|
|
})
|
|
|
|
return Number(price).toFixed(2)
|
|
},
|
|
...mapState(['payOrderProduct']),
|
|
},
|
|
onLoad() {
|
|
this.getRiceProductDetail()
|
|
},
|
|
onShow() {
|
|
this.getAddressList()
|
|
},
|
|
methods: {
|
|
// 获取商品
|
|
getRiceProductDetail() {
|
|
this.productList = JSON.parse(JSON.stringify(this.payOrderProduct))
|
|
},
|
|
// 打开
|
|
getAddressList() {
|
|
// 获取地址列表
|
|
this.$refs.addressList.getAddressList().then(res => {
|
|
this.addressTotal = res.total
|
|
if (this.addressTotal != 0) {
|
|
this.address = res.records[0]
|
|
}
|
|
})
|
|
},
|
|
// 打开选择地址
|
|
openAddress() {
|
|
if (this.addressTotal == 0) {
|
|
return uni.navigateTo({
|
|
url: '/pages_order/mine/address?type=back'
|
|
})
|
|
}
|
|
this.$refs.addressPopup.open('bottom')
|
|
},
|
|
// 选择地址
|
|
selectAddress(e) {
|
|
this.address = e
|
|
this.$refs.addressPopup.close()
|
|
},
|
|
// 确认下单
|
|
// submit(){
|
|
// this.$api('createOrder', {
|
|
// productId : this.productList[0].id,
|
|
// num : 1,
|
|
// }, res => {
|
|
// if(res.code == 200){
|
|
// uni.showToast({
|
|
// title: '购买成功',
|
|
// icon: 'none'
|
|
// })
|
|
|
|
// setInterval(uni.navigateTo, 1000, {
|
|
// url : '/pages/index/order'
|
|
// })
|
|
// }
|
|
// })
|
|
// },
|
|
submit(){
|
|
|
|
let addressId = this.address.id
|
|
|
|
if(!addressId){
|
|
uni.showToast({
|
|
title: '请选择地址',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
let data = {}
|
|
let api = ''
|
|
|
|
if(this.productList[0].type == 2){//普通商品
|
|
let list = []
|
|
this.productList.forEach(n => {
|
|
list.push({
|
|
num : n.num,
|
|
shopId : n.shopId || n.id,
|
|
})
|
|
})
|
|
data = {
|
|
addressId,
|
|
list : JSON.stringify(list),
|
|
}
|
|
api = 'createSumOrder'
|
|
}else{//体验、常规商品
|
|
data = {
|
|
addressId,
|
|
num : this.productList[0].num,
|
|
productId : this.productList[0].id,
|
|
}
|
|
api = 'createOrder'
|
|
}
|
|
|
|
this.$api(api, data, res => {
|
|
if(res.code == 200){
|
|
uni.requestPaymentWxPay(res)
|
|
.then(res => {
|
|
uni.showToast({
|
|
title: '下单成功',
|
|
icon: 'none'
|
|
})
|
|
|
|
setTimeout(uni.navigateTo, 700, {
|
|
url: '/pages_order/order/order'
|
|
})
|
|
}).catch(n => {
|
|
setTimeout(uni.navigateTo, 500, {
|
|
url: '/pages_order/order/order'
|
|
})
|
|
})
|
|
}
|
|
})
|
|
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.page {
|
|
.box {
|
|
padding: 20rpx;
|
|
|
|
.address {
|
|
display: flex;
|
|
padding: 20rpx;
|
|
background-color: #fff;
|
|
align-items: center;
|
|
border-radius: 20rpx;
|
|
|
|
image {
|
|
width: 40rpx;
|
|
height: 40rpx;
|
|
margin: 20rpx;
|
|
}
|
|
|
|
view {
|
|
margin: 20rpx;
|
|
overflow: hidden; //超出的文本隐藏
|
|
text-overflow: ellipsis; //溢出用省略号显示
|
|
white-space: nowrap; //溢出不换行
|
|
}
|
|
|
|
.icon {
|
|
margin-left: auto;
|
|
}
|
|
}
|
|
|
|
.productList {
|
|
margin-top: 20rpx;
|
|
background-color: #fff;
|
|
border-radius: 20rpx;
|
|
.item {
|
|
padding: 10rpx 20rpx;
|
|
align-items: center;
|
|
margin-bottom: 20rpx;
|
|
display: flex;
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
.item-image {
|
|
width: 140rpx;
|
|
height: 140rpx;
|
|
flex-shrink: 0;
|
|
|
|
image {
|
|
height: 100%;
|
|
width: 100%;
|
|
border-radius: 20rpx;
|
|
}
|
|
}
|
|
|
|
.info {
|
|
padding: 20rpx;
|
|
color: #555;
|
|
flex: 1;
|
|
|
|
.title {
|
|
font-size: 28rpx;
|
|
font-weight: 900;
|
|
}
|
|
|
|
.desc {
|
|
font-size: 22rpx;
|
|
color: #777;
|
|
margin-top: 10rpx;
|
|
}
|
|
|
|
.price {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
color: #f40;
|
|
font-size: 30rpx;
|
|
font-weight: 900;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
.submit-box{
|
|
background-color: #fff;
|
|
padding: 20rpx;
|
|
border-radius: 20rpx;
|
|
&>view:nth-child(2){
|
|
margin-top: 20rpx;
|
|
}
|
|
&>view{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
font-size: 28rpx;
|
|
&>view:nth-child(1){
|
|
font-weight: 900;
|
|
}
|
|
&>view:nth-child(2){
|
|
color: #999;
|
|
font-size: 24rpx;
|
|
}
|
|
.totalPrice{
|
|
color: #f40 !important;
|
|
font-size: 34rpx !important;
|
|
font-weight: 900;
|
|
}
|
|
}
|
|
.remark{
|
|
margin-top: 30rpx;
|
|
input{
|
|
background-color: #f3f3f3;
|
|
padding: 14rpx 20rpx;
|
|
border-radius: 20rpx;
|
|
flex: 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|