index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. if (!Array) {
  4. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  5. const _easycom_u_line2 = common_vendor.resolveComponent("u-line");
  6. const _easycom_u_button2 = common_vendor.resolveComponent("u-button");
  7. (_easycom_u_icon2 + _easycom_u_line2 + _easycom_u_button2)();
  8. }
  9. const _easycom_u_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
  10. const _easycom_u_line = () => "../../node-modules/uview-plus/components/u-line/u-line.js";
  11. const _easycom_u_button = () => "../../node-modules/uview-plus/components/u-button/u-button.js";
  12. if (!Math) {
  13. (_easycom_u_icon + _easycom_u_line + _easycom_u_button)();
  14. }
  15. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  16. __name: "index",
  17. setup(__props) {
  18. var _a;
  19. const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
  20. common_vendor.computed(() => {
  21. return common_vendor.index.getStorageSync("openid");
  22. });
  23. const config = common_vendor.ref({});
  24. const id = common_vendor.ref("");
  25. const shop = common_vendor.ref({});
  26. const type = common_vendor.ref("0");
  27. const is_show = common_vendor.ref(false);
  28. 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 }, { title: "更多筛选", type: "4", is_open: false }]);
  29. 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 }]);
  30. 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 }]);
  31. const yearList = common_vendor.ref([{ title: "不限车龄", type: "0", is_open: true }, { title: "2年以下", type: "1", is_open: false }, { title: "4年以下", type: "2", is_open: false }, { title: "6年以下", type: "3", is_open: false }]);
  32. const searchInfo = common_vendor.ref({});
  33. const moreList = common_vendor.ref([]);
  34. const list = common_vendor.ref([]);
  35. const total = common_vendor.ref(0);
  36. const skip = common_vendor.ref(0);
  37. const limit = common_vendor.ref(6);
  38. const page = common_vendor.ref(0);
  39. const is_bottom = common_vendor.ref(false);
  40. common_vendor.ref(0);
  41. common_vendor.onLoad(async (options) => {
  42. id.value = options && options.id;
  43. common_vendor.index.setNavigationBarTitle({
  44. title: options && options.name || "车行详情"
  45. });
  46. await searchConfig();
  47. await search();
  48. });
  49. common_vendor.onShow(async () => {
  50. common_vendor.index.$on("toRoute", function(data) {
  51. if (data && data.name)
  52. searchInfo.value.brand = data.name;
  53. });
  54. await clearPage();
  55. await searchOther();
  56. });
  57. const searchConfig = async () => {
  58. config.value = common_vendor.index.getStorageSync("config");
  59. };
  60. const search = async () => {
  61. if (id.value) {
  62. const res = await $api(`shop/${id.value}`, "GET", {});
  63. if (res.errcode === 0) {
  64. shop.value = res.data;
  65. } else {
  66. common_vendor.index.showToast({
  67. title: res.errmsg || "",
  68. icon: "error"
  69. });
  70. }
  71. }
  72. };
  73. const searchOther = async () => {
  74. let res;
  75. const info = {
  76. skip: skip.value,
  77. limit: limit.value,
  78. status: "0",
  79. shop: id.value
  80. };
  81. if (searchInfo.value.brand)
  82. info.brand = searchInfo.value.brand;
  83. if (searchInfo.value.money)
  84. info.money = searchInfo.value.money;
  85. if (searchInfo.value.year)
  86. info.year = searchInfo.value.year;
  87. res = await $api("car", "GET", {
  88. ...info
  89. });
  90. if (res.errcode === 0) {
  91. list.value = list.value.concat(res.data);
  92. total.value = res.total;
  93. shop.value.sale = res.total;
  94. } else {
  95. common_vendor.index.showToast({
  96. title: res.errmsg || "",
  97. icon: "error"
  98. });
  99. }
  100. res = await $api("car", "GET", {
  101. skip: 0,
  102. limit: 1,
  103. status: "0",
  104. shop: id.value
  105. });
  106. if (res.errcode === 0)
  107. shop.value.sold = res.total;
  108. };
  109. const toSearch = (value) => {
  110. searchList.value = searchList.value.map((item, index) => {
  111. if (item.type == value.type && !item.is_open)
  112. item.is_open = true;
  113. else
  114. item.is_open = false;
  115. return item;
  116. });
  117. type.value = value.type;
  118. if (value.type == "1") {
  119. toClose();
  120. common_vendor.index.navigateTo({
  121. url: `/pagesHome/brand/index`
  122. });
  123. } else if (value.type == "4") {
  124. toClose();
  125. common_vendor.index.navigateTo({
  126. url: `/pagesHome/condition/index`
  127. });
  128. } else
  129. is_show.value = searchList.value.some((item) => item.is_open == true);
  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 = async (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 if (type2 == "2") {
  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. if (data.type != "0")
  161. searchInfo.value.money = data.title;
  162. else
  163. searchInfo.value.money = "";
  164. } else {
  165. yearList.value = yearList.value.map((item, index) => {
  166. if (item.type == data.type)
  167. item.is_open = true;
  168. else
  169. item.is_open = false;
  170. return item;
  171. });
  172. if (data.type != "0")
  173. searchInfo.value.year = data.title;
  174. else
  175. searchInfo.value.year = "";
  176. }
  177. await clearPage();
  178. await searchOther();
  179. };
  180. const toDelete = async (item, type2) => {
  181. if (type2 == "0")
  182. searchInfo.value.brand = "";
  183. else if (type2 == "1") {
  184. moneyList.value = moneyList.value.map((item2, index) => {
  185. if (item2.type == "0")
  186. item2.is_open = true;
  187. else
  188. item2.is_open = false;
  189. return item2;
  190. });
  191. searchInfo.value.money = "";
  192. } else if (type2 == "2") {
  193. yearList.value = yearList.value.map((item2, index) => {
  194. if (item2.type == "0")
  195. item2.is_open = true;
  196. else
  197. item2.is_open = false;
  198. return item2;
  199. });
  200. searchInfo.value.year = "";
  201. } else
  202. moreList.value = moreList.value.filter((i, index) => i.type != item.type);
  203. await clearPage();
  204. await searchOther();
  205. };
  206. const toReset = async () => {
  207. toDelete({}, "0");
  208. toDelete({}, "1");
  209. toDelete({}, "2");
  210. moreList.value = [];
  211. toClear();
  212. await clearPage();
  213. await searchOther();
  214. };
  215. const toClear = () => {
  216. searchList.value = searchList.value.map((i, index) => {
  217. if (i.type == "0")
  218. i.title = "默认排序";
  219. return i;
  220. });
  221. sortList.value = sortList.value.map((item, index) => {
  222. if (item.type == "0")
  223. item.is_open = true;
  224. else
  225. item.is_open = false;
  226. return item;
  227. });
  228. };
  229. const toChat = () => {
  230. var _a2;
  231. common_vendor.index.makePhoneCall({
  232. phoneNumber: (_a2 = shop.value) == null ? void 0 : _a2.tel,
  233. success: function() {
  234. console.log("拨打电话成功");
  235. },
  236. fail: function() {
  237. common_vendor.index.showToast({
  238. title: "拨打电话失败",
  239. icon: "error"
  240. });
  241. }
  242. });
  243. };
  244. const toView = (item) => {
  245. common_vendor.index.navigateTo({
  246. url: `/pagesHome/car/index?id=${item.id || item._id}`
  247. });
  248. };
  249. const toImage = () => {
  250. var _a2;
  251. if (((_a2 = shop.value) == null ? void 0 : _a2.file.length) > 0) {
  252. common_vendor.index.previewImage({
  253. urls: [shop.value.file[0].url],
  254. longPressActions: {
  255. itemList: ["发送给朋友", "保存图片", "收藏"],
  256. success: function(data) {
  257. console.log("选中了第" + (data.tapIndex + 1) + "个按钮,第" + (data.index + 1) + "张图片");
  258. },
  259. fail: function(err) {
  260. console.log(err.errMsg);
  261. }
  262. }
  263. });
  264. }
  265. };
  266. const toPage = () => {
  267. if (total.value > list.value.length) {
  268. common_vendor.index.showLoading({
  269. title: "加载中",
  270. mask: true
  271. });
  272. page.value = page.value + 1;
  273. skip.value = page.value * limit.value;
  274. search();
  275. common_vendor.index.hideLoading();
  276. } else
  277. is_bottom.value = true;
  278. };
  279. const clearPage = () => {
  280. list.value = [];
  281. skip.value = 0;
  282. limit.value = 6;
  283. page.value = 0;
  284. };
  285. return (_ctx, _cache) => {
  286. var _a2;
  287. return common_vendor.e({
  288. a: shop.value.logo && ((_a2 = shop.value.logo) == null ? void 0 : _a2.length) > 0 ? shop.value.logo[0].url : "https://cdn.uviewui.com/uview/album/1.jpg",
  289. b: common_vendor.t(shop.value.name || "暂无"),
  290. c: common_vendor.t(shop.value.sale || "0"),
  291. d: common_vendor.t(shop.value.sold || "0"),
  292. e: common_vendor.t(shop.value.status == "0" ? "营业中" : "休息中"),
  293. f: common_vendor.t(shop.value.start_time || "8:00"),
  294. g: common_vendor.t(shop.value.end_time || "17:00"),
  295. h: common_vendor.p({
  296. name: "file-text",
  297. size: "16"
  298. }),
  299. i: common_vendor.o(toImage),
  300. j: common_vendor.p({
  301. direction: "col"
  302. }),
  303. k: common_vendor.t(shop.value.address || "暂无"),
  304. l: common_vendor.f(searchList.value, (item, index, i0) => {
  305. return common_vendor.e({
  306. a: common_vendor.t(item.title),
  307. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  308. c: item.is_open == false
  309. }, item.is_open == false ? {
  310. d: "88a3d2e5-2-" + i0,
  311. e: common_vendor.p({
  312. color: "#000",
  313. size: "10px",
  314. name: "arrow-down-fill"
  315. })
  316. } : {
  317. f: "88a3d2e5-3-" + i0,
  318. g: common_vendor.p({
  319. color: "#ffbc00",
  320. size: "10px",
  321. name: "arrow-up-fill"
  322. })
  323. }, {
  324. h: index,
  325. i: common_vendor.o(($event) => toSearch(item), index)
  326. });
  327. }),
  328. m: type.value == "0"
  329. }, type.value == "0" ? {
  330. n: common_vendor.f(sortList.value, (item, index, i0) => {
  331. return {
  332. a: common_vendor.t(item.title),
  333. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  334. c: index,
  335. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  336. };
  337. })
  338. } : type.value == "2" ? {
  339. p: common_vendor.f(moneyList.value, (item, index, i0) => {
  340. return {
  341. a: common_vendor.t(item.title),
  342. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  343. c: index,
  344. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  345. };
  346. })
  347. } : type.value == "3" ? {
  348. r: common_vendor.f(yearList.value, (item, index, i0) => {
  349. return {
  350. a: common_vendor.t(item.title),
  351. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  352. c: index,
  353. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  354. };
  355. })
  356. } : {
  357. s: common_vendor.f(yearList.value, (item, index, i0) => {
  358. return {
  359. a: common_vendor.t(item.title),
  360. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  361. c: index,
  362. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  363. };
  364. })
  365. }, {
  366. o: type.value == "2",
  367. q: type.value == "3",
  368. t: is_show.value,
  369. v: common_vendor.o(toClose),
  370. w: searchInfo.value.brand || searchInfo.value.money || moreList.value.length > 0
  371. }, searchInfo.value.brand || searchInfo.value.money || moreList.value.length > 0 ? common_vendor.e({
  372. x: searchInfo.value && searchInfo.value.brand
  373. }, searchInfo.value && searchInfo.value.brand ? {
  374. y: common_vendor.t(searchInfo.value.brand),
  375. z: common_vendor.p({
  376. color: "#000",
  377. size: "14px",
  378. name: "close"
  379. }),
  380. A: common_vendor.o(($event) => toDelete({}, "0"))
  381. } : {}, {
  382. B: searchInfo.value && searchInfo.value.money
  383. }, searchInfo.value && searchInfo.value.money ? {
  384. C: common_vendor.t(searchInfo.value.money),
  385. D: common_vendor.p({
  386. color: "#000",
  387. size: "14px",
  388. name: "close"
  389. }),
  390. E: common_vendor.o(($event) => toDelete({}, "1"))
  391. } : {}, {
  392. F: searchInfo.value && searchInfo.value.year
  393. }, searchInfo.value && searchInfo.value.year ? {
  394. G: common_vendor.t(searchInfo.value.year),
  395. H: common_vendor.p({
  396. color: "#000",
  397. size: "14px",
  398. name: "close"
  399. }),
  400. I: common_vendor.o(($event) => toDelete({}, "2"))
  401. } : {}, {
  402. J: moreList.value.length > 0
  403. }, moreList.value.length > 0 ? {
  404. K: common_vendor.f(moreList.value, (item, index, i0) => {
  405. return {
  406. a: common_vendor.t(item.title),
  407. b: "88a3d2e5-7-" + i0,
  408. c: index,
  409. d: common_vendor.o(($event) => toDelete(item, "3"), index)
  410. };
  411. }),
  412. L: common_vendor.p({
  413. color: "#000",
  414. size: "14px",
  415. name: "close"
  416. })
  417. } : {}, {
  418. M: common_vendor.o(toReset)
  419. }) : {}, {
  420. N: common_vendor.f(list.value, (item, index, i0) => {
  421. return common_vendor.e({
  422. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  423. b: common_vendor.t(item.series || "暂无"),
  424. c: common_vendor.t(item.year || "暂无"),
  425. d: common_vendor.t(item.style || "暂无"),
  426. e: item.year
  427. }, item.year ? {
  428. f: common_vendor.t(item.year || "暂无")
  429. } : {}, {
  430. g: item.mileage
  431. }, item.mileage ? {
  432. h: common_vendor.t(item.mileage || "暂无")
  433. } : {}, {
  434. i: item.place
  435. }, item.place ? {
  436. j: common_vendor.t(item.place || "暂无")
  437. } : {}, {
  438. k: common_vendor.t(item.total_money || "0"),
  439. l: index,
  440. m: common_vendor.o(($event) => toView(item), index)
  441. });
  442. }),
  443. O: is_bottom.value
  444. }, is_bottom.value ? {
  445. P: common_vendor.t(config.value.bottom_title || "没有更多了!")
  446. } : {}, {
  447. Q: common_vendor.o(toPage),
  448. R: common_vendor.o(toChat),
  449. S: common_vendor.p({
  450. icon: "phone",
  451. text: "电话联系",
  452. size: "normal",
  453. type: "info"
  454. })
  455. });
  456. };
  457. }
  458. });
  459. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-88a3d2e5"], ["__file", "D:/project/二手车/car_applet/pagesHome/shop/index.vue"]]);
  460. wx.createPage(MiniProgramPage);