shop-applet/pages/product/goodsOnSale/index.vue

518 lines
12 KiB
Vue
Raw Normal View History

2023-09-20 18:16:59 +08:00
<template>
<view class="container">
<view class="title">
<view class="search">
<view class="title_search">
<span class="iconfont">&#xe67d;</span>
<form @submit="search" report-submit="true">
2024-04-10 17:05:24 +08:00
<input type="text" :name="where.keyword" v-model="where.keyword" placeholder="搜索商品"
confirm-type='search' />
</form>
2023-09-20 18:16:59 +08:00
</view>
</view>
<view class="longTab">
2024-04-10 17:05:24 +08:00
<scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation
class="menu" :scroll-left="tabLeft" show-scrollbar="true">
<view class="longItem" :style="'width:' + isWidth + 'px'" :data-index="index"
:class="index === tabClick ? 'click' : ''" v-for="(item, index) in menuList" :key="index"
:id="'id' + index" @click="selectMenu(item, index)">
2023-09-20 18:16:59 +08:00
{{ item.name }}
</view>
2024-04-10 17:05:24 +08:00
<view v-if="menuList.length" class="underlineBox"
:style="'transform:translateX(' + isLeft + 'px);width:' + isWidth + 'px'">
2023-09-20 18:16:59 +08:00
<view class="underline bg-color-white"></view>
</view>
</scroll-view>
</view>
</view>
<view v-if="shopList.length">
<block v-for="(item, index) in shopList" :key="index">
<view class="shop_list">
<view class="shop_list_item">
<view class="shop_list_item_shop">
<view class="shop_list_item_shop_image">
<image :src="item.image"></image>
<text v-if="item.spec_type == 1" class="spec">多规格</text>
</view>
<view class="shop_list_item_shop_con">
<view class="shop_list_item_shop_con_title line1">{{ item.store_name }}</view>
<view class="shop_list_item_shop_con_message">
<span>库存{{ item.stock }}</span>
<span>销量{{ item.sales }}</span>
</view>
<view class="shop_list_item_shop_con_price">
2023-12-01 11:42:20 +08:00
<block v-if="mer_info.type_code=='TypeSupplyChain'">
2024-04-10 17:05:24 +08:00
<block v-if="item.attrValue[0]">
<text class='price font-color'>{{item.attrValue[0].wholesale_price}}</text>
<text class='ot_price'>零售价{{item.attrValue[0].price}}</text>
</block>
<text v-else class='ot_price'>商品规格错误</text>
2023-12-01 11:42:20 +08:00
</block>
<text v-else class='price font-color'>{{item.price}}</text>
2023-09-20 18:16:59 +08:00
</view>
</view>
</view>
<view class="shop_list_item_handle">
2024-04-10 17:05:24 +08:00
<view v-if="item.is_show == 1 && item.status == 1 && type != 5" class="shop_button"
@click="upperShelfAndLowerShelf(item, index)">下架</view>
<view v-if="item.is_show == 0 && item.status == 1 && type != 5" class="shop_button"
@click="upperShelfAndLowerShelf(item, index)">上架</view>
<view class="shop_button" v-if="type != 1 && type != 3" @click="handleDelete(item, index)">
删除</view>
2023-09-20 18:16:59 +08:00
<view class="shop_button" v-if="type == 5" @click="reduction(item, index)">恢复</view>
2024-01-15 10:00:23 +08:00
<block v-if="type != 5">
2024-04-10 17:05:24 +08:00
<navigator v-if="mer_info.type_code=='PersonalStore'"
:url="`/pages/product/addGood/addGood_one?mer_id=${merId}&product_id=${item.product_id}`"
class="shop_button" hover-class="none">编辑</navigator>
<navigator v-else-if="mer_info.type_code=='TypeSupplyChain'"
:url="`/pages/product/addGood/addGood_supply?mer_id=${merId}&product_id=${item.product_id}`"
class="shop_button" hover-class="none">编辑</navigator>
<navigator v-else
:url="`/pages/product/addGood/addGood?mer_id=${merId}&product_id=${item.product_id}`"
class="shop_button" hover-class="none">编辑</navigator>
</block>
2023-09-20 18:16:59 +08:00
</view>
</view>
</view>
</block>
</view>
<Loading :loaded="loaded" :loading="loading"></Loading>
</view>
</template>
<script>
2024-04-10 17:05:24 +08:00
import {
productLstApi,
productTitle,
productDeleteApi,
productOffApi,
productRestore,
productDestory
} from 'api/product.js';
2023-09-20 18:16:59 +08:00
2024-04-10 17:05:24 +08:00
import Loading from '@/components/Loading/index.vue';
import {
Toast,
Modal,
navigateTo,
getStorage,
removeStorage
} from 'libs/uniApi.js';
export default {
components: {
Loading
2023-09-20 18:16:59 +08:00
},
2024-04-10 17:05:24 +08:00
data() {
return {
type: 1,
tabClick: 0,
tabLeft: 0,
isLeft: 0, //导航栏下划线位置
isWidth: 0, //每个导航栏占位
childIndex: 0,
menuList: [],
merId: '',
mer_info: {},
shopList: [],
loaded: false,
loading: false,
where: {
page: 1,
limit: 15,
keyword: '',
},
canNotReade: true
};
2023-09-20 18:16:59 +08:00
},
2024-04-10 17:05:24 +08:00
created() {
var that = this;
// 获取设备宽度
uni.getSystemInfo({
success(e) {
that.isWidth = e.windowWidth / 5;
}
2023-09-20 18:16:59 +08:00
});
},
2024-04-10 17:05:24 +08:00
onLoad(opt) {
let user = this.$store.state.app.userInfo;
if (typeof user == 'string') user = JSON.parse(user);
this.mer_info = user.mer_info;
this.merId = opt.mer_id;
this.getProductTitle();
this.$set(this, 'type', opt.type ? Number(opt.type) : 1);
this.initData();
2023-09-20 18:16:59 +08:00
},
2024-04-10 17:05:24 +08:00
onShow() {},
// 下拉到底部
onReachBottom() {
2023-09-20 18:16:59 +08:00
this.initData();
},
2024-04-10 17:05:24 +08:00
methods: {
initData() {
var that = this;
if (that.loading || that.loaded) return;
that.loading = true;
productLstApi(this.merId, {
...this.where,
type: this.type
}).then(
res => {
that.loading = false;
that.loaded = res.data.list.length < that.where.limit;
that.shopList.push.apply(that.shopList, res.data.list);
that.where.page = that.where.page + 1;
},
error => {
that.$util.Tips({
title: error.msg
});
}
);
},
search() {
let that = this;
that.loading = that.loaded = false;
that.where.page = 1;
that.shopList = [];
that.initData();
},
// 获取列表头部
getProductTitle() {
productTitle(this.merId).then(res => {
this.menuList = res.data;
let clickIndex = 1;
this.menuList.forEach((item, index) => {
if (item.type == this.type) {
clickIndex = index;
}
});
this.setMenuLeft(clickIndex);
2023-09-20 18:16:59 +08:00
});
2024-04-10 17:05:24 +08:00
},
// 点击列表头部
selectMenu(item, index) {
this.type = item.type;
this.loading = this.loaded = false;
this.where.page = 1;
this.shopList = [];
this.setMenuLeft(index);
},
/*导航栏移动位置*/
setMenuLeft(index) {
this.childIndex = 0;
if (this.menuList.length > 5) {
var tempIndex = index - 2;
tempIndex = tempIndex <= 0 ? 0 : tempIndex;
let tabLeft = (index - 2) * this.isWidth; //设置下划线位置
this.$nextTick(function() {
this.$set(this, 'tabLeft', tabLeft);
});
2023-09-20 18:16:59 +08:00
}
2024-04-10 17:05:24 +08:00
this.tabClick = index; //设置导航点击了哪一个
this.isLeft = index * this.isWidth; //设置下划线位置
this.initData();
},
//还原
reduction(item, index) {
Modal('温馨提示', `商品"${item.store_name}",将被还原,请问是否继续`).then(() => {
productRestore(this.merId, item.product_id).then(res => {
this.$util.Tips({
title: res.message,
icon: 'success'
});
this.shopList.splice(index, 1);
});
});
},
editGoods(item) {
// console.log(item);
let waitDeleteData = [
'addGoodsFormData',
'singleSpecification',
'attrValue',
'modifyPriceData',
'addGoodsSecoundData',
'goodsDis',
'editGoodsDetils',
'canChange',
'canChangeSecound'
];
waitDeleteData.forEach(item => {
if (getStorage(item)) {
removeStorage(item);
}
});
navigateTo(1, '/pages/product/addGood/addGood', {
mer_id: this.merId,
type: 'edit',
product_id: item.product_id,
type: 'edit'
});
},
// 加入回收站
handleDelete(item, index) {
item.is_del == 1 ?
Modal('温馨提示', `商品"${item.store_name}"将被删除,请问是否继续?`).then(res => {
2023-09-20 18:16:59 +08:00
productDestory(this.merId, item.product_id)
.then(res => {
this.shopList.splice(index, 1);
Toast('删除成功');
})
.catch(rej => {
Toast(`${rej}`);
});
2024-04-10 17:05:24 +08:00
}) :
Modal('温馨提示', `商品"${item.store_name}"将被加入回收站,请问是否继续?`).then(res => {
2023-09-20 18:16:59 +08:00
productDeleteApi(this.merId, item.product_id)
.then(res => {
this.shopList.splice(index, 1);
Toast('已加入回收站');
})
.catch(rej => {
Toast(`${rej}, 加入回收站失败`);
});
});
2024-04-10 17:05:24 +08:00
},
// 上架下架
upperShelfAndLowerShelf(obj, index) {
let status = obj.is_show == 1 ? 0 : 1;
productOffApi(this.merId, obj.product_id, {
status: status
})
.then(res => {
this.$util.Tips({
title: res.message,
icon: 'success'
});
this.shopList.splice(index, 1);
})
.catch(err => {
return this.$util.Tips({
title: err
});
});
},
handleMethod(item, obj, index) {
if (item.id == 1) {
this.upperShelfAndLowerShelf(obj, index);
return;
}
if (item.id == 2) {
this.addToRecycleBin(obj, index);
return;
}
2023-09-20 18:16:59 +08:00
}
}
2024-04-10 17:05:24 +08:00
};
2023-09-20 18:16:59 +08:00
</script>
<style lang="scss" scoped>
2024-04-10 17:05:24 +08:00
@import './scss/index.scss';
.longTab {
display: flex;
width: 100%;
/* #ifdef H5 */
padding-bottom: 20rpx;
/* #endif */
/* #ifdef MP */
padding-top: 12rpx;
padding-bottom: 12rpx;
/* #endif */
.longItem {
height: 50upx;
display: inline-block;
line-height: 50upx;
text-align: center;
2023-09-20 18:16:59 +08:00
font-size: 30rpx;
2024-04-10 17:05:24 +08:00
color: #282828;
max-width: 160rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
overflow-x: scroll;
overflow-y: hidden;
/*解决ios上滑动不流畅*/
-webkit-overflow-scrolling: touch;
&.click {
font-weight: bold;
font-size: 30rpx;
color: #e93323;
.underline {
opacity: 1;
}
}
}
.underlineBox {
height: 3px;
width: 20%;
display: flex;
align-content: center;
justify-content: center;
transition: 0.5s;
2023-09-20 18:16:59 +08:00
.underline {
2024-04-10 17:05:24 +08:00
width: 60rpx;
height: 4rpx;
background-color: #e93323;
2023-09-20 18:16:59 +08:00
}
}
}
2024-04-10 17:05:24 +08:00
.title_search {
background: #f5f5f5;
border-radius: 30rpx;
height: 60rpx;
padding-left: 60rpx;
position: relative;
2023-09-20 18:16:59 +08:00
2024-04-10 17:05:24 +08:00
.iconfont {
position: absolute;
top: 50%;
margin-top: -14rpx;
left: 30rpx;
font-size: 28rpx;
}
input {
height: 60rpx;
font-size: 26rpx;
margin-left: 20rpx;
2023-09-20 18:16:59 +08:00
}
}
2024-04-10 17:05:24 +08:00
.shop_button {
margin-left: 18rpx;
padding: 0 34rpx;
2023-09-20 18:16:59 +08:00
height: 60rpx;
2024-04-10 17:05:24 +08:00
border: 1px solid #c7c7c7;
border-radius: 30px;
display: flex;
align-items: center;
justify-content: center;
margin-top: 30rpx;
2023-09-20 18:16:59 +08:00
font-size: 26rpx;
2024-04-10 17:05:24 +08:00
color: #999999;
2023-09-20 18:16:59 +08:00
}
2024-04-10 17:05:24 +08:00
.shop_list {
margin-top: 20rpx;
padding: 0 20rpx;
&_item {
padding: 30rpx;
background: #ffffff;
border-radius: 10px;
margin-bottom: 20rpx;
&_shop {
display: flex;
&_image,
uni-image {
2023-09-20 18:16:59 +08:00
width: 150rpx;
height: 150rpx;
2024-04-10 17:05:24 +08:00
border-radius: 16rpx;
position: relative;
image {
width: 150rpx;
height: 150rpx;
}
2023-09-20 18:16:59 +08:00
}
2024-04-10 17:05:24 +08:00
position: relative;
.spec {
color: #ffffff;
background: rgba(0, 0, 0, 0.5);
border-radius: 16rpx 0 16rpx 0;
text-align: center;
font-size: 18rpx;
display: inline-block;
width: 84rpx;
line-height: 30rpx;
position: absolute;
bottom: 0;
right: 0;
2023-09-20 18:16:59 +08:00
}
2024-04-10 17:05:24 +08:00
&_con {
flex: 1;
display: flex;
flex-direction: column;
margin-left: 20rpx;
padding-bottom: 12rpx;
&_title {
font-size: 28rpx;
color: #282828;
max-width: 500rpx;
padding-top: 4rpx;
2023-09-20 18:16:59 +08:00
}
2024-04-10 17:05:24 +08:00
&_message {
margin-top: 15rpx;
font-size: 22rpx;
color: #868686;
>span:nth-child(1) {
display: inline-block;
margin-right: 20rpx;
}
}
&_price {
margin-top: 10rpx;
>span {
display: inline-block;
margin-right: 7rpx;
font-size: 30rpx;
color: #e93323;
}
>del {
color: #bebebe;
font-size: 26rpx;
}
2023-09-20 18:16:59 +08:00
}
2024-04-10 17:05:24 +08:00
.ot_price {
2023-09-20 18:16:59 +08:00
color: #bebebe;
font-size: 26rpx;
2024-04-10 17:05:24 +08:00
margin-left: 10rpx;
// text-decoration: line-through;
2023-09-20 18:16:59 +08:00
}
}
}
2024-04-10 17:05:24 +08:00
&_handle {
2023-09-20 18:16:59 +08:00
display: flex;
2024-04-10 17:05:24 +08:00
justify-content: flex-end;
>view {
margin-left: 18rpx;
padding: 0 34rpx;
height: 60rpx;
border: 1px solid #c7c7c7;
border-radius: 30px;
display: flex;
align-items: center;
justify-content: center;
margin-top: 30rpx;
font-size: 26rpx;
color: #999999;
}
2023-09-20 18:16:59 +08:00
}
}
}
2024-04-10 17:05:24 +08:00
</style>