index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <view class="content">
  3. <u-navbar title="消息" titleStyle="font-weight:620;font-family: PingFang SC" safeAreaInsetTop fixed placeholder leftIcon=" " :autoBack="false">
  4. <view class="u-nav-slot" slot="right">
  5. <text class="rightBtn" @click="setAllRead()">清除未读</text>
  6. </view>
  7. </u-navbar>
  8. <view class="u-demo">
  9. <!-- <msg-pop :isShowMsgPop="isShowMsgPop" @clickMask='clickMask' @clickChat='clickChat' @clickScan='clickScan'></msg-pop> -->
  10. <mescroll-body ref="mescrollRef" @init="mescrollInit" top="0" bottom="20" :down="downOption" :up="upOption" @down="downCallback" @up="upCallback" @emptyclick="emptyClick">
  11. <!-- 列表 -->
  12. <uni-swipe-action>
  13. <uni-swipe-action-item v-for="(item,index) in dataList" :key="index" :class="index == 0?'action-item active':'action-item'" :disabled="true">
  14. <view class="msg-list" @tap='clickListItem(index)' v-if="item.content != '暂无消息'">
  15. <view class="msg-icon">
  16. <image v-if="item.msgType==1" src="@/static/images/message/regular_client_icon_80.png" mode="widthFix"></image>
  17. <image v-else-if="item.msgType==2" src="@/static/images/message/Timingvideo.png" mode="widthFix"></image>
  18. <image v-else-if="item.msgType==3" src="@/static/images/message/budget_icon_80.png" mode="widthFix"></image>
  19. <image v-else src="@/static/images/message/announcement_icon_100.png" mode="widthFix"></image>
  20. <!-- <image v-if="item.msgType==1" src="@/static/images/message/regular_client_icon_80.png" mode="widthFix"></image>
  21. <image v-else-if="item.msgType==3" src="@/static/images/message/budget_icon_80.png" mode="widthFix"></image>
  22. <image v-else src="@/static/images/message/announcement_icon_100.png" mode="widthFix"></image> -->
  23. </view>
  24. <view class="msg-info">
  25. <view class="top u-f-ac u-f-jsb">
  26. <text class="title">{{item.msgTypeName}}</text>
  27. <text class="timer">{{ $isEmpty(item.createTime)?"":$formatDate(item.createTime)}}</text>
  28. </view>
  29. <view class="bottom">
  30. <view class="frist-msg">
  31. {{$isEmpty(item.title)?"暂无内容":item.title}}
  32. </view>
  33. <view class="msg-tag u-f-ajc" v-show="item.total>0">{{item.total}}</view>
  34. </view>
  35. <view class="line"></view>
  36. <!-- <u-line color="#EDEEEF" style="margin-top: 30rpx;"></u-line> -->
  37. </view>
  38. </view>
  39. <template v-slot:right>
  40. <view class="item-right-btn-box">
  41. <view class="btn dele" @click="doRead(index)">
  42. <text class="text">已读</text>
  43. </view>
  44. </view>
  45. </template>
  46. </uni-swipe-action-item>
  47. </uni-swipe-action>
  48. </mescroll-body>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  54. import mescrollBody from "@/uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.vue";
  55. import { getMsg,getMyCrmMsgList,doRead,setAllRead } from "@/api/message.js";
  56. export default {
  57. mixins: [MescrollMixin], // 使用mixin
  58. components: {
  59. mescrollBody,
  60. },
  61. data() {
  62. return {
  63. downOption: { //下拉刷新
  64. auto: true // 不自动加载 (mixin已处理第一个tab触发downCallback)
  65. },
  66. upOption: { //上拉加载
  67. auto: false, // 不自动加载
  68. page: {
  69. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  70. size: 10 // 每页数据的数量
  71. },
  72. noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  73. empty: {
  74. tip: '~ 空空如也 ~' // 提示
  75. // btnText: '去看看'
  76. }
  77. },
  78. dataList: [
  79. // {"content":"明天上午8点电话预约","un_read_count":0,"scene_name":"用户消息","create_time":"2023-01-05 09:48","imgSrc":"regular_client_icon_80.png"},
  80. // {"content":"张三已认领用户弹棉花","un_read_count":0,"scene_name":"系统消息","create_time":"2022-12-28 12:13","imgSrc":"announcement_icon_100.png"},
  81. // {"content":"这周三有一个随访预约","un_read_count":0,"scene_name":"随访消息","create_time":"2022-12-15 15:39","imgSrc":"followUp.png"},
  82. ]
  83. }
  84. },
  85. computed: {
  86. slotRightCurrent() {
  87. return this.slotRight ? 0 : 1;
  88. }
  89. },
  90. onShow() {
  91. },
  92. onLoad() {
  93. let that=this;
  94. uni.$on('refreshMessage', function(index) {
  95. let item=that.dataList[index];
  96. item.isRead=1;
  97. that.dataList.splice(index,1,item);//删除
  98. });
  99. },
  100. onUnload(){
  101. uni.$off('refreshMessage');
  102. },
  103. methods: {
  104. /*下拉刷新的回调 */
  105. downCallback() {
  106. let that=this;
  107. setTimeout(function() {
  108. that.mescroll.resetUpScroll();
  109. }, 500);
  110. },
  111. /*上拉加载的回调*/
  112. upCallback(page) {
  113. getMsg().then(res => {
  114. if(res.code==200){
  115. setTimeout(()=>{
  116. this.mescroll.endByPage(res.counts.length, 1);
  117. if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
  118. this.dataList=this.dataList.concat(res.counts); //追加新数据
  119. },100);
  120. }else{
  121. uni.showToast({title: res.msg,icon:"none"});
  122. this.mescroll.endErr();
  123. }
  124. },
  125. rej => {}
  126. ).catch(()=>{
  127. //联网失败, 结束加载
  128. this.mescroll.endErr();
  129. });
  130. },
  131. //点击空布局按钮的回调
  132. emptyClick(){
  133. this.mescroll.resetUpScroll();
  134. },
  135. //消息item点击
  136. clickListItem(index) {
  137. //this.doRead(index);
  138. if (this.dataList[index].msgType == 1) {
  139. this.$Router.push({
  140. name: 'message-detail',
  141. query: {
  142. itemData: this.dataList[index],
  143. index:index,
  144. }
  145. });
  146. }
  147. },
  148. doRead(index){
  149. let item=this.dataList[index];
  150. //uni.showLoading({title:""});
  151. let that=this;
  152. doRead(item.msgType).then(res => {
  153. if(res.code==200){
  154. uni.showToast({ title: "操作成功" });
  155. item.isRead=1;
  156. that.dataList.splice(index,1,item);//删除
  157. }else{
  158. uni.showToast({title: res.msg,icon:"none"});
  159. }
  160. },
  161. rej => {}
  162. ).catch(()=>{
  163. });
  164. },
  165. setAllRead(){
  166. let that=this;
  167. uni.showModal({
  168. title: '系统提示',
  169. content: '确定清除未读吗',
  170. cancelText:'确定',
  171. confirmText:'取消',
  172. success: function (res) {
  173. if (res.cancel) {
  174. that.setAllReadPost();
  175. } else if (res.confirm) {
  176. console.log('用户点击取消');
  177. }
  178. }
  179. });
  180. },
  181. setAllReadPost(){
  182. uni.showLoading({title:""});
  183. let that=this;
  184. setAllRead().then(res => {
  185. if(res.code==200){
  186. uni.showToast({ title: "操作成功" });
  187. this.mescroll.resetUpScroll();
  188. }else{
  189. uni.showToast({title: res.msg,icon:"none"});
  190. }
  191. },
  192. rej => {}
  193. ).catch(()=>{
  194. uni.showToast({title:"服务器请求超时",icon:"error"});
  195. });
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .u-demo{
  202. background-color: #fff;
  203. }
  204. .msg-list {
  205. // padding-left: 30rpx;
  206. display: flex;
  207. align-items: center;
  208. margin-top: 26rpx;
  209. justify-content: flex-start;
  210. flex: 1;
  211. margin-left: 30rpx;
  212. margin-right: 30rpx;
  213. padding-right: 0;
  214. height: 57px;
  215. .msg-icon {
  216. position: relative;
  217. margin-bottom: 44rpx;
  218. image {
  219. width: 80rpx;
  220. height: 80rpx;
  221. margin-right: 30rpx;
  222. }
  223. }
  224. .msg-tag {
  225. width: 36rpx;
  226. height: 36rpx;
  227. text-align: center;
  228. font-size: 24rpx;
  229. font-family: PingFang SC;
  230. font-weight: bold;
  231. color: #FFFFFF;
  232. background: #FF1D1D;
  233. border-radius: 50%;
  234. margin-top: 10rpx;
  235. // position: absolute;
  236. // right: 18rpx;
  237. // top: 0;
  238. }
  239. .msg-info {
  240. display: flex;
  241. flex-direction: column;
  242. justify-content: space-between;
  243. flex: 1;
  244. //border-bottom: 2rpx solid #EDEEEF;
  245. margin: 0rpx 0rpx 26rpx 0;
  246. .bottom{
  247. display: flex;
  248. flex-direction: row;
  249. margin-bottom: 26rpx;
  250. }
  251. .title {
  252. font-size: 30rpx;
  253. font-family: PingFang SC;
  254. //font-weight: 620;
  255. color: #232323;
  256. }
  257. .timer {
  258. font-size: 24rpx;
  259. font-family: PingFang SC;
  260. font-weight: 500;
  261. color: #999999;
  262. }
  263. .frist-msg {
  264. font-size: 24rpx;
  265. font-family: PingFang SC;
  266. font-weight: 500;
  267. color: #999999;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. white-space: nowrap;
  271. margin-top: 16rpx;
  272. width: calc(100% - 50rpx);
  273. }
  274. .line{
  275. background: #EDEEEF;
  276. // margin-top: 20rpx;
  277. width: 100%;
  278. height: 0.5px;
  279. }
  280. }
  281. }
  282. .action-item{
  283. box-sizing: border-box;
  284. &:last-child .uni-swipe::after{
  285. display: none;
  286. }
  287. &.active .uni-swipe::before{
  288. background: #FF5C03;
  289. border: 4upx solid #FF5C03;
  290. }
  291. .uni-swipe{
  292. overflow: inherit !important;
  293. position: relative;
  294. &::after{
  295. content: "";
  296. width: 4upx;
  297. height: calc(100% + 20upx);
  298. background: #7B7B7B;
  299. opacity: 0.1;
  300. position: absolute;
  301. top: 56upx;
  302. left: 124upx;
  303. z-index: 9;
  304. }
  305. &::before{
  306. content: "";
  307. width: 20upx;
  308. height: 20upx;
  309. background: #FFFFFF;
  310. border: 4upx solid #DDDDDD;
  311. border-radius: 50%;
  312. position: absolute;
  313. top: 46upx;
  314. left: 112upx;
  315. z-index: 99;
  316. }
  317. }
  318. .item-right-btn-box{
  319. display: flex;
  320. align-items: center;
  321. margin-bottom: 20upx;
  322. .btn{
  323. width: 120upx;
  324. text-align: center;
  325. height: 100%;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. .text{
  330. font-size: 30upx;
  331. font-family: PingFang SC;
  332. font-weight: 500;
  333. color: #FFFFFF;
  334. }
  335. &.edit{
  336. background: #FF5C03;
  337. }
  338. &.dele{
  339. background: #EF910C;
  340. border-radius: 0 10upx 10upx 0;
  341. }
  342. }
  343. }
  344. }
  345. .u-nav-slot {
  346. @include flex;
  347. align-items: center;
  348. justify-content: space-between;
  349. border-width: 0.5px;
  350. border-radius: 100px;
  351. border-color: $u-border-color;
  352. padding: 3px 7px;
  353. opacity: 0.8;
  354. .rightBtn{
  355. color: #999;
  356. font-size: 26rpx;
  357. background: #fff;
  358. border-width: 0;
  359. }
  360. }
  361. .header-view {
  362. padding: 0 40rpx;
  363. font-size: 36rpx;
  364. font-weight: bold;
  365. color: #0A0204;
  366. view {
  367. width: calc(670rpx/3);
  368. height: 100rpx;
  369. text-align: center;
  370. line-height: 88rpx;
  371. }
  372. image {
  373. width: 40rpx;
  374. height: 40rpx;
  375. }
  376. view:last-child {
  377. text-align: right;
  378. }
  379. }
  380. </style>