123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- <template>
- <view class="shopping-cart">
- <view class="header">
- <view class="title">
- 我的购物车
- </view>
- <view style="position: relative;">
- <view class="sub-title">购物车订单</view>
- </view>
- </view>
-
- <view v-if="cart.length===0" style="margin: 20upx auto;text-align: center; font-size: 28upx;color: #999999;">
- 暂未添加任何商品
- </view>
- <view class="shopping-cart-item" v-for="seller in cart">
- <view class="shopping-cart-item-head">
- <view class="select">
- <checkbox class="checkbox" :checked="seller.checked" @tap="selectSeller(seller.seller_id)" />
- </view>
- <view class="factory-name">{{seller.seller_nickname?seller.seller_nickname:'省心直供(该厂家暂未设置昵称)'}}</view>
- </view>
- <view class="shopping-cart-info">
- <view class="product-item" v-for="product in seller.products"
- @longpress="longpress(product.id,product.spec_index)">
- <view class="select">
- <checkbox class="checkbox" :checked="product.checked"
- @tap="select(product.id,product.spec_index)" />
- </view>
- <view class="product-image">
- <image class="image" :src="product.spec_image|imagesFilter" mode="scaleToFill"></image>
- </view>
- <view class="product-info">
- <view class="row row-1">
- <text class="title"><text class="sxzg-icon">省心直供</text>{{product.name}}</text>
- </view>
- <view class="row">
- <view class="spec">{{product.spec_name}}</view>
- </view>
- <view class="row row-2">
- <text class="org-price">¥{{product.spec_org_price}}</text>
- </view>
- <view class="row">
- <text class="sxj-icon">省心价</text>
- <text class="price">¥{{product.spec_price}}</text>
- </view>
- </view>
- <view class="counter">
- <view class="sub" @tap="subnum(product.id,product.num,product.spec_index)">
- <image style="width: 42upx;height: 42upx;" src="../../static/minus.png" mode="scaleToFill"></image>
- </view>
- <input class="num" type="text" v-model="product.num" />
- <view class="plus" @tap="plusnum(product.id,product.num,product.spec_index)">
- <image style="width: 42upx;height: 42upx;" src="../../static/add.png" mode="scaleToFill"></image>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="footer">
- <view class="select-all">
- <label @tap="selectAll()">
- <checkbox color="#ff5d5b" class="checkbox" :checked="checkall" />全选
- </label>
- </view>
- <view class="total">合计 <text>¥{{total}}</text></view>
- <view class="settlement"><button class="settlement-btn" type="default" @tap="buy">结算</button></view>
- </view>
- </view>
- </template>
- <script>
- import {
- mapState
- } from 'vuex'
- export default {
- data() {
- return {
- checkall: false
- }
- },
- computed: mapState({
- cart: state => state.cart,
- total() {
- return this.$store.getters['cart/total']
- }
- }),
- onLoad() {
- // uni.removeStorageSync("cart")
- },
- methods: {
- selectSeller(seller_id) {
- this.$store.commit("cart/selectSeller", {
- seller_id: seller_id
- })
- },
- select(id, spec_index) {
- this.$store.commit("cart/select", {
- id: id,
- spec_index: spec_index
- })
- },
- selectAll() {
- this.checkall = !this.checkall;
- this.$store.commit("cart/selectAll", {
- checked: this.checkall
- })
- },
- subnum(id, num, spec_index) {
- if (num === 1) {
- uni.showModal({
- title: "移除商品",
- content: "确认移除该商品?",
- success: (res) => {
- if (res.confirm) {
- this.$store.commit("cart/remove", {
- id: id,
- num: num,
- spec_index: spec_index
- })
- }
- }
- })
- } else {
- num--
- }
- this.$store.commit("cart/numchange", {
- id: id,
- num: num,
- spec_index: spec_index
- })
- },
- plusnum(id, num, spec_index) {
- num++
- this.$store.commit("cart/numchange", {
- id: id,
- num: num,
- spec_index: spec_index
- })
- },
- longpress(id, spec_index) {
- uni.showActionSheet({
- itemList: ['删除'],
- itemColor: "#FF5D5B",
- success: (res)=> {
- if (res.tapIndex === 0) {
- this.$store.commit("cart/remove", {
- id: id,
- spec_index: spec_index
- })
- uni.showToast({
- icon: "none",
- title: "删除成功"
- })
- }
- },
- })
- },
- buy() {
- let i = 0;
- let postData = {}
- for (let seller of this.cart) {
- for (let product of seller.products) {
- if (product.checked) {
- postData[`products[${i}]`] = JSON.stringify({
- id: product.id,
- spec_index: product.spec_index,
- num: product.num
- })
- i++;
- }
- }
- }
- this.$http.post({
- url: '/order/create',
- data: postData,
- success: (res) => {
- for (const [key, value] of Object.entries(postData)) {
- console.log(value)
- this.$store.commit("cart/remove", JSON.parse(value))
- }
- uni.navigateTo({
- url: "/pages/order/cashier?order_no=" + res.data.data
- })
- }
- })
- }
- }
- }
- </script>
- <style lang="scss">
- .header {
- margin: 20upx;
- background: white;
- text-align: center;
- border-radius: 20upx;
- padding-bottom: 10upx;
-
- .title {
- height: 100upx;
- font-size: 32upx;
- line-height: 100upx;
- // font-weight: bold;
- }
-
- .sub-title {
- font-size: 28upx;
- color: #999999;
- }
-
- }
-
- .shopping-cart {
- padding-bottom: 80upx;
- overflow: hidden;
- position: relative;
- }
- .shopping-cart-item {
- padding: 20upx;
- background: white;
- // padding-left: 100upx;
- margin: 20upx;
- border-radius: 20upx;
- .shopping-cart-item-head {
- margin-bottom: 20upx;
- font-size: 28upx;
- font-weight: bold;
- position: relative;
- display: flex;
- }
- .select {
- align-self: center;
- position: relative;
- margin-top: -4upx;
- margin-right: 20upx;
- }
- .checkbox {
- transform: scale(0.7);
- /deep/ .uni-checkbox-input {
- border: 2upx solid #CCCCCC;
- &.uni-checkbox-input-checked {
- color: $primary-color !important;
- }
- }
- /deep/ .uni-checkbox-input:hover {
- border: 2upx solid #CCCCCC;
- }
- }
- .product-item {
- display: flex;
- position: relative;
- margin-bottom: 20upx;
- .checkbox::before {
- top: 70upx;
- }
- .product-image {
- margin-right: 20upx;
- width: 180upx;
- height: 180upx;
- .image {
- width: 180upx;
- height: 180upx;
- margin-top: 5upx;
- }
- }
- .title {
- font-size: 24rpx;
- display: inline-block;
- white-space: normal;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- height: 68upx;
- }
- .spec {
- font-size: 22upx;
- background: #CCCCCC;
- color: white;
- padding: 0 5upx;
- border-radius: 10upx;
- margin-top: 10upx;
- // display: inline-block;
- }
- .counter {
- position: absolute;
- bottom: 0upx;
- right: 10upx;
- display: flex;
- border: 2upx solid #CCCCCC;
- font-size: 28upx;
- align-items: center;
- border-radius: 10upx;
- .sub,
- .plus {
- // transform: scale(0.5);
- font-weight: 0;
- width: 42upx;
- text-align: center;
- display: flex;
- align-items: center;
- &:active {
- background: rgba(0, 0, 0, .1);
- }
- }
- .num {
- text-align: center;
- font-size: 24upx;
- border-left: 2upx solid #EEEEEE;
- border-right: 2upx solid #EEEEEE;
- width: 50upx;
- }
- }
- }
- }
- .sxzg-icon {
- color: $primary-color;
- font-size: 16rpx;
- width: 80rpx;
- text-align: center;
- line-height: normal;
- border: 2rpx solid $primary-color;
- border-radius: 20rpx;
- display: inline-block;
- position: relative;
- top: -4rpx;
- margin-right: 10upx;
- // transform: scale(0.9);
- }
- .sxj-icon {
- background: $primary-color;
- color: white;
- font-size: 20upx;
- padding: 0 5upx;
- border-radius: 5upx;
- vertical-align: middle;
- }
- .row {
- display: flex;
- align-items: center;
- }
- .org-price {
- text-decoration: line-through;
- font-size: 26rpx;
- color: #cccccc;
- }
- .price {
- font-size: 26rpx;
- color: $primary-color;
- font-weight: bold;
- }
- .footer {
- display: flex;
- position: fixed;
- height: 100upx;
- background: $primary-color;
- bottom: 0;
- width: 100%;
- box-shadow: 0 0 10upx #999999;
- align-items: center;
- /* #ifdef H5 */
- bottom: 90upx;
- /* #endif */
- color: white;
- .select-all {
- width: 200upx;
- flex: 0 0 200upx;
- position: relative;
- margin-left: 20upx;
- .checkbox {
- transform: scale(0.7);
- position: relative;
- top: -4upx
- }
- /deep/ .uni-checkbox-input {
- border: none;
- }
- /deep/ .uni-checkbox-input:hover {
- border: none;
- }
- }
- .total {
- flex-grow: 1;
- text-align: right;
- }
- .settlement {
- flex-grow: 0;
- text-align: right;
- margin: 0 20upx;
- }
- .settlement-btn {
- background: #ffa82e;
- padding: 15upx 60upx;
- color: white;
- line-height: normal;
- font-size: 32upx;
- border-radius: 50upx;
- }
- }
- </style>
|