123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- <template>
- <view>
- <view class="search-view">
- <u-search
- @custom="searchList()"
- @search="searchList()"
- @clear="searchList()"
- action-text="搜索"
- :clearabled="true"
- placeholder="请输入商品名称"
- v-model="keyword"
- ></u-search>
- </view>
- <view class="main-view clearfix">
- <view class="left-view float_left">
- <scroll-view scroll-y="true" class="left-scroll">
- <view class="cate-li" :class="[!category_id ? 'cate-on' : '']" @click="changeCate(0)">全部</view>
- <view
- class="cate-li ellipsis"
- v-for="(item, index) in category_list"
- :key="index"
- @click="changeCate(item.id)"
- :class="[category_id === item.id ? 'cate-on' : '']"
- >
- {{ item.title }}
- </view>
- </scroll-view>
- </view>
- <view class="rigth-view float_left">
- <scroll-view scroll-y="true" @scrolltolower="scrolltolower" class="rigth-scroll" :scroll-top="scrollTop">
- <view class="goods-li" v-for="(item, index) in goods_list" :key="index">
- <view class="add-btn">
- <text @click="addGoods(index)" v-if="item.buyNum === 0" class="custom-icon custom-icon-xinzeng"></text>
- <u-number-box v-else :min="0" :index="index" @change="buyNumChange" :value="item.buyNum"></u-number-box>
- </view>
- <view class="goods-main clearfix">
- <image class="goods-img float_left" :src="item.images[0]" mode="aspectFill"></image>
- <view class="goods-info float_left">
- <view class="goods-name ellipsis">{{ item.materielName }}</view>
- <view class="goods-code">{{ item.materielCode }}</view>
- <view class="goods-code">
- {{ item.unitName }};
- <text v-for="(sku, skuI) in item.specGroup" :key="skuI">{{ sku.specValueName }};</text>
- </view>
- <view class="num-ul">
- <view class="num-li">
- <view class="label">库存量</view>
- {{ $utils.formatNub(item.inventoryNum) }}{{ item.unitName }}
- </view>
- <view class="num-li">
- <view class="label">平均成本</view>
- ¥{{ $utils.formatNub(item.costPrice) }}
- </view>
- <view class="num-li">
- <view class="label">总成本</view>
- ¥{{ $utils.formatNub(item.total) }}
- </view>
- </view>
- <view class="goods-tag"><u-tag class="tag-li" mode="plain" size="mini" :text="item.categoryName" /></view>
- </view>
- </view>
- </view>
- <u-loadmore :status="load_status" />
- </scroll-view>
- </view>
- </view>
- <view class="bottom-view clearfix">
- <view class="float_left" @click="openPop">
- <view class="shop-icon-view"><u-icon name="shopping-cart-fill" class="uicon" color="#ffffff" size="40"></u-icon></view>
- <text>共{{ add_goods.length }}个商品</text>
- </view>
- <view class="float_right"><u-button type="primary" size="medium" @click="addGoodsTo">选好了</u-button></view>
- </view>
- <u-popup v-model="sel_pop" mode="bottom">
- <view class="sel-goods-pop">
- <view class="pop-tit clearfix">
- <view class="float_left">本次已选商品</view>
- <view class="float_right" @click="clearGoods">
- <text class="custom-icon custom-icon-shanchu"></text>
- <text>清空</text>
- </view>
- </view>
- <scroll-view class="goods-ul" scroll-y>
- <view class="goods-li" v-for="(item, index) in add_goods" :key="index">
- <view class="goods-name">{{ item.title }}</view>
- <view class="goods-code clearfix">{{ item.code }}</view>
- <view class="goods-code clearfix">
- <view class="float_left">
- {{ item.unitName }};
- <block v-if="item.specGroup">
- <text v-for="(sku, skuI) in item.specGroup" :key="skuI">{{ sku.specValueName }};</text>
- </block>
- <text v-else>{{ item.specGropName }}</text>
- </view>
- <view class="float_right"><u-number-box :min="0" :index="index" @change="addBuyNumChange" :value="item.buyNum"></u-number-box></view>
- </view>
- <text class="custom-icon custom-icon-shanchu" @click="delGoods(index)"></text>
- </view>
- <view style="padding-top: 100rpx;" v-if="!add_goods.length"><u-empty text="未选择商品" mode="data"></u-empty></view>
- </scroll-view>
- <view class="btn-view" @click="addGoodsTo">选好了</view>
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- sel_pop: false, //已选商品
- load_status: 'nomore',
- activeName: 'all',
- keyword: '',
- is_more: false,
- page: 1,
- pageSize: 10,
- total: 0,
- category_list: [], // 分类列表
- category_id: '', // 分类id
- auditStatus: 2, // 审核状态
- goods_list: [],
- add_goods: [],
- sel_goods_id: [],
- goods_detail: {},
- isRevealSku: 4, // 5 只显示基本单位 4:主辅助单位都显示
- shopId: '',
- scrollTop: -1,
- warehouseId: ''
- };
- },
- onLoad(options) {
- this.warehouseId = options.id;
- this.add_goods = uni.getStorageSync('warehouseGoods').map(item => {
- return {
- ...item,
- title: item.materielName,
- code: item.materielCode
- };
- });
- console.log(this.add_goods)
- this.getAllCategory();
- this.getInventoryByWarehouseId();
- },
- methods: {
- clearGoods() {
- this.add_goods = [];
- },
- openPop() {
- this.sel_pop = true;
- },
- addGoodsTo() {
- this._prePage().warehouseGoods = this.add_goods;
- uni.navigateBack();
- },
- // 滚动到底部,触发上拉加载
- scrolltolower() {
- if (this.total / this.pageSize > this.page) {
- this.page += 1;
- this.getInventoryByWarehouseId();
- }
- },
- buyNumChange({ value, index }) {
- let target = this.$u.deepClone(this.goods_list);
- target[index].buyNum = value;
- let addGoods = this.$u.deepClone(this.add_goods);
- const goodsI = addGoods.findIndex(item => item.skuId === target[index].skuId);
- if (!Number(value)) {
- addGoods.splice(goodsI, 1);
- } else {
- addGoods[goodsI].buyNum = value;
- }
- this.add_goods = addGoods;
- this.goods_list = target;
- },
- addBuyNumChange({ value, index }) {
- let target = this.$u.deepClone(this.goods_list);
- let addGoods = this.$u.deepClone(this.add_goods);
- const goodsI = target.findIndex(item => item.skuId === addGoods[index].skuId);
- if (!Number(value)) {
- addGoods.splice(goodsI, 1);
- } else {
- addGoods[index].buyNum = value;
- }
- if (goodsI > -1) {
- target[goodsI].buyNum = value;
- }
- this.add_goods = addGoods;
- this.goods_list = target;
- },
- delGoods(index) {
- let target = this.$u.deepClone(this.goods_list);
- const goodsI = target.findIndex(item => item.skuId === this.add_goods[index].skuId);
- if (goodsI > -1) {
- target[goodsI].buyNum = 0;
- }
- this.goods_list = target;
- this.add_goods.splice(index, 1);
- },
- // 获取商品列表
- getInventoryByWarehouseId() {
- this.load_status = 'loading';
- this.$u.api
- .getInventoryByWarehouseId({
- page: this.page,
- pageSize: this.pageSize,
- warehouseId: this.warehouseId,
- categoryId: this.category_id
- })
- .then(res => {
- const list = res.data.map(item => {
- const goods = this.add_goods.find(agoods => agoods.skuId === item.skuId);
- return {
- ...item,
- buyNum: goods ? (goods.buyNum||goods.num) : 0
- };
- });
- if (this.page === 1) {
- this.goods_list = list;
- } else {
- this.goods_list = this.goods_list.concat(list);
- }
- // console.log(res.data)
- this.total = res.pageTotal;
- this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
- });
- },
- // 获取所有商品分类
- getAllCategory() {
- this.$u.api
- .getAllCategory({
- enableStatus: 5
- })
- .then(res => {
- this.category_list = res.data;
- });
- },
- // 切换分类
- changeCate(id) {
- this.scrollTop = 0;
- this.$nextTick(() => {
- this.scrollTop = -1;
- });
- this.category_id = id;
- this.page = 1;
- this.searchList();
- },
- searchList() {
- this.page = 1;
- this.getInventoryByWarehouseId();
- },
- addGoods(index) {
- const target = this.$u.deepClone(this.goods_list);
- const isindex = this.add_goods.findIndex(item => item.skuId === target[index].skuId);
- if (isindex === -1) {
- target[index].buyNum = 1;
- this.add_goods.push(target[index]);
- } else {
- this.add_goods[isindex].buyNum += target[index].buyNum;
- }
- this.goods_list = target;
- }
- }
- };
- </script>
- <style scoped lang="scss">
- .bottom-view {
- box-shadow: 0px 2px 12rpx rgba(0, 0, 0, 0.2);
- position: fixed;
- width: 100%;
- padding: 20rpx;
- bottom: 0;
- left: 0;
- background-color: #ffffff;
- .float_left {
- line-height: 70rpx;
- .shop-icon-view {
- display: inline-block;
- width: 60rpx;
- height: 60rpx;
- border-radius: 100%;
- background-color: $uni-color-primary;
- text-align: center;
- line-height: 60rpx;
- vertical-align: middle;
- margin-right: 20rpx;
- .uicon {
- display: inline-block;
- margin-top: 6rpx;
- }
- }
- }
- }
- .search-view {
- background-color: #ffffff;
- padding: 20rpx;
- .input-view {
- padding: 0 24rpx;
- input {
- height: 60rpx;
- line-height: 60rpx;
- padding: 0 24rpx;
- margin: 0 auto;
- width: 620rpx;
- border: 1px solid #f5f5f5;
- vertical-align: middle;
- border-radius: 8rpx;
- background-color: #f7f8fa;
- }
- }
- .search-other {
- display: flex;
- border-bottom: 1px solid #f5f5f5;
- .search-li {
- flex: 2;
- text-align: center;
- font-size: 24rpx;
- line-height: 80rpx;
- .arrow-down {
- margin-left: 10rpx;
- }
- }
- }
- }
- .main-view {
- .left-view {
- width: 168rpx;
- background-color: #f7f8fa;
- .left-scroll {
- width: 100%;
- height: calc(100vh - 214rpx);
- .cate-li {
- line-height: 90rpx;
- padding-left: 36rpx;
- color: #666666;
- }
- .cate-on {
- background-color: #ffffff;
- color: #000000;
- position: relative;
- &::before {
- content: '';
- display: block;
- width: 6rpx;
- height: 20rpx;
- background-color: $uni-color-primary;
- position: absolute;
- left: 14rpx;
- top: 50%;
- transform: translateY(-50%);
- }
- }
- }
- }
- .rigth-view {
- width: calc(100% - 168rpx);
- background-color: #ffffff;
- .rigth-scroll {
- width: 100%;
- height: calc(100vh - 214rpx);
- .goods-li {
- padding: 20rpx;
- border-bottom: 1px solid #f5f5f5;
- position: relative;
- .add-btn {
- position: absolute;
- right: 20rpx;
- bottom: 20rpx;
- .custom-icon {
- color: #ffffff;
- font-size: 32rpx;
- display: block;
- width: 46rpx;
- height: 46rpx;
- text-align: center;
- line-height: 46rpx;
- background-color: $uni-color-primary;
- border-radius: 100%;
- }
- }
- .add-on {
- background-color: #999999;
- }
- .goods-main {
- .goods-img {
- border-radius: 10rpx;
- width: 156rpx;
- height: 156rpx;
- margin-right: 20rpx;
- }
- .goods-info {
- width: 366rpx;
- .num-ul {
- display: flex;
- padding-top: 20rpx;
- .num-li {
- font-size: 24rpx;
- line-height: 36rpx;
- flex: 3;
- text-align: center;
- position: relative;
- font-weight: bold;
- .label {
- font-weight: 400;
- color: #999999;
- }
- &::after {
- display: block;
- content: '';
- position: absolute;
- width: 1px;
- height: 60rpx;
- top: 50%;
- transform: translateY(-50%);
- right: 0;
- background-color: #eeeeee;
- }
- &:last-child {
- &::after {
- display: block;
- content: '';
- position: absolute;
- width: 1px;
- height: 50rpx;
- top: 50%;
- transform: translateY(-50%);
- right: 0;
- background-color: transparent;
- }
- }
- }
- }
- .goods-name {
- -webkit-line-clamp: 1;
- }
- .goods-code {
- font-size: 24rpx;
- padding-top: 6rpx;
- }
- .goods-tag {
- padding: 10rpx 0;
- .tag-li {
- margin-right: 14rpx;
- }
- }
- .goods-num {
- color: #999999;
- font-size: 22rpx;
- text {
- padding-right: 10rpx;
- }
- }
- }
- }
- }
- }
- }
- }
- .sel-goods-pop {
- padding-bottom: 1px;
- .pop-tit {
- line-height: 70rpx;
- background-color: #f5f5f5;
- padding: 0 24rpx;
- .float_right {
- font-size: 24rpx;
- color: #666666;
- .custom-icon-shanchu {
- font-size: 26rpx;
- margin-right: 10rpx;
- }
- }
- }
- .goods-ul {
- min-height: 400rpx;
- max-height: 600rpx;
- .goods-li {
- padding: 24rpx;
- position: relative;
- border-bottom: 1px solid #f5f5f5;
- .goods-name {
- width: 660rpx;
- }
- .goods-code {
- padding-top: 10rpx;
- font-size: 24rpx;
- color: #999999;
- }
- .custom-icon-shanchu {
- position: absolute;
- right: 24rpx;
- top: 24rpx;
- width: 40rpx;
- height: 40rpx;
- color: $uni-color-error;
- }
- }
- }
- .btn-view {
- width: 680rpx;
- height: 70rpx;
- line-height: 70rpx;
- border-radius: 10rpx;
- background-color: $uni-color-primary;
- color: #ffffff;
- text-align: center;
- margin: 20rpx auto;
- }
- }
- </style>
|