From f1f7e8b22d391bf17f99ceb87f598af3f0617e97 Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Fri, 24 Jun 2022 17:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=9B=9E=E6=98=BE=E7=BC=96=E8=BE=91=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/exchangecode/product/add.js | 42 +++++++++++++++------------ src/pages/plan/product/add.js | 27 +++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/pages/exchangecode/product/add.js b/src/pages/exchangecode/product/add.js index f3a9614c..ea61751e 100644 --- a/src/pages/exchangecode/product/add.js +++ b/src/pages/exchangecode/product/add.js @@ -112,11 +112,11 @@ export default class adduserinfo extends React.Component { for (let i = 0; i < pics.length; i++) { let obj = {} let nameArr = pics[i].split('/') - obj.name = nameArr[5] + obj.name = nameArr[5] || nameArr[2] obj.src = pics[i] defaultPic.push(obj) let obj2 = { - name: nameArr[5], + name: nameArr[5] || nameArr[2], url: pics[i] } temp_productpic.push(obj2) @@ -259,14 +259,24 @@ export default class adduserinfo extends React.Component { const obj1 = [] const obj2 = [] - if(picItem.describe_url){ - let id_name = `${new Date().getTime()}`; + if (picItem.describe_url) { + let id_name = new Date().getTime() picItem?.describe_url.map((item) => { - obj1.push({ src: item, id: `${id_name}`, type:"add", name:`${picItem.name}`}) - obj2.push({ url: item, id: `${id_name}`, type:"add", name:`${picItem.name}` }) + obj1.push({ + src: item, + id: id_name, + type: 'add', + name: picItem.name + }) + obj2.push({ + url: item, + id: id_name, + type: 'add', + name: picItem.name + }) }) } - console.log(" picItem =>", picItem); + console.log(' picItem =>', picItem) let quantity = this.state.model.quantity let model2 = { @@ -325,7 +335,7 @@ export default class adduserinfo extends React.Component { onUploadChange1(files, e) { console.log('编辑 ==>files', files) let arr = _.map(files, (o) => { - return o.id + return o.name }) if (mySwiper !== 0) { mySwiper.destroy() @@ -338,13 +348,12 @@ export default class adduserinfo extends React.Component { autoplay: 3000 }) clearTimeout(timer) - debugger timer = setTimeout(() => { if (arr.length > this.state.productpic.length) { //新增 for (let i = 0; i < arr.length; i++) { let index = this.state.productpic.findIndex((o) => { - return o.id == arr[i] + return o.name == arr[i] }) if (index < 0) { let path = '' @@ -388,7 +397,7 @@ export default class adduserinfo extends React.Component { let temp_arr2 = this.state.productpic for (let i = 0; i < temp_arr.length; i++) { let temp = temp_arr[i] - if (arr.indexOf(temp.id) > -1) { + if (arr.indexOf(temp.name) > -1) { temp_arr2.push(temp) } } @@ -401,7 +410,7 @@ export default class adduserinfo extends React.Component { let pic_arr = this.state.productpic for (let i = 0; i < arr.length; i++) { let temp = pic_arr.find((o) => { - return o.id == arr[i] + return o.name == arr[i] }) temp_arr[i] = temp } @@ -409,10 +418,10 @@ export default class adduserinfo extends React.Component { console.log(this.state.model) console.log('temp_arr =>', temp_arr) - let left_temp_arr = temp_arr.map((item) => { + let left_temp_arr = files.map((item) => { return { ...item, - src: item.url + url: item.src } }) let models = this.state.model @@ -631,10 +640,7 @@ export default class adduserinfo extends React.Component { value={this.state.model.show_url} /> - + { obj1.push({ src: item, name: 'xxx.png', - id: new Date().getTime() + id: _id }) obj2.push({ url: item, name: 'xxx.png', - id: new Date().getTime() + id: _id }) }) model2.describe_url = obj1 model2.map_product_name = cur_product.title model2.detail_url = '' - this.setState({ model: model2 }) this.setState({ + model: model2, show_url: picItem ? [{ src: picItem.pic, id: new Date().getTime() }] : [], productpic: obj2 }) @@ -420,7 +421,7 @@ export default class adduserinfo extends React.Component { } // //调整位置 - if (arr.length == this.state.productpic.length) { + if (arr.length === this.state.productpic.length) { let temp_arr = [] let pic_arr = this.state.productpic for (let i = 0; i < arr.length; i++) { @@ -429,24 +430,16 @@ export default class adduserinfo extends React.Component { }) temp_arr[i] = temp } - this.setState({ productpic: temp_arr }) - let left_temp_arr = temp_arr.map((item) => { + let left_temp_arr = files.map((item) => { return { ...item, - src: item.url + url: item.src } }) let models = this.state.model models.describe_url = left_temp_arr - this.setState({ model: models }) + this.setState({ model: models, productpic: temp_arr }) } - - // if(this.mySwiper) - // { - // // this.refs.swiperwrapper - // this.mySwiper.destroy() - - // } }, 500) }