index.vue 12.8 KB
<!-- 秒杀活动 -->
<template>
    <div class="ctnr">
        <div class="search-wrap">
            <GLCombiForm ref="goodsRef" @handleOk="handleSearch" @handleRest="handleReset" :formObj="goodsFormObj" :formData="goodsFormData">
                <div slot="categorySlot">
                    <!-- <el-cascader :props="categoryProps" v-model="goodsFormObj.categoryCode" :options="categoryList"></el-cascader>  -->
                    <categoryCascader :categoryCode.sync="goodsFormObj"></categoryCascader>                   
                </div>
                <div slot="supplyPriceSlot">
                    <inputNumRange :formData="goodsFormObj" :keyObj="{from: 'startSellPrice', to:'endSellPrice'}"></inputNumRange>
                </div>
                <div slot="spreadPriceSlot">
                    <inputNumRange :formData="goodsFormObj" :keyObj="{from: 'startDiffPrice', to:'endDiffPrice'}"></inputNumRange>
                </div>
            </GLCombiForm>
        </div>
        <div class="operate-wrap">
            <span class="table-title">选品库</span>
            <el-button :size="size" type="primary" plain @click="addWarehouseFn({}, 1)">当页添加进仓库</el-button>
        </div>
        <div class="goods-wrap" v-if="goodsList && goodsList.length">
            <div v-for="item in goodsList" :class="['goods-box',{'optional' : item.stockroomFlag==1}, {'in-warehouse': item.stockroomFlag==2}]" :key="item">
                <div class="mask">
                    <el-button class="add-warehouse" icon="el-icon-plus" :size="size" type="primary" @click="addWarehouseFn(item)">加入仓库</el-button>
                </div>
                <img v-if="item.stockroomFlag==2" class="status-label" :src="require('@/assets/images/inWarehouse.png')" alt="">
                <div class="goods-img">
                    <img  :src="item.goodsImgUrl" alt="">
                </div>
                <div class="info">
                    <div class="title">{{ item.goodsSkuName }}
                        <!-- <el-tooltip class="item" effect="dark" :content="item.goodsSkuName" placement="top">
                            <span>{{ item.goodsSkuName }}</span>
                        </el-tooltip> -->
                    </div>
                    <p>
                        <span>库存:</span>
                        <span  class="inventory">{{item.goodsStock}}</span>
                    </p>
                    <p>
                        <span>供货价:</span>
                        <span  class="supply">¥{{ item.sellPrice }}</span>
                    </p>
                    <p>
                        <span>市场价:</span>
                        <span  class="market">¥{{ item.marketPrice }}</span>
                    </p>
                </div>
            </div>
        </div>
        <div class="noData" v-else>
            <img :src="require('@/assets/images/noData.png')" alt="">
            <p>暂无数据</p>
        </div>
        <div class="pagination">
            <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageObj.pageNum"
            :page-sizes="pageObj.pageSizes"
            :page-size="pageObj.pageSize"
            :total="pageObj.total"
            layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
        </div>
    </div>
</template>
  
<script>
import categoryCascader from '@/components/categoryCascader.vue'
import inputNumRange from '@/components/inputNumRange'
export default {
    name: 'index',
    data() {
      return {
        size: 'small',
        page:{},
        goodsList: [],
        categoryVal: [],
        categoryList: [],
        categoryProps: {
          lazy: true,
          label: 'categoryName',
          value: 'categoryCode',
          lazyLoad: this.getCategoryList
        },
        pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
        pageObj :{
            total: 0,
            pageSize: 50,
            pageSizes: [40, 50, 60, 70],
            pageNum: 1
        },
        goodsFormObj: {
            goodsSkuName: '',
            categoryCode: '',
            priceOrderType: '',
            startSellPrice: '',
            endSellPrice: '',
            endDiffPrice: '',
            startDiffPrice: ''
        },
        goodsFormData: [
            {
                label: '商品信息',
                name: 'goodsSkuName',
                type: 'input',
                maxlength: 50,
                isClear: true
            },
            {
                label: '商品分类',
                name: 'classify',
                addHtml: 'categorySlot'
            },
            {
                label: '供货价排序',
                name: 'priceOrderType',
                type: 'select',
                optionList: [{
                    id: '1',
                    value: '降序'
                },
                {
                    id: '2',
                    value: '升序'
                }],
                optionId: 'id',
                optionLabel: 'value'
            },
            {
                label: '供货价',
                addHtml: 'supplyPriceSlot'
            },
            {
                label: '差价',
                tips: '市场价和供货价的价格差',
                addHtml: 'spreadPriceSlot'
            },
        ],
      }
    },
  
    components: {
        inputNumRange,
        categoryCascader
    },
    created(){
        this.getGoodsList()
        // this.getCategoryList()
    },
    mounted() {

    },
  
    methods: {
        handleSizeChange(e){
            this.pageObj.pageSize = e
            this.getGoodsList()
        },
        handleCurrentChange(e){
            this.pageObj.pageNum = e
            this.getGoodsList()
        },
        getGoodsList(){
            const { pageSize, pageNum } = this.pageObj
            const { goodsSkuName, categoryCode, priceOrderType, startSellPrice, endSellPrice, endDiffPrice, startDiffPrice } = this.goodsFormObj
            const params = {
                goodsSkuName,
                priceOrderType,
                startSellPrice,
                endSellPrice,
                endDiffPrice,
                startDiffPrice,
                pageNum,
                pageSize,
                categoryCode: categoryCode && categoryCode.length ? categoryCode[categoryCode.length-1] : ''
            }
            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.3)'
            })
            this.$apis.platformGoods.getGoodsListApi(params).then(res=>{
                loading.close()
                if(res){
                    this.goodsList = res.list
                    this.pageObj.total = res.total
                }
            }).catch(err => {
                loading.close()
                console.log(err)
            })
        }, 
        getCategoryList(node, resolve){
            const params = {
                categoryCode: node?.value,
                categoryLevel: node?.level + 1 
            }
            this.$apis.platformGoods.getCategoryListApi(params).then(res=>{
                if(res){
                    res.map(item => item.leaf = params.categoryLevel>2)
                    if(params.categoryLevel == 1) this.categoryList = res
                    resolve(res)
                }
            })
        },  
        handleReset(){
            this.goodsFormObj = {
                goodsSkuName: '',
                categoryCode: '',
                priceOrderType: '',
                startSellPrice: '',
                endSellPrice: '',
                endDiffPrice: '',
                startDiffPrice: ''
            }
            this.pageObj  = {
                total: 0,
                pageSize: 50,
                pageSizes: [40, 50, 60, 70],
                pageNum: 1
            }
            this.getGoodsList()
        },
        handleSearch(){
            this.pageObj.pageNum = 1
            this.getGoodsList()
        },
        addWarehouseFn(item, isAll){
            let params = {
                goodsSkuCodes: [item.goodsSkuCode],
            }
            let tip = `是否把 ${item.goodsSkuName} 添加到仓库?`
            if(isAll){
                params.goodsSkuCodes = this.goodsList.map(item => item.goodsSkuCode)
                tip = `是否把当前页${this.goodsList.length}个商品全部添加到仓库?`
            }
            this.$confirm(tip, '提示', {
                type: 'warning',
                callback: action => {
                    if(action=='confirm'){
                        this.$apis.platformGoods.addWarehouseApi(params).then(res=>{
                            if(res){
                                this.$message.success('操作成功')
                                this.getGoodsList()
                            }
                        })
                    }
                }
            })
        }
    }
  }
</script>
  
<style scoped lang="scss">
.ctnr{
    background-color: #fff;
    padding: 20px;
    
    .noData{
        height: calc(100vh - 310px);
        min-height: 300px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        text-align: center;
        color: #666;
        img{
            width: 320px;
            height: 94px;
        }
    }
    .goods-wrap{
        // display: flex;
        // flex-wrap: wrap;
        // overflow-y: auto;
        // height: 700px;
        display: grid;
        grid-template-columns: 20% 20% 20% 20% 20%;
        .goods-box{
            // flex: 0 1 216px;
            // width: 216px;
            height: 346px;
            background: #F9F9F9;
            border-radius: 4px;
            margin-left: 16px;
            margin-bottom: 20px;
            padding: 12px;
            box-sizing: border-box;
            position: relative;
            &:nth-last-child(5n){
                margin-left: 0;
            }
            &:nth-last-child(-n+5){
                margin-bottom: 0;
            }
            .mask{
                display: none;
                position: absolute;
                top: 0;
                right: 0;
                left: 0;
                bottom: 0;
                background: rgba(0,0,0,.3);
                border-radius: 4px;
                z-index: 2;
                .add-warehouse{
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    transform: translate(-50%, -50%);
                    &:hover{
                        background: #8A85FF;
                        border-color: #8A85FF;
                    }
                }
            }
            .status-label{
                z-index: 2;
                width: 50px;
                height: 50px;
                position: absolute;
                right: 0;
                top: 0;
            }
            .goods-img{
                width: 100%;
                height: 192px;
                border-radius: 2px;
                display: flex;
                align-items: center;
                justify-content: center;
                img{
                    object-fit: contain;
                    width: 100%;
                    height: 100%;
                    border-radius: 2px;
                }
            }
            .info{
                margin-top: 12px;
                .title{
                    font-weight: 500;
                    font-size: 14px;
                    color: #333;
                    line-height: 22px;
                    margin-bottom: 8px;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    overflow: hidden;
                    text-overflow:ellipsis;
                }
                p{
                    margin: 4px 0 0;
                    line-height: 18px;
                    font-size: 12px;
                    color: #666;
                }
                .inventory{
                    color: #333;
                }
                .supply{
                    color: #EB4E4E;
                    font-weight: 500;
                }
                .market{
                    font-weight: 500;
                    font-size: 13px;
                    color: #333;
                }

            }
        }
        .optional:hover{
            .mask{
                display: block;
            }
        }
        .in-warehouse{
            cursor: not-allowed;
            .mask{
                display: block;
                background: rgba(255, 255, 255, .5);
                .add-warehouse{
                    display: none;
                }
            }
        }
    }
    
}
</style>