index.js 12 KB

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