courseCollect.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view>
  3. <mescroll-body ref="mescrollRef" style="background-color: #FAFAFA;" @init="mescrollInit" top="0" bottom="0" :down="downOption" @down="downCallback" :up="upOption"
  4. @up="upCallback" @emptyclick="emptyClick">
  5. <view class="goods-list">
  6. <goodsItemVertical :isOperate="isOperate" :showCollect="false" v-for="(item, index) in dataList" :item="item" :key="index" :index="index" @canCalFav="canCalFav" @handleChoose='handleChoose' />
  7. </view>
  8. <uni-view v-if="dataList.length==0 && isPostBack" data-v-79c5cef0="" data-v-6f5cf468="" class="mescroll-empty" style="z-index: 99; top: 50px;padding: 0 25px 25px;">
  9. <uni-view data-v-79c5cef0="">
  10. <uni-image data-v-79c5cef0="" class="empty-icon" style="height: 186px;">
  11. <div style="background-image: url(&quot;/static/images/icon_img_empty.png&quot;); background-size: 100% 100%; background-repeat: no-repeat;"></div><uni-resize-sensor><div><div></div></div><div><div></div></div></uni-resize-sensor>
  12. <img src="/static/images/icon_img_empty.png" draggable="false">
  13. </uni-image>
  14. </uni-view>
  15. <uni-view data-v-79c5cef0="" class="empty-tip">~ 暂无数据 ~</uni-view>
  16. <uni-view data-v-79c5cef0="" class="empty-btn">刷新重试</uni-view>
  17. </uni-view>
  18. <!-- 推荐 -->
  19. <view class="recommend-title">
  20. <view class="line"></view>
  21. <text>为你推荐</text>
  22. <view class="line"></view>
  23. </view>
  24. <view class="recommend-box">
  25. <hallItem class="gapitem" v-for="(item, index) in recommendList " :key="index" :item="item" @click.native="$navTo('/pages_course/info?courseId='+item.courseId)" />
  26. </view>
  27. </mescroll-body>
  28. </view>
  29. </template>
  30. <script>
  31. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  32. import mescrollBody from "@/uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.vue";
  33. import goodsItemVertical from "@/pages_course/components/goodsItemVertical.vue";
  34. import hallItem from "@/pages/course/components/hallItem.vue";
  35. import { getMyFavoriteCourseList,getCourseList,doFavorite } from '@/api/course'
  36. export default {
  37. mixins: [MescrollMixin], // 使用mixin
  38. components: {
  39. goodsItemVertical,
  40. hallItem
  41. },
  42. data() {
  43. return {
  44. showCollect: false, // 是否显示收藏
  45. text: '管理',
  46. isOperate: false, // 是否操作
  47. downOption: { //下拉刷新
  48. use:true,
  49. auto: true // 不自动加载 (mixin已处理第一个tab触发downCallback)
  50. },
  51. totalNum:0,
  52. upOption: { //上拉加载
  53. use:true,
  54. auto: false, // 不自动加载
  55. page: {
  56. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  57. size: 10 // 每页数据的数量
  58. },
  59. noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  60. empty:{
  61. tip: '~ 暂无数据 ~', // 提示
  62. btnText: '刷新重试',
  63. icon:"/static/images/icon_img_empty.png"
  64. }
  65. },
  66. recommendList:[],
  67. dataList:[],
  68. isPostBack:false,
  69. }
  70. },
  71. onNavigationBarButtonTap(e) {
  72. if(this.text == "管理") {
  73. if(this.dataList.length == 0) {
  74. uni.showToast({
  75. title: '暂无数据',
  76. icon: "none"
  77. })
  78. return
  79. }
  80. this.isOperate = true
  81. this.resetTitle( "删除")
  82. return
  83. }
  84. // 删除
  85. if(this.text == "删除") {
  86. this.handleDel()
  87. return
  88. }
  89. },
  90. onLoad() {
  91. this.getRecommendList();
  92. this.upCallback({num:1});
  93. },
  94. methods: {
  95. /*下拉刷新的回调 */
  96. downCallback() {
  97. this.refreshPage();
  98. },
  99. /*上拉加载的回调*/
  100. upCallback(page) {
  101. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  102. let params={};
  103. getMyFavoriteCourseList(params,page.num).then(res => {
  104. if(res.code==200){
  105. setTimeout(()=>{
  106. let list = res.data.list.map(item=>({
  107. ...item,
  108. checked: false
  109. }))
  110. //this.mescroll.endByPage(res.data.list.length, res.data.pages);
  111. if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
  112. this.dataList=this.dataList.concat(list); //追加新数据
  113. this.totalNum=res.data.total;
  114. this.isPostBack=true;
  115. },300);
  116. }else{
  117. this.mescroll.endByPage(0, 1);
  118. }
  119. },
  120. rej => {}
  121. ).catch(()=>{
  122. //联网失败, 结束加载
  123. this.mescroll.endErr();
  124. });
  125. },
  126. getRecommendList:function(){
  127. let that=this;
  128. const params={"isTui":1};
  129. getCourseList(params,1,10).then(res => {
  130. if(res.code==200){
  131. this.recommendList=res.data.list;
  132. }
  133. },
  134. rej => {}
  135. );
  136. },
  137. refreshPage(){
  138. // this.mescroll.hideTopBtn();
  139. // this.mescroll.resetUpScroll(true);
  140. this.upCallback({num:1});
  141. },
  142. back() {
  143. uni.navigateBack({
  144. delta: 1
  145. })
  146. },
  147. canCalFav(item) {
  148. uni.showLoading({title:""});
  149. doFavorite(item.courseId).then(res => {
  150. uni.hideLoading();
  151. if(res.code==200){
  152. uni.showToast({title: '操作成功',icon: 'none'});
  153. this.dataList.splice(item.index,1);
  154. }else{
  155. uni.showToast({title: res.msg,icon: 'none'});
  156. }
  157. },
  158. rej => {}
  159. );
  160. },
  161. emptyClick(){
  162. },
  163. resetTitle(text) {
  164. this.text = text
  165. // #ifdef H5
  166. document.querySelector('.uni-page-head-ft .uni-page-head-btn .uni-btn-icon').innerHTML = text;
  167. // #endif
  168. // #ifdef APP-PLUS
  169. let pages = getCurrentPages();
  170. let page= pages[pages.length - 1];
  171. let webView = page.$getAppWebview()
  172. // 修改buttons
  173. // index: 按钮索引, style {WebviewTitleNViewButtonStyles }
  174. webView.setTitleNViewButtonStyle(0, { text: text });
  175. // #endif
  176. },
  177. handleDel(){
  178. this.isOperate = false;
  179. this.resetTitle("管理")
  180. },
  181. handleChoose(index) {
  182. this.dataList[index].checked = !this.dataList[index].checked
  183. },
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .navbar-title {
  189. font-weight: 700;
  190. font-size: 16px;
  191. width: 100%;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. }
  196. .goods-list {
  197. padding: 20rpx 24rpx;
  198. .vertical-goods-itembox {
  199. margin-bottom: 20rpx;
  200. }
  201. }
  202. .recommend-title {
  203. width: 100%;
  204. height: 80rpx;
  205. padding: 0 24rpx;
  206. box-sizing: border-box;
  207. font-family: PingFang SC, PingFang SC;
  208. font-weight: 500;
  209. font-size: 26rpx;
  210. color: #FF5C03;
  211. text-align: center;
  212. line-height: 80rpx;
  213. display: flex;
  214. align-items: center;
  215. text {
  216. margin: 0 32rpx;
  217. }
  218. .line {
  219. flex: 1;
  220. height: 0;
  221. border: 2rpx solid #ECECEC;
  222. }
  223. }
  224. .recommend-box {
  225. padding: 8rpx 24rpx;
  226. display: flex;
  227. flex-direction: row;
  228. flex-wrap: wrap;
  229. margin-right: -18rpx;
  230. }
  231. .gapitem {
  232. margin-right: 18rpx;
  233. margin-bottom: 18rpx;
  234. }
  235. </style>