修复 商品回显编辑报错问题

This commit is contained in:
wangsongsole 2022-06-24 17:10:24 +08:00
parent 8b19c1e484
commit f1f7e8b22d
2 changed files with 34 additions and 35 deletions

View File

@ -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}
/>
</FormItem>
<FormItem
prop='describe_url'
labelname='商品图2222'
id='describe_url'>
<FormItem prop='describe_url' labelname='商品图' id='describe_url'>
<ImageUpload
className='good-image-upload-demo'
maxSize={2 * 1024 * 1024}

View File

@ -104,11 +104,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)
@ -256,24 +256,25 @@ export default class adduserinfo extends React.Component {
const obj1 = []
const obj2 = []
const _id = new Date().getTime() + '48153461544'
picItem?.describe_url.map((item) => {
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)
}