fans.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. function debounce(handle, delay) {
  5. let time = null;
  6. return function () {
  7. let self = this,
  8. arg = arguments;
  9. clearTimeout(time);
  10. time = setTimeout(function () {
  11. handle.apply(self, arg);
  12. }, delay)
  13. }
  14. }
  15. var fansIndex = new Vue({
  16. el: "#fansIndex",
  17. data() {
  18. return {
  19. searchKey: '',
  20. fansList: [],
  21. currentPage: 1,
  22. totalPage: 0,
  23. offset: 0,
  24. limit: 10,
  25. }
  26. },
  27. mounted() {
  28. this.getfansList();
  29. },
  30. methods: {
  31. getfansList() {
  32. var that = this;
  33. Fast.api.ajax({
  34. url: 'shopro/wechat/fans/index',
  35. loading: true,
  36. type: 'GET',
  37. data: {
  38. offset: that.offset,
  39. limit: that.limit,
  40. searchWhere: that.searchKey,
  41. }
  42. }, function (ret, res) {
  43. that.fansList = res.data.rows;
  44. that.totalPage = res.data.total;
  45. return false;
  46. })
  47. },
  48. handleSizeChange(val) {
  49. this.limit = val;
  50. this.offset=0;
  51. this.currentPage= 1;
  52. this.getfansList();
  53. },
  54. handleCurrentChange(val) {
  55. this.limit=10;
  56. this.offset = this.limit*(val-1);
  57. this.currentPage= 1;
  58. this.getfansList();
  59. },
  60. viewBtn(openid) {
  61. var that = this;
  62. Fast.api.ajax({
  63. url: 'shopro/wechat/fans/user?openid='+openid,
  64. loading: true,
  65. type: 'GET',
  66. }, function (ret, res) {
  67. Fast.api.open('shopro/user/user/profile?id=' + res.data,"查看详情")
  68. })
  69. },
  70. getSync() {
  71. var that = this;
  72. Fast.api.ajax({
  73. url: 'shopro/wechat/fans/syncfans',
  74. loading: true,
  75. type: 'GET',
  76. }, function (ret, res) {
  77. if (res.code == 1) {
  78. that.getfansList();
  79. }
  80. })
  81. },
  82. tableRowClassName({rowIndex}) {
  83. if (rowIndex % 2 == 1) {
  84. return 'bg-color';
  85. }
  86. return '';
  87. },
  88. tableCellClassName({columnIndex}) {
  89. if (columnIndex == 1 || columnIndex == 2) {
  90. return 'cell-left';
  91. }
  92. return '';
  93. },
  94. debounceFilter: debounce(function () {
  95. this.getfansList()
  96. }, 1000),
  97. },
  98. watch: {
  99. searchKey(newVal, oldVal) {
  100. if (newVal != oldVal) {
  101. this.offset = 0;
  102. this.limit=10
  103. this.currentPage= 1;
  104. this.debounceFilter();
  105. }
  106. }
  107. },
  108. })
  109. },
  110. api: {
  111. bindevent: function () {
  112. Form.api.bindevent($("form[role=form]"));
  113. }
  114. }
  115. };
  116. return Controller;
  117. });