secondShareGoods.html 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  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. * 商品详情:POST https://test.ailien.shop/alienSecond/recommend/querySecondGoodsDetail
  595. * body: application/x-www-form-urlencoded(「表单数据」);键 goodsId、longitude、latitude,值均为字符串;经纬度未传时用默认 121.662567 / 38.925757
  596. * 留言:GET {API_BASE}/commonComment/getListBySourceType — 成功时 data 常为数组;项含 parentId、childCommonComments、headName、headImg、createdTime、content、likeCount
  597. * URL 常用:goodsId、userId、longitude/lon/jingdu、latitude/lat/weidu、pageNum、pageSize、sourceType(含 hash 内 ? 参数)
  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. /** 二手商品等业务接口前缀(与 alienStore 分离) */
  1196. var API_BASE_SECOND = 'https://test.ailien.shop/alienSecond';
  1197. /** 与接口调试「表单数据」一致;优先取地址栏 longitude/latitude,未带时用默认坐标 */
  1198. var DEFAULT_REQUEST_LONGITUDE =
  1199. (q('longitude') || q('lon') || q('jingdu') || '').trim() || '121.662567';
  1200. var DEFAULT_REQUEST_LATITUDE =
  1201. (q('latitude') || q('lat') || q('weidu') || '').trim() || '38.925757';
  1202. var COMMENT_SOURCE_TYPE = 4;
  1203. function apiGet(path) {
  1204. return fetch(API_BASE + path, {
  1205. method: 'GET',
  1206. mode: 'cors',
  1207. credentials: 'omit',
  1208. headers: { Accept: 'application/json' }
  1209. }).then(function (res) {
  1210. if (!res.ok) throw new Error('HTTP ' + res.status);
  1211. return res.json();
  1212. });
  1213. }
  1214. function apiPostJson(path, body) {
  1215. return fetch(API_BASE + path, {
  1216. method: 'POST',
  1217. mode: 'cors',
  1218. credentials: 'omit',
  1219. headers: {
  1220. Accept: 'application/json',
  1221. 'Content-Type': 'application/json'
  1222. },
  1223. body: JSON.stringify(body || {})
  1224. }).then(function (res) {
  1225. if (!res.ok) throw new Error('HTTP ' + res.status);
  1226. return res.json();
  1227. });
  1228. }
  1229. function pick(d, keys) {
  1230. if (!d || typeof d !== 'object') return null;
  1231. for (var i = 0; i < keys.length; i++) {
  1232. var k = keys[i];
  1233. if (d[k] != null && d[k] !== '') return d[k];
  1234. }
  1235. return null;
  1236. }
  1237. function isApiOk(res) {
  1238. if (!res || typeof res !== 'object') return false;
  1239. if (res.success === false) return false;
  1240. var c = res.code;
  1241. return c === 200 || c === '200' || Number(c) === 200;
  1242. }
  1243. function fmtPriceNum(v) {
  1244. var n = v != null ? Number(v) : NaN;
  1245. return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
  1246. }
  1247. /** kind: topic(#话题 棕橙)| label(分类名 深灰,不带 #) */
  1248. function appendGoodsTag(mount, raw, kind) {
  1249. if (!mount || raw == null) return;
  1250. var s = String(raw).trim();
  1251. if (!s) return;
  1252. var span = document.createElement('span');
  1253. span.className =
  1254. 'goods-tag ' + (kind === 'label' ? 'goods-tag--label' : 'goods-tag--topic');
  1255. if (kind === 'label') {
  1256. span.textContent = s.replace(/^#+/, '');
  1257. } else {
  1258. span.textContent = s.indexOf('#') === 0 ? s : '#' + s;
  1259. }
  1260. mount.appendChild(span);
  1261. }
  1262. function renderGoodsDetail(d) {
  1263. if (!d || typeof d !== 'object') return;
  1264. var title = pick(d, ['goodsName', 'title', 'secondGoodsTitle', 'name']);
  1265. if (title) {
  1266. var el = document.getElementById('goodsTitle');
  1267. if (el) el.textContent = String(title);
  1268. }
  1269. var price = pick(d, ['price', 'goodsPrice', 'salePrice', 'currentPrice', 'amount']);
  1270. if (price != null) {
  1271. var pe = document.getElementById('goodsPrice');
  1272. if (pe) pe.textContent = fmtPriceNum(price);
  1273. }
  1274. var dist = pick(d, ['dist', 'distance', 'distanceText', 'distanceDesc', 'distanceDescription', 'distanceKm']);
  1275. if (dist != null) {
  1276. var dt = String(dist).trim();
  1277. if (dt) {
  1278. if (!/^距离/.test(dt)) dt = '距离 ' + dt;
  1279. if (!/km$/i.test(dt) && !/千米/.test(dt) && !/米/.test(dt) && !/\s*m\s*$/i.test(dt)) {
  1280. dt = dt.replace(/\s+$/, '') + 'km';
  1281. }
  1282. var de = document.getElementById('goodsDistance');
  1283. if (de) de.textContent = dt;
  1284. }
  1285. }
  1286. var img =
  1287. pick(d, ['coverUrl', 'mainImage', 'goodsImage', 'firstImage', 'bannerUrl']) ||
  1288. (Array.isArray(d.goodsImageList) && d.goodsImageList[0]) ||
  1289. (Array.isArray(d.imageList) && d.imageList[0]);
  1290. if (img) {
  1291. var hi = document.getElementById('goodsHeroImg');
  1292. if (hi) {
  1293. hi.src = String(img);
  1294. hi.alt = '商品图';
  1295. }
  1296. }
  1297. var nick = pick(d, ['publishUserNick', 'userNickName', 'nickName', 'userName', 'publisherName']);
  1298. if (nick) {
  1299. var ne = document.getElementById('goodsUserName');
  1300. if (ne) ne.textContent = String(nick);
  1301. }
  1302. var av = pick(d, ['publishUserAvatar', 'userAvatar', 'userHead', 'avatar', 'headImg']);
  1303. if (av) {
  1304. var ae = document.getElementById('goodsUserAvatar');
  1305. if (ae) ae.src = String(av);
  1306. }
  1307. var tm = pick(d, ['timeAgo', 'releaseTime', 'publishTime', 'createTime', 'publishTimeStr']);
  1308. if (tm) {
  1309. var te = document.getElementById('goodsTimeAgo');
  1310. if (te) te.textContent = String(tm);
  1311. }
  1312. var s1 = pick(d, ['promotionLineOne', 'promotionTitle', 'subtitle', 'slogan1', 'line1']);
  1313. var s2 = pick(d, ['promotionLineTwo', 'subTitle', 'slogan2', 'line2']);
  1314. var wrap = document.getElementById('goodsHeroSloganWrap');
  1315. var e1 = document.getElementById('goodsSlogan1');
  1316. var e2 = document.getElementById('goodsSlogan2');
  1317. if (wrap && e1 && e2) {
  1318. if (s1 || s2) {
  1319. if (s1) e1.textContent = String(s1);
  1320. if (s2) e2.textContent = String(s2);
  1321. wrap.style.display = '';
  1322. } else {
  1323. wrap.style.display = 'none';
  1324. }
  1325. }
  1326. var hotStat = document.getElementById('goodsHotStat');
  1327. var cs = pick(d, ['collectStatus']);
  1328. if (hotStat) {
  1329. var hideHot =
  1330. cs != null &&
  1331. (Number(cs) === 0 || String(cs).trim() === '0');
  1332. hotStat.style.display = hideHot ? 'none' : '';
  1333. }
  1334. var hot = pick(d, ['browseCount', 'viewCount', 'hotCount', 'readCount']);
  1335. if (hot != null) {
  1336. var he = document.getElementById('goodsHotCount');
  1337. if (he) he.textContent = String(hot);
  1338. }
  1339. var fav = pick(d, ['collectCount', 'wantCount', 'favCount', 'favoriteCount']);
  1340. if (fav != null) {
  1341. var fe = document.getElementById('goodsFavCount');
  1342. if (fe) fe.textContent = String(fav);
  1343. }
  1344. var topicStr = d.topic != null ? String(d.topic).trim() : '';
  1345. var labelStr = d.label != null ? String(d.label).trim() : '';
  1346. var hasApiTags = topicStr !== '' || labelStr !== '';
  1347. var mount = document.getElementById('goodsTags');
  1348. if (mount) {
  1349. if (hasApiTags) {
  1350. mount.innerHTML = '';
  1351. if (topicStr) appendGoodsTag(mount, topicStr, 'topic');
  1352. if (labelStr) appendGoodsTag(mount, labelStr, 'label');
  1353. } else {
  1354. var tags = d.tagList || d.tags || d.labelList || d.goodsTags;
  1355. if (tags) {
  1356. mount.innerHTML = '';
  1357. var arr = Array.isArray(tags) ? tags : String(tags).split(/[,,]/);
  1358. arr.forEach(function (t) {
  1359. if (t == null || t === '') return;
  1360. var label =
  1361. typeof t === 'object'
  1362. ? (t.tagName || t.name || t.label || '')
  1363. : String(t);
  1364. label = String(label).trim();
  1365. if (!label) return;
  1366. var isTopic = label.indexOf('#') === 0;
  1367. appendGoodsTag(mount, label, isTopic ? 'topic' : 'label');
  1368. });
  1369. }
  1370. }
  1371. }
  1372. }
  1373. 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>';
  1374. 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>';
  1375. 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>';
  1376. function cmtAvatarUrl(c) {
  1377. return String(
  1378. pick(c, ['headImg', 'userAvatar', 'userHead', 'avatar', 'avatarUrl']) || ''
  1379. ).trim();
  1380. }
  1381. function cmtUserName(c) {
  1382. var s = String(pick(c, ['headName', 'userName', 'nickName', 'userNickName', 'commentUserName', 'headPhone']) || '—').trim();
  1383. return s || '—';
  1384. }
  1385. function cmtTime(c) {
  1386. return String(pick(c, ['createTime', 'createdTime', 'commentTime']) || '');
  1387. }
  1388. function cmtContent(c) {
  1389. return String(pick(c, ['content', 'commentContent', 'text']) || '');
  1390. }
  1391. function cmtLikeCount(c) {
  1392. var v = pick(c, ['likeCount', 'likeNum', 'praiseCount']);
  1393. return v != null ? String(v) : '0';
  1394. }
  1395. function cmtReplies(c) {
  1396. if (!c || typeof c !== 'object') return [];
  1397. var sub =
  1398. c.childCommonComments ||
  1399. c.replyList ||
  1400. c.replyVOList ||
  1401. c.children ||
  1402. c.subComments ||
  1403. c.replies;
  1404. if (sub == null) return [];
  1405. return Array.isArray(sub) ? sub.filter(Boolean) : [];
  1406. }
  1407. function appendCmtRow(parentBody, c, showReply) {
  1408. var row = document.createElement('div');
  1409. row.className = 'goods-cmt__row';
  1410. var img = document.createElement('img');
  1411. img.className = 'goods-cmt__avatar';
  1412. img.alt = '';
  1413. var au = cmtAvatarUrl(c);
  1414. img.src = au || 'images/demouser.png';
  1415. var body = document.createElement('div');
  1416. body.className = 'goods-cmt__body';
  1417. var name = document.createElement('span');
  1418. name.className = 'goods-cmt__name';
  1419. name.textContent = cmtUserName(c);
  1420. var time = document.createElement('span');
  1421. time.className = 'goods-cmt__time';
  1422. time.textContent = cmtTime(c);
  1423. var text = document.createElement('p');
  1424. text.className = 'goods-cmt__text';
  1425. text.textContent = cmtContent(c);
  1426. var actions = document.createElement('div');
  1427. actions.className = 'goods-cmt__actions';
  1428. var likeBtn = document.createElement('button');
  1429. likeBtn.type = 'button';
  1430. likeBtn.className = 'goods-cmt__action';
  1431. likeBtn.setAttribute('aria-label', '点赞');
  1432. likeBtn.innerHTML = SVG_LIKE + '<span>' + cmtLikeCount(c) + '</span>';
  1433. actions.appendChild(likeBtn);
  1434. if (showReply) {
  1435. var repBtn = document.createElement('button');
  1436. repBtn.type = 'button';
  1437. repBtn.className = 'goods-cmt__action';
  1438. repBtn.setAttribute('aria-label', '回复');
  1439. repBtn.innerHTML = SVG_REPLY + '<span>回复</span>';
  1440. actions.appendChild(repBtn);
  1441. }
  1442. body.appendChild(name);
  1443. body.appendChild(time);
  1444. body.appendChild(text);
  1445. body.appendChild(actions);
  1446. row.appendChild(img);
  1447. row.appendChild(body);
  1448. parentBody.appendChild(row);
  1449. return body;
  1450. }
  1451. function buildNestedCmt(c) {
  1452. var wrap = document.createElement('div');
  1453. wrap.className = 'goods-cmt goods-cmt--nested';
  1454. appendCmtRow(wrap, c, false);
  1455. return wrap;
  1456. }
  1457. function filterTopLevelComments(list) {
  1458. if (!Array.isArray(list) || !list.length) return [];
  1459. var top = list.filter(function (c) {
  1460. if (!c) return false;
  1461. var pid = c.parentId != null ? c.parentId : c.pid;
  1462. if (typeof pid === 'string') pid = pid.trim();
  1463. return pid == null || pid === '' || Number(pid) === 0;
  1464. });
  1465. return top.length ? top : list.slice();
  1466. }
  1467. function countCommentsInApiList(records) {
  1468. if (!Array.isArray(records)) return 0;
  1469. var tops = filterTopLevelComments(records);
  1470. var n = 0;
  1471. for (var i = 0; i < tops.length; i++) {
  1472. var c = tops[i];
  1473. if (!c) continue;
  1474. n += 1 + cmtReplies(c).length;
  1475. }
  1476. return n;
  1477. }
  1478. function normalizeCommentListPayload(d) {
  1479. if (typeof d === 'string') {
  1480. try {
  1481. d = JSON.parse(d);
  1482. } catch (e) {
  1483. return { records: [], total: 0 };
  1484. }
  1485. }
  1486. if (Array.isArray(d)) {
  1487. return { records: d, total: countCommentsInApiList(d) };
  1488. }
  1489. if (d && typeof d === 'object') {
  1490. var arr = d.records || d.list || d.rows;
  1491. if (!Array.isArray(arr) && Array.isArray(d.data)) arr = d.data;
  1492. if (!Array.isArray(arr)) arr = [];
  1493. var total =
  1494. d.total != null && !isNaN(Number(d.total))
  1495. ? Number(d.total)
  1496. : countCommentsInApiList(arr);
  1497. return { records: arr, total: total };
  1498. }
  1499. return { records: [], total: 0 };
  1500. }
  1501. function renderCommentsList(rows, total) {
  1502. var mount = document.getElementById('goodsCommentList');
  1503. var totEl = document.getElementById('goodsCommentTotal');
  1504. if (!mount) return;
  1505. mount.innerHTML = '';
  1506. var list = filterTopLevelComments(Array.isArray(rows) ? rows : []);
  1507. var n = total != null && !isNaN(Number(total)) ? Number(total) : countCommentsInApiList(Array.isArray(rows) ? rows : []);
  1508. if (totEl) totEl.textContent = String(n);
  1509. if (!list.length) {
  1510. var empty = document.createElement('li');
  1511. empty.className = 'goods-comments__empty';
  1512. empty.setAttribute('role', 'status');
  1513. empty.textContent = '暂无留言';
  1514. mount.appendChild(empty);
  1515. return;
  1516. }
  1517. list.forEach(function (c) {
  1518. if (!c) return;
  1519. var li = document.createElement('li');
  1520. li.className = 'goods-cmt';
  1521. appendCmtRow(li, c, true);
  1522. var replies = cmtReplies(c);
  1523. if (replies.length) {
  1524. var thread = document.createElement('div');
  1525. thread.className = 'goods-cmt__thread';
  1526. var inner = document.createElement('div');
  1527. inner.className = 'goods-cmt__replies-inner';
  1528. replies.forEach(function (r) {
  1529. if (r) inner.appendChild(buildNestedCmt(r));
  1530. });
  1531. var bar = document.createElement('button');
  1532. bar.type = 'button';
  1533. bar.className = 'goods-cmt__thread-bar';
  1534. bar.setAttribute('aria-expanded', 'true');
  1535. bar.innerHTML =
  1536. '<span>共<span class="js-reply-count">' + replies.length + '</span>条回复</span>' +
  1537. '<span class="goods-cmt__thread-bar-right">' +
  1538. '<span class="js-thread-label">收起</span>' + SVG_CHEV + '</span>';
  1539. thread.appendChild(inner);
  1540. thread.appendChild(bar);
  1541. li.appendChild(thread);
  1542. }
  1543. mount.appendChild(li);
  1544. });
  1545. }
  1546. function bindCommentThreadDelegation() {
  1547. var list = document.getElementById('goodsCommentList');
  1548. if (!list || list.dataset.threadDeleg) return;
  1549. list.dataset.threadDeleg = '1';
  1550. list.addEventListener('click', function (e) {
  1551. var bar = e.target.closest('.goods-cmt__thread-bar');
  1552. if (!bar) return;
  1553. var inner = bar.previousElementSibling;
  1554. if (!inner || !inner.classList.contains('goods-cmt__replies-inner')) return;
  1555. var collapsed = inner.classList.toggle('is-collapsed');
  1556. bar.classList.toggle('is-collapsed', collapsed);
  1557. bar.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
  1558. var lab = bar.querySelector('.js-thread-label');
  1559. if (lab) lab.textContent = collapsed ? '展开' : '收起';
  1560. });
  1561. }
  1562. function pickGoodsStatusFromStatusApi(res) {
  1563. if (!res || typeof res !== 'object') return null;
  1564. var d = isApiOk(res) ? (res.data != null ? res.data : res.result) : null;
  1565. if (d != null && typeof d === 'object' && d.goodsStatus != null) {
  1566. return d.goodsStatus;
  1567. }
  1568. if (res.goodsStatus != null) return res.goodsStatus;
  1569. return null;
  1570. }
  1571. /** 打开页时先拉取商品状态;query 参数名为 id */
  1572. function fetchGoodsStatusById(id) {
  1573. var sid = String(id != null ? id : '').trim();
  1574. if (!sid) return Promise.resolve(null);
  1575. var path =
  1576. '/secondGoods/getGoodsStatusById?id=' + encodeURIComponent(sid);
  1577. return fetch(API_BASE_SECOND + path, {
  1578. method: 'GET',
  1579. mode: 'cors',
  1580. credentials: 'omit',
  1581. headers: { Accept: 'application/json' }
  1582. }).then(function (res) {
  1583. if (!res.ok) throw new Error('HTTP ' + res.status);
  1584. return res.json();
  1585. });
  1586. }
  1587. function fetchSecondGoodsDetail(goodsId, lon, lat, phoneId) {
  1588. var lonStr =
  1589. lon != null && String(lon).trim() !== ''
  1590. ? String(lon).trim()
  1591. : String(DEFAULT_REQUEST_LONGITUDE);
  1592. var latStr =
  1593. lat != null && String(lat).trim() !== ''
  1594. ? String(lat).trim()
  1595. : String(DEFAULT_REQUEST_LATITUDE);
  1596. var pid =
  1597. phoneId != null && String(phoneId).trim() !== ''
  1598. ? String(phoneId).trim()
  1599. : '';
  1600. /** 表单字段:键为 string,值一律 string(x-www-form-urlencoded) */
  1601. var formBody = {
  1602. goodsId: String(goodsId != null ? goodsId : '').trim(),
  1603. longitude: String(lonStr),
  1604. latitude: String(latStr),
  1605. phoneId: pid
  1606. };
  1607. var form = new URLSearchParams();
  1608. form.set('goodsId', formBody.goodsId);
  1609. form.set('longitude', formBody.longitude);
  1610. form.set('latitude', formBody.latitude);
  1611. form.set('phoneId', formBody.phoneId);
  1612. return fetch(API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT', {
  1613. method: 'POST',
  1614. mode: 'cors',
  1615. credentials: 'omit',
  1616. headers: {
  1617. Accept: 'application/json',
  1618. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  1619. },
  1620. body: form.toString()
  1621. }).then(function (res) {
  1622. if (!res.ok) throw new Error('HTTP ' + res.status);
  1623. return res.json();
  1624. }).then(function (res) {
  1625. var d = isApiOk(res) ? res.data || res.result : null;
  1626. if (d && typeof d === 'object') {
  1627. renderGoodsDetail(d);
  1628. } else if (res && res.msg) {
  1629. console.warn('[querySecondGoodsDetail]', res.msg);
  1630. }
  1631. });
  1632. }
  1633. function fetchCommentList(goodsId, userId, pageNum, pageSize) {
  1634. var st = (q('sourceType') || '').trim();
  1635. var sourceType = st && !isNaN(Number(st)) ? Number(st) : COMMENT_SOURCE_TYPE;
  1636. var path = '/commonComment/getListBySourceType?' +
  1637. 'sourceType=' + encodeURIComponent(String(sourceType)) +
  1638. '&sourceId=' + encodeURIComponent(String(goodsId)) +
  1639. '&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
  1640. '&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
  1641. '&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
  1642. return apiGet(path).then(function (res) {
  1643. if (!isApiOk(res)) {
  1644. if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
  1645. renderCommentsList([], 0);
  1646. return;
  1647. }
  1648. var raw = res.data != null ? res.data : res.result;
  1649. var pack = normalizeCommentListPayload(raw);
  1650. renderCommentsList(pack.records, pack.total);
  1651. });
  1652. }
  1653. function run() {
  1654. var goodsId = (q('goodsId') || q('id') || '').trim();
  1655. var userId = (q('userId') || '').trim();
  1656. var phoneId = (q('phoneId') || q('phone_id') || '').trim();
  1657. var lon = (q('longitude') || q('lon') || q('jingdu') || '').trim();
  1658. var lat = (q('latitude') || q('lat') || q('weidu') || '').trim();
  1659. var userCity = (q('userCity') || q('city') || '').trim();
  1660. var lonResolved = lon || DEFAULT_REQUEST_LONGITUDE;
  1661. var latResolved = lat || DEFAULT_REQUEST_LATITUDE;
  1662. var pageNum = (q('pageNum') || '1').trim();
  1663. var pageSize = (q('pageSize') || '10').trim();
  1664. bindCommentThreadDelegation();
  1665. if (!goodsId) {
  1666. applyFromUrl();
  1667. return;
  1668. }
  1669. fetchGoodsStatusById(goodsId)
  1670. .catch(function (e) {
  1671. console.warn('[getGoodsStatusById]', e);
  1672. return null;
  1673. })
  1674. .then(function (statusRes) {
  1675. var gs = pickGoodsStatusFromStatusApi(statusRes);
  1676. var gsNum = gs != null ? Number(gs) : NaN;
  1677. var gsStr = gs != null ? String(gs).trim() : '';
  1678. var gsGotoUndefined =
  1679. gs != null &&
  1680. ((!isNaN(gsNum) && (gsNum === 2 || gsNum === 4 || gsNum === 5)) ||
  1681. gsStr === '2' || gsStr === '4' || gsStr === '5');
  1682. if (gsGotoUndefined) {
  1683. var uq = new URLSearchParams();
  1684. uq.set('goodsUnavailable', '1');
  1685. if (gs != null && String(gs).trim() !== '') {
  1686. uq.set('goodsStatus', String(gs).trim());
  1687. }
  1688. if (userId) {
  1689. uq.set('userId', userId);
  1690. }
  1691. uq.set('longitude', lonResolved);
  1692. uq.set('latitude', latResolved);
  1693. if (userCity) {
  1694. uq.set('userCity', userCity);
  1695. }
  1696. window.location.replace('shareUndefined.html?' + uq.toString());
  1697. return { skipRest: true };
  1698. }
  1699. return Promise.all([
  1700. fetchSecondGoodsDetail(goodsId, lon, lat, phoneId).catch(function (e) {
  1701. console.warn('[querySecondGoodsDetail]', e);
  1702. }),
  1703. fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
  1704. console.warn('[getListBySourceType]', e);
  1705. renderCommentsList([], 0);
  1706. })
  1707. ]).then(function () {
  1708. return { skipRest: false };
  1709. });
  1710. })
  1711. .then(function (flag) {
  1712. if (flag && flag.skipRest) return;
  1713. applyFromUrl();
  1714. });
  1715. }
  1716. function applyFromUrl() {
  1717. var heroImg = document.getElementById('goodsHeroImg');
  1718. var imgUrl = q('image') || q('goodsImage') || q('coverUrl') || q('img');
  1719. imgUrl = tryDecode(imgUrl).trim();
  1720. if (imgUrl) {
  1721. heroImg.src = imgUrl;
  1722. heroImg.alt = '商品图';
  1723. } else {
  1724. heroImg.src = DEFAULT_HERO;
  1725. heroImg.alt = '';
  1726. }
  1727. var av = tryDecode(q('userImage') || q('avatar')).trim();
  1728. document.getElementById('goodsUserAvatar').src = av || 'images/demouser.png';
  1729. var uname = tryDecode(q('userName') || q('nickname')).trim();
  1730. if (uname) document.getElementById('goodsUserName').textContent = uname;
  1731. var ago = tryDecode(q('timeAgo') || q('publishTime')).trim();
  1732. if (ago) document.getElementById('goodsTimeAgo').textContent = ago;
  1733. var s1 = tryDecode(q('slogan1') || q('line1')).trim();
  1734. var s2 = tryDecode(q('slogan2') || q('line2')).trim();
  1735. var elS1 = document.getElementById('goodsSlogan1');
  1736. var elS2 = document.getElementById('goodsSlogan2');
  1737. var elWrap = document.getElementById('goodsHeroSloganWrap');
  1738. if (s1 && elS1) elS1.textContent = s1;
  1739. if (s2 && elS2) elS2.textContent = s2;
  1740. if (elWrap && (s1 || s2)) elWrap.style.display = '';
  1741. var price = tryDecode(q('price')).trim();
  1742. if (price) {
  1743. var pn = parseFloat(price.replace(/[^\d.]/g, ''));
  1744. document.getElementById('goodsPrice').textContent =
  1745. !isNaN(pn) ? pn.toFixed(2) : price;
  1746. }
  1747. var dist = tryDecode(q('distance') || q('distanceKm') || q('dist')).trim();
  1748. if (dist) {
  1749. if (!/^距离/.test(dist)) dist = '距离 ' + dist;
  1750. if (!/km$/i.test(dist) && !/千米/.test(dist) && !/米/.test(dist) && !/\s*m\s*$/i.test(dist)) {
  1751. dist = dist.replace(/\s+$/, '') + 'km';
  1752. }
  1753. document.getElementById('goodsDistance').textContent = dist;
  1754. }
  1755. var title = tryDecode(q('title') || q('goodsTitle')).trim();
  1756. if (title) document.getElementById('goodsTitle').textContent = title;
  1757. var hot = tryDecode(q('hotCount') || q('hot')).trim();
  1758. if (hot) document.getElementById('goodsHotCount').textContent = hot;
  1759. var fav = tryDecode(q('favCount') || q('fav') || q('collectCount')).trim();
  1760. if (fav) document.getElementById('goodsFavCount').textContent = fav;
  1761. var cc = tryDecode(q('commentCount') || q('comments')).trim();
  1762. if (cc) {
  1763. var elTot = document.getElementById('goodsCommentTotal');
  1764. if (elTot) elTot.textContent = cc;
  1765. }
  1766. var tagsRaw = tryDecode(q('tags') || q('tag')).trim();
  1767. var mount = document.getElementById('goodsTags');
  1768. var hasGoodsId = (q('goodsId') || q('id') || '').trim();
  1769. if (mount) {
  1770. if (tagsRaw) {
  1771. mount.innerHTML = '';
  1772. tagsRaw.split(/[,,]/).map(function (t) { return t.trim(); }).filter(Boolean).forEach(function (t) {
  1773. appendGoodsTag(mount, t, t.indexOf('#') === 0 ? 'topic' : 'label');
  1774. });
  1775. } else if (!hasGoodsId) {
  1776. mount.innerHTML = '';
  1777. ['复古冰箱', '网红冰箱', '复古烤漆', '冰箱'].forEach(function (t) {
  1778. appendGoodsTag(mount, t, 'label');
  1779. });
  1780. }
  1781. }
  1782. }
  1783. function sharePage() {
  1784. var title = document.getElementById('goodsTitle').textContent || '商品分享';
  1785. var url = location.href;
  1786. if (navigator.share) {
  1787. navigator.share({ title: title, text: title, url: url }).catch(function () {});
  1788. return;
  1789. }
  1790. if (navigator.clipboard && navigator.clipboard.writeText) {
  1791. navigator.clipboard.writeText(url).then(function () {
  1792. window.alert('链接已复制');
  1793. }).catch(function () {
  1794. window.prompt('复制链接', url);
  1795. });
  1796. } else {
  1797. window.prompt('复制链接', url);
  1798. }
  1799. }
  1800. var shareBtn = document.getElementById('goodsShareBtn');
  1801. if (shareBtn) shareBtn.addEventListener('click', sharePage);
  1802. function boot() {
  1803. var launchTag = document.getElementById('launch-btn');
  1804. if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
  1805. bindWeChatLaunchTagEvents();
  1806. if (isWeChatInAppBrowser()) {
  1807. document.body.classList.add('is-wechat');
  1808. ensureWxShareFromQueryBeforeConfig();
  1809. logWxEntryDiagnostics();
  1810. }
  1811. if (shouldInitWeChatJssdkOnLoad()) {
  1812. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1813. document.body.classList.add('wx-pc-debug');
  1814. }
  1815. scheduleWeChatJssdkBootstrap();
  1816. }
  1817. document.addEventListener('WeixinOpenTagsError', function (e) {
  1818. console.warn('[WeixinOpenTagsError]', e && e.detail);
  1819. });
  1820. if (isWeChatInAppBrowser()) {
  1821. var openBtnWx = document.getElementById('openApp');
  1822. if (openBtnWx) {
  1823. openBtnWx.addEventListener('click', function () {
  1824. if (!weChatJssdkConfigured) {
  1825. showFabToast(
  1826. wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
  1827. );
  1828. }
  1829. });
  1830. }
  1831. } else {
  1832. var openAppBtn = document.getElementById('openApp');
  1833. if (openAppBtn) {
  1834. openAppBtn.addEventListener('click', tryOpenHBuilderApp);
  1835. }
  1836. }
  1837. run();
  1838. }
  1839. if (document.readyState === 'complete') {
  1840. boot();
  1841. } else {
  1842. window.onload = boot;
  1843. }
  1844. })();
  1845. </script>
  1846. </body>
  1847. </html>