| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 | <script setup>  import {    ref  } from "vue";  import {    onLoad,    onShow,    onUnload,  } from "@dcloudio/uni-app";  import {    getMessageList,    getMessageCreateList,    getMessageNum  } from "@/api/work/message.js";  import {    toast,    showConfirm,    tansParams  } from '@/utils/common'  let isOver = ref(true)  // 切换  let switchActiveArr = ['未读', '已读', '自发'];  let switchActive = ref('未读');  const switchSetActive = function(val) {    defaultCurrent.value = val;    switchActive.value = switchActiveArr[val];    searchInfo.value.pageNo = 1    isOver.value = true    if (switchActive.value === "已读") {      searchInfo.value.read = true      getList();    }    if (switchActive.value === "未读") {      searchInfo.value.read = false      getList();    }    if (switchActive.value === "自发") {      getCreateList();    }  };  // swiper  let defaultCurrent = ref(0);  const chgangeSwiperItem = function(e) {    switchActive.value = switchActiveArr[e.detail.current];  }  // 数据  let unReadList = ref([]);  let readList = ref([]);  let createList = ref([]);  // 获取数据  let searchInfo = ref({    pageNo: 1,    pageSize: 10,    read: false,    beginDate: '',    endDate: '',    userName: '',    content: '',  });  function getList() {    if (searchInfo.value.pageNo == 1) {      readList.value = []      unReadList.value = []    }    console.log(searchInfo.value, '列表请求参数');    if (isOver.value) {      getMessageList(searchInfo.value).then(res => {        if (res.data.pageTotal == 0 || res.data.pageTotal <= searchInfo.value.pageNo) {          isOver.value = false        }        if (searchInfo.value.read) {          readList.value = readList.value.concat(res.data.list);        } else {          unReadList.value = unReadList.value.concat(res.data.list);        }      });    }  };  let searchObj = {};  function getCreateList() {    if (searchInfo.value.pageNo == 1) {      createList.value = []    }    console.log(searchInfo.value, '列表请求参数');    if (isOver.value) {      getMessageCreateList(searchInfo.value).then(res => {        if (res.data.pageTotal == 0 || res.data.pageTotal <= searchInfo.value.pageNo) {          isOver.value = false        }        createList.value = createList.value.concat(res.data.list);      })    }  }  // 跳转页面  function goToPage(url) {    uni.navigateTo({      url    })  }  // 去详情  function goToDetail(type, id, userName, content) {    if (type === "unread") {      console.log(unReadList.value);      let index = unReadList.value.findIndex(item => item.id === id);      unReadList.value.splice(index, 1)    }    uni.navigateTo({      url: `/pages/message/detail/index?type=${type}&id=${id}&userName=${userName}&content=${content}`    })  }  // 改数量  function getMessageCount() {    getMessageNum().then(res => {      if (res.data.count) {        uni.setTabBarBadge({ //显示数字          index: 1, //tabbar下标          text: res.data.count //数字        })      } else {        uni.removeTabBarBadge({ //显示数字          index: 1, //tabbar下标        })      }    })  }  //触底加载  function onScrolltData() {    searchInfo.value.pageNo++    if (switchActive.value === "已读") {      searchInfo.value.read = true      getList();    }    if (switchActive.value === "未读") {      searchInfo.value.read = false      getList();    }    if (switchActive.value === "自发") {      getCreateList();    }    if (!isOver.value) {      toast('无更多消息')    }  }  //跳转搜索  function gotoSearch(e) {    uni.$u.route({      url: 'pages/message/search/index',      params: searchInfo.value    })  }  function search() {    isOver.value = true    searchInfo.value.pageNo = 1    if (switchActive.value === "已读") {      searchInfo.value.read = true      getList();    }    if (switchActive.value === "未读") {      searchInfo.value.read = false      getList();    }    if (switchActive.value === "自发") {      getCreateList();    }  }  onLoad(() => {    uni.$on('messageSearch', resolve => {      searchInfo.value.pageNo = 1      isOver.value = true      searchInfo.value.content = resolve.content      searchInfo.value.beginDate = resolve.beginDate      searchInfo.value.endDate = resolve.endDate      searchInfo.value.userName = resolve.userName      search();      console.log('执行搜索', resolve);    })    search()  })  onShow(() => {    getMessageCount();  })  onUnload(() => {    uni.$off('messageSearch');  })</script><template>  <view class="container" style="padding-top: 0 !important;">    <view class="top-box">      <view class="tabs-layer">        <view class="tabs-search" @click="gotoSearch()">          <image src="@/static/images/messageSearch.svg" mode=""></image>          <text>查询</text>        </view>        <view class="tabs-box">          <view class="switch-item" :class="switchActive === '未读'?'active':''" @click="switchSetActive(0)">未读          </view>          <view class="switch-item" :class="switchActive === '已读'?'active':''" @click="switchSetActive(1)">已读          </view>          <view class="switch-item" :class="switchActive === '自发'?'active':''" @click="switchSetActive(2)">自发          </view>        </view>      </view>    </view>    <view class="content">      <swiper class="swiper" :current="defaultCurrent" @change="chgangeSwiperItem">        <swiper-item>          <scroll-view class="swiper-item-content" scroll-y @scrolltolower="onScrolltData">            <view class="card" v-for="(item,index) in unReadList" :key="index">              <view class="card-status-message no-read">                未读              </view>              <view class="card-massage-top">                <view class="time">                  {{item.createTime}}                </view>                <view class="view-btn" @click="goToDetail('unread',item.id,item.userName,item.content)">                  查看                </view>              </view>              <view class="card-massage-from">                <view class="card-massage-from-item">                  <view class="item-label">                    发送人                  </view>                  <view class="item-text">                    {{item.userName}}                  </view>                </view>                <view class="card-massage-from-item">                  <view class="item-label">                    内   容                  </view>                  <view class="item-text">                    {{item.content}}                  </view>                </view>              </view>            </view>            <view class="item-empty" v-if="unReadList.length === 0">              <empty-show onlyText showText='暂无消息'></empty-show>            </view>          </scroll-view>        </swiper-item>        <swiper-item>          <scroll-view class="swiper-item-content" scroll-y @scrolltolower="onScrolltData">            <view class="card" v-for="(item,index) in readList" :key="index">              <view class="card-status-message over-read">                已读              </view>              <view class="card-massage-top">                <view class="time">                  {{item.createTime}}                </view>                <view class="view-btn" @click="goToDetail('read',item.id,item.userName,item.content)">                  查看                </view>              </view>              <view class="card-massage-from">                <view class="card-massage-from-item">                  <view class="item-label">                    发送人                  </view>                  <view class="item-text">                    {{item.userName}}                  </view>                </view>                <view class="card-massage-from-item">                  <view class="item-label">                    内   容                  </view>                  <view class="item-text">                    {{item.content}}                  </view>                </view>              </view>            </view>            <view class="item-empty" v-if="readList.length === 0">              <empty-show onlyText showText='暂无消息'></empty-show>            </view>          </scroll-view>        </swiper-item>        <swiper-item>          <scroll-view class="swiper-item-content" scroll-y @scrolltolower="onScrolltData">            <view class="card" v-for="(item,index) in createList" :key="index">              <view class="card-status-message no-read" v-if="item.status == '0'">                未读              </view>              <view class="card-status-message over-read" v-if="item.status == '1'">                已读              </view>              <view class="card-massage-top">                <view class="time">                  {{item.createTime}}                </view>                <!-- 								<view class="view-btn" @click="goToDetail('unread',item.id,item.userName,item.content)">									查看								</view> -->              </view>              <view class="card-massage-from">                <view class="card-massage-from-item">                  <view class="item-label">                    接收人                  </view>                  <view class="item-text">                    {{item.userName}}                  </view>                </view>                <view class="card-massage-from-item">                  <view class="item-label">                    内   容                  </view>                  <view class="item-text">                    {{item.content}}                  </view>                </view>              </view>            </view>            <view class="item-empty" v-if="createList.length === 0">              <empty-show onlyText showText='暂无消息'></empty-show>            </view>          </scroll-view>        </swiper-item>      </swiper>    </view>    <view class="send-massage">      <text @click="goToPage('/pages/message/send/index')">发送<br />消息</text>    </view>  </view></template><style lang="scss" scoped>  .item-empty {    width: 100%;    height: calc(100% - 32rpx);  }  .send-massage {    position: relative;    position: fixed;    bottom: calc(var(--window-bottom) + 16rpx);    right: 8rpx;    width: 160rpx;    height: 160rpx;    font-weight: 500;    font-size: 28rpx;    color: #FFFFFF;    line-height: 36rpx;    background-image: url('@/static/massage-send-icon.svg');    text {      position: absolute;      top: 50%;      left: 50%;      transform: translate(-58%, -55%);    }  }  .top-box {    height: calc(var(--status-bar-height) + 88rpx);    display: flex;    justify-content: center;    align-items: flex-end;    background-color: #002F69;  }  .tabs-layer {    padding: 0 2.5% 0 2.5%;    display: flex;    justify-content: center;    align-items: center;    gap: 20rpx;    width: 100%;    background-color: #002F69;    height: 88rpx;    .tabs-search {      display: flex;      justify-content: center;      align-items: center;      gap: 5rpx;      width: 128rpx;      height: 56rpx;      // background: #FFFFFF;      border: 2rpx solid #244B7E;      border-radius: 12rpx;      opacity: 0.9;      font-weight: 500;      font-size: 24rpx;      color: #333333;      image {        width: 40rpx;        height: 40rpx;      }      text {        font-weight: 500;        font-size: 32rpx;        color: #FFFFFF;      }    }    .tabs-box {      flex-grow: 1;      display: flex;      justify-content: center;      align-items: center;      gap: 72rpx;      .switch-item {        font-size: 32rpx;        font-weight: 500;        color: rgba(255, 255, 255, 0.6);      }    }  }  .active {    font-size: 32rpx;    color: #FFFFFF !important;  }  .over-read {    background-color: #C7FDD9;    color: #03872F;  }  .no-read {    background-color: #FFCBC1 !important;    color: #B00909;  }  .content {    width: 100%;    height: calc(100vh - var(--status-bar-height) - 88rpx - var(--window-bottom));    .swiper {      width: 100%;      height: 100%;      .swiper-item-content {        height: 100%;        .line {          width: 100%;          height: 32rpx;        }      }    }  }  .card {    width: 95%;    padding: 18rpx 44rpx !important;    margin: auto;    margin-top: 32rpx;    .card-status-message {      position: absolute;      top: 18rpx;      right: 0;      display: flex;      justify-content: center;      align-items: center;      width: 96rpx;      height: 48rpx;      background: #D3F4FF;      border-radius: 16rpx 0rpx 0rpx 16rpx;    }    .card-massage-top {      display: flex;      justify-content: space-between;      align-items: center;      width: 100%;      padding-right: 80rpx;      .time {        font-size: 24rpx;        font-weight: 300;        color: #444444;      }      .view-btn {        display: flex;        justify-content: center;        align-items: center;        width: 96rpx;        height: 48rpx;        background: #F6F6F6;        border-radius: 16rpx;        font-size: 28rpx;        color: #275797;        font-weight: 500;      }    }    .card-massage-from {      margin-top: 16rpx;      padding-top: 28rpx;      display: flex;      flex-direction: column;      align-items: flex-start;      justify-content: flex-start;      gap: 14rpx;      width: 100%;      border-top: 1px dashed #DDDDDD;      min-height: 150rpx;      .card-massage-from-item {        display: flex;        justify-content: flex-start;        align-items: flex-start;        gap: 20rpx;        .item-label {          width: 100rpx;          font-weight: 500;          font-size: 28rpx;          color: #B5B5B5;          white-space: nowrap;        }        .item-text {          width: calc(100% - 140rpx);          flex-grow: 1;          font-size: 28rpx;          font-weight: 500;          color: #222222;          line-break: anywhere;        }      }    }    .card-item-page {      display: flex;      width: 100%;      padding: 20rpx 26rpx;      box-sizing: border-box;      font-size: 28rpx;      font-weight: 400;      .card-item-key {        color: #939AA5;        min-width: 140rpx;      }      .card-item-value {        display: flex;        justify-content: space-between;        align-items: center;        width: 100%;        color: #343437;        line-height: 46rpx;        line-break: anywhere;      }      .card-item-look {        color: #1763E7;      }      .card-item-read {        width: 62rpx;        height: 32rpx;        line-height: 32rpx;        text-align: center;        background-color: #C7FDD9;        border-radius: 12rpx;        font-size: 24rpx;        color: #03872F;      }      .unread {        background-color: #FFCBC1;        color: #B00909;      }    }  }</style>
 |