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) } },