更新了扫码入库功能,新增上传商品图片,修改产品名称

This commit is contained in:
weipengfei 2023-11-04 14:33:54 +08:00
parent 35fa04c9d5
commit e53c0fffcc
2 changed files with 187 additions and 25 deletions

View File

@ -16,6 +16,14 @@ export function microProductAdd(data) {
return request.post('micro/product_add', data); return request.post('micro/product_add', data);
} }
/**
* 添加商品库审核
*
*/
export function microProductEdit(data) {
return request.post('micro/eadt_product', data);
}
/** /**
* 获取收款二维码 * 获取收款二维码
* @returns {*} * @returns {*}

View File

@ -14,12 +14,13 @@
<view class="top"> <view class="top">
<view class="pictrue"> <view class="pictrue">
<!-- <easy-loadimage mode="widthFix" :image-src="item.image"></easy-loadimage> --> <!-- <easy-loadimage mode="widthFix" :image-src="item.image"></easy-loadimage> -->
<image class="img" :src="item.image||defaultImageSRC" :lazy-load="true"></image> <image class="img" :src="item.image||defaultImageSRC" :lazy-load="true" @click="clickImg(item, 1, 0)"></image>
<view class="swiper"> <view class="swiper">
<image :src="item.slider_image[0]||defaultImageSRC" :lazy-load="true"></image> <image :src="item.slider_image[0]||defaultImageSRC" :lazy-load="true" @click="clickImg(item, 2, 0)"></image>
<image :src="item.slider_image[1]||defaultImageSRC" :lazy-load="true"></image> <image :src="item.slider_image[1]||defaultImageSRC" :lazy-load="true" @click="clickImg(item, 2, 1)"></image>
<image :src="item.slider_image[2]||defaultImageSRC" :lazy-load="true"></image> <image :src="item.slider_image[2]||defaultImageSRC" :lazy-load="true" @click="clickImg(item, 2, 2)"></image>
</view> </view>
<view v-if="item.update" class="btn" @click="updateItemImage(item)">保存修改</view>
</view> </view>
<view class="text-info"> <view class="text-info">
<view class="title"> <view class="title">
@ -135,7 +136,7 @@
<u-popup :show="addGoodsShow" @close="searchGoodsClose" :round="18" mode="center"> <u-popup :show="addGoodsShow" @close="searchGoodsClose" :round="18" mode="center">
<view class="search_goods_box"> <view class="search_goods_box">
<view style="text-align: center;font-weight: bold;">完善商品信息</view> <view style="text-align: center;font-weight: bold;">完善商品信息</view>
<view v-if="showPutGoodsInput.store_name" style="display: flex;align-items: center;margin-top: 16rpx;"> <view style="display: flex;align-items: center;margin-top: 16rpx;">
<view style="margin-right: 20rpx;">名称:</view> <view style="margin-right: 20rpx;">名称:</view>
<input style="flex: 1;" type="text" v-model="putGoods.store_name" class="putGoods" placeholder="请输入商品名称"> <input style="flex: 1;" type="text" v-model="putGoods.store_name" class="putGoods" placeholder="请输入商品名称">
</view> </view>
@ -176,19 +177,25 @@
</template> </template>
<script> <script>
import {
TOKENNAME,
HTTP_REQUEST_URL
} from '@/config/app.js';
import { import {
productCreate productCreate
} from '@/api/product.js' } from '@/api/product.js'
import { import {
microSeachBarCode, microSeachBarCode,
microEadtProduct, microEadtProduct,
microProductAdd microProductAdd,
microProductEdit
} from '@/api/store.js' } from '@/api/store.js'
import { import {
seachBarCodeAPI, seachBarCodeAPI,
micro_product_import micro_product_import
} from '@/api/api.js' } from '@/api/api.js'
import { import {
chooseImage,
Toast Toast
} from '@/libs/uniApi' } from '@/libs/uniApi'
export default { export default {
@ -233,33 +240,37 @@
showModel: false, showModel: false,
goods: [ goods: [
// { // {
// "id": 56, // "id": 35,
// "store_name": "400 400g", // "store_name": "DT1515015024",
// "bar_code": "8998389621348", // "bar_code": "6903244675314",
// "manu_address": null, // "manu_address": "",
// "price": "0.00", // "price": "0.00",
// "stock": 9999999, // "stock": 9999999,
// "image": "http://lihai001.oss-cn-chengdu.aliyuncs.com/def/2023-11-02/202311021119037679.jpg", // "image": "https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png",
// "slider_image": [ // "slider_image": [],
// "http://lihai001.oss-cn-chengdu.aliyuncs.com/def/2023-11-02/202311021119037679.jpg" // "spec": "1",
// ], // "trademark": "",
// "spec": null, // "manu_name": null,
// "trademark": null, // "note": ""
// "manu_name": null,
// "note": null
// }, // },
], ],
putGoods: { putGoods: { //
id: '', id: '',
price: '', price: '',
stock: '', stock: '',
store_name: '',
images: [], images: [],
}, },
uploadImgInfo:{ //
id: '',
type: 1,
index: 0
},
uploadImgIdList: new Map(),//,
showPutGoodsInput: { showPutGoodsInput: {
spec: false, spec: false,
trademark: false, trademark: false,
store_name: false
}, },
item: [], item: [],
addGoodsShow: false, addGoodsShow: false,
@ -273,9 +284,15 @@
}, },
methods: { methods: {
addGoods(item) { addGoods(item) {
if(this.isNullImage(item.image)||
( this.isNullImage(item.slider_image[0]) && this.isNullImage(item.slider_image[1]) && this.isNullImage(item.slider_image[2]) )){
return Toast('请先上传商品图片后再加入店铺');
}
if(item.update) return Toast('请保存修改后再添加');
this.putGoods.id = item.id; this.putGoods.id = item.id;
this.putGoods.price = ''; this.putGoods.price = '';
this.putGoods.stock = ''; this.putGoods.stock = '';
this.putGoods.store_name = item.store_name;
Object.keys(this.showPutGoodsInput).forEach((key)=>{ Object.keys(this.showPutGoodsInput).forEach((key)=>{
if(item[key]==null||item[key]==undefined||item[key]==''){ if(item[key]==null||item[key]==undefined||item[key]==''){
this.showPutGoodsInput[key] = true; this.showPutGoodsInput[key] = true;
@ -290,10 +307,135 @@
this.addGoodsShow = true this.addGoodsShow = true
this.item = item this.item = item
}, },
isNullImage(src){
let flag = false;
if(src==this.defaultImageSRC||!src)flag =true;
return flag;
},
clickImg(data, type, index){
if(!data.update&&!this.uploadImgIdList.get(data.id)){
let arr = [];
if(this.isNullImage(data.image))arr.push(-1);
if(this.isNullImage(data.slider_image[0]))arr.push(0);
if(this.isNullImage(data.slider_image[1]))arr.push(1);
if(this.isNullImage(data.slider_image[2]))arr.push(2);
this.uploadImgIdList.set(data.id, arr)
}
let obj = this.uploadImgIdList.get(data.id) || [];
if(type==1&&!obj.includes(-1)) return ;
if(type==2&&!obj.includes(index)) return ;
this.uploadImgInfo.id = data.id;
this.uploadImgInfo.type = type;
this.uploadImgInfo.index = index;
if(data.image==this.defaultImageSRC||(type==2&&this.isNullImage(data.slider_image[index]))){
this.chooseImg()
}else if(data.update){
this.chooseImg()
}
},
chooseImg(){
let that = this;
uni.chooseImage({
count: 1,
sizeType: ['original'],
crop:{
width: 1024,
height: 1024,
resize: false
},
success: (res) => {
let tempFilePaths = res.tempFilePaths[0]
//#ifdef APP-PLUS
if (uni.getSystemInfoSync().platform == 'ios') {
that.doUpload(tempFilePaths)
} else {
let size = res.tempFiles[0].size / 1024
if (size >= 1) {
uni.compressImage({
src: tempFilePaths,
quality: 80, // jpg
success: res => {
that.doUpload(res.tempFilePath)
},
fail: err => {
that.doUpload(tempFilePaths)
}
})
} else {
that.doUpload(tempFilePaths)
}
}
//#endif
//#ifndef APP-PLUS
that.doUpload(tempFilePaths)
//#endif
}
})
},
doUpload(rsp) {
let that = this
uni.showLoading({
title: '上传中',
mask: true
})
uni.uploadFile({
url: HTTP_REQUEST_URL + '/api/upload/image/field',
filePath: rsp,
name: 'field',
header: {
// #ifdef MP
"Content-Type": "multipart/form-data",
// #endif
[TOKENNAME]: 'Bearer ' + that.$store.state.app.token
},
success: (uploadFileRes) => {
let imgData = JSON.parse(uploadFileRes.data)
if(this.uploadImgInfo.type==1){
this.goods.forEach(item=>{
if(item.id==this.uploadImgInfo.id){
item.image = imgData.data.path;
item.update = true;
}
})
this.putGoods.image = imgData.data.path;
}else if(this.uploadImgInfo.type==2){
this.goods = this.goods.map(item=>{
if(item.id==this.uploadImgInfo.id){
item.slider_image[this.uploadImgInfo.index] = imgData.data.path;
item.update = true;
}
return item;
})
this.putGoods.slider_image[this.uploadImgInfo.index] = imgData.data.path;
}
},
complete(res) {
let data = JSON.parse(res.data)
that.$util.Tips({
title: data.message
});
}
});
},
//
updateItemImage(item){
microProductEdit({
id: item.id,
image: item.image,
slider_image: item.slider_image.join(',')
}).then((res)=>{
this.goods = this.goods.map(e=>{
if(e.id==item.id)e.update = false;
return e;
})
Toast('更新成功')
}).catch(err=>{
Toast(err||'更新失败')
})
},
// //
addGoodsopen() { async addGoodsopen() {
let good = this.goods.find(item=>item.id==this.putGoods.id); let good = this.goods.find(item=>item.id==this.putGoods.id);
// console.log(good);
if (this.putGoods.id&&good) { if (this.putGoods.id&&good) {
// //
let auditFlag = false; let auditFlag = false;
@ -317,7 +459,7 @@
this.addGoodsShow = false; this.addGoodsShow = false;
} else { } else {
Toast(e.message) Toast(e.message)
this.addGoodsShow = false this.addGoodsShow = false;
} }
}).catch(err => { }).catch(err => {
Toast(err || '导入出错'); Toast(err || '导入出错');
@ -1053,6 +1195,18 @@
height: 60rpx; height: 60rpx;
} }
} }
.btn{
font-size: 24rpx;
margin: 0 auto;
margin-top: 10rpx;
width: 120rpx;
height: 40rpx;
background-color: #419aff;
color: #fff;
line-height: 40rpx;
text-align: center;
border-radius: 40rpx;
}
} }
.text-info { .text-info {