index.js 12 KB

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