123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- <template>
- <view class="board">
- <view class="tab flexS">
- <view @click="choose(0)" :class="tabType == 0 ? 'active' : ''" style="margin-right:30rpx;">精选留言</view>
- <view @click="choose(1)" :class="tabType == 1 ? 'active' : ''">{{ userInfo.type == 1 ? '全部留言' : '个人留言' }}</view>
- </view>
- <view class="board_list" v-for="(item, index) in msgList" :key="item.id">
- <view class="top">
- <view class="flexS">
- <image :src="item.get_user.avatar ? item.get_user.avatar : userInfo.avatar"></image>
- <view>
- <view class="nickname flexS">
- <text>{{ item.get_user.nickname ? item.get_user.nickname : userInfo.nickname | getName }}</text>
- <view v-if="item.is_wonderful == 1" class="best">精选</view>
- <view v-if="item.is_top == 1" class="best">置顶</view>
- </view>
- <view class="time">{{ item.created_at | timeFormat }}</view>
- </view>
- </view>
- <view class="del" @click="userInfo.type == 1 ? setMsg(item.$orig) : delMsg(item.$orig.id)">
- <text v-if="userInfo.type == 1">设置</text>
- <text v-if="userInfo.type == 0">{{ tabType == 1 ? '删除' : '' }}</text>
- </view>
- </view>
- <view class="con">{{ item.content }}</view>
- <view class="reply_btn flexB" v-if="!item.get_message_reply && userInfo.type == 1">
- <input type="text" placeholder="回复一句吧~" v-model="item.replayCon" />
- <view @click="replyMsg(item.id, item.replayCon)">回复</view>
- </view>
- <view class="bottom" v-if="item.get_message_reply">
- <image src="../../static/imgs/logo.png"></image>
- <view>
- <view class="nickname" style="color:#F44545;">大卫博士</view>
- <view>
- <view class="time">{{ item.get_message_reply.created_at | timeFormat }}</view>
- <view class="con">{{ item.get_message_reply.content }}</view>
- </view>
- </view>
- </view>
- </view>
- <view class="no_msg" v-if="noMsg">
- <image src="../../static/no_msg.png"></image>
- <view>目前还没有留言哦~</view>
- <view class="go_msg" @click="goMsg" v-if="userInfo.type == 0">去留言</view>
- </view>
- <view class="msg_btn flexC" v-if="!noMsg && userInfo.type == 0"><view @click="goMsg" class="go_msg">去留言</view></view>
- </view>
- </template>
- <script>
- import { lookMsg, putMsg, replyMsg, manageMsg, deleteMsg, wonderfulMsg, isWonderful, isTop, cancelWonderful, cancelTop } from '../../api/msg.js';
- export default {
- data() {
- return {
- noMsg: false, //没有留言状态显示
- replyCon: '', //回复留言内容
- msgList: '', //留言列表
- userInfo: {},
- tabType: '', // 个人留言,精选留言切换
- timer: null, //toast定时器
- page: 1, //当前页面
- totalPage: '' //总页数
- };
- },
- onLoad(options) {
- if (options.tabType) {
- this.tabType = options.tabType;
- }
- },
- onShow() {
- this.userInfo = uni.getStorageSync('userInfo');
- this.page = 1;
- this.msgState();
- this.goTop();
- },
- filters: {
- timeFormat(times) {
- var timearr = times
- .replace(' ', ':')
- .replace(/\:/g, '-')
- .split('-');
- let time = '';
- if (new Date(times).toDateString() === new Date().toDateString()) {
- time = '今天' + ' ' + timearr[3] + ':' + timearr[4];
- } else {
- time = timearr[0] + '/' + timearr[1] + '/' + timearr[2] + ' ' + timearr[3] + ':' + timearr[4];
- }
- return time;
- },
- getName(name) {
- if (name) {
- return name.length > 10 ? name.slice(0, 10) + '...' : name;
- }
- return '';
- }
- },
- beforeDestroy() {
- clearInterval(this.timer);
- this.timer = null;
- },
- onReachBottom() {
- this.getMore();
- },
- methods: {
- goTop() {
- // 一键回到顶部
- if (uni.pageScrollTo) {
- uni.pageScrollTo({
- scrollTop: 0
- });
- }
- },
- //管理员设置留言
- setMsg(item) {
- let item1 = '';
- let item2 = '';
- if (item.is_wonderful == 1) {
- item1 = '取消精选(对所有人不可见)';
- } else {
- item1 = '设为精选(对所与人可见)';
- }
- if (item.is_top == 1) {
- item2 = '取消置顶';
- } else {
- item2 = '置顶';
- }
- uni.showActionSheet({
- itemList: [item1, item2, '删除'],
- success: res => {
- if (res.tapIndex == 0) {
- let http = '';
- let hint = '';
- if (item1 == '取消精选(对所有人不可见)') {
- http = cancelWonderful;
- hint = '取消精选成功';
- } else {
- http = isWonderful;
- hint = '设为精选成功';
- }
- http({ id: item.id }).then(res => {
- console.log(res);
- if (res.code == 200) {
- uni.showToast({
- title: hint,
- icon: 'none',
- duration: 2000,
- mask: true,
- success: res => {
- this.timer = setTimeout(res => {
- this.tabType = 0;
- this.getMsg();
- }, 2000);
- }
- });
- } else {
- console.log(res);
- uni.showModal({
- content: res.message,
- showCancel: false
- });
- }
- });
- return false;
- }
- if (res.tapIndex == 1) {
- let topHttp = '';
- let hint1 = '';
- if (item2 == '取消置顶') {
- topHttp = cancelTop;
- hint1 = '取消置顶成功';
- } else {
- topHttp = isTop;
- hint1 = '留言置顶成功';
- }
- topHttp({ id: item.id }).then(res => {
- if (res.code == 200) {
- uni.showToast({
- title: hint1,
- icon: 'none'
- });
- } else {
- uni.showModal({
- content: res.message || '留言置顶失败',
- showCancel: false
- });
- }
- });
- return false;
- }
- if (res.tapIndex == 2) {
- this.delMsg(item.id);
- }
- },
- fail: function(res) {
- console.log(res.errMsg);
- }
- });
- },
- //用户删除留言
- delMsg(id) {
- uni.showModal({
- title: '删除留言',
- content: '您确定要删除此条留言吗?',
- success: res => {
- if (res.confirm) {
- deleteMsg({ id }).then(res => {
- if (res.code == 200) {
- uni.showToast({
- title: '删除留言成功',
- icon: 'none',
- duration: 2000,
- mask: true,
- success: res => {
- this.timer = setTimeout(res => {
- uni.hideToast();
- this.msgState();
- }, 2000);
- }
- });
- } else {
- uni.showModal({
- content: res.message || '删除留言失败',
- showCancel: false
- });
- }
- });
- }
- }
- });
- },
- msgState(isMore) {
- if (this.tabType == 0) {
- this.getMsg(isMore);
- return false;
- }
- if (this.tabType == 1 && this.userInfo.type == 1) {
- this.getManagMsg(isMore);
- } else {
- this.getUserMsg(isMore);
- }
- },
- getMsg(isMore) {
- wonderfulMsg({ page: this.page }).then(res => {
- if (res.code == 200) {
- this.totalPage = Math.ceil(res.data.total / 20);
- if (isMore) {
- this.msgList = this.msgList.concat(res.data.list);
- } else {
- if (res.data.list.length == 0) {
- this.msgList = '';
- this.noMsg = true;
- return false;
- }
- this.noMsg = false;
- this.msgList = res.data.list;
- }
- } else {
- uni.showModal({
- content: res.message || '获取留言失败',
- showCancel: false
- });
- }
- });
- },
- //用户看到的留言列表
- getUserMsg(isMore) {
- lookMsg({ page: this.page }).then(res => {
- if (res.code == 200) {
- this.totalPage = Math.ceil(res.data.total / 20);
- if (isMore) {
- this.msgList = this.msgList.concat(res.data.list);
- } else {
- if (res.data.list.length == 0) {
- this.msgList = '';
- this.noMsg = true;
- return false;
- }
- this.noMsg = false;
- this.msgList = res.data.list;
- }
- } else {
- uni.showModal({
- content: res.message || '获取留言失败',
- showCancel: false
- });
- }
- });
- },
- //管理员看到的留言列表
- getManagMsg(isMore) {
- manageMsg({ page: this.page }).then(res => {
- if (res.code == 200) {
- this.noMsg = false;
- this.totalPage = Math.ceil(res.data.total / 20);
- let list = res.data.list;
- if (isMore) {
- list = this.msgList.concat(res.data.list);
- } else {
- if (res.data.list.length == 0) {
- this.msgList = '';
- this.noMsg = true;
- return false;
- }
- this.noMsg = false;
- list = res.data.list;
- }
- list.map(i => {
- this.$set(i, 'inpVal', '');
- });
- this.msgList = list;
- } else {
- uni.showModal({
- content: res.message || '获取留言失败',
- showCancel: false
- });
- }
- });
- },
- //获取更多留言列表
- getMore() {
- if (this.page > this.totalPage) {
- uni.showToast({
- title: '没有更多啦~',
- icon: 'none'
- });
- return false;
- }
- this.page++;
- this.msgState(true);
- },
- /*
- * 精选 和 个人(全部)切换
- * type 0 精选 1 个人(全部)
- */
- choose(cur) {
- this.msgList = [];
- this.tabType = cur;
- this.page = 1;
- let { type } = this.userInfo;
- if (cur == 0) {
- //精选接口
- this.getMsg();
- return false;
- }
- if (cur == 1 && type == 1) {
- this.getManagMsg();
- return false;
- }
- if (cur == 1 && type == 0) {
- this.getUserMsg();
- }
- },
- goMsg() {
- uni.navigateTo({
- url: '../message/message'
- });
- },
- //回复留言
- replyMsg(id, content) {
- console.log(content);
- if (!content) {
- uni.showModal({
- content: '请先输入回复内容',
- showCancel: false
- });
- return false;
- }
- replyMsg({
- id,
- content
- }).then(res => {
- if (res.code == 200) {
- uni.showToast({
- title: '回复留言成功',
- showCancel: false,
- duration: 2000,
- mask: true,
- success: res => {
- this.timer = setTimeout(res => {
- uni.hideToast();
- this.msgState();
- }, 2000);
- }
- });
- this.replyCon = '';
- } else {
- uni.showModal({
- content: res.message || '回复留言失败',
- showCancel: false
- });
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .board {
- width: 100%;
- min-height: 100%;
- position: relative;
- padding-bottom: 150rpx;
- .tab {
- width: 690rpx;
- margin: 30rpx auto;
- view {
- font-size: 28rpx;
- color: #999;
- }
- .active {
- font-size: 32rpx;
- color: #333;
- font-weight: bold;
- &::after {
- content: '';
- display: block;
- margin-top: 5rpx;
- width: 42rpx;
- height: 8rpx;
- background: linear-gradient(90deg, #f97c55 0%, #f44545 100%);
- opacity: 1;
- border-radius: 4rpx;
- }
- }
- }
- .board_list {
- width: 690rpx;
- margin: 30rpx auto 0;
- padding: 30rpx;
- box-sizing: border-box;
- background-color: #fff;
- border-radius: 24rpx;
- .nickname {
- font-size: 28rpx;
- color: #333;
- }
- .time {
- font-size: 24rpx;
- color: #999;
- margin-top: 5rpx;
- }
- .con {
- margin: 20rpx 0;
- font-size: 28rpx;
- color: #333;
- }
- .top {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
- .best {
- width: 60rpx;
- text-align: center;
- height: 32rpx;
- line-height: 32rpx;
- font-size: 20rpx;
- border: 1rpx solid #f44545;
- margin-left: 15rpx;
- color: #f44545;
- border-radius: 4rpx;
- }
- image {
- width: 72rpx;
- height: 72rpx;
- margin-right: 15rpx;
- border-radius: 50%;
- }
- .del {
- font-size: 28rpx;
- color: #999;
- }
- }
- .reply_btn {
- height: 70rpx;
- margin: 30rpx 0;
- input {
- width: 80%;
- height: 100%;
- background: #f8f8f8;
- border-radius: 36rpx;
- padding-left: 25rpx;
- }
- view {
- width: 120rpx;
- text-align: center;
- height: 62rpx;
- line-height: 62rpx;
- background: linear-gradient(141deg, #f97c55 0%, #f44545 100%);
- opacity: 1;
- border-radius: 34rpx;
- color: #fff;
- }
- }
- .bottom {
- display: flex;
- justify-content: flex-start;
- align-items: flex-start;
- image {
- width: 48rpx;
- height: 48rpx;
- flex-shrink: 0;
- margin-right: 15rpx;
- }
- .reply {
- font-size: 28rpx;
- color: #999;
- }
- }
- }
- .no_msg {
- width: 100%;
- text-align: center;
- margin-top: 116rpx;
- image {
- width: 484rpx;
- height: 350rpx;
- }
- view:nth-child(2) {
- font-size: 28rpx;
- color: #333;
- margin: 30rpx 0 80rpx;
- }
- }
- .go_msg {
- width: 460rpx;
- margin: 0 auto;
- text-align: center;
- height: 88rpx;
- line-height: 88rpx;
- background: linear-gradient(93deg, #f97c55 0%, #f44545 100%);
- opacity: 1;
- border-radius: 44rpx;
- color: #fff;
- font-size: 32rpx;
- }
- .msg_btn {
- position: fixed;
- left: 0;
- bottom: 0;
- width: 100%;
- height: 108rpx;
- background-color: #fff;
- z-index: 999;
- }
- }
- </style>
|