微信小程序商城项目实战(第七篇:生成订单支付页)

微信小程序商城项目实战(第七篇:生成订单支付页)订单支付分析代码实现效果图展示分析顶部改为”支付”上方为地址,跳转至地址管理,可修改下方为订单信息最下方显示所需支付金额以及支付按钮,点击支付则支付成功跳转订单页如果不支付则可以在我的订单内容查看该订单并且继续支付代码实现改变顶部导航内容”navigationBarTitleText”:”支付”界面:<navigatorurl=”/pages/addressList/addressList”class=”user_info_row”wx:if=”{{statu!=’待发

大家好,又见面了,我是你们的朋友全栈君。

分析

顶部改为”支付”
上方为地址,跳转至地址管理,可修改
下方为订单信息
最下方显示所需支付金额以及支付按钮,点击支付则支付成功跳转订单页
如果不支付则可以在我的订单内容查看该订单并且继续支付

代码实现

改变顶部导航内容"navigationBarTitleText": "支付"
界面:

<navigator url="/pages/addressList/addressList" class="user_info_row" wx:if="{ 
    {statu!='待发货'}}">
  <view class="user_info" wx:for="{ 
    {addressList}}" wx:if="{ 
    {item.statu==true}}" wx:key="index">
    <view>{
  
  {item.name}}</view>
    <view>{
  
  {item.city}}{
  
  {item.address}}</view>
  </view>
  <view class="user_phone">{
  
  {item.tel}}</view>
</navigator>

<view class="user_info_row" wx:if="{ 
    {statu=='待发货'}}">
  <view class="user_info" wx:for="{ 
    {address}}" wx:key="index">
    <view>{
  
  {item.name}}</view>
    <view>{
  
  {item.city}}{
  
  {item.address}}</view>
  </view>
  <view class="user_phone">{
  
  {item.tel}}</view>
</view>

<!--购物车的内容-->
<view class="cart_content">
  <view class="cart_title">订单</view>
  <view class="cart_main">
    <!--当cart数组不为0显示 -->

    <view class="cart_item" wx:for="{ 
    {payList}}" wx:key="index">

      <!--商品图片-->
      <navigator class="cart_img_wrap">
        <image src="{ 
    {item.goods.goods_small_logo}}" mode="widthFix" />
      </navigator>
      <!--商品信息-->
      <view class="cart_info_wrap">
        <view class="goods_name">
          {
  
  {item.goods.goods_name}}
        </view>
        <view class="goods_price_wrap">
          <view class="goods_price">¥{
  
  {item.goods.goods_price}}</view>
          <view class="cart_num_tool">
            <view class="goods_num">X {
  
  {item.shu}}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</view>

<!--底部工具栏-->
<view class="footer_tool" wx:if="{ 
    {statu!='待发货'}}">

  <!--总价格-->
  <view class="total_price_wrap">
    <view class="total_price">
      合计
      <text class="total_price_text">¥{
  
  {sum}}</text>
    </view>
    <view>
      包含运费
    </view>

  </view>
  <!--结算-->
  <view class="order_pay_wrap" bindtap="payshop">支付({
  
  {num}})</view>
</view>

js

  • payList:支付的信息,即支付的商品列表
  • addressList:所有的收货地址
  • sum:总金额
  • num:数量
  • orderid:订单id
  • statu:订单状态
  • address:所选择的收货地址

函数:

  • onLoad(options)页面加载执行,主要是提供订单信息
  • onshow()页面显示时执行,主要是进行判断该订单的状态并且进行赋值
  • payshop():支付函数
// pages/pay/pay.js
Page({ 
   

    /** * 页面的初始数据 */
    data: { 
   
        payList:[],
        addressList:[],
        sum:0,
        num:0,
        orderid:0,
        statu:'待付款',
        address:[]
    },

    /** * 生命周期函数--监听页面加载 */
    onLoad: function (options) { 
   
        let order1=wx.getStorageSync('orderList')||[];
        var newpaylist=[];
        console.log(options.orderid);
        let sum=0;
        let num=0;
        let orid=0;
        let zt='待付款';
        if(options.orderid!=undefined){ 
   
            newpaylist=order1.filter((item)=>{ 
   
                return item.orderid==options.orderid;
            })
            sum=newpaylist[0].goods[0].sum;
            num=newpaylist[0].goods[0].num;
            orid=options.orderid;
            zt=newpaylist[0].statu;
            this.setData({ 
   
                payList:newpaylist[0].goods
            })
        }else{ 
   
            newpaylist=wx.getStorageSync('payList')||[];
            sum=newpaylist[0].sum;
            num=newpaylist[0].num;
            orid=newpaylist[0].orderid;
            this.setData({ 
   
                payList:newpaylist
            })
            
        }
        
        console.log(orid);
        this.setData({ 
   
            sum:sum,
            num:num,
            orderid:orid,
            statu:zt
        })
        console.log(this.data.payList);
        var order=wx.getStorageSync('orderList')||[];
        if(order.length==0){ 
   
            let ord=[];
            order={ 
   
                goods:this.data.payList,
                statu:'待付款',
                orderid:this.data.orderid
            };
            console.log(order);
            ord.push(order)
            wx.setStorageSync('orderList',ord)
        }else{ 
   
            
            let flag=order.findIndex((item)=>{ 
   
                return item.orderid==this.data.payList[0].orderid;
            })
            if(flag==-1){ 
   
                let ord={ 
   
                    goods:this.data.payList,
                    statu:'待付款',
                    orderid:this.data.orderid
                }
                order.push(ord)
                wx.setStorageSync('orderList',order)
            }else{ 
   
                console.log('已存在该订单');
            }
        }
    },

    /** * 生命周期函数--监听页面初次渲染完成 */
    onReady: function () { 
   

    },

    /** * 生命周期函数--监听页面显示 */
    onShow: function () { 
   
        let addressList=wx.getStorageSync('address')||[];
        this.setData({ 
   
            addressList:addressList
        })
        let address=wx.getStorageSync('orderList')||[];
        console.log(this.data.orderid);
        let index=address.findIndex((item)=>{ 
   
            return item.orderid==this.data.orderid;
        })
        this.setData({ 
   
            address: address[index]
        })
    },
    //支付
    payshop(){ 
   
        let order=wx.getStorageSync('orderList')||[];
        let addressList=wx.getStorageSync('address')||[];
        let flag=order.findIndex((item)=>{ 
   
            return item.orderid==this.data.payList[0].orderid;
        })
        var address=addressList[0];
        for(let i=0;i<addressList.length;i++){ 
   
            if(addressList[i].statu==true){ 
   
                console.log(addressList);
                address=addressList[i];
            }
        }
        var sz=[];
        
        wx.showModal({ 
   
            title: '提示',
            content: '确认支付?',
            success (res) { 
   
              if (res.confirm) { 
   
                if(address.address==undefined){ 
   
                    for(let j=0;j<order.length;j++){ 
   
                        let new1={ 
   
                        goods:order[j].goods,
                        orderid:order[j].orderid,
                        statu:'待发货',
                        address:address
                        }
                        sz.push(new1)
                    }
                }else{ 
   
                    order[flag].address=address;
                    order[flag].statu='待发货'
                    console.log(order[flag]);
                    sz=order;
                }
                // sz[flag].statu='待发货';
                wx.setStorageSync('orderList', sz);//更新状态
                wx.showToast({ 
   
                    title: '正在支付',
                    icon:"loading",
                    duration: 800//持续的时间
                })
                wx.showToast({ 
   
                    title: '支付成功',
                    icon:"success",
                    duration: 800//持续的时间
                })
                wx.redirectTo({ 
   
                  url: '/pages/order/order',
                })
              } else if (res.cancel) { 
   
                wx.showToast({ 
   
                    title: '支付失败',
                    icon:"error",
                    duration: 800//持续的时间
                })
              }
            }
          })
          
    }
})

css样式

page { 
   
    padding-bottom: 90rpx;
  }
  .cart_content .cart_title { 
   
    padding: 20rpx;
    color: var(--themeColor);
    font-size: 36rpx;
    border-top: 1px solid currentColor;
    border-bottom: 1px solid currentColor;
  }
  .cart_content .cart_main .cart_item { 
   
    display: flex;
    padding: 10rpx;
    border-bottom: 1px solid #ccc;
  }
  .cart_content .cart_main .cart_item .cart_img_wrap { 
   
    flex: 2;
    display: flex;
    justify-content: center;
    align-items: center;
   
  }
  .cart_content .cart_main .cart_item .cart_img_wrap image{ 
   
    width: 80%;
  }
  .cart_content .cart_main .cart_item .cart_info_wrap { 
   
    flex: 4;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
  .cart_content .cart_main .cart_item .cart_info_wrap .goods_name { 
   
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    color: #666;
  }
  .cart_content .cart_main .cart_item .cart_info_wrap .goods_price_wrap { 
   
    display: flex;
    justify-content: space-between;
  }
  .cart_content .cart_main .cart_item .cart_info_wrap .goods_price_wrap .goods_price { 
   
    color: var(--themeColor);
    font-size: 34rpx;
  }
  .cart_content .cart_main .cart_item .cart_info_wrap .goods_price_wrap .cart_num_tool { 
   
    display: flex;
  }
  .cart_content .cart_main .cart_item .cart_info_wrap .goods_price_wrap .cart_num_tool .goods_num { 
   
    width: 50rpx;
    height: 50rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .footer_tool { 
   
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 90rpx;
    background-color: #fff;
    display: flex;
    border-top: 1px solid #ccc;
  }
  .footer_tool .total_price_wrap { 
   
    flex: 4;
    padding-left: 15rpx;
  }
  .footer_tool .total_price_wrap .total_price .total_price_text { 
   
    color: var(--themeColor);
    font-size: 34rpx;
    font-weight: 600;
  }
  .footer_tool .order_pay_wrap { 
   
    flex: 3;
    background-color: var(--themeColor);
    font-size: 32rpx;
    font-weight: 600;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  

效果图展示

订单生成
在这里插入图片描述

点击支付时:在这里插入图片描述

点击确认即可支付成功,取消则支付失败,
后续可在订单列表查看,这里还没有做,后续做~
完成~

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/136871.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • 智能优化算法简介

    智能优化算法简介智能优化算法:受人类智能、生物群体社会性或自然现象规律的启发。主要包括:(1)遗传算法:模仿自然界生物进化机制(2)差分进化算法:通过群体个体间的合作与竞争来优化搜索(3)免疫算法:模拟生物免疫系统学习和认知功能(4)蚁群算法:模拟蚂蚁集体寻径行为(5)粒子群算法:模拟鸟群和鱼群群体行为(6)模拟退火算法:源于固体物质退火过程(7)禁忌搜索算法:模拟人类智力记忆过程(8)…

    2022年5月10日
  • Java连接MySQL mysql-connector-java-bin.jar驱动包的下载与安装

    Java连接MySQL mysql-connector-java-bin.jar驱动包的下载与安装eclipse在连接mysql数据库的时候要通过mysql驱动包进行连接首先进入官网中—-官网地址:https://dev.mysql.com/进入官网中选择DOWNLOADS(下载)2.选择下载中的mysql-connectors3.选择connector/JJ指的是Java4.接下在选择操作系统,此处选择platformindependent(独立于平台)…

    2022年5月21日
  • 1.2.太极平台框架简介

    1.2.太极平台框架简介1、太极平台框架简介太极平台框架,是专为制作管理后台系统而开发的一个框架。使用该框架,可以非常快速的搭建后台管理系统。针对于列表、以及增删改查这种通用的功能,太极框架只需要配置列表有哪些字段,以及这些字段的一些属性,就能创建出一个增删改查的功能。不需要编写任何代码即可完成。列表功能可设置字段的各种显示效果,自动格式化各种类型的字段数据。比如只需要设置字段为搜索项,就自动拥有搜索功能。添…

    2022年6月4日
  • 网站前端和后台性能优化21

    网站前端和后台性能优化21

    2022年3月13日
  • 建立友好城市有什么用_缔结友好城市

    建立友好城市有什么用_缔结友好城市原题连接Palmia国有一条横贯东西的大河,河有笔直的南北两岸,岸上各有位置各不相同的N个城市。北岸的每个城市有且仅有一个友好城市在南岸,而且不同城市的友好城市不相同。每对友好城市都向政府申请在河上开辟一条直线航道连接两个城市,但是由于河上雾太大,政府决定避免任意两条航道交叉,以避免事故。编程帮助政府做出一些批准和拒绝申请的决定,使得在保证任意两条航线不相交的情况下,被批准的申请尽量多。输入格式第1行,一个整数N,表示城市数。第2行到第n+1行,每行两个整数,中间用1个空格隔开,分别表示南岸和

    2022年8月8日
  • zoj2781

    zoj2781zoj2781

    2022年7月16日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号