index.js 6.0 KB

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