123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <template>
- <view class="main">
- <view class="top-tabs" :style="colorStyle">
- <view class="tabs">
- <view class="item" :class="{btborder:type === index}" v-for="(item,index) in tabsList" :key="index"
- @tap="changeTabs(index)">
- {{$t(item.name)}}
- </view>
- </view>
- <view class="read-all" @click="allLook()">
- 全部已读
- </view>
- </view>
- <view v-if="list.length && type ===1" class="list">
- <view v-for="(item, index) in list" :key="index" class="item" @click="goChat(item.to_uid)">
- <view class="image-wrap">
- <image class="image" :src="item.avatar"></image>
- </view>
- <view class="text-wrap">
- <view class="name-wrap">
- <view class="name">{{ $t(item.nickname) }}</view>
- <view>{{ item._update_time }}</view>
- </view>
- <view class="info-wrap">
- <view v-if="item.message_type === 1" class="info" v-html="item.message"></view>
- <view v-if="item.message_type === 2" class="info" v-html="item.message"></view>
- <view v-if="item.message_type === 3" class="info">{{$t(`[图片]`)}}</view>
- <view v-if="item.message_type === 4" class="info">{{$t(`[语音]`)}}</view>
- <view v-if="item.message_type === 5" class="info">{{$t(`[商品]`)}}</view>
- <view v-if="item.message_type === 6" class="info">{{$t(`[订单]`)}}</view>
- <view class="num" v-if="item.mssage_num">{{ item.mssage_num }}</view>
- </view>
- </view>
- </view>
- </view>
- <view class="list" v-if="list.length && type === 0">
- <view v-for="(item, index) in list" :key="index">
- <!-- <tuiDrawer @click="(e)=>bindClick(e,item)" :key="item.id" :actions="!item.look ? actions :actionsIsLook"
- :params="{id:item.id}">
- <template v-slot:content>
- <view class="item" @click="goDetail(item.id)">
- <view class="image-wrap">
- <image v-if="item.type === 1" class="image" src="../static/admin-msg.png"></image>
- <image v-else class="image" src="../static/user-msg.png"></image>
- <view class="no-look" v-if="!item.look"></view>
- </view>
- <view class="text-wrap">
- <view class="name-wrap">
- <view class="name">{{ $t(item.title) || '--' }}</view>
- <view>{{ item.add_time }}</view>
- </view>
- <view class="info-wrap">
- <view class="info" v-html="item.content"></view>
- </view>
- </view>
- </view>
- </template>
- </tuiDrawer> -->
- </view>
- </view>
- <view v-else-if="finished && !list.length" class="empty-wrap">
- <view class="image-wrap">
- <image class="image" :src="imgHost + '/statics/images/noMessage.png'"></image>
- </view>
- <view>{{$t(`亲、暂无消息记录哟!`)}}</view>
- </view>
- <!-- #ifndef MP -->
- <home></home>
- <!-- #endif -->
- </view>
- </template>
- <script>
- import {
- serviceRecord,
- messageSystem,
- msgLookDel
- } from '@/api/user.js';
- import colors from '@/mixins/color.js';
- import home from '@/components/home';
- import {
- HTTP_REQUEST_URL
- } from '@/config/app';
- export default {
- mixins: [colors],
- components: {
- home
- },
- data() {
- return {
- imgHost: HTTP_REQUEST_URL,
- list: [],
- page: 1,
- type: 0,
- limit: 20,
- loading: false,
- finished: false,
- tabsList: [{
- key: 0,
- name: '站内消息'
- }, {
- key: 1,
- name: '客服消息'
- }],
- startData: {
- clientX: 0,
- clientY: 0
- },
- actions: [{
- name: '删除',
- color: '#fff',
- fontsize: 28, //单位rpx
- width: 70, //单位px
- background: '#E6A23C'
- },
- {
- name: '已读',
- color: '#fff',
- fontsize: 28, //单位rpx
- width: 70, //单位px
- background: '#409EFF'
- },
- ],
- actionsIsLook: [{
- name: '删除',
- color: '#fff',
- fontsize: 28, //单位rpx
- width: 70, //单位px
- background: '#E6A23C'
- }, ]
- };
- },
- onShow() {
- this.page = 1
- this.list = []
- this.changeTabs(this.type)
- },
- onReachBottom() {
- if (this.type === 1) {
- this.getList()
- } else {
- this.messageSystem()
- }
- },
- onPullDownRefresh() {
- this.page = 1
- this.finished = false
- this.list = []
- if (this.type === 1) {
- this.getList()
- } else {
- this.messageSystem()
- }
- },
- methods: {
- start(e) {
- this.startData.clientX = e.changedTouches[0].clientX;
- this.startData.clientY = e.changedTouches[0].clientY;
- },
- end(e) {
- const subX = e.changedTouches[0].clientX - this.startData.clientX;
- const subY = e.changedTouches[0].clientY - this.startData.clientY;
- if (subY > 50 || subY < -50) {
- console.log('上下滑')
- } else {
- if (subX > 50) {
- console.log('右滑')
- if (this.type == 1) {
- this.type = 0
- this.changeTabs(this.type)
- }
- } else if (subX < -50) {
- if (this.type == 0) {
- this.type = 1
- this.changeTabs(this.type)
- }
- console.log('左滑')
- } else {
- console.log('无效')
- }
- }
- },
- // 滑动点击操作
- bindClick(e, item) {
- if (e.index == 0) {
- msgLookDel({
- id: item.id,
- key: 'is_del',
- value: 1
- }).then(res => {
- let i = this.list.findIndex(e=>{
- return e.id === item.id
- })
- this.list.splice(i,1)
- }).catch(err => {
- uni.showToast({
- title: err.msg,
- icon: 'none'
- })
- })
- } else {
- // 已读
- msgLookDel({
- id: item.id,
- key: 'look',
- value: 1
- }).then(res => {
- item.look = 1
- }).catch(err => {
- uni.showToast({
- title: err.msg,
- icon: 'none'
- })
- })
- }
- },
- allLook() {
- msgLookDel({
- id: 0,
- key: 'look',
- value: 1,
- all: 1
- }).then(res => {
- this.page = 1
- this.limit = 20
- this.list = []
- this.finished = false
- if (this.type === 1) {
- this.getList()
- } else {
- this.messageSystem()
- }
- }).catch(err => {
- uni.showToast({
- title: err.msg,
- icon: 'none'
- })
- })
- },
- changeTabs(index) {
- this.type = index
- this.page = 1
- this.limit = 20
- this.list = []
- this.finished = false
- if (index === 1) {
- this.getList()
- } else {
- this.messageSystem()
- }
- },
- // 站内信
- messageSystem() {
- if (this.loading || this.finished) {
- return;
- }
- this.loading = true;
- uni.showLoading({
- title: this.$t(`加载中`)
- });
- messageSystem({
- page: this.page,
- limit: this.limit
- })
- .then(res => {
- let data = res.data;
- uni.hideLoading();
- this.loading = false;
- this.list = this.list.concat(data.list);
- this.finished = data.list.length < this.limit;
- this.page += 1;
- uni.stopPullDownRefresh();
- })
- .catch(err => {
- uni.showToast({
- title: err.msg,
- icon: 'none'
- })
- })
- },
- // 客服list
- getList() {
- if (this.loading || this.finished) {
- return;
- }
- this.loading = true;
- uni.showLoading({
- title: '加载中'
- });
- serviceRecord({
- page: this.page,
- limit: this.limit
- })
- .then(res => {
- uni.stopPullDownRefresh();
- let data = res.data;
- uni.hideLoading();
- this.loading = false;
- data.forEach(item => {
- if (item.message_type === 1) {
- item.message = this.replace_em(item.message);
- }
- if (item.message_type === 2) {
- item.message = this.replace_em(item.message);
- }
- });
- this.list = this.list.concat(data);
- this.finished = data.length < this.limit;
- this.page += 1;
- })
- .catch(err => {
- uni.showToast({
- title: err.msg,
- icon: 'none'
- })
- })
- },
- replace_em(str) {
- str = str.replace(/\[em-([a-z_]*)\]/g, "<span class='em em-$1'/></span>");
- return str;
- },
- goChat(id) {
- uni.navigateTo({
- url: '/pages/extension/customer_list/chat?to_uid=' + id + '&type=1'
- })
- },
- goDetail(id) {
- uni.navigateTo({
- url: '/pages/users/message_center/messageDetail?id=' + id,
- })
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- .list {
- // background-color: #fff;
- overflow: hidden;
- padding-top: 100rpx;
- .item {
- background-color: #fff;
- display: flex;
- align-items: center;
- // height: 130rpx;
- padding: 30rpx 30rpx;
- margin: 10rpx 20rpx;
- border-radius: 12rpx;
- box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
- -webkit-box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
- -moz-box-shadow: 0px 0px 1px 0px rgba(235, 214, 214, 0.75);
- ~.item {
- border-top: 1rpx solid #f5f5f5;
- }
- .image {
- border-radius: 50%;
- }
- }
- .image-wrap {
- width: 88rpx;
- height: 88rpx;
- border-radius: 50%;
- position: relative;
- .no-look {
- position: absolute;
- width: 18rpx;
- height: 18rpx;
- border-radius: 50%;
- background-color: #1ABB1D;
- top: 0rpx;
- right: 0rpx;
- z-index: 999;
- }
- }
- .image {
- display: block;
- width: 100%;
- height: 100%;
- }
- .text-wrap {
- flex: 1;
- min-width: 0;
- margin-left: 20rpx;
- }
- .name-wrap {
- display: flex;
- align-items: center;
- font-size: 20rpx;
- color: #ccc;
- }
- .name {
- flex: 1;
- min-width: 0;
- margin-right: 20rpx;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- font-size: 28rpx;
- color: #333;
- }
- .info-wrap {
- display: flex;
- align-items: center;
- margin-top: 18rpx;
- }
- .info {
- flex: 1;
- min-width: 0;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- font-size: 24rpx;
- color: #999;
- }
- .num {
- min-width: 32rpx;
- height: 32rpx;
- border-radius: 16rpx;
- margin-left: 20rpx;
- background-color: #e93323;
- font-size: 20rpx;
- line-height: 32rpx;
- text-align: center;
- color: #fff;
- }
- }
- .empty-wrap {
- font-size: 26rpx;
- text-align: center;
- color: #999;
- .image-wrap {
- width: 414rpx;
- height: 436rpx;
- padding-top: 100rpx;
- margin: 0rpx auto 0;
- }
- .image {
- display: block;
- width: 100%;
- height: 100%;
- }
- }
- .main {
- position: relative;
- min-height: 100vh;
- }
- .top-tabs {
- position: fixed;
- width: 100%;
- display: flex;
- align-items: center;
- background-color: #fff;
- font-size: 28rpx;
- border-radius: 8rpx;
- padding: 20rpx 0;
- margin-bottom: 10rpx;
- z-index: 1000;
- transition: all 0.3s;
- justify-content: space-between;
- .read-all {
- margin-right: 24rpx;
- font-size: 24rpx;
- }
- }
- .tabs {
- display: flex;
- }
- .item {
- display: flex;
- align-items: center;
- padding: 4rpx 15rpx;
- margin: 0 20rpx;
- animation: Gradient 0.3s;
- border-radius: 30rpx;
- transition: all 0.4s;
- }
- .btborder {
- color: #fff;
- background-color: var(--view-theme);
- border-radius: 30rpx;
- }
- @-webkit-keyframes Gradient {
- 0% {
- background-color: pink;
- }
- 50% {
- background-position: 100% 50%
- }
- 100% {
- background-position: 0% 50%
- }
- }
- @-moz-keyframes Gradient {
- 0% {
- background-position: 0% 50%
- }
- 50% {
- background-position: 100% 50%
- }
- 100% {
- background-position: 0% 50%
- }
- }
- @keyframes Gradient {
- 0% {
- background-position: 0% 50%
- }
- 50% {
- background-position: 100% 50%
- }
- 100% {
- background-position: 0% 50%
- }
- }
- </style>
|