index.js 16 KB

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