<view class="item">
<view class="header-block" v-if="imageList == ''">
<image class="header-img" mode="aspectFill" :src="image"></image>
<view>
<button class="positiion-button" @click="chooseImage">
<u-icon name="photo"></u-icon>上传活动图片
</button>
</view>
</view>
<view class="image-block" v-else>
<view class="item-image" v-for="(item, index) in imageList" :key="index">
<image class="image" mode="aspectFill" :src="item" @click="previewImage(item)"></image>
<u-icon class="close-icon" name="minus-circle-fill" size="44" color="red" @click="deleteImage(index)"></u-icon>
</view>
<view v-if="imageList.length <= 4" class="add-image" @click="chooseImage()">
<image class="add-icon" src="../static/images/note/note-create-add-icon.png"></image>
</view>
</view>
</view>
openList:[],//多图接口参数
imageList: [],//多图展示
deleteImage: function(index) {
console.log(index,'删除哪个的index')
this.imageList.splice(index, 1)
this.openList.splice(index, 1)
},
chooseImage: function() {
uni.chooseImage({
count: 6 - this.imageList.length,
sizeType: 'compressed',
success: res => {
this.imageList = this.imageList.concat(res.tempFilePaths)
let params = {
file:this.imageList
}
uni.showLoading({ title: '动态发布中···', mask: true })
if (this.imageList.length > 0) {
let that = this
let index = 0
let imgList = []
callbackfunc(this.imageList)
function callbackfunc(imageList) {
uploadImageApi(imageList[index]).then(res => {
imgList.push(res.data.imgUrl)
// if (index + 1 < imageList.length) {
index++
callbackfunc(imageList)
that.openList = imgList
// } else {
// Object.assign(params, { imgList: imgList.toString() })
// that.createDynamic(params)
// }
}).catch(err => console.warn(err))
}
}
},
fail: () => {
uni.showToast({ title: '上传失败', icon: 'none' })
}
})
},