index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 brandInfo = common_vendor.ref({});
  33. const moneyInfo = common_vendor.ref({});
  34. const yearInfo = common_vendor.ref({});
  35. const moreList = common_vendor.ref([]);
  36. const list = common_vendor.ref([]);
  37. const total = common_vendor.ref(0);
  38. const skip = common_vendor.ref(0);
  39. const limit = common_vendor.ref(6);
  40. const page = common_vendor.ref(0);
  41. const is_bottom = common_vendor.ref(false);
  42. common_vendor.ref(0);
  43. common_vendor.onLoad(async (options) => {
  44. id.value = options && options.id;
  45. common_vendor.index.setNavigationBarTitle({
  46. title: options && options.name || "车行详情"
  47. });
  48. await searchConfig();
  49. await search();
  50. await searchOther();
  51. });
  52. common_vendor.onShow(() => {
  53. common_vendor.index.$on("toRoute", function(data) {
  54. brandInfo.value = data;
  55. });
  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. res = await $api("car", "GET", {
  82. ...info
  83. });
  84. if (res.errcode === 0) {
  85. list.value = list.value.concat(res.data);
  86. total.value = res.total;
  87. shop.value.sale = res.total;
  88. } else {
  89. common_vendor.index.showToast({
  90. title: res.errmsg || "",
  91. icon: "error"
  92. });
  93. }
  94. res = await $api("car", "GET", {
  95. skip: 0,
  96. limit: 1,
  97. status: "1",
  98. shop: id.value
  99. });
  100. if (res.errcode === 0)
  101. shop.value.sold = res.total;
  102. };
  103. const toSearch = (value) => {
  104. searchList.value = searchList.value.map((item, index) => {
  105. if (item.type == value.type && !item.is_open)
  106. item.is_open = true;
  107. else
  108. item.is_open = false;
  109. return item;
  110. });
  111. type.value = value.type;
  112. if (value.type == "1") {
  113. toClose();
  114. common_vendor.index.navigateTo({
  115. url: `/pagesHome/brand/index`
  116. });
  117. } else if (value.type == "4") {
  118. toClose();
  119. common_vendor.index.navigateTo({
  120. url: `/pagesHome/condition/index`
  121. });
  122. } else
  123. is_show.value = searchList.value.some((item) => item.is_open == true);
  124. };
  125. const toClose = () => {
  126. is_show.value = false;
  127. searchList.value = searchList.value.map((item, index) => {
  128. item.is_open = false;
  129. return item;
  130. });
  131. };
  132. const toSelect = (data, type2) => {
  133. if (type2 == "0") {
  134. sortList.value = sortList.value.map((item, index) => {
  135. if (item.type == data.type)
  136. item.is_open = true;
  137. else
  138. item.is_open = false;
  139. return item;
  140. });
  141. searchList.value = searchList.value.map((i, index) => {
  142. if (i.type == "0")
  143. i.title = data.title;
  144. return i;
  145. });
  146. } else if (type2 == "2") {
  147. moneyList.value = moneyList.value.map((item, index) => {
  148. if (item.type == data.type)
  149. item.is_open = true;
  150. else
  151. item.is_open = false;
  152. return item;
  153. });
  154. moneyInfo.value = data;
  155. } else {
  156. yearList.value = yearList.value.map((item, index) => {
  157. if (item.type == data.type)
  158. item.is_open = true;
  159. else
  160. item.is_open = false;
  161. return item;
  162. });
  163. yearInfo.value = data;
  164. }
  165. };
  166. const toDelete = (item, type2) => {
  167. if (type2 == "0")
  168. brandInfo.value = {};
  169. else if (type2 == "1") {
  170. moneyList.value = moneyList.value.map((item2, index) => {
  171. if (item2.type == "0")
  172. item2.is_open = true;
  173. else
  174. item2.is_open = false;
  175. return item2;
  176. });
  177. moneyInfo.value = {};
  178. } else if (type2 == "2") {
  179. yearList.value = yearList.value.map((item2, index) => {
  180. if (item2.type == "0")
  181. item2.is_open = true;
  182. else
  183. item2.is_open = false;
  184. return item2;
  185. });
  186. yearInfo.value = {};
  187. } else
  188. moreList.value = moreList.value.filter((i, index) => i.type != item.type);
  189. };
  190. const toReset = () => {
  191. toDelete({}, "0");
  192. toDelete({}, "1");
  193. toDelete({}, "2");
  194. moreList.value = [];
  195. toClear();
  196. };
  197. const toClear = () => {
  198. searchList.value = searchList.value.map((i, index) => {
  199. if (i.type == "0")
  200. i.title = "默认排序";
  201. return i;
  202. });
  203. sortList.value = sortList.value.map((item, index) => {
  204. if (item.type == "0")
  205. item.is_open = true;
  206. else
  207. item.is_open = false;
  208. return item;
  209. });
  210. };
  211. const toChat = (item) => {
  212. common_vendor.index.makePhoneCall({
  213. phoneNumber: item.shop || "110",
  214. success: function() {
  215. console.log("拨打电话成功");
  216. },
  217. fail: function() {
  218. console.log("拨打电话失败");
  219. }
  220. });
  221. };
  222. const toView = (item) => {
  223. common_vendor.index.navigateTo({
  224. url: `/pagesHome/car/index?id=${item.id || item._id}`
  225. });
  226. };
  227. const toImage = () => {
  228. var _a2;
  229. if (((_a2 = shop.value) == null ? void 0 : _a2.file.length) > 0) {
  230. common_vendor.index.previewImage({
  231. urls: [shop.value.file[0].url],
  232. longPressActions: {
  233. itemList: ["发送给朋友", "保存图片", "收藏"],
  234. success: function(data) {
  235. console.log("选中了第" + (data.tapIndex + 1) + "个按钮,第" + (data.index + 1) + "张图片");
  236. },
  237. fail: function(err) {
  238. console.log(err.errMsg);
  239. }
  240. }
  241. });
  242. }
  243. };
  244. const toPage = () => {
  245. if (total.value > list.value.length) {
  246. common_vendor.index.showLoading({
  247. title: "加载中",
  248. mask: true
  249. });
  250. page.value = page.value + 1;
  251. skip.value = page.value * limit.value;
  252. search();
  253. common_vendor.index.hideLoading();
  254. } else
  255. is_bottom.value = true;
  256. };
  257. return (_ctx, _cache) => {
  258. var _a2;
  259. return common_vendor.e({
  260. 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",
  261. b: common_vendor.t(shop.value.name || "暂无"),
  262. c: common_vendor.t(shop.value.sale || "0"),
  263. d: common_vendor.t(shop.value.sold || "0"),
  264. e: common_vendor.t(shop.value.status == "0" ? "营业中" : "休息中"),
  265. f: common_vendor.t(shop.value.start_time || "8:00"),
  266. g: common_vendor.t(shop.value.end_time || "17:00"),
  267. h: common_vendor.p({
  268. name: "file-text",
  269. size: "16"
  270. }),
  271. i: common_vendor.o(toImage),
  272. j: common_vendor.p({
  273. direction: "col"
  274. }),
  275. k: common_vendor.t(shop.value.address || "暂无"),
  276. l: common_vendor.f(searchList.value, (item, index, i0) => {
  277. return common_vendor.e({
  278. a: common_vendor.t(item.title),
  279. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  280. c: item.is_open == false
  281. }, item.is_open == false ? {
  282. d: "88a3d2e5-2-" + i0,
  283. e: common_vendor.p({
  284. color: "#000",
  285. size: "10px",
  286. name: "arrow-down-fill"
  287. })
  288. } : {
  289. f: "88a3d2e5-3-" + i0,
  290. g: common_vendor.p({
  291. color: "#ffbc00",
  292. size: "10px",
  293. name: "arrow-up-fill"
  294. })
  295. }, {
  296. h: index,
  297. i: common_vendor.o(($event) => toSearch(item), index)
  298. });
  299. }),
  300. m: type.value == "0"
  301. }, type.value == "0" ? {
  302. n: common_vendor.f(sortList.value, (item, index, i0) => {
  303. return {
  304. a: common_vendor.t(item.title),
  305. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  306. c: index,
  307. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  308. };
  309. })
  310. } : type.value == "2" ? {
  311. p: common_vendor.f(moneyList.value, (item, index, i0) => {
  312. return {
  313. a: common_vendor.t(item.title),
  314. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  315. c: index,
  316. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  317. };
  318. })
  319. } : type.value == "3" ? {
  320. r: common_vendor.f(yearList.value, (item, index, i0) => {
  321. return {
  322. a: common_vendor.t(item.title),
  323. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  324. c: index,
  325. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  326. };
  327. })
  328. } : {
  329. s: common_vendor.f(yearList.value, (item, index, i0) => {
  330. return {
  331. a: common_vendor.t(item.title),
  332. b: common_vendor.n(item.is_open == false ? "title_1" : "title_2"),
  333. c: index,
  334. d: common_vendor.o(($event) => toSelect(item, type.value), index)
  335. };
  336. })
  337. }, {
  338. o: type.value == "2",
  339. q: type.value == "3",
  340. t: is_show.value,
  341. v: common_vendor.o(toClose),
  342. w: Object.keys(brandInfo.value).length > 0 || Object.keys(moneyInfo.value).length > 0 || Object.keys(yearInfo.value).length > 0 || moreList.value.length > 0
  343. }, Object.keys(brandInfo.value).length > 0 || Object.keys(moneyInfo.value).length > 0 || Object.keys(yearInfo.value).length > 0 || moreList.value.length > 0 ? common_vendor.e({
  344. x: brandInfo.value && brandInfo.value.type
  345. }, brandInfo.value && brandInfo.value.type ? {
  346. y: common_vendor.t(brandInfo.value.title),
  347. z: common_vendor.p({
  348. color: "#000",
  349. size: "14px",
  350. name: "close"
  351. }),
  352. A: common_vendor.o(($event) => toDelete({}, "0"))
  353. } : {}, {
  354. B: moneyInfo.value && moneyInfo.value.type
  355. }, moneyInfo.value && moneyInfo.value.type ? {
  356. C: common_vendor.t(moneyInfo.value.title),
  357. D: common_vendor.p({
  358. color: "#000",
  359. size: "14px",
  360. name: "close"
  361. }),
  362. E: common_vendor.o(($event) => toDelete({}, "1"))
  363. } : {}, {
  364. F: yearInfo.value && yearInfo.value.type
  365. }, yearInfo.value && yearInfo.value.type ? {
  366. G: common_vendor.t(yearInfo.value.title),
  367. H: common_vendor.p({
  368. color: "#000",
  369. size: "14px",
  370. name: "close"
  371. }),
  372. I: common_vendor.o(($event) => toDelete({}, "2"))
  373. } : {}, {
  374. J: moreList.value.length > 0
  375. }, moreList.value.length > 0 ? {
  376. K: common_vendor.f(moreList.value, (item, index, i0) => {
  377. return {
  378. a: common_vendor.t(item.title),
  379. b: "88a3d2e5-7-" + i0,
  380. c: index,
  381. d: common_vendor.o(($event) => toDelete(item, "3"), index)
  382. };
  383. }),
  384. L: common_vendor.p({
  385. color: "#000",
  386. size: "14px",
  387. name: "close"
  388. })
  389. } : {}, {
  390. M: common_vendor.o(toReset)
  391. }) : {}, {
  392. N: common_vendor.f(list.value, (item, index, i0) => {
  393. return common_vendor.e({
  394. a: item.file && item.file.length > 0 ? item.file[0].url : "",
  395. b: common_vendor.t(item.series || "暂无"),
  396. c: common_vendor.t(item.year || "暂无"),
  397. d: common_vendor.t(item.style || "暂无"),
  398. e: item.year
  399. }, item.year ? {
  400. f: common_vendor.t(item.year || "暂无")
  401. } : {}, {
  402. g: item.mileage
  403. }, item.mileage ? {
  404. h: common_vendor.t(item.mileage || "暂无")
  405. } : {}, {
  406. i: item.place
  407. }, item.place ? {
  408. j: common_vendor.t(item.place || "暂无")
  409. } : {}, {
  410. k: common_vendor.t(item.total_money || "0"),
  411. l: index,
  412. m: common_vendor.o(($event) => toView(item), index)
  413. });
  414. }),
  415. O: is_bottom.value
  416. }, is_bottom.value ? {
  417. P: common_vendor.t(config.value.bottom_title || "没有更多了!")
  418. } : {}, {
  419. Q: common_vendor.o(toPage),
  420. R: common_vendor.o(toChat),
  421. S: common_vendor.p({
  422. icon: "phone",
  423. text: "电话联系",
  424. size: "normal",
  425. type: "info"
  426. })
  427. });
  428. };
  429. }
  430. });
  431. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-88a3d2e5"], ["__file", "D:/project/二手车/car_applet/pagesHome/shop/index.vue"]]);
  432. wx.createPage(MiniProgramPage);