wangfukang 4 days ago
parent
commit
2944801de1
  1. 16
      pages/login/login.vue
  2. 154
      pages/shop/addGoods.vue

16
pages/login/login.vue

@ -539,12 +539,20 @@
} }
// uni.setStorageSync('area',JSON.stringify(item)) // uni.setStorageSync('area',JSON.stringify(item))
this.shopList = res.result.shop; this.shopList = res.result.shop;
let data = {
regionId: res.result.worker.region
}
uni.setStorageSync('area', JSON.stringify(data))
uni.setStorageSync('peisongyuan', this.peisongyuan) uni.setStorageSync('peisongyuan', this.peisongyuan)
if (this.peisongyuan) { if (this.peisongyuan) {
if (!res.result.worker) {
uni.showToast({
title: '该账号暂无配送员身份',
icon: 'none'
})
this.getCaptchaImg()
return
}
let data = {
regionId: res.result.worker.region
}
uni.setStorageSync('area', JSON.stringify(data))
this.saveLocal(res.result.worker) this.saveLocal(res.result.worker)
uni.reLaunch({ uni.reLaunch({
url: '../worker/index' url: '../worker/index'

154
pages/shop/addGoods.vue

@ -110,6 +110,23 @@
</view> </view>
</view> </view>
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="可搭配商品选择" name="moreBuyProductIds" v-if="formData.isMoreBuy!=1">
<view class="more-buy-select">
<view v-if="moreBuyProductLoading" class="more-buy-empty">加载中...</view>
<view v-else-if="moreBuyProductOptions.length == 0" class="more-buy-empty">暂无可搭配商品</view>
<view
v-else
v-for="item in moreBuyProductOptions"
:key="item.id"
:class="isMoreBuyProductSelected(item.id) ? 'more-buy-option checked' : 'more-buy-option'"
@tap="toggleMoreBuyProduct(item)"
>
<image v-if="item.productPicture" class="more-buy-option-img" :src="item.productPicture"></image>
<text class="more-buy-option-name">{{item.productName}}</text>
<text class="more-buy-option-check">{{isMoreBuyProductSelected(item.id) ? '已选' : '选择'}}</text>
</view>
</view>
</uni-forms-item>
<view id="lunchBoxField" v-if="shopMerchantType == 1 && formData.isMoreBuy==0"> <view id="lunchBoxField" v-if="shopMerchantType == 1 && formData.isMoreBuy==0">
<uni-forms-item label="餐盒费" name="lunchBox"> <uni-forms-item label="餐盒费" name="lunchBox">
<input type="digit" class="content-input" v-model="formData.lunchBox" placeholder="请输入餐盒费" <input type="digit" class="content-input" v-model="formData.lunchBox" placeholder="请输入餐盒费"
@ -195,6 +212,8 @@
categorySonData:[], categorySonData:[],
specValueArr:[], specValueArr:[],
attrValueArr:[], attrValueArr:[],
moreBuyProductLoading:false,
moreBuyProductOptions:[],
scrollTarget:'', scrollTarget:'',
editorIns: null, editorIns: null,
typeItem: {}, typeItem: {},
@ -217,6 +236,7 @@
shopId:'', shopId:'',
sellTime: 0, //可售时间 sellTime: 0, //可售时间
isMoreBuy: 0, isMoreBuy: 0,
moreBuyProductIds: [],
sellBeginTime: '', //可售时段自定义---开始时间 sellBeginTime: '', //可售时段自定义---开始时间
sellEndTime: '', //可售时段自定义---结束时间 sellEndTime: '', //可售时段自定义---结束时间
attributeList: '', attributeList: '',
@ -255,6 +275,9 @@
this.syncSelectedCategory() this.syncSelectedCategory()
} }
this.formData.shopId = uni.getStorageSync('shopId') this.formData.shopId = uni.getStorageSync('shopId')
if (!this.isMoreBuyEnabled()) {
this.getMoreBuyProductOptions()
}
}, },
onLoad(option) { onLoad(option) {
this.getGategoryList() this.getGategoryList()
@ -277,6 +300,7 @@
this.formData.sellEndTime = res.result.sellEndTime this.formData.sellEndTime = res.result.sellEndTime
this.formData.attributeList = res.result.attributeList this.formData.attributeList = res.result.attributeList
this.formData.productGroupBuyPrices = res.result.productGroupBuyPrices this.formData.productGroupBuyPrices = res.result.productGroupBuyPrices
this.formData.moreBuyProductIds = res.result.moreBuyProductIds || ''
this.formData.attributeList1 = new Map() this.formData.attributeList1 = new Map()
this.formData.productName = res.result.productName this.formData.productName = res.result.productName
this.formData.productPicture = res.result.productPicture this.formData.productPicture = res.result.productPicture
@ -452,15 +476,17 @@
// if (valid) { // if (valid) {
if (this.modalType == 0) { if (this.modalType == 0) {
// 添加 避免编辑后传入id等数据 记得删除 // 添加 避免编辑后传入id等数据 记得删除
delete this.formData.id; let submitData = Object.assign({}, this.formData)
if(this.formData.isMoreBuy != 1){ delete submitData.id;
this.formData.isMoreBuy = 0 if(submitData.isMoreBuy != 1){
submitData.isMoreBuy = 0
} }
this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice) submitData.moreBuyProductIds = this.getSubmitMoreBuyProductIds()
this.formData.attributeList = Object.fromEntries(this.formData.attributeList1) submitData.attributeListPrice = JSON.stringify(submitData.attributeListPrice)
this.formData.attributeList = JSON.stringify(this.formData.attributeList) submitData.attributeList = Object.fromEntries(submitData.attributeList1)
submitData.attributeList = JSON.stringify(submitData.attributeList)
this.NB.sendRequest("/app/product/save", this.formData, false, 'post', 'application/json').then((res) => { this.NB.sendRequest("/app/product/save", submitData, false, 'post', 'application/json').then((res) => {
if(res.code == 200){ if(res.code == 200){
uni.showToast({ uni.showToast({
title: "操作成功", title: "操作成功",
@ -471,11 +497,13 @@
}) })
} else if (this.modalType == 1) { } else if (this.modalType == 1) {
// 编辑 // 编辑
this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice) let submitData = Object.assign({}, this.formData)
this.formData.attributeList = Object.fromEntries(this.formData.attributeList1) submitData.moreBuyProductIds = this.getSubmitMoreBuyProductIds()
this.formData.attributeList = JSON.stringify(this.formData.attributeList) submitData.attributeListPrice = JSON.stringify(submitData.attributeListPrice)
this.formData.productPictures = [] submitData.attributeList = Object.fromEntries(submitData.attributeList1)
this.NB.sendRequest("/app/product/edit", this.formData, false, 'post', 'application/json').then((res) => { submitData.attributeList = JSON.stringify(submitData.attributeList)
submitData.productPictures = []
this.NB.sendRequest("/app/product/edit", submitData, false, 'post', 'application/json').then((res) => {
if(res.code == 200){ if(res.code == 200){
uni.showToast({ uni.showToast({
title: "操作成功", title: "操作成功",
@ -624,8 +652,66 @@
blurFormField(){ blurFormField(){
this.scrollTarget = '' this.scrollTarget = ''
}, },
normalizeMoreBuyProductIds(value) {
if (Array.isArray(value)) {
return value.filter(item => item !== '' && item !== null && item !== undefined).map(String)
}
if (value === '' || value === null || value === undefined) {
return []
}
return String(value).split(',').map(item => item.trim()).filter(item => item)
},
getSubmitMoreBuyProductIds() {
if (this.isMoreBuyEnabled()) {
return ''
}
return this.normalizeMoreBuyProductIds(this.formData.moreBuyProductIds).join(',')
},
isMoreBuyProductSelected(id) {
return this.normalizeMoreBuyProductIds(this.formData.moreBuyProductIds).indexOf(String(id)) != -1
},
toggleMoreBuyProduct(item) {
let selectedIds = this.normalizeMoreBuyProductIds(this.formData.moreBuyProductIds)
const id = String(item.id)
const index = selectedIds.indexOf(id)
if (index == -1) {
selectedIds.push(id)
} else {
selectedIds.splice(index, 1)
}
this.formData.moreBuyProductIds = selectedIds
this.$forceUpdate()
},
getMoreBuyProductOptions() {
const shopId = this.formData.shopId || uni.getStorageSync('shopId')
if (!shopId) {
this.moreBuyProductOptions = []
return
}
this.moreBuyProductLoading = true
this.NB.sendRequest('/app/product/getShareList', {
shopId: shopId,
isMoreBuy: 1,
pageNum: 1,
pageSize: 1000
}, false, 'post', 'application/json').then((res) => {
this.moreBuyProductLoading = false
if (res.code == 200 && res.result) {
const records = Array.isArray(res.result.records) ? res.result.records : []
this.moreBuyProductOptions = records.filter(item => item.id != this.formData.id)
}
}).catch(() => {
this.moreBuyProductLoading = false
})
},
checkisMoreBuy(type){ checkisMoreBuy(type){
this.formData.isMoreBuy = type; this.formData.isMoreBuy = type;
if (this.isMoreBuyEnabled()) {
this.formData.moreBuyProductIds = []
} else {
this.formData.moreBuyProductIds = this.normalizeMoreBuyProductIds(this.formData.moreBuyProductIds)
this.getMoreBuyProductOptions()
}
this.syncLunchBoxByMoreBuy() this.syncLunchBoxByMoreBuy()
}, },
isMoreBuyEnabled(){ isMoreBuyEnabled(){
@ -768,6 +854,8 @@
specNum:9999 specNum:9999
}], }],
sellTime:0, //可售时间 sellTime:0, //可售时间
isMoreBuy:0,
moreBuyProductIds:[],
sellBeginTime:'', //可售时段自定义---开始时间 sellBeginTime:'', //可售时段自定义---开始时间
sellEndTime:'', //可售时段自定义---结束时间 sellEndTime:'', //可售时段自定义---结束时间
attributeList:'', attributeList:'',
@ -793,6 +881,7 @@
let str = JSON.stringify(v); let str = JSON.stringify(v);
let data = JSON.parse(str); let data = JSON.parse(str);
this.formData = data; this.formData = data;
this.formData.moreBuyProductIds = this.normalizeMoreBuyProductIds(this.formData.moreBuyProductIds)
// 解析attributeList(商品属性),兼容string和已解析的对象 // 解析attributeList(商品属性),兼容string和已解析的对象
let attrObj = this.formData.attributeList let attrObj = this.formData.attributeList
@ -833,6 +922,9 @@
this.formData.sellTime = this.formData.sellBeginTime != '' ? 1 : 0 this.formData.sellTime = this.formData.sellBeginTime != '' ? 1 : 0
this.syncLunchBoxByMoreBuy() this.syncLunchBoxByMoreBuy()
if (!this.isMoreBuyEnabled()) {
this.getMoreBuyProductOptions()
}
this.modalVisible = true; this.modalVisible = true;
}, },
checkSpecValue(index){ checkSpecValue(index){
@ -1190,6 +1282,44 @@
font-weight: 700; font-weight: 700;
opacity: 0.7; opacity: 0.7;
} }
.more-buy-select {
display: flex;
flex-direction: column;
gap: 14rpx;
}
.more-buy-empty {
color: #999;
line-height: 60rpx;
}
.more-buy-option {
display: flex;
align-items: center;
min-height: 88rpx;
padding: 12rpx;
border: 2rpx solid #eee;
border-radius: 14rpx;
background: #fff;
box-sizing: border-box;
}
.more-buy-option.checked {
border-color: #60F3FF;
background: rgba(96, 243, 255, 0.16);
}
.more-buy-option-img {
width: 64rpx;
height: 64rpx;
margin-right: 14rpx;
border-radius: 10rpx;
}
.more-buy-option-name {
flex: 1;
font-size: 28rpx;
color: #00231C;
}
.more-buy-option-check {
color: #008ba0;
font-size: 24rpx;
}
.group-delete-btn { .group-delete-btn {
flex: 0 0 70rpx; flex: 0 0 70rpx;
width: 70rpx; width: 70rpx;

Loading…
Cancel
Save