mycollection.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="myCollection">
  3. <view class="bg"></view>
  4. <u-navbar back-icon-color="#fff" :back-text="$t('common.Back')" :is-back="true"
  5. :background="{background:'#1777FE'}" :back-text-style="{color:'#fff'}" :border-bottom="true"
  6. title-color="#fff" :title="title" :custom-back="back">
  7. </u-navbar>
  8. <view class="collectList" v-if="collectList.length>0">
  9. <view class="item" v-for="(item,index) in collectList" :key="index">
  10. <uni-swipe-action style="width:100%">
  11. <uni-swipe-action-item :right-options="options" @click="addCollectInfo(index,item)">
  12. <view class="thumb" @click="showDetial(item)"
  13. v-if="item.pictureUrl && !isArray(item.pictureUrl)">
  14. <image class="img" :src="websiteUrl+item.pictureUrl" mode="widthFix"></image>
  15. </view>
  16. <view class="info" @click="showDetial(item)">
  17. <view class="label" :class="{hasThumb:item.pictureUrl}">{{item.title}}</view>
  18. <view class="tags" :class="{hasThumb:item.pictureUrl}">
  19. <text class="textitem">{{item.auther}}</text>
  20. <view class="date" v-if="item.publishDate">{{formatDate(item.publishDate -0)}}</view>
  21. </view>
  22. <!-- <view class="mulimgs" v-if="!item.pictureUrl && index==0">
  23. <view class="imgitem" @click="showDetial(item)">
  24. <image class="img" src="https://www.geidcp.com/api/file/pub//def/projectdefault.png" mode="widthFix"></image>
  25. </view>
  26. <view class="imgitem" @click="showDetial(item)">
  27. <image class="img" src="https://www.geidcp.com/api/file/pub//def/projectdefault.png" mode="widthFix"></image>
  28. </view>
  29. <view class="imgitem" @click="showDetial(item)">
  30. <image class="img" src="https://www.geidcp.com/api/file/pub//def/projectdefault.png" mode="widthFix"></image>
  31. </view>
  32. </view> -->
  33. </view>
  34. </uni-swipe-action-item>
  35. </uni-swipe-action>
  36. </view>
  37. <uni-load-more :status="status" v-show="this.total>10"></uni-load-more>
  38. </view>
  39. <!-- <view class="loading" v-if="showLoading" :class="{fixbottom:pageNo<totalPage}">
  40. <u-loadmore :status="status" iconType="flower" :load-text="{loading: $t('common.Loading')}" />
  41. </view> -->
  42. <view class="nodata" v-if="!showLoading && collectList.length==0"
  43. style="text-align: center;margin-top: 120upx;">
  44. <view class="imgBox" style="height:600upx;margin-bottom:60upx">
  45. <image src="../../../static/img/public/7.png" style="width: 80%;margin:0 10%" mode="widthFix"></image>
  46. </view>
  47. <text style="font-size: 30upx;color:#ccc">{{$t('common.Nodata')}}</text>
  48. </view>
  49. <u-toast ref="uToast" />
  50. </view>
  51. </template>
  52. <script>
  53. import UNavbar from '@/components/uni-nav-bar/uni-nav-bar.vue'
  54. import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
  55. import {
  56. addCollectInfo,
  57. getPortalMyCollecModel
  58. } from '@/api/baseUnitView'
  59. export default {
  60. name: 'MyCollection',
  61. components: {
  62. UNavbar,
  63. uniSwipeAction,
  64. },
  65. data() {
  66. return {
  67. total: null,
  68. token: '',
  69. userId: '',
  70. pageNo: 1,
  71. pageSize: 10,
  72. modelType: '',
  73. totalPage: 0,
  74. options: [{
  75. text: this.$t('common.CancelCollection'),
  76. style: {
  77. fontSize: '12px',
  78. height: '30px',
  79. backgroundColor: '#f2a059',
  80. height: '60px'
  81. }
  82. }],
  83. menuIndex: 0,
  84. flag: false,
  85. collectList: [],
  86. showLoading: true,
  87. status: 'more',
  88. }
  89. },
  90. onLoad(e) {
  91. this.title = this.$i18n.locale == 'zh' ? '我的收藏' : 'My Collection';
  92. },
  93. onShow() {
  94. this.token = uni.getStorageSync('Auth-Token') ? 'Bearer ' + uni.getStorageSync('Auth-Token') : '';
  95. this.userId = uni.getStorageSync('user') ? JSON.parse(uni.getStorageSync('user')).id : '';
  96. },
  97. created() {
  98. this.getPortalMyCollecModel()
  99. },
  100. //加载更多
  101. onReachBottom() {
  102. if (this.pageNo < this.totalPage) {
  103. this.showLoading = true;
  104. this.pageNo++;
  105. this.getPortalMyCollecModel('loadmore')
  106. } else {
  107. if (this.showLoading != false) this.showLoading = false
  108. this.status = 'noMore';
  109. }
  110. },
  111. onPullDownRefresh() {
  112. //调用获取数据方法
  113. this.getPortalMyCollecModel('loadmore')
  114. setTimeout(() => {
  115. uni.stopPullDownRefresh();
  116. }, 1000);
  117. },
  118. // onReachBottom() {
  119. // let allTotal = this.pageNo * this.pageSize
  120. // if (allTotal < this.total) {
  121. // console.log(this.total);
  122. // //当前条数小于总条数 则增加请求页数
  123. // this.status = 'loading';
  124. // this.pageSize++;
  125. // this.getPortalMyCollecModel() //调用加载数据方法
  126. // } else {
  127. // this.status = 'noMore';
  128. // // console.log('已加载全部数据')
  129. // }
  130. // },
  131. methods: {
  132. // 获取我的收藏数据列表
  133. async getPortalMyCollecModel(loadmore) {
  134. let data = {
  135. modelType: 'message',
  136. userId: this.userId,
  137. language: this.$i18n.locale.toUpperCase(),
  138. pageNo: this.pageNo,
  139. pageSize: this.pageSize,
  140. }
  141. let res = await this.$myRequest({
  142. url: '/op/basePortalModelCollectInfos/getPortalMyCollecModel',
  143. headers: {
  144. token: this.token
  145. },
  146. data
  147. })
  148. // if (res.status != 200) {
  149. // this.collectList = []
  150. // } else {
  151. if (res.data.models) {
  152. this.totalPage = res.data.page.totalPage
  153. this.total = res.data.page.totalCount
  154. if (!loadmore) this.collectList = res.data.models.cmsInformationViewList;
  155. else this.collectList = [...this.collectList, ...res.data.models.cmsInformationViewList]
  156. }
  157. // }
  158. this.showLoading = false;
  159. },
  160. //路由后退一步
  161. back() {
  162. // #ifdef H5
  163. history.back()
  164. // #endif
  165. // #ifndef H5
  166. uni.navigateBack()
  167. // #endif
  168. },
  169. // 查看详情
  170. showDetial(item) {
  171. uni.navigateTo({
  172. url: '/pages/information/components/rankDetail?key=' + item.baseEntityId
  173. })
  174. },
  175. //取消收藏
  176. async addCollectInfo(index, item) {
  177. // let res = await addCollectInfo(item.id,item.businessType,this.userId,'uncollect',this.token);
  178. let res = await this.$myRequest({
  179. url: '/op/basePortalModelCollectInfos/addCollectInfo',
  180. method: 'post',
  181. headers: {
  182. token: this.token
  183. },
  184. data: {
  185. collectType: "uncollect",
  186. modelId: item.baseEntityId,
  187. modelType: "message",
  188. // modelType: item.businessType,
  189. userId: this.userId
  190. }
  191. })
  192. if (res.status == 200) {
  193. this.collectList.splice(index, 1);
  194. this.$refs.uToast.show({
  195. title: this.$i18n.locale == 'zh' ? "取消收藏成功" : "Success Cancel the like",
  196. type: 'success',
  197. })
  198. } else {
  199. this.$refs.uToast.show({
  200. title: this.$i18n.locale == 'zh' ? "取消收藏失败" : "Fail Cancel the like",
  201. type: 'error',
  202. })
  203. }
  204. },
  205. // 判断是否为数组
  206. isArray(data) {
  207. return Array.isArray(data) === true ? true : false
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .myCollection {
  214. .bg {
  215. position: fixed;
  216. top: 0;
  217. left: 0;
  218. bottom: 0;
  219. right: 0;
  220. background-color: #fff;
  221. z-index: -1;
  222. }
  223. .line-h {
  224. height: 1px;
  225. background-color: #eee;
  226. margin: 10upx 0;
  227. }
  228. .loading {
  229. width: 100%;
  230. height: 88rpx;
  231. line-height: 88rpx;
  232. .fixbottom {
  233. position: fixed;
  234. bottom: 0;
  235. z-index: 999;
  236. }
  237. }
  238. .collectList {
  239. display: flex;
  240. flex-direction: column;
  241. padding: 0 3% 50upx 3%;
  242. width: 100%;
  243. .item {
  244. margin: 20upx 0 0 0;
  245. padding: 20upx 0;
  246. border-bottom: 2upx solid #eee;
  247. display: flex;
  248. flex: 1;
  249. &:last-of-type {
  250. border: none
  251. }
  252. .thumb {
  253. width: 200upx;
  254. margin-right: 3%;
  255. position: relative;
  256. overflow: hidden;
  257. display: flex;
  258. align-items: center;
  259. .img {
  260. width: 100%;
  261. display: block;
  262. }
  263. }
  264. .info {
  265. flex: 1;
  266. margin-right: 10px;
  267. .label {
  268. font-size: 24upx;
  269. color: #666;
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. display: -webkit-box;
  273. -webkit-box-orient: vertical;
  274. -webkit-line-clamp: 2;
  275. margin-bottom: 20upx;
  276. &.hasThumb {
  277. margin-bottom: 12upx;
  278. }
  279. .follow {
  280. background-color: #0081FF;
  281. color: #fff;
  282. padding: 4upx 10upx;
  283. border-radius: 6upx;
  284. margin-left: 10upx;
  285. }
  286. }
  287. .tags {
  288. display: flex;
  289. justify-content: space-between;
  290. width: 100%;
  291. &.hasThumb {
  292. width: 90%;
  293. }
  294. .textitem {
  295. margin-right: 20upx;
  296. background: #EBF3FF;
  297. padding: 4upx 8upx;
  298. color: #3386F1;
  299. font-size: 12px;
  300. }
  301. .date {
  302. font-size: 24upx;
  303. color: #999;
  304. }
  305. }
  306. .mulimgs {
  307. flex: 1;
  308. display: flex;
  309. flex-wrap: wrap;
  310. align-items: center;
  311. .imgitem {
  312. width: 30%;
  313. height: 140upx;
  314. margin: 16upx 16upx 0 0;
  315. position: relative;
  316. overflow: hidden;
  317. &:last-of-type {
  318. margin-right: 0
  319. }
  320. .img {
  321. display: block;
  322. width: 100%;
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. </style>