index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. const $config = (_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. const typeList = common_vendor.ref([
  27. {
  28. title: "5万以下",
  29. type: "0"
  30. },
  31. {
  32. title: "5-10万",
  33. type: "1"
  34. },
  35. {
  36. title: "10-15万",
  37. type: "2"
  38. },
  39. {
  40. title: "更多条件",
  41. type: "3"
  42. }
  43. ]);
  44. const carList = common_vendor.ref([]);
  45. common_vendor.onShow(async () => {
  46. await searchOther();
  47. await searchConfig();
  48. await clearPage();
  49. await search();
  50. });
  51. common_vendor.onPullDownRefresh(async () => {
  52. await clearPage();
  53. await searchOther();
  54. await search();
  55. common_vendor.index.stopPullDownRefresh();
  56. });
  57. const searchOther = async () => {
  58. let res;
  59. res = await $api(`brand`, "GET", { skip: 0, limit: 4, is_use: "0" });
  60. if (res.errcode === 0)
  61. carList.value = res.data;
  62. carList.value.push({
  63. name: "更多品牌",
  64. type: "4"
  65. });
  66. };
  67. const searchConfig = async () => {
  68. config.value = common_vendor.index.getStorageSync("config");
  69. };
  70. const search = async () => {
  71. const info = {
  72. skip: skip.value,
  73. limit: limit.value,
  74. status: "0"
  75. };
  76. const res = await $api("car", "GET", {
  77. ...info,
  78. ...searchInfo.value
  79. });
  80. if (res.errcode === 0) {
  81. list.value = list.value.concat(res.data);
  82. total.value = res.total;
  83. } else {
  84. common_vendor.index.showToast({
  85. title: res.errmsg || "",
  86. icon: "error"
  87. });
  88. }
  89. };
  90. const toRoute = (item) => {
  91. common_vendor.index.navigateTo({
  92. url: `/${item.route}`
  93. });
  94. };
  95. const toCommon = (item, type) => {
  96. console.log(item);
  97. if (type == "0" && item.type == "4") {
  98. common_vendor.index.navigateTo({
  99. url: `/pagesHome/brand/index?type=${item.type || ""}`
  100. });
  101. } else {
  102. common_vendor.index.navigateTo({
  103. url: `/pagesHome/search/index?type=${item.type || ""}`
  104. });
  105. }
  106. };
  107. const toView = (item) => {
  108. common_vendor.index.navigateTo({
  109. url: `/pagesHome/car/index?id=${item.id || item._id}`
  110. });
  111. };
  112. const toPage = () => {
  113. if (total.value > list.value.length) {
  114. common_vendor.index.showLoading({
  115. title: "加载中",
  116. mask: true
  117. });
  118. page.value = page.value + 1;
  119. skip.value = page.value * limit.value;
  120. search();
  121. common_vendor.index.hideLoading();
  122. } else
  123. is_bottom.value = true;
  124. };
  125. const clearPage = () => {
  126. list.value = [];
  127. skip.value = 0;
  128. limit.value = 6;
  129. page.value = 0;
  130. };
  131. return (_ctx, _cache) => {
  132. return common_vendor.e({
  133. a: common_vendor.p({
  134. shape: "square",
  135. ["show-action"]: false,
  136. placeholder: "品牌/车系"
  137. }),
  138. b: common_vendor.f(common_vendor.unref($config).searchList, (item, index, i0) => {
  139. return {
  140. a: common_vendor.n(item.icon),
  141. b: common_vendor.t(item.title || "暂无"),
  142. c: index,
  143. d: common_vendor.o(($event) => toRoute(item), index)
  144. };
  145. }),
  146. c: common_vendor.f(carList.value, (item, index, i0) => {
  147. return {
  148. a: item.logo && item.logo.length > 0 ? item.logo[0].url : "/static/logo.png",
  149. b: common_vendor.t(item.name),
  150. c: index,
  151. d: common_vendor.o(($event) => toCommon(item, "0"), index)
  152. };
  153. }),
  154. d: common_vendor.f(typeList.value, (item, index, i0) => {
  155. return {
  156. a: common_vendor.t(item.title || "暂无"),
  157. b: index,
  158. c: common_vendor.o(($event) => toCommon(item, "1"), index)
  159. };
  160. }),
  161. e: common_vendor.f(list.value, (item, index, i0) => {
  162. return common_vendor.e({
  163. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  164. b: common_vendor.t(item.series || "暂无"),
  165. c: common_vendor.t(item.year || "暂无"),
  166. d: common_vendor.t(item.style || "暂无"),
  167. e: item.year
  168. }, item.year ? {
  169. f: common_vendor.t(item.year || "暂无")
  170. } : {}, {
  171. g: item.mileage
  172. }, item.mileage ? {
  173. h: common_vendor.t(item.mileage || "暂无")
  174. } : {}, {
  175. i: item.place
  176. }, item.place ? {
  177. j: common_vendor.t(item.place || "暂无")
  178. } : {}, {
  179. k: common_vendor.t(item.total_money || "0"),
  180. l: index,
  181. m: common_vendor.o(($event) => toView(item), index)
  182. });
  183. }),
  184. f: is_bottom.value
  185. }, is_bottom.value ? {
  186. g: common_vendor.t(config.value.bottom_title || "没有更多了!")
  187. } : {}, {
  188. h: common_vendor.o(toPage)
  189. });
  190. };
  191. }
  192. });
  193. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4723889f"], ["__file", "D:/project/二手车/car_applet/pages/select/index.vue"]]);
  194. wx.createPage(MiniProgramPage);