123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- <template>
- <view class="container">
- <view class="no-goods" v-if="goodsList.list.length<1">
- <view class="title-box">
- 购物车空空如也~
- </view>
- <view class="to-index-btn" :style="'background:'+ pagestyleconfig.appstylecolor" @tap="toIndexPage">
- 去逛逛
- </view>
- </view>
- <view v-if="goodsList.list.length>0">
- <!-- #ifdef MP || H5-->
- <view class="tui-edit-goods">
- <view>购物车商品</view>
- <view>
- <tui-button v-if="goodsList.saveHidden" type="gray" :plain="true" shape="circle" width="160rpx"
- height="60rpx" :size="24" @click="editTap">编辑商品</tui-button>
- <tui-button v-if="!goodsList.saveHidden" type="gray" :plain="true" shape="circle" width="160rpx"
- height="60rpx" :size="24" @click="saveTap">完成</tui-button>
- </view>
- </view>
- <!-- #endif -->
- <checkbox-group @change="selectChange">
- <view class="tui-cart-cell tui-mtop" v-for="(item,index) in goodsList.list" :key="index">
- <tui-swipe-action :actions="actions" @click="delItem" :params="item">
- <template v-slot:content>
- <view class="tui-goods-item">
- <label class="tui-checkbox">
- <checkbox :value="item.id" :data-id="index" :checked="item.active"
- color="#fff"></checkbox>
- </label>
- <image :src="item.pic" class="tui-goods-img" />
- <view class="tui-goods-info">
- <view class="tui-goods-title">
- {{item.name}}
- </view>
- <view class="tui-goods-model" v-if="item.label">
- <view class="tui-model-text">{{item.label}}</view>
- </view>
- <view class="tui-price-box">
- <view class="tui-goods-price">¥{{item.price}}</view>
- <tui-numberbox :value="item.number" :height="36" :width="64" :min="1"
- :index="item.cart_id" @change="changeNum"></tui-numberbox>
- </view>
- </view>
- </view>
- </template>
- </tui-swipe-action>
- </view>
- </checkbox-group>
- <!--tabbar-->
- <view class="settlement">
- <view class="tui-checkAll">
- <checkbox-group @change="bindAllSelect">
- <label class="tui-checkbox">
- <checkbox :checked="goodsList.allSelect" color="#fff"></checkbox>
- <text class="tui-checkbox-pl">全选</text>
- </label>
- </checkbox-group>
- <view class="tui-total-price" v-if="!goodsList.noSelect">合计:<text
- class="tui-bold">¥{{goodsList.totalPrice}}</text>
- </view>
- </view>
- <view>
- <button @click="toPayOrder" :disabled="goodsList.noSelect" v-if="goodsList.saveHidden" class="settlementbutt" :style="'background:'+ pagestyleconfig.appstylecolor">去结算({{goodsList.number}})</button>
- <tui-button @click="deleteSelected" :disabled="goodsList.noSelect" width="200rpx" height="70rpx"
- :size="30" type="black" shape="circle" :plain="true" v-else>
- 删除</tui-button>
- </view>
- </view>
- </view>
- <!--猜你喜欢-->
- <block v-if="recommendgoods.length>0">
- <tui-divider :size="28" :bold="true" color="#333" width="50%">
- <tui-icon name="like" :size="18" color="#e41f19"></tui-icon>
- <text class="tui-youlike">猜你喜欢</text>
- </tui-divider>
- <view class="tui-product-list">
- <view class="tui-product-container">
- <block v-for="(item, index) in recommendgoods" :key="index">
- <!--商品列表-->
- <view class="tui-pro-item" hover-class="hover" :hover-start-time="150"
- @tap="navigateTo('/pages/goodsDetail/goodsDetail?id='+item.id)">
- <image :src="item.pic" class="tui-pro-img" mode="widthFix" />
- <view class="tui-pro-content">
- <view class="tui-pro-tit">{{ item.name }}</view>
- <view>
- <view class="tui-pro-price">
- <text v-if="item.is_points_goods==1" class="tui-sale-price">{{lang.points}}:{{ item.pay_points }}</text>
- <text v-if="item.is_points_goods!=1" class="tui-sale-price">¥{{ item.price }}</text>
- <text v-if="item.costs>0" class="tui-factory-price">¥{{ item.costs }}</text>
- </view>
- <view class="tui-pro-pay">{{ item.sale_count }}人付款</view>
- </view>
- </view>
- </view>
- </block>
- </view>
- </view>
- </block>
- <!--加载loadding-->
- <tui-loadmore v-if="loadding" :index="3" type="red"></tui-loadmore>
- <tui-tabbar :current="current">
- </tui-tabbar>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- lang:{},
- current: '',
- pagestyleconfig: [],
- totalPrice1: 0,
- cartIds: [], //购物车id
- actions: [{
- name: '删除',
- color: '#fff',
- fontsize: 28,
- width: 64,
- background: '#F82400'
- }],
- recommendgoods: [],
- pageIndex: 1,
- loadding: false,
- pullUpOn: true,
- islogin: 1, //是否要需要登录,需要在onLoad加截 app.page.onLoad(this,e);
- goodsList: {
- saveHidden: true,
- number: 0,
- totalPrice: 0,
- totalPayPoints: 0,
- allSelect: true,
- noSelect: false,
- list: [],
- bottommenulist: []
- },
- }
- },
- filters: {
- getPrice(price) {
- price = price || 0;
- return price.toFixed(2)
- }
- },
- onLoad: function(e) {
- let _this = this;
- // #ifdef MP-WEIXIN
- this.current = "/" + this.__route__;
- // #endif
- //#ifdef H5
- this.current = this.$route.path;
- //#endif
- _this.$request.get('Lang.getlang').then(res => {
- if (res.errno == 0) {
- _this.lang = res.data;
- }
- });
- _this.$request.post('config', {
- mo: 'pagestyle'
- }).then(res => {
- if (res.errno == 0) {
- _this.pagestyleconfig = res.data;
- }
- });
- _this.$request.get('Goods.recommend').then(res => {
- if (res.errno == 0) {
- _this.recommendgoods = res.data;
- }
- });
- },
- onShow: function() {
- var _this = this;
- _this.getcarlist()
- },
- methods: {
- getcarlist: function() {
- var _this = this;
- var shopList = [];
- // 获取购物车数据
- _this.$request.get('cart.list', {
- samkey: (new Date()).valueOf(),
- showLoading:true,
- }).then(function(res) {
- var shopCarInfoMem = res.data;
- //console.log(shopCarInfoMem);
- if (shopCarInfoMem && shopCarInfoMem.shopList) {
- shopList = shopCarInfoMem.shopList
- }
- _this.goodsList.list = shopList;
- _this.setGoodsList(_this.getSaveHide(), _this.allSelect());
- })
- },
- changeNum: function(e) {
- var _this = this
- _this.$request.post('cart.quantity', {
- id: e.index,
- uptype: 'jia',
- quantity: e.value,
- samkey: (new Date()).valueOf()
- }).then(function(res) {
- _this.getcarlist();
- })
- },
- toIndexPage: function() {
- this.sam.navigateTo('/pages/index/index');
- },
- navigateTo: function(url) {
- this.sam.navigateTo(url)
- },
- delItem: function(e) {
- var _this = this;
- _this.$request.post('cart.del', {
- id: e.item.cart_id
- }).then(function(res) {
- _this.getcarlist();
- })
- },
- selectChange: function(e) {
- this.cartIds = e.detail.value;
- this.goodsList.list.map(item => {
- //如果购物车id为数字统一转成字符串
- if (this.cartIds.indexOf(item.id.toString())>-1) {
- item.active = true;
- } else {
- item.active = false;
- }
- })
- this.setGoodsList(this.getSaveHide(), this.allSelect());
- },
- allSelect: function() {
- var list = this.goodsList.list;
- var allSelect = false;
- for (var i = 0; i < list.length; i++) {
- var curItem = list[i];
- if (curItem.active) {
- allSelect = true;
- } else {
- allSelect = false;
- break;
- }
- }
- return allSelect;
- },
- setGoodsList: function(saveHidden, allSelect) {
- var list = this.goodsList.list;
- var number = 0;
- var total = 0;
- let totalPayPoints = 0;
- var noSelect = 0;
- for (var i = 0; i < list.length; i++) {
- var curItem = list[i];
- if (curItem.active) {
- number += parseInt(curItem.number);
- total += parseFloat(curItem.price) * curItem.number;
- totalPayPoints += curItem.points * curItem.number;
- } else {
- noSelect++;
- }
- }
- total = parseFloat(total.toFixed(2)); //js浮点计算bug,取两位小数精度
- if (noSelect == list.length) {
- noSelect = true;
- } else {
- noSelect = false;
- }
- this.goodsList = {
- saveHidden: saveHidden,
- number: number,
- totalPrice: total,
- allSelect: allSelect,
- noSelect: noSelect,
- list: list,
- totalPayPoints: totalPayPoints
- };
- var shopCarInfo = {};
- shopCarInfo.shopList = list;
- uni.setStorage({
- key: "shopCarInfo",
- data: shopCarInfo
- })
- },
- bindAllSelect: function() {
- var currentAllSelect = this.goodsList.allSelect;
- var list = this.goodsList.list;
- if (currentAllSelect) {
- for (var i = 0; i < list.length; i++) {
- var curItem = list[i];
- curItem.active = false;
- }
- } else {
- for (var i = 0; i < list.length; i++) {
- var curItem = list[i];
- curItem.active = true;
- }
- }
- this.setGoodsList(this.getSaveHide(), !currentAllSelect);
- },
- editTap: function() {
- this.goodsList.list.map(item => {
- item.active = false;
- })
- this.setGoodsList(!this.getSaveHide(), this.allSelect());
- },
- saveTap: function() {
- this.goodsList.list.map(item => {
- item.active = true;
- })
- this.setGoodsList(!this.getSaveHide(), this.allSelect());
- },
- getSaveHide: function() {
- return this.goodsList.saveHidden;
- },
- deleteSelected: function() {
- var _this = this;
- var list = this.goodsList.list;
- var ids = '';
- for (let i = 0; i < list.length; i++) {
- let curItem = list[i];
- if (curItem.active) {
- ids = ids + curItem.cart_id + ',';
- }
- }
- //console.log(ids);
- _this.$request.post('cart.del', {
- ids: ids
- }).then(function(res) {
- _this.getcarlist();
- })
- /*
- list = list.filter(function(curGoods) {
- return !curGoods.active;
- });
- this.setGoodsList(this.getSaveHide(), this.allSelect());
- */
- },
- toPayOrder: function() {
- uni.showLoading();
- var _this = this;
- if (this.goodsList.noSelect) {
- uni.hideLoading();
- return;
- }
- // 重新计算价格,判断库存
- var shopList = [];
- var shopCarInfoMem = uni.getStorageSync('shopCarInfo');
- if (shopCarInfoMem && shopCarInfoMem.shopList) {
- // shopList = shopCarInfoMem.shopList
- shopList = shopCarInfoMem.shopList.filter(entity => {
- return entity.active;
- });
- }
- if (shopList.length == 0) {
- uni.hideLoading();
- return;
- }
- var isFail = false;
- var doneNumber = 0;
- var needDoneNUmber = shopList.length;
- for (let i = 0; i < shopList.length; i++) {
- if (isFail) {
- uni.hideLoading();
- return;
- }
- let carShopBean = shopList[i];
- //console.log(carShopBean);
- // 获取价格和库存
- _this.$request.post('cart.check', {
- goodsId: carShopBean.goodsId,
- number: carShopBean.number,
- sku: carShopBean.sku
- }).then(function(res) {
- doneNumber++;
-
- if (carShopBean.sku) {
- if (!res.data.sku || res.data.sku == "") {
- uni.showModal({
- title: '提示',
- content: carShopBean.name + ' 商品已失效,请重新购买',
- showCancel: false
- })
- isFail = true;
- uni.hideLoading();
- return;
- }
- }
- if (Number(res.data.stores) < Number(carShopBean.number)) {
- uni.showModal({
- title: '提示',
- content: carShopBean.name + ' 库存不足,请重新购买',
- showCancel: false
- })
- isFail = true;
- uni.hideLoading();
- return;
- }
- if (res.data.price != carShopBean.price) {
- uni.showModal({
- title: '提示',
- content: carShopBean.name + '价格有调整,请重新购买',
- showCancel: false
- })
- isFail = true;
- uni.hideLoading();
- return;
- }
-
- if (needDoneNUmber == doneNumber) {
- if (!isFail) {
-
- _this.navigateToPayOrder();
- }
- }
- })
- }
- },
- navigateToPayOrder: function() {
- uni.hideLoading();
- this.sam.navigateTo('/pagesA/submitOrder/submitOrder');
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- setTimeout(() => {
- uni.stopPullDownRefresh()
- }, 200);
- },
- onNavigationBarButtonTap(e) {
- this.goodsList.saveHidden = !this.goodsList.saveHidden;
- let text = this.goodsList.saveHidden ? "完成" : "编辑";
- // #ifdef APP-PLUS
- let webView = this.$mp.page.$getAppWebview();
- webView.setTitleNViewButtonStyle(0, {
- text: text
- });
- // #endif
- }
- }
- </script>
- <style>
- .container {
- padding-bottom: 120rpx;
- }
- .no-goods {
- padding-bottom: 230rpx;
- }
- .title-box {
- width: 100%;
- padding-top: 330rpx;
- text-align: center;
- font-size: 28rpx;
- color: #999;
- background: url(/static/images/icon-cart.png) no-repeat center 205rpx;
- background-size: 100rpx auto;
- margin-bottom: 50rpx;
- }
- .to-index-btn {
- color: #fff;
- border-radius: 6px;
- margin-left: auto;
- margin-right: auto;
- width: 300rpx;
- height: 70rpx;
- line-height: 70rpx;
- text-align: center;
- font-size: 28rpx;
- }
- .tui-mtop {
- margin-top: 24rpx;
- }
- .tui-edit-goods {
- width: 100%;
- border-radius: 12rpx;
- overflow: hidden;
- padding: 24rpx 30rpx 0 30rpx;
- box-sizing: border-box;
- display: flex;
- justify-content: space-between;
- align-items: center;
- color: #333;
- font-size: 24rpx;
- }
- .tui-goods-num {
- font-weight: bold;
- color: #e41f19;
- }
- .tui-cart-cell {
- width: 100%;
- border-radius: 12rpx;
- background: #FFFFFF;
- padding: 40rpx 0;
- overflow: hidden;
- }
- .tui-goods-item {
- display: flex;
- padding: 0 30rpx;
- box-sizing: border-box;
- }
- .tui-checkbox {
- min-width: 70rpx;
- display: flex;
- align-items: center;
- }
- /* #ifdef MP-WEIXIN */
- .tui-checkbox .wx-checkbox-input {
- width: 40rpx;
- height: 40rpx;
- margin-right: 0 !important;
- border-radius: 50% !important;
- transform: scale(0.8);
- border-color: #d1d1d1 !important;
- }
- .tui-checkbox .wx-checkbox-input.wx-checkbox-input-checked {
- background: #eb0909;
- width: 44rpx !important;
- height: 44rpx !important;
- border: none;
- }
- /* #endif */
- /* #ifndef MP-WEIXIN */
- >>>.tui-checkbox .uni-checkbox-input {
- width: 40rpx;
- height: 40rpx;
- margin-right: 0 !important;
- border-radius: 50% !important;
- transform: scale(0.8);
- border-color: #d1d1d1 !important;
- }
- >>>.tui-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
- background: #eb0909;
- width: 45rpx !important;
- height: 45rpx !important;
- border: none;
- }
- /* #endif */
- .tui-goods-img {
- width: 180rpx;
- height: 180rpx !important;
- border-radius: 12rpx;
- flex-shrink: 0;
- display: block;
- }
- .tui-goods-info {
- width: 100%;
- padding-left: 20rpx;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: space-between;
- box-sizing: border-box;
- overflow: hidden;
- }
- .tui-goods-title {
- white-space: normal;
- word-break: break-all;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- font-size: 24rpx;
- color: #333;
- }
- .tui-goods-model {
- max-width: 100%;
- color: #333;
- background: #F5F5F5;
- border-radius: 40rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 16rpx;
- box-sizing: border-box;
- }
- .tui-model-text {
- max-width: 100%;
- transform: scale(0.9);
- transform-origin: 0 center;
- font-size: 24rpx;
- line-height: 32rpx;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .tui-price-box {
- width: 100%;
- display: flex;
- align-items: flex-end;
- justify-content: space-between;
- }
- .tui-goods-price {
- font-size: 34rpx;
- font-weight: 500;
- color: #e41f19;
- }
- .tui-scale {
- transform: scale(0.8);
- transform-origin: 100% 100%;
- }
- .tui-activity {
- font-size: 24rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 30rpx 20rpx 100rpx;
- box-sizing: border-box;
- }
- .tui-buy {
- display: flex;
- align-items: center
- }
- .tui-bold {
- font-weight: bold;
- }
- .tui-sub-info {
- max-width: 532rpx;
- font-size: 24rpx;
- line-height: 24rpx;
- padding: 20rpx 30rpx 10rpx 30rpx;
- box-sizing: border-box;
- color: #333;
- transform: scale(0.8);
- transform-origin: 100% center;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- margin-left: auto
- }
- .tui-invalid-text {
- width: 66rpx;
- margin-right: 4rpx;
- text-align: center;
- font-size: 24rpx;
- color: #fff;
- background: rgba(0, 0, 0, .3);
- transform: scale(0.8);
- transform-origin: center center;
- border-radius: 4rpx;
- flex-shrink: 0;
- }
- .tui-gray {
- color: #B2B2B2 !important;
- }
- .tui-goods-invalid {
- color: #555;
- font-size: 24rpx;
- }
- .tui-flex-center {
- align-items: center !important;
- }
- .tui-invalid-ptop {
- padding-top: 40rpx;
- }
- .settlement {
- width: 100%;
- height: 100rpx;
- background: #fff;
- position: fixed;
- left: 0;
- bottom: 160rpx;
- /* #ifdef H5 */
- bottom: 200rpx;
- /* #endif */
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 30rpx;
- box-sizing: border-box;
- font-size: 24rpx;
- z-index: 9999;
- }
- .settlement::before {
- content: '';
- width: 100%;
- border-bottom: 1rpx solid #d9d9d9;
- position: absolute;
- top: 0;
- left: 0;
- -webkit-transform: scaleY(0.5);
- transform: scaleY(0.5);
- }
- .tui-checkAll {
- display: flex;
- align-items: center;
- }
- .tui-checkbox-pl {
- padding-left: 12rpx;
- }
- .tui-total-price {
- padding-left: 30rpx;
- font-size: 30rpx !important;
- }
- /*猜你喜欢*/
- .tui-youlike {
- padding-left: 12rpx
- }
- .tui-product-list {
- display: flex;
- justify-content: space-between;
- flex-direction: row;
- flex-wrap: wrap;
- box-sizing: border-box;
- padding: 10rpx;
- padding-bottom: 100rpx;
- }
- .tui-product-container {
- width: 100%;
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- }
- .tui-pro-item {
- background: #fff;
- box-sizing: border-box;
- overflow: hidden;
- border-radius: 12rpx;
- width: 48%;
- margin-left: 1%;
- margin-right: 1%;
- margin-bottom: 2%;
- }
- .tui-pro-img {
- width: 100%;
- display: block;
- }
- .tui-pro-content {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- box-sizing: border-box;
- padding: 20rpx;
- }
- .tui-pro-tit {
- color: #2e2e2e;
- font-size: 26rpx;
- word-break: break-all;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- }
- .tui-pro-price {
- padding-top: 18rpx;
- }
- .tui-sale-price {
- font-size: 34rpx;
- font-weight: 500;
- color: #e41f19;
- }
- .tui-factory-price {
- font-size: 24rpx;
- color: #a0a0a0;
- text-decoration: line-through;
- padding-left: 12rpx;
- }
- .tui-pro-pay {
- padding-top: 10rpx;
- font-size: 24rpx;
- color: #656565;
- }
- .no-select {
- background-color: #ccc;
- }
- .settlementbutt{
- width: 200rpx;
- font-size: 30rpx;
- height: 72rpx;
- line-height: 72rpx;
- border-radius: 98rpx;
- color: #fff;
- }
- </style>
|