123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <template>
- <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
- <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
- <view class="list-scroll-view">
- <view class="main">
- <!-- <view class="one">
- <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索">
- </view> -->
- <view class="two">
- <view class="list" v-for="(item,index) in list" :key="index" @tap="toInfo(item)">
- <image class="image"
- :src="item.shop&&item.shop.logo&&item.shop.logo.length>0?item.shop.logo[0].url:''"
- mode="">
- </image>
- <view class="content">
- <view class="name textOver">{{item.shop&&item.shop.name||'暂无'}}</view>
- <view class="news textOver">{{item.last_chat}}</view>
- </view>
- <view class="time">
- <view class="time_1">{{item.last_time}}</view>
- <uni-badge :text="item.not_read" size="small"></uni-badge>
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </mobile-frame>
- </template>
- <script>
- export default {
- data() {
- return {
- frameStyle: {
- useBar: true
- },
- user: {},
- searchInfo: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 10,
- page: 0,
- };
- },
- onLoad: async function() {
- const that = this;
- await that.watchlogin();
- },
- onShow: async function() {
- const that = this;
- that.clearPage();
- if (that.user && that.user._id) that.search();
- },
- onPullDownRefresh: async function() {
- const that = this;
- that.clearPage();
- await that.watchlogin();
- uni.stopPullDownRefresh();
- },
- computed: {
- listenWebsocket() {
- return this.$store.state.websocketData;
- }
- },
- watch: {
- listenWebsocket: function(newstr) {
- if (newstr.type == 'chat') {
- this.clearPage()
- this.search();
- }
- }
- },
- methods: {
- // 监听用户是否登录
- watchlogin() {
- const that = this;
- uni.getStorage({
- key: 'token',
- success: function(res) {
- let user = that.$jwt(res.data);
- if (user) {
- that.$set(that, `user`, user)
- that.search();
- }
- }
- })
- },
- async search() {
- const that = this;
- let config = that.$config;
- let info = {
- skip: that.skip,
- limit: that.limit,
- customer: that.user && that.user._id,
- }
- let res;
- res = await that.$api(`/room`, `GET`, {
- ...info,
- ...that.searchInfo
- }, 'chat');
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- for (let val of list) {
- if (val.last_chat) {
- val.last_time = val.last_chat.time
- if (val.last_chat.msg_type == '1') val.last_chat = `[图片]`
- else if (val.last_chat.msg_type == '2') val.last_chat = `[商品]`
- else if (val.last_chat.msg_type == '3') val.last_chat = `[订单]`
- else val.last_chat = val.last_chat.content
- }
- }
- that.$set(that, `list`, list);
- that.$set(that, `total`, res.total)
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- // 输入框
- toInput(e) {
- const that = this;
- if (that.searchInfo.goods) that.$set(that.searchInfo, `goods`, e.detail.value)
- else that.$set(that, `searchInfo`, {})
- that.clearPage();
- that.search();
- },
- // 详情
- toInfo(e) {
- uni.navigateTo({
- url: `/pagesMessage/message/info?id=${e._id}`
- })
- },
- // 分页
- toPage(e) {
- const that = this;
- let list = that.marketList;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.search();
- uni.hideLoading();
- }
- },
- clearPage() {
- const that = this;
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 10)
- that.$set(that, `page`, 0)
- },
- // 菜单跳转
- toPath(e) {
- let url = `/${e.route}`;
- if (e.type == '0') uni.redirectTo({
- url
- })
- else {
- uni.navigateTo({
- url
- })
- }
- },
- }
- }
- </script>
- <style lang="scss">
- .main {
- display: flex;
- flex-direction: column;
- width: 96vw;
- padding: 2vw;
- background-color: var(--f1Color);
- .one {
- input {
- padding: 2vw;
- background-color: #ffffff;
- font-size: var(--font14Size);
- border-radius: 10px;
- }
- }
- .two {
- margin: 1vw 0 0 0;
- .list {
- display: flex;
- padding: 2vw;
- margin: 1vw 0 0 0;
- background-color: #ffffff;
- border-radius: 10px;
- .image {
- width: 15vw;
- height: 15vw;
- border-radius: 15vw;
- border: 1px solid #C0C0C0;
- }
- .content {
- width: 40vw;
- padding: 2vw;
- .name {
- font-size: 16px;
- padding: 1vw 0;
- }
- .news {
- font-size: 12px;
- color: #C0C0C0;
- }
- }
- .time {
- width: 30vw;
- text-align: right;
- padding: 2vw 0;
- font-size: 12px;
- color: #C0C0C0;
- .time_1 {
- margin: 0 0 1vw 0;
- }
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- </style>
|