shopCar.js
2.9 KB
"use strict";const e=require("../../common/vendor.js"),r=require("../../api/index.js");require("../../utils/request.js");Array||e.resolveComponent("u-navbar")();const b=()=>"../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";Math||b();const T={__name:"shopCar",setup(i){e.onShow(()=>{a(),e.index.getStorageSync("defaultAdres")&&(o.adress=e.index.getStorageSync("defaultAdres").diqu+e.index.getStorageSync("defaultAdres").address),console.log("默认",o.adress)});let o=e.reactive({shopList:[],btnStatus:!0,adress:"请新建默认地址"});const h=()=>{console.log(o.btnStatus),o.btnStatus=!o.btnStatus},d=()=>{e.index.navigateTo({url:"/pages/mine/myAddress"})},p=t=>{o.shopList[t].checkType=!o.shopList[t].checkType},g=()=>{if(o.btnStatus){let t=o.shopList.filter(s=>s.checkType).map(s=>s.cart_id);e.index.navigateTo({url:`/pages/shopCar/confirmOrder?ids=${t.join(",")}`})}else{let t=o.shopList.filter(s=>s.checkType).map(s=>s.cart_id);_(t.join(","))}},_=async t=>{try{const s=await r.getDelCar(t);a(),e.index.showToast({title:"成功移出购物车~",icon:"none"}),console.log("getDelCar",s)}catch(s){e.index.showToast({title:s,icon:"none"}),console.log("getDelCar",s)}},u=(t,s)=>{if(t==0){if(s.total_num==1)return e.index.showToast({title:"至少一件哦~",icon:"none"});y(s.cart_id,s.total_num-1),s.total_num=s.total_num-1}else f(s.cart_id,s.total_num+1),s.total_num=s.total_num+1},f=async(t,s)=>{try{const n=await r.getCarAdd(t,s);a()}catch(n){e.index.showToast({title:n,icon:"none"})}},y=async(t,s)=>{try{const n=await r.getCarReduce(t,s);a()}catch(n){e.index.showToast({title:n,icon:"none"})}},v=()=>{c.value?o.shopList.forEach(t=>{t.checkType=!1}):o.shopList.forEach(t=>{t.checkType=!0})},a=async()=>{try{const t=await r.getCarList();t.goods_list.forEach(s=>s.checkType=!1),o.shopList=t.goods_list,console.log("是什么",o.shopList),console.log("getCarList",t)}catch(t){console.log("getCarList",t)}},c=e.computed(()=>o.shopList.every(t=>t.checkType===!0)),L=e.computed(()=>o.shopList.filter(t=>t.checkType).reduce((t,s)=>t+s.total_price*1,0));return(t,s)=>e.e({a:e.p({bgColor:"#F6F8FA",placeholder:!0,title:"购物车",autoBack:!0}),b:e.unref(o).shopList.length>0},e.unref(o).shopList.length>0?{c:e.t(e.unref(o).adress),d:e.o(d),e:e.t(e.unref(o).btnStatus?"管理":"完成"),f:e.o(h),g:e.f(e.unref(o).shopList,(n,C,k)=>e.e({a:!n.checkType},n.checkType?{}:{},{b:e.o(l=>p(C),n.id),c:n.image,d:n.status==0},n.status==0?{}:{},{e:e.t(n.name),f:e.t(n.goods_price),g:e.o(l=>u(0,n),n.id),h:e.t(n.total_num),i:e.o(l=>u(1,n),n.id),j:n.id}))}:{},{h:e.unref(o).shopList.length>0},e.unref(o).shopList.length>0?e.e({i:!e.unref(c)},e.unref(c)?{}:{},{j:e.o(v),k:e.unref(o).btnStatus},e.unref(o).btnStatus?{l:e.t(+e.unref(L).toFixed(2))}:{},{m:e.t(e.unref(o).btnStatus?"结算":"删除"),n:e.o(g)}):{})}},S=e._export_sfc(T,[["__file","D:/vue/大健康商城/healthMall/pages/shopCar/shopCar.vue"]]);wx.createPage(S);