shareUndefined.html 31 KB

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