123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- <template>
- <view class="container">
- <view class="swiper" :style="{height: getCartAllGoods() ? '120px' : '60px'}">
- <view class="swiper-text">共{{getCartAllGoods()}}件商品</view>
- <view v-if="cartsList.length" class="swiper-text" style="float: right;" @click="manageType = !manageType">{{manageType ? '完成' :'管理'}}</view>
- </view>
- <view class="cart-box" :style="{bottom: manageType ? '52px' : '0px'}">
- <view class="no-cart" v-if="!cartsList.length">
- <image class="no-cart-img" src="../../static/images/noCart.png" mode="aspectFill"></image>
- <text class="no-cart-text">购物车暂无商品</text>
- <u-button type="success" shape="circle" :ripple="true" :hair-line="false" :plain="true" @click="goToMall" class="button1">去逛逛</u-button>
- </view>
- <view v-if="cartsList.length" class="shop-row" v-for="(item, index1) in cartsList" :key="index1">
- <view class="shop-info">
- <view class="iconfont" :class="item.allCheck ? 'iconqueding' : 'iconfeigouxuan'" @click="checkShop(item)"></view>
- <view class="shop-info-right" @click="goToShop(item)">
- <view class="iconfont iconshangjia"></view>
- <view class="shop-name">{{item.supplierName}}</view>
- <view class="iconfont iconfangxiang"></view>
- </view>
- </view>
- <view class="goods-list">
- <view class="goods-row" v-for="(site, index2) in item.products" :key="index2" @click.stop="goToGoodDetails(site)">
- <view class="iconfont" :class="site.check ? 'iconqueding' : 'iconfeigouxuan'" @click.stop="checkGoods(item, site)"></view>
- <image class="goods-img" :src="site.imgUrl" mode="aspectFill"></image>
- <view class="goods-info">
- <view class="goods-name">{{site.productName}}</view>
- <view class="goods-type">类型:{{site.productType == 1 ? '普通商品' : '自助采摘'}}</view>
- <view class="goods-handle">
- <view class="goods-price">
- <text style="font-size: 15px;">¥</text>{{site.bizPrice}}
- </view>
- <view class="handle-box" @click.stop="">
- <uni-icons type="minus-filled" size="20" color="#A67A54" @click.native.stop="numSub(item, site)"></uni-icons>
- <text class="good-select">{{site.buyNum}}</text>
- <uni-icons type="plus-filled" size="20" color="#A67A54" @click.native.stop="numAdd(item, site)"></uni-icons>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="shop-handle-box">
- <view class="shop-handle-text">
- <text class="shop-text">合计</text>
- <text class="shop-price">¥{{getShopCheckPrice(item)}}</text>
- </view>
- <u-button type="success" size="medium" shape="circle" :ripple="true" @click="toPay(item)" :disabled="!getShopCheckGoods(item)"
- class="handle-button">结算({{getShopCheckGoods(item)}})</u-button>
- </view>
- </view>
- </view>
- <view class="cart-handle-box" v-if="manageType">
- <view class="iconfont" :class="getAllCartType() ? 'iconqueding' : 'iconfeigouxuan'" @click="checkAllShop()"></view>
- <view class="icon-text" @click="checkAllShop()">{{getAllCartType() ? '取消' : ''}}全选</view>
- <u-button type="success" size="medium" shape="circle" :ripple="true" :hair-line="false" :plain="true" @click="deleteSelectCarts()"
- class="cart-handle-delete">删除</u-button>
- </view>
- <u-modal v-model="modalShow" content="是否删除勾选商品?" @confirm="submitDeleteData()" :async-close="true"
- :show-cancel-button="true"></u-modal>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- data() {
- return {
- cartsList: [],
- cartNum: 1,
- manageType: false,
- modalShow: false,
- }
- },
- onLoad() {
-
- },
- onShow() {
- this.cartsList = []
- this.getCartData()
- },
- onPullDownRefresh() {
- this.cartsList = []
- this.getCartData('refresh')
- },
- methods: {
- // 跳转商城
- goToMall() {
- uni.switchTab({
- url: '/pages/shop/index'
- });
- },
- // 跳转商铺页
- goToShop(item) {
- uni.navigateTo({
- url: '/pagesGood/shopDetails?goodId=' + item.products[0].productId
- });
- },
- // 跳转商品详情
- goToGoodDetails(site) {
- uni.navigateTo({
- url: '/pagesGood/goodDetails?goodId=' + site.productId
- });
- },
- // 获取购物车列表
- getCartData(type) {
- NET.request(API.getCartList, {}, 'GET').then(res => {
- if (type == 'refresh') {
- uni.stopPullDownRefresh();
- }
- res.data.merchants && res.data.merchants.forEach(item => {
- item.allCheck = false
- item.products.forEach(site => {
- site.check = false
- })
- })
- this.cartsList = res.data.merchants || []
- }).catch(error => {
- this.$refs.uTips.show({
- title: '获取购物车列表失败',
- type: 'warning',
- })
- })
- },
- // 获取商铺下选中商品价格
- getShopCheckPrice(item) {
- return item.products.reduce((total, site) => {
- return total + (site.check ? (site.buyNum * site.bizPrice) : 0)
- }, 0)
- },
- // 获取全部商铺下商品
- getCartAllGoods() {
- return this.cartsList.reduce((total1, item) => {
- return total1 + item.products.reduce((total2, site) => {
- return total2 + site.buyNum
- }, 0)
- }, 0)
- },
- // 获取全部商铺下商品
- getShopCheckGoods(item) {
- return item.products.reduce((total, site) => {
- return total + (site.check ? site.buyNum : 0)
- }, 0)
- },
- // 全选店铺
- checkShop(item) {
- item.allCheck = !item.allCheck
- item.products.forEach(site => {
- site.check = item.allCheck
- })
- },
- // 勾选商品
- checkGoods(item, site) {
- site.check = !site.check
- item.allCheck = item.products.filter(site => site.check).length == item.products.length
- },
- // 数量减
- numSub(item, site) {
- if (site.buyNum > 1) {
- site.buyNum--
- this.setCartNum(item, site)
- }
- },
- // 数量加
- numAdd(item, site) {
- site.buyNum++
- this.setCartNum(item, site)
- },
- // 提交购物车变更参数
- setCartNum(item, site) {
- NET.request(API.editCart, {
- vos: [{
- buyNum: site.buyNum,
- flag: 2,
- selected: site.selected,
- shoppingcartId: site.shoppingcartId,
- }]
- }, 'PUT').then(res => {}).catch(error => {
- this.$refs.uTips.show({
- title: '改变商品数量失败',
- type: 'warning',
- })
- })
- },
- // 检测所有商铺全选情况
- getAllCartType() {
- return this.cartsList.filter(site => site.allCheck).length == this.cartsList.length
- },
- // 设置所有商铺全选状态
- checkAllShop() {
- let type = this.getAllCartType()
- this.cartsList.forEach(item => {
- item.allCheck = !type
- item.products.forEach(site => {
- site.check = !type
- })
- })
- },
- // 删除购物车
- deleteSelectCarts(item, site) {
- this.modalShow = true
- },
- // 提交删除购物车数据
- submitDeleteData() {
- let shoppingcartIds = []
- this.cartsList.forEach(item => {
- item.products.forEach(site => {
- if (site.check) {
- shoppingcartIds.push(site.shoppingcartId)
- }
- })
- })
- if (!shoppingcartIds.length) {
- this.modalShow = false
- this.$refs.uTips.show({
- title: '请勾选商品',
- type: 'warning',
- })
- return false
- }
- let str = '?'
- shoppingcartIds.forEach((site, index) => {
- str += (index ? '&' : '') + 'shoppingcartIds=' + site
- })
- NET.request(API.deleteCart + str, {}, 'POST').then(res => {
- this.modalShow = false
- this.manageType = false
- this.getCartData()
- }).catch(error => {
- this.modalShow = false
- this.$refs.uTips.show({
- title: '删除购物车失败',
- type: 'warning',
- })
- })
- },
- // 提交购物车变更参数
- toPay(item) {
- uni.removeStorageSync('defaultAddress');
- uni.setStorage({
- key: 'orderData',
- data: {
- tenantCode: item.tenantCode,
- supplierName: item.supplierName,
- areaSize: '',
- term: '',
- goodsList: item.products.filter(site => site.check).map(site => {
- return {
- bizPrice: site.bizPrice,
- buyNum: site.buyNum,
- imgUrl: site.imgUrl,
- originalPrice: site.originalPrice,
- productId: site.productId,
- productName: site.productName,
- productType: site.productType,
- shoppingcartId: site.shoppingcartId,
- }
- })
- }
- });
- uni.navigateTo({
- url: '/pagesGood/orderPay?flag=1&orderType=1'
- });
- }
- }
- }
- </script>
- <style>
- page {
- width: 100%;
- height: 100%;
- }
- </style>
- <style lang="less" scoped>
- // page {
- // width: 100%;
- // height: 100%;
- // }
- .container {
- width: 100%;
- height: 100%;
- background-color: #F3F3F3;
- position: relative;
- .iconqueding,
- .iconfeigouxuan {
- color: #56a83a;
- font-size: 36px;
- margin-left: 5px;
- }
- .swiper {
- width: 100%;
- height: 120px;
- float: left;
- background-color: #56a83a;
- border-radius: 0 0 40px 40px;
- .swiper-text {
- float: left;
- line-height: 16px;
- font-size: 15px;
- color: #FFFFFF;
- padding: 16px 15px;
- }
- }
- .swiper2 {
- width: 100%;
- height: 60px;
- float: left;
- background-color: #56a83a;
- border-radius: 0 0 40px 40px;
-
- .swiper-text {
- float: left;
- line-height: 16px;
- font-size: 15px;
- color: #FFFFFF;
- padding: 16px 15px;
- }
- }
- .no-cart {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- top: 50px;
- position: relative;
- .no-cart-img {
- width: 155px;
- height: 200px;
- margin-bottom: 20px;
- }
- .no-cart-text {
- font-size: 16px;
- font-family: PingFang SC;
- color: #999999;
- margin-bottom: 60px;
- }
- .button1 {
- /deep/button {
- background-color: #74bd60 !important;
- border: none !important;
- color: white !important;
- }
- width: 40%;
- height: 34px;
- }
- }
- .cart-box {
- width: calc(100% - 30px);
- min-height: calc(100vh - 40px - 50px);
- overflow: visible;
- position: absolute;
- top: 50px;
- bottom: 0;
- left: 15px;
- overflow-y: auto;
- .shop-row {
- width: 100%;
- float: left;
- background: #FFFFFF;
- border-radius: 10px;
- margin-bottom: 15px;
- .shop-info {
- width: 100%;
- height: 50px;
- float: left;
- display: flex;
- align-items: center;
- border-bottom: 1px solid #EEEEEE;
- .shop-info-right {
- display: flex;
- align-items: center;
- }
- .shop-name {
- font-size: 15px;
- font-family: PingFang SC;
- color: #333333;
- margin: 0 6px;
- }
- .iconshangjia {
- color: #333333;
- font-size: 26px;
- }
- .iconfangxiang {
- color: #999999;
- font-size: 20px;
- }
- }
- .goods-list {
- width: 100%;
- float: left;
- .goods-row {
- width: 100%;
- height: 120px;
- float: left;
- padding-top: 15px;
- border-bottom: 1px solid #EEEEEE;
- display: flex;
- .iconqueding,
- .iconfeigouxuan {
- margin-top: 26px;
- }
- .goods-img {
- width: 90px;
- height: 90px;
- margin: 0 15px 0 2px;
- border-radius: 5px;
- object-fit: cover;
- overflow: hidden;
- }
- .goods-info {
- height: 90px;
- flex: 1;
- .goods-name {
- width: 100%;
- height: 32px;
- float: left;
- font-size: 12px;
- font-family: PingFang SC;
- color: #333333;
- line-height: 16px;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- word-wrap: break-word;
- margin-bottom: 8px;
- }
- .goods-type {
- float: left;
- height: 20px;
- padding: 0 8px;
- background: #F0F0F0;
- border-radius: 4px;
- color: #666666;
- font-size: 10px;
- line-height: 20px;
- margin-bottom: 10px;
- }
- .goods-handle {
- width: 100%;
- height: 20px;
- box-sizing: border-box;
- padding-right: 15px;
- float: left;
- display: flex;
- justify-content: space-between;
- align-items: center;
- line-height: 20px;
- .goods-price {
- flex: 1;
- font-size: 18px;
- font-family: PingFang SC;
- color: #56a83a;
- line-height: 20px;
- }
- .handle-box {
- flex: 1;
- line-height: 20px;
- text-align: right;
- .good-select {
- font-size: 16px;
- font-family: PingFang SC;
- color: #333333;
- margin: 0 10px;
- }
- }
- }
- }
- }
- }
- .shop-handle-box {
- width: 100%;
- height: 54px;
- float: left;
- box-sizing: border-box;
- padding: 0 16px;
- .shop-handle-text {
- width: calc(100% - 110px);
- height: 54px;
- float: left;
- white-space: nowrap;
- font-size: 15px;
- font-family: PingFang SC;
- line-height: 54px;
- text-align: right;
- .shop-text {
- color: #333333;
- margin-right: 16px;
- }
- .shop-price {
- color: #56a83a;
- }
- }
- .handle-button {
- width: 96px;
- height: 40px;
- display: block;
- float: right;
- margin-top: 7px;
- padding: 0;
- text-align: center;
- /deep/button {
- background-color: #56a83a;
- color: #FFFFFF;
- height: 40px;
- width: 96px;
- line-height: 40px;
- }
- /deep/.u-btn--success--disabled{
- background-color: #74bd60!important;
- }
- }
- }
- }
- }
- .cart-handle-box {
- width: 100%;
- height: 52px;
- position: absolute;
- z-index: 1;
- bottom: 0;
- background: #FFFFFF;
- box-sizing: border-box;
- border-top: 1px solid #EEEEEE;
- padding: 0 15px 0 4px;
- .iconfont {
- height: 52px;
- line-height: 52px;
- float: left;
- display: block;
- }
- .icon-text {
- height: 52px;
- float: left;
- font-size: 15px;
- font-family: PingFang SC;
- color: #666666;
- line-height: 52px;
- }
- .cart-handle-delete {
- display: block;
- width: 96px;
- height: 32px;
- line-height: 32px;
- padding: 0;
- margin: 10px 0 0 0;
- float: right;
- border-color: #56a83a !important;
- background-color: #FFFFFF !important;
- color: #56a83a !important;
- /deep/button {
- border-color: #56a83a !important;
- background-color: #FFFFFF !important;
- color: #56a83a !important;
- padding: 0 24px;
- }
- }
- }
- }
- </style>
|