shareUndefined.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <meta name="format-detection" content="telephone=no">
  7. <title>U店在哪</title>
  8. <style>
  9. :root {
  10. --orange: #F58220;
  11. --orange-light: #FFF4E8;
  12. --red: #FF4D4F;
  13. --text: #333333;
  14. --text-secondary: #999999;
  15. --border: #EEEEEE;
  16. --bg: #FFFFFF;
  17. --safe-bottom: env(safe-area-inset-bottom, 0px);
  18. }
  19. * {
  20. margin: 0;
  21. padding: 0;
  22. box-sizing: border-box;
  23. }
  24. html {
  25. font-size: 16px;
  26. -webkit-tap-highlight-color: transparent;
  27. overflow-x: hidden;
  28. }
  29. body {
  30. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  31. background: var(--bg);
  32. color: var(--text);
  33. padding-bottom: calc(88px + var(--safe-bottom));
  34. min-height: 100vh;
  35. overflow-x: hidden;
  36. }
  37. /* Header */
  38. .header {
  39. position: sticky;
  40. top: 0;
  41. z-index: 100;
  42. display: flex;
  43. align-items: center;
  44. justify-content: center;
  45. height: 44px;
  46. padding: 0 15px;
  47. background: var(--bg);
  48. border-bottom: 1px solid var(--border);
  49. }
  50. .header__back {
  51. position: absolute;
  52. left: 15px;
  53. width: 24px;
  54. height: 24px;
  55. display: flex;
  56. align-items: center;
  57. justify-content: center;
  58. color: var(--text);
  59. text-decoration: none;
  60. }
  61. .header__title {
  62. font-size: 17px;
  63. font-weight: 600;
  64. color: var(--text);
  65. }
  66. /* Hero carousel */
  67. .hero {
  68. position: relative;
  69. margin: 0 15px;
  70. margin-top: 10px;
  71. border-radius: 0 0 12px 12px;
  72. overflow: hidden;
  73. }
  74. /* 内容不存在 / 已删除:居中插图 + 说明文案 */
  75. .hero.hero--empty {
  76. display: flex;
  77. flex-direction: column;
  78. align-items: center;
  79. justify-content: center;
  80. padding: 48px 24px 56px;
  81. min-height: min(52vh, 440px);
  82. background: var(--bg);
  83. overflow: visible;
  84. }
  85. .hero--empty__illustration {
  86. display: block;
  87. width: 100%;
  88. max-width: 280px;
  89. height: auto;
  90. object-fit: contain;
  91. }
  92. .hero--empty__tip {
  93. padding: 0 16px;
  94. font-size: 15px;
  95. line-height: 1.5;
  96. color: var(--text-secondary);
  97. text-align: center;
  98. font-weight: 400;
  99. }
  100. .hero__track {
  101. display: flex;
  102. transition: transform 0.35s ease;
  103. }
  104. .hero__slide {
  105. flex: 0 0 100%;
  106. aspect-ratio: 16 / 10;
  107. background: #f0f0f0;
  108. }
  109. .hero__slide img {
  110. width: 100%;
  111. height: 100%;
  112. object-fit: cover;
  113. display: block;
  114. vertical-align: middle;
  115. }
  116. .hero__dots {
  117. position: absolute;
  118. bottom: 12px;
  119. left: 0;
  120. right: 0;
  121. display: flex;
  122. justify-content: center;
  123. align-items: center;
  124. gap: 6px;
  125. }
  126. .hero__dot {
  127. width: 6px;
  128. height: 6px;
  129. border-radius: 3px;
  130. background: rgba(255, 255, 255, 0.45);
  131. transition: width 0.25s ease, background 0.25s ease;
  132. }
  133. .hero__dot.is-active {
  134. width: 16px;
  135. background: #fff;
  136. }
  137. /* Store block */
  138. .section {
  139. padding: 16px 15px 0;
  140. }
  141. .store-name {
  142. font-size: 20px;
  143. font-weight: 700;
  144. line-height: 1.35;
  145. margin-bottom: 12px;
  146. }
  147. .row {
  148. display: flex;
  149. align-items: center;
  150. justify-content: space-between;
  151. gap: 10px;
  152. }
  153. .rating-row {
  154. margin-bottom: 12px;
  155. }
  156. .stars {
  157. display: inline-flex;
  158. align-items: center;
  159. gap: 2px;
  160. }
  161. .star {
  162. width: 14px;
  163. height: 14px;
  164. color: var(--orange);
  165. }
  166. .rating-num {
  167. margin-left: 6px;
  168. font-size: 14px;
  169. font-weight: 600;
  170. color: var(--orange);
  171. }
  172. .link-muted {
  173. display: inline-flex;
  174. align-items: center;
  175. gap: 2px;
  176. font-size: 13px;
  177. color: var(--text-secondary);
  178. text-decoration: none;
  179. }
  180. .chevron {
  181. width: 14px;
  182. height: 14px;
  183. opacity: 0.6;
  184. }
  185. .hours-row {
  186. margin-bottom: 16px;
  187. align-items: flex-start;
  188. }
  189. .hours-left {
  190. flex: 1;
  191. min-width: 0;
  192. }
  193. .status {
  194. font-size: 14px;
  195. color: var(--red);
  196. margin-right: 8px;
  197. }
  198. .status.is-open {
  199. color: var(--orange);
  200. }
  201. .hours-text {
  202. font-size: 14px;
  203. color: var(--text-secondary);
  204. }
  205. .divider {
  206. height: 8px;
  207. background: #F7F7F7;
  208. margin: 0;
  209. }
  210. /* Location */
  211. .loc-wrap {
  212. display: flex;
  213. padding: 16px 15px;
  214. gap: 12px;
  215. }
  216. .loc-main {
  217. flex: 1;
  218. min-width: 0;
  219. padding-right: 12px;
  220. }
  221. .addr {
  222. font-size: 15px;
  223. font-weight: 600;
  224. line-height: 1.45;
  225. margin-bottom: 10px;
  226. }
  227. .meta-line {
  228. display: flex;
  229. align-items: flex-start;
  230. gap: 6px;
  231. font-size: 13px;
  232. color: var(--text-secondary);
  233. line-height: 1.45;
  234. margin-top: 6px;
  235. }
  236. .meta-line svg {
  237. flex-shrink: 0;
  238. margin-top: 2px;
  239. opacity: 0.75;
  240. }
  241. .loc-actions {
  242. display: flex;
  243. flex-direction: row;
  244. align-items: center;
  245. justify-content: center;
  246. gap: 18px;
  247. flex-shrink: 0;
  248. }
  249. .act-btn {
  250. display: flex;
  251. flex-direction: column;
  252. align-items: center;
  253. gap: 4px;
  254. background: none;
  255. border: none;
  256. padding: 0;
  257. cursor: pointer;
  258. font-size: 12px;
  259. color: var(--text);
  260. }
  261. .act-btn__icon {
  262. width: 44px;
  263. height: 44px;
  264. border-radius: 50%;
  265. background: #F5F5F5;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. color: var(--orange);
  270. }
  271. /* More */
  272. .more-title {
  273. padding: 8px 15px 12px;
  274. font-size: 16px;
  275. font-weight: 700;
  276. }
  277. .more-scroll {
  278. display: grid;
  279. grid-template-columns: repeat(2, 1fr);
  280. gap: 10px;
  281. padding: 0 15px 20px;
  282. }
  283. #recEmpty {
  284. grid-column: 1 / -1;
  285. }
  286. .rec-card {
  287. min-width: 0;
  288. background: #fff;
  289. border-radius: 8px;
  290. overflow: hidden;
  291. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  292. }
  293. .rec-card__img {
  294. aspect-ratio: 4 / 3;
  295. background: #eee;
  296. }
  297. .rec-card__img img {
  298. width: 100%;
  299. height: 100%;
  300. object-fit: cover;
  301. }
  302. .rec-card__body {
  303. padding: 10px;
  304. }
  305. .rec-card__top {
  306. display: flex;
  307. justify-content: space-between;
  308. align-items: baseline;
  309. gap: 8px;
  310. margin-bottom: 6px;
  311. }
  312. .rec-card__name {
  313. font-size: 15px;
  314. font-weight: 700;
  315. flex: 1;
  316. min-width: 0;
  317. overflow: hidden;
  318. text-overflow: ellipsis;
  319. white-space: nowrap;
  320. }
  321. .rec-card__dist {
  322. font-size: 12px;
  323. color: var(--text-secondary);
  324. flex-shrink: 0;
  325. }
  326. .rec-card__rating {
  327. display: flex;
  328. align-items: center;
  329. flex-wrap: wrap;
  330. gap: 4px 8px;
  331. }
  332. .rec-card__rating .stars .star {
  333. width: 11px;
  334. height: 11px;
  335. }
  336. .rec-card__rating .rating-num {
  337. font-size: 12px;
  338. }
  339. .rec-meta {
  340. font-size: 12px;
  341. color: var(--text-secondary);
  342. }
  343. .rec-card__seller {
  344. display: flex;
  345. align-items: center;
  346. gap: 8px;
  347. margin-top: 8px;
  348. min-width: 0;
  349. }
  350. .rec-card__avatar {
  351. width: 22px;
  352. height: 22px;
  353. border-radius: 50%;
  354. object-fit: cover;
  355. flex-shrink: 0;
  356. background: #eee;
  357. }
  358. .rec-card__seller-name {
  359. font-size: 12px;
  360. color: var(--text-secondary);
  361. overflow: hidden;
  362. text-overflow: ellipsis;
  363. white-space: nowrap;
  364. }
  365. /* FAB */
  366. .fab-wrap {
  367. position: fixed;
  368. left: 0;
  369. right: 0;
  370. bottom: 0;
  371. z-index: 200;
  372. padding: 12px 24px calc(12px + var(--safe-bottom));
  373. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  374. pointer-events: none;
  375. }
  376. .fab-wrap .fab {
  377. pointer-events: auto;
  378. }
  379. .fab {
  380. display: flex;
  381. align-items: center;
  382. justify-content: center;
  383. gap: 10px;
  384. width: 100%;
  385. max-width: 320px;
  386. margin: 0 auto;
  387. height: 48px;
  388. border: none;
  389. border-radius: 24px;
  390. background: var(--orange);
  391. color: #fff;
  392. font-size: 16px;
  393. font-weight: 600;
  394. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  395. cursor: pointer;
  396. }
  397. .fab__logo {
  398. width: 28px;
  399. height: 28px;
  400. flex-shrink: 0;
  401. }
  402. .home-indicator {
  403. height: 5px;
  404. background: #000;
  405. border-radius: 3px;
  406. width: 134px;
  407. margin: 8px auto 4px;
  408. opacity: 0.2;
  409. }
  410. </style>
  411. </head>
  412. <body>
  413. <div class="hero hero--empty" id="hero" role="status" aria-live="polite">
  414. <img class="hero--empty__illustration" src="images/empty.png" alt="" decoding="async">
  415. <p class="hero--empty__tip">内容已删除/下架/卖出</p>
  416. </div>
  417. <div class="divider"></div>
  418. <h3 class="more-title">更多推荐</h3>
  419. <div class="more-scroll" id="recList">
  420. <p id="recEmpty" style="padding:12px;color:#999;font-size:14px;display:none;">暂无推荐</p>
  421. </div>
  422. <div class="fab-wrap">
  423. <button type="button" class="fab" id="openApp">
  424. <img src="images/ubtn.png" alt="APP内打开" decoding="async">
  425. </button>
  426. <div class="home-indicator" aria-hidden="true"></div>
  427. </div>
  428. <script>
  429. (function () {
  430. 'use strict';
  431. /**
  432. * 更多推荐:POST http://124.93.18.180:9100/ai/life-manager/api/v1/second_hand/global-recommend
  433. * 常用 query:userId、userLat/userLng 或 lat/weidu、lon/jingdu、radiusKm、page、pageSize、categoryOneId、categoryTwoId
  434. *
  435. * 商品已卖出 / 下架 / 删除(secondShareGoods 跳转时带 goodsUnavailable=1 或 goodsStatus=2|4|5):
  436. * 点「APP内打开」深链为 shopro://pages/index/login?…(与 shareIndex.html 关店 businessStatus=99 一致)。
  437. *
  438. * 注意:用 file:// 打开本页时,浏览器可能因 CORS 拦截跨域请求。
  439. */
  440. var API_BASE = 'http://120.26.186.130:8000/alienStore';
  441. var API_LIFE_AI_BASE = 'http://124.93.18.180:9100';
  442. var SECOND_GLOBAL_RECOMMEND_PATH = '/ai/life-manager/api/v1/second_hand/global-recommend';
  443. var DEFAULT_REC_USER_LAT = 38.925756;
  444. var DEFAULT_REC_USER_LNG = 121.662543;
  445. var DEFAULT_REC_RADIUS_KM = 195.69;
  446. /**
  447. * 与 secondShareGoods.html 一致:唤起 App 打开二手商品详情页(合并 search + hash 内 query)
  448. */
  449. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  450. var APP_IOS_URL_SCHEME = 'shopro://';
  451. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  452. function showDownloadTip() {
  453. var msg = '请到应用商店下载';
  454. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  455. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  456. } else {
  457. window.alert(msg);
  458. }
  459. }
  460. function mergeSearchAndHashParams() {
  461. var params = new URLSearchParams();
  462. function ingest(querySlice) {
  463. if (!querySlice) return;
  464. var p = new URLSearchParams(querySlice);
  465. p.forEach(function (val, key) {
  466. params.append(key, val);
  467. });
  468. }
  469. if (location.search && location.search.length > 1) {
  470. ingest(location.search.slice(1));
  471. }
  472. var hash = location.hash || '';
  473. var qi = hash.indexOf('?');
  474. if (qi >= 0) {
  475. ingest(hash.slice(qi + 1));
  476. }
  477. return params;
  478. }
  479. /**
  480. * 二手商品不可用(已卖出 / 下架 / 删除):URL(含 hash)带 goodsUnavailable=1 或 goodsStatus 为 2、4、5;
  481. * businessStatus=99 与 shareIndex 关店唤起登录一致。
  482. */
  483. function isSecondGoodsUnavailableForAppOpen() {
  484. function checkGoodsUnavailableParam(raw) {
  485. var s = String(raw == null ? '' : raw).trim().toLowerCase();
  486. return s === '1' || s === 'true' || s === 'yes';
  487. }
  488. function checkGoodsStatusParam(raw) {
  489. var s = String(raw == null ? '' : raw).trim();
  490. if (s === '2' || s === '4' || s === '5') return true;
  491. var n = Number(s);
  492. return !isNaN(n) && (n === 2 || n === 4 || n === 5);
  493. }
  494. function checkBusiness99(raw) {
  495. var s = String(raw == null ? '' : raw).trim();
  496. return s === '99' || Number(s) === 99;
  497. }
  498. try {
  499. var p = mergeSearchAndHashParams();
  500. if (checkGoodsUnavailableParam(p.get('goodsUnavailable'))) return true;
  501. if (checkGoodsStatusParam(p.get('goodsStatus'))) return true;
  502. if (checkBusiness99(p.get('businessStatus'))) return true;
  503. } catch (e0) {}
  504. if (checkGoodsUnavailableParam(q('goodsUnavailable'))) return true;
  505. if (checkGoodsStatusParam(q('goodsStatus'))) return true;
  506. if (checkBusiness99(q('businessStatus'))) return true;
  507. return false;
  508. }
  509. function getAppUniPathForShareUndefined() {
  510. if (isSecondGoodsUnavailableForAppOpen()) {
  511. return 'pages/index/login';
  512. }
  513. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(/^\//, '');
  514. }
  515. function buildAppOpenQueryStringMerged() {
  516. var params = mergeSearchAndHashParams();
  517. var gid = params.get('goodsId') || params.get('id') || '';
  518. if (gid && !params.has('goodsId')) {
  519. params.set('goodsId', gid);
  520. }
  521. var sid = params.get('storeId') || params.get('id') || '';
  522. if (sid && !params.has('storeId')) {
  523. params.set('storeId', sid);
  524. }
  525. var qsOut = params.toString();
  526. return qsOut ? ('?' + qsOut) : '';
  527. }
  528. function buildAppDeepLink() {
  529. var path = getAppUniPathForShareUndefined().replace(/^\//, '');
  530. var s = buildAppOpenQueryStringMerged();
  531. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  532. if (!s) {
  533. return root + '/' + path;
  534. }
  535. return root + '/' + path + s;
  536. }
  537. function isWeChatInAppBrowser() {
  538. return /MicroMessenger/i.test(navigator.userAgent || '');
  539. }
  540. function launchAppDeepLink(deepLink) {
  541. try {
  542. var a = document.createElement('a');
  543. a.href = deepLink;
  544. a.setAttribute('target', '_self');
  545. document.body.appendChild(a);
  546. a.click();
  547. document.body.removeChild(a);
  548. } catch (e1) {}
  549. try {
  550. window.location.href = deepLink;
  551. } catch (e2) {}
  552. }
  553. /**
  554. * App-Plus:检测是否已安装;H5:scheme 唤起 + 超时提示(与 secondShareGoods 一致)。
  555. */
  556. function tryOpenUShopApp() {
  557. var deepLink = buildAppDeepLink();
  558. if (typeof plus !== 'undefined' && plus.runtime) {
  559. var installed = null;
  560. try {
  561. if (typeof plus.runtime.isApplicationExist === 'function') {
  562. installed = plus.runtime.isApplicationExist({
  563. pname: APP_ANDROID_PACKAGE,
  564. action: APP_IOS_URL_SCHEME
  565. });
  566. }
  567. } catch (e) {
  568. console.warn(e);
  569. }
  570. if (installed === false) {
  571. showDownloadTip();
  572. return;
  573. }
  574. try {
  575. plus.runtime.openURL(deepLink);
  576. } catch (e2) {
  577. console.warn(e2);
  578. showDownloadTip();
  579. }
  580. return;
  581. }
  582. var t0 = Date.now();
  583. var done = false;
  584. function finish() {
  585. if (done) return;
  586. done = true;
  587. document.removeEventListener('visibilitychange', onVis);
  588. window.removeEventListener('pagehide', onHide);
  589. }
  590. function onVis() {
  591. if (document.visibilityState === 'hidden') finish();
  592. }
  593. function onHide() {
  594. finish();
  595. }
  596. document.addEventListener('visibilitychange', onVis);
  597. window.addEventListener('pagehide', onHide);
  598. if (isWeChatInAppBrowser()) {
  599. window.alert('若点击后无法打开 App:请先点右上角「···」,选择「在浏览器中打开」,再点「APP内打开」。');
  600. }
  601. try {
  602. launchAppDeepLink(deepLink);
  603. } catch (e3) {
  604. finish();
  605. showDownloadTip();
  606. return;
  607. }
  608. window.setTimeout(function () {
  609. if (done) return;
  610. if (document.visibilityState === 'visible' && Date.now() - t0 < 3500) {
  611. showDownloadTip();
  612. }
  613. finish();
  614. }, 2600);
  615. }
  616. function qs() {
  617. return new URLSearchParams(location.search || '');
  618. }
  619. function q(name) {
  620. var v = qs().get(name);
  621. return v == null ? '' : String(v);
  622. }
  623. function showErr(msg) {
  624. var el = document.getElementById('pageError');
  625. el.textContent = msg;
  626. el.style.display = 'block';
  627. }
  628. function getStoreId() {
  629. return q('id') || q('storeId');
  630. }
  631. function apiFetch(path) {
  632. return fetch(API_BASE + path, {
  633. method: 'GET',
  634. mode: 'cors',
  635. credentials: 'omit',
  636. headers: { Accept: 'application/json' }
  637. }).then(function (res) {
  638. if (!res.ok) throw new Error('HTTP ' + res.status);
  639. return res.json();
  640. });
  641. }
  642. function isApiOk(res) {
  643. if (!res || typeof res !== 'object') return false;
  644. if (res.success === false) return false;
  645. var c = res.code;
  646. return c === 200 || c === '200' || Number(c) === 200;
  647. }
  648. function fetchSecondGlobalRecommend() {
  649. var userIdRaw = q('userId').trim();
  650. var userId =
  651. userIdRaw !== '' && !isNaN(Number(userIdRaw)) ? Number(userIdRaw) : null;
  652. var latRaw = (q('userLat') || q('latitude') || q('lat') || q('weidu')).trim();
  653. var lngRaw = (q('userLng') || q('longitude') || q('lon') || q('jingdu')).trim();
  654. var userLat =
  655. latRaw !== '' && !isNaN(Number(latRaw)) ? Number(latRaw) : DEFAULT_REC_USER_LAT;
  656. var userLng =
  657. lngRaw !== '' && !isNaN(Number(lngRaw)) ? Number(lngRaw) : DEFAULT_REC_USER_LNG;
  658. var rkRaw = q('radiusKm').trim();
  659. var radiusKm =
  660. rkRaw !== '' && !isNaN(Number(rkRaw)) ? Number(rkRaw) : DEFAULT_REC_RADIUS_KM;
  661. var page = parseInt(q('page') || '1', 10);
  662. var pageSize = parseInt(q('pageSize') || '20', 10);
  663. if (isNaN(page) || page < 1) page = 1;
  664. if (isNaN(pageSize) || pageSize < 1) pageSize = 20;
  665. var c1Raw = q('categoryOneId').trim();
  666. var c2Raw = q('categoryTwoId').trim();
  667. var categoryOneId =
  668. c1Raw === '' || c1Raw.toLowerCase() === 'null'
  669. ? null
  670. : isNaN(Number(c1Raw))
  671. ? null
  672. : Number(c1Raw);
  673. var categoryTwoId =
  674. c2Raw === '' || c2Raw.toLowerCase() === 'null'
  675. ? null
  676. : isNaN(Number(c2Raw))
  677. ? null
  678. : Number(c2Raw);
  679. var body = {
  680. categoryOneId: categoryOneId,
  681. categoryTwoId: categoryTwoId,
  682. page: page,
  683. pageSize: pageSize,
  684. radiusKm: radiusKm,
  685. userLat: userLat,
  686. userLng: userLng,
  687. userId: userId
  688. };
  689. return fetch(API_LIFE_AI_BASE + SECOND_GLOBAL_RECOMMEND_PATH, {
  690. method: 'POST',
  691. mode: 'cors',
  692. credentials: 'omit',
  693. headers: {
  694. Accept: 'application/json',
  695. 'Content-Type': 'application/json;charset=UTF-8'
  696. },
  697. body: JSON.stringify(body)
  698. }).then(function (res) {
  699. if (!res.ok) throw new Error('HTTP ' + res.status);
  700. return res.json();
  701. });
  702. }
  703. function normalizeGlobalRecommendList(res) {
  704. if (!res || typeof res !== 'object') return [];
  705. var raw = null;
  706. if (isApiOk(res)) {
  707. raw = res.data != null ? res.data : res.result;
  708. }
  709. if (Array.isArray(raw)) return raw;
  710. if (raw && typeof raw === 'object') {
  711. if (Array.isArray(raw.list)) return raw.list;
  712. if (Array.isArray(raw.records)) return raw.records;
  713. if (Array.isArray(raw.rows)) return raw.rows;
  714. if (Array.isArray(raw.content)) return raw.content;
  715. }
  716. return [];
  717. }
  718. function buildHeroSlides(urls) {
  719. var track = document.getElementById('heroTrack');
  720. var dotsWrap = document.getElementById('heroDots');
  721. track.innerHTML = '';
  722. dotsWrap.innerHTML = '';
  723. var list = (urls || []).filter(Boolean);
  724. if (!list.length) {
  725. var slide = document.createElement('div');
  726. slide.className = 'hero__slide';
  727. var img = document.createElement('img');
  728. img.src = 'images/hero.png';
  729. img.alt = '店铺';
  730. slide.appendChild(img);
  731. track.appendChild(slide);
  732. var dot = document.createElement('span');
  733. dot.className = 'hero__dot is-active';
  734. dotsWrap.appendChild(dot);
  735. return initHeroCarousel(1);
  736. }
  737. list.forEach(function (url, d) {
  738. var slide = document.createElement('div');
  739. slide.className = 'hero__slide';
  740. var img = document.createElement('img');
  741. img.src = url;
  742. img.alt = '店铺图';
  743. slide.appendChild(img);
  744. track.appendChild(slide);
  745. var dot = document.createElement('span');
  746. dot.className = 'hero__dot' + (d === 0 ? ' is-active' : '');
  747. dotsWrap.appendChild(dot);
  748. });
  749. initHeroCarousel(list.length);
  750. }
  751. var heroI = 0;
  752. var heroTimer = null;
  753. function initHeroCarousel(slides) {
  754. var track = document.getElementById('heroTrack');
  755. var dotsWrap = document.getElementById('heroDots');
  756. var dots = dotsWrap.querySelectorAll('.hero__dot');
  757. if (slides < 2) return;
  758. function go(n) {
  759. heroI = (n + slides) % slides;
  760. track.style.transform = 'translateX(' + (-heroI * 100) + '%)';
  761. dots.forEach(function (el, idx) {
  762. el.classList.toggle('is-active', idx === heroI);
  763. });
  764. }
  765. if (heroTimer) clearInterval(heroTimer);
  766. heroTimer = setInterval(function () { go(heroI + 1); }, 4000);
  767. var hero = document.getElementById('hero');
  768. var startX = 0;
  769. hero.addEventListener('touchstart', function (e) {
  770. startX = e.changedTouches[0].clientX;
  771. }, { passive: true });
  772. hero.addEventListener('touchend', function (e) {
  773. var dx = e.changedTouches[0].clientX - startX;
  774. if (Math.abs(dx) > 40) go(dx < 0 ? heroI + 1 : heroI - 1);
  775. }, { passive: true });
  776. }
  777. function timeToMinutes(t) {
  778. var parts = String(t || '').trim().split(':');
  779. var h = parseInt(parts[0], 10) || 0;
  780. var m = parseInt(parts[1], 10) || 0;
  781. return h * 60 + m;
  782. }
  783. function isTimeInRange(startTime, endTime) {
  784. var s = String(startTime || '').trim();
  785. var e = String(endTime || '').trim();
  786. if (s === '00:00' && e === '00:00') return true;
  787. if (s === '00:00' && e === '23:59') return true;
  788. var cur = new Date().getHours() * 60 + new Date().getMinutes();
  789. var sm = timeToMinutes(s);
  790. var em = timeToMinutes(e);
  791. if (em < sm) {
  792. return cur >= sm || cur <= em;
  793. }
  794. return cur >= sm && cur <= em;
  795. }
  796. function parseHolidayDate(str) {
  797. if (!str) return null;
  798. var d = new Date(String(str).trim().replace(/-/g, '/'));
  799. return isNaN(d.getTime()) ? null : d;
  800. }
  801. function isTodayInHolidayRange(holidayInfo) {
  802. if (!holidayInfo) return false;
  803. var hi = holidayInfo;
  804. if (typeof hi === 'string') {
  805. try {
  806. hi = JSON.parse(hi);
  807. } catch (err) {
  808. return false;
  809. }
  810. }
  811. var start = hi.startDate || hi.holidayStartDate || hi.beginDate || hi.start || hi.holidayStart;
  812. var end = hi.endDate || hi.holidayEndDate || hi.finishDate || hi.end || hi.holidayEnd;
  813. if (!start || !end) return false;
  814. var startD = parseHolidayDate(start);
  815. var endD = parseHolidayDate(end);
  816. if (!startD || !endD) return false;
  817. var today = new Date();
  818. today.setHours(0, 0, 0, 0);
  819. startD.setHours(0, 0, 0, 0);
  820. endD.setHours(0, 0, 0, 0);
  821. return today >= startD && today <= endD;
  822. }
  823. function findNormalBusinessInfo(list) {
  824. var wdJs = new Date().getDay();
  825. var i;
  826. var x;
  827. var w;
  828. for (i = 0; i < list.length; i++) {
  829. x = list[i];
  830. if (!x || x.holidayInfo) continue;
  831. w = x.weekDay != null ? x.weekDay : x.week;
  832. if (w === undefined || w === null) continue;
  833. if (Number(w) === wdJs) return x;
  834. }
  835. var wdMap = wdJs === 0 ? 7 : wdJs;
  836. for (i = 0; i < list.length; i++) {
  837. x = list[i];
  838. if (!x || x.holidayInfo) continue;
  839. w = x.weekDay != null ? x.weekDay : x.week;
  840. if (w === undefined || w === null) continue;
  841. if (Number(w) === wdMap) return x;
  842. }
  843. for (i = 0; i < list.length; i++) {
  844. x = list[i];
  845. if (x && !x.holidayInfo && (x.startTime || x.endTime)) return x;
  846. }
  847. return null;
  848. }
  849. /** 营业状态:暂停营业 | 商家暂未配置营业时间 | 休息中 | 营业中 xx:xx至xx:xx | 营业中 全天营业 */
  850. function computeBusinessStatusDisplay(d) {
  851. if (!d) return { text: '—', isOpen: false };
  852. if (Number(d.businessStatus) === 1) {
  853. return { text: '暂停营业', isOpen: false };
  854. }
  855. var list = d.storeBusinessInfoVos || d.storeBusinessInfos || [];
  856. if (!list.length) {
  857. return { text: '商家暂未配置营业时间', isOpen: false };
  858. }
  859. var holidayList = Array.isArray(d.holidayBusinessInfoList) && d.holidayBusinessInfoList.length
  860. ? d.holidayBusinessInfoList
  861. : list.filter(function (item) { return item && item.holidayInfo; });
  862. var todayHolidayItem = holidayList.find(function (item) {
  863. return isTodayInHolidayRange(item.holidayInfo);
  864. });
  865. var normal = d.normalBusinessInfo || d.normalBusinessInfoVo || findNormalBusinessInfo(list);
  866. var isOpen = false;
  867. var currentItem = null;
  868. if (todayHolidayItem) {
  869. isOpen = isTimeInRange(todayHolidayItem.startTime, todayHolidayItem.endTime);
  870. currentItem = todayHolidayItem;
  871. } else if (normal) {
  872. isOpen = isTimeInRange(normal.startTime, normal.endTime);
  873. currentItem = normal;
  874. }
  875. if (!currentItem) return { text: '休息中', isOpen: false };
  876. if (!isOpen) return { text: '休息中', isOpen: false };
  877. var st = String(currentItem.startTime || '').trim();
  878. var et = String(currentItem.endTime || '').trim();
  879. if (st === '00:00' && et === '00:00') return { text: '营业中 全天营业', isOpen: true };
  880. if (st === '00:00' && et === '23:59') return { text: '营业中 全天营业', isOpen: true };
  881. var needNextDay = timeToMinutes(et) < timeToMinutes(st);
  882. var suffix = (needNextDay ? '次日' : '') + et;
  883. return { text: ('营业中 ' + st + ' 至 ' + suffix).trim(), isOpen: true };
  884. }
  885. function renderDetail(d) {
  886. if (!d) return;
  887. document.getElementById('storeName').textContent = d.storeName || '—';
  888. var score = d.scoreAvg != null ? Number(d.scoreAvg) : NaN;
  889. document.getElementById('scoreAvg').textContent = !isNaN(score) ? score.toFixed(1) : '—';
  890. document.getElementById('commitCount').textContent = d.commitCount != null ? String(d.commitCount) : '0';
  891. var bizDisp = computeBusinessStatusDisplay(d);
  892. var bizEl = document.getElementById('bizStatus');
  893. bizEl.textContent = bizDisp.text;
  894. bizEl.className = 'status' + (bizDisp.isOpen ? ' is-open' : '');
  895. document.getElementById('hoursText').textContent = '';
  896. document.getElementById('storeAddr').textContent = d.queryAddress || d.storeAddress || '—';
  897. if (d.distance != null) {
  898. document.getElementById('metaDistance').style.display = 'flex';
  899. document.getElementById('distanceText').textContent =
  900. '距您' + (Number(d.distance) > 1 ? d.distance + '千米' : Math.round(Number(d.distance) * 1000) + '米');
  901. }
  902. if (d.subwayName && d.distance2 != null) {
  903. document.getElementById('metaSubway').style.display = 'flex';
  904. document.getElementById('subwayText').textContent =
  905. '距' + d.subwayName + '步行' + (Number(d.distance2) >= 1000
  906. ? (Number(d.distance2) / 1000).toFixed(1) + 'km'
  907. : Math.round(Number(d.distance2)) + 'm');
  908. }
  909. var imgs = [];
  910. if (Array.isArray(d.storeAlbumUrlList) && d.storeAlbumUrlList.length) imgs = d.storeAlbumUrlList.slice();
  911. else if (d.entranceImage) imgs = [d.entranceImage];
  912. buildHeroSlides(imgs);
  913. }
  914. function formatRecDist(m) {
  915. if (m == null || m === '') return '';
  916. var n = Number(m);
  917. if (isNaN(n)) return String(m);
  918. return n >= 1000 ? (n / 1000).toFixed(1) + 'km' : Math.round(n) + 'm';
  919. }
  920. function escHtml(s) {
  921. return String(s == null ? '' : s)
  922. .replace(/&/g, '&amp;')
  923. .replace(/</g, '&lt;')
  924. .replace(/>/g, '&gt;')
  925. .replace(/"/g, '&quot;');
  926. }
  927. /** global-recommend records:homeImage、title、position、dist、price、amount、likeCount、collectCount、userName、userImage */
  928. function renderRecommended(list) {
  929. var wrap = document.getElementById('recList');
  930. var empty = document.getElementById('recEmpty');
  931. wrap.querySelectorAll('.rec-card').forEach(function (n) {
  932. n.remove();
  933. });
  934. if (!list || !list.length) {
  935. empty.style.display = 'block';
  936. return;
  937. }
  938. empty.style.display = 'none';
  939. list.forEach(function (item) {
  940. if (!item || typeof item !== 'object') return;
  941. var card = document.createElement('article');
  942. card.className = 'rec-card';
  943. var home = item.homeImage != null ? String(item.homeImage).trim() : '';
  944. if (home && /\.mp4(\?|#|$)/i.test(home)) {
  945. var vf = item.videoFirstFrame != null ? String(item.videoFirstFrame).trim() : '';
  946. if (vf) home = vf;
  947. }
  948. var imgUrl =
  949. home ||
  950. (item.coverUrl != null ? String(item.coverUrl).trim() : '') ||
  951. (item.mainImage != null ? String(item.mainImage).trim() : '') ||
  952. (item.goodsImage != null ? String(item.goodsImage).trim() : '') ||
  953. (Array.isArray(item.goodsImageList) && item.goodsImageList[0]) ||
  954. (Array.isArray(item.imageList) && item.imageList[0]) ||
  955. 'images/hero.png';
  956. var name = item.title != null && String(item.title).trim() !== ''
  957. ? String(item.title).replace(/\r?\n/g, ' ').replace(/\s+/g, ' ').trim()
  958. : (item.goodsName ||
  959. item.secondGoodsTitle ||
  960. item.name ||
  961. '商品');
  962. var dist = '';
  963. if (item.position != null && String(item.position).trim() !== '') {
  964. dist = String(item.position).trim();
  965. } else if (item.dist != null && item.dist !== '') {
  966. var dn = Number(item.dist);
  967. if (!isNaN(dn)) {
  968. dist = dn.toFixed(dn % 1 === 0 ? 0 : 2) + 'km';
  969. }
  970. } else if (item.distance != null && item.distance !== '') {
  971. var d2 = Number(item.distance);
  972. dist = !isNaN(d2) ? d2.toFixed(d2 % 1 === 0 ? 0 : 2) + 'km' : String(item.distance);
  973. }
  974. var priceStr = '';
  975. if (item.price != null && String(item.price).trim() !== '') {
  976. var ps = String(item.price).trim();
  977. var pNum = parseFloat(ps.replace(/[^\d.]/g, ''));
  978. priceStr = !isNaN(pNum) ? pNum.toFixed(2) : ps;
  979. } else if (item.amount != null && item.amount !== '') {
  980. var an = Number(item.amount);
  981. priceStr = !isNaN(an) ? an.toFixed(2) : String(item.amount);
  982. } else {
  983. priceStr = '—';
  984. }
  985. var seller =
  986. item.userName != null && String(item.userName).trim() !== ''
  987. ? String(item.userName).trim()
  988. : '';
  989. var userImg =
  990. item.userImage != null && String(item.userImage).trim() !== ''
  991. ? String(item.userImage).trim()
  992. : '';
  993. var likeN = item.likeCount != null ? Number(item.likeCount) : NaN;
  994. var colN = item.collectCount != null ? Number(item.collectCount) : NaN;
  995. var metaBits = [];
  996. // if (!isNaN(likeN)) metaBits.push(likeN + '赞');
  997. // if (!isNaN(colN)) metaBits.push(colN + '想要');
  998. var metaRight = metaBits.join(' · ');
  999. var showSellerRow = !!(seller || userImg);
  1000. card.innerHTML =
  1001. '<div class="rec-card__img"><img class="rec-card__cover" src="" alt=""></div>' +
  1002. '<div class="rec-card__body">' +
  1003. '<div class="rec-card__top">' +
  1004. '<span class="rec-card__name">' + escHtml(name) + '</span>' +
  1005. (dist ? '<span class="rec-card__dist">' + escHtml(dist) + '</span>' : '') +
  1006. '</div>' +
  1007. '<div class="rec-card__rating">' +
  1008. '<span class="rec-meta" style="color:#E62E2E;font-weight:600;">¥' + escHtml(priceStr) + '</span>' +
  1009. (metaRight
  1010. ? '<span class="rec-meta">' + escHtml(metaRight) + '</span>'
  1011. : '') +
  1012. '</div>' +
  1013. (showSellerRow
  1014. ? '<div class="rec-card__seller">' +
  1015. '<img class="rec-card__avatar" src="" alt="" width="22" height="22" decoding="async">' +
  1016. (seller ? '<span class="rec-card__seller-name">' + escHtml(seller) + '</span>' : '') +
  1017. '</div>'
  1018. : '') +
  1019. '</div>';
  1020. var coverIm = card.querySelector('img.rec-card__cover');
  1021. if (coverIm) {
  1022. coverIm.src = imgUrl;
  1023. coverIm.onerror = function () {
  1024. this.onerror = null;
  1025. this.src = 'images/hero.png';
  1026. };
  1027. }
  1028. var avIm = card.querySelector('img.rec-card__avatar');
  1029. if (avIm) {
  1030. avIm.src = userImg || 'images/demouser.png';
  1031. avIm.onerror = function () {
  1032. this.onerror = null;
  1033. this.src = 'images/demouser.png';
  1034. };
  1035. }
  1036. wrap.appendChild(card);
  1037. });
  1038. }
  1039. function run() {
  1040. fetchSecondGlobalRecommend()
  1041. .then(function (res) {
  1042. var list = normalizeGlobalRecommendList(res);
  1043. if (!list.length && res && res.msg) {
  1044. console.warn('[global-recommend]', res.msg);
  1045. }
  1046. renderRecommended(list);
  1047. })
  1048. .catch(function (e) {
  1049. console.error(e);
  1050. renderRecommended([]);
  1051. });
  1052. }
  1053. function boot() {
  1054. run();
  1055. var openBtn = document.getElementById('openApp');
  1056. if (openBtn) {
  1057. openBtn.addEventListener('click', function () {
  1058. tryOpenUShopApp();
  1059. });
  1060. }
  1061. }
  1062. if (document.readyState === 'complete') {
  1063. boot();
  1064. } else {
  1065. window.onload = boot;
  1066. }
  1067. })();
  1068. </script>
  1069. </body>
  1070. </html>