index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. define([
  2. 'api/auth',
  3. 'api/special',
  4. 'api/material',
  5. 'text!components/my/favor/index.html',
  6. 'css!components/my/favor/index.css'
  7. ], function(authApi, specialApi, materialApi, html) {
  8. return {
  9. props: {
  10. activeName: {
  11. type: String,
  12. default: 'favor'
  13. },
  14. isLogin: {
  15. type: Boolean,
  16. default: false
  17. }
  18. },
  19. data: function () {
  20. return {
  21. page1: 1,
  22. page2: 1,
  23. limit: 16,
  24. active: '0',
  25. list1: [],
  26. list2: [],
  27. finished1: false,
  28. finished2: false,
  29. count1: 0,
  30. count2: 0
  31. };
  32. },
  33. watch: {
  34. isLogin: function (value) {
  35. if (value) {
  36. this.get_grade_list1();
  37. this.get_grade_list2();
  38. }
  39. },
  40. page1: function () {
  41. this.get_grade_list1();
  42. },
  43. page2: function () {
  44. this.get_grade_list2();
  45. }
  46. },
  47. methods: {
  48. // 课程
  49. get_grade_list1: function () {
  50. var vm = this;
  51. authApi.get_grade_list({
  52. page: this.page1,
  53. limit: this.limit,
  54. active: 0
  55. }).then(function (res) {
  56. var data = res.data;
  57. vm.count1 = data.count;
  58. vm.list1 = data.list;
  59. // vm.finished1 = vm.limit > data.list.length;
  60. }).catch(function (err) {
  61. vm.$message.error(err.msg);
  62. });
  63. },
  64. // 资料
  65. get_grade_list2: function () {
  66. var vm = this;
  67. authApi.get_grade_list({
  68. page: this.page2,
  69. limit: this.limit,
  70. active: 1
  71. }).then(function (res) {
  72. var data = res.data;
  73. vm.count2 = data.count;
  74. vm.list2 = data.list;
  75. // vm.finished2 = vm.limit > data.list.length;
  76. }).catch(function (err) {
  77. vm.$message.error(err.msg);
  78. });
  79. },
  80. // 取消课程收藏
  81. specialCollect: function (id) {
  82. var vm = this;
  83. specialApi.collect({
  84. id: id
  85. }).then(function () {
  86. vm.$message.success('取消收藏成功');
  87. if (!(vm.list1.length - 1)) {
  88. if (vm.page1 > 1) {
  89. vm.page1--;
  90. }
  91. }
  92. vm.get_grade_list1();
  93. }).catch(function (err) {
  94. vm.$message.error(err.msg);
  95. });
  96. },
  97. // 取消资料收藏
  98. materialCollect: function (id) {
  99. var vm = this;
  100. materialApi.collect({
  101. id: id
  102. }).then(function () {
  103. vm.$message.success('取消收藏成功');
  104. if (!(vm.list2.length - 1)) {
  105. if (vm.page2 > 1) {
  106. vm.page2--;
  107. }
  108. }
  109. vm.get_grade_list2();
  110. }).catch(function (err) {
  111. vm.$message.error(err.msg);
  112. });
  113. },
  114. tabClick: function (params) {
  115. }
  116. },
  117. template: html
  118. };
  119. });