index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <view class="search">
  4. <u-search placeholder="搜索标题" v-model="param.title" bgColor="white" :showAction="false" @search="(current = 0), (param.type = ''), refresh()" @clear="(current = 0), (param.type = ''), (param.title = ''), refresh()"></u-search>
  5. </view>
  6. <view class="tab">
  7. <u-tabs :list="tab" :current="current" keyName="dictLabel" @click="click"></u-tabs>
  8. </view>
  9. <view class="list">
  10. <view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/knowledge/detail?id=' + item.id)">
  11. <view class="title omit">
  12. <text class="icon" v-if="item.top === 1">&#xe61f;</text>
  13. <text>{{ item.title }}</text>
  14. </view>
  15. <view class="desc">
  16. <text>{{ item.type }}</text>
  17. <text>发布于 {{ item.createTime }}</text>
  18. <text class="del" @click.stop="del(item, index)">删除</text>
  19. </view>
  20. </view>
  21. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  22. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  23. </view>
  24. <view class="mfooter">
  25. <button class="btn" @click="go('/pages/knowledge/doctor/add')">
  26. <text class="icon">&#xe8d5;</text>
  27. <text>发布</text>
  28. </button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. tab: [],
  37. current: 0,
  38. list: [],
  39. param: { pageNum: 1, pageSize: 10 },
  40. loadMore: true
  41. };
  42. },
  43. onLoad(e) {
  44. this.getType();
  45. this.getData();
  46. uni.$on('knowledge', (res) => {
  47. this.refresh();
  48. });
  49. },
  50. methods: {
  51. click(e) {
  52. this.current = e.index;
  53. this.param.type = e.dictValue;
  54. this.refresh();
  55. },
  56. getData() {
  57. this.http.request({
  58. url: '/work/knowledge/list',
  59. data: this.param,
  60. loading: 'false',
  61. success: (res) => {
  62. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  63. res.data.rows.forEach((item) => {
  64. item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
  65. this.list.push(item);
  66. });
  67. }
  68. });
  69. },
  70. getType() {
  71. this.http.request({
  72. url: '/app/common/type/knowledge_type',
  73. loading: 'false',
  74. success: (res) => {
  75. this.tab = res.data.data;
  76. this.tab.unshift({ dictLabel: '全部类型', dictValue: '' });
  77. }
  78. });
  79. },
  80. del(item, index) {
  81. uni.showModal({
  82. title: '提示',
  83. content: '确定删除该知识?',
  84. success: (res) => {
  85. if (res.confirm) {
  86. this.http.request({
  87. url: '/work/knowledge/remove/' + item.id,
  88. success: (res) => {
  89. uni.showToast({ title: '删除成功' });
  90. this.list.splice(index, 1);
  91. }
  92. });
  93. }
  94. }
  95. });
  96. },
  97. go(url) {
  98. uni.navigateTo({ url: url });
  99. },
  100. //刷新数据
  101. refresh() {
  102. this.loadMore = true;
  103. this.param.pageNum = 1;
  104. this.list = [];
  105. this.getData();
  106. }
  107. },
  108. //下拉刷新
  109. onPullDownRefresh() {
  110. setTimeout(() => {
  111. this.refresh();
  112. uni.stopPullDownRefresh();
  113. }, 1000);
  114. },
  115. //上拉加载
  116. onReachBottom() {
  117. if (this.loadMore) {
  118. this.param.pageNum++;
  119. this.getData();
  120. }
  121. }
  122. };
  123. </script>
  124. <style lang="scss">
  125. .list {
  126. padding: 10px 12px;
  127. background-color: white;
  128. margin: 10px;
  129. border-radius: 10px;
  130. .item {
  131. border-radius: 5px;
  132. padding: 13px 12px 13px 12px;
  133. margin-bottom: 10px;
  134. overflow: hidden;
  135. border-bottom: 1px solid $line;
  136. &:last-child{
  137. border: 0px;
  138. }
  139. .title {
  140. font-size: 15px;
  141. font-weight: bold;
  142. .icon {
  143. color: orangered;
  144. padding-right: 3px;
  145. }
  146. }
  147. .desc {
  148. font-size: 14px;
  149. padding-top: 10px;
  150. color: $font-c;
  151. text {
  152. padding-right: 30px;
  153. }
  154. .del {
  155. color: red;
  156. float: right;
  157. }
  158. }
  159. }
  160. }
  161. </style>