From 9802fda53abaff03e3969a7fb70cbc5fb0a81e23 Mon Sep 17 00:00:00 2001 From: zmj <1493694146@qq.com> Date: Tue, 23 Apr 2024 08:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/product/addGood/addGood.vue | 53 +- pages/product/addGoodDetail/addGoodDetail.vue | 108 ++-- pages/product/addGoodDetail/goodsAttr.vue | 24 +- pages/product/addGoodDetail/goodsPrice.vue | 91 +-- pages/product/addGoodDetail/goodsSearch.vue | 32 +- pages/product/addGoodDetail/goodsType.vue | 54 +- pages/product/list/index.vue | 152 +++-- pages/product/updateStock/updateStock.vue | 521 ++++++++++++------ utils/util.js | 92 +++- 9 files changed, 763 insertions(+), 364 deletions(-) diff --git a/pages/product/addGood/addGood.vue b/pages/product/addGood/addGood.vue index d1910df..5dbee42 100644 --- a/pages/product/addGood/addGood.vue +++ b/pages/product/addGood/addGood.vue @@ -26,7 +26,7 @@ + style=" width:140rpx"> @@ -39,9 +39,11 @@ - + + - + @@ -206,8 +208,7 @@ "volume": "", "extension_one": "", "extension_two": "", - open: true, - spec_type: "" + "is_use": 0, }], "cate_name": "", "unit_name": "", @@ -217,7 +218,10 @@ ], "mer_cate_name": "", "spec_type": "0", - "attr": [], + attr: [{ + detail: [], + value: "" + }, ], "specifica": "", "delivery_way": [ @@ -239,7 +243,16 @@ "title": "", "image": [] }, - "stock": "" + "stock": "", + product_attribute: { + address: "", + leval: "", + pack: "", + attr: [{ + label: "", + value: '' + }] + } }, showPouple: false, fileList6: [], @@ -299,8 +312,10 @@ // 选择图片 handleChooseImage() { let that = this; - that.$util.uploadImageOne('upload/image', function(res) { - console.log(that.formData) + that.$util.uploadImages({ + count: 6, + url: 'upload/image' + }, function(res) { that.formData.imageList.push(res.data.path); }); }, @@ -309,6 +324,7 @@ let that = this uni.chooseVideo({ sourceType: ['camera', 'album'], + limit: 6, success: res => { uni.showLoading({ title: '正在上传中。。。' @@ -377,7 +393,7 @@ }, goDetail() { - uni.navigateTo({ + uni.redirectTo({ url: `/pages/product/addGoodDetail/addGoodDetail?mer_id=${this.mer_id}&&formData=${JSON.stringify(this.formData)}&&showSet=${false}` }) }, @@ -386,6 +402,22 @@ url }) }, + preViewImg(url, index) { + let that = this + uni.previewImage({ + urls: [url], + // longPressActions: { + // itemList: ['发送给朋友', '保存图片', '收藏'], + // success: function(data) { + // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片'); + // }, + // fail: function(err) { + // console.log(err.errMsg); + // } + // } + }); + + }, async submit() { let data = uni.$u.deepClone(this.formData) data.image = data.imageList[0] @@ -411,7 +443,6 @@ .catch(rej => { // Toast(rej); }); - console.log(this.formData) } }, onLoad(option) { diff --git a/pages/product/addGoodDetail/addGoodDetail.vue b/pages/product/addGoodDetail/addGoodDetail.vue index 1adf079..13c1809 100644 --- a/pages/product/addGoodDetail/addGoodDetail.vue +++ b/pages/product/addGoodDetail/addGoodDetail.vue @@ -139,33 +139,50 @@ - - + + + + + + 零售价格 + 5000元/斤 + + + 商品库存 + 5000 + - - - - - 零售价 - - - {{item.price}}元/{{item.unit_name}} - - - - - - 批发价 + + + + + + + + 零售价 + + + {{item.price}}元/{{item.unit_name}} + - - {{item.wholesale_price}}元/{{item.wholesale_unit_name}} + + + + + 批发价 + + + {{item.wholesale_price}}元/{{item.wholesale_unit_name}} + - - + + + @@ -308,7 +325,7 @@ "volume": "", "extension_one": "", "extension_two": "", - "open": true, + "is_use": 0, "spec_type": "" }], "cate_name": "", @@ -317,7 +334,10 @@ "mer_cate_id": [], "mer_cate_name": "", "spec_type": "0", - "attr": [], + attr: [{ + detail: [], + value: "" + }, ], "specifica": "", "delivery_way": [], "delivery_free": "", @@ -429,15 +449,15 @@ } }, + // 选择图片 handleChooseImage() { let that = this; - that.$util.uploadImageOne('upload/image', function(res) { - if (that.isDetail) { - that.formData.content.image.push(res.data.path); - } else { - that.formData.imageList.push(res.data.path); - } + that.$util.uploadImages({ + count: 6, + url: 'upload/image' + }, function(res) { + that.formData.imageList.push(res.data.path); }); }, // 上传视频 @@ -579,41 +599,37 @@ .catch(rej => { // Toast(rej); }) - - + }, + initFormData(option) { + this.delivery_way = this.$store.state.app.userInfo?.mer_info.delivery_way.split(',') + this.isWholeSale = this.$store.state.app.userInfo?.mer_info?.wholesale == 2; + this.mer_id = option.mer_id + if (option.formData) { + this.formData = JSON.parse(option.formData) + } } }, onLoad(option) { - this.delivery_way = this.$store.state.app.userInfo?.mer_info.delivery_way.split(',') - this.isWholeSale = this.$store.state.app.userInfo?.mer_info?.wholesale == 2; - this.mer_id = option.mer_id + this.initFormData(option) this.showSet = option.showSet ? JSON.parse(option.showSet) : this.showSet - if (option.typeData) { - this.formData.cate_name = JSON.parse(option.typeData).label - this.formData.cate_id = JSON.parse(option.typeData).value - } - if (option.formData) { - let data = JSON.parse(option.formData) - for (let key in data) { - this.formData[key] = data[key] - } - } let that = this this.isSet2() if (option.product_id) { that.formData.product_id = option.product_id this.mode = 'edit' + this.showSet = true productDetail(option.mer_id, option.product_id).then(res => { this.formData = res.data + //该死的后端,格式不按添加的格式来 this.formData.product_attribute = JSON.parse(this.formData.product_attribute) this.formData.cate_name = this.formData.storeCategory.cate_name this.formData.cate_id = this.formData.storeCategory.store_category_id this.formData.imageList = this.formData.image_list }) } - + console.log(this.formData) // console.log(this.isSet(this.formData.attrValue)) }, onBackPress: function(e) { diff --git a/pages/product/addGoodDetail/goodsAttr.vue b/pages/product/addGoodDetail/goodsAttr.vue index 6e491e0..4f7593d 100644 --- a/pages/product/addGoodDetail/goodsAttr.vue +++ b/pages/product/addGoodDetail/goodsAttr.vue @@ -76,7 +76,7 @@ - {{address.province}}{{address.city}}{{address.district}} + {{(address.province+address.city+address.district )||errMag}} 刷新定位 @@ -103,7 +103,6 @@ 请选择 - @@ -184,7 +183,7 @@ data() { return { - + errMag: "", provinceList: [], cityList: [], districtList: [], @@ -303,22 +302,30 @@ }).then(res => { this.cityList = res.data this.positionList = this.cityList + this.cityList.forEach(item => { + if (this.address.city == item.name) { + this.address.city_code = item.code + } + }) }) }, choseArea() { this.positionType = 2; + console.log(this.address) getArea({ city_code: this.address.city_code }).then(res => { this.areaList = res.data this.positionList = this.areaList + }) }, getLocation() { let that = this uni.getLocation({ - type: 'gcj02', + type: 'wgs84', success: function(res) { + console.log(res, 'res') getGeocoder({ lat: res.latitude, long: res.longitude @@ -331,6 +338,7 @@ } }) }).catch(err => { + console.log("获取位置失败") uni.showToast({ title: err, icon: 'none' @@ -338,13 +346,16 @@ }) + }, + fail: function(err) { + that.errMag = "获取位置失败,请手动先择" + console.log('sad', err) } }); }, submit() { let that = this - console.log(this.mer_id) - uni.navigateTo({ + uni.reLaunch({ url: `/pages/product/addGoodDetail/addGoodDetail?mer_id=${that.mer_id}&&formData=${JSON.stringify(that.formData) }` }) @@ -354,6 +365,7 @@ onLoad(option) { getProvince().then(res => { this.provinceList = res.data + this.positionList = res.data }) this.formData = JSON.parse(option.formData) if (option.mer_id) { diff --git a/pages/product/addGoodDetail/goodsPrice.vue b/pages/product/addGoodDetail/goodsPrice.vue index 5bf0031..cd3c16b 100644 --- a/pages/product/addGoodDetail/goodsPrice.vue +++ b/pages/product/addGoodDetail/goodsPrice.vue @@ -1,14 +1,15 @@ \ No newline at end of file diff --git a/utils/util.js b/utils/util.js index 15c59f1..ce14983 100644 --- a/utils/util.js +++ b/utils/util.js @@ -590,28 +590,28 @@ export default { */ uploadImageOne: function(opt, successCallback, errorCallback) { let that = this; - let obj = {}; + let obj = {}; if (typeof opt === 'string') { let url = opt; opt = {}; opt.url = url; - }else { - opt.crop ? obj.crop = opt.crop : null; - } + } else { + opt.crop ? obj.crop = opt.crop : null; + } let count = opt.count || 1, sizeType = opt.sizeType || ['compressed'], sourceType = opt.sourceType || ['album', 'camera'], is_load = opt.is_load || true, uploadUrl = opt.url || '', inputName = opt.name || 'field'; - + uni.chooseImage({ count: count, //最多可以选择的图片总数 sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有 sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有 - ...obj, + ...obj, success: function(res) { - console.log(res); + console.log(res); //启动上传等待中... uni.showLoading({ title: '图片上传中', @@ -657,6 +657,84 @@ export default { } }) }, + /* + * 多上传 + * @param object opt + * @param callable successCallback 成功执行方法 data + * @param callable errorCallback 失败执行方法 + */ + uploadImages: function(opt, successCallback, errorCallback) { + let that = this; + let obj = {}; + if (typeof opt === 'string') { + let url = opt; + opt = {}; + opt.url = url; + } else { + opt.crop ? obj.crop = opt.crop : null; + } + let count = opt.count || 1, + sizeType = opt.sizeType || ['compressed'], + sourceType = opt.sourceType || ['album', 'camera'], + is_load = opt.is_load || true, + uploadUrl = opt.url || '', + inputName = opt.name || 'field'; + + uni.chooseImage({ + count: count, //最多可以选择的图片总数 + sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有 + sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有 + ...obj, + success: function(res) { + console.log(res.tempFilePaths); + //启动上传等待中... + uni.showLoading({ + title: '图片上传中', + }); + res.tempFilePaths.forEach((item, index) => { + uni.uploadFile({ + url: HTTP_REQUEST_URL + '/api/' + uploadUrl + '/' + inputName, + filePath: item, + name: inputName, + formData: { + 'filename': inputName + }, + header: { + // #ifdef MP + "Content-Type": "multipart/form-data", + // #endif + [TOKENNAME]: 'Bearer ' + store.state.app.token + }, + success: function(res) { + uni.hideLoading(); + if (res.statusCode == 403) { + that.Tips({ + title: res.data + }); + } else { + let data = res.data ? JSON.parse(res.data) : {}; + if (data.status == 200) { + successCallback && successCallback(data) + } else { + errorCallback && errorCallback(data); + that.Tips({ + title: data.message + }); + } + } + }, + fail: function(res) { + uni.hideLoading(); + that.Tips({ + title: '上传图片失败' + }); + } + }) + }) + + } + }) + }, /** * 小程序头像获取上传 * @param uploadUrl 上传接口地址