From df2747734921b79a443769393d9cf31341e83f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E6=A3=9A?= <849005670@qq.com> Date: Wed, 8 Dec 2021 11:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/exchangecode/commodity/goodedit.js | 4 +- src/pages/exchangecode/product/add.js | 144 ++++++++++++------- src/pages/plan/key/product/add.js | 6 +- src/pages/plan/product/add.js | 20 ++- 4 files changed, 110 insertions(+), 64 deletions(-) diff --git a/src/pages/exchangecode/commodity/goodedit.js b/src/pages/exchangecode/commodity/goodedit.js index c960a919..7fea27a7 100644 --- a/src/pages/exchangecode/commodity/goodedit.js +++ b/src/pages/exchangecode/commodity/goodedit.js @@ -389,7 +389,7 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange(e)}} onUpload={this.onUpload} @@ -404,7 +404,7 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange1(e)}} onUpload={this.onUpload} diff --git a/src/pages/exchangecode/product/add.js b/src/pages/exchangecode/product/add.js index aeaaada1..f0f5defb 100644 --- a/src/pages/exchangecode/product/add.js +++ b/src/pages/exchangecode/product/add.js @@ -119,6 +119,7 @@ export default class adduserinfo extends React.Component{ onProductChange(e){ this.setState({cur_product:e}) let cur_product = this.state.products.find((item)=>{return item.id == e.key}) + let picItem = window.goods.find((item)=>{return item.id == cur_product.product_category_id}) let model2 = { product_id:cur_product.id, @@ -128,11 +129,15 @@ export default class adduserinfo extends React.Component{ cost_price:cur_product.cost_price, quantity:this.state.model.quantity, product_name:this.state.model.product_name, - show_url:this.state.show_url ? this.state.show_url : "", - describe_url:this.state.describe_url ? this.state.describe_url : "", + show_url:picItem ? picItem.pic : "", + describe_url:picItem ? picItem.pic : "", account_type:cur_product.account_type } + + + + this.setState({model:model2}) } onTypeChange(e){ @@ -148,75 +153,110 @@ export default class adduserinfo extends React.Component{ onUpload = (file, report) => { - return new Promise((resolve, reject) => { - let path = "" - let formdata= new FormData(); - formdata.append("file",file) - formdata.append("path","common_image") - uploadImg(formdata).then((res)=>{ - handelResponse(res,(req,msg)=>{ - path = req.path; + + + // return new Promise((resolve, reject) => { + // let path = "" + // let formdata= new FormData(); + // formdata.append("file",file) + // formdata.append("path","common_image") + // uploadImg(formdata).then((res)=>{ + // handelResponse(res,(req,msg)=>{ + // path = req.path; - },(err)=>{ - reject(); - }) - }); + // },(err)=>{ + // reject(); + // }) + // }); - let count = 0; - const update = () => { - if(path) - { + // let count = 0; + // const update = () => { + // if(path) + // { - resolve( - path - ); + // resolve( + // path + // ); - } - else{ + // } + // else{ - if (count < 100) { - count += 2; - report(count); - setTimeout(update, 500); - console.log("上传中") - } - else{ + // if (count < 100) { + // count += 2; + // report(count); + // setTimeout(update, 500); + // console.log("上传中") + // } + // else{ - reject(); - } - } + // reject(); + // } + // } - }; - setTimeout(update, 500); - }); + // }; + // setTimeout(update, 500); + // }); }; onUploadChange(files){ - - if(files.length > 0 && files[0].status == "success") + console.log(files) + if(files.length > 0 ) { + if(files[0].file.size > 20000) + { + Notify.error(`图片大小不能超过 20KB`); + return; + } + let formdata= new FormData(); + formdata.append("file",files[0].file) + formdata.append("path","common_image") + uploadImg(formdata).then((res)=>{ + handelResponse(res,(req,msg)=>{ + let path = req.path; + let model = this.state.model; + model.show_url = path; + this.setState({model:model}) + },(err)=>{ + + }) + }); + } + else{ let model = this.state.model; - model.show_url = files[0].src; + model.show_url = ""; this.setState({model:model}) } - - - - - }; onUploadChange1(files){ - if(files.length > 0 && files[0].status == "success") + if(files.length > 0 ) { + if(files[0].file.size > 20000) + { + Notify.error(`图片大小不能超过 20KB`); + return; + } + let formdata= new FormData(); + formdata.append("file",files[0].file) + formdata.append("path","common_image") + uploadImg(formdata).then((res)=>{ + handelResponse(res,(req,msg)=>{ + let path = req.path; let model = this.state.model; - model.describe_url = files[0].src; + model.describe_url = path; + this.setState({model:model}) + },(err)=>{ + + }) + }); + } + else{ + let model = this.state.model; + model.describe_url = ""; this.setState({model:model}) } - }; - onUploadError = (type, data) => { if (type === 'overMaxAmount') { Notify.error(`最多可上传 ${data.maxAmount} 张图片`); @@ -325,10 +365,10 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange(e)}} - onUpload={this.onUpload} + fileList={this.state.model.show_url ? [{'src':this.state.model.show_url}] : null} value={this.state.model.show_url} /> @@ -336,10 +376,10 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange1(e)}} - onUpload={this.onUpload} + fileList={this.state.model.describe_url ? [{'src':this.state.model.describe_url}] : null} value={this.state.model.describe_url} /> diff --git a/src/pages/plan/key/product/add.js b/src/pages/plan/key/product/add.js index 9a23f6c1..41346d95 100644 --- a/src/pages/plan/key/product/add.js +++ b/src/pages/plan/key/product/add.js @@ -311,7 +311,7 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange(e)}} onUpload={this.onUpload} @@ -321,8 +321,8 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange1(e)}} onUpload={this.onUpload} diff --git a/src/pages/plan/product/add.js b/src/pages/plan/product/add.js index c26a6a22..a4dbe323 100644 --- a/src/pages/plan/product/add.js +++ b/src/pages/plan/product/add.js @@ -151,9 +151,6 @@ export default class adduserinfo extends React.Component{ // } this.setState({model:model2}) - - console.log(model2) - console.log(this.state.show_url) } onTypeChange(e){ let model2 = this.state.model; @@ -189,7 +186,11 @@ export default class adduserinfo extends React.Component{ console.log(files) if(files.length > 0 ) { - + if(files[0].file.size > 20000) + { + Notify.error(`图片大小不能超过 20KB`); + return; + } let formdata= new FormData(); formdata.append("file",files[0].file) formdata.append("path","common_image") @@ -214,6 +215,11 @@ export default class adduserinfo extends React.Component{ if(files.length > 0 ) { + if(files[0].file.size > 20000) + { + Notify.error(`图片大小不能超过 20KB`); + return; + } let formdata= new FormData(); formdata.append("file",files[0].file) formdata.append("path","common_image") @@ -343,8 +349,8 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange(e)}} @@ -359,7 +365,7 @@ export default class adduserinfo extends React.Component{ {this.onUploadChange1(e)}}