index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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: "1",
  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. searchInfo.value.money = data.title;
  161. } else {
  162. yearList.value = yearList.value.map((item, index) => {
  163. if (item.type == data.type)
  164. item.is_open = true;
  165. else
  166. item.is_open = false;
  167. return item;
  168. });
  169. searchInfo.value.year = data.title;
  170. }
  171. await clearPage();
  172. await searchOther();
  173. };
  174. const toDelete = async (item, type2) => {
  175. if (type2 == "0")
  176. searchInfo.value.brand = "";
  177. else if (type2 == "1") {
  178. moneyList.value = moneyList.value.map((item2, index) => {
  179. if (item2.type == "0")
  180. item2.is_open = true;
  181. else
  182. item2.is_open = false;
  183. return item2;
  184. });
  185. searchInfo.value.money = "";
  186. } else if (type2 == "2") {
  187. yearList.value = yearList.value.map((item2, index) => {
  188. if (item2.type == "0")
  189. item2.is_open = true;
  190. else
  191. item2.is_open = false;
  192. return item2;
  193. });
  194. searchInfo.value.year = "";
  195. } else
  196. moreList.value = moreList.value.filter((i, index) => i.type != item.type);
  197. await clearPage();
  198. await searchOther();
  199. };
  200. const toReset = async () => {
  201. toDelete({}, "0");
  202. toDelete({}, "1");
  203. toDelete({}, "2");
  204. moreList.value = [];
  205. toClear();
  206. await clearPage();
  207. await searchOther();
  208. };
  209. const toClear = () => {
  210. searchList.value = searchList.value.map((i, index) => {
  211. if (i.type == "0")
  212. i.title = "默认排序";
  213. return i;
  214. });
  215. sortList.value = sortList.value.map((item, index) => {
  216. if (item.type == "0")
  217. item.is_open = true;
  218. else
  219. item.is_open = false;
  220. return item;
  221. });
  222. };
  223. const toChat = () => {
  224. var _a2;
  225. common_vendor.index.makePhoneCall({
  226. phoneNumber: (_a2 = shop.value) == null ? void 0 : _a2.tel,
  227. success: function() {
  228. console.log("拨打电话成功");
  229. },
  230. fail: function() {
  231. common_vendor.index.showToast({
  232. title: "拨打电话失败",
  233. icon: "error"
  234. });
  235. }
  236. });
  237. };
  238. const toView = (item) => {
  239. common_vendor.index.navigateTo({
  240. url: `/pagesHome/car/index?id=${item.id || item._id}`
  241. });
  242. };
  243. const toImage = () => {
  244. var _a2;
  245. if (((_a2 = shop.value) == null ? void 0 : _a2.file.length) > 0) {
  246. common_vendor.index.previewImage({
  247. urls: [shop.value.file[0].url],
  248. longPressActions: {
  249. itemList: ["发送给朋友", "保存图片", "收藏"],
  250. success: function(data) {
  251. console.log("选中了第" + (data.tapIndex + 1) + "个按钮,第" + (data.index + 1) + "张图片");
  252. },
  253. fail: function(err) {
  254. console.log(err.errMsg);
  255. }
  256. }
  257. });
  258. }
  259. };
  260. const toPage = () => {
  261. if (total.value > list.value.length) {
  262. common_vendor.index.showLoading({
  263. title: "加载中",
  264. mask: true
  265. });
  266. page.value = page.value + 1;
  267. skip.value = page.value * limit.value;
  268. search();
  269. common_vendor.index.hideLoading();
  270. } else
  271. is_bottom.value = true;
  272. };
  273. const clearPage = () => {
  274. list.value = [];
  275. skip.value = 0;
  276. limit.value = 6;
  277. page.value = 0;
  278. };
  279. return (_ctx, _cache) => {
  280. var _a2;
  281. return common_vendor.e({
  282. 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",
  283. b: common_vendor.t(shop.value.name || "暂无"),
  284. c: common_vendor.t(shop.value.sale || "0"),
  285. d: common_vendor.t(shop.value.sold || "0"),
  286. e: common_vendor.t(shop.value.status == "0" ? "营业中" : "休息中"),
  287. f: common_vendor.t(shop.value.start_time || "8:00"),
  288. g: common_vendor.t(shop.value.end_time || "17:00"),
  289. h: common_vendor.p({
  290. name: "file-text",
  291. size: "16"
  292. }),
  293. i: common_vendor.o(toImage),
  294. j: common_vendor.p({
  295. direction: "col"
  296. }),
  297. k: common_vendor.t(shop.value.address || "暂无"),
  298. l: common_vendor.f(searchList.value, (item, index, i0) => {
  299. return common_vendor.e({
  300. a: common_vendor.t(item.title),
  301. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  302. c: item.is_open == false
  303. }, item.is_open == false ? {
  304. d: "88a3d2e5-2-" + i0,
  305. e: common_vendor.p({
  306. color: "#000",
  307. size: "10px",
  308. name: "arrow-down-fill"
  309. })
  310. } : {
  311. f: "88a3d2e5-3-" + i0,
  312. g: common_vendor.p({
  313. color: "#ffbc00",
  314. size: "10px",
  315. name: "arrow-up-fill"
  316. })
  317. }, {
  318. h: index,
  319. i: common_vendor.o(($event) => toSearch(item), index)
  320. });
  321. }),
  322. m: type.value == "0"
  323. }, type.value == "0" ? {
  324. n: common_vendor.f(sortList.value, (item, index, i0) => {
  325. return {
  326. a: common_vendor.t(item.title),
  327. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  328. c: index,
  329. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  330. };
  331. })
  332. } : type.value == "2" ? {
  333. p: common_vendor.f(moneyList.value, (item, index, i0) => {
  334. return {
  335. a: common_vendor.t(item.title),
  336. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  337. c: index,
  338. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  339. };
  340. })
  341. } : type.value == "3" ? {
  342. r: common_vendor.f(yearList.value, (item, index, i0) => {
  343. return {
  344. a: common_vendor.t(item.title),
  345. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  346. c: index,
  347. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  348. };
  349. })
  350. } : {
  351. s: common_vendor.f(yearList.value, (item, index, i0) => {
  352. return {
  353. a: common_vendor.t(item.title),
  354. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  355. c: index,
  356. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  357. };
  358. })
  359. }, {
  360. o: type.value == "2",
  361. q: type.value == "3",
  362. t: is_show.value,
  363. v: common_vendor.o(toClose),
  364. w: searchInfo.value.brand || searchInfo.value.money || moreList.value.length > 0
  365. }, searchInfo.value.brand || searchInfo.value.money || moreList.value.length > 0 ? common_vendor.e({
  366. x: searchInfo.value && searchInfo.value.brand
  367. }, searchInfo.value && searchInfo.value.brand ? {
  368. y: common_vendor.t(searchInfo.value.brand),
  369. z: common_vendor.p({
  370. color: "#000",
  371. size: "14px",
  372. name: "close"
  373. }),
  374. A: common_vendor.o(($event) => toDelete({}, "0"))
  375. } : {}, {
  376. B: searchInfo.value && searchInfo.value.money
  377. }, searchInfo.value && searchInfo.value.money ? {
  378. C: common_vendor.t(searchInfo.value.money),
  379. D: common_vendor.p({
  380. color: "#000",
  381. size: "14px",
  382. name: "close"
  383. }),
  384. E: common_vendor.o(($event) => toDelete({}, "1"))
  385. } : {}, {
  386. F: searchInfo.value && searchInfo.value.year
  387. }, searchInfo.value && searchInfo.value.year ? {
  388. G: common_vendor.t(searchInfo.value.year),
  389. H: common_vendor.p({
  390. color: "#000",
  391. size: "14px",
  392. name: "close"
  393. }),
  394. I: common_vendor.o(($event) => toDelete({}, "2"))
  395. } : {}, {
  396. J: moreList.value.length > 0
  397. }, moreList.value.length > 0 ? {
  398. K: common_vendor.f(moreList.value, (item, index, i0) => {
  399. return {
  400. a: common_vendor.t(item.title),
  401. b: "88a3d2e5-7-" + i0,
  402. c: index,
  403. d: common_vendor.o(($event) => toDelete(item, "3"), index)
  404. };
  405. }),
  406. L: common_vendor.p({
  407. color: "#000",
  408. size: "14px",
  409. name: "close"
  410. })
  411. } : {}, {
  412. M: common_vendor.o(toReset)
  413. }) : {}, {
  414. N: common_vendor.f(list.value, (item, index, i0) => {
  415. return common_vendor.e({
  416. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  417. b: common_vendor.t(item.series || "暂无"),
  418. c: common_vendor.t(item.year || "暂无"),
  419. d: common_vendor.t(item.style || "暂无"),
  420. e: item.year
  421. }, item.year ? {
  422. f: common_vendor.t(item.year || "暂无")
  423. } : {}, {
  424. g: item.mileage
  425. }, item.mileage ? {
  426. h: common_vendor.t(item.mileage || "暂无")
  427. } : {}, {
  428. i: item.place
  429. }, item.place ? {
  430. j: common_vendor.t(item.place || "暂无")
  431. } : {}, {
  432. k: common_vendor.t(item.total_money || "0"),
  433. l: index,
  434. m: common_vendor.o(($event) => toView(item), index)
  435. });
  436. }),
  437. O: is_bottom.value
  438. }, is_bottom.value ? {
  439. P: common_vendor.t(config.value.bottom_title || "没有更多了!")
  440. } : {}, {
  441. Q: common_vendor.o(toPage),
  442. R: common_vendor.o(toChat),
  443. S: common_vendor.p({
  444. icon: "phone",
  445. text: "电话联系",
  446. size: "normal",
  447. type: "info"
  448. })
  449. });
  450. };
  451. }
  452. });
  453. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-88a3d2e5"], ["__file", "D:/project/二手车/car_applet/pagesHome/shop/index.vue"]]);
  454. wx.createPage(MiniProgramPage);