123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- <template>
- <view class="container">
- <view class="choose">
- <view class="choose_address">
- <picker mode="selector" :range="addressList" @change="changeAddress">
- <view class="address-item">
- <text>收货地址:</text>
- <text>{{ selectedAddress }}</text>
- <van-icon name="arrow" color="#999" size="14px" />
- </view>
- </picker>
- <view class="add-address" @click="navigateToAddAddress">
- <van-icon name="plus" color="#ff6600" size="16px" />
- <text>添加地址</text>
- </view>
- </view>
- <view class="choose_time">
- <picker mode="selector" :range="timeList" @change="changeTime">
- <view class="time-item">
- <text>预计送达时间:</text>
- <text>{{ selectedTime }}</text>
- <van-icon name="arrow" color="#999" size="14px" />
- </view>
- </picker>
- </view>
- </view>
- <view class="payInfo">
- <view class="shop_title">{{ shopTitle }}</view>
- <view class="orderList">
- <view class="order-item" v-for="item in cart" :key="item.goods_id">
- <image class="goods-image" :src="item.goods_small_logo" mode="aspectFill"></image>
- <view class="goods-info">
- <text class="goods-name">{{ item.goods_name }}</text>
- <text class="goods-price">¥{{ item.goods_price }}</text>
- <text class="goods-count">x {{ item.goods_count }}</text>
- </view>
- <view>¥{{ item.goods_price*item.goods_count|toFixed(2) }}</view>
- </view>
- </view>
- <view class="tip">
- <text>温馨提示: 餐品已包装,请您尽快食用</text>
- </view>
- <view class="priceInfo">
- <view class="PackingFee">
- <text>餐盒费</text>
- <text>¥{{ PackingFee }}</text>
- </view>
- <view class="deliveryFee">
- <text>运费</text>
- <text>¥{{ deliveryFee }}</text>
- </view>
- <view class="disCount">
- <text>优惠券</text>
- <text>-¥{{ PackingFee+deliveryFee }}</text>
- </view>
- </view>
- </view>
- <view class="payBtn">
- <view class="left_info">
- <view class="totalPrice">合计: ¥{{ Number.parseFloat(checkedGoodsAmount()).toFixed(2) }}</view>
- <view class="discountPrice">已优惠: ¥{{ checkedGoodsAmount() - checkedGoodsAmount()+PackingFee+deliveryFee }}</view>
- </view>
- <view class="pay" @click="pay">提交订单</view>
- </view>
- </view>
- </template>
- <script>
- import { mapState, mapMutations, mapGetters } from 'vuex'
- export default {
- onLoad(args) {
- this.cart=this.getCart()
- this.addressList = this.getAddressList()
- console.log(this.addressList,"Listen")
- this.shopTitle=args.shopTitle
- this.storeId=args.storeId
- },
- onShow() {
- this.cart=this.getCart()
- this.addressList = this.getAddressList()
- console.log(this.addressList,"Listen")
- },
- data() {
- return {
- storeId:0,
- addressList: ['江西省上饶市', '南昌市青山湖区', '江西省上饶市', '南昌市青山湖区'],
- timeList: [this.getCurOfSet(10), this.getCurOfSet(15), this.getCurOfSet(20), this.getCurOfSet(25), this.getCurOfSet(30)], // 获取当前时间取整数进制+10
- shopTitle: '麦当劳',
- selectedAddress: '',
- selectedTime: this.getCurOfSet(10),
- cart:[],
- PackingFee: 1.5,
- deliveryFee: 3,
- orderList: []
- }
- },
- methods: {
- ...mapGetters('m_cart', ['total', 'checkedGoodsAmount','getCart']),
- ...mapGetters('m_addr', ['getAddressList']),
- ...mapMutations('m_cart', ['clearCart']),
- ...mapMutations('m_order', ['putOrder']),
- changeAddress(e) {
- this.selectedAddress = this.addressList[e.detail.value]
- },
- changeTime(e) {
- this.selectedTime = this.timeList[e.detail.value]
- },
- // pay() {
- // console.log(this.cart)
- // console.log(this.getCart())
- // },
- pay() {
- // 模拟微信支付流程
- uni.requestPayment({
- fail: () => {
- // 支付成功后生成订单数据
- const orderId = this.generateOrderId()
- const orderData = {
- id: orderId,
- addressList: this.addressList,
- selectedAddress: this.selectedAddress,
- timeList: this.timeList,
- orderTime: new Date().toLocaleString(),
- selectedTime: this.selectedTime,
- shopTitle: this.shopTitle,
- PackingFee: this.PackingFee,
- deliveryFee: this.deliveryFee,
- total: this.checkedGoodsAmount()
- }
- let userId = 1
- if (!uni.getStorageSync('userId')) {
- userId = 1
- }else{
- userId = uni.getStorageSync('userId')
- }
- let originPay=Number.parseFloat(this.checkedGoodsAmount())+Number.parseFloat(this.PackingFee)+Number.parseFloat(this.deliveryFee)
- let data =[]
- for(let i=0;i<this.cart.length;i++){
- data.push(
- {id:this.cart[i].goods_id, // TODO productId
- count:this.cart[i].goods_count,
- productName:this.cart[i].goods_name,
- amount:this.cart[i].goods_price*this.cart[i].goods_count
- ,productIcons:this.cart[i].goods_small_logo})
- }
- console.log(data,"data")
- let order=
- {
- // "address":this.selectedAddress,
- // "phone":"12345678901",
- "bidPay":this.checkedGoodsAmount(),
- "originPay":originPay,
- "addressId":9,
- "userId":userId,
- "storeId":1,
- "orderRemark":"无",
- "orderProductsLists":data
- }
- // {
- // "bidPay":this.checkedGoodsAmount(),
- // "originPay":originPay,
- // "addressId":9,
- // "userId":1,
- // "orderProductsLists":[
- // {
- // "productName":"芒果",
- // "count":12,
- // "cnt":12
- // },
- // {
- // "productName":"芒果",
- // "count":12,
- // "cnt":12
- // }
- // ]
- // }
- console.log(order,"order")
- this.orderList.push(order)
- this.putOrder(order)
- // 保存订单数据到本地
- console.log(order)
- uni.setStorageSync('orderList', this.orderList)
- // 跳转到订单详情页面
- // uni.navigateTo({
- // url: `/subpkg/orderDetail/orderDetail?orderId=${orderId}`
- // })
- //清空购物车
- this.clearCart()
- this.cart=[]
- //返回上一页
- uni.navigateBack({
- delta: 1
- })
- // 显示支付成功提示
- uni.showToast({
- title: '支付成功',
- icon: 'success',
- duration: 3000
- })
- // 3秒后自动关闭提示
- setTimeout(() => {
- uni.hideToast()
- }, 3000)
- },
- success: (e) => {
- console.log(e,"e")
- uni.showToast({
- title: '支付失败',
- icon: 'none',
- duration: 3000
- })
- }
- })
- },
- generateOrderId() {
- // 生成随机订单号
- return Math.random().toString(36).substr(2, 9)
- },
- navigateToAddAddress() {
- uni.navigateTo({
- url: '/subpkg/addAddress/addAddress'
- })
- },
- getCurOfSet(offset){ //获取时间偏移
- // 获取当前时间
- var currentTime = new Date();
- // 获取小时和分钟
- var hours = currentTime.getHours();
- var minutes = currentTime.getMinutes();
- // 添加 10 分钟
- minutes = minutes + offset;
- if (minutes >= 60) {
- hours = hours + 1;
- minutes = minutes % 60;
- }
- // 调整小时,如果超过 24 小时,则回到 0
- hours = hours % 24;
- // 格式化小时和分钟为两位数
- hours = (hours < 10 ? "0" : "") + hours;
- minutes = (minutes < 10 ? "0" : "") + minutes;
- // 格式化结果
- var formattedTime = hours + ":" + minutes;
- // 输出结果
- return formattedTime
- }
- },
- filters: {
- toFixed(val) {
- return Number(val).toFixed(2)
- }
- }
- }
- </script>
- <style lang="scss">
- .container {
- padding: 20rpx;
- background-color: #f7f7f7;
- }
- .choose {
- display: flex;
- justify-content: space-between;
- background-color: #fff;
- //col
- flex-direction: column;
- padding: 20rpx;
- border-radius: 10rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
- .choose_address,
- .choose_time {
- flex: 1;
- .address-item,
- .time-item {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
- font-size: 35rpx;
- color: #333;
- }
- }
- }
- .payInfo {
- margin-top: 20rpx;
- background-color: #fff;
- padding: 20rpx;
- border-radius: 10rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
- .shop_title {
- font-size: 32rpx;
- font-weight: bold;
- margin-bottom: 20rpx;
- color: #ff6600;
- }
- .orderList {
- .order-item {
- display: flex;
- align-items: center;
- margin-bottom: 20rpx;
- .goods-image {
- width: 120rpx;
- height: 120rpx;
- border-radius: 10rpx;
- margin-right: 20rpx;
- }
- .goods-info {
- flex: 1;
- .goods-name {
- font-size: 28rpx;
- color: #333;
- }
- .goods-price {
- font-size: 26rpx;
- color: #ff6600;
- margin-right: 10rpx;
- }
- .goods-count {
- font-size: 24rpx;
- color: #999;
- }
- }
- }
- }
- .tip {
- font-size: 24rpx;
- color: #999;
- margin: 20rpx 0;
- }
- .priceInfo {
- display: flex;
- justify-content: space-between;
- font-size: 26rpx;
- color: #333;
- view {
- display: flex;
- justify-content: space-between;
- margin-bottom: 10rpx;
- }
- }
- }
- .payBtn {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 20rpx;
- padding: 20rpx;
- background-color: #fff;
- border-radius: 10rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
- .left_info {
- .totalPrice {
- font-size: 32rpx;
- font-weight: bold;
- color: #ff6600;
- }
- .discountPrice {
- font-size: 24rpx;
- color: #999;
- }
- }
- .pay {
- background-color: #ff6600;
- color: #fff;
- font-size: 28rpx;
- padding: 10rpx 20rpx;
- border-radius: 30rpx;
- }
- }
- /* 样式保持不变 */
- .choose_address {
- display: flex;
- justify-content: space-between;
- align-items: center;
- .add-address {
- display: flex;
- align-items: center;
- font-size: 26rpx;
- color: #ff6600;
- }
- }
- </style>
- <!--<template>-->
- <!-- <view class="container">-->
- <!-- <view class="choose">-->
- <!-- <view class="choose_address">-->
- <!-- <picker mode="selector" :range="addressList" @change="changeAddress">-->
- <!-- <view class="address-item">-->
- <!-- <text>收货地址</text>-->
- <!-- <text>{{ selectedAddress }}</text>-->
- <!-- <van-icon type="arrowright" size="16"></van-icon>-->
- <!-- </view>-->
- <!-- </picker>-->
- <!-- </view>-->
- <!-- <view class="choose_time">-->
- <!-- <picker mode="selector" :range="timeList" @change="changeTime">-->
- <!-- <view class="time-item">-->
- <!-- <text>预计送达时间</text>-->
- <!-- <text>{{ selectedTime }}</text>-->
- <!-- <van-icon type="arrowright" size="16"></van-icon>-->
- <!-- </view>-->
- <!-- </picker>-->
- <!-- </view>-->
- <!-- </view>-->
- <!-- <view class="payInfo">-->
- <!-- <view class="shop_title">{{ shopTitle }}</view>-->
- <!-- <view class="orderList">-->
- <!-- <view class="order-item" v-for="item in cart" :key="item.goods_id">-->
- <!-- <image class="goods-image" :src="item.goods_small_logo" mode="aspectFill"></image>-->
- <!-- <view class="goods-info">-->
- <!-- <text class="goods-name">{{ item.goods_name }}</text>-->
- <!-- <text class="goods-price">¥{{ item.goods_price }}</text>-->
- <!-- <text class="goods-count">x {{ item.goods_count }}</text>-->
- <!-- </view>-->
- <!-- </view>-->
- <!-- </view>-->
- <!-- <view class="tip">-->
- <!-- <text>温馨提示: 餐品已包装,请您尽快食用</text>-->
- <!-- </view>-->
- <!-- <view class="priceInfo">-->
- <!-- <view class="PackingFee">-->
- <!-- <text>餐盒费</text>-->
- <!-- <text>¥{{ PackingFee }}</text>-->
- <!-- </view>-->
- <!-- <view class="deliveryFee">-->
- <!-- <text>运费</text>-->
- <!-- <text>¥{{ deliveryFee }}</text>-->
- <!-- </view>-->
- <!-- <view class="disCount">-->
- <!-- <text>优惠券</text>-->
- <!-- <text>-¥0</text>-->
- <!-- </view>-->
- <!-- </view>-->
- <!-- </view>-->
- <!-- <view class="payBtn">-->
- <!-- <view class="left_info">-->
- <!-- <view class="totalPrice">合计: ¥{{ total }}</view>-->
- <!-- <view class="discountPrice">已优惠: ¥{{ checkedGoodsAmount - total }}</view>-->
- <!-- </view>-->
- <!-- <view class="pay">提交订单</view>-->
- <!-- </view>-->
- <!-- </view>-->
- <!--</template>-->
- <!--<script>-->
- <!--import { mapState, mapMutations, mapGetters } from 'vuex'-->
- <!--export default {-->
- <!-- onLoad() {-->
- <!-- console.log('吾问无为谓啊')-->
- <!-- },-->
- <!-- data() {-->
- <!-- return {-->
- <!-- addressList: ['江西省上饶市', '南昌市青山湖区'],-->
- <!-- timeList: ['18:00', '18:30', '19:00', '19:30', '20:00'],-->
- <!-- shopTitle: '麦当劳',-->
- <!-- selectedAddress: '江西省上饶市',-->
- <!-- selectedTime: '18:00',-->
- <!-- ...mapState('m_cart', ['cart']), //cart:商品信息列表。每个{}包括{goods_id,goods_name,goods_price,goods_count,goods_small_logo,goods_state}信息-->
- <!-- PackingFee: 1.5,-->
- <!-- deliveryFee: 3-->
- <!-- }-->
- <!-- },-->
- <!-- methods: {-->
- <!-- ...mapGetters('m_cart', ['total', 'checkedGoodsAmount']), //total:计算数量,checkedGoodsAmount:计算总价-->
- <!-- changeAddress(e) {-->
- <!-- this.selectedAddress = this.addressList[e.detail.value]-->
- <!-- },-->
- <!-- changeTime(e) {-->
- <!-- this.selectedTime = this.timeList[e.detail.value]-->
- <!-- }-->
- <!-- }-->
- <!--}-->
- <!--</script>-->
- <!--<style lang="scss">-->
- <!--.container {-->
- <!-- padding: 20rpx;-->
- <!--}-->
- <!--.choose {-->
- <!-- display: flex;-->
- <!-- justify-content: space-between;-->
- <!-- background-color: #fff;-->
- <!-- padding: 20rpx;-->
- <!-- border-radius: 10rpx;-->
- <!-- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);-->
- <!-- .choose_address,-->
- <!-- .choose_time {-->
- <!-- flex: 1;-->
- <!-- .address-item,-->
- <!-- .time-item {-->
- <!-- display: flex;-->
- <!-- align-items: center;-->
- <!-- justify-content: space-between;-->
- <!-- font-size: 28rpx;-->
- <!-- color: #333;-->
- <!-- }-->
- <!-- }-->
- <!--}-->
- <!--.payInfo {-->
- <!-- margin-top: 20rpx;-->
- <!-- background-color: #fff;-->
- <!-- padding: 20rpx;-->
- <!-- border-radius: 10rpx;-->
- <!-- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);-->
- <!-- .shop_title {-->
- <!-- font-size: 32rpx;-->
- <!-- font-weight: bold;-->
- <!-- margin-bottom: 20rpx;-->
- <!-- }-->
- <!-- .orderList {-->
- <!-- .order-item {-->
- <!-- display: flex;-->
- <!-- align-items: center;-->
- <!-- margin-bottom: 20rpx;-->
- <!-- .goods-image {-->
- <!-- width: 120rpx;-->
- <!-- height: 120rpx;-->
- <!-- border-radius: 10rpx;-->
- <!-- margin-right: 20rpx;-->
- <!-- }-->
- <!-- .goods-info {-->
- <!-- flex: 1;-->
- <!-- .goods-name {-->
- <!-- font-size: 28rpx;-->
- <!-- color: #333;-->
- <!-- }-->
- <!-- .goods-price {-->
- <!-- font-size: 26rpx;-->
- <!-- color: #ff6600;-->
- <!-- margin-right: 10rpx;-->
- <!-- }-->
- <!-- .goods-count {-->
- <!-- font-size: 24rpx;-->
- <!-- color: #999;-->
- <!-- }-->
- <!-- }-->
- <!-- }-->
- <!-- }-->
- <!-- .tip {-->
- <!-- font-size: 24rpx;-->
- <!-- color: #999;-->
- <!-- margin: 20rpx 0;-->
- <!-- }-->
- <!-- .priceInfo {-->
- <!-- display: flex;-->
- <!-- justify-content: space-between;-->
- <!-- font-size: 26rpx;-->
- <!-- color: #333;-->
- <!-- view {-->
- <!-- display: flex;-->
- <!-- justify-content: space-between;-->
- <!-- margin-bottom: 10rpx;-->
- <!-- }-->
- <!-- }-->
- <!--}-->
- <!--.payBtn {-->
- <!-- display: flex;-->
- <!-- justify-content: space-between;-->
- <!-- align-items: center;-->
- <!-- margin-top: 20rpx;-->
- <!-- padding: 20rpx;-->
- <!-- background-color: #fff;-->
- <!-- border-radius: 10rpx;-->
- <!-- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);-->
- <!-- .left_info {-->
- <!-- .totalPrice {-->
- <!-- font-size: 32rpx;-->
- <!-- font-weight: bold;-->
- <!-- color: #ff6600;-->
- <!-- }-->
- <!-- .discountPrice {-->
- <!-- font-size: 24rpx;-->
- <!-- color: #999;-->
- <!-- }-->
- <!-- }-->
- <!-- .pay {-->
- <!-- background-color: #ff6600;-->
- <!-- color: #fff;-->
- <!-- font-size: 28rpx;-->
- <!-- padding: 10rpx 20rpx;-->
- <!-- border-radius: 30rpx;-->
- <!-- }-->
- <!--}-->
- <!--</style>-->
- <!--<!–<template>–>-->
- <!--<!– <view>–>-->
- <!--<!– <view class="choose">–>-->
- <!--<!– <view class="choose_address"></view>–>-->
- <!--<!– <view class="choose_time"></view>–>-->
- <!--<!– </view>–>-->
- <!--<!– <view class="payInfo">–>-->
- <!--<!– <view class="shop_title"></view>–>-->
- <!--<!– <view class="orderList">–>-->
- <!--<!– </view>–>-->
- <!--<!– <view class="tip"></view>–>-->
- <!--<!– <view class="priceInfo">–>-->
- <!--<!– <view class="PackingFee"></view>–>-->
- <!--<!– <view class="deliveryFee"></view>–>-->
- <!--<!– <view class="disCount"></view>–>-->
- <!--<!– </view>–>-->
- <!--<!– </view>–>-->
- <!--<!– <view class="payBtn">–>-->
- <!--<!– <view class="left_info">–>-->
- <!--<!– <view class="totalPrice">合计...</view>–>-->
- <!--<!– <view class="discountPrice">已优惠...</view>–>-->
- <!--<!– </view>–>-->
- <!--<!– <view class="pay">提交订单</view>–>-->
- <!--<!– </view>–>-->
- <!--<!– </view>–>-->
- <!--<!–</template>–>-->
- <!--<!–<script>–>-->
- <!--<!–import {mapState,mapMutations,mapGetters} from'vuex'–>-->
- <!--<!–export default {–>-->
- <!--<!– onLoad() {–>-->
- <!--<!– console.log('吾问无为谓啊')–>-->
- <!--<!– },–>-->
- <!--<!– data() {–>-->
- <!--<!– return {–>-->
- <!--<!– addressList:['江西省上饶市','南昌市青山湖区'],–>-->
- <!--<!– timeList:['18:00','18:30','19:00','19:30','20:00'],–>-->
- <!--<!– shopTitle:'麦当劳',–>-->
- <!--<!– ...mapState('m_cart',['cart']),//cart:商品信息列表。每个{}包括{goods_id,goods_name,goods_price,goods_count,goods_small_logo,goods_state}信息–>-->
- <!--<!– PackingFee:0,–>-->
- <!--<!– deliveryFee:0,–>-->
- <!--<!– };–>-->
- <!--<!– },–>-->
- <!--<!– methods: {–>-->
- <!--<!– ...mapGetters('m_cart', {'total':'total','checkedGoodsAmount':'checkedGoodsAmount'}),//total:计算数量,checkedGoodsAmount:计算总价–>-->
- <!--<!– },–>-->
- <!--<!–}–>-->
- <!--<!–</script>–>-->
- <!--<!–<style lang="scss">–>-->
- <!--<!–</style>–>-->
|