index.js 6.1 KB

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