美文网首页
商品结算

商品结算

作者: 2764906e4d3d | 来源:发表于2019-01-10 20:48 被阅读0次

获取数据

  1. 获取store中所有的商品的id,然后拼接,如果购物车中没有任何商品,则返回,不需要请求任何数据,否则会报错
getGoodsList(){
    var idArr=[];
    this.$store.state.car.forEach(item=>idArr.push(item.id));
    if(idArr.length<=0){
        return
    }
}
  1. [Vue warn]: Error in event handler for "click": "ReferenceError: state is not defined"报错
    将 localStorage.setItem移动到store中
  2. 在商品详情页面点击购买时,就会在购物车界面相应的添加一个商品列表组件
getGoodsList(){
    var idArr=[];
    this.$store.state.car.forEach(item=>idArr.push(item.id));
    if(idArr.length<=0){
        return
    }
    this.$http.get("/api/goodsList"+idArr.join(",")).then(res=>{
        if(res.body.status===0){
            this.goodslist=res.body;
        }
    })
}
  1. 在数字选择框组件中,每当数量值改变,则立即把最新的数量同步到购物车store中,覆盖之前的数量值
countChanged(){
    // this.$emit('getcount',parseInt(this.$refs.numbox.value))
    this.$store.commit('updateGoodsInfo
',{id:this.goodsid,
        count:this.$refs.numbox.value

    })

}
  1. 获取当前商品的数量和id值
<numbox
        :initcount="$store.getters.getGoodsCount[item.id]"
        :goodsid="item.id"
></numbox>
  1. 同步更新商品详情和购物车中的数据
updateGoodsInfo(state,goodsinfo){
    state.car.some(item=>{
        if(item.id==goodsinfo.id){
            item.count=parseInt(goodsinfo.count)
            return true
        }
    })
    localStorage.setItem('car',JSON.stringify(state.car))

},

删除商品清单

  1. 点击删除把商品从store中根据传递的ID删除,同时把当前组件中的goodslist中对应要删除的那个商品使用index删除
remove(id,index){
      this.goodslist.splice(index ,1)
}
  1. 根据id从store的 购物车中删除对应的商品数据
removeFormCar(state,id){
    state.car.some(item=>{
        if(item==id){
            state.car.splice(i,1)
            return true
            
        }
    })
    localStorage.setItem('car', JSON.stringify(state.car))

},

结算区域

  1. 设计结算区域样式
<div class="mui-card">
    <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
           <div class="left">
               <p>总计(不含运费)</p>
               <p>已勾选商品<span class="red">0</span>件,总价¥<span class="red">0</span></p>
           </div>
            <mt-button type="danger">结算</mt-button>
        </div>

    </div>
</div>
.jiesuan{
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.red{
    color: red;
    font-weight: bold;
    font-size: 16px;
}
  1. 每当点击开关,把最新的开关状态,同步到store中
   selectedChange(id,value){
       this.$store.commit('updateGoodsSelected',{id,selected:val})

   }
<mt-switch v-model="$store.getters.getGoodsSelected[item.id]"
           @change="selectedChange(item.id,$store.getters.getGoodsSelected[item.id])"
>
</mt-switch>

相关文章

  • 商品结算

    获取数据 获取store中所有的商品的id,然后拼接,如果购物车中没有任何商品,则返回,不需要请求任何数据,否则会...

  • 购物车可选择商品支付,功能设计

    老系统中购物车内所有商品只能全部结算,现在需要购物车内商品可选择结算,需求如下 需求描述 增加选择结算功能 点击提...

  • 手机淘宝购物车加支付原型图

    购物车页面原型图 说明: 1.购物车(x) x为购物车中商品种类数量(非总商品数量,同理结算(0) 0为结算时商品...

  • day54-天天生鲜项目订单管理

    1生成结算页面的相关数据 生成提交页面的商品种类及小计,总价等信息 寄送地址 所提交的商品详情页面 金额结算 aj...

  • 移动支付

    微信支付逻辑? 1、顾客选择商品 2、顾客选到心怡的商品找店员结算 3、店员拿着顾客交给他的商品生成预付单(后台服...

  • 循环数组判断

    思路:购物车去结算时,如果数组里的商品都没有被选中,则提示“请至少选择一件商品”,反之跳转至商品确认页面

  • 电商订单系统设计

    ​ 1、用户需求 买家需求: 常见的购物场景: 直接下单(单件商品购买) 购物车结算(多件商品购买) 拼团 定金购...

  • 竞品分析:购物车设计

    一、横向分析 常规的购物车功能:价格提醒、活动促销、凑单、商品收藏与删除、失效商品管理、合并结算。平台不同的定位,...

  • iOS设计模式-装饰者模式

    问题: 某煎饼店现有煎饼、手抓饼和烧饼三种商品出售,每种商品都可以另外加鸡蛋或者香肠,现要开发一套商品结算系统,那...

  • 闲鱼极速回收交易流程|闲鱼二手回收交易流程

    闲鱼各类目的回收交易流程如下: 1、卡券:填写商品信息→在线估价→下单→等待质检→结算钱款; 2、奢侈品:提交商品...

网友评论

      本文标题:商品结算

      本文链接:https://www.haomeiwen.com/subject/ucqzrqtx.html