2025-03-19 19:25:16 +08:00

493 lines
14 KiB
Vue

<template>
<view class="main">
<scroll-view
scroll-y
class="scrollContent"
@scrolltolower="handleScrollBottom"
refresher-enabled
:refresher-triggered="triggered"
@refresherrefresh="handleRefresh"
>
<view
class="scrollItem"
v-for="(item, index) in postList"
:key="index"
@click="handleEditPost(item)"
>
<view class="itemTop">
<view class="topLeft">
<view class="profileBox">
<image
class="profile"
src="https://eshangtech.com/wanmeiyizhanImg/home/defaultProfit.svg"
/>
</view>
<view class="otherBox">
<view class="userName">{{ item.AUTHOR_NAME || "-" }}</view>
<view class="timeBox">{{ item.PUBLISH_TIME || "-" }}</view>
</view>
</view>
<view class="rightBox">
<view class="commentBox">
<image
class="commentIcon"
src="https://eshangtech.com/wanmeiyizhanImg/home/commentIcon.svg"
/>
<span class="commentText">
{{ item.POST_COMMENTCOUNT || 0 }}</span
>
</view>
<view class="commentBox">
<image
class="commentIcon"
src="https://eshangtech.com/wanmeiyizhanImg/home/thumbsUp.svg"
/>
<span class="thumbsUp">{{ item.POST_LIKECOUNT || 0 }}</span>
</view>
</view>
</view>
<view class="itemContent"
>{{ item.isShowSmall === 1 ? item.smallText : item.POST_CONTENT || ""
}}<span
v-if="item.isShowSmall > 0"
class="expend"
@click.stop="handleChangeIsShowSmall(item)"
>{{
item.isShowSmall === 1
? "展开"
: item.isShowSmall === 2
? "收起"
: ""
}}</span
></view
>
<view
class="imageList"
v-if="item.ImageList && item.ImageList.length > 0"
>
<view
class="imageItem"
v-for="(subItem, subIndex) in item.ImageList"
:key="subIndex"
>
<image class="image" :src="subItem.ImageUrl" />
</view>
</view>
<view class="optionBox">
<span class="label">{{
item.POST_TAG && tabObj ? `#${tabObj[item.POST_TAG] || ""}` : ""
}}</span>
<view>
<span class="edit" @click.stop="handleEditPost(item)">编辑</span>
<span
class="edit"
style="color: #000; margin-left: 8rpx"
@click.stop="handleDeletePost(item)"
>删除</span
>
</view>
</view>
</view>
<view class="inBottom" v-if="postList && postList.length > 0">
<text class="bottomText">{{
listDetail.isOver ? "我是有底线的" : "下拉加载更多"
}}</text>
</view>
<div v-else style="width: 100%; height: 100%">
<no-data text="暂无帖子" :isShow="true" :type="1"></no-data>
</div>
</scroll-view>
</view>
</template>
<script>
import { mapGetters } from "vuex";
import NoData from "../../components/noData.vue";
export default {
data() {
return {
postList: [], // 发帖列表
tabObj: {}, // 标签的枚举
listDetail: {
pageSize: 10,
pageIndex: 1,
isOver: false,
},
triggered: false, // 下拉状态
};
},
components: {
NoData,
},
onLoad() {
console.log("user", this.user);
this.handleGetTypeList();
this.handleGetMyPost();
},
onShow() {
// this.handleGetMyPost();
},
computed: {
...mapGetters({
user: "user",
}),
},
methods: {
// 下拉刷新
async handleRefresh(e) {
console.log("handleRefresh", e);
this.triggered = true;
this.postList = [];
this.listDetail = {
pageIndex: 1,
pageSize: 10,
isOver: false,
};
await this.handleGetMyPost();
this.triggered = false;
},
// 删除发帖
async handleDeletePost(obj) {
let _this = this;
uni.showModal({
title: "提示",
content: "确认删除?",
success: async function (res) {
if (res.confirm) {
uni.showLoading({
title: "删除中...",
});
console.log("obj", obj);
let req = {
...obj,
POST_STATE: 0,
};
const data = await _this.$api.$post("/Member/SynchroPOST", req);
if (data.Result_Code === 100) {
uni.showToast({
title: data.Result_Desc || "更新成功",
icon: "success",
});
uni.hideLoading();
_this.postList = [];
_this.handleGetMyPost();
} else {
uni.showToast({
title: data.Result_Desc || "请求失败",
icon: "none",
});
uni.hideLoading();
}
}
},
});
},
// 编辑发帖内容
handleEditPost(obj) {
console.log("obj", obj);
uni.navigateTo({ url: `/pages/community/addNewPost?id=${obj.POST_ID}` });
},
// 拿到我的发帖列表
async handleGetMyPost() {
uni.showLoading({
title: "加载中...",
});
const req = {
searchParameter: {
WECHATAPP_APPID: "wx4c497eddcec4a0e7",
POST_STATE: 1,
MEMBERSHIP_ID: this.user.MEMBERSHIP_ID,
},
SortStr: "PUBLISH_TIME desc",
PageIndex: this.listDetail.pageIndex,
PageSize: this.listDetail.pageSize,
};
console.log("handleGetNowPostListREq");
const data = await this.$api.$post("/Member/GetPOSTList", req);
let list = data.Result_Data.List;
if (list && list.length > 0) {
list.forEach((item) => {
if (item.POST_CONTENT.length > 100) {
item.isShowSmall = 1;
item.smallText = item.POST_CONTENT.slice(0, 100);
} else {
item.isShowSmall = 0;
}
});
if (list.length < this.listDetail.pageSize) {
this.listDetail.isOver = true;
}
}
let oldList = [];
if (this.postList && this.postList.length > 0) {
oldList = JSON.parse(JSON.stringify(this.postList));
}
this.postList = oldList.concat(list);
console.log("handleGetNowPostList", this.postList);
uni.hideLoading();
},
// 滚动到底部
handleScrollBottom() {
this.listDetail.pageIndex += 1;
if (!this.listDetail.isOver) {
this.handleGetMyPost();
}
},
// 展开
handleChangeIsShowSmall(obj) {
this.postList.forEach((item) => {
if (obj.POST_ID === item.POST_ID && obj.isShowSmall > 0) {
if (obj.isShowSmall === 1) {
item.isShowSmall = 2;
} else {
item.isShowSmall = 1;
}
}
});
},
// 拿到类型枚举
async handleGetTypeList() {
uni.showLoading({
title: "加载中...",
});
const data = await this.$api.$get(
"/EShangApiMain/FrameWork/GetFieldEnumTree",
{ FieldExplainField: "business_target" }
);
let list = this.$utils.wrapTreeNode(data.Result_Data.List);
console.log("listlistlist", list);
let typeList = [];
let typeObj = {};
// 拿到发帖的枚举
if (list && list.length > 0) {
list.forEach((item) => {
if (item.value === 7000) {
console.log("item", item);
if (item.children && item.children.length > 0) {
item.children.forEach((subItem) => {
typeList.push(subItem);
typeObj[subItem.value] = subItem.label;
});
}
}
});
}
this.tabObj = typeObj;
uni.hideLoading();
},
},
};
</script>
<style lang="less" scoped>
.main {
width: 100vw;
height: 100vh;
box-sizing: border-box;
padding: 16rpx 32rpx;
.scrollContent {
width: 100%;
height: 100%;
box-sizing: border-box;
padding-bottom: 32rpx;
.scrollItem {
width: 100%;
border-bottom: 1px solid #f5f6f7;
box-sizing: border-box;
padding: 16rpx 0;
.itemTop {
display: flex;
align-items: center;
justify-content: space-between;
.topLeft {
width: calc(100% - 190rpx);
display: flex;
align-items: center;
.profileBox {
width: 72rpx;
height: 72rpx;
margin-right: 16rpx;
.profile {
width: 100%;
height: 100%;
}
}
.otherBox {
width: calc(100% - 88rpx);
.userName {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 28rpx;
color: #130f05;
line-height: 40rpx;
text-align: left;
font-style: normal;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.timeBox {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 24rpx;
color: #716f69;
line-height: 36rpx;
text-align: left;
font-style: normal;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
}
}
.rightBox {
width: 180rpx;
display: flex;
align-items: center;
justify-content: space-between;
.commentBox {
display: flex;
align-items: center;
.commentIcon {
width: 32rpx;
height: 32rpx;
margin-right: 4rpx;
}
.commentText {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 24rpx;
color: #716f69;
line-height: 36rpx;
text-align: left;
font-style: normal;
}
.thumbsUp {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 24rpx;
color: #ba922f;
line-height: 36rpx;
text-align: left;
font-style: normal;
}
}
}
}
.itemContent {
width: 100%;
margin-top: 16rpx;
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 28rpx;
color: #130f05;
line-height: 40rpx;
text-align: justify;
font-style: normal;
.expend {
margin-left: 8rpx;
color: #ba922f;
}
}
.imageList {
width: 100%;
margin-top: 24rpx;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
.imageItem {
width: 218rpx;
height: 218rpx;
border-radius: 8rpx;
overflow: hidden;
margin-right: 8rpx;
margin-bottom: 8rpx;
.image {
width: 100%;
height: 100%;
}
}
}
.optionBox {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
.label {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 26rpx;
color: #ba922f;
line-height: 36rpx;
text-align: left;
font-style: normal;
}
.edit {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 26rpx;
color: #ba922f;
line-height: 36rpx;
text-align: left;
font-style: normal;
}
}
}
.inBottom {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
.bottomText {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 26rpx;
color: #d0d0d0;
line-height: 40rpx;
text-align: justify;
font-style: normal;
position: relative;
padding: 6rpx 0;
}
.bottomText::after {
content: "";
width: 30vw;
height: 2rpx;
background: #e0e0e0;
position: absolute;
left: -32vw;
top: 50%;
}
.bottomText::before {
content: "";
width: 30vw;
height: 2rpx;
background: #e0e0e0;
position: absolute;
right: -32vw;
top: 50%;
}
}
}
.scrollContent ::-webkit-scrollbar {
width: 0;
}
}
</style>