123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- <template>
- <view class="cart-pages">
- <view class="cart-bar" v-if="cartList.length>0">
- <view>共<text class="special-val">{{count}}</text>件商品</view>
- <view @click="editCart">
- <text class="edit" v-if="!isEdit">管理</text>
- <text class="save" v-else>完成</text>
- </view>
- </view>
- <view class="goods-list">
-
- <view class="goods-class-box" v-for="(item,cindex) in cartList" :key="item.goodsTypeNo">
- <view class="goods-class-head">
- <view @click="goodsClasChange(cindex)">
- <view
- class="check-button"
- v-if="isSxGoodAll(item).length||isEdit"
- :class="item.checked?'checked':'uncheck'">
- </view>
- <view v-else class="check-button disabled"></view>
- <view class="goodClsName">
- {{item.name}}
- </view>
- </view>
- <view class="des">
- <view>商品乐豆合计满<text>{{item.goldLimit}}</text></view>
- <u-image mode="scaleToFill" width="26rpx" height="26rpx" src="/static/ledou.png"></u-image>
- <view>才可购买</view>
- </view>
- </view>
- <view class="goods-class-list">
-
- <view class="goods-item" v-for="(good,index) in item.shoppingCartGoodsList" :key="good.id">
- <view class="checkbox"
- @click="goodsChange(good,index,cindex)">
- <view
- class="check-button"
- v-if="isSxGood(good)||isEdit"
- :class="good.checked?'checked':'uncheck'">
- </view>
- <view v-else class="check-button disabled"></view>
- </view>
- <view class="goods-info">
- <view class="goods-imgs">
- <view v-if="good.goods.inventoryQty==0||good.goods.state == 0||good.goods.delFlage == 0" class="goods-staus">
- <text>已失效</text>
- </view>
- <u-image border-radius="12" width="158rpx" height="140rpx" :src="good.goods.homeImage+'?x-oss-process=image/resize,m_pad,h_252,w_325,color_ffffff'"></u-image>
- </view>
- <view class="goods-text">
- <view class="good-name">{{good.goods.name}}</view>
- <view class="goods-price">
- <view>
- <text>{{good.goods.sellGold}}</text>
- <u-image mode="scaleToFill" width="30rpx" height="30rpx" src="/static/ledou.png"></u-image>
- </view>
- <view v-if="good.goods.inventoryQty>0&&good.goods.state==1">
- <uni-numbers-box @change="goodsNumsChange()" :index="cindex+'-'+index" :value="good.buyQty" :min="1"></uni-numbers-box>
- </view>
- <view v-else>
- <view style="width: 100rpx;text-align: center;">×{{good.buyQty}}</view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="noData" v-if="cartList.length==0">
- <u-empty mode="car">
- <view slot="bottom">
- <u-button size="mini" @click="toBuy">去选商品</u-button>
- </view>
- </u-empty>
- </view>
- </view>
- <view class="cart-submit" v-if="cartList.length>0">
- <view @click="checkAllChange()">
- <view
- class="check-button"
- :class="checkAll?'checked':'uncheck'">
- </view>
- <view class="checkAll">
- {{checkAll?'取消':'全选'}}
- </view>
- </view>
- <view v-if="!isEdit">
- <view class="heji">
- <view>总计:<text>{{totalPrice}}</text></view>
- <u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
- </view>
- <u-button size="mini" :custom-style="toOrderButton" type="error" @click="toOrder">立即下单</u-button>
- </view>
- <view v-else>
- <u-button size="mini" :custom-style="toOrderButton" type="error" @click="delGoods">删除</u-button>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- toOrderButton: {
- borderRadius:'100rpx',
- fontSize:'30rpx',
- width: '180rpx',
- height: '60rpx'
- },
- checkAll: false,
- isEdit: false,
- cartList: [],
- };
- },
- computed: {
- // 总数
- count() {
- let arr = this.cartList
- let count = 0
- arr.map(item=>{
- count = count + item.shoppingCartGoodsList.length
- if(!item.hasOwnProperty("checked")){
- item.checked = false
- }
- item.shoppingCartGoodsList.map(goods=>{
- if(!goods.hasOwnProperty("checked")){
- goods.checked = false
- }
- })
- })
- return count
- },
-
- totalPrice(){
- let arr = this.cartList
- let total = 0
- arr.map(item=>{
- item.shoppingCartGoodsList.map(a =>{
- if(a.checked){
- total = total + a.buyQty * a.goods.sellGold
- }
- })
- })
- return total
- },
- },
- onLoad() {
- uni.$emit('getCartList')
- // 刷新列表成功
- uni.$on('getCarListSuccess',item => {
- this.cartList = JSON.parse(JSON.stringify(this.$store.state.vuex_cartList))
- // 默认全选
- if(!this.isEdit){
- this.checkAllChange()
- }
- })
- },
- onShow() {
- },
- methods: {
- toBuy(){
- uni.switchTab({
- url:"/pages/goods/index"
- })
- },
-
- getCheckGoods(type){
- let arr = this.cartList
- let goods = []
- arr.map(item=>{
- item.shoppingCartGoodsList.map(a =>{
- if(a.checked){
- goods.push(type?a:a.id)
- }
- })
- })
- return goods
- },
-
- hasZgjindu(item){
- let ret = 0
- let goldLimit = item.goldLimit
- item.shoppingCartGoodsList.map(good=>{
- ret = ret + good.goods.sellGold * good.buyQty
- })
- console.log(ret , goldLimit)
- return !this.isEdit ? ret >= goldLimit : true
- },
-
- setClsGoodStatus(item,checked){
- console.log(checked)
- item.shoppingCartGoodsList.map(good=>{
- // 已下架,已删除,已销完的不选
- if((good.goods.inventoryQty==0||good.goods.state == 0||good.goods.delFlage == 0) && !this.isEdit){
- good.checked = false
- }else{
- good.checked = checked
- }
- })
- },
-
- checkAllChange() {
- let arr = this.cartList
- arr.map(item=>{
- item.checked = !this.checkAll
- this.setClsGoodStatus(item,!this.checkAll)
- })
- this.checkAll = !this.checkAll
- arr.splice()
- },
-
- goodsClasChange(index){
- let item = this.cartList[index]
- item.checked = !item.checked
- this.setClsGoodStatus(item,item.checked)
- // 判断是否全选
- this.hasCheckAll()
- },
-
- goodsChange(good,index,cindex){
- let goods = this.cartList[cindex] // 当前分类
- good.checked = !good.checked
- // 判断当前分类是否全选
- this.clasGoodsHasCheckAll(goods)
- },
-
- isSxGood(item){
- return !(item.goods.inventoryQty==0||item.goods.state == 0||item.goods.delFlage == 0) || this.isEdit
- },
-
- isSxGoodAll(row){
- return row.shoppingCartGoodsList.filter(item => {
- return this.isSxGood(item)
- })
- },
-
- clasGoodsHasCheckAll(row){
- let goods = this.isSxGoodAll(row)
- let len = goods.length
- let clen = 0
- if(len==0){
- return
- }
- goods.map(item=>{
- if(item.checked){
- clen = clen + 1
- }
- })
- row.checked = clen == len
- this.cartList.splice()
-
- this.hasCheckAll()
- },
-
- hasCheckAll(){
- let list = this.cartList
- let len = list.length
- let clen = 0
- list.map(item => {
- if(item.checked){
- clen = clen + 1
- }
- })
- this.checkAll = clen == len
- list.splice()
- },
-
- editCart(){
- this.isEdit = !this.isEdit
- this.checkAll = true
- this.checkAllChange()
- },
-
- toOrder(){
- let goods = this.getCheckGoods(1)
- console.log(goods)
- if(goods.length){
- this.$u.vuex("vuex_toOrderList",goods)
- uni.redirectTo({
- url:"/pages/toOrder/index"
- })
- }else{
- uni.showToast({
- title:"请选择商品",
- icon:"none"
- })
- }
- },
-
- delGoods(){
- let ids = this.getCheckGoods(0)
- if(ids.length){
- uni.$emit("delCartGood", ids)
- }else{
- uni.showToast({
- title:"请选择要删除的商品",
- icon:"none"
- })
- }
- },
-
- goodsNumsChange(val,id){
- console.log(val,id)
- let cindex = id.split('-')[0]
- let index = id.split('-')[1]
- let item = this.cartList[cindex]
- let row = item.shoppingCartGoodsList[index]
- row.buyQty = val
- uni.$emit("updateGoodsBuyQty",{id:row.id,buyQty:row.buyQty})
- }
- },
- }
- </script>
- <style lang="scss">
- page{
- height: 100%;
- }
- .cart-pages{
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- .noData{
- padding-top: 150upx;
- }
- .cart-bar{
- display: flex;
- justify-content: space-between;
- padding:20upx;
- .edit{
- color: #666;
- }
- .save{
- color: #00aaff;
- }
- .special-val{
- color: #FA3534;
- font-weight: bold;
- margin: 0 10rpx;
- }
- }
- .check-button{
- width: 40rpx;
- height: 40rpx;
- }
- .checked{
- background: url('/static/checked.png') no-repeat center center;
- background-size: 100% 100%;
- }
- .uncheck{
- background: url('/static/uncheck.png') no-repeat center center;
- background-size: 100% 100%;
- }
- .disabled{
- border:2rpx solid #EEEEEE;
- border-radius: 100rpx;
- background: #F8F8F8;
- }
- .goods-list{
- flex-grow: 1;
- overflow: auto;
- .goods-class-box{
- background: #FFFFFF;
- box-shadow: 1px 1px 3px #eee;
- margin-bottom: 20upx;
- .goods-class-head{
- display: flex;
- align-items: center;
- padding: 20upx;
- border-bottom: 1px solid #F8F8F8;
- justify-content: space-between;
- > view{
- &:first-child{
- display: flex;
- align-items: center;
- }
- .goodClsName{
- font-size: 30rpx;
- margin-left: 10rpx;
- }
- }
- .des{
- display: flex;
- align-items: center;
- font-size: 26upx;
- color: #999;
- text{
- color: #FA3534;
- }
- }
- }
- }
-
- .goods-item{
- padding: 20upx;
- display: flex;
- align-items: center;
- border-bottom: 1px solid #F8F8F8;
- &:last-child{
- border: 0;
- }
- .checkbox{
- width: 60rpx;
- overflow: hidden;
- }
- .goods-info{
- display: flex;
- align-items: center;
- flex-grow: 1;
- .goods-imgs{
- position: relative;
- .goods-staus{
- width: 100%;
- height: 100%;
- position: absolute;
- z-index: 10000;
- border-radius: 15rpx;
- background: rgba($color: #000000, $alpha: 0.4);
- text-align: center;
- line-height: 140rpx;
- left: 0;
- top: 0;
- color: #eee;
- font-size: 24upx;
- font-weight: bold;
- }
- }
- .goods-text{
- padding-left: 20upx;
- flex-grow: 1;
- .good-name{
- font-weight: bold;
- word-break: break-all;
- }
- }
- }
- .goods-price{
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding-top: 20upx;
- >view{
- &:first-child{
- font-size: 22upx;
- display: flex;
- align-items: center;
- text{
- color: red;
- font-size: 32upx;
- margin-right: 6upx;
- font-weight: bold;
- }
- }
- }
- }
- }
- }
- .cart-submit{
- padding: 20upx;
- background: #FFFFFF;
- box-shadow: 1px 1px 3px #eee;
- border-top: 1px solid #eee;
- display: flex;
- align-items: center;
- justify-content: space-between;
- >view{
- display: flex;
- align-items: center;
- .checkAll{
- margin-left: 10rpx;
- }
- &:last-child{
- font-size: 26upx;
- text{
- color: red;
- font-size: 40upx;
- }
- > view{
- padding-right: 50upx;
- }
- .heji{
- display: flex;
- align-items: center;
- font-weight: bold;
- }
- }
- }
- }
- }
- </style>
|