From 60dea96dc9112879be00a03f6dcdb33244273b06 Mon Sep 17 00:00:00 2001 From: fanfan Date: Thu, 6 Jun 2024 17:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/goods/Create.vue | 49 +++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/views/goods/Create.vue b/src/views/goods/Create.vue index df3232b..097aee9 100644 --- a/src/views/goods/Create.vue +++ b/src/views/goods/Create.vue @@ -38,7 +38,7 @@ - + @@ -408,7 +408,6 @@ export default { ], // 城市总数 citysCount: null, - goods_images: [] } }, // 初始化数据 @@ -420,29 +419,41 @@ export default { }) }, methods: { + generateRandomDigits(length) { + let result = ''; + for (let i = 0; i < length; i++) { + result += Math.floor(Math.random() * 10); // 生成0-9的随机数字 + } + return result; + }, handInfo() { const { form } = this const goods_no = form.getFieldValue('goods_no') - if(goods_no){ - let param = { - sku: goods_no - } - this.isLoading = true - GoodsApi.getCollector(param).then((result) => { - this.goods_images = result.data.goods_images - let obj = { - goods_name: result.data.name, - content: result.data.content, - goods_price: result.data.proxyPrice, + if (goods_no) { + let param = { + sku: goods_no } - this.form.setFieldsValue(obj) - this.isLoading = false - }) - .catch(() => { + this.isLoading = true + GoodsApi.getCollector(param).then((result) => { + if (result.data.goods_images.length > 0) { + result.data.goods_images.forEach(item => { + item.id = Number(this.generateRandomDigits(7)) + }); + } + this.$refs.childComponent.selectedItems= result.data.goods_images + let obj = { + goods_name: result.data.name, + content: result.data.content, + goods_price: result.data.proxyPrice, + } + this.form.setFieldsValue(obj) this.isLoading = false }) - .finally(() => (this.isLoading = false)) - }else{ + .catch(() => { + this.isLoading = false + }) + .finally(() => (this.isLoading = false)) + } else { this.$message.warning('请输入商品SKU', 1.5) } },