小草二手闲置_H5/app.js · 约 4147 字符
1// 小草二手闲置 · 逻辑层
2const $=s=>document.querySelector(s), $$=s=>document.querySelectorAll(s);
3function toast(msg){const t=document.createElement('div');t.textContent=msg;t.style.cssText='position:fixed;top:20%;left:50%;transform:translateX(-50%);background:rgba(0,0,0,.78);color:#fff;padding:10px 20px;border-radius:20px;font-size:13px;z-index:999;transition:opacity .3s';document.body.appendChild(t);setTimeout(()=>{t.style.opacity='0';setTimeout(()=>t.remove(),300)},1200)}
4function fmt(n){return '¥'+n.toLocaleString()}
5function goodsById(id){return GOODS.find(g=>g.id==id)}
6function renderOrders(){
7 const wrap=$('#order-list');
8 const steps=[['待付款','✓'],['已付款','✓'],['担保中','🛡️'],['已确认','🎉']];
9 if(!wrap)return;
10 wrap.innerHTML=ORDERS.map(o=>`
11 <div class="order-card">
12 <div class="oc-head"><span>${o.time} · 来自 ${o.from}</span><span class="oc-status">● ${o.status}</span></div>
13 <div class="oc-body"><span class="oc-emoji">${o.emoji}</span>
14 <div><div class="oc-name">${o.name}</div><div class="oc-meta">${o.status==='担保中'?'货款平台托管中 · 确认收货后打款卖家':'同城已面交 · 交易完成'}</div></div>
15 <div class="oc-price">${fmt(o.price)}</div>
16 </div>
17 <div class="oc-steps">${steps.map((s,i)=>'<div class="os '+(i<o.step?'done':i===o.step?'now':'')+'"><span class="dot">'+s[1]+'</span>'+s[0]+'</div>').join('')}</div>
18 <div class="escrow">🛡️ 担保交易:${o.status==='担保中'?'买家货款由平台托管,确认收货后资金才到卖家账户,支持仲裁维权':'已完成,双方可互相评价'}</div>
19 </div>`).join('');
20}
21function renderMine(){
22 $('#u-name').textContent=USER.name;$('#u-level').textContent=USER.level+' · 成交 '+USER.orders+' 单';
23 $('#m-credit').textContent=USER.credit;$('#m-orders').textContent=USER.orders;
24 $('#m-likes').textContent=USER.likes;$('#m-follows').textContent=USER.follows;
25}
26function renderDetail(){
27 const id=new URLSearchParams(location.search).get('id')||1;
28 const g=goodsById(id);window.CURRENT=g;
29 $('#d-img').textContent=g.emoji;
30 $('#d-price').innerHTML='<em>¥</em>'+g.price.toLocaleString()+' <s>¥'+g.origin.toLocaleString()+'</s>';
31 $('#d-name').textContent=g.name;
32 $('#d-meta').innerHTML='<span class="tag">'+g.cond+'</span><span class="tag">📍 距你 '+g.dist+'</span>'+g.tags.map(t=>'<span class="tag">'+t+'</span>').join('');
33 $('#d-desc').textContent='自用闲置,功能完好无维修,买来没多久,闲置可惜了。支持小刀,诚心要可以聊~';
34 $('#d-info').innerHTML=
35 '<div class="info-row"><span>成色</span><b>'+g.cond+' · 无拆无修</b></div>'+
36 '<div class="info-row"><span>入手价</span><b>¥'+g.origin.toLocaleString()+'</b></div>'+
37 '<div class="info-row"><span>交易方式</span><b>'+(g.tags.includes('可快递')?'同城自提 / 快递发货':'同城自提·当面验货')+'</b></div>'+
38 '<div class="info-row"><span>保障</span><b style="color:var(--green)">平台担保交易 · 可验货</b></div>';
39 $$('.trade-cell').forEach(t=>t.onclick=()=>{$$('.trade-cell').forEach(x=>x.classList.remove('sel'));t.classList.add('sel')});
40}
41function submitBuy(){
42 const g=window.CURRENT;
43 const mode=document.querySelector('.trade-cell.sel')?document.querySelector('.trade-cell.sel').querySelector('.tc-name').textContent:'同城自提';
44 toast('已下单:'+g.name+'('+mode+')· 货款由平台托管');
45 setTimeout(()=>location.href='orders.html',900);
46}
47function renderSell(){
48 $$('.opt-chip').forEach(c=>c.onclick=()=>{$$('.opt-chip').forEach(x=>x.classList.remove('sel'));c.classList.add('sel');SELL_FORM.cond=c.textContent});
49 $$('.trade-cell').forEach(t=>t.onclick=()=>{$$('.trade-cell').forEach(x=>x.classList.remove('sel'));t.classList.add('sel');SELL_FORM.mode=t.querySelector('.tc-name').textContent.includes('自提')?'pickup':'express'});
50}
51function submitSell(){
52 toast('发布成功!已进入审核,预计10分钟内上架');
53 setTimeout(()=>location.href='index.html',900);
54}
55