index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. define([
  2. 'api/auth',
  3. 'api/special',
  4. 'api/material',
  5. 'text!./index.html',
  6. 'css!./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. },
  41. methods: {
  42. // 课程
  43. get_grade_list1: function () {
  44. var vm = this;
  45. authApi.get_grade_list({
  46. page: this.page1,
  47. limit: this.limit,
  48. active: 0
  49. }).then(function (res) {
  50. var data = res.data;
  51. vm.count1 = data.count;
  52. vm.list1 = data.list;
  53. // vm.finished1 = vm.limit > data.list.length;
  54. }).catch(function (err) {
  55. vm.$message.error(err.msg);
  56. });
  57. },
  58. // 资料
  59. get_grade_list2: function () {
  60. var vm = this;
  61. authApi.get_grade_list({
  62. page: this.page2,
  63. limit: this.limit,
  64. active: 1
  65. }).then(function (res) {
  66. var data = res.data;
  67. vm.count2 = data.count;
  68. vm.list2 = data.list;
  69. // vm.finished2 = vm.limit > data.list.length;
  70. }).catch(function (err) {
  71. vm.$message.error(err.msg);
  72. });
  73. },
  74. // 取消课程收藏
  75. specialCollect: function (id) {
  76. var vm = this;
  77. specialApi.collect({
  78. id: id
  79. }).then(function () {
  80. vm.$message.success('取消收藏成功');
  81. if (!(vm.list1.length - 1)) {
  82. if (vm.page1 > 1) {
  83. vm.page1--;
  84. }
  85. }
  86. vm.get_grade_list1();
  87. }).catch(function (err) {
  88. vm.$message.error(err.msg);
  89. });
  90. },
  91. // 取消资料收藏
  92. materialCollect: function (id) {
  93. var vm = this;
  94. materialApi.collect({
  95. id: id
  96. }).then(function () {
  97. vm.$message.success('取消收藏成功');
  98. if (!(vm.list2.length - 1)) {
  99. if (vm.page2 > 1) {
  100. vm.page2--;
  101. }
  102. }
  103. vm.get_grade_list2();
  104. }).catch(function (err) {
  105. vm.$message.error(err.msg);
  106. });
  107. },
  108. tabClick: function (params) {
  109. }
  110. },
  111. template: html
  112. };
  113. });