index.js 12 KB

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