index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. if (options && options.type != "3") {
  36. searchInfo.value.brand = options && options.brand || "";
  37. searchInfo.value.money = options && options.money || "";
  38. }
  39. await searchConfig();
  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. if (data.type != "0")
  132. searchInfo.value.money = data.title;
  133. else
  134. searchInfo.value.money = "";
  135. }
  136. await clearPage();
  137. await search();
  138. };
  139. const toDelete = async (item, type2) => {
  140. if (type2 == "0")
  141. searchInfo.value.brand = "";
  142. else if (type2 == "1") {
  143. moneyList.value = moneyList.value.map((item2, index) => {
  144. if (item2.type == "0")
  145. item2.is_open = true;
  146. else
  147. item2.is_open = false;
  148. return item2;
  149. });
  150. searchInfo.value.money = "";
  151. } else
  152. moreList.value = moreList.value.filter((i, index) => i.type != item.type);
  153. await clearPage();
  154. await search();
  155. };
  156. const toReset = async () => {
  157. searchInfo.value.brand = "";
  158. searchInfo.value.money = "";
  159. moreList.value = [];
  160. toClear();
  161. await clearPage();
  162. await search();
  163. };
  164. const toClear = () => {
  165. searchList.value = searchList.value.map((i, index) => {
  166. if (i.type == "0")
  167. i.title = "默认排序";
  168. return i;
  169. });
  170. moneyList.value = moneyList.value.map((item, index) => {
  171. if (item.type == "0")
  172. item.is_open = true;
  173. else
  174. item.is_open = false;
  175. return item;
  176. });
  177. sortList.value = sortList.value.map((item, index) => {
  178. if (item.type == "0")
  179. item.is_open = true;
  180. else
  181. item.is_open = false;
  182. return item;
  183. });
  184. };
  185. const toChat = (item) => {
  186. var _a2;
  187. common_vendor.index.makePhoneCall({
  188. phoneNumber: (_a2 = item.shop) == null ? void 0 : _a2.tel,
  189. success: function() {
  190. console.log("拨打电话成功");
  191. },
  192. fail: function() {
  193. common_vendor.index.showToast({
  194. title: "拨打电话失败",
  195. icon: "error"
  196. });
  197. }
  198. });
  199. };
  200. const toView = (item) => {
  201. common_vendor.index.navigateTo({
  202. url: `/pagesHome/car/index?id=${item.id || item._id}`
  203. });
  204. };
  205. const toPage = () => {
  206. if (total.value > list.value.length) {
  207. common_vendor.index.showLoading({
  208. title: "加载中",
  209. mask: true
  210. });
  211. page.value = page.value + 1;
  212. skip.value = page.value * limit.value;
  213. search();
  214. common_vendor.index.hideLoading();
  215. } else
  216. is_bottom.value = true;
  217. };
  218. const clearPage = () => {
  219. list.value = [];
  220. skip.value = 0;
  221. limit.value = 6;
  222. page.value = 0;
  223. };
  224. return (_ctx, _cache) => {
  225. return common_vendor.e({
  226. a: common_vendor.o(toChange),
  227. b: common_vendor.p({
  228. shape: "square",
  229. ["show-action"]: false,
  230. placeholder: "请输入车辆的名称或品牌"
  231. }),
  232. c: common_vendor.f(searchList.value, (item, index, i0) => {
  233. return common_vendor.e({
  234. a: common_vendor.t(item.title),
  235. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  236. c: item.is_open == false
  237. }, item.is_open == false ? {
  238. d: "2519f642-1-" + i0,
  239. e: common_vendor.p({
  240. color: "#000",
  241. size: "10px",
  242. name: "arrow-down-fill"
  243. })
  244. } : {
  245. f: "2519f642-2-" + i0,
  246. g: common_vendor.p({
  247. color: "#2979ff",
  248. size: "10px",
  249. name: "arrow-up-fill"
  250. })
  251. }, {
  252. h: index,
  253. i: common_vendor.o(($event) => toSearch(item), index)
  254. });
  255. }),
  256. d: type.value == "0"
  257. }, type.value == "0" ? {
  258. e: common_vendor.f(sortList.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. } : type.value == "2" ? {
  267. g: common_vendor.f(moneyList.value, (item, index, i0) => {
  268. return {
  269. a: common_vendor.t(item.title),
  270. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  271. c: index,
  272. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  273. };
  274. })
  275. } : {}, {
  276. f: type.value == "2",
  277. h: is_show.value,
  278. i: common_vendor.o(toClose),
  279. j: searchInfo.value.brand || searchInfo.value.money || moreList.value.length > 0
  280. }, searchInfo.value.brand || searchInfo.value.money || moreList.value.length > 0 ? common_vendor.e({
  281. k: searchInfo.value && searchInfo.value.brand
  282. }, searchInfo.value && searchInfo.value.brand ? {
  283. l: common_vendor.t(searchInfo.value.brand),
  284. m: common_vendor.p({
  285. color: "#000",
  286. size: "14px",
  287. name: "close"
  288. }),
  289. n: common_vendor.o(($event) => toDelete({}, "0"))
  290. } : {}, {
  291. o: searchInfo.value && searchInfo.value.money
  292. }, searchInfo.value && searchInfo.value.money ? {
  293. p: common_vendor.t(searchInfo.value.money),
  294. q: common_vendor.p({
  295. color: "#000",
  296. size: "14px",
  297. name: "close"
  298. }),
  299. r: common_vendor.o(($event) => toDelete({}, "1"))
  300. } : {}, {
  301. s: moreList.value.length > 0
  302. }, moreList.value.length > 0 ? {
  303. t: common_vendor.f(moreList.value, (item, index, i0) => {
  304. return {
  305. a: common_vendor.t(item.title),
  306. b: "2519f642-5-" + i0,
  307. c: index,
  308. d: common_vendor.o(($event) => toDelete(item, "2"), index)
  309. };
  310. }),
  311. v: common_vendor.p({
  312. color: "#000",
  313. size: "14px",
  314. name: "close"
  315. })
  316. } : {}, {
  317. w: common_vendor.o(toReset)
  318. }) : {}, {
  319. x: common_vendor.f(list.value, (item, index, i0) => {
  320. return common_vendor.e({
  321. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  322. b: common_vendor.t(item.series || "暂无"),
  323. c: common_vendor.t(item.year || "暂无"),
  324. d: common_vendor.t(item.style || "暂无"),
  325. e: item.year
  326. }, item.year ? {
  327. f: common_vendor.t(item.year || "暂无")
  328. } : {}, {
  329. g: item.mileage
  330. }, item.mileage ? {
  331. h: common_vendor.t(item.mileage || "暂无")
  332. } : {}, {
  333. i: item.place
  334. }, item.place ? {
  335. j: common_vendor.t(item.place || "暂无")
  336. } : {}, {
  337. k: common_vendor.t(item.total_money || "0"),
  338. l: common_vendor.o(($event) => toChat(item), index),
  339. m: index,
  340. n: common_vendor.o(($event) => toView(item), index)
  341. });
  342. }),
  343. y: is_bottom.value
  344. }, is_bottom.value ? {
  345. z: common_vendor.t(config.value.bottom_title || "没有更多了!")
  346. } : {}, {
  347. A: common_vendor.o(toPage)
  348. });
  349. };
  350. }
  351. });
  352. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2519f642"], ["__file", "D:/project/赋强公证/notarization_applet/pagesHome/search/index.vue"]]);
  353. wx.createPage(MiniProgramPage);