From 3d93e06173e66c04196cc3b3fd1f0ec985e98642 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Sat, 18 Nov 2023 19:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E6=B7=BB=E5=8A=A0=E5=95=86?= =?UTF-8?q?=E5=93=81=E9=A1=B5=E9=9D=A2(=E8=BF=9B=E8=A1=8C=E4=B8=AD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/product/addGood/addGood.vue | 193 +++++++++++++++++++++++------- 1 file changed, 152 insertions(+), 41 deletions(-) diff --git a/pages/product/addGood/addGood.vue b/pages/product/addGood/addGood.vue index cfa503b..93a54d1 100644 --- a/pages/product/addGood/addGood.vue +++ b/pages/product/addGood/addGood.vue @@ -35,15 +35,15 @@ - - - - + + + + - + - + @@ -58,32 +58,34 @@ - + 商品单位 - + - + - + - - + + + - - + - + 关键字 - + - + - + 提交 - + - + - + @@ -153,14 +155,23 @@ attrList, templateList, productDetail, - getDeliveryType + getDeliveryType, + productCreate, + productUpdate } from '@/api/product.js'; + import { + serialize, + Toast, + Loading, + hideLoading, + Modal + } from "@/libs/uniApi.js"; import avatar from "@/components/yq-avatar/yq-avatar.vue"; import platfrom from "./components/platform.vue"; import commodityComponent from "./components/commodity.vue"; import priceComponent from "./components/price.vue"; export default { - components:{ + components: { avatar, platfrom, commodityComponent, @@ -174,11 +185,23 @@ code: '', //商品条码 show: false, //是否预览图片 image: false, //预览的图 - setFormData:{ + setFormData: { store_name: '', imageList: [], - cate_name: '', //平台分类 + cate_name: '', //平台名称 unit_name: '', //商品单位 + cate_id: '', // 平台分类id + mer_cate_id: '', // 店铺分类 + mer_cate_name: '', // 店铺分类名称 + spec_type: '0', // 0.单规格 1:多规格 + attr: [], // 商品规格 + specifica: '', // 商品规格名称 + setSpecificaValue: '', // 价格设置提示 + setSpecificaValue2: '', + delivery_way: [1, 2], // 配送方式 1 到店核销 2 快递配送 + delivery_free: '1', // 是否包邮 0不包邮 1包邮 + temp_id: '', // 运费模板ID + tempName: '' // 运费模板名称 }, platformClassificationData: [], // 平台分类数据 merchantClassification: [], // 店铺分类 @@ -207,18 +230,58 @@ onLoad(opt) { this.merId = Number(opt.mer_id); this.product_id = opt.product_id; - if(!opt.product_id)this.showCommodity=true; + if (!opt.product_id) this.showCommodity = true; this.initData(); this.initClasiffy(); }, - onBackPress() { - - }, + onBackPress() {}, onShow() { - + this.setFormData = Object.assign(this.setFormData, { + "store_name": "方法", + "imageList": [ + "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/457c6202311181745387896.jpeg", + "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/185e2202311181745434402.jpeg" + ], + "cate_name": "丧葬服务", + "unit_name": "给", + "cate_id": 445, + "keyword": "22" + }) + this.$nextTick(() => { + this.$refs.commodityRef.addGoodsSecoundData = { + "is_good": 1, + "is_gift_bag": 0, + "sort": "20", + "once_count": "", + "video_link": "https://lihai001.oss-cn-chengdu.aliyuncs.com/media/7ce3d202311181816166215.mp4" + } + this.$refs.commodityRef.goodsDis = { + "store_name": "", + "imageList": [ + "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/fb73d202311181751262661.png" + ] + } + this.$refs.priceRef.singleSpecification = { + "price": "1", + "cost": "1", + "stock": "11", + "ot_price": "", + "procure_price": "", + "bar_code": "666", + "weight": "10", + "volume": "5", + "image": "", + "extension_one": "", + "extension_two": "" + } + }) }, - beforeDestroy() { - + beforeDestroy() {}, + watch: { + 'setFormData.imageList'(val) { + this.setFormData.image = val.length ? val[0] : ''; + this.setFormData.slider_image = val.length ? serialize(val).splice(1) : []; + } }, methods: { // 查询详情数据 @@ -253,7 +316,7 @@ } productDetail(this.merId, this.product_id).then(res => { setStorage('editGoodsDetils', res.data); - if(res.data.content_arr.length>0) res.data.content = res.data.content_arr; + if (res.data.content_arr.length > 0) res.data.content = res.data.content_arr; this.$store.commit('setStorage', res.data); let editGoodsDetils = res.data; Object.keys(this.setFormData).forEach(item => { @@ -288,8 +351,8 @@ editGoodsDetils.temp && (this.setFormData.tempName = editGoodsDetils.temp.name); setStorage('canChange', true); hideLoading(); - this.showCommodity = true; - + this.showCommodity = true; + }); }, //获取商户分类 @@ -301,15 +364,15 @@ this.brand = (await categoryBrandlist(this.merId)).data; // 获取平台分类 let { data } = await categoryList(this.merId); - data.forEach((item1)=>{ - item1.children.forEach((item2)=>{ + data.forEach((item1) => { + item1.children.forEach((item2) => { item2.children = null; }) }) this.platformClassificationData = data; }, // 更新商品条码 - updateCode(e){ + updateCode(e) { this.code = e + ''; }, // 选择图片 @@ -450,11 +513,59 @@ this.$refs.tempId.open(); }); }, - + // 创建商品 submitCreatedGoods() { console.log('创建商品'); - console.log('商品数据', this.setFormData); + console.log('是否推荐', this.$refs.commodityRef.addGoodsSecoundData); + console.log('商品详情', this.$refs.commodityRef.goodsDis, this.$refs.commodityRef.store_name); + console.log('价格库存', this.$refs.priceRef.singleSpecification); + let postData = { + ...this.setFormData, + ...this.$refs.commodityRef.addGoodsSecoundData, + content: { + title: this.$refs.commodityRef.goodsDis?.store_name || '', + image: this.$refs.commodityRef.goodsDis?.imageList || [] + }, + video_link: this.$refs.commodityRef.addGoodsSecoundData.video_link, + attrValue: this.$refs.priceRef.singleSpecification + }; + postData.stock = postData.attrValue[0]?.stock||0; + // return console.log('商品数据', postData); + Loading(); + if (this.product_id) { + productUpdate(this.merId, this.product_id, postData) + .then(res => { + hideLoading() + Modal('提交成功', '点击确定,返回商品管理', { + showCancel: false + }).then(() => { + uni.removeStorageSync('singleSpecification') + uni.redirectTo({ + url: '/pages/product/goodsOnSale/index?mer_id=' + this.merId + }) + }) + }) + .catch(rej => { + Toast(rej); + }); + + } else { + productCreate(this.merId, postData) + .then(res => { + hideLoading(); + Modal('提交成功', '点击确定,返回商品管理', { + showCancel: false, + }).then(() => { + uni.redirectTo({ + url: '/pages/product/goodsOnSale/index?mer_id=' + this.merId + }) + }) + }) + .catch(rej => { + Toast(rej); + }); + } }, } };