CategoryModel.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import request from '../../../Utils/RequestUtils';
  2. import Toast from '../../../flooks/Toast';
  3. import MapModel from '../../Map/model';
  4. const CategoryModel = (now) => ({
  5. list: [],
  6. finish: false,
  7. page: 0,
  8. size: 20,
  9. sort: '',
  10. filter: '',
  11. tag: '',
  12. natureId: '',
  13. endAmount: '',
  14. categoryId: null,
  15. merchantNatureList: [],
  16. getData(chooseCategoryId) {
  17. if (chooseCategoryId != null) {
  18. now({ categoryId: chooseCategoryId });
  19. }
  20. const {
  21. page,
  22. size,
  23. list,
  24. sort,
  25. filter,
  26. tag,
  27. natureId,
  28. endAmount,
  29. categoryId,
  30. } = now();
  31. const { loading, warnning, clearLoading } = now(Toast);
  32. loading();
  33. const { chooseInfo } = now(MapModel);
  34. const { location } = chooseInfo;
  35. const params = { latitude: location.lat, longitude: location.lng };
  36. if (sort) {
  37. params.sort = sort;
  38. }
  39. if (filter) {
  40. params.filter = filter;
  41. }
  42. if (tag) {
  43. params.tag = tag;
  44. }
  45. if (natureId) {
  46. params.natureId = natureId;
  47. }
  48. if (endAmount) {
  49. params.startAmount = 0;
  50. params.endAmount = endAmount;
  51. }
  52. request
  53. .get('/settings/show', {
  54. params,
  55. })
  56. .then((res) => {
  57. clearLoading();
  58. now({
  59. list: list.concat(res),
  60. finish: true,
  61. page: 0,
  62. loading: false,
  63. });
  64. })
  65. .catch((e) => {
  66. warnning(e.error);
  67. });
  68. },
  69. changeChooseMap(info) {
  70. console.log(info);
  71. },
  72. changeSort(type) {
  73. now({
  74. sort: type,
  75. page: 0,
  76. list: [],
  77. });
  78. const { getData } = now();
  79. getData();
  80. },
  81. getNature() {
  82. request.get('/merchantNature/all').then((res) => {
  83. now({
  84. merchantNatureList: res.content,
  85. });
  86. });
  87. },
  88. ChangeFiliter(filter, tag, natureId, endAmount) {
  89. now({
  90. filter,
  91. tag,
  92. natureId,
  93. endAmount,
  94. page: 0,
  95. list: [],
  96. });
  97. const { getData } = now();
  98. getData();
  99. },
  100. clearFiliter() {
  101. now({
  102. filter: '',
  103. tag: '',
  104. natureId: '',
  105. endAmount: '',
  106. page: 0,
  107. list: [],
  108. });
  109. const { getData } = now();
  110. getData();
  111. },
  112. });
  113. export default CategoryModel;