index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. if (!Array) {
  4. const _easycom_u_search2 = common_vendor.resolveComponent("u-search");
  5. _easycom_u_search2();
  6. }
  7. const _easycom_u_search = () => "../../node-modules/uview-plus/components/u-search/u-search.js";
  8. if (!Math) {
  9. _easycom_u_search();
  10. }
  11. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  12. __name: "index",
  13. setup(__props) {
  14. var _a, _b;
  15. const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
  16. (_b = common_vendor.getCurrentInstance()) == null ? void 0 : _b.appContext.config.globalProperties.$config;
  17. const config = common_vendor.ref({ logoUrl: [] });
  18. const searchInfo = common_vendor.ref({});
  19. const list = common_vendor.ref([]);
  20. const total = common_vendor.ref(0);
  21. const skip = common_vendor.ref(0);
  22. const limit = common_vendor.ref(6);
  23. const page = common_vendor.ref(0);
  24. const is_bottom = common_vendor.ref(false);
  25. common_vendor.ref(0);
  26. common_vendor.onShow(async () => {
  27. await searchConfig();
  28. await clearPage();
  29. await search();
  30. });
  31. common_vendor.onPullDownRefresh(async () => {
  32. await clearPage();
  33. await search();
  34. common_vendor.index.stopPullDownRefresh();
  35. });
  36. const searchConfig = async () => {
  37. config.value = common_vendor.index.getStorageSync("config");
  38. };
  39. const search = async () => {
  40. const info = {
  41. skip: skip.value,
  42. limit: limit.value,
  43. status: "0"
  44. };
  45. const res = await $api("car", "GET", {
  46. ...info,
  47. ...searchInfo.value
  48. });
  49. if (res.errcode === 0) {
  50. list.value = list.value.concat(res.data);
  51. total.value = res.total;
  52. } else {
  53. common_vendor.index.showToast({
  54. title: res.errmsg || "",
  55. icon: "error"
  56. });
  57. }
  58. };
  59. const toView = (item) => {
  60. common_vendor.index.navigateTo({
  61. url: `/pagesHome/car/index?id=${item.id || item._id}`
  62. });
  63. };
  64. const toPage = () => {
  65. if (total.value > list.value.length) {
  66. common_vendor.index.showLoading({
  67. title: "加载中",
  68. mask: true
  69. });
  70. page.value = page.value + 1;
  71. skip.value = page.value * limit.value;
  72. search();
  73. common_vendor.index.hideLoading();
  74. } else
  75. is_bottom.value = true;
  76. };
  77. const clearPage = () => {
  78. list.value = [];
  79. skip.value = 0;
  80. limit.value = 6;
  81. page.value = 0;
  82. };
  83. return (_ctx, _cache) => {
  84. return common_vendor.e({
  85. a: common_vendor.p({
  86. shape: "square",
  87. ["show-action"]: false,
  88. placeholder: "品牌/车系"
  89. }),
  90. b: common_vendor.f(list.value, (item, index, i0) => {
  91. return {
  92. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  93. b: common_vendor.t(item.series || "暂无"),
  94. c: common_vendor.t(item.year || "暂无"),
  95. d: common_vendor.t(item.style || "暂无"),
  96. e: common_vendor.t(item.total_money || "0"),
  97. f: index,
  98. g: common_vendor.o(($event) => toView(item), index)
  99. };
  100. }),
  101. c: is_bottom.value
  102. }, is_bottom.value ? {
  103. d: common_vendor.t(config.value.bottom_title || "没有更多了!")
  104. } : {}, {
  105. e: common_vendor.o(toPage)
  106. });
  107. };
  108. }
  109. });
  110. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4978fed5"], ["__file", "D:/project/二手车/car_applet/pages/home/index.vue"]]);
  111. wx.createPage(MiniProgramPage);