shareUndefined.html 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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. * 注意:用 file:// 打开本页时,浏览器可能因 CORS 拦截跨域请求。
  436. */
  437. var API_BASE = 'http://120.26.186.130:8000/alienStore';
  438. var API_LIFE_AI_BASE = 'http://124.93.18.180:9100';
  439. var SECOND_GLOBAL_RECOMMEND_PATH = '/ai/life-manager/api/v1/second_hand/global-recommend';
  440. var DEFAULT_REC_USER_LAT = 38.925756;
  441. var DEFAULT_REC_USER_LNG = 121.662543;
  442. var DEFAULT_REC_RADIUS_KM = 195.69;
  443. /**
  444. * 与 secondShareGoods.html 一致:唤起 App 打开二手商品详情页(合并 search + hash 内 query)
  445. */
  446. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  447. var APP_IOS_URL_SCHEME = 'shopro://';
  448. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  449. function showDownloadTip() {
  450. var msg = '请到应用商店下载';
  451. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  452. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  453. } else {
  454. window.alert(msg);
  455. }
  456. }
  457. function mergeSearchAndHashParams() {
  458. var params = new URLSearchParams();
  459. function ingest(querySlice) {
  460. if (!querySlice) return;
  461. var p = new URLSearchParams(querySlice);
  462. p.forEach(function (val, key) {
  463. params.append(key, val);
  464. });
  465. }
  466. if (location.search && location.search.length > 1) {
  467. ingest(location.search.slice(1));
  468. }
  469. var hash = location.hash || '';
  470. var qi = hash.indexOf('?');
  471. if (qi >= 0) {
  472. ingest(hash.slice(qi + 1));
  473. }
  474. return params;
  475. }
  476. function buildAppOpenQueryStringMerged() {
  477. var params = mergeSearchAndHashParams();
  478. var gid = params.get('goodsId') || params.get('id') || '';
  479. if (gid && !params.has('goodsId')) {
  480. params.set('goodsId', gid);
  481. }
  482. var sid = params.get('storeId') || params.get('id') || '';
  483. if (sid && !params.has('storeId')) {
  484. params.set('storeId', sid);
  485. }
  486. var qsOut = params.toString();
  487. return qsOut ? ('?' + qsOut) : '';
  488. }
  489. function buildAppDeepLink() {
  490. var path = String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(/^\//, '');
  491. var s = buildAppOpenQueryStringMerged();
  492. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  493. if (!s) {
  494. return root + '/' + path;
  495. }
  496. return root + '/' + path + s;
  497. }
  498. function isWeChatInAppBrowser() {
  499. return /MicroMessenger/i.test(navigator.userAgent || '');
  500. }
  501. function launchAppDeepLink(deepLink) {
  502. try {
  503. var a = document.createElement('a');
  504. a.href = deepLink;
  505. a.setAttribute('target', '_self');
  506. document.body.appendChild(a);
  507. a.click();
  508. document.body.removeChild(a);
  509. } catch (e1) {}
  510. try {
  511. window.location.href = deepLink;
  512. } catch (e2) {}
  513. }
  514. /**
  515. * App-Plus:检测是否已安装;H5:scheme 唤起 + 超时提示(与 secondShareGoods 一致)。
  516. */
  517. function tryOpenUShopApp() {
  518. var deepLink = buildAppDeepLink();
  519. if (typeof plus !== 'undefined' && plus.runtime) {
  520. var installed = null;
  521. try {
  522. if (typeof plus.runtime.isApplicationExist === 'function') {
  523. installed = plus.runtime.isApplicationExist({
  524. pname: APP_ANDROID_PACKAGE,
  525. action: APP_IOS_URL_SCHEME
  526. });
  527. }
  528. } catch (e) {
  529. console.warn(e);
  530. }
  531. if (installed === false) {
  532. showDownloadTip();
  533. return;
  534. }
  535. try {
  536. plus.runtime.openURL(deepLink);
  537. } catch (e2) {
  538. console.warn(e2);
  539. showDownloadTip();
  540. }
  541. return;
  542. }
  543. var t0 = Date.now();
  544. var done = false;
  545. function finish() {
  546. if (done) return;
  547. done = true;
  548. document.removeEventListener('visibilitychange', onVis);
  549. window.removeEventListener('pagehide', onHide);
  550. }
  551. function onVis() {
  552. if (document.visibilityState === 'hidden') finish();
  553. }
  554. function onHide() {
  555. finish();
  556. }
  557. document.addEventListener('visibilitychange', onVis);
  558. window.addEventListener('pagehide', onHide);
  559. if (isWeChatInAppBrowser()) {
  560. window.alert('若点击后无法打开 App:请先点右上角「···」,选择「在浏览器中打开」,再点「APP内打开」。');
  561. }
  562. try {
  563. launchAppDeepLink(deepLink);
  564. } catch (e3) {
  565. finish();
  566. showDownloadTip();
  567. return;
  568. }
  569. window.setTimeout(function () {
  570. if (done) return;
  571. if (document.visibilityState === 'visible' && Date.now() - t0 < 3500) {
  572. showDownloadTip();
  573. }
  574. finish();
  575. }, 2600);
  576. }
  577. function qs() {
  578. return new URLSearchParams(location.search || '');
  579. }
  580. function q(name) {
  581. var v = qs().get(name);
  582. return v == null ? '' : String(v);
  583. }
  584. function showErr(msg) {
  585. var el = document.getElementById('pageError');
  586. el.textContent = msg;
  587. el.style.display = 'block';
  588. }
  589. function getStoreId() {
  590. return q('id') || q('storeId');
  591. }
  592. function apiFetch(path) {
  593. return fetch(API_BASE + path, {
  594. method: 'GET',
  595. mode: 'cors',
  596. credentials: 'omit',
  597. headers: { Accept: 'application/json' }
  598. }).then(function (res) {
  599. if (!res.ok) throw new Error('HTTP ' + res.status);
  600. return res.json();
  601. });
  602. }
  603. function isApiOk(res) {
  604. if (!res || typeof res !== 'object') return false;
  605. if (res.success === false) return false;
  606. var c = res.code;
  607. return c === 200 || c === '200' || Number(c) === 200;
  608. }
  609. function fetchSecondGlobalRecommend() {
  610. var userIdRaw = q('userId').trim();
  611. var userId =
  612. userIdRaw !== '' && !isNaN(Number(userIdRaw)) ? Number(userIdRaw) : null;
  613. var latRaw = (q('userLat') || q('latitude') || q('lat') || q('weidu')).trim();
  614. var lngRaw = (q('userLng') || q('longitude') || q('lon') || q('jingdu')).trim();
  615. var userLat =
  616. latRaw !== '' && !isNaN(Number(latRaw)) ? Number(latRaw) : DEFAULT_REC_USER_LAT;
  617. var userLng =
  618. lngRaw !== '' && !isNaN(Number(lngRaw)) ? Number(lngRaw) : DEFAULT_REC_USER_LNG;
  619. var rkRaw = q('radiusKm').trim();
  620. var radiusKm =
  621. rkRaw !== '' && !isNaN(Number(rkRaw)) ? Number(rkRaw) : DEFAULT_REC_RADIUS_KM;
  622. var page = parseInt(q('page') || '1', 10);
  623. var pageSize = parseInt(q('pageSize') || '20', 10);
  624. if (isNaN(page) || page < 1) page = 1;
  625. if (isNaN(pageSize) || pageSize < 1) pageSize = 20;
  626. var c1Raw = q('categoryOneId').trim();
  627. var c2Raw = q('categoryTwoId').trim();
  628. var categoryOneId =
  629. c1Raw === '' || c1Raw.toLowerCase() === 'null'
  630. ? null
  631. : isNaN(Number(c1Raw))
  632. ? null
  633. : Number(c1Raw);
  634. var categoryTwoId =
  635. c2Raw === '' || c2Raw.toLowerCase() === 'null'
  636. ? null
  637. : isNaN(Number(c2Raw))
  638. ? null
  639. : Number(c2Raw);
  640. var body = {
  641. categoryOneId: categoryOneId,
  642. categoryTwoId: categoryTwoId,
  643. page: page,
  644. pageSize: pageSize,
  645. radiusKm: radiusKm,
  646. userLat: userLat,
  647. userLng: userLng,
  648. userId: userId
  649. };
  650. return fetch(API_LIFE_AI_BASE + SECOND_GLOBAL_RECOMMEND_PATH, {
  651. method: 'POST',
  652. mode: 'cors',
  653. credentials: 'omit',
  654. headers: {
  655. Accept: 'application/json',
  656. 'Content-Type': 'application/json;charset=UTF-8'
  657. },
  658. body: JSON.stringify(body)
  659. }).then(function (res) {
  660. if (!res.ok) throw new Error('HTTP ' + res.status);
  661. return res.json();
  662. });
  663. }
  664. function normalizeGlobalRecommendList(res) {
  665. if (!res || typeof res !== 'object') return [];
  666. var raw = null;
  667. if (isApiOk(res)) {
  668. raw = res.data != null ? res.data : res.result;
  669. }
  670. if (Array.isArray(raw)) return raw;
  671. if (raw && typeof raw === 'object') {
  672. if (Array.isArray(raw.list)) return raw.list;
  673. if (Array.isArray(raw.records)) return raw.records;
  674. if (Array.isArray(raw.rows)) return raw.rows;
  675. if (Array.isArray(raw.content)) return raw.content;
  676. }
  677. return [];
  678. }
  679. function buildHeroSlides(urls) {
  680. var track = document.getElementById('heroTrack');
  681. var dotsWrap = document.getElementById('heroDots');
  682. track.innerHTML = '';
  683. dotsWrap.innerHTML = '';
  684. var list = (urls || []).filter(Boolean);
  685. if (!list.length) {
  686. var slide = document.createElement('div');
  687. slide.className = 'hero__slide';
  688. var img = document.createElement('img');
  689. img.src = 'images/hero.png';
  690. img.alt = '店铺';
  691. slide.appendChild(img);
  692. track.appendChild(slide);
  693. var dot = document.createElement('span');
  694. dot.className = 'hero__dot is-active';
  695. dotsWrap.appendChild(dot);
  696. return initHeroCarousel(1);
  697. }
  698. list.forEach(function (url, d) {
  699. var slide = document.createElement('div');
  700. slide.className = 'hero__slide';
  701. var img = document.createElement('img');
  702. img.src = url;
  703. img.alt = '店铺图';
  704. slide.appendChild(img);
  705. track.appendChild(slide);
  706. var dot = document.createElement('span');
  707. dot.className = 'hero__dot' + (d === 0 ? ' is-active' : '');
  708. dotsWrap.appendChild(dot);
  709. });
  710. initHeroCarousel(list.length);
  711. }
  712. var heroI = 0;
  713. var heroTimer = null;
  714. function initHeroCarousel(slides) {
  715. var track = document.getElementById('heroTrack');
  716. var dotsWrap = document.getElementById('heroDots');
  717. var dots = dotsWrap.querySelectorAll('.hero__dot');
  718. if (slides < 2) return;
  719. function go(n) {
  720. heroI = (n + slides) % slides;
  721. track.style.transform = 'translateX(' + (-heroI * 100) + '%)';
  722. dots.forEach(function (el, idx) {
  723. el.classList.toggle('is-active', idx === heroI);
  724. });
  725. }
  726. if (heroTimer) clearInterval(heroTimer);
  727. heroTimer = setInterval(function () { go(heroI + 1); }, 4000);
  728. var hero = document.getElementById('hero');
  729. var startX = 0;
  730. hero.addEventListener('touchstart', function (e) {
  731. startX = e.changedTouches[0].clientX;
  732. }, { passive: true });
  733. hero.addEventListener('touchend', function (e) {
  734. var dx = e.changedTouches[0].clientX - startX;
  735. if (Math.abs(dx) > 40) go(dx < 0 ? heroI + 1 : heroI - 1);
  736. }, { passive: true });
  737. }
  738. function timeToMinutes(t) {
  739. var parts = String(t || '').trim().split(':');
  740. var h = parseInt(parts[0], 10) || 0;
  741. var m = parseInt(parts[1], 10) || 0;
  742. return h * 60 + m;
  743. }
  744. function isTimeInRange(startTime, endTime) {
  745. var s = String(startTime || '').trim();
  746. var e = String(endTime || '').trim();
  747. if (s === '00:00' && e === '00:00') return true;
  748. if (s === '00:00' && e === '23:59') return true;
  749. var cur = new Date().getHours() * 60 + new Date().getMinutes();
  750. var sm = timeToMinutes(s);
  751. var em = timeToMinutes(e);
  752. if (em < sm) {
  753. return cur >= sm || cur <= em;
  754. }
  755. return cur >= sm && cur <= em;
  756. }
  757. function parseHolidayDate(str) {
  758. if (!str) return null;
  759. var d = new Date(String(str).trim().replace(/-/g, '/'));
  760. return isNaN(d.getTime()) ? null : d;
  761. }
  762. function isTodayInHolidayRange(holidayInfo) {
  763. if (!holidayInfo) return false;
  764. var hi = holidayInfo;
  765. if (typeof hi === 'string') {
  766. try {
  767. hi = JSON.parse(hi);
  768. } catch (err) {
  769. return false;
  770. }
  771. }
  772. var start = hi.startDate || hi.holidayStartDate || hi.beginDate || hi.start || hi.holidayStart;
  773. var end = hi.endDate || hi.holidayEndDate || hi.finishDate || hi.end || hi.holidayEnd;
  774. if (!start || !end) return false;
  775. var startD = parseHolidayDate(start);
  776. var endD = parseHolidayDate(end);
  777. if (!startD || !endD) return false;
  778. var today = new Date();
  779. today.setHours(0, 0, 0, 0);
  780. startD.setHours(0, 0, 0, 0);
  781. endD.setHours(0, 0, 0, 0);
  782. return today >= startD && today <= endD;
  783. }
  784. function findNormalBusinessInfo(list) {
  785. var wdJs = new Date().getDay();
  786. var i;
  787. var x;
  788. var w;
  789. for (i = 0; i < list.length; i++) {
  790. x = list[i];
  791. if (!x || x.holidayInfo) continue;
  792. w = x.weekDay != null ? x.weekDay : x.week;
  793. if (w === undefined || w === null) continue;
  794. if (Number(w) === wdJs) return x;
  795. }
  796. var wdMap = wdJs === 0 ? 7 : wdJs;
  797. for (i = 0; i < list.length; i++) {
  798. x = list[i];
  799. if (!x || x.holidayInfo) continue;
  800. w = x.weekDay != null ? x.weekDay : x.week;
  801. if (w === undefined || w === null) continue;
  802. if (Number(w) === wdMap) return x;
  803. }
  804. for (i = 0; i < list.length; i++) {
  805. x = list[i];
  806. if (x && !x.holidayInfo && (x.startTime || x.endTime)) return x;
  807. }
  808. return null;
  809. }
  810. /** 营业状态:暂停营业 | 商家暂未配置营业时间 | 休息中 | 营业中 xx:xx至xx:xx | 营业中 全天营业 */
  811. function computeBusinessStatusDisplay(d) {
  812. if (!d) return { text: '—', isOpen: false };
  813. if (Number(d.businessStatus) === 1) {
  814. return { text: '暂停营业', isOpen: false };
  815. }
  816. var list = d.storeBusinessInfoVos || d.storeBusinessInfos || [];
  817. if (!list.length) {
  818. return { text: '商家暂未配置营业时间', isOpen: false };
  819. }
  820. var holidayList = Array.isArray(d.holidayBusinessInfoList) && d.holidayBusinessInfoList.length
  821. ? d.holidayBusinessInfoList
  822. : list.filter(function (item) { return item && item.holidayInfo; });
  823. var todayHolidayItem = holidayList.find(function (item) {
  824. return isTodayInHolidayRange(item.holidayInfo);
  825. });
  826. var normal = d.normalBusinessInfo || d.normalBusinessInfoVo || findNormalBusinessInfo(list);
  827. var isOpen = false;
  828. var currentItem = null;
  829. if (todayHolidayItem) {
  830. isOpen = isTimeInRange(todayHolidayItem.startTime, todayHolidayItem.endTime);
  831. currentItem = todayHolidayItem;
  832. } else if (normal) {
  833. isOpen = isTimeInRange(normal.startTime, normal.endTime);
  834. currentItem = normal;
  835. }
  836. if (!currentItem) return { text: '休息中', isOpen: false };
  837. if (!isOpen) return { text: '休息中', isOpen: false };
  838. var st = String(currentItem.startTime || '').trim();
  839. var et = String(currentItem.endTime || '').trim();
  840. if (st === '00:00' && et === '00:00') return { text: '营业中 全天营业', isOpen: true };
  841. if (st === '00:00' && et === '23:59') return { text: '营业中 全天营业', isOpen: true };
  842. var needNextDay = timeToMinutes(et) < timeToMinutes(st);
  843. var suffix = (needNextDay ? '次日' : '') + et;
  844. return { text: ('营业中 ' + st + ' 至 ' + suffix).trim(), isOpen: true };
  845. }
  846. function renderDetail(d) {
  847. if (!d) return;
  848. document.getElementById('storeName').textContent = d.storeName || '—';
  849. var score = d.scoreAvg != null ? Number(d.scoreAvg) : NaN;
  850. document.getElementById('scoreAvg').textContent = !isNaN(score) ? score.toFixed(1) : '—';
  851. document.getElementById('commitCount').textContent = d.commitCount != null ? String(d.commitCount) : '0';
  852. var bizDisp = computeBusinessStatusDisplay(d);
  853. var bizEl = document.getElementById('bizStatus');
  854. bizEl.textContent = bizDisp.text;
  855. bizEl.className = 'status' + (bizDisp.isOpen ? ' is-open' : '');
  856. document.getElementById('hoursText').textContent = '';
  857. document.getElementById('storeAddr').textContent = d.queryAddress || d.storeAddress || '—';
  858. if (d.distance != null) {
  859. document.getElementById('metaDistance').style.display = 'flex';
  860. document.getElementById('distanceText').textContent =
  861. '距您' + (Number(d.distance) > 1 ? d.distance + '千米' : Math.round(Number(d.distance) * 1000) + '米');
  862. }
  863. if (d.subwayName && d.distance2 != null) {
  864. document.getElementById('metaSubway').style.display = 'flex';
  865. document.getElementById('subwayText').textContent =
  866. '距' + d.subwayName + '步行' + (Number(d.distance2) >= 1000
  867. ? (Number(d.distance2) / 1000).toFixed(1) + 'km'
  868. : Math.round(Number(d.distance2)) + 'm');
  869. }
  870. var imgs = [];
  871. if (Array.isArray(d.storeAlbumUrlList) && d.storeAlbumUrlList.length) imgs = d.storeAlbumUrlList.slice();
  872. else if (d.entranceImage) imgs = [d.entranceImage];
  873. buildHeroSlides(imgs);
  874. }
  875. function formatRecDist(m) {
  876. if (m == null || m === '') return '';
  877. var n = Number(m);
  878. if (isNaN(n)) return String(m);
  879. return n >= 1000 ? (n / 1000).toFixed(1) + 'km' : Math.round(n) + 'm';
  880. }
  881. function escHtml(s) {
  882. return String(s == null ? '' : s)
  883. .replace(/&/g, '&amp;')
  884. .replace(/</g, '&lt;')
  885. .replace(/>/g, '&gt;')
  886. .replace(/"/g, '&quot;');
  887. }
  888. /** global-recommend records:homeImage、title、position、dist、price、amount、likeCount、collectCount、userName、userImage */
  889. function renderRecommended(list) {
  890. var wrap = document.getElementById('recList');
  891. var empty = document.getElementById('recEmpty');
  892. wrap.querySelectorAll('.rec-card').forEach(function (n) {
  893. n.remove();
  894. });
  895. if (!list || !list.length) {
  896. empty.style.display = 'block';
  897. return;
  898. }
  899. empty.style.display = 'none';
  900. list.forEach(function (item) {
  901. if (!item || typeof item !== 'object') return;
  902. var card = document.createElement('article');
  903. card.className = 'rec-card';
  904. var home = item.homeImage != null ? String(item.homeImage).trim() : '';
  905. if (home && /\.mp4(\?|#|$)/i.test(home)) {
  906. var vf = item.videoFirstFrame != null ? String(item.videoFirstFrame).trim() : '';
  907. if (vf) home = vf;
  908. }
  909. var imgUrl =
  910. home ||
  911. (item.coverUrl != null ? String(item.coverUrl).trim() : '') ||
  912. (item.mainImage != null ? String(item.mainImage).trim() : '') ||
  913. (item.goodsImage != null ? String(item.goodsImage).trim() : '') ||
  914. (Array.isArray(item.goodsImageList) && item.goodsImageList[0]) ||
  915. (Array.isArray(item.imageList) && item.imageList[0]) ||
  916. 'images/hero.png';
  917. var name = item.title != null && String(item.title).trim() !== ''
  918. ? String(item.title).replace(/\r?\n/g, ' ').replace(/\s+/g, ' ').trim()
  919. : (item.goodsName ||
  920. item.secondGoodsTitle ||
  921. item.name ||
  922. '商品');
  923. var dist = '';
  924. if (item.position != null && String(item.position).trim() !== '') {
  925. dist = String(item.position).trim();
  926. } else if (item.dist != null && item.dist !== '') {
  927. var dn = Number(item.dist);
  928. if (!isNaN(dn)) {
  929. dist = dn.toFixed(dn % 1 === 0 ? 0 : 2) + 'km';
  930. }
  931. } else if (item.distance != null && item.distance !== '') {
  932. var d2 = Number(item.distance);
  933. dist = !isNaN(d2) ? d2.toFixed(d2 % 1 === 0 ? 0 : 2) + 'km' : String(item.distance);
  934. }
  935. var priceStr = '';
  936. if (item.price != null && String(item.price).trim() !== '') {
  937. var ps = String(item.price).trim();
  938. var pNum = parseFloat(ps.replace(/[^\d.]/g, ''));
  939. priceStr = !isNaN(pNum) ? pNum.toFixed(2) : ps;
  940. } else if (item.amount != null && item.amount !== '') {
  941. var an = Number(item.amount);
  942. priceStr = !isNaN(an) ? an.toFixed(2) : String(item.amount);
  943. } else {
  944. priceStr = '—';
  945. }
  946. var seller =
  947. item.userName != null && String(item.userName).trim() !== ''
  948. ? String(item.userName).trim()
  949. : '';
  950. var userImg =
  951. item.userImage != null && String(item.userImage).trim() !== ''
  952. ? String(item.userImage).trim()
  953. : '';
  954. var likeN = item.likeCount != null ? Number(item.likeCount) : NaN;
  955. var colN = item.collectCount != null ? Number(item.collectCount) : NaN;
  956. var metaBits = [];
  957. // if (!isNaN(likeN)) metaBits.push(likeN + '赞');
  958. // if (!isNaN(colN)) metaBits.push(colN + '想要');
  959. var metaRight = metaBits.join(' · ');
  960. var showSellerRow = !!(seller || userImg);
  961. card.innerHTML =
  962. '<div class="rec-card__img"><img class="rec-card__cover" src="" alt=""></div>' +
  963. '<div class="rec-card__body">' +
  964. '<div class="rec-card__top">' +
  965. '<span class="rec-card__name">' + escHtml(name) + '</span>' +
  966. (dist ? '<span class="rec-card__dist">' + escHtml(dist) + '</span>' : '') +
  967. '</div>' +
  968. '<div class="rec-card__rating">' +
  969. '<span class="rec-meta" style="color:#E62E2E;font-weight:600;">¥' + escHtml(priceStr) + '</span>' +
  970. (metaRight
  971. ? '<span class="rec-meta">' + escHtml(metaRight) + '</span>'
  972. : '') +
  973. '</div>' +
  974. (showSellerRow
  975. ? '<div class="rec-card__seller">' +
  976. '<img class="rec-card__avatar" src="" alt="" width="22" height="22" decoding="async">' +
  977. (seller ? '<span class="rec-card__seller-name">' + escHtml(seller) + '</span>' : '') +
  978. '</div>'
  979. : '') +
  980. '</div>';
  981. var coverIm = card.querySelector('img.rec-card__cover');
  982. if (coverIm) {
  983. coverIm.src = imgUrl;
  984. coverIm.onerror = function () {
  985. this.onerror = null;
  986. this.src = 'images/hero.png';
  987. };
  988. }
  989. var avIm = card.querySelector('img.rec-card__avatar');
  990. if (avIm) {
  991. avIm.src = userImg || 'images/demouser.png';
  992. avIm.onerror = function () {
  993. this.onerror = null;
  994. this.src = 'images/demouser.png';
  995. };
  996. }
  997. wrap.appendChild(card);
  998. });
  999. }
  1000. function run() {
  1001. fetchSecondGlobalRecommend()
  1002. .then(function (res) {
  1003. var list = normalizeGlobalRecommendList(res);
  1004. if (!list.length && res && res.msg) {
  1005. console.warn('[global-recommend]', res.msg);
  1006. }
  1007. renderRecommended(list);
  1008. })
  1009. .catch(function (e) {
  1010. console.error(e);
  1011. renderRecommended([]);
  1012. });
  1013. }
  1014. function boot() {
  1015. run();
  1016. var openBtn = document.getElementById('openApp');
  1017. if (openBtn) {
  1018. openBtn.addEventListener('click', function () {
  1019. tryOpenUShopApp();
  1020. });
  1021. }
  1022. }
  1023. if (document.readyState === 'complete') {
  1024. boot();
  1025. } else {
  1026. window.onload = boot;
  1027. }
  1028. })();
  1029. </script>
  1030. </body>
  1031. </html>