secondShareGoods.html 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  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>商品分享</title>
  8. <style>
  9. :root {
  10. --orange: #F58220;
  11. --price-red: #E62E2E;
  12. --tag-bg: #fff5e9;
  13. --tag-text: #b05b28;
  14. --text: #1a1a1a;
  15. --text-secondary: #999999;
  16. --safe-bottom: env(safe-area-inset-bottom, 0px);
  17. }
  18. * {
  19. margin: 0;
  20. padding: 0;
  21. box-sizing: border-box;
  22. }
  23. html {
  24. font-size: 16px;
  25. -webkit-tap-highlight-color: transparent;
  26. overflow-x: hidden;
  27. }
  28. body {
  29. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  30. background: #fff;
  31. color: var(--text);
  32. min-height: 100vh;
  33. padding-bottom: calc(100px + var(--safe-bottom));
  34. }
  35. .fab-wrap {
  36. position: fixed;
  37. left: 0;
  38. right: 0;
  39. bottom: 0;
  40. z-index: 200;
  41. padding: 12px 24px calc(12px + var(--safe-bottom));
  42. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  43. pointer-events: none;
  44. }
  45. .fab-dock__slot {
  46. width: 100%;
  47. max-width: 198px;
  48. height: 48px;
  49. margin: 0 auto;
  50. pointer-events: auto;
  51. }
  52. #openApp img {
  53. display: block;
  54. width: 100%;
  55. height: 48px;
  56. object-fit: contain;
  57. pointer-events: none;
  58. }
  59. #launch-btn {
  60. display: none;
  61. width: 100%;
  62. height: 48px;
  63. min-height: 48px;
  64. border-radius: 24px;
  65. overflow: hidden;
  66. opacity: 1;
  67. }
  68. body.is-wechat.wx-jssdk-ready #launch-btn {
  69. display: block;
  70. }
  71. body.is-wechat.wx-jssdk-ready #openApp {
  72. display: none !important;
  73. }
  74. .fab-wrap .fab {
  75. pointer-events: auto;
  76. }
  77. #openAppToast {
  78. display: none;
  79. position: fixed;
  80. left: 16px;
  81. right: 16px;
  82. bottom: calc(72px + var(--safe-bottom));
  83. z-index: 10001;
  84. padding: 10px 14px;
  85. font-size: 13px;
  86. line-height: 1.45;
  87. color: #fff;
  88. text-align: center;
  89. background: rgba(0, 0, 0, 0.78);
  90. border-radius: 8px;
  91. pointer-events: none;
  92. word-break: break-all;
  93. }
  94. #openApp {
  95. touch-action: manipulation;
  96. }
  97. .fab {
  98. display: flex;
  99. align-items: center;
  100. justify-content: center;
  101. gap: 10px;
  102. width: 100%;
  103. max-width: 198px;
  104. margin: 0 auto;
  105. height: 48px;
  106. border: none;
  107. border-radius: 24px;
  108. background: #F47D1F;
  109. color: #fff;
  110. font-size: 16px;
  111. font-weight: 600;
  112. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  113. cursor: pointer;
  114. }
  115. .fab__logo {
  116. width: 28px;
  117. height: 28px;
  118. flex-shrink: 0;
  119. }
  120. .home-indicator {
  121. height: 5px;
  122. background: #000;
  123. border-radius: 3px;
  124. width: 134px;
  125. margin: 8px auto 4px;
  126. opacity: 0.2;
  127. }
  128. /* 顶部大图 + 叠字 */
  129. .goods-hero {
  130. position: relative;
  131. width: 100%;
  132. min-height: 58vh;
  133. max-height: 520px;
  134. background: #e8e8e8 center / cover no-repeat;
  135. overflow: hidden;
  136. }
  137. .goods-hero__img {
  138. position: absolute;
  139. inset: 0;
  140. width: 100%;
  141. height: 100%;
  142. object-fit: cover;
  143. display: block;
  144. }
  145. .goods-hero__shade {
  146. position: absolute;
  147. inset: 0;
  148. background: linear-gradient(
  149. 180deg,
  150. rgba(0, 0, 0, 0.35) 0%,
  151. rgba(0, 0, 0, 0.1) 38%,
  152. rgba(0, 0, 0, 0.45) 100%
  153. );
  154. pointer-events: none;
  155. }
  156. .goods-hero__inner {
  157. position: relative;
  158. z-index: 1;
  159. min-height: 58vh;
  160. max-height: 520px;
  161. padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 28px;
  162. display: flex;
  163. flex-direction: column;
  164. justify-content: space-between;
  165. align-items: flex-start;
  166. }
  167. .goods-hero__user {
  168. display: flex;
  169. align-items: center;
  170. gap: 10px;
  171. }
  172. .goods-hero__avatar {
  173. width: 40px;
  174. height: 40px;
  175. border-radius: 50%;
  176. object-fit: cover;
  177. flex-shrink: 0;
  178. background: rgba(255, 255, 255, 0.3);
  179. }
  180. .goods-hero__user-meta {
  181. display: flex;
  182. flex-direction: column;
  183. gap: 2px;
  184. }
  185. .goods-hero__name {
  186. font-size: 15px;
  187. font-weight: 600;
  188. color: #fff;
  189. text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  190. }
  191. .goods-hero__time {
  192. font-size: 12px;
  193. color: rgba(255, 255, 255, 0.82);
  194. text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  195. }
  196. .goods-hero__slogan {
  197. margin-top: auto;
  198. padding-bottom: 4px;
  199. }
  200. .goods-hero__slogan-line {
  201. font-size: 26px;
  202. font-weight: 800;
  203. line-height: 1.25;
  204. color: #fff;
  205. letter-spacing: 0.02em;
  206. text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  207. }
  208. /* 白色内容区 */
  209. .goods-panel {
  210. background: #fff;
  211. border-radius: 16px 16px 0 0;
  212. margin-top: -16px;
  213. position: relative;
  214. z-index: 2;
  215. padding: 20px 16px 24px;
  216. box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
  217. }
  218. .goods-panel__row-price {
  219. display: flex;
  220. align-items: flex-end;
  221. justify-content: space-between;
  222. gap: 12px;
  223. margin-bottom: 14px;
  224. }
  225. .goods-panel__price {
  226. display: flex;
  227. align-items: baseline;
  228. gap: 2px;
  229. color: var(--price-red);
  230. font-weight: 800;
  231. line-height: 1;
  232. }
  233. .goods-panel__price-yen {
  234. font-size: 18px;
  235. }
  236. .goods-panel__price-num {
  237. font-size: 28px;
  238. letter-spacing: -0.02em;
  239. }
  240. .goods-panel__dist {
  241. display: inline-flex;
  242. align-items: center;
  243. gap: 4px;
  244. font-size: 12px;
  245. color: var(--text-secondary);
  246. flex-shrink: 0;
  247. padding-bottom: 2px;
  248. }
  249. .goods-panel__dist svg,
  250. .goods-panel__dist img {
  251. width: 14px;
  252. height: 14px;
  253. opacity: 0.85;
  254. display: block;
  255. flex-shrink: 0;
  256. object-fit: contain;
  257. }
  258. .goods-panel__title {
  259. font-size: 17px;
  260. font-weight: 700;
  261. line-height: 1.45;
  262. color: var(--text);
  263. margin-bottom: 16px;
  264. }
  265. .goods-panel__row-stats {
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. gap: 12px;
  270. margin-bottom: 16px;
  271. }
  272. .goods-panel__stats {
  273. display: flex;
  274. align-items: center;
  275. gap: 18px;
  276. }
  277. .goods-panel__stat {
  278. display: inline-flex;
  279. align-items: center;
  280. gap: 5px;
  281. font-size: 14px;
  282. color: var(--text-secondary);
  283. }
  284. .goods-panel__stat svg {
  285. width: 16px;
  286. height: 16px;
  287. flex-shrink: 0;
  288. }
  289. .goods-panel__stat img {
  290. width: 16px;
  291. height: 16px;
  292. flex-shrink: 0;
  293. display: block;
  294. object-fit: contain;
  295. }
  296. .goods-panel__share {
  297. display: inline-flex;
  298. align-items: center;
  299. gap: 4px;
  300. padding: 0;
  301. border: none;
  302. background: none;
  303. font-size: 14px;
  304. color: var(--text-secondary);
  305. cursor: pointer;
  306. -webkit-tap-highlight-color: transparent;
  307. }
  308. .goods-panel__share svg {
  309. width: 18px;
  310. height: 18px;
  311. }
  312. .goods-panel__tags {
  313. display: flex;
  314. flex-wrap: wrap;
  315. align-items: center;
  316. gap: 8px;
  317. }
  318. .goods-tag {
  319. display: inline-block;
  320. padding: 2px 8px;
  321. border-radius: 4px;
  322. font-size: 12px;
  323. font-weight: 400;
  324. line-height: 1.35;
  325. background: #fff5e9;
  326. }
  327. .goods-tag--topic {
  328. color: #b05b28;
  329. }
  330. .goods-tag--label {
  331. color: #333333;
  332. }
  333. /* 留言 */
  334. .goods-comments {
  335. margin-top: 20px;
  336. padding-top: 20px;
  337. border-top: 1px solid #eee;
  338. }
  339. .goods-comments__head {
  340. display: flex;
  341. align-items: center;
  342. justify-content: space-between;
  343. margin-bottom: 18px;
  344. }
  345. .goods-comments__title {
  346. font-size: 17px;
  347. font-weight: 700;
  348. color: var(--text);
  349. }
  350. .goods-comments__total {
  351. display: inline-flex;
  352. align-items: center;
  353. gap: 4px;
  354. font-size: 14px;
  355. color: #151515;
  356. }
  357. .goods-comments__total svg {
  358. width: 18px;
  359. height: 18px;
  360. opacity: 0.85;
  361. }
  362. .goods-comments__list {
  363. list-style: none;
  364. }
  365. .goods-comments__empty {
  366. list-style: none;
  367. padding: 24px 12px;
  368. text-align: center;
  369. font-size: 14px;
  370. color: var(--text-secondary);
  371. }
  372. .goods-cmt {
  373. padding-bottom: 18px;
  374. margin-bottom: 18px;
  375. border-bottom: 1px solid #eee;
  376. }
  377. .goods-cmt:last-child {
  378. margin-bottom: 0;
  379. padding-bottom: 0;
  380. border-bottom: none;
  381. }
  382. .goods-cmt__row {
  383. display: flex;
  384. align-items: flex-start;
  385. gap: 12px;
  386. }
  387. .goods-cmt__avatar {
  388. width: 40px;
  389. height: 40px;
  390. border-radius: 50%;
  391. object-fit: cover;
  392. background: #e8e8e8;
  393. flex-shrink: 0;
  394. }
  395. .goods-cmt--nested .goods-cmt__avatar {
  396. width: 32px;
  397. height: 32px;
  398. }
  399. .goods-cmt__body {
  400. flex: 1;
  401. min-width: 0;
  402. }
  403. .goods-cmt__name {
  404. font-size: 15px;
  405. font-weight: 700;
  406. color: var(--text);
  407. line-height: 1.3;
  408. }
  409. .goods-cmt__time {
  410. display: block;
  411. margin-top: 2px;
  412. font-size: 12px;
  413. color: var(--text-secondary);
  414. line-height: 1.35;
  415. }
  416. .goods-cmt__text {
  417. margin-top: 10px;
  418. font-size: 15px;
  419. line-height: 1.5;
  420. color: var(--text);
  421. word-break: break-word;
  422. }
  423. .goods-cmt__actions {
  424. display: flex;
  425. align-items: center;
  426. gap: 20px;
  427. margin-top: 12px;
  428. }
  429. .goods-cmt__action {
  430. display: inline-flex;
  431. align-items: center;
  432. gap: 4px;
  433. padding: 0;
  434. border: none;
  435. background: none;
  436. font-size: 13px;
  437. color: var(--text-secondary);
  438. cursor: pointer;
  439. -webkit-tap-highlight-color: transparent;
  440. }
  441. .goods-cmt__action svg {
  442. width: 16px;
  443. height: 16px;
  444. flex-shrink: 0;
  445. opacity: 0.88;
  446. }
  447. .goods-cmt__thread {
  448. margin-top: 14px;
  449. padding-left: 52px;
  450. }
  451. .goods-cmt__replies-inner.is-collapsed {
  452. display: none;
  453. }
  454. .goods-cmt__thread-bar {
  455. display: flex;
  456. align-items: center;
  457. justify-content: space-between;
  458. width: 100%;
  459. margin-top: 10px;
  460. padding: 10px 12px;
  461. border: none;
  462. border-radius: 8px;
  463. background: #f5f5f5;
  464. font-size: 13px;
  465. color: #888;
  466. cursor: pointer;
  467. -webkit-tap-highlight-color: transparent;
  468. }
  469. .goods-cmt__thread-bar-right {
  470. display: inline-flex;
  471. align-items: center;
  472. gap: 4px;
  473. color: var(--text-secondary);
  474. }
  475. .goods-cmt__thread-chevron {
  476. width: 14px;
  477. height: 14px;
  478. transition: transform 0.2s ease;
  479. flex-shrink: 0;
  480. }
  481. .goods-cmt__thread-bar.is-collapsed .goods-cmt__thread-chevron {
  482. transform: rotate(180deg);
  483. }
  484. .goods-cmt--nested {
  485. padding-bottom: 0;
  486. margin-bottom: 0;
  487. border-bottom: none;
  488. }
  489. .goods-cmt--nested .goods-cmt__text {
  490. margin-top: 8px;
  491. }
  492. </style>
  493. </head>
  494. <body>
  495. <section class="goods-hero" id="goodsHero" aria-label="商品配图">
  496. <img class="goods-hero__img" id="goodsHeroImg" src="" alt="">
  497. <div class="goods-hero__shade" aria-hidden="true"></div>
  498. <div class="goods-hero__inner">
  499. <div class="goods-hero__user">
  500. <img class="goods-hero__avatar" id="goodsUserAvatar" src="images/demouser.png" alt="">
  501. <div class="goods-hero__user-meta">
  502. <span class="goods-hero__name" id="goodsUserName">维尼</span>
  503. <span class="goods-hero__time" id="goodsTimeAgo">11小时前</span>
  504. </div>
  505. </div>
  506. <div class="goods-hero__slogan" id="goodsHeroSloganWrap" style="display:none;">
  507. <div class="goods-hero__slogan-line" id="goodsSlogan1"></div>
  508. <div class="goods-hero__slogan-line" id="goodsSlogan2"></div>
  509. </div>
  510. </div>
  511. </section>
  512. <div class="goods-panel">
  513. <div class="goods-panel__row-price">
  514. <div class="goods-panel__price">
  515. <span class="goods-panel__price-yen">¥</span>
  516. <span class="goods-panel__price-num" id="goodsPrice">690.00</span>
  517. </div>
  518. <div class="goods-panel__dist">
  519. <img src="images/juli.svg" alt="" width="14" height="14" decoding="async" aria-hidden="true">
  520. <span id="goodsDistance">距离 2.5km</span>
  521. </div>
  522. </div>
  523. <h1 class="goods-panel__title" id="goodsTitle">HCK哈士奇BC-330RDE烤漆复古冰箱家用大容量单门冰柜高颜值网红</h1>
  524. <div class="goods-panel__row-stats">
  525. <div class="goods-panel__stats">
  526. <span class="goods-panel__stat goods-panel__stat--hot" id="goodsHotStat">
  527. <img src="images/huo.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
  528. <span id="goodsHotCount" style="color:#151515;">510</span>
  529. </span>
  530. <span class="goods-panel__stat">
  531. <img src="images/xing.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
  532. <span id="goodsFavCount" style="color:#151515;">260</span>
  533. </span>
  534. </div>
  535. </div>
  536. <div class="goods-panel__tags" id="goodsTags"></div>
  537. <section class="goods-comments" id="goodsComments" aria-label="留言">
  538. <div class="goods-comments__head">
  539. <h2 class="goods-comments__title">留言</h2>
  540. <div class="goods-comments__total">
  541. <img src="images/liuyan.svg" alt="" width="16" height="16" decoding="async" aria-hidden="true">
  542. <span id="goodsCommentTotal">24</span>
  543. </div>
  544. </div>
  545. <ul class="goods-comments__list" id="goodsCommentList"></ul>
  546. </section>
  547. </div>
  548. <div id="openAppToast" role="status" aria-live="polite"></div>
  549. <div class="fab-wrap">
  550. <div class="fab-dock__slot">
  551. <button type="button" class="fab" id="openApp">
  552. <img src="images/uBtn.png" alt="APP内打开" decoding="async">
  553. </button>
  554. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  555. <script type="text/wxtag-template">
  556. <style>
  557. .wx-open-app-btn {
  558. display: block;
  559. width: 100%;
  560. height: 48px;
  561. margin: 0;
  562. padding: 0;
  563. border: none;
  564. border-radius: 24px;
  565. background: #F47D1F;
  566. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  567. cursor: pointer;
  568. overflow: hidden;
  569. -webkit-tap-highlight-color: transparent;
  570. }
  571. .wx-open-app-btn img {
  572. display: block;
  573. width: 100%;
  574. height: 48px;
  575. object-fit: contain;
  576. opacity: 1;
  577. pointer-events: none;
  578. -webkit-user-drag: none;
  579. }
  580. </style>
  581. <button class="wx-open-app-btn" aria-label="APP内打开">
  582. <img src="https://test.ailien.shop/h5/HBuilderProjects/images/uBtn.png" alt="APP内打开" width="198" height="48" />
  583. </button>
  584. </script>
  585. </wx-open-launch-app>
  586. </div>
  587. <div class="home-indicator" aria-hidden="true"></div>
  588. </div>
  589. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  590. <script>
  591. (function () {
  592. 'use strict';
  593. /**
  594. * 进入页仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在(不用其 data 渲染页面):
  595. * POST {API_BASE_SECOND}/recommend/querySecondGoodsDetailWithOutJWT
  596. * body:goodsId、longitude、latitude、phoneId
  597. * 不存在/已下架/删除 → shareUndefined;存在 → applyFromUrl(分享链参数)+ 留言列表
  598. */
  599. /**
  600. * 唤起 App 落地:二手商品详情(与 pages.json 路径一致)
  601. */
  602. var APP_ANDROID_PACKAGE = 'com.alien.Udianzaizhe';
  603. var APP_IOS_URL_SCHEME = 'shopro://';
  604. var APP_UNI_STORE_PATH = 'pages/secondHandTransactions/pages/detail/index';
  605. var API_BASE = 'https://test.ailien.shop/alienStore';
  606. /**
  607. * 微信 JSSDK — 与 shareIndex.html 一致
  608. * POST {API_BASE}/wx/getWxConfig,body 传 url(当前页完整地址,不含 #)
  609. */
  610. var WECHAT_MP_APP_ID = 'wx412792c77f47babd';
  611. var WECHAT_OPEN_APP_ID = 'wxf5f1efe3a9f5012e';
  612. var WECHAT_GET_WX_CONFIG_PATH = '/wx/getWxConfig';
  613. var H5_PAGE_BASE_FALLBACK = 'https://test.ailien.shop/h5/HBuilderProjects/';
  614. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + 'secondShareGoods.html';
  615. var WECHAT_JS_SAFE_HOSTS = ['uat.ailien.shop', 'test.ailien.shop'];
  616. var weChatJssdkConfigured = false;
  617. var wxConfigSignRetriedBaseUrl = false;
  618. var wxInitLastError = '';
  619. var wxJssdkInitPromise = null;
  620. function showDownloadTip() {
  621. var msg = '请到应用商店下载';
  622. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  623. uni.showToast({ title: msg, icon: 'none', duration: 2500 });
  624. } else {
  625. window.alert(msg);
  626. }
  627. }
  628. function mergeSearchAndHashParams() {
  629. var params = new URLSearchParams();
  630. function ingestAppend(querySlice) {
  631. if (!querySlice) return;
  632. var p = new URLSearchParams(querySlice);
  633. p.forEach(function (val, key) {
  634. params.append(key, val);
  635. });
  636. }
  637. function ingestSet(querySlice) {
  638. if (!querySlice) return;
  639. var p = new URLSearchParams(querySlice);
  640. p.forEach(function (val, key) {
  641. params.set(key, val);
  642. });
  643. }
  644. if (location.search && location.search.length > 1) {
  645. ingestAppend(location.search.slice(1));
  646. }
  647. var hash = location.hash || '';
  648. var qi = hash.indexOf('?');
  649. if (qi >= 0) {
  650. ingestSet(hash.slice(qi + 1));
  651. }
  652. return params;
  653. }
  654. function q(name) {
  655. var v = mergeSearchAndHashParams().get(name);
  656. return v == null ? '' : String(v);
  657. }
  658. function buildAppOpenQueryStringMerged() {
  659. var params = mergeSearchAndHashParams();
  660. var gid = params.get('goodsId') || params.get('id') || '';
  661. if (gid && !params.has('goodsId')) {
  662. params.set('goodsId', gid);
  663. }
  664. var sid = params.get('storeId') || params.get('id') || '';
  665. if (sid && !params.has('storeId')) {
  666. params.set('storeId', sid);
  667. }
  668. var qsOut = params.toString();
  669. return qsOut ? ('?' + qsOut) : '';
  670. }
  671. function getSecondGoodsAppUniPath() {
  672. return String(APP_UNI_STORE_PATH || 'pages/secondHandTransactions/pages/detail/index').replace(
  673. /^\//,
  674. ''
  675. );
  676. }
  677. function buildAppDeepLink() {
  678. var path = getSecondGoodsAppUniPath();
  679. var s = buildAppOpenQueryStringMerged();
  680. var root = APP_IOS_URL_SCHEME.replace(/\/$/, '');
  681. if (!s) {
  682. return root + '/' + path;
  683. }
  684. return root + '/' + path + s;
  685. }
  686. /** Uni 路由串(无 shopro://),供 wx-open-launch-app extinfo */
  687. function buildAppUniPageLaunchUrl() {
  688. var path = getSecondGoodsAppUniPath();
  689. var qs = buildAppOpenQueryStringMerged().replace(/^\?/, '');
  690. return qs ? path + '?' + qs : path;
  691. }
  692. /**
  693. * wx-open-launch-app extinfo:pages/secondHandTransactions/pages/detail/index?goodsId=…
  694. */
  695. function buildWeChatLaunchExtinfo() {
  696. var uniPage = buildAppUniPageLaunchUrl();
  697. if (uniPage.length <= 1024) return uniPage;
  698. var params = mergeSearchAndHashParams();
  699. var mini = new URLSearchParams();
  700. var goodsId = params.get('goodsId') || params.get('id') || '';
  701. if (goodsId) mini.set('goodsId', goodsId);
  702. var path = getSecondGoodsAppUniPath();
  703. var shortPage = path + '?' + mini.toString();
  704. if (shortPage.length <= 1024) return shortPage;
  705. return shortPage.slice(0, 1024);
  706. }
  707. function isWeChatInAppBrowser() {
  708. return /MicroMessenger/i.test(navigator.userAgent || '');
  709. }
  710. /**
  711. * 复制链接进入常无 from=;与点击分享卡片对齐,在拉 getWxConfig 前补 from=singlemessage(不刷新页面)。
  712. */
  713. function ensureWxShareFromQueryBeforeConfig() {
  714. if (!isWeChatInAppBrowser()) return;
  715. var from = String(q('from') || '').trim();
  716. if (from) return;
  717. try {
  718. var u = new URL(location.href);
  719. u.searchParams.set('from', 'singlemessage');
  720. history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
  721. } catch (eFrom) {
  722. var sep = location.search && location.search.length > 1 ? '&' : '?';
  723. history.replaceState(
  724. null,
  725. '',
  726. location.pathname +
  727. (location.search || '') +
  728. sep +
  729. 'from=singlemessage' +
  730. (location.hash || '')
  731. );
  732. }
  733. }
  734. function logWxEntryDiagnostics() {
  735. if (!isWeChatInAppBrowser()) return;
  736. console.log('[wx-entry]', {
  737. entryFrom: q('from') || '(无)',
  738. signUrl: getWxConfigSignUrl()
  739. });
  740. }
  741. function readQueryParam(name) {
  742. return q(name);
  743. }
  744. function isWxDebugOn() {
  745. return readQueryParam('wxDebug') === '1';
  746. }
  747. function isWxForceDebug() {
  748. return readQueryParam('wxForce') === '1';
  749. }
  750. function isWxConfigOnClickDebug() {
  751. return readQueryParam('wxConfigOnClick') === '1';
  752. }
  753. function isWxPcAutoDebugHost() {
  754. var h = (location.hostname || '').toLowerCase();
  755. if (h === 'localhost' || h === '127.0.0.1') return true;
  756. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  757. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  758. }
  759. return false;
  760. }
  761. function isWxPcBrowser() {
  762. return !isWeChatInAppBrowser();
  763. }
  764. function shouldInitWeChatJssdkOnLoad() {
  765. if (isWeChatInAppBrowser()) return true;
  766. return isWxForceDebug() || isWxPcAutoDebugHost();
  767. }
  768. function shouldFetchWxConfig(fromUserClick) {
  769. if (isWeChatInAppBrowser()) return true;
  770. if (fromUserClick) return true;
  771. return isWxForceDebug() || isWxPcAutoDebugHost();
  772. }
  773. function getWxHtmlUrl() {
  774. var forced = String(q('wxSignUrl') || '').trim();
  775. if (forced) return forced.split('#')[0];
  776. return String(location.href || '').split('#')[0];
  777. }
  778. function getWxSignPageUrlForApi() {
  779. var htmlUrl = getWxHtmlUrl();
  780. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  781. return WX_GET_CONFIG_SIGN_URL;
  782. }
  783. function getWxHtmlUrlBase() {
  784. var htmlUrl = getWxSignPageUrlForApi();
  785. try {
  786. var u = new URL(htmlUrl);
  787. return u.origin + u.pathname;
  788. } catch (eU) {
  789. return WX_GET_CONFIG_SIGN_URL;
  790. }
  791. }
  792. function getWxConfigSignUrl() {
  793. if (String(q('wxSignBaseOnly') || '') === '1') return getWxHtmlUrlBase();
  794. return getWxSignPageUrlForApi();
  795. }
  796. function getWxGetConfigApiUrl() {
  797. return API_BASE.replace(/\/$/, '') + WECHAT_GET_WX_CONFIG_PATH;
  798. }
  799. function buildWxGetConfigRequestBody(htmlUrl) {
  800. return {
  801. url: String(htmlUrl || '').split('#')[0].trim()
  802. };
  803. }
  804. function resolveWxConfigAppIdFromSignData(d) {
  805. if (!d || typeof d !== 'object') return '';
  806. var mp =
  807. d.mpAppId ||
  808. d.mpAppid ||
  809. d.officialAppId ||
  810. d.gzhAppId ||
  811. d.serviceAppId;
  812. if (mp != null && String(mp).trim() !== '') return String(mp).trim();
  813. var fromQuery = String(q('wxMpAppId') || WECHAT_MP_APP_ID || '').trim();
  814. if (fromQuery) return fromQuery;
  815. var raw = d.appId || d.appid || d.wxAppId;
  816. return raw != null && String(raw).trim() !== '' ? String(raw).trim() : '';
  817. }
  818. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  819. if (!res || typeof res !== 'object') return null;
  820. var d = res.data != null && typeof res.data === 'object' ? res.data : res;
  821. if (!d || typeof d !== 'object') return null;
  822. var appId = resolveWxConfigAppIdFromSignData(d);
  823. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  824. var nonceStr =
  825. d.nonceStr != null && String(d.nonceStr) !== ''
  826. ? d.nonceStr
  827. : d.noncestr != null && String(d.noncestr) !== ''
  828. ? d.noncestr
  829. : d.nonce;
  830. var signature = d.signature || d.sign;
  831. if (!appId || timestamp == null || nonceStr == null || nonceStr === '' || !signature) {
  832. return null;
  833. }
  834. return {
  835. appId: String(appId),
  836. timestamp: Number(timestamp),
  837. nonceStr: String(nonceStr),
  838. signature: String(signature),
  839. signUrl: String(signUrlUsed || '')
  840. .split('#')[0]
  841. .trim()
  842. };
  843. }
  844. function getWxErrMsg(err) {
  845. if (!err) return '';
  846. if (err.errMsg) return String(err.errMsg);
  847. if (typeof err === 'string') return err;
  848. try {
  849. return JSON.stringify(err);
  850. } catch (e) {
  851. return String(err);
  852. }
  853. }
  854. function formatWxConfigErrorTip(err, signPageUrl) {
  855. var errMsg = getWxErrMsg(err);
  856. var tip = '微信 JSSDK 配置失败';
  857. if (/invalid signature/i.test(errMsg)) {
  858. return (
  859. tip +
  860. ':签名无效。url=' +
  861. (signPageUrl || getWxHtmlUrl()) +
  862. ';appId=' +
  863. WECHAT_MP_APP_ID
  864. );
  865. }
  866. if (/require\s*subscribe/i.test(errMsg)) {
  867. return tip + ':' + errMsg + '(服务号需用户已关注)';
  868. }
  869. return errMsg ? tip + ':' + errMsg : tip;
  870. }
  871. function setWxInitError(msg) {
  872. wxInitLastError = String(msg || '').trim();
  873. if (wxInitLastError) console.warn('[wx]', wxInitLastError);
  874. }
  875. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  876. var htmlUrl = String(
  877. htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl()
  878. )
  879. .split('#')[0]
  880. .trim();
  881. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  882. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  883. }
  884. if (isWxDebugOn()) {
  885. try {
  886. window.alert('htmlUrl(签名用):\n' + htmlUrl);
  887. } catch (eDbg) {}
  888. }
  889. var requestUrl = getWxGetConfigApiUrl();
  890. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  891. console.log('[wx] htmlUrl=', htmlUrl);
  892. console.log('[wx] POST getWxConfig →', requestUrl, requestBody);
  893. return fetch(requestUrl, {
  894. method: 'POST',
  895. mode: 'cors',
  896. credentials: 'omit',
  897. headers: {
  898. Accept: 'application/json',
  899. 'Content-Type': 'application/json;charset=UTF-8'
  900. },
  901. body: JSON.stringify(requestBody)
  902. })
  903. .then(function (r) {
  904. if (r.ok) return r.json();
  905. return r
  906. .text()
  907. .catch(function () {
  908. return '';
  909. })
  910. .then(function (text) {
  911. var hint = '';
  912. try {
  913. var j = JSON.parse(text);
  914. hint = j.msg || j.message || '';
  915. } catch (eP) {
  916. if (text) hint = text.slice(0, 120);
  917. }
  918. throw new Error('getWxConfig HTTP ' + r.status + (hint ? ':' + hint : ''));
  919. });
  920. })
  921. .then(function (res) {
  922. if (res && res.code != null) {
  923. var c = Number(res.code);
  924. if (c !== 200 && c !== 0 && res.success !== true) {
  925. throw new Error(res.msg || res.message || 'getWxConfig code ' + c);
  926. }
  927. }
  928. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  929. if (!sign) {
  930. console.warn('[wx] getWxConfig 响应字段不全', res, 'htmlUrl=', htmlUrl);
  931. throw new Error(
  932. 'getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)'
  933. );
  934. }
  935. if (sign.appId !== WECHAT_MP_APP_ID) {
  936. console.warn(
  937. '[wx] 后端 appId=' + sign.appId + ',期望服务号 ' + WECHAT_MP_APP_ID
  938. );
  939. }
  940. if (typeof wx === 'undefined') {
  941. if (isWxPcBrowser()) {
  942. console.log('[wx] PC getWxConfig 成功(无 jweixin)', sign);
  943. return true;
  944. }
  945. setWxInitError('jweixin.js 未加载');
  946. return false;
  947. }
  948. return applyWxConfigFromSign(sign, htmlUrl);
  949. });
  950. }
  951. function applyWxConfigFromSign(sign, htmlUrl) {
  952. var wxConfigParams = {
  953. debug: isWxDebugOn(),
  954. appId: String(sign.appId),
  955. timestamp: sign.timestamp,
  956. nonceStr: String(sign.nonceStr),
  957. signature: String(sign.signature),
  958. jsApiList: [],
  959. openTagList: ['wx-open-launch-app']
  960. };
  961. return new Promise(function (resolve) {
  962. wx.config(wxConfigParams);
  963. wx.ready(function () {
  964. weChatJssdkConfigured = true;
  965. document.body.classList.add('wx-jssdk-ready');
  966. refreshWxLaunchTagAttrs();
  967. console.log('[wx.config] ready, htmlUrl=', htmlUrl);
  968. resolve(true);
  969. });
  970. wx.error(function (err) {
  971. weChatJssdkConfigured = false;
  972. document.body.classList.remove('wx-jssdk-ready');
  973. wxJssdkInitPromise = null;
  974. var errMsg = getWxErrMsg(err);
  975. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  976. if (isWxDebugOn()) window.alert(wxInitLastError);
  977. console.warn('[wx.config]', errMsg, 'htmlUrl=', htmlUrl);
  978. var baseUrl = getWxHtmlUrlBase();
  979. var fullUrl = getWxSignPageUrlForApi();
  980. if (
  981. !/invalid signature/i.test(errMsg) ||
  982. wxConfigSignRetriedBaseUrl ||
  983. baseUrl === fullUrl ||
  984. htmlUrl === baseUrl
  985. ) {
  986. resolve(false);
  987. return;
  988. }
  989. wxConfigSignRetriedBaseUrl = true;
  990. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  991. });
  992. });
  993. }
  994. function refreshWxLaunchTagAttrs() {
  995. var tag = document.getElementById('launch-btn');
  996. if (!tag) return;
  997. try {
  998. tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  999. tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
  1000. } catch (eA) {}
  1001. }
  1002. function bindWeChatLaunchTagEvents() {
  1003. var tag = document.getElementById('launch-btn');
  1004. if (!tag || tag._wxLaunchBound) return;
  1005. tag._wxLaunchBound = true;
  1006. refreshWxLaunchTagAttrs();
  1007. tag.addEventListener('launch', function () {
  1008. console.log('[wx-open-launch-app] launch ok');
  1009. // showFabToast('正在打开 U店在哪…');
  1010. });
  1011. tag.addEventListener('error', function (e) {
  1012. var detail = e && e.detail;
  1013. var errMsg =
  1014. detail && detail.errMsg
  1015. ? String(detail.errMsg)
  1016. : detail && detail.errmsg
  1017. ? String(detail.errmsg)
  1018. : '';
  1019. console.warn('[wx-open-launch-app]', detail);
  1020. showAppOpenFailTip(
  1021. '请确复制链接进入U店在哪'
  1022. );
  1023. });
  1024. }
  1025. function initWeChatOpenLaunchApp(fromUserClick) {
  1026. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1027. return Promise.resolve(false);
  1028. }
  1029. ensureWxShareFromQueryBeforeConfig();
  1030. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1031. wxConfigSignRetriedBaseUrl = false;
  1032. wxInitLastError = '';
  1033. var htmlUrl = getWxConfigSignUrl();
  1034. bindWeChatLaunchTagEvents();
  1035. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1036. .then(function (ok) {
  1037. if (ok === true) return true;
  1038. if (!wxInitLastError) {
  1039. setWxInitError('wx.config 失败,可加 ?wxDebug=1');
  1040. }
  1041. return false;
  1042. })
  1043. .catch(function (e) {
  1044. var msg = e && e.message ? e.message : 'getWxConfig 请求失败';
  1045. setWxInitError(msg);
  1046. console.warn('[wx] init failed', msg, 'htmlUrl=', htmlUrl);
  1047. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1048. return false;
  1049. })
  1050. .finally(function () {
  1051. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1052. });
  1053. return wxJssdkInitPromise;
  1054. }
  1055. function scheduleWeChatJssdkBootstrap() {
  1056. if (!shouldInitWeChatJssdkOnLoad()) return;
  1057. var attempts = 0;
  1058. function tick() {
  1059. attempts += 1;
  1060. if (weChatJssdkConfigured) return;
  1061. initWeChatOpenLaunchApp();
  1062. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === 'undefined') {
  1063. setTimeout(tick, 400);
  1064. }
  1065. }
  1066. tick();
  1067. }
  1068. function showFabToast(msg, ms) {
  1069. var tip = String(msg || '').trim();
  1070. if (!tip) return;
  1071. var el = document.getElementById('openAppToast');
  1072. if (el) {
  1073. el.textContent = tip;
  1074. el.style.display = 'block';
  1075. if (showFabToast._t) clearTimeout(showFabToast._t);
  1076. showFabToast._t = setTimeout(function () {
  1077. el.style.display = 'none';
  1078. }, ms || 2800);
  1079. }
  1080. console.log('[openApp]', tip);
  1081. }
  1082. function showAppOpenFailTip(msg) {
  1083. var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
  1084. if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
  1085. uni.showToast({ title: tip, icon: 'none', duration: 2800 });
  1086. } else if (isWeChatInAppBrowser()) {
  1087. window.alert(tip);
  1088. } else {
  1089. console.warn('[openApp]', tip);
  1090. }
  1091. }
  1092. function tryFetchWxConfigOnPcClick() {
  1093. if (!isWxPcBrowser()) return Promise.resolve(false);
  1094. showFabToast('正在请求 getWxConfig…');
  1095. wxJssdkInitPromise = null;
  1096. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1097. if (ok) {
  1098. showFabToast(
  1099. weChatJssdkConfigured
  1100. ? 'getWxConfig 成功,wx.config 已就绪'
  1101. : 'getWxConfig 成功'
  1102. );
  1103. } else {
  1104. showFabToast(wxInitLastError || 'getWxConfig 失败');
  1105. }
  1106. return ok;
  1107. });
  1108. }
  1109. function launchAppDeepLink(deepLink) {
  1110. try {
  1111. var a = document.createElement('a');
  1112. a.href = deepLink;
  1113. a.setAttribute('target', '_self');
  1114. document.body.appendChild(a);
  1115. a.click();
  1116. document.body.removeChild(a);
  1117. } catch (e1) {}
  1118. try {
  1119. window.location.href = deepLink;
  1120. } catch (e2) {}
  1121. }
  1122. function tryOpenHBuilderApp() {
  1123. if (isWeChatInAppBrowser()) return;
  1124. tryFetchWxConfigOnPcClick().then(function () {
  1125. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1126. return;
  1127. }
  1128. tryOpenHBuilderAppViaScheme();
  1129. });
  1130. }
  1131. function tryOpenHBuilderAppViaScheme() {
  1132. // showFabToast('正在打开 U店在哪…');
  1133. var deepLink = buildAppDeepLink();
  1134. if (typeof plus !== 'undefined' && plus.runtime) {
  1135. var installed = null;
  1136. try {
  1137. if (typeof plus.runtime.isApplicationExist === 'function') {
  1138. installed = plus.runtime.isApplicationExist({
  1139. pname: APP_ANDROID_PACKAGE,
  1140. action: APP_IOS_URL_SCHEME
  1141. });
  1142. }
  1143. } catch (e) {
  1144. console.warn(e);
  1145. }
  1146. if (installed === false) {
  1147. showDownloadTip();
  1148. return;
  1149. }
  1150. try {
  1151. plus.runtime.openURL(deepLink);
  1152. } catch (e2) {
  1153. console.warn(e2);
  1154. showDownloadTip();
  1155. }
  1156. return;
  1157. }
  1158. var t0 = Date.now();
  1159. var done = false;
  1160. function finish() {
  1161. if (done) return;
  1162. done = true;
  1163. document.removeEventListener('visibilitychange', onVis);
  1164. window.removeEventListener('pagehide', onHide);
  1165. }
  1166. function onVis() {
  1167. if (document.visibilityState === 'hidden') finish();
  1168. }
  1169. function onHide() {
  1170. finish();
  1171. }
  1172. document.addEventListener('visibilitychange', onVis);
  1173. window.addEventListener('pagehide', onHide);
  1174. try {
  1175. launchAppDeepLink(deepLink);
  1176. } catch (e3) {
  1177. finish();
  1178. showDownloadTip();
  1179. return;
  1180. }
  1181. window.setTimeout(function () {
  1182. finish();
  1183. }, 2600);
  1184. }
  1185. function tryDecode(s) {
  1186. s = String(s || '');
  1187. if (!s) return '';
  1188. try {
  1189. return decodeURIComponent(s.replace(/\+/g, ' '));
  1190. } catch (e) {
  1191. return s;
  1192. }
  1193. }
  1194. var DEFAULT_HERO = '';
  1195. /** 二手商品接口前缀;可用 URL 参数 alienSecondBase / secondApiBase 覆盖 */
  1196. function resolveSecondApiBase() {
  1197. var custom = (q('alienSecondBase') || q('secondApiBase') || '').trim();
  1198. if (custom) {
  1199. return custom.replace(/\/+$/, '');
  1200. }
  1201. var host = (location.hostname || '').toLowerCase();
  1202. if (host === 'test.ailien.shop' || host === 'uat.ailien.shop') {
  1203. return 'https://test.ailien.shop/alienSecond';
  1204. }
  1205. return 'http://120.26.186.130:8000/alienSecond';
  1206. }
  1207. var API_BASE_SECOND = resolveSecondApiBase();
  1208. /** 与 querySecondGoodsDetailWithOutJWT 表单一致;优先地址栏,否则默认坐标 */
  1209. var DEFAULT_REQUEST_LONGITUDE =
  1210. (q('longitude') || q('lon') || q('jingdu') || '').trim() || '121.662527';
  1211. var DEFAULT_REQUEST_LATITUDE =
  1212. (q('latitude') || q('lat') || q('weidu') || '').trim() || '38.925754';
  1213. var COMMENT_SOURCE_TYPE = 4;
  1214. function apiGet(path) {
  1215. return fetch(API_BASE + path, {
  1216. method: 'GET',
  1217. mode: 'cors',
  1218. credentials: 'omit',
  1219. headers: { Accept: 'application/json' }
  1220. }).then(function (res) {
  1221. if (!res.ok) throw new Error('HTTP ' + res.status);
  1222. return res.json();
  1223. });
  1224. }
  1225. function apiPostJson(path, body) {
  1226. return fetch(API_BASE + path, {
  1227. method: 'POST',
  1228. mode: 'cors',
  1229. credentials: 'omit',
  1230. headers: {
  1231. Accept: 'application/json',
  1232. 'Content-Type': 'application/json'
  1233. },
  1234. body: JSON.stringify(body || {})
  1235. }).then(function (res) {
  1236. if (!res.ok) throw new Error('HTTP ' + res.status);
  1237. return res.json();
  1238. });
  1239. }
  1240. function pick(d, keys) {
  1241. if (!d || typeof d !== 'object') return null;
  1242. for (var i = 0; i < keys.length; i++) {
  1243. var k = keys[i];
  1244. if (d[k] != null && d[k] !== '') return d[k];
  1245. }
  1246. return null;
  1247. }
  1248. function isApiOk(res) {
  1249. if (!res || typeof res !== 'object') return false;
  1250. if (res.success === false) return false;
  1251. var c = res.code;
  1252. return c === 200 || c === '200' || Number(c) === 200;
  1253. }
  1254. /** 二手详情存在性接口:兼容 code 0 / success:true(与 alienSecond 常见返回一致) */
  1255. function isSecondGoodsExistOk(res) {
  1256. if (!res || typeof res !== 'object') return false;
  1257. if (res.success === false) return false;
  1258. if (res.success === true) return true;
  1259. var c = res.code;
  1260. if (c === 200 || c === '200' || Number(c) === 200) return true;
  1261. if (c === 0 || c === '0' || Number(c) === 0) return true;
  1262. return false;
  1263. }
  1264. function pickSecondGoodsDetailData(res) {
  1265. if (!res || typeof res !== 'object') return null;
  1266. var d = res.data != null ? res.data : res.result;
  1267. if (d == null) return null;
  1268. if (Array.isArray(d)) {
  1269. return d.length && typeof d[0] === 'object' ? d[0] : null;
  1270. }
  1271. if (typeof d !== 'object') return null;
  1272. var inner =
  1273. d.secondGoodsDetail ||
  1274. d.goodsDetail ||
  1275. d.goodsInfo ||
  1276. d.detail ||
  1277. d.record;
  1278. if (inner && typeof inner === 'object' && !Array.isArray(inner)) {
  1279. return inner;
  1280. }
  1281. return d;
  1282. }
  1283. /** 详情里是否有可识别的商品实体(有则视为存在,不依赖 goodsStatus 数值) */
  1284. function hasSecondGoodsDetailPayload(d) {
  1285. if (!d || typeof d !== 'object') return false;
  1286. var id = d.goodsId != null ? d.goodsId : d.id;
  1287. if (id != null && String(id).trim() !== '' && String(id).trim() !== '0') {
  1288. return true;
  1289. }
  1290. var name = d.goodsName || d.title || d.secondGoodsTitle || d.name;
  1291. if (name != null && String(name).trim() !== '') return true;
  1292. var img =
  1293. d.coverUrl ||
  1294. d.mainImage ||
  1295. d.goodsImage ||
  1296. d.firstImage ||
  1297. (Array.isArray(d.goodsImageList) && d.goodsImageList[0]);
  1298. if (img != null && String(img).trim() !== '') return true;
  1299. return Object.keys(d).length > 0;
  1300. }
  1301. function isDetailDataExplicitlyDeleted(d) {
  1302. if (!d || typeof d !== 'object') return false;
  1303. if (d.deleteFlag === 1 || d.deleteFlag === '1' || Number(d.deleteFlag) === 1) {
  1304. return true;
  1305. }
  1306. if (d.deleted === true || d.isDelete === 1 || d.isDelete === '1') {
  1307. return true;
  1308. }
  1309. return false;
  1310. }
  1311. function isMsgIndicateGoodsGone(msg) {
  1312. msg = String(msg || '').trim();
  1313. if (!msg) return false;
  1314. return /已删除|已下架|已卖出|商品不存在|不存在该|查无此商品|找不到该商品|商品不可用/.test(
  1315. msg
  1316. );
  1317. }
  1318. function fmtPriceNum(v) {
  1319. var n = v != null ? Number(v) : NaN;
  1320. return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
  1321. }
  1322. /** kind: topic(#话题 棕橙)| label(分类名 深灰,不带 #) */
  1323. function appendGoodsTag(mount, raw, kind) {
  1324. if (!mount || raw == null) return;
  1325. var s = String(raw).trim();
  1326. if (!s) return;
  1327. var span = document.createElement('span');
  1328. span.className =
  1329. 'goods-tag ' + (kind === 'label' ? 'goods-tag--label' : 'goods-tag--topic');
  1330. if (kind === 'label') {
  1331. span.textContent = s.replace(/^#+/, '');
  1332. } else {
  1333. span.textContent = s.indexOf('#') === 0 ? s : '#' + s;
  1334. }
  1335. mount.appendChild(span);
  1336. }
  1337. function renderGoodsDetail(d) {
  1338. if (!d || typeof d !== 'object') return;
  1339. var title = pick(d, ['goodsName', 'title', 'secondGoodsTitle', 'name']);
  1340. if (title) {
  1341. var el = document.getElementById('goodsTitle');
  1342. if (el) el.textContent = String(title);
  1343. }
  1344. var price = pick(d, ['price', 'goodsPrice', 'salePrice', 'currentPrice', 'amount']);
  1345. if (price != null) {
  1346. var pe = document.getElementById('goodsPrice');
  1347. if (pe) pe.textContent = fmtPriceNum(price);
  1348. }
  1349. var dist = pick(d, ['dist', 'distance', 'distanceText', 'distanceDesc', 'distanceDescription', 'distanceKm']);
  1350. if (dist != null) {
  1351. var dt = String(dist).trim();
  1352. if (dt) {
  1353. if (!/^距离/.test(dt)) dt = '距离 ' + dt;
  1354. if (!/km$/i.test(dt) && !/千米/.test(dt) && !/米/.test(dt) && !/\s*m\s*$/i.test(dt)) {
  1355. dt = dt.replace(/\s+$/, '') + 'km';
  1356. }
  1357. var de = document.getElementById('goodsDistance');
  1358. if (de) de.textContent = dt;
  1359. }
  1360. }
  1361. var img =
  1362. pick(d, ['coverUrl', 'mainImage', 'goodsImage', 'firstImage', 'bannerUrl']) ||
  1363. (Array.isArray(d.goodsImageList) && d.goodsImageList[0]) ||
  1364. (Array.isArray(d.imageList) && d.imageList[0]);
  1365. if (img) {
  1366. var hi = document.getElementById('goodsHeroImg');
  1367. if (hi) {
  1368. hi.src = String(img);
  1369. hi.alt = '商品图';
  1370. }
  1371. }
  1372. var nick = pick(d, ['publishUserNick', 'userNickName', 'nickName', 'userName', 'publisherName']);
  1373. if (nick) {
  1374. var ne = document.getElementById('goodsUserName');
  1375. if (ne) ne.textContent = String(nick);
  1376. }
  1377. var av = pick(d, ['publishUserAvatar', 'userAvatar', 'userHead', 'avatar', 'headImg']);
  1378. if (av) {
  1379. var ae = document.getElementById('goodsUserAvatar');
  1380. if (ae) ae.src = String(av);
  1381. }
  1382. var tm = pick(d, ['timeAgo', 'releaseTime', 'publishTime', 'createTime', 'publishTimeStr']);
  1383. if (tm) {
  1384. var te = document.getElementById('goodsTimeAgo');
  1385. if (te) te.textContent = String(tm);
  1386. }
  1387. var s1 = pick(d, ['promotionLineOne', 'promotionTitle', 'subtitle', 'slogan1', 'line1']);
  1388. var s2 = pick(d, ['promotionLineTwo', 'subTitle', 'slogan2', 'line2']);
  1389. var wrap = document.getElementById('goodsHeroSloganWrap');
  1390. var e1 = document.getElementById('goodsSlogan1');
  1391. var e2 = document.getElementById('goodsSlogan2');
  1392. if (wrap && e1 && e2) {
  1393. if (s1 || s2) {
  1394. if (s1) e1.textContent = String(s1);
  1395. if (s2) e2.textContent = String(s2);
  1396. wrap.style.display = '';
  1397. } else {
  1398. wrap.style.display = 'none';
  1399. }
  1400. }
  1401. var hotStat = document.getElementById('goodsHotStat');
  1402. var cs = pick(d, ['collectStatus']);
  1403. if (hotStat) {
  1404. var hideHot =
  1405. cs != null &&
  1406. (Number(cs) === 0 || String(cs).trim() === '0');
  1407. hotStat.style.display = hideHot ? 'none' : '';
  1408. }
  1409. var hot = pick(d, ['browseCount', 'viewCount', 'hotCount', 'readCount']);
  1410. if (hot != null) {
  1411. var he = document.getElementById('goodsHotCount');
  1412. if (he) he.textContent = String(hot);
  1413. }
  1414. var fav = pick(d, ['collectCount', 'wantCount', 'favCount', 'favoriteCount']);
  1415. if (fav != null) {
  1416. var fe = document.getElementById('goodsFavCount');
  1417. if (fe) fe.textContent = String(fav);
  1418. }
  1419. var topicStr = d.topic != null ? String(d.topic).trim() : '';
  1420. var labelStr = d.label != null ? String(d.label).trim() : '';
  1421. var hasApiTags = topicStr !== '' || labelStr !== '';
  1422. var mount = document.getElementById('goodsTags');
  1423. if (mount) {
  1424. if (hasApiTags) {
  1425. mount.innerHTML = '';
  1426. if (topicStr) appendGoodsTag(mount, topicStr, 'topic');
  1427. if (labelStr) appendGoodsTag(mount, labelStr, 'label');
  1428. } else {
  1429. var tags = d.tagList || d.tags || d.labelList || d.goodsTags;
  1430. if (tags) {
  1431. mount.innerHTML = '';
  1432. var arr = Array.isArray(tags) ? tags : String(tags).split(/[,,]/);
  1433. arr.forEach(function (t) {
  1434. if (t == null || t === '') return;
  1435. var label =
  1436. typeof t === 'object'
  1437. ? (t.tagName || t.name || t.label || '')
  1438. : String(t);
  1439. label = String(label).trim();
  1440. if (!label) return;
  1441. var isTopic = label.indexOf('#') === 0;
  1442. appendGoodsTag(mount, label, isTopic ? 'topic' : 'label');
  1443. });
  1444. }
  1445. }
  1446. }
  1447. }
  1448. var SVG_LIKE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"/></svg>';
  1449. var SVG_REPLY = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';
  1450. var SVG_CHEV = '<svg class="goods-cmt__thread-chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>';
  1451. function cmtAvatarUrl(c) {
  1452. return String(
  1453. pick(c, ['headImg', 'userAvatar', 'userHead', 'avatar', 'avatarUrl']) || ''
  1454. ).trim();
  1455. }
  1456. function cmtUserName(c) {
  1457. var s = String(pick(c, ['headName', 'userName', 'nickName', 'userNickName', 'commentUserName', 'headPhone']) || '—').trim();
  1458. return s || '—';
  1459. }
  1460. function cmtTime(c) {
  1461. return String(pick(c, ['createTime', 'createdTime', 'commentTime']) || '');
  1462. }
  1463. function cmtContent(c) {
  1464. return String(pick(c, ['content', 'commentContent', 'text']) || '');
  1465. }
  1466. function cmtLikeCount(c) {
  1467. var v = pick(c, ['likeCount', 'likeNum', 'praiseCount']);
  1468. return v != null ? String(v) : '0';
  1469. }
  1470. function cmtReplies(c) {
  1471. if (!c || typeof c !== 'object') return [];
  1472. var sub =
  1473. c.childCommonComments ||
  1474. c.replyList ||
  1475. c.replyVOList ||
  1476. c.children ||
  1477. c.subComments ||
  1478. c.replies;
  1479. if (sub == null) return [];
  1480. return Array.isArray(sub) ? sub.filter(Boolean) : [];
  1481. }
  1482. function appendCmtRow(parentBody, c, showReply) {
  1483. var row = document.createElement('div');
  1484. row.className = 'goods-cmt__row';
  1485. var img = document.createElement('img');
  1486. img.className = 'goods-cmt__avatar';
  1487. img.alt = '';
  1488. var au = cmtAvatarUrl(c);
  1489. img.src = au || 'images/demouser.png';
  1490. var body = document.createElement('div');
  1491. body.className = 'goods-cmt__body';
  1492. var name = document.createElement('span');
  1493. name.className = 'goods-cmt__name';
  1494. name.textContent = cmtUserName(c);
  1495. var time = document.createElement('span');
  1496. time.className = 'goods-cmt__time';
  1497. time.textContent = cmtTime(c);
  1498. var text = document.createElement('p');
  1499. text.className = 'goods-cmt__text';
  1500. text.textContent = cmtContent(c);
  1501. var actions = document.createElement('div');
  1502. actions.className = 'goods-cmt__actions';
  1503. var likeBtn = document.createElement('button');
  1504. likeBtn.type = 'button';
  1505. likeBtn.className = 'goods-cmt__action';
  1506. likeBtn.setAttribute('aria-label', '点赞');
  1507. likeBtn.innerHTML = SVG_LIKE + '<span>' + cmtLikeCount(c) + '</span>';
  1508. actions.appendChild(likeBtn);
  1509. if (showReply) {
  1510. var repBtn = document.createElement('button');
  1511. repBtn.type = 'button';
  1512. repBtn.className = 'goods-cmt__action';
  1513. repBtn.setAttribute('aria-label', '回复');
  1514. repBtn.innerHTML = SVG_REPLY + '<span>回复</span>';
  1515. actions.appendChild(repBtn);
  1516. }
  1517. body.appendChild(name);
  1518. body.appendChild(time);
  1519. body.appendChild(text);
  1520. body.appendChild(actions);
  1521. row.appendChild(img);
  1522. row.appendChild(body);
  1523. parentBody.appendChild(row);
  1524. return body;
  1525. }
  1526. function buildNestedCmt(c) {
  1527. var wrap = document.createElement('div');
  1528. wrap.className = 'goods-cmt goods-cmt--nested';
  1529. appendCmtRow(wrap, c, false);
  1530. return wrap;
  1531. }
  1532. function filterTopLevelComments(list) {
  1533. if (!Array.isArray(list) || !list.length) return [];
  1534. var top = list.filter(function (c) {
  1535. if (!c) return false;
  1536. var pid = c.parentId != null ? c.parentId : c.pid;
  1537. if (typeof pid === 'string') pid = pid.trim();
  1538. return pid == null || pid === '' || Number(pid) === 0;
  1539. });
  1540. return top.length ? top : list.slice();
  1541. }
  1542. function countCommentsInApiList(records) {
  1543. if (!Array.isArray(records)) return 0;
  1544. var tops = filterTopLevelComments(records);
  1545. var n = 0;
  1546. for (var i = 0; i < tops.length; i++) {
  1547. var c = tops[i];
  1548. if (!c) continue;
  1549. n += 1 + cmtReplies(c).length;
  1550. }
  1551. return n;
  1552. }
  1553. function normalizeCommentListPayload(d) {
  1554. if (typeof d === 'string') {
  1555. try {
  1556. d = JSON.parse(d);
  1557. } catch (e) {
  1558. return { records: [], total: 0 };
  1559. }
  1560. }
  1561. if (Array.isArray(d)) {
  1562. return { records: d, total: countCommentsInApiList(d) };
  1563. }
  1564. if (d && typeof d === 'object') {
  1565. var arr = d.records || d.list || d.rows;
  1566. if (!Array.isArray(arr) && Array.isArray(d.data)) arr = d.data;
  1567. if (!Array.isArray(arr)) arr = [];
  1568. var total =
  1569. d.total != null && !isNaN(Number(d.total))
  1570. ? Number(d.total)
  1571. : countCommentsInApiList(arr);
  1572. return { records: arr, total: total };
  1573. }
  1574. return { records: [], total: 0 };
  1575. }
  1576. function renderCommentsList(rows, total) {
  1577. var mount = document.getElementById('goodsCommentList');
  1578. var totEl = document.getElementById('goodsCommentTotal');
  1579. if (!mount) return;
  1580. mount.innerHTML = '';
  1581. var list = filterTopLevelComments(Array.isArray(rows) ? rows : []);
  1582. var n = total != null && !isNaN(Number(total)) ? Number(total) : countCommentsInApiList(Array.isArray(rows) ? rows : []);
  1583. if (totEl) totEl.textContent = String(n);
  1584. if (!list.length) {
  1585. var empty = document.createElement('li');
  1586. empty.className = 'goods-comments__empty';
  1587. empty.setAttribute('role', 'status');
  1588. empty.textContent = '暂无留言';
  1589. mount.appendChild(empty);
  1590. return;
  1591. }
  1592. list.forEach(function (c) {
  1593. if (!c) return;
  1594. var li = document.createElement('li');
  1595. li.className = 'goods-cmt';
  1596. appendCmtRow(li, c, true);
  1597. var replies = cmtReplies(c);
  1598. if (replies.length) {
  1599. var thread = document.createElement('div');
  1600. thread.className = 'goods-cmt__thread';
  1601. var inner = document.createElement('div');
  1602. inner.className = 'goods-cmt__replies-inner';
  1603. replies.forEach(function (r) {
  1604. if (r) inner.appendChild(buildNestedCmt(r));
  1605. });
  1606. var bar = document.createElement('button');
  1607. bar.type = 'button';
  1608. bar.className = 'goods-cmt__thread-bar';
  1609. bar.setAttribute('aria-expanded', 'true');
  1610. bar.innerHTML =
  1611. '<span>共<span class="js-reply-count">' + replies.length + '</span>条回复</span>' +
  1612. '<span class="goods-cmt__thread-bar-right">' +
  1613. '<span class="js-thread-label">收起</span>' + SVG_CHEV + '</span>';
  1614. thread.appendChild(inner);
  1615. thread.appendChild(bar);
  1616. li.appendChild(thread);
  1617. }
  1618. mount.appendChild(li);
  1619. });
  1620. }
  1621. function bindCommentThreadDelegation() {
  1622. var list = document.getElementById('goodsCommentList');
  1623. if (!list || list.dataset.threadDeleg) return;
  1624. list.dataset.threadDeleg = '1';
  1625. list.addEventListener('click', function (e) {
  1626. var bar = e.target.closest('.goods-cmt__thread-bar');
  1627. if (!bar) return;
  1628. var inner = bar.previousElementSibling;
  1629. if (!inner || !inner.classList.contains('goods-cmt__replies-inner')) return;
  1630. var collapsed = inner.classList.toggle('is-collapsed');
  1631. bar.classList.toggle('is-collapsed', collapsed);
  1632. bar.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
  1633. var lab = bar.querySelector('.js-thread-label');
  1634. if (lab) lab.textContent = collapsed ? '展开' : '收起';
  1635. });
  1636. }
  1637. function buildShareUndefinedRedirectQuery(gs, ctx) {
  1638. ctx = ctx || {};
  1639. var uq = new URLSearchParams();
  1640. uq.set('goodsUnavailable', '1');
  1641. if (gs != null && String(gs).trim() !== '') {
  1642. uq.set('goodsStatus', String(gs).trim());
  1643. }
  1644. if (ctx.userId) uq.set('userId', String(ctx.userId));
  1645. if (ctx.longitude) uq.set('longitude', String(ctx.longitude));
  1646. if (ctx.latitude) uq.set('latitude', String(ctx.latitude));
  1647. if (ctx.userCity) uq.set('userCity', String(ctx.userCity));
  1648. var gid = ctx.goodsId || '';
  1649. if (gid) {
  1650. uq.set('goodsId', String(gid));
  1651. uq.set('id', String(gid));
  1652. }
  1653. return uq;
  1654. }
  1655. function redirectToShareUndefined(gs, ctx) {
  1656. window.location.replace(
  1657. 'shareUndefined.html?' + buildShareUndefinedRedirectQuery(gs, ctx).toString()
  1658. );
  1659. }
  1660. /**
  1661. * 存在性接口只判断「有没有商品数据」,不用 goodsStatus(在售也可能是 2)。
  1662. * 仅 deleteFlag/明确删除文案/无 data 且接口失败 时视为不可用。
  1663. */
  1664. function isDetailResponseGoodsUnavailable(res) {
  1665. if (!res || typeof res !== 'object') return true;
  1666. var d = pickSecondGoodsDetailData(res);
  1667. if (hasSecondGoodsDetailPayload(d)) {
  1668. return isDetailDataExplicitlyDeleted(d);
  1669. }
  1670. var msg = res.msg != null ? String(res.msg) : '';
  1671. if (isMsgIndicateGoodsGone(msg)) {
  1672. return true;
  1673. }
  1674. if (isSecondGoodsExistOk(res)) {
  1675. return false;
  1676. }
  1677. return true;
  1678. }
  1679. /**
  1680. * 仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在,不渲染接口返回的详情字段
  1681. * @returns {Promise<{redirected:boolean, exists:boolean}>}
  1682. */
  1683. function checkSecondGoodsExists(goodsId, lon, lat, phoneId, redirectCtx) {
  1684. var lonStr =
  1685. lon != null && String(lon).trim() !== ''
  1686. ? String(lon).trim()
  1687. : String(DEFAULT_REQUEST_LONGITUDE);
  1688. var latStr =
  1689. lat != null && String(lat).trim() !== ''
  1690. ? String(lat).trim()
  1691. : String(DEFAULT_REQUEST_LATITUDE);
  1692. var pid =
  1693. phoneId != null && String(phoneId).trim() !== ''
  1694. ? String(phoneId).trim()
  1695. : '';
  1696. /** 表单字段:键为 string,值一律 string(x-www-form-urlencoded) */
  1697. var formBody = {
  1698. goodsId: String(goodsId != null ? goodsId : '').trim(),
  1699. longitude: String(lonStr),
  1700. latitude: String(latStr),
  1701. phoneId: pid
  1702. };
  1703. var form = new URLSearchParams();
  1704. form.set('goodsId', formBody.goodsId);
  1705. form.set('longitude', formBody.longitude);
  1706. form.set('latitude', formBody.latitude);
  1707. form.set('phoneId', formBody.phoneId);
  1708. var detailUrl =
  1709. API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT';
  1710. var formStr = form.toString();
  1711. return fetch(detailUrl, {
  1712. method: 'POST',
  1713. mode: 'cors',
  1714. credentials: 'omit',
  1715. headers: {
  1716. Accept: 'application/json',
  1717. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  1718. },
  1719. body: formStr
  1720. })
  1721. .then(function (res) {
  1722. if (!res.ok) throw new Error('HTTP ' + res.status);
  1723. return res.json();
  1724. })
  1725. .then(function (res) {
  1726. redirectCtx = redirectCtx || {};
  1727. var d = pickSecondGoodsDetailData(res);
  1728. if (isDetailResponseGoodsUnavailable(res)) {
  1729. console.warn(
  1730. '[querySecondGoodsDetailWithOutJWT] unavailable',
  1731. res && res.code,
  1732. res && res.msg,
  1733. d
  1734. );
  1735. redirectToShareUndefined(null, redirectCtx);
  1736. return { redirected: true, exists: false };
  1737. }
  1738. return { redirected: false, exists: true };
  1739. });
  1740. }
  1741. function fetchCommentList(goodsId, userId, pageNum, pageSize) {
  1742. var st = (q('sourceType') || '').trim();
  1743. var sourceType = st && !isNaN(Number(st)) ? Number(st) : COMMENT_SOURCE_TYPE;
  1744. var path = '/commonComment/getListBySourceType?' +
  1745. 'sourceType=' + encodeURIComponent(String(sourceType)) +
  1746. '&sourceId=' + encodeURIComponent(String(goodsId)) +
  1747. '&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
  1748. '&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
  1749. '&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
  1750. return apiGet(path).then(function (res) {
  1751. if (!isApiOk(res)) {
  1752. if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
  1753. renderCommentsList([], 0);
  1754. return;
  1755. }
  1756. var raw = res.data != null ? res.data : res.result;
  1757. var pack = normalizeCommentListPayload(raw);
  1758. renderCommentsList(pack.records, pack.total);
  1759. });
  1760. }
  1761. function run() {
  1762. var goodsId = (q('goodsId') || q('id') || '').trim();
  1763. var userId = (q('userId') || '').trim();
  1764. var phoneId = (q('phoneId') || q('phone_id') || '').trim();
  1765. var lon = (q('longitude') || q('lon') || q('jingdu') || '').trim();
  1766. var lat = (q('latitude') || q('lat') || q('weidu') || '').trim();
  1767. var userCity = (q('userCity') || q('city') || '').trim();
  1768. var lonResolved = lon || DEFAULT_REQUEST_LONGITUDE;
  1769. var latResolved = lat || DEFAULT_REQUEST_LATITUDE;
  1770. var pageNum = (q('pageNum') || '1').trim();
  1771. var pageSize = (q('pageSize') || '10').trim();
  1772. var redirectCtx = {
  1773. goodsId: goodsId,
  1774. userId: userId,
  1775. longitude: lonResolved,
  1776. latitude: latResolved,
  1777. userCity: userCity
  1778. };
  1779. bindCommentThreadDelegation();
  1780. /* 分享卡片应带 goodsId;勿因 URL 残留 goodsUnavailable=1 跳过存在性校验直接进不可用页 */
  1781. if (
  1782. !goodsId &&
  1783. String(q('goodsUnavailable') || '').trim() === '1'
  1784. ) {
  1785. redirectToShareUndefined(q('goodsStatus'), redirectCtx);
  1786. return;
  1787. }
  1788. if (!goodsId) {
  1789. applyFromUrl();
  1790. return;
  1791. }
  1792. checkSecondGoodsExists(goodsId, lon, lat, phoneId, redirectCtx)
  1793. .catch(function (e) {
  1794. console.warn('[querySecondGoodsDetailWithOutJWT]', e);
  1795. return { redirected: false, exists: null, checkFailed: true };
  1796. })
  1797. .then(function (checkResult) {
  1798. if (checkResult && checkResult.redirected) {
  1799. return;
  1800. }
  1801. applyFromUrl();
  1802. return fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
  1803. console.warn('[getListBySourceType]', e);
  1804. renderCommentsList([], 0);
  1805. });
  1806. });
  1807. }
  1808. function applyFromUrl() {
  1809. var heroImg = document.getElementById('goodsHeroImg');
  1810. var imgUrl = q('image') || q('goodsImage') || q('coverUrl') || q('img');
  1811. imgUrl = tryDecode(imgUrl).trim();
  1812. if (imgUrl) {
  1813. heroImg.src = imgUrl;
  1814. heroImg.alt = '商品图';
  1815. } else {
  1816. heroImg.src = DEFAULT_HERO;
  1817. heroImg.alt = '';
  1818. }
  1819. var av = tryDecode(q('userImage') || q('avatar')).trim();
  1820. document.getElementById('goodsUserAvatar').src = av || 'images/demouser.png';
  1821. var uname = tryDecode(q('userName') || q('nickname')).trim();
  1822. if (uname) document.getElementById('goodsUserName').textContent = uname;
  1823. var ago = tryDecode(q('timeAgo') || q('publishTime')).trim();
  1824. if (ago) document.getElementById('goodsTimeAgo').textContent = ago;
  1825. var s1 = tryDecode(q('slogan1') || q('line1')).trim();
  1826. var s2 = tryDecode(q('slogan2') || q('line2')).trim();
  1827. var elS1 = document.getElementById('goodsSlogan1');
  1828. var elS2 = document.getElementById('goodsSlogan2');
  1829. var elWrap = document.getElementById('goodsHeroSloganWrap');
  1830. if (s1 && elS1) elS1.textContent = s1;
  1831. if (s2 && elS2) elS2.textContent = s2;
  1832. if (elWrap && (s1 || s2)) elWrap.style.display = '';
  1833. var price = tryDecode(q('price')).trim();
  1834. if (price) {
  1835. var pn = parseFloat(price.replace(/[^\d.]/g, ''));
  1836. document.getElementById('goodsPrice').textContent =
  1837. !isNaN(pn) ? pn.toFixed(2) : price;
  1838. }
  1839. var dist = tryDecode(q('distance') || q('distanceKm') || q('dist')).trim();
  1840. if (dist) {
  1841. if (!/^距离/.test(dist)) dist = '距离 ' + dist;
  1842. if (!/km$/i.test(dist) && !/千米/.test(dist) && !/米/.test(dist) && !/\s*m\s*$/i.test(dist)) {
  1843. dist = dist.replace(/\s+$/, '') + 'km';
  1844. }
  1845. document.getElementById('goodsDistance').textContent = dist;
  1846. }
  1847. var title = tryDecode(q('title') || q('goodsTitle')).trim();
  1848. if (title) document.getElementById('goodsTitle').textContent = title;
  1849. var hot = tryDecode(q('hotCount') || q('hot')).trim();
  1850. if (hot) document.getElementById('goodsHotCount').textContent = hot;
  1851. var fav = tryDecode(q('favCount') || q('fav') || q('collectCount')).trim();
  1852. if (fav) document.getElementById('goodsFavCount').textContent = fav;
  1853. var cc = tryDecode(q('commentCount') || q('comments')).trim();
  1854. if (cc) {
  1855. var elTot = document.getElementById('goodsCommentTotal');
  1856. if (elTot) elTot.textContent = cc;
  1857. }
  1858. var tagsRaw = tryDecode(q('tags') || q('tag')).trim();
  1859. var mount = document.getElementById('goodsTags');
  1860. var hasGoodsId = (q('goodsId') || q('id') || '').trim();
  1861. if (mount) {
  1862. if (tagsRaw) {
  1863. mount.innerHTML = '';
  1864. tagsRaw.split(/[,,]/).map(function (t) { return t.trim(); }).filter(Boolean).forEach(function (t) {
  1865. appendGoodsTag(mount, t, t.indexOf('#') === 0 ? 'topic' : 'label');
  1866. });
  1867. } else if (!hasGoodsId) {
  1868. mount.innerHTML = '';
  1869. ['复古冰箱', '网红冰箱', '复古烤漆', '冰箱'].forEach(function (t) {
  1870. appendGoodsTag(mount, t, 'label');
  1871. });
  1872. }
  1873. }
  1874. }
  1875. function sharePage() {
  1876. var title = document.getElementById('goodsTitle').textContent || '商品分享';
  1877. var url = location.href;
  1878. if (navigator.share) {
  1879. navigator.share({ title: title, text: title, url: url }).catch(function () {});
  1880. return;
  1881. }
  1882. if (navigator.clipboard && navigator.clipboard.writeText) {
  1883. navigator.clipboard.writeText(url).then(function () {
  1884. window.alert('链接已复制');
  1885. }).catch(function () {
  1886. window.prompt('复制链接', url);
  1887. });
  1888. } else {
  1889. window.prompt('复制链接', url);
  1890. }
  1891. }
  1892. var shareBtn = document.getElementById('goodsShareBtn');
  1893. if (shareBtn) shareBtn.addEventListener('click', sharePage);
  1894. function boot() {
  1895. var launchTag = document.getElementById('launch-btn');
  1896. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1897. bindWeChatLaunchTagEvents();
  1898. if (isWeChatInAppBrowser()) {
  1899. document.body.classList.add('is-wechat');
  1900. ensureWxShareFromQueryBeforeConfig();
  1901. logWxEntryDiagnostics();
  1902. }
  1903. if (shouldInitWeChatJssdkOnLoad()) {
  1904. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1905. document.body.classList.add('wx-pc-debug');
  1906. }
  1907. scheduleWeChatJssdkBootstrap();
  1908. }
  1909. document.addEventListener('WeixinOpenTagsError', function (e) {
  1910. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1911. });
  1912. if (isWeChatInAppBrowser()) {
  1913. var openBtnWx = document.getElementById('openApp');
  1914. if (openBtnWx) {
  1915. openBtnWx.addEventListener('click', function () {
  1916. if (!weChatJssdkConfigured) {
  1917. showFabToast(
  1918. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1919. );
  1920. }
  1921. });
  1922. }
  1923. } else {
  1924. var openAppBtn = document.getElementById('openApp');
  1925. if (openAppBtn) {
  1926. openAppBtn.addEventListener('click', tryOpenHBuilderApp);
  1927. }
  1928. }
  1929. run();
  1930. }
  1931. if (document.readyState === 'complete') {
  1932. boot();
  1933. } else {
  1934. window.onload = boot;
  1935. }
  1936. })();
  1937. </script>
  1938. </body>
  1939. </html>