notice.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <!-- 公告管理 -->
  2. <template>
  3. <view class="notice">
  4. <view class="btn-add">
  5. <image
  6. src="../../../static/images/addicon.png"
  7. class="addicon"
  8. @tap="topage('add')"
  9. ></image>
  10. </view>
  11. <view class="notice-content">
  12. <view class="item" v-for="item in noticeList" :key="item.id">
  13. <view class="notice-top">
  14. <view class="title">{{ item.shopName }}</view>
  15. <image mode="aspectFill" :src="item.icon" class="picture"></image>
  16. <view class="detail">
  17. <text class="txt">{{ item.title }}</text>
  18. <text class="time">{{ item.time.substring(0, 10) }}</text>
  19. </view>
  20. </view>
  21. <view class="notice-btns">
  22. <!-- <view class="up btn">置顶</view> -->
  23. <view class="edit btn" @tap="topage(item.id)">编辑</view>
  24. <view class="delete btn" @tap="deleteNotice(item.id)">删除</view>
  25. </view>
  26. </view>
  27. </view>
  28. <uni-load-more :status="more"> </uni-load-more>
  29. </view>
  30. </template>
  31. <script>
  32. import Header from '../../components/header';
  33. export default {
  34. name: 'notice',
  35. components: {
  36. Header,
  37. },
  38. data() {
  39. //这里存放数据
  40. return {
  41. title: '公告管理',
  42. more: 'loading',
  43. params: {
  44. mid: 53,
  45. pageNo: 1,
  46. pageSize: 3,
  47. type: '2',
  48. },
  49. noticeList: [],
  50. };
  51. },
  52. // 下拉刷新
  53. onPullDownRefresh() {
  54. this.more = 'loading'
  55. this.params.pageNo = 1;
  56. this.getNoticeList();
  57. },
  58. // 上拉加载
  59. onReachBottom() {
  60. if (this.more != 'noMore') {
  61. this.params.pageNo ++
  62. this.getNoticeListMoare();
  63. }
  64. console.log(this.more);
  65. },
  66. onShow() {
  67. this.getShopMessage();
  68. this.getNoticeList();
  69. },
  70. //方法集合
  71. methods: {
  72. // 编辑
  73. topage(id) {
  74. this.$mRouter.push({ route: '/pages/index/setting/editnotice?id=' + id });
  75. },
  76. // 商家信息
  77. async getShopMessage() {
  78. await this.$http.get('/getUserInfo').then(async (res) => {
  79. if (res.data) {
  80. this.params.mid = res.data.id;
  81. }
  82. });
  83. },
  84. // 公告列表
  85. async getNoticeList() {
  86. console.log(this.more);
  87. await this.$http.post('/news/list', this.params).then(async (res) => {
  88. if (res.data.list.length > 0) {
  89. console.log(res);
  90. this.noticeList = res.data.list;
  91. if (res.data.nextPage === 0) {
  92. this.more = 'noMore';
  93. }
  94. } else {
  95. this.more = 'noMore';
  96. }
  97. uni.stopPullDownRefresh();
  98. });
  99. },
  100. // 加载更多
  101. async getNoticeListMoare() {
  102. let arr = [];
  103. await this.$http.post('/news/list', this.params).then(async (res) => {
  104. if (res.data.list.length > 0) {
  105. console.log('more');
  106. console.log(res);
  107. arr = res.data.list;
  108. this.noticeList = this.noticeList.concat(arr);
  109. if (res.data.nextPage === 0) {
  110. this.more = 'noMore';
  111. }
  112. } else {
  113. this.more = 'noMore';
  114. return;
  115. }
  116. });
  117. },
  118. // 删除
  119. deleteNotice(id) {
  120. let _self = this;
  121. uni.showModal({
  122. content: '是否删除该条公告?',
  123. success: (confirmRes) => {
  124. if (confirmRes.confirm) {
  125. _self.more = 'loading'
  126. _self.$http.delete('/news/del/' + id).then(async (res) => {
  127. if (res.code === 200 && res.msg === 'OK') {
  128. _self.$mHelper.toast('删除成功');
  129. _self.params.pageNo = 1;
  130. _self.getNoticeList();
  131. }
  132. });
  133. }
  134. },
  135. });
  136. }
  137. },
  138. };
  139. </script>
  140. <style lang='scss' scoped>
  141. .btn-add {
  142. position: fixed;
  143. right: 33upx;
  144. top: 20upx;
  145. z-index: 100;
  146. .addicon {
  147. width: 48upx;
  148. height: 48upx;
  149. }
  150. }
  151. .notice-content {
  152. background-color: #f4f4f4;
  153. padding: 15upx 33upx;
  154. .item {
  155. background-color: #fff;
  156. border-radius: 10upx;
  157. padding: 20upx;
  158. margin-bottom: 25upx;
  159. .notice-top {
  160. .title {
  161. padding: 20upx;
  162. color: #2f2f2f;
  163. font-size: 28upx;
  164. }
  165. .picture {
  166. width: 100%;
  167. height: 350upx;
  168. border-radius: 20upx;
  169. }
  170. .detail {
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: center;
  174. margin-top: 20upx;
  175. .txt {
  176. flex: 1;
  177. font-size: 30upx;
  178. color: $titleColor;
  179. overflow: hidden;
  180. text-overflow: ellipsis;
  181. white-space: nowrap;
  182. }
  183. .time {
  184. width: 143upx;
  185. color: #9ea9a3;
  186. font-size: 26upx;
  187. }
  188. }
  189. }
  190. .notice-btns {
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. margin-top: 20upx;
  195. .btn {
  196. width: 200upx;
  197. height: 70upx;
  198. border: 1px solid #ccc;
  199. border-radius: 10upx;
  200. text-align: center;
  201. line-height: 70upx;
  202. margin-left: 60upx;
  203. &:first-child {
  204. margin-left: 0;
  205. }
  206. }
  207. .edit {
  208. background-color: #fff;
  209. }
  210. .delete {
  211. background-color: #ff6a5e;
  212. color: #fff;
  213. border:none;
  214. }
  215. }
  216. }
  217. }
  218. </style>