index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  6. (_easycom_u_search2 + _easycom_u_icon2)();
  7. }
  8. const _easycom_u_search = () => "../../node-modules/uview-plus/components/u-search/u-search.js";
  9. const _easycom_u_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
  10. if (!Math) {
  11. (_easycom_u_search + _easycom_u_icon)();
  12. }
  13. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  14. __name: "index",
  15. setup(__props) {
  16. var _a, _b;
  17. const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
  18. (_b = common_vendor.getCurrentInstance()) == null ? void 0 : _b.appContext.config.globalProperties.$config;
  19. const config = common_vendor.ref({ logoUrl: [] });
  20. const searchInfo = common_vendor.ref({});
  21. const type = common_vendor.ref("0");
  22. const is_show = common_vendor.ref(false);
  23. const searchList = common_vendor.ref([{ title: "默认排序", type: "0", is_open: false }, { title: "品牌", type: "1", is_open: false }, { title: "价格", type: "2", is_open: false }, { title: "更多筛选", type: "3", is_open: false }]);
  24. const sortList = common_vendor.ref([{ title: "默认排序", type: "0", is_open: true }, { title: "最新上架", type: "1", is_open: false }, { title: "车龄最短", type: "2", is_open: false }, { title: "里程最少", type: "3", is_open: false }, { title: "价格最高", type: "4", is_open: false }, { title: "价格最低", type: "5", is_open: false }]);
  25. const moneyList = common_vendor.ref([{ title: "不限价格", type: "0", is_open: true }, { title: "10万以下", type: "1", is_open: false }, { title: "10-15万", type: "2", is_open: false }, { title: "15-20万", type: "3", is_open: false }, { title: "20-25万", type: "4", is_open: false }, { title: "25-30万", type: "5", is_open: false }, { title: "30-50万", type: "6", is_open: false }, { title: "50万以上", type: "7", is_open: false }]);
  26. const brandInfo = common_vendor.ref({});
  27. const moneyInfo = common_vendor.ref({});
  28. const moreList = common_vendor.ref([]);
  29. const list = common_vendor.ref([]);
  30. const total = common_vendor.ref(0);
  31. const skip = common_vendor.ref(0);
  32. const limit = common_vendor.ref(6);
  33. const page = common_vendor.ref(0);
  34. const is_bottom = common_vendor.ref(false);
  35. common_vendor.ref(0);
  36. common_vendor.ref([
  37. {
  38. title: "5万以下",
  39. type: "0"
  40. },
  41. {
  42. title: "5-10万",
  43. type: "1"
  44. },
  45. {
  46. title: "10-15万",
  47. type: "2"
  48. },
  49. {
  50. title: "更多条件",
  51. type: "3"
  52. }
  53. ]);
  54. common_vendor.ref([
  55. {
  56. title: "大众",
  57. type: "0"
  58. },
  59. {
  60. title: "宝马",
  61. type: "1"
  62. },
  63. {
  64. title: "本田",
  65. type: "2"
  66. },
  67. {
  68. title: "丰田",
  69. type: "3"
  70. },
  71. {
  72. title: "更多品牌",
  73. type: "4"
  74. }
  75. ]);
  76. common_vendor.onLoad(async () => {
  77. await searchConfig();
  78. await search();
  79. });
  80. common_vendor.onShow(() => {
  81. common_vendor.index.$on("toRoute", function(data) {
  82. brandInfo.value = data;
  83. });
  84. });
  85. const searchConfig = async () => {
  86. config.value = common_vendor.index.getStorageSync("config");
  87. };
  88. const search = async () => {
  89. const info = {
  90. skip: skip.value,
  91. limit: limit.value,
  92. status: "0"
  93. };
  94. const res = await $api("car", "GET", {
  95. ...info,
  96. ...searchInfo.value
  97. });
  98. if (res.errcode === 0) {
  99. list.value = list.value.concat(res.data);
  100. total.value = res.total;
  101. } else {
  102. common_vendor.index.showToast({
  103. title: res.errmsg || "",
  104. icon: "error"
  105. });
  106. }
  107. };
  108. const toSearch = (value) => {
  109. searchList.value = searchList.value.map((item, index) => {
  110. if (item.type == value.type && !item.is_open)
  111. item.is_open = true;
  112. else
  113. item.is_open = false;
  114. return item;
  115. });
  116. type.value = value.type;
  117. if (value.type == "1") {
  118. toClose();
  119. common_vendor.index.navigateTo({
  120. url: `/pagesHome/brand/index`
  121. });
  122. } else if (value.type == "3") {
  123. toClose();
  124. common_vendor.index.navigateTo({
  125. url: `/pagesHome/condition/index`
  126. });
  127. } else
  128. is_show.value = searchList.value.some((item) => item.is_open == true);
  129. };
  130. const toClose = () => {
  131. is_show.value = false;
  132. searchList.value = searchList.value.map((item, index) => {
  133. item.is_open = false;
  134. return item;
  135. });
  136. };
  137. const toSelect = (data, type2) => {
  138. if (type2 == "0") {
  139. sortList.value = sortList.value.map((item, index) => {
  140. if (item.type == data.type)
  141. item.is_open = true;
  142. else
  143. item.is_open = false;
  144. return item;
  145. });
  146. searchList.value = searchList.value.map((i, index) => {
  147. if (i.type == "0")
  148. i.title = data.title;
  149. return i;
  150. });
  151. } else {
  152. moneyList.value = moneyList.value.map((item, index) => {
  153. if (item.type == data.type)
  154. item.is_open = true;
  155. else
  156. item.is_open = false;
  157. return item;
  158. });
  159. moneyInfo.value = data;
  160. }
  161. };
  162. const toDelete = (item, type2) => {
  163. if (type2 == "0")
  164. brandInfo.value = {};
  165. else if (type2 == "1") {
  166. moneyList.value = moneyList.value.map((item2, index) => {
  167. if (item2.type == "0")
  168. item2.is_open = true;
  169. else
  170. item2.is_open = false;
  171. return item2;
  172. });
  173. moneyInfo.value = {};
  174. } else
  175. moreList.value = moreList.value.filter((i, index) => i.type != item.type);
  176. };
  177. const toReset = () => {
  178. brandInfo.value = {};
  179. moneyInfo.value = {};
  180. moreList.value = [];
  181. toClear();
  182. };
  183. const toClear = () => {
  184. searchList.value = searchList.value.map((i, index) => {
  185. if (i.type == "0")
  186. i.title = "默认排序";
  187. return i;
  188. });
  189. moneyList.value = moneyList.value.map((item, index) => {
  190. if (item.type == "0")
  191. item.is_open = true;
  192. else
  193. item.is_open = false;
  194. return item;
  195. });
  196. sortList.value = sortList.value.map((item, index) => {
  197. if (item.type == "0")
  198. item.is_open = true;
  199. else
  200. item.is_open = false;
  201. return item;
  202. });
  203. };
  204. const toChat = (item) => {
  205. common_vendor.index.makePhoneCall({
  206. phoneNumber: item.shop || "110",
  207. success: function() {
  208. console.log("拨打电话成功");
  209. },
  210. fail: function() {
  211. console.log("拨打电话失败");
  212. }
  213. });
  214. };
  215. const toView = (item) => {
  216. common_vendor.index.navigateTo({
  217. url: `/pagesHome/car/index?id=${item.id || item._id}`
  218. });
  219. };
  220. const toPage = () => {
  221. if (total.value > list.value.length) {
  222. common_vendor.index.showLoading({
  223. title: "加载中",
  224. mask: true
  225. });
  226. page.value = page.value + 1;
  227. skip.value = page.value * limit.value;
  228. search();
  229. common_vendor.index.hideLoading();
  230. } else
  231. is_bottom.value = true;
  232. };
  233. return (_ctx, _cache) => {
  234. return common_vendor.e({
  235. a: common_vendor.p({
  236. shape: "square",
  237. ["show-action"]: false,
  238. placeholder: "请输入车辆的名称或品牌"
  239. }),
  240. b: common_vendor.f(searchList.value, (item, index, i0) => {
  241. return common_vendor.e({
  242. a: common_vendor.t(item.title),
  243. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  244. c: item.is_open == false
  245. }, item.is_open == false ? {
  246. d: "2519f642-1-" + i0,
  247. e: common_vendor.p({
  248. color: "#000",
  249. size: "10px",
  250. name: "arrow-down-fill"
  251. })
  252. } : {
  253. f: "2519f642-2-" + i0,
  254. g: common_vendor.p({
  255. color: "#ffbc00",
  256. size: "10px",
  257. name: "arrow-up-fill"
  258. })
  259. }, {
  260. h: index,
  261. i: common_vendor.o(($event) => toSearch(item), index)
  262. });
  263. }),
  264. c: type.value == "0"
  265. }, type.value == "0" ? {
  266. d: common_vendor.f(sortList.value, (item, index, i0) => {
  267. return {
  268. a: common_vendor.t(item.title),
  269. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  270. c: index,
  271. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  272. };
  273. })
  274. } : type.value == "2" ? {
  275. f: common_vendor.f(moneyList.value, (item, index, i0) => {
  276. return {
  277. a: common_vendor.t(item.title),
  278. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  279. c: index,
  280. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  281. };
  282. })
  283. } : {}, {
  284. e: type.value == "2",
  285. g: is_show.value,
  286. h: common_vendor.o(toClose),
  287. i: Object.keys(brandInfo.value).length > 0 || Object.keys(moneyInfo.value).length > 0 || moreList.value.length > 0
  288. }, Object.keys(brandInfo.value).length > 0 || Object.keys(moneyInfo.value).length > 0 || moreList.value.length > 0 ? common_vendor.e({
  289. j: brandInfo.value && brandInfo.value.type
  290. }, brandInfo.value && brandInfo.value.type ? {
  291. k: common_vendor.t(brandInfo.value.title),
  292. l: common_vendor.p({
  293. color: "#000",
  294. size: "14px",
  295. name: "close"
  296. }),
  297. m: common_vendor.o(($event) => toDelete({}, "0"))
  298. } : {}, {
  299. n: moneyInfo.value && moneyInfo.value.type
  300. }, moneyInfo.value && moneyInfo.value.type ? {
  301. o: common_vendor.t(moneyInfo.value.title),
  302. p: common_vendor.p({
  303. color: "#000",
  304. size: "14px",
  305. name: "close"
  306. }),
  307. q: common_vendor.o(($event) => toDelete({}, "1"))
  308. } : {}, {
  309. r: moreList.value.length > 0
  310. }, moreList.value.length > 0 ? {
  311. s: common_vendor.f(moreList.value, (item, index, i0) => {
  312. return {
  313. a: common_vendor.t(item.title),
  314. b: "2519f642-5-" + i0,
  315. c: index,
  316. d: common_vendor.o(($event) => toDelete(item, "2"), index)
  317. };
  318. }),
  319. t: common_vendor.p({
  320. color: "#000",
  321. size: "14px",
  322. name: "close"
  323. })
  324. } : {}, {
  325. v: common_vendor.o(toReset)
  326. }) : {}, {
  327. w: common_vendor.f(list.value, (item, index, i0) => {
  328. return common_vendor.e({
  329. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  330. b: common_vendor.t(item.series || "暂无"),
  331. c: common_vendor.t(item.year || "暂无"),
  332. d: common_vendor.t(item.style || "暂无"),
  333. e: item.year
  334. }, item.year ? {
  335. f: common_vendor.t(item.year || "暂无")
  336. } : {}, {
  337. g: item.mileage
  338. }, item.mileage ? {
  339. h: common_vendor.t(item.mileage || "暂无")
  340. } : {}, {
  341. i: item.place
  342. }, item.place ? {
  343. j: common_vendor.t(item.place || "暂无")
  344. } : {}, {
  345. k: common_vendor.t(item.total_money || "0"),
  346. l: common_vendor.o(($event) => toChat(item), index),
  347. m: index,
  348. n: common_vendor.o(($event) => toView(item), index)
  349. });
  350. }),
  351. x: is_bottom.value
  352. }, is_bottom.value ? {
  353. y: common_vendor.t(config.value.bottom_title || "没有更多了!")
  354. } : {}, {
  355. z: common_vendor.o(toPage)
  356. });
  357. };
  358. }
  359. });
  360. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2519f642"], ["__file", "D:/project/二手车/car_applet/pagesHome/search/index.vue"]]);
  361. wx.createPage(MiniProgramPage);