msg.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view class="msg">
  3. <MyNav title="消息" bgColor="" :backIcon="false"></MyNav>
  4. <!-- 自定义导航栏 -->
  5. <!-- <u-navbar title='消息' fixed safeAreaInsetTop :placeholder='true' :bgColor="bgColor" >
  6. </u-navbar> -->
  7. <!-- 搜索框 -->
  8. <view class="search">
  9. <u-input placeholderStyle='color:#999' placeholder="搜索" border='none' v-model="search" @input="searchText">
  10. <template slot="suffix" style='margin-right:40rpx;'>
  11. <u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
  12. height="32rpx"></u-image>
  13. </template>
  14. </u-input>
  15. </view>
  16. <view style="width: 100%;height: 124rpx;"></view>
  17. <view class="msg-null" v-if="messageList.length == 0">
  18. <image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
  19. <view class="msg-null-text">
  20. <text>暂无数据</text>
  21. </view>
  22. </view>
  23. <!-- 消息列表 -->
  24. <view class="msgListBox" v-if="messageList.length > 0">
  25. <uni-swipe-action>
  26. <uni-swipe-action-item :right-options="options" v-for="(item,index) in messageList" :key="index" @change="change()">
  27. <template v-slot:right>
  28. <view style="display: flex;align-items: center;justify-content: center;" @click="deleteImg(item.id)">
  29. <image src="/static/icon/delete.png" style="width: 36rpx; height: 40rpx; margin-right: 20rpx; "></image>
  30. <text class="slot-button-text" style="color: red;">删除</text>
  31. </view>
  32. </template>
  33. <view class="childBox" @click="jumpPage(item.type,item.relation_id,item.product_type)">
  34. <view class="childBox-top">{{item.title}}</view>
  35. <view class="childBox-content">
  36. <text>{{item.content}}</text>
  37. <image v-if="!isOpenMsg" style="width: 12rpx;height: 20rpx;" src="/static/icon/right.png"></image>
  38. </view>
  39. <view class="childBox-bom">{{item.created_at}}</view>
  40. </view>
  41. </uni-swipe-action-item>
  42. </uni-swipe-action>
  43. </view>
  44. <!-- 触底 -->
  45. <view class="home-bottom" style="padding-bottom: 20rpx;" v-if="messageList.length > 0">
  46. <uni-load-more :status="status" color="#CCCCCC" :content-text="contentText" />
  47. </view>
  48. <!-- 底部导航栏 -->
  49. <view style="height: 140rpx; width: 100%; background-color: #f9f9f9; "></view>
  50. <tab-bar checked="msg"></tab-bar>
  51. </view>
  52. </template>
  53. <script>
  54. import util from '@/utils/util.js'
  55. import TabBar from '../../components/TabBar/tabbar.vue'
  56. import MyNav from "@/components/my-nav/my-nav.vue"
  57. export default {
  58. components: {
  59. TabBar,
  60. MyNav
  61. },
  62. data() {
  63. return {
  64. //用户是否登录
  65. admin:'',
  66. //是否展示信息图标
  67. isOpenMsg:false,
  68. //自定义导航栏
  69. bgColor: '#fff',
  70. //搜索文字
  71. search:'',
  72. //删除按钮
  73. options: [{
  74. text: '删除',
  75. style: {
  76. backgroundColor: '#dd524d'
  77. }
  78. }],
  79. contentText: {
  80. contentdown: '查看更多',
  81. contentrefresh: '加载中',
  82. contentnomore: '—— 已经到底啦 ——'
  83. },
  84. //消息列表
  85. messageList: [],
  86. // 分页
  87. page: 1,
  88. pagesize: 15,
  89. totalElements: '',
  90. allListItem: '',
  91. // 组件uni-load-more
  92. status: 'noMore',
  93. };
  94. },
  95. async onShow() {
  96. this.admin = this.$store.getters.userInfo
  97. await this.isLogin()
  98. },
  99. async onLoad() {
  100. this.admin = this.$store.getters.userInfo
  101. await this.isLogin()
  102. },
  103. // 触底加载
  104. onReachBottom() {
  105. // 触底的时候请求数据,即为上拉加载更多
  106. var allTotal = this.page * this.pagesize
  107. console.log(allTotal, '----allTotal');
  108. //this.page为加载次数,this.pagesize为每一次加载的数据条数
  109. if (allTotal < this.totalElements) {
  110. //this.totalElements为请求数据的总条数。只要现有条数小于总条数就就执行一下代码
  111. this.allListItem = false;
  112. this.page++;
  113. //加载次数递加
  114. this.status = "loading"
  115. this.$api.my.messageList({ //请求更多数据列表
  116. page: this.page,
  117. }).then(res => {
  118. let ret = [...this.messageList, ...res.data.data]
  119. this.messageList = ret
  120. console.log(ret)
  121. })
  122. } else {
  123. this.allListItem = true;
  124. console.log('已加载全部数据')
  125. this.status = "noMore"
  126. }
  127. },
  128. methods: {
  129. isLogin(){
  130. //获取消息列表
  131. if(this.admin != undefined ){
  132. this.getMessageList()
  133. }else{
  134. this.messageList = ''
  135. }
  136. },
  137. //打开或关闭是触发
  138. change(){
  139. this.isOpenMsg = !this.isOpenMsg
  140. },
  141. //删除消息
  142. deleteImg(id){
  143. this.$api.my.delMessage({
  144. message_id:id
  145. }).then(res=>{
  146. if(res.code == 0 ){
  147. console.log(res.data);
  148. this.getMessageList()
  149. }else{
  150. uni.showToast({
  151. icon:'none',
  152. title:res.msg
  153. })
  154. }
  155. })
  156. },
  157. //跳转消息详情页面
  158. jumpPage(type,id,product_type){
  159. if(type>2){
  160. //实物奖品
  161. if(product_type == 1){
  162. uni.navigateTo({
  163. url:'/pages/my/prize/prize?product_type='+product_type
  164. })
  165. }else if(product_type == 2 ){
  166. //虚拟奖品
  167. uni.navigateTo({
  168. url:'/pages/my/prize/prize?product_type='+product_type
  169. })
  170. }else if(product_type == 3){
  171. //积分奖品
  172. uni.navigateTo({
  173. url:'/pages/my/integral/integralRecord'
  174. })
  175. }
  176. }else{
  177. uni.navigateTo({
  178. url:'/pages/index/active-detail/index?id='+id
  179. })
  180. }
  181. },
  182. // 搜索防抖
  183. searchText:util.debounce(function(){
  184. if(this.search !=''){
  185. this.goSearch()
  186. }else{
  187. this.getMessageList()
  188. }
  189. },500),
  190. //搜索
  191. goSearch(){
  192. uni.showLoading({
  193. title:'加载中'
  194. })
  195. this.$api.my.messageList({
  196. page: 0,
  197. keyword:this.search,
  198. }).then(res=>{
  199. if(res.code==0){
  200. uni.hideLoading()
  201. this.messageList = res.data.data
  202. this.totalElements = res.data.total
  203. this.pagesize = res.data.per_page
  204. }
  205. })
  206. },
  207. //获取消息列表
  208. getMessageList() {
  209. this.$api.my.messageList({
  210. page: 0
  211. }).then(res => {
  212. this.messageList = res.data.data
  213. this.totalElements = res.data.total
  214. this.pagesize = res.data.per_page
  215. console.log(this.messageList, '------>this.messageList');
  216. })
  217. },
  218. },
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. $pageColor:#F9F9F9;
  223. $bgColor:#FFFFFF;
  224. // flex布局居中对齐
  225. @mixin flexlayout {
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. }
  230. .msg {
  231. height: 100%;
  232. background-color: $pageColor;
  233. }
  234. .home-bottom {
  235. background-color: #f9f9f9;
  236. }
  237. .msg-null{
  238. margin-top: 162rpx;
  239. display: flex;
  240. flex-direction: column;
  241. align-items: center;
  242. justify-content: center;
  243. .msg-null-text{
  244. margin-top: 40rpx;
  245. font-size: 28rpx;
  246. color: #333;
  247. }
  248. }
  249. // 搜索
  250. .search {
  251. position: fixed;
  252. z-index: 99;
  253. // top: 0;
  254. // width: 100%;
  255. padding: 0 30rpx;
  256. height: 124rpx;
  257. background-color: $bgColor;
  258. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
  259. @include flexlayout;
  260. ::v-deep .u-input {
  261. width: 690rpx !important;
  262. height: 68rpx !important;
  263. background: #F1F1F1;
  264. border-radius: 74rpx;
  265. }
  266. ::v-deep .u-input__content__field-wrapper {
  267. padding-left: 36rpx;
  268. }
  269. ::v-deep .u-input__content__field-wrapper__field {
  270. color: #999999 !important;
  271. font-size: 28rpx !important;
  272. }
  273. }
  274. // 消息列表
  275. .msgListBox {
  276. padding: 48rpx 30rpx 0;
  277. padding-top: 0;
  278. margin-top: 24rpx;
  279. background: #fff;
  280. box-shadow: 0rpx 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.3);
  281. border-radius: 12rpx;
  282. .childBox {
  283. padding-top: 40rpx;
  284. padding-bottom: 40rpx;
  285. border-bottom: 2rpx solid rgba(240, 240, 240, .7);
  286. &:last-child {
  287. padding-bottom: 0;
  288. border-bottom: none;
  289. }
  290. &:first-child {
  291. padding-top: 48rpx;
  292. }
  293. .childBox-top {
  294. font-weight: bold;
  295. color: #333333;
  296. font-size: 32rpx;
  297. }
  298. .childBox-content {
  299. padding-right: 24rpx;
  300. display: flex;
  301. align-items: center;
  302. justify-content: space-between;
  303. color: #333333;
  304. font-size: 28rpx;
  305. margin: 24rpx 0 12rpx;
  306. }
  307. .childBox-bom {
  308. color: #999999;
  309. font-size: 26rpx;
  310. }
  311. }
  312. }
  313. ::v-deep .uni-swipe_text--center {
  314. padding-bottom: 40rpx;
  315. border-bottom: 2rpx solid rgba(240, 240, 240, 0.7);
  316. }
  317. </style>