This commit is contained in:
yanran200730
2022-11-02 16:05:35 +08:00
parent a1ddb7ab60
commit 83e06be215
5 changed files with 347 additions and 174 deletions

View File

@@ -18,161 +18,188 @@
<div class="phone-wrapper">
<h2>我上传的</h2>
<div class="list">
<div class="item" v-for="(item, index) in 10" :key="index">
<image src="https://cdn.cunwuyun.cn/wxmp/tianfuxing/photo-bg.png" />
<span>待审核</span>
<div class="item" v-for="(item, index) in list" :key="index" @click="preview(item.accessUrl)">
<image :src="item.accessUrl" mode="aspectFill" />
<span :class="'status-' + item.status">{{ mapStatus(item.status) }}</span>
<div class="bottom">
<i>10-15 19:25</i>
<span>积分+5</span>
<i>{{ $dayjs(item.createTime).format('MM-DD HH:mm') }}</i>
<span v-if="item.integral > 0">积分+{{ item.integral }}</span>
</div>
</div>
<AiEmpty v-if="!list.length"></AiEmpty>
</div>
</div>
<div class="btn-wrapper">
<div class="btn" @click="upload" hover-class="text-hover">上传朋友圈截图</div>
<div class="btn" @click="upload" hover-class="text-hover">上传群聊截图</div>
<div class="btn" @click="upload(1)" hover-class="text-hover">上传朋友圈截图</div>
<div class="btn" @click="upload(2)" hover-class="text-hover">上传群聊截图</div>
</div>
<AiLogin ref="login"/>
</div>
</template>
<script>
export default {
name: 'Culture',
appName: '文明倡导',
customNavigation: true,
import { mapState } from 'vuex'
export default {
name: 'PhotoReport',
appName: '随手拍',
customNavigation: true,
data () {
return {
isFixed: false,
statusBarHeight: 20,
list: [],
hideStatus: false,
pageShow: false
}
},
onLoad () {
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
},
methods: {
back () {
uni.navigateBack({
delta: 1
})
},
preview (url) {
let imgs = []
this.list.forEach(item => {
imgs = [...imgs, ...item.list.map(v => v.url)]
})
uni.previewImage({
urls: imgs,
current: url
})
},
upload () {
if (!this.token) {
this.$refs.login.show()
return false
}
this.imgList = []
this.hideStatus = false
uni.chooseImage({
count: this.limit,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
if (res.tempFilePaths.length > 9) {
this.$toast(`图片不能超过9张`)
return false
}
this.$loading('上传中')
res.tempFilePaths.forEach((item, index) => {
if (index === res.tempFilePaths.length - 1) {
this.hideStatus = true
}
this.$nextTick(() => {
this.uploadFile(item, res.tempFilePaths.length)
})
})
},
})
},
uploadFile (img, total) {
uni.uploadFile({
url: this.$instance.defaults.baseURL + '/admin/file/add',
filePath: img,
name: 'file',
header: {
'Content-Type': 'multipart/form-data',
Authorization: uni.getStorageSync('token'),
},
success: (res) => {
const data = JSON.parse(res.data)
if (data.code === 0) {
this.imgList.push(data.data[0].split(';')[0])
} else {
this.$toast(data.msg)
}
},
complete: () => {
this.$nextTick(() => {
if (this.imgList.length === total && this.hideStatus) {
this.$instance.post(`/app/appvillagepicturealbum/addPictures`, {
areaName: uni.getStorageSync('areaName'),
areaId: uni.getStorageSync('areaId'),
type: this.type,
urlList: this.imgList
}).then(res => {
if (res.code == 0) {
this.getList(this.type)
this.getTotalInfo(this.type)
uni.$emit('update')
}
this.$hideLoading()
this.hideStatus = false
})
}
})
}
})
},
getList (type) {
this.$instance.post(`/app/appvillagepicturealbum/queryAlbum?areaId=${uni.getStorageSync('areaId')}&type=${type}`).then(res => {
if (res.code === 0) {
this.list = Object.keys(res.data).map(v => {
return {
name: v,
list: res.data[v]
}
})
this.$nextTick(() => {
this.pageShow = true
})
}
this.$hideLoading()
})
}
},
onPageScroll (params) {
this.isFixed = params.scrollTop > 60
data () {
return {
isFixed: false,
statusBarHeight: 20,
list: [],
hideStatus: false,
pageShow: false,
current: 1,
isMore: false
}
},
computed: {
...mapState(['user', 'token'])
},
onLoad () {
this.$loading()
this.getList()
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
},
methods: {
back () {
uni.navigateBack({
delta: 1
})
},
preview (url) {
let imgs = this.list.map(v => v.accessUrl)
uni.previewImage({
urls: imgs,
current: url
})
},
mapStatus (status) {
return {
'0': '待审核',
'1': '审核通过',
'2': '审核拒绝'
}[status]
},
upload (type) {
this.imgList = []
this.hideStatus = false
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
if (res.tempFilePaths.length > 9) {
this.$toast(`图片不能超过9张`)
return false
}
this.$loading('上传中')
res.tempFilePaths.forEach((item, index) => {
if (index === res.tempFilePaths.length - 1) {
this.hideStatus = true
}
this.$nextTick(() => {
this.uploadFile(item, res.tempFilePaths.length, type)
})
})
},
})
},
uploadFile (img, total, type) {
uni.uploadFile({
url: this.$instance.defaults.baseURL + '/api/file/add',
filePath: img,
name: 'file',
header: {
'Content-Type': 'multipart/form-data',
Authorization: uni.getStorageSync('token'),
},
success: (res) => {
const data = JSON.parse(res.data)
if (data.code === 0) {
this.imgList.push(data.data[0].split(';')[0])
} else {
this.$toast(data.msg)
}
},
complete: () => {
this.$nextTick(() => {
if (this.imgList.length === total && this.hideStatus) {
this.$instance.post(`/appwechatescalation/addOrUpdate`, {
type: type,
openId: this.user.openId,
accessUrl: this.imgList[0]
}).then(res => {
if (res.code == 0) {
this.$toast('上传成功!请等待后台人员审核')
this.isMore = false
this.current = 1
this.getList()
}
this.$hideLoading()
this.hideStatus = false
})
}
})
}
})
},
getList () {
if (this.isMore) return
this.$instance.post(`/appwechatescalation/list`, null, {
params: {
current: this.current,
size: 10,
listType: 1
}
}).then(res => {
if (res.code === 0) {
this.$hideLoading()
if (this.current > 1) {
this.list = [...this.list, ...res.data.records]
} else {
this.list = res.data.records
}
if (res.data.records.length < 10) {
this.isMore = true
return false
}
this.current = this.current + 1
} else {
this.isMore = true
}
}).catch(() => {
this.$hideLoading()
})
}
},
onPageScroll (params) {
this.isFixed = params.scrollTop > 60
},
onReachBottom () {
this.getList()
}
}
</script>
<style lang="scss" socped>
@@ -322,6 +349,14 @@
color: #FF883C;
background: rgba($color: #000000, $alpha: 0.8);
border-radius: 8px;
&.status-1 {
color: #3BBC37;
}
&.status-2 {
color: red;
}
}
.bottom {