courseCollect.vue 7.4 KB

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