myarticle.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="我发布的文章"></fa-navbar>
  5. <!-- 分类 -->
  6. <view class="u-border-top" v-if="isTab">
  7. <!-- #ifdef MP-BAIDU -->
  8. <fa-u-tabs :list="tabList" :active-color="theme.bgColor" :bar-width="tabwidth" name="name" :is-scroll="true" :current="current" @change="change"></fa-u-tabs>
  9. <!-- #endif -->
  10. <!-- #ifndef MP-BAIDU -->
  11. <u-tabs :list="tabList" :active-color="theme.bgColor" :bar-width="tabwidth" name="name" :is-scroll="true" :current="current" @change="change"></u-tabs>
  12. <!-- #endif -->
  13. </view>
  14. <!-- 文章列表 -->
  15. <u-swipe-action v-for="(res, index) in list" :show="res.show" :index="index" :key="res.id" @click="click" @open="open(index)" :options="options">
  16. <view class="article" @click="goDetail(res)">
  17. <view class="left"><image :src="res.image" mode="aspectFill"></image></view>
  18. <view class="right">
  19. <view class="content u-line-2">
  20. <view class="u-m-r-10 flag" v-if="res.status == 'hidden'"><u-tag text="审核中" type="error" size="mini" /></view>
  21. {{ res.title }}
  22. </view>
  23. <view class="u-flex u-flex-wrap">
  24. <view class="u-m-r-10" v-for="(item, ik) in res.taglist" :key="ik">
  25. <u-tag
  26. :text="item.name"
  27. shape="circle"
  28. :bg-color="lightColor"
  29. :border-color="faBorderColor"
  30. :color="theme.bgColor"
  31. type="info"
  32. size="mini"
  33. mode="light"
  34. />
  35. </view>
  36. </view>
  37. <view class="u-p-t-10 u-tips-color">发布时间:{{ res.publishtime | date('yyyy-mm-dd hh:MM:ss') }}</view>
  38. </view>
  39. </view>
  40. </u-swipe-action>
  41. <!-- 加载更多 -->
  42. <view class="u-p-t-30 u-p-b-30" v-if="list.length"><u-loadmore bg-color="#ffffff" :status="has_more ? status : 'nomore'" /></view>
  43. <!-- 空数据 -->
  44. <view class="fa-empty" v-if="!list.length"><u-empty></u-empty></view>
  45. <!-- 回到顶部 -->
  46. <u-back-top :scroll-top="scrollTop" :icon-style="{ color: theme.bgColor }" :custom-style="{ backgroundColor: lightColor }"></u-back-top>
  47. <!-- 底部导航 -->
  48. <fa-tabbar></fa-tabbar>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. onLoad() {
  54. this.getmyArchives();
  55. },
  56. data() {
  57. return {
  58. isTab: false,
  59. tabwidth: 40,
  60. tabList: [],
  61. current: 0,
  62. scrollTop: 0,
  63. list: [],
  64. status: 'loadmore',
  65. has_more: false,
  66. page: 1,
  67. channel_id: 0,
  68. is_update: false,
  69. options: []
  70. };
  71. },
  72. methods: {
  73. change(index) {
  74. //重设Bar宽度
  75. this.tabwidth = this.$util.strlen(this.tabList[index].name) * 30;
  76. this.current = index;
  77. this.channel_id = this.tabList[index].id;
  78. this.page = 1;
  79. this.is_update = true;
  80. this.getmyArchives();
  81. },
  82. getmyArchives() {
  83. this.$api.myArchives({ page: this.page, channel_id: this.channel_id }).then(res => {
  84. this.status = 'loadmore';
  85. if (!res.code) {
  86. this.$u.toast(res.msg);
  87. return;
  88. }
  89. if (this.is_update) {
  90. this.list = [];
  91. this.is_update = false;
  92. }
  93. if (this.tabList.length <= res.data.channelList.length) {
  94. this.tabList = [{ name: '全部', id: 0 }, ...res.data.channelList];
  95. this.options = [
  96. {
  97. text: '编辑',
  98. style: {
  99. backgroundColor: this.theme.bgColor
  100. }
  101. },
  102. {
  103. text: '删除',
  104. style: {
  105. backgroundColor: '#dd524d'
  106. }
  107. }
  108. ];
  109. }
  110. let archivesList = res.data.archivesList;
  111. archivesList.data.map(function(item) {
  112. item.show = false;
  113. });
  114. this.list = this.list.concat(archivesList.data);
  115. this.has_more = archivesList.last_page > archivesList.current_page;
  116. if (!this.isTab) {
  117. this.isTab = true;
  118. }
  119. });
  120. },
  121. click(index, index1) {
  122. if (index1 == 1) {
  123. this.$api.deleteArchives({id:this.list[index].id}).then(res=>{
  124. this.$u.toast(res.msg);
  125. if(res.code){
  126. this.list.splice(index, 1);
  127. }
  128. })
  129. } else {
  130. this.$Router.push({
  131. path: '/pages/publish/channel',
  132. query: { archives_id: this.list[index].id }
  133. });
  134. }
  135. },
  136. open(index) {
  137. this.list[index].show = true;
  138. this.list.map((val, idx) => {
  139. if (index != idx) this.list[idx].show = false;
  140. });
  141. },
  142. goDetail(item) {
  143. if (item.model_id == 2) {
  144. this.$Router.push({
  145. path: '/pages/product/detail',
  146. query: { id: item.id }
  147. });
  148. } else {
  149. this.$Router.push({
  150. path: '/pages/article/detail',
  151. query: { id: item.id }
  152. });
  153. }
  154. }
  155. },
  156. onPageScroll(e) {
  157. this.scrollTop = e.scrollTop;
  158. },
  159. onReachBottom() {
  160. if (this.has_more) {
  161. this.status = 'loading';
  162. this.page++;
  163. this.getmyArchives();
  164. }
  165. }
  166. };
  167. </script>
  168. <style lang="scss">
  169. page {
  170. background-color: #ffffff;
  171. }
  172. </style>
  173. <style lang="scss" scoped>
  174. .article {
  175. display: flex;
  176. padding: 30rpx;
  177. border-bottom: 1px solid #eee;
  178. .left {
  179. image {
  180. width: 200rpx;
  181. height: 150rpx;
  182. background-color: #f2f2f2;
  183. border-radius: 10rpx;
  184. }
  185. }
  186. .right {
  187. flex: 1;
  188. padding-left: 20rpx;
  189. font-size: 28rpx;
  190. .content {
  191. margin-bottom: 10rpx;
  192. .flag{
  193. display: inline-block;
  194. }
  195. }
  196. }
  197. }
  198. </style>