msg.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 onLoad() {
  96. this.admin = this.$store.getters.userInfo
  97. await this.isLogin()
  98. },
  99. // 触底加载
  100. onReachBottom() {
  101. // 触底的时候请求数据,即为上拉加载更多
  102. var allTotal = this.page * this.pagesize
  103. console.log(allTotal, '----allTotal');
  104. //this.page为加载次数,this.pagesize为每一次加载的数据条数
  105. if (allTotal < this.totalElements) {
  106. //this.totalElements为请求数据的总条数。只要现有条数小于总条数就就执行一下代码
  107. this.allListItem = false;
  108. this.page++;
  109. //加载次数递加
  110. this.status = "loading"
  111. this.$api.my.messageList({ //请求更多数据列表
  112. page: this.page,
  113. }).then(res => {
  114. let ret = [...this.messageList, ...res.data.data]
  115. this.messageList = ret
  116. console.log(ret)
  117. })
  118. } else {
  119. this.allListItem = true;
  120. console.log('已加载全部数据')
  121. this.status = "noMore"
  122. }
  123. },
  124. methods: {
  125. isLogin(){
  126. //获取消息列表
  127. if(this.admin != undefined ){
  128. this.getMessageList()
  129. }else{
  130. this.messageList = ''
  131. }
  132. },
  133. //打开或关闭是触发
  134. change(){
  135. this.isOpenMsg = !this.isOpenMsg
  136. },
  137. //删除消息
  138. deleteImg(id){
  139. this.$api.my.delMessage({
  140. message_id:id
  141. }).then(res=>{
  142. if(res.code == 0 ){
  143. console.log(res.data);
  144. this.getMessageList()
  145. }else{
  146. uni.showToast({
  147. icon:'none',
  148. title:res.msg
  149. })
  150. }
  151. })
  152. },
  153. //跳转消息详情页面
  154. jumpPage(type,id,product_type){
  155. if(type>2){
  156. //实物奖品
  157. if(product_type == 1){
  158. uni.navigateTo({
  159. url:'/pages/my/prize/prize?product_type='+product_type
  160. })
  161. }else if(product_type == 2 ){
  162. //虚拟奖品
  163. uni.navigateTo({
  164. url:'/pages/my/prize/prize?product_type='+product_type
  165. })
  166. }else if(product_type == 3){
  167. //积分奖品
  168. uni.navigateTo({
  169. url:'/pages/my/integral/integralRecord'
  170. })
  171. }
  172. }else{
  173. uni.navigateTo({
  174. url:'/pages/index/active-detail/index?id='+id
  175. })
  176. }
  177. },
  178. // 搜索防抖
  179. searchText:util.debounce(function(){
  180. if(this.search !=''){
  181. this.goSearch()
  182. }else{
  183. this.getMessageList()
  184. }
  185. },500),
  186. //搜索
  187. goSearch(){
  188. uni.showLoading({
  189. title:'加载中'
  190. })
  191. this.$api.my.messageList({
  192. page: 0,
  193. keyword:this.search,
  194. }).then(res=>{
  195. if(res.code==0){
  196. uni.hideLoading()
  197. this.messageList = res.data.data
  198. this.totalElements = res.data.total
  199. this.pagesize = res.data.per_page
  200. }
  201. })
  202. },
  203. //获取消息列表
  204. getMessageList() {
  205. this.$api.my.messageList({
  206. page: 0
  207. }).then(res => {
  208. this.messageList = res.data.data
  209. this.totalElements = res.data.total
  210. this.pagesize = res.data.per_page
  211. console.log(this.messageList, '------>this.messageList');
  212. })
  213. },
  214. },
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. $pageColor:#F9F9F9;
  219. $bgColor:#FFFFFF;
  220. // flex布局居中对齐
  221. @mixin flexlayout {
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. }
  226. .msg {
  227. height: 100%;
  228. background-color: $pageColor;
  229. }
  230. .home-bottom {
  231. background-color: #f9f9f9;
  232. }
  233. .msg-null{
  234. margin-top: 162rpx;
  235. display: flex;
  236. flex-direction: column;
  237. align-items: center;
  238. justify-content: center;
  239. .msg-null-text{
  240. margin-top: 40rpx;
  241. font-size: 28rpx;
  242. color: #333;
  243. }
  244. }
  245. // 搜索
  246. .search {
  247. position: fixed;
  248. z-index: 99;
  249. // top: 0;
  250. // width: 100%;
  251. padding: 0 30rpx;
  252. height: 124rpx;
  253. background-color: $bgColor;
  254. box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.04);
  255. @include flexlayout;
  256. ::v-deep .u-input {
  257. width: 690rpx !important;
  258. height: 68rpx !important;
  259. background: #F1F1F1;
  260. border-radius: 74rpx;
  261. }
  262. ::v-deep .u-input__content__field-wrapper {
  263. padding-left: 36rpx;
  264. }
  265. ::v-deep .u-input__content__field-wrapper__field {
  266. color: #999999 !important;
  267. font-size: 28rpx !important;
  268. }
  269. }
  270. // 消息列表
  271. .msgListBox {
  272. padding: 48rpx 30rpx;
  273. padding-top: 0;
  274. margin-top: 24rpx;
  275. background: #f9f9f9;
  276. box-shadow: 0rpx 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.3);
  277. border-radius: 12rpx;
  278. .childBox {
  279. padding-top: 40rpx;
  280. padding-bottom: 40rpx;
  281. border-bottom: 2rpx solid rgba(240, 240, 240, .7);
  282. &:last-child {
  283. padding-bottom: 0;
  284. border-bottom: none;
  285. }
  286. &:first-child {
  287. padding-top: 48rpx;
  288. }
  289. .childBox-top {
  290. font-weight: bold;
  291. color: #333333;
  292. font-size: 32rpx;
  293. }
  294. .childBox-content {
  295. padding-right: 24rpx;
  296. display: flex;
  297. align-items: center;
  298. justify-content: space-between;
  299. color: #333333;
  300. font-size: 28rpx;
  301. margin: 24rpx 0 12rpx;
  302. }
  303. .childBox-bom {
  304. color: #999999;
  305. font-size: 26rpx;
  306. }
  307. }
  308. }
  309. ::v-deep .uni-swipe_text--center {
  310. padding-bottom: 40rpx;
  311. border-bottom: 2rpx solid rgba(240, 240, 240, 0.7);
  312. &:last-child {
  313. padding-bottom: 0;
  314. border-bottom: none;
  315. }
  316. }
  317. </style>