3 lines
60 KiB
JavaScript
3 lines
60 KiB
JavaScript
import{j as e,a as r,b as we}from"./react-vendor-l-BBvuKH.js";import{r as q,c as B,A as bt}from"./index-CiBUw4Te.js";import{c as Qe}from"./contract-COFcZjyb.js";import{a3 as gt,U as $e,R as Se,N as De,a4 as Pe,a5 as _e,V as yt,y as ft,B as jt,a6 as Oe,a7 as vt,a8 as Nt,A as wt,d as _t,X as ye,o as kt,a9 as Ue,I as ze}from"./icons-vendor-Bgrth_9N.js";import"./vendor-cRYyTeIw.js";const Ke="ydisks-amap-js-api",Ct="c9b68d4ce9a2a97f22a4a439404488ca";let fe=null;const It=()=>Ct,St=()=>window.AMap?Promise.resolve(window.AMap):fe||(fe=new Promise((s,a)=>{const n=document.getElementById(Ke),d=n||document.createElement("script"),u=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(G)},f=()=>{window.AMap?(u(),s(window.AMap)):(u(),a(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},G=window.setTimeout(()=>{u(),a(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=f,d.id=Ke,d.async=!0,d.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(It())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,d.onerror=()=>{u(),a(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},n||document.head.appendChild(d)}).catch(s=>{throw fe=null,s}),fe),ke=s=>Number.isFinite(s)&&s!==0,Pt=s=>{var u,f;const a=Number((u=s.location)==null?void 0:u.lng),n=Number((f=s.location)==null?void 0:f.lat),d={area:String(s.adname||"").trim(),city:String(s.cityname||"").trim(),division_id:String(s.adcode||"").trim(),longitude:a,latitude:n,poi_id:String(s.id||"").trim(),poi_name:String(s.name||"").trim(),province:String(s.pname||"").trim()};return!d.division_id||!d.province||!d.city||!d.poi_id||!d.poi_name||!ke(a)||!ke(n)||a<-180||a>180||n<-90||n>90?null:d},qt=async(s,a,n={})=>{if(!ke(s)||!ke(a)||s<-180||s>180||a<-90||a>90)throw new Error("经纬度无效");const d=await St();return new Promise((u,f)=>{var $,M;let G=!1;const k=Math.max(1,n.timeoutMs??1e4),R=F=>{var p;G||(G=!0,globalThis.clearTimeout(W),(p=n.signal)==null||p.removeEventListener("abort",I),F())},I=()=>R(()=>f(new DOMException("aborted","AbortError"))),W=globalThis.setTimeout(()=>R(()=>f(new Error("高德地图附近地址查询超时,请稍后重试"))),k);if(($=n.signal)!=null&&$.aborted){I();return}(M=n.signal)==null||M.addEventListener("abort",I,{once:!0}),new d.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[s,a],1e3,(F,p)=>{var x;if(G)return;if(F!=="complete"){if(F==="no_data"){R(()=>u([]));return}R(()=>f(new Error("高德地图附近地址查询失败,请稍后重试")));return}const E=(((x=p==null?void 0:p.poiList)==null?void 0:x.pois)||[]).map(Pt).filter(j=>j!==null);R(()=>u(E))})})},Bt=async s=>q(a=>B.GET("/api/v1/accounts/details",{signal:a}),s),Je=async s=>q(a=>B.GET("/api/v1/automation-rules",{signal:a}),s),Et=(s,a,n)=>qt(s,a,n),qe=(s,a)=>{if(s instanceof bt)switch(s.code){case"stock_permission_missing":return"发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。";case"conflict":case"item_conflict":return"商品状态已发生变化,请刷新后重试。";case"external_result_unknown":case"manual_review_required":return"平台结果暂时无法确认,请先人工核对闲鱼状态,再决定是否重试。";case"retryable":case"temporarily_unavailable":return"平台暂时不可用,请稍后重试。";default:return s.message||a}if(s instanceof Error)return s.message;const n=typeof s=="object"&&s!==null&&"message"in s?s.message:void 0;return typeof n=="string"?n:a},Be=s=>s===!0||s===1||s==="1",Ze=async(s,a)=>{const n=await q(u=>B.GET("/api/v1/items",{params:{query:{cookie_id:s}},signal:u}),a);return Qe(n,["items","data","results"]).map(u=>({...u,id:u.id||`${u.cookie_id}-${u.item_id}`,is_multi_spec:Be(u.is_multi_spec),is_multi_qty_ship:Be(u.is_multi_qty_ship??u.multi_quantity_delivery),multi_quantity_delivery:Be(u.multi_quantity_delivery??u.is_multi_qty_ship)}))},Lt=async s=>q(a=>B.POST("/api/v1/items/get-all-from-account",{body:{cookie_id:s},signal:a})),At=async(s,a)=>q(n=>B.DELETE("/api/v1/items/{cookie_id}/{item_id}",{params:{path:{cookie_id:s,item_id:a}},signal:n})),Rt=async(s,a)=>q(n=>B.POST("/api/v1/items/{cookie_id}",{params:{path:{cookie_id:s}},body:a,signal:n})),Mt=async s=>{const a=new FormData;a.set("cookie_id",s.cookie_id),a.set("title",s.title),a.set("description",s.description),a.set("price",s.price),a.set("original_price",s.original_price||""),a.set("quantity",String(s.quantity)),a.set("postage_mode",s.postage_mode),a.set("postage",s.postage||""),s.location&&a.set("location",JSON.stringify(s.location));for(const n of s.images)a.append("images",n);return q(n=>B.POST("/api/v1/items/publish",{body:a,signal:n}))},Ft=async(s,a,n)=>q(d=>B.POST("/api/v1/items/publish-categories/recommend",{body:{cookie_id:s,keyword:a},signal:d}),n),Gt=async(s,a)=>{const n=new FormData;return n.set("file",s.file),s.imagesZip&&n.set("images_zip",s.imagesZip),s.defaultCookieId&&n.set("default_cookie_id",s.defaultCookieId),n.set("fallback_category_id",s.fallbackCategory.catId),n.set("fallback_category_name",s.fallbackCategory.catName),n.set("fallback_channel_category_id",s.fallbackCategory.channelCatId||""),n.set("fallback_tb_category_id",s.fallbackCategory.tbCatId||""),s.location&&n.set("location",JSON.stringify(s.location)),n.set("publish_interval_seconds",String(s.publishIntervalSeconds??5)),q(d=>B.POST("/api/v1/items/publish-batches/preview",{body:n,signal:d}),a)},Tt=async(s,a)=>q(n=>B.POST("/api/v1/items/publish-batches",{body:{preview_id:s},signal:n}),a),oe=async(s,a)=>q(n=>B.GET("/api/v1/items/publish-batches/{batch_id}",{params:{path:{batch_id:s}},signal:n}),a),et=async(s=20,a)=>{const n=await q(d=>B.GET("/api/v1/items/publish-batches",{params:{query:{limit:s}},signal:d}),a);return Qe(n,["batches","data","items"])},Ve=async(s,a)=>q(n=>B.DELETE("/api/v1/items/publish-batches/{batch_id}",{params:{path:{batch_id:s}},signal:n}),a),$t=async(s,a)=>q(n=>B.POST("/api/v1/items/publish-batches/{batch_id}/cancel",{params:{path:{batch_id:s}},body:{},signal:n}),a),Dt=async(s,a)=>q(n=>B.POST("/api/v1/items/publish-batches/{batch_id}/retry-failed",{params:{path:{batch_id:s}},body:{},signal:n}),a),Ot=async(s,a,n)=>q(d=>B.PUT("/api/v1/items/{cookie_id}/{item_id}",{params:{path:{cookie_id:s,item_id:a}},body:n,signal:d})),Ut=s=>s.find(a=>a.status==="pending"||a.status==="running"||a.status==="canceling"),je=s=>s==="pending"||s==="running"||s==="canceling",zt=s=>!!(s!=null&&s.preview_id&&Number(s.valid||0)>0),Kt=s=>!!(s!=null&&s.id&&Number(s.retryable||0)>0&&!je(s.status)),Jt=(s,a)=>s===a,We=s=>{switch(s){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return s||"-"}},Ye=s=>{switch(s){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},Zt=({phase:s})=>{const a=[["upload","1 上传"],["preview","2 预检"],["running","3 发布"],["done","4 结果"]];return e.jsx("div",{className:"grid grid-cols-4 gap-2",children:a.map(([n,d])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${s===n?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:d},n))})},Vt=s=>{const[a,n]=r.useState(!1),[d,u]=r.useState("upload"),[f,G]=r.useState(null),[k,R]=r.useState(null),[I,W]=r.useState(""),[U,$]=r.useState(!1),[M,F]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[p,E]=r.useState(null),[x,j]=r.useState(null),[S,Y]=r.useState(null),[H,X]=r.useState([]),[z,D]=r.useState(null),[Z,C]=r.useState(5),[le,b]=r.useState(!1),y=r.useRef(0),g=r.useRef(null),v=r.useCallback(()=>{var h;(h=g.current)==null||h.abort();const l=new AbortController;g.current=l;const i=++y.current;return{controller:l,requestGeneration:i}},[]),m=r.useCallback((l,i)=>l===y.current&&i===g.current&&!i.signal.aborted,[]);r.useEffect(()=>(()=>{var l;(l=g.current)==null||l.abort(),y.current+=1}),[]);const re=r.useCallback(async()=>{const l=v();u("upload"),E(null),j(null),G(null),R(null),W(""),F({catId:"",catName:"",channelCatId:"",tbCatId:""}),X([]),D(null),C(5),n(!0),b(!0);try{const i=await et(20,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;const h=Ut(i);if(h!=null&&h.id){const L=await oe(h.id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;Y(L),j(L),C(L.publish_interval_seconds||5),u(je(L.status)?"running":"done")}}catch(i){if(!m(l.requestGeneration,l.controller))return;console.error("恢复最近批量铺货任务失败:",i)}finally{m(l.requestGeneration,l.controller)&&b(!1)}},[v,m]),Q=r.useCallback(async()=>{const l=I.trim();if(!s.selectedAccount){alert("请先选择默认发布账号");return}if(!l){alert("请输入类目关键词");return}const i=v();$(!0);try{const h=await Ft(s.selectedAccount,l,{signal:i.controller.signal});if(!m(i.requestGeneration,i.controller))return;const L=h.category;F({catId:L.cat_id,catName:L.cat_name,channelCatId:L.channel_cat_id,tbCatId:L.tb_cat_id||""})}catch(h){if(!m(i.requestGeneration,i.controller))return;console.error("获取推荐类目失败:",h),alert((h==null?void 0:h.message)||"没有匹配到类目,请换一个更具体的关键词")}finally{m(i.requestGeneration,i.controller)&&$(!1)}},[I,v,m,s.selectedAccount]),K=r.useCallback(async()=>{if(!(S!=null&&S.id))return;const l=v();b(!0),n(!0);try{const i=await oe(S.id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;j(i),C(i.publish_interval_seconds||5),u(je(i.status)?"running":"done")}catch(i){if(!m(l.requestGeneration,l.controller))return;console.error("加载最近批量铺货结果失败:",i)}finally{m(l.requestGeneration,l.controller)&&b(!1)}},[v,m,S==null?void 0:S.id]),O=r.useCallback(async()=>{if(!f){alert("请先上传商品表格");return}if(!s.selectedAccount){alert("请先选择默认发布账号");return}const l=v();b(!0);try{const i=await Gt({file:f,imagesZip:k,defaultCookieId:s.selectedAccount,fallbackCategory:M,location:z||void 0,publishIntervalSeconds:Z},{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;E(i),j(null),u("preview")}catch(i){if(!m(l.requestGeneration,l.controller))return;console.error("批量铺货预检失败:",i),alert((i==null?void 0:i.message)||"预检失败,请检查表格和图片 zip")}finally{m(l.requestGeneration,l.controller)&&b(!1)}},[M,f,k,z,Z,v,m,s.selectedAccount]),ae=r.useCallback(async()=>{if(!(p!=null&&p.preview_id))return;if(!zt(p)){alert("没有可发布的商品行");return}const l=v();b(!0);try{const i=await Tt(p.preview_id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;const h=await oe(i.batch_id||p.preview_id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;j(h),Y(h),u(h.status==="running"?"running":"done")}catch(i){if(!m(l.requestGeneration,l.controller))return;console.error("启动批量铺货失败:",i),alert((i==null?void 0:i.message)||"启动发布任务失败")}finally{m(l.requestGeneration,l.controller)&&b(!1)}},[p,v,m]),de=r.useCallback(async()=>{if(!(x!=null&&x.id)||!confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。"))return;const l=v();b(!0);try{const i=await $t(x.id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;const h=await oe(x.id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;j(h),u((i==null?void 0:i.status)==="canceling"||h.status==="canceling"?"running":"done")}catch(i){if(!m(l.requestGeneration,l.controller))return;alert((i==null?void 0:i.message)||"取消失败")}finally{m(l.requestGeneration,l.controller)&&b(!1)}},[x==null?void 0:x.id,v,m]),ne=r.useCallback(async()=>{const l=p==null?void 0:p.preview_id,i=v();if(l&&d==="preview")try{await Ve(l,{signal:i.controller.signal})}catch(h){if(!m(i.requestGeneration,i.controller))return;console.error("清理批量铺货预检失败:",h)}m(i.requestGeneration,i.controller)&&(E(null),u("upload"))},[d,p==null?void 0:p.preview_id,v,m]),xe=r.useCallback(async()=>{var i;const l=p==null?void 0:p.preview_id;if((i=g.current)==null||i.abort(),y.current+=1,E(null),u("upload"),n(!1),l&&d==="preview")try{await Ve(l)}catch(h){console.error("关闭批量铺货弹窗时清理预检失败:",h)}},[d,p==null?void 0:p.preview_id]),me=r.useCallback(async()=>{if(!(x!=null&&x.id)||!Kt(x))return;const l=v();b(!0);try{if(await Dt(x.id,{signal:l.controller.signal}),!m(l.requestGeneration,l.controller))return;const i=await oe(x.id,{signal:l.controller.signal});if(!m(l.requestGeneration,l.controller))return;j(i),u("running")}catch(i){if(!m(l.requestGeneration,l.controller))return;alert((i==null?void 0:i.message)||"重试失败")}finally{m(l.requestGeneration,l.controller)&&b(!1)}},[x,v,m]);return r.useEffect(()=>{if(!a||!(x!=null&&x.id)||!je(x.status))return;const l=++y.current,i=new AbortController;let h=!1;const L=async()=>{if(!(h||i.signal.aborted)){h=!0;try{const N=await oe(x.id,{signal:i.signal});if(!Jt(l,y.current))return;j(N),Y(N),je(N.status)||(u("done"),await Promise.all([s.loadItems(),s.loadShippingRules()]))}catch(N){i.signal.aborted||console.error("刷新批量铺货进度失败:",N)}finally{h=!1}}},o=window.setInterval(()=>void L(),3e3);return(()=>{window.clearInterval(o),i.abort(),y.current+=1})},[x==null?void 0:x.id,x==null?void 0:x.status,s.loadItems,s.loadShippingRules,a]),{showBatchModal:a,setShowBatchModal:n,batchLoading:le,batchPhase:d,setBatchPhase:u,batchFile:f,setBatchFile:G,batchImagesZip:k,setBatchImagesZip:R,batchCategoryKeyword:I,setBatchCategoryKeyword:W,batchCategoryLoading:U,batchFallbackCategory:M,setBatchFallbackCategory:F,batchPreview:p,setBatchPreview:E,batchDetail:x,setBatchDetail:j,recentBatch:S,setRecentBatch:Y,batchLocations:H,batchLocation:z,setBatchLocations:X,setBatchLocation:D,batchPublishIntervalSeconds:Z,setBatchPublishIntervalSeconds:C,openBatchModal:re,handleRecommendBatchCategory:Q,openRecentBatchResult:K,handlePreviewBatch:O,handleStartBatch:ae,handleCancelBatch:de,abandonBatchPreview:ne,closeBatchModal:xe,handleRetryBatchFailed:me}},He=()=>({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),Xe=(s="")=>({cookie_id:s,title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),Wt=({selectedAccount:s,setSelectedAccount:a,setItems:n,loadItems:d,loadShippingRules:u,onConfigureDelivery:f,setBatchLocations:G,setBatchLocation:k})=>{const[R,I]=r.useState(!1),[W,U]=r.useState(!1),[$,M]=r.useState(!1),[F,p]=r.useState(!1),[E,x]=r.useState(!1),[j,S]=r.useState(!1),[Y,H]=r.useState([]),[X,z]=r.useState(null),[D,Z]=r.useState(null),[C,le]=r.useState({}),[b,y]=r.useState(He),[g,v]=r.useState(Xe),[m,re]=r.useState([]),Q=r.useRef(null),K=r.useRef(0);r.useEffect(()=>{if(!E||g.images.length===0){re([]);return}const o=g.images.map((N,A)=>({key:N.name+A,url:URL.createObjectURL(N)}));return re(o),(()=>o.forEach(N=>URL.revokeObjectURL(N.url)))},[g.images,E]);const O=r.useCallback(()=>{var o;(o=Q.current)==null||o.abort(),Q.current=null,K.current+=1,S(!1)},[]);r.useEffect(()=>O,[O]),r.useEffect(()=>{E||O()},[O,E]);const ae=r.useCallback(async()=>{if(!s)return alert("请先选择账号");I(!0);try{const o=await Lt(s);await d(),alert((o==null?void 0:o.message)||"商品同步完成")}catch(o){console.error("同步商品失败:",o),alert(qe(o,"同步失败,请重试"))}finally{I(!1)}},[d,s]),de=r.useCallback(o=>{Z(o),le({...o}),M(!0)},[]),ne=r.useCallback(async()=>{if(D)try{await Ot(D.cookie_id,D.item_id,{item_title:C.item_title||"",item_description:C.item_description||"",item_category:C.item_category||"",item_price:C.item_price||"",item_detail:C.item_detail||D.item_detail||""}),await d(),await u(),M(!1),Z(null)}catch(o){console.error("更新商品失败:",o),alert("更新失败,请重试")}},[C,d,u,D]),xe=r.useCallback(async o=>{if(confirm(`确认删除商品"${o.item_title}"吗?`))try{await At(o.cookie_id,o.item_id),n(N=>N.filter(A=>!(A.cookie_id===o.cookie_id&&A.item_id===o.item_id)))}catch(N){console.error("删除商品失败:",N),alert("删除失败,请重试")}},[n]),me=r.useCallback(async()=>{try{if(!b.cookie_id||!b.item_id){alert("请选择账号并填写商品ID");return}await Rt(b.cookie_id,{item_id:b.item_id,item_title:b.item_title,item_price:b.item_price,item_detail:b.item_image?JSON.stringify({item_image:b.item_image}):""}),await d(),p(!1),y(He())}catch(o){console.error("添加商品失败:",o),alert("添加失败,请重试")}},[b,d]),ve=r.useCallback(async()=>{if(!g.cookie_id)return alert("请选择发布账号");if(!g.title.trim())return alert("请填写商品标题");if(!g.price.trim())return alert("请填写商品价格");if(!g.quantity||Number(g.quantity)<=0)return alert("库存数量必须大于 0");if(g.images.length===0)return alert("至少上传 1 张商品图片");if(g.postage_mode==="fixed"&&!g.postage.trim())return alert("请填写一口价邮费");U(!0);try{const o=await Mt({...g,location:X||void 0});if(await d(),x(!1),v(Xe(s||"")),H([]),z(null),o!=null&&o.item_id){const N={id:o.item_id,cookie_id:g.cookie_id,item_id:o.item_id,item_title:o.item_title||g.title,item_price:o.item_price||g.price,item_image:o.item_image};f(N),alert("商品发布成功,ID: "+o.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(o){console.error("发布商品失败:",o),alert(qe(o,"发布失败,请重试"))}finally{U(!1)}},[d,f,g,X,s]),l=r.useCallback(()=>{const A=[["账号ID","标题","描述","价格","原价","库存","邮费模式","邮费","图片","类目ID","类目名称","频道类目ID","淘宝类目ID","付款发货启用","付款发货内容","评价赠品启用","评价赠品内容","求评价启用","求评价等待小时","求评价文案","求评价最多次数"],...[["","会员组合包自动发货","下单后发送主卡和附赠卡。","19.90","29.90","10","free","","images/bundle-1.jpg;images/bundle-2.jpg","","","","","是","101:1;102:1","是","201:1;202:2","是","72","亲,满意的话麻烦给个评价,谢谢~","1"],["","普通商品","仅发布商品,不创建自动化规则。","49.90","","10","fixed","8.00","https://example.com/product.jpg","","","","","否","","否","","否","","",""]]].map(ue=>ue.map(he=>`"${String(he).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),ee=new Blob(["\uFEFF"+A],{type:"text/csv;charset=utf-8"}),T=URL.createObjectURL(ee),P=document.createElement("a");P.href=T,P.download="批量铺货模板.csv",document.body.appendChild(P),P.click(),P.remove(),URL.revokeObjectURL(T)},[]),i=r.useCallback(()=>{y(o=>({...o,cookie_id:s||o.cookie_id})),p(!0)},[s]),h=r.useCallback(()=>{v(o=>({...o,cookie_id:s||o.cookie_id})),x(!0)},[s]),L=r.useCallback(async o=>{if(!(o?s:g.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");O();const A=new AbortController;Q.current=A;const ee=++K.current;S(!0);try{const T=await new Promise((ue,he)=>{const Ce=te=>ue(te),ie=te=>he(te);navigator.geolocation.getCurrentPosition(Ce,ie,{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})});if(A.signal.aborted||ee!==K.current)return;const P=await Et(T.coords.longitude,T.coords.latitude,{signal:A.signal});if(A.signal.aborted||ee!==K.current)return;if(!P.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");o?(G(P),k(P[0])):(H(P),z(P[0]))}catch(T){if(A.signal.aborted||ee!==K.current)return;if(typeof T=="object"&&T!==null&&"code"in T){const P=T;alert(P.code===P.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")}else alert(qe(T,"获取发货地失败"))}finally{ee===K.current&&(Q.current=null,S(!1))}},[O,g.cookie_id,s,k,G]);return{selectedAccount:s,setSelectedAccount:a,loading:R,publishing:W,showEditModal:$,setShowEditModal:M,showAddModal:F,setShowAddModal:p,showPublishModal:E,setShowPublishModal:x,locationLoading:j,publishLocations:Y,setPublishLocations:H,publishLocation:X,setPublishLocation:z,selectedItem:D,editForm:C,setEditForm:le,addForm:b,setAddForm:y,publishForm:g,setPublishForm:v,publishImagePreviews:m,handleSync:ae,handleEdit:de,handleSaveEdit:ne,handleDelete:xe,handleAddItem:me,handlePublishItem:ve,downloadPublishTemplate:l,openAddModal:i,openPublishModal:h,locateForPublish:L}},Yt=s=>{const a=String(s||"").trim();return a?/^[¥¥]/.test(a)?a:`¥${a}`:"-"},ss=({onConfigureDelivery:s})=>{const[a,n]=r.useState([]),[d,u]=r.useState([]),[f,G]=r.useState([]),[k,R]=r.useState(""),[I,W]=r.useState(""),U=r.useRef(0),$=r.useRef(0),M=r.useCallback(async()=>{const t=++U.current,c=await Ze();t===U.current&&n(c)},[]),F=r.useCallback(async()=>{const t=++$.current,c=await Je();t===$.current&&u(c)},[]),p=Vt({selectedAccount:k,loadItems:M,loadShippingRules:F}),{showBatchModal:E,batchLoading:x,batchPhase:j,batchFile:S,setBatchFile:Y,batchImagesZip:H,setBatchImagesZip:X,batchCategoryKeyword:z,setBatchCategoryKeyword:D,batchCategoryLoading:Z,batchFallbackCategory:C,setBatchFallbackCategory:le,batchPreview:b,batchDetail:y,recentBatch:g,setRecentBatch:v,batchLocations:m,batchLocation:re,batchPublishIntervalSeconds:Q,setBatchPublishIntervalSeconds:K,setBatchLocations:O,setBatchLocation:ae,openBatchModal:de,handleRecommendBatchCategory:ne,openRecentBatchResult:xe,handlePreviewBatch:me,handleStartBatch:ve,handleCancelBatch:l,abandonBatchPreview:i,closeBatchModal:h,handleRetryBatchFailed:L}=p,o=Wt({selectedAccount:k,setSelectedAccount:R,setItems:n,loadItems:M,loadShippingRules:F,onConfigureDelivery:s,setBatchLocations:O,setBatchLocation:ae}),{loading:N,publishing:A,showEditModal:ee,setShowEditModal:T,showAddModal:P,setShowAddModal:ue,showPublishModal:he,setShowPublishModal:Ce,locationLoading:ie,publishLocations:te,setPublishLocations:tt,publishLocation:st,setPublishLocation:Ee,selectedItem:Le,editForm:se,setEditForm:Ne,addForm:J,setAddForm:pe,publishForm:w,setPublishForm:V,publishImagePreviews:Ae,handleSync:at,handleEdit:lt,handleSaveEdit:rt,handleDelete:nt,handleAddItem:it,handlePublishItem:ct,downloadPublishTemplate:ot,openAddModal:dt,openPublishModal:xt,locateForPublish:Re}=o;r.useEffect(()=>{const t=new AbortController,c=++U.current,_=++$.current;let ge=!0;return Promise.all([Bt({signal:t.signal}),Ze(void 0,{signal:t.signal}),Je({signal:t.signal}),et(20,{signal:t.signal})]).then(([ce,ut,ht,Te])=>{if(!ge||t.signal.aborted||c!==U.current||_!==$.current)return;G(ce),n(ut),u(ht);const pt=Te.find(Ie=>["running","canceling"].includes(Ie.status))||Te.find(Ie=>Ie.status!=="preview");v(pt||null)}).catch(ce=>{t.signal.aborted||console.error("加载商品配置失败:",ce)}),(()=>{ge=!1,t.abort()})},[]);const mt=t=>d.filter(c=>c.cookie_id===t.cookie_id&&c.item_id===t.item_id).length>0?d.filter(c=>c.cookie_id===t.cookie_id&&c.item_id===t.item_id):d.filter(c=>c.cookie_id===t.cookie_id&&!c.item_id),Me=r.useMemo(()=>new Map(f.map(t=>[t.id,t])),[f]),Fe=r.useMemo(()=>I?a.filter(t=>t.cookie_id===I):a,[I,a]),be=t=>{const c=Me.get(t),_=(c==null?void 0:c.remark)||(c==null?void 0:c.nickname);return _?`${_} · ${t.slice(0,6)}`:`账号 ${t.slice(0,8)}`},Ge=t=>{const c=Me.get(t);return(c==null?void 0:c.remark)||(c==null?void 0:c.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(gt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:I,onChange:(t=>W(t.target.value)),children:[e.jsx("option",{value:"",children:"全部账号"}),f.map(t=>e.jsx("option",{value:t.id,children:be(t.id)},t.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx($e,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:k,onChange:(t=>R(t.target.value)),children:[e.jsx("option",{value:"",children:"请选择账号"}),f.map(t=>e.jsx("option",{value:t.id,children:be(t.id)},t.id))]})]})]}),e.jsxs("button",{onClick:at,disabled:N||!k,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Se,{className:`w-4 h-4 ${N?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:dt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(De,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:xt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Pe,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:(()=>void de()),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(_e,{className:"w-4 h-4"}),g&&["running","canceling"].includes(g.status)?"继续批量任务":"批量铺货"]}),g&&!["running","canceling"].includes(g.status)&&e.jsx("button",{onClick:(()=>void xe()),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[Fe.map(t=>{const c=mt(t),_=c.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex flex-col",children:[e.jsxs("div",{className:"absolute top-2 right-2 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:[e.jsx("button",{onClick:(()=>lt(t)),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md text-gray-600 hover:bg-brand hover:text-white transition-colors",title:"编辑",children:e.jsx(yt,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:(()=>nt(t)),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md hover:bg-red-100 text-red-500 transition-colors",title:"删除",children:e.jsx(ft,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"aspect-square bg-gray-100 rounded-xl mb-2.5 overflow-hidden relative",children:[t.item_image?e.jsx("img",{src:t.item_image,alt:"",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(jt,{className:"w-8 h-8"})}),e.jsx("div",{className:"absolute top-1.5 left-1.5 bg-black/50 backdrop-blur-md text-white text-[10px] font-bold px-1.5 py-0.5 rounded-md",children:Yt(t.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:t.item_title}),e.jsxs("div",{className:"mb-2 inline-flex min-w-0 max-w-full items-center gap-1 self-start rounded-md bg-blue-50 px-2 py-1 text-[10px] font-extrabold text-blue-700",title:Ge(t.cookie_id),children:[e.jsx($e,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:Ge(t.cookie_id)})]}),e.jsxs("div",{className:"flex justify-between items-center text-[10px] text-gray-500 mb-2",children:[e.jsxs("span",{className:"bg-gray-100 px-1.5 py-0.5 rounded truncate max-w-[80px]",children:["ID: ",t.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${_?"text-emerald-600":"text-amber-600"}`,children:[_?e.jsx(Oe,{className:"w-3 h-3"}):e.jsx(vt,{className:"w-3 h-3"}),_?`${c.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:(()=>s(t)),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${_?"bg-gray-900 text-white hover:bg-black":"bg-brand text-white hover:bg-brand-highlight shadow-md shadow-blue-100"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{className:"w-3.5 h-3.5"}),_?"查看发货规则":"关联发货规则"]}),e.jsx(wt,{className:"w-3.5 h-3.5"})]})})]},`${t.cookie_id}-${t.item_id}`)}),Fe.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(_t,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),I?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),ee&&Le&&we.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"560px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"编辑商品"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["ID: ",Le.item_id]})]}),e.jsx("button",{onClick:(()=>T(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(ye,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-4",children:[e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"商品标题",value:se.item_title||"",onChange:(t=>Ne({...se,item_title:t.target.value}))}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:se.item_price||"",onChange:(t=>Ne({...se,item_price:t.target.value}))}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:se.item_category||"",onChange:(t=>Ne({...se,item_category:t.target.value}))}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:se.item_description||"",onChange:(t=>Ne({...se,item_description:t.target.value}))})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:rt,className:"w-full ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(kt,{className:"w-4 h-4"}),"保存"]})})]})}),document.body),P&&we.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"720px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"添加商品"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"手动建立商品与自动发货规则的关联"})]}),e.jsx("button",{onClick:(()=>ue(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(ye,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"所属账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:J.cookie_id,onChange:(t=>pe({...J,cookie_id:t.target.value})),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(t=>e.jsx("option",{value:t.id,children:be(t.id)},t.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品 ID"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"输入闲鱼商品 ID",value:J.item_id,onChange:(t=>pe({...J,item_id:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品价格"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如 99.00",value:J.item_price,onChange:(t=>pe({...J,item_price:t.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品标题"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"输入商品标题",value:J.item_title,onChange:(t=>pe({...J,item_title:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"图片 URL"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://...",value:J.item_image,onChange:(t=>pe({...J,item_image:t.target.value}))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:it,className:"w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(De,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),he&&we.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"820px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"发布商品到闲鱼"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"普通单规格发布;库存数量会写入闲鱼发布参数,用于判断账号库存能力。"})]}),e.jsx("button",{onClick:(()=>Ce(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(ye,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-800 leading-6",children:"发布时必须填写库存。若账号没有库存发布能力,后端会返回明确的“库存权限不足”错误,不会误报为普通发布失败。"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:w.cookie_id,onChange:(t=>{V({...w,cookie_id:t.target.value}),tt([]),Ee(null)}),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(t=>e.jsx("option",{value:t.id,children:be(t.id)},t.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品标题"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:会员月卡自动发货",value:w.title,onChange:(t=>V({...w,title:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"库存数量"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",type:"number",min:"1",placeholder:"必须大于 0",value:w.quantity,onChange:(t=>V({...w,quantity:t.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品描述"}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述会用于自动识别类目;留空时使用标题",value:w.description,onChange:(t=>V({...w,description:t.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"售价"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"99.00",value:w.price,onChange:(t=>V({...w,price:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"原价(可选)"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"129.00",value:w.original_price,onChange:(t=>V({...w,original_price:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"运费方式"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:w.postage_mode,onChange:(t=>V({...w,postage_mode:t.target.value})),children:[e.jsx("option",{value:"free",children:"包邮"}),e.jsx("option",{value:"distance",children:"按距离计费"}),e.jsx("option",{value:"fixed",children:"一口价邮费"}),e.jsx("option",{value:"none",children:"无需邮寄"})]})]})]}),w.postage_mode==="fixed"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"一口价邮费"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如 8.00",value:w.postage,onChange:(t=>V({...w,postage:t.target.value}))})]}),e.jsxs("div",{className:"rounded-2xl border border-sky-200 bg-sky-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"发货地(可选)"}),e.jsx("p",{className:"mt-1 text-xs text-sky-800",children:"虚拟商品无需发货地;发布失败时可再定位并作为补充信息提交。"})]}),e.jsxs("button",{type:"button",disabled:ie||!w.cookie_id,onClick:(()=>void Re(!1)),className:"ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50",children:[e.jsx(Ue,{className:"h-4 w-4"}),ie?"定位中...":"获取当前位置"]})]}),te.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,te.indexOf(st))),onChange:(t=>Ee(te[Number(t.target.value)]||null)),children:te.map((t,c)=>e.jsx("option",{value:String(c),children:[t.province,t.city,t.area,t.poi_name].filter(Boolean).join(" ")},`${t.division_id}-${t.poi_id}-${c}`))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品图片(1-9 张)"}),e.jsxs("label",{className:"flex min-h-[120px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50/50 transition-colors",children:[e.jsx(_e,{className:"w-8 h-8 text-emerald-600 mb-2"}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"选择图片"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:w.images.length?"已选择 "+w.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:(t=>V({...w,images:Array.from(t.target.files||[]).slice(0,9)}))})]}),Ae.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:Ae.map(t=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:t.url,alt:"",className:"w-full h-full object-cover"})},t.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:A,onClick:ct,className:"w-full bg-emerald-500 hover:bg-emerald-600 disabled:opacity-60 text-white px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),A?"正在发布...":"发布到闲鱼"]})})]})}),document.body),E&&we.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"980px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量铺货"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"上传商品表格和图片 zip,先预检,再逐条发布到闲鱼。"})]}),e.jsx("button",{onClick:(()=>void h()),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(ye,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx(Zt,{phase:j}),j==="upload"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"rounded-2xl border border-blue-100 bg-blue-50 p-4 text-sm text-blue-900 leading-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:"先下载模板,再按字段填写。"}),e.jsxs("div",{children:["图片字段写 zip 内相对路径,多个图片用英文分号分隔,例如 ",e.jsx("span",{className:"font-mono font-bold",children:"images/a.jpg;images/b.jpg"}),"。也支持直接填写图片 URL。"]})]}),e.jsx("button",{type:"button",onClick:ot,className:"shrink-0 rounded-xl bg-blue-600 px-4 py-2 text-sm font-extrabold text-white hover:bg-blue-700",children:"下载CSV模板"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"默认发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:k,onChange:(t=>{R(t.target.value),O([]),ae(null)}),children:[e.jsx("option",{value:"",children:"选择账号"}),f.map(t=>e.jsx("option",{value:t.id,children:be(t.id)},t.id))]}),e.jsx("p",{className:"text-xs text-gray-500",children:"表格中“账号ID”为空时,会使用这里选择的账号。"})]}),e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50/70 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-extrabold text-gray-900",children:["默认类目 ",e.jsx("span",{className:"font-medium text-gray-500",children:"(可为空)"})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-amber-800",children:"填写后优先使用该类目;留空时由闲鱼根据每件商品自动识别。仍无法识别时,系统最终使用“电子资料”兜底。"})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("label",{className:"relative flex-1",children:[e.jsx("span",{className:"sr-only",children:"类目关键词"}),e.jsx(ze,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"w-full ios-input rounded-xl bg-white py-2.5 pl-10 pr-3",placeholder:"输入关键词,例如:课程资料、设计素材",value:z,onChange:(t=>D(t.target.value)),onKeyDown:(t=>{t.key==="Enter"&&(t.preventDefault(),ne())})})]}),e.jsxs("button",{type:"button",disabled:!k||!z.trim()||Z,onClick:(()=>void ne()),className:"ios-btn-primary flex min-h-[42px] items-center justify-center gap-2 rounded-xl px-4 text-sm font-bold disabled:opacity-50",children:[e.jsx(ze,{className:"h-4 w-4"}),Z?"匹配中...":"获取类目"]})]}),C.catId?e.jsxs("div",{className:"flex min-h-[46px] items-center justify-between gap-3 border-t border-amber-200 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-bold text-gray-900",children:[e.jsx(Oe,{className:"h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("span",{className:"truncate",children:C.catName})]}),e.jsxs("div",{className:"mt-1 font-mono text-xs text-gray-500",children:["类目 ",C.catId," · 频道 ",C.channelCatId]})]}),e.jsx("button",{type:"button",title:"清除默认类目",onClick:(()=>le({catId:"",catName:"",channelCatId:"",tbCatId:""})),className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-gray-500 hover:bg-white hover:text-gray-900",children:e.jsx(ye,{className:"h-4 w-4"})})]}):null]}),e.jsxs("div",{className:"rounded-xl border border-sky-200 bg-sky-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"批次发货地(可选)"}),e.jsx("p",{className:"mt-1 text-xs text-sky-800",children:"虚拟商品可留空;填写后整个批次使用同一个发货地,并随任务保存用于恢复和重试。"})]}),e.jsxs("button",{type:"button",disabled:ie||!k,onClick:(()=>void Re(!0)),className:"ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50",children:[e.jsx(Ue,{className:"h-4 w-4"}),ie?"定位中...":"获取当前位置"]})]}),m.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,m.indexOf(re))),onChange:(t=>ae(m[Number(t.target.value)]||null)),children:m.map((t,c)=>e.jsx("option",{value:String(c),children:[t.province,t.city,t.area,t.poi_name].filter(Boolean).join(" ")},`${t.division_id}-${t.poi_id}-${c}`))})]}),e.jsx("div",{className:"rounded-xl border border-violet-200 bg-violet-50 p-4 space-y-2",children:e.jsxs("label",{className:"flex items-center justify-between gap-4",htmlFor:"batch-publish-interval",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-extrabold text-gray-900",children:"商品发布强制间隔"}),e.jsx("span",{className:"mt-1 block text-xs text-violet-800",children:"图片会提前上传,只有最终发布请求之间至少等待该时间。"})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("input",{id:"batch-publish-interval",type:"number",min:1,max:3600,step:1,inputMode:"numeric",className:"ios-input w-24 rounded-xl bg-white px-3 py-2 text-right",value:Q,onChange:(t=>K(Math.min(3600,Math.max(1,Number(t.target.value)||1))))}),e.jsx("span",{className:"text-sm font-bold text-violet-900",children:"秒"})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-blue-300 hover:bg-blue-50 transition-colors",children:[e.jsx(_e,{className:"w-9 h-9 text-blue-600 mb-3"}),e.jsx("span",{className:"text-sm font-extrabold text-gray-900",children:"上传商品表格"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:S?S.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:(t=>{var c;return Y(((c=t.target.files)==null?void 0:c[0])||null)})})]}),e.jsxs("label",{className:"flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50 transition-colors",children:[e.jsx(_e,{className:"w-9 h-9 text-emerald-600 mb-3"}),e.jsx("span",{className:"text-sm font-extrabold text-gray-900",children:"上传图片 zip(可选)"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:H?H.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:(t=>{var c;return X(((c=t.target.files)==null?void 0:c[0])||null)})})]})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 border border-gray-100 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"字段说明"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"照着下面的“什么时候填写”处理即可。预检发现问题时,会指出具体哪一行需要修改。"})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 text-xs text-blue-950",children:[e.jsx("div",{className:"text-sm font-extrabold",children:"“付款后发送的卡密”怎么填"}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-3 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101"}),e.jsx("p",{className:"mt-1 leading-5",children:"从卡密组 101 立即发送 1 份。卡密组 ID 可以在“卡密库存”页面查看。"})]}),e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101:2"}),e.jsx("p",{className:"mt-1 leading-5",children:"每购买 1 件,就从卡密组 101 发送 2 份。买家购买 3 件时会发送 6 份。"})]}),e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101:1:0;102:2:3"}),e.jsx("p",{className:"mt-1 leading-5",children:"先立即发送卡密组 101 的 1 份,再等待 3 秒发送卡密组 102 的 2 份。"})]})]}),e.jsxs("p",{className:"mt-3 leading-5 text-blue-800",children:["每一组依次写“卡密组 ID : 每件发送几份 : 等待几秒”。份数不写时按 1 份处理,等待时间不写时立即发送。需要发送多种卡密时,用英文分号 ",e.jsx("code",{className:"font-bold",children:";"})," 隔开。"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-gray-100 bg-white",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"字段"}),e.jsx("th",{className:"px-3 py-2",children:"什么时候填写"}),e.jsx("th",{className:"px-3 py-2",children:"填写方法"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 text-gray-700",children:[["账号ID","需要覆盖默认账号时填写","上方默认发布账号为必选;本列留空时使用默认账号,填写后仅覆盖当前行"],["标题","每个商品都要填","填写买家能看到的商品标题"],["描述","可以留空","留空时会使用商品标题作为描述"],["价格","每个商品都要填","只填数字,例如 19.90"],["原价","可以留空","需要展示划线原价时填写,例如 29.90"],["库存","可以留空","留空按 1 件处理;填写时必须大于 0"],["邮费模式","可以留空","留空表示包邮;包邮填 free,固定邮费填 fixed"],["邮费","邮费模式填 fixed 时填写","只填数字,例如 8.00"],["图片","每个商品都要填","填写 zip 内图片路径或图片网址;多张图片用英文分号隔开"],["类目ID","需要指定当前行默认类目时填写","必须和“类目名称、频道类目ID”同时填写;优先于自动识别"],["类目名称","填写了“类目ID”时必填","填写该 ID 对应的准确类目名称"],["频道类目ID","覆盖类目时必填","必须填写闲鱼返回的准确频道类目 ID"],["淘宝类目ID","按闲鱼返回填写","“电子资料”无淘宝类目 ID,保持为空"],["付款发货启用","需要付款后自动发货时填写","填“是”表示开启;不需要时填“否”或留空"],["付款发货内容","“付款发货启用”填“是”时填写","从“卡密库存”页面取得卡密组 ID,按上方示例填写"],["评价赠品启用","需要评价赠品时填写","填“是”表示开启;不需要时填“否”或留空"],["评价赠品内容","“评价赠品启用”填“是”时填写","格式和付款发货内容相同,也可以同时发送多个卡密组"],["求评价启用","需要自动求评价时填写","填“是”表示开启;不需要时填“否”或留空"],["求评价等待小时","“求评价启用”填“是”时填写","填写等待小时数;留空按 72 小时处理"],["求评价文案","“求评价启用”填“是”时填写","填写要发送给买家的求评价消息"],["求评价最多次数","可以留空","留空只提醒 1 次"]].map(([t,c,_])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:t}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${c==="每个商品都要填"?"text-red-600":c==="可以留空"?"text-gray-500":"text-amber-700"}`,children:c}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:_})]},t))})]})})]})]}),j==="preview"&&b&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-2xl bg-gray-50 p-4 border border-gray-100",children:[e.jsx("div",{className:"text-xs font-bold text-gray-500",children:"总行数"}),e.jsx("div",{className:"text-2xl font-extrabold text-gray-900 mt-1",children:b.total})]}),e.jsxs("div",{className:"rounded-2xl bg-emerald-50 p-4 border border-emerald-100",children:[e.jsx("div",{className:"text-xs font-bold text-emerald-700",children:"可发布"}),e.jsx("div",{className:"text-2xl font-extrabold text-emerald-700 mt-1",children:b.valid})]}),e.jsxs("div",{className:"rounded-2xl bg-red-50 p-4 border border-red-100",children:[e.jsx("div",{className:"text-xs font-bold text-red-700",children:"有问题"}),e.jsx("div",{className:"text-2xl font-extrabold text-red-700 mt-1",children:b.invalid})]})]}),e.jsx("div",{className:"max-h-[380px] overflow-y-auto rounded-2xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-white text-xs text-gray-400 border-b border-gray-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"行号"}),e.jsx("th",{className:"px-4 py-3",children:"状态"}),e.jsx("th",{className:"px-4 py-3",children:"标题"}),e.jsx("th",{className:"px-4 py-3",children:"价格/库存"}),e.jsx("th",{className:"px-4 py-3",children:"类目策略"}),e.jsx("th",{className:"px-4 py-3",children:"图片"}),e.jsx("th",{className:"px-4 py-3",children:"问题"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:b.rows.map(t=>{var c,_,ge,ce;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:t.row_no}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-1 rounded-lg border text-xs font-extrabold ${t.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:t.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:t.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",t.price||"-"," / ",t.quantity||1]}),e.jsxs("td",{className:"px-4 py-3 text-xs text-gray-600 min-w-[150px]",children:[e.jsx("div",{className:"font-bold text-gray-800",children:((c=t.category)==null?void 0:c.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((_=t.category)==null?void 0:_.cat_id)||"失败后使用电子资料"})]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((ge=t.images)==null?void 0:ge.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((ce=t.errors)==null?void 0:ce.join(";"))||"-"})]},t.row_no)})})]})})]}),(j==="running"||j==="done")&&y&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsxs("div",{className:`rounded-2xl p-4 border ${Ye(y.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:We(y.status)})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 p-4 border border-gray-100",children:[e.jsx("div",{className:"text-xs font-bold text-gray-500",children:"总数"}),e.jsx("div",{className:"text-xl font-extrabold text-gray-900 mt-1",children:y.total})]}),e.jsxs("div",{className:"rounded-2xl bg-emerald-50 p-4 border border-emerald-100",children:[e.jsx("div",{className:"text-xs font-bold text-emerald-700",children:"成功"}),e.jsx("div",{className:"text-xl font-extrabold text-emerald-700 mt-1",children:y.success})]}),e.jsxs("div",{className:"rounded-2xl bg-red-50 p-4 border border-red-100",children:[e.jsx("div",{className:"text-xs font-bold text-red-700",children:"失败"}),e.jsx("div",{className:"text-xl font-extrabold text-red-700 mt-1",children:y.failed})]}),e.jsxs("div",{className:"rounded-2xl bg-blue-50 p-4 border border-blue-100",children:[e.jsx("div",{className:"text-xs font-bold text-blue-700",children:"等待"}),e.jsx("div",{className:"text-xl font-extrabold text-blue-700 mt-1",children:y.pending})]})]}),e.jsx("div",{className:"max-h-[420px] overflow-y-auto rounded-2xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-white text-xs text-gray-400 border-b border-gray-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"行号"}),e.jsx("th",{className:"px-4 py-3",children:"状态"}),e.jsx("th",{className:"px-4 py-3",children:"标题"}),e.jsx("th",{className:"px-4 py-3",children:"类目策略"}),e.jsx("th",{className:"px-4 py-3",children:"商品ID"}),e.jsx("th",{className:"px-4 py-3",children:"错误原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:y.rows.map(t=>{var c,_;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:t.row_no}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-1 rounded-lg border text-xs font-extrabold ${Ye(t.status)}`,children:We(t.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:t.title}),e.jsxs("td",{className:"px-4 py-3 text-xs text-gray-600 min-w-[150px]",children:[e.jsx("div",{className:"font-bold text-gray-800",children:((c=t.category)==null?void 0:c.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((_=t.category)==null?void 0:_.cat_id)||"失败后使用电子资料"})]}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:t.item_url?e.jsx("a",{href:t.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:t.item_id}):t.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:t.error_message||"-"})]},t.id)})})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[j==="upload"&&e.jsxs("button",{disabled:x||!S||!k,onClick:me,className:"w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Se,{className:`w-4 h-4 ${x?"animate-spin":""}`}),x?"正在预检...":"开始预检"]}),j==="preview"&&b&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:x,onClick:(()=>void i()),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold",children:"返回修改"}),e.jsxs("button",{disabled:x||b.valid<=0,onClick:ve,className:"flex-1 ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Pe,{className:"w-4 h-4"}),x?"启动中...":`确认发布 ${b.valid} 个商品`]})]}),(j==="running"||j==="done")&&y&&e.jsxs("div",{className:"flex gap-3 w-full",children:[y.status==="running"?e.jsx("button",{disabled:x,onClick:l,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):y.status==="canceling"?e.jsx("button",{disabled:!0,className:"flex-1 px-6 py-3.5 rounded-xl bg-amber-100 text-amber-800 font-bold",children:"正在保存远端结果并安全取消…"}):e.jsx("button",{onClick:(()=>window.open(`/api/v1/items/publish-batches/${y.id}/result.csv`,"_blank")),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"下载结果"}),y.retryable>0&&!["running","canceling"].includes(y.status)&&e.jsxs("button",{disabled:x,onClick:L,className:"flex-1 ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Se,{className:`w-4 h-4 ${x?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(y.status)&&e.jsx("button",{onClick:(()=>{h(),M(),F()}),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold",children:"完成"})]})]})]})}),document.body)]})};export{ss as default};
|