index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. define([
  2. 'require',
  3. 'api/merchant',
  4. 'text!./index.html',
  5. 'css!./index.css'
  6. ], function (require, merchantApi, html) {
  7. return {
  8. props: {
  9. activeName: {
  10. type: String,
  11. default: ''
  12. }
  13. },
  14. data: function () {
  15. return {
  16. page: 1,
  17. limit: 16,
  18. total: 0,
  19. followList: [],
  20. finished: false
  21. };
  22. },
  23. watch: {
  24. activeName: function (value) {
  25. if (value === 'lecturer') {
  26. this.getFollowList();
  27. }
  28. },
  29. page: function () {
  30. this.getFollowList();
  31. }
  32. },
  33. methods: {
  34. getFollowList: function () {
  35. var vm = this;
  36. merchantApi.get_user_follow_list({
  37. page: this.page,
  38. limit: this.limit
  39. }).then(function (res) {
  40. var list = res.data.data;
  41. list.forEach(function (item) {
  42. item.label = JSON.parse(item.label);
  43. });
  44. vm.total = res.data.count;
  45. vm.followList = list;
  46. vm.finished = vm.limit > list.length;
  47. });
  48. },
  49. follow: function (item) {
  50. var vm = this;
  51. merchantApi.user_follow({
  52. mer_id: item.mer_id,
  53. is_follow: 0
  54. }).then(function (res) {
  55. if (vm.followList.length > 1) {
  56. vm.getFollowList();
  57. } else {
  58. if (vm.page > 1) {
  59. vm.page -= 1
  60. vm.getFollowList();
  61. } else {
  62. vm.followList = [];
  63. }
  64. }
  65. vm.$message.success('移除成功');
  66. });
  67. }
  68. },
  69. template: html
  70. };
  71. });