3 lines
57 KiB
JavaScript
3 lines
57 KiB
JavaScript
import{r as i,j as e,b as be}from"./react-vendor-C_od1ZSF.js";import{g as xe,a as te,b as We,d as Ye,p as gt}from"./index-Dw5V5tCq.js";import{c as He}from"./contract-COFcZjyb.js";import{a3 as bt,U as Me,R as we,N as Ee,a4 as _e,a5 as ye,V as yt,F as ft,B as jt,a6 as Ge,a7 as vt,a8 as Nt,A as wt,d as _t,X as oe,r as kt,a9 as $e,I as De}from"./icons-vendor-CvzvbbIV.js";const Ue="ydisks-amap-js-api",Ct="c9b68d4ce9a2a97f22a4a439404488ca";let de=null;const It=()=>Ct,St=()=>window.AMap?Promise.resolve(window.AMap):de||(de=new Promise((s,r)=>{const o=document.getElementById(Ue),u=o||document.createElement("script"),h=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(S)},j=()=>{window.AMap?(h(),s(window.AMap)):(h(),r(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},S=window.setTimeout(()=>{h(),r(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=j,u.id=Ue,u.async=!0,u.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(It())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,u.onerror=()=>{h(),r(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},o||document.head.appendChild(u)}).catch(s=>{throw de=null,s}),de),fe=s=>Number.isFinite(s)&&s!==0,Pt=s=>{var h,j;const r=Number((h=s.location)==null?void 0:h.lng),o=Number((j=s.location)==null?void 0:j.lat),u={area:String(s.adname||"").trim(),city:String(s.cityname||"").trim(),division_id:String(s.adcode||"").trim(),longitude:r,latitude:o,poi_id:String(s.id||"").trim(),poi_name:String(s.name||"").trim(),province:String(s.pname||"").trim()};return!u.division_id||!u.province||!u.city||!u.poi_id||!u.poi_name||!fe(r)||!fe(o)||r<-180||r>180||o<-90||o>90?null:u},Bt=async(s,r)=>{if(!fe(s)||!fe(r)||s<-180||s>180||r<-90||r>90)throw new Error("经纬度无效");const o=await St();return new Promise((u,h)=>{new o.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[s,r],1e3,(S,w)=>{var C;if(S!=="complete"){if(S==="no_data"){u([]);return}h(new Error("高德地图附近地址查询失败,请稍后重试"));return}const R=(((C=w==null?void 0:w.poiList)==null?void 0:C.pois)||[]).map(Pt).filter(D=>D!==null);u(R)})})},qt=async s=>xe("/api/v1/accounts/details",void 0,s),ze=async s=>xe("/api/v1/automation-rules",void 0,s),ke=s=>s===!0||s===1||s==="1",Oe=async(s,r)=>{const o=await xe("/api/v1/items",void 0,r);return He(o,["items","data","results"]).map(h=>({...h,id:h.id||`${h.cookie_id}-${h.item_id}`,is_multi_spec:ke(h.is_multi_spec),is_multi_qty_ship:ke(h.is_multi_qty_ship??h.multi_quantity_delivery),multi_quantity_delivery:ke(h.multi_quantity_delivery??h.is_multi_qty_ship)}))},Ft=async s=>te("/api/v1/items/get-all-from-account",{cookie_id:s}),Rt=async(s,r)=>Ye(`/api/v1/items/${s}/${r}`),Lt=async(s,r)=>te(`/api/v1/items/${s}`,r),At=async s=>{const r=new FormData;r.set("cookie_id",s.cookie_id),r.set("title",s.title),r.set("description",s.description),r.set("price",s.price),r.set("original_price",s.original_price||""),r.set("quantity",String(s.quantity)),r.set("postage_mode",s.postage_mode),r.set("postage",s.postage||""),s.location&&r.set("location",JSON.stringify(s.location));for(const o of s.images)r.append("images",o);return We("/api/v1/items/publish",r)},Mt=async(s,r,o)=>te("/api/v1/items/publish-categories/recommend",{cookie_id:s,keyword:r},o),Et=async(s,r)=>{const o=new FormData;return o.set("file",s.file),s.imagesZip&&o.set("images_zip",s.imagesZip),s.defaultCookieId&&o.set("default_cookie_id",s.defaultCookieId),o.set("fallback_category_id",s.fallbackCategory.catId),o.set("fallback_category_name",s.fallbackCategory.catName),o.set("fallback_channel_category_id",s.fallbackCategory.channelCatId||""),o.set("fallback_tb_category_id",s.fallbackCategory.tbCatId||""),s.location&&o.set("location",JSON.stringify(s.location)),We("/api/v1/items/publish-batches/preview",o,r)},Gt=async(s,r)=>te("/api/v1/items/publish-batches",{preview_id:s},r),ee=async(s,r)=>xe(`/api/v1/items/publish-batches/${s}`,void 0,r),Xe=async(s=20,r)=>{const o=await xe("/api/v1/items/publish-batches",{limit:s},r);return He(o,["batches","data","items"])},Te=async(s,r)=>Ye(`/api/v1/items/publish-batches/${s}`,void 0,r),$t=async(s,r)=>te(`/api/v1/items/publish-batches/${s}/cancel`,{},r),Dt=async(s,r)=>te(`/api/v1/items/publish-batches/${s}/retry-failed`,{},r),Ut=async(s,r,o)=>gt(`/api/v1/items/${s}/${r}`,o),zt=s=>s.find(r=>r.status==="running"||r.status==="canceling"),Ie=s=>s==="running"||s==="canceling",Ot=s=>!!(s!=null&&s.preview_id&&Number(s.valid||0)>0),Tt=s=>!!(s!=null&&s.id&&Number(s.retryable||0)>0&&!Ie(s.status)),Kt=(s,r)=>s===r,Ke=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||"-"}},Je=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"}},Jt=s=>{const[r,o]=i.useState(!1),[u,h]=i.useState("upload"),[j,S]=i.useState(null),[w,R]=i.useState(null),[C,D]=i.useState(""),[M,E]=i.useState(!1),[B,G]=i.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[b,q]=i.useState(null),[d,v]=i.useState(null),[k,U]=i.useState(null),[z,O]=i.useState([]),[L,F]=i.useState(null),[Z,y]=i.useState(!1),T=i.useRef(!1),g=i.useRef(0),f=i.useRef(null),x=i.useCallback(()=>{var l;(l=f.current)==null||l.abort();const a=new AbortController;f.current=a;const n=++g.current;return{controller:a,requestGeneration:n}},[]),m=i.useCallback((a,n)=>a===g.current&&n===f.current&&!n.signal.aborted,[]);i.useEffect(()=>(()=>{var a;(a=f.current)==null||a.abort(),g.current+=1}),[]);const K=i.useCallback(async()=>{const a=x();h("upload"),q(null),v(null),S(null),R(null),D(""),G({catId:"",catName:"",channelCatId:"",tbCatId:""}),O([]),F(null),o(!0),y(!0);try{const n=await Xe(20,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;const l=zt(n);if(l!=null&&l.id){const p=await ee(l.id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;U(p),v(p),h(["running","canceling"].includes(p.status)?"running":"done")}}catch(n){if(!m(a.requestGeneration,a.controller))return;console.error("恢复最近批量铺货任务失败:",n)}finally{m(a.requestGeneration,a.controller)&&y(!1)}},[x,m]),Y=i.useCallback(async()=>{const a=C.trim();if(!s.selectedAccount){alert("请先选择默认发布账号");return}if(!a){alert("请输入类目关键词");return}const n=x();E(!0);try{const l=await Mt(s.selectedAccount,a,{signal:n.controller.signal});if(!m(n.requestGeneration,n.controller))return;const p=l.category;G({catId:p.cat_id,catName:p.cat_name,channelCatId:p.channel_cat_id,tbCatId:p.tb_cat_id||""})}catch(l){if(!m(n.requestGeneration,n.controller))return;console.error("获取推荐类目失败:",l),alert((l==null?void 0:l.message)||"没有匹配到类目,请换一个更具体的关键词")}finally{m(n.requestGeneration,n.controller)&&E(!1)}},[C,x,m,s.selectedAccount]),H=i.useCallback(async()=>{if(!(k!=null&&k.id))return;const a=x();y(!0),o(!0);try{const n=await ee(k.id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;v(n),h(["running","canceling"].includes(n.status)?"running":"done")}catch(n){if(!m(a.requestGeneration,a.controller))return;console.error("加载最近批量铺货结果失败:",n)}finally{m(a.requestGeneration,a.controller)&&y(!1)}},[x,m,k==null?void 0:k.id]),V=i.useCallback(async()=>{if(!j){alert("请先上传商品表格");return}if(!s.selectedAccount){alert("请先选择默认发布账号");return}const a=x();y(!0);try{const n=await Et({file:j,imagesZip:w,defaultCookieId:s.selectedAccount,fallbackCategory:B,location:L||void 0},{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;q(n),v(null),h("preview")}catch(n){if(!m(a.requestGeneration,a.controller))return;console.error("批量铺货预检失败:",n),alert((n==null?void 0:n.message)||"预检失败,请检查表格和图片 zip")}finally{m(a.requestGeneration,a.controller)&&y(!1)}},[B,j,w,L,x,m,s.selectedAccount]),se=i.useCallback(async()=>{if(!(b!=null&&b.preview_id))return;if(!Ot(b)){alert("没有可发布的商品行");return}const a=x();y(!0);try{const n=await Gt(b.preview_id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;const l=await ee(n.batch_id||b.preview_id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;v(l),U(l),h(l.status==="running"?"running":"done")}catch(n){if(!m(a.requestGeneration,a.controller))return;console.error("启动批量铺货失败:",n),alert((n==null?void 0:n.message)||"启动发布任务失败")}finally{m(a.requestGeneration,a.controller)&&y(!1)}},[b,x,m]),X=i.useCallback(async()=>{if(!(d!=null&&d.id)||!confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。"))return;const a=x();y(!0);try{const n=await $t(d.id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;const l=await ee(d.id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;v(l),h((n==null?void 0:n.status)==="canceling"||l.status==="canceling"?"running":"done")}catch(n){if(!m(a.requestGeneration,a.controller))return;alert((n==null?void 0:n.message)||"取消失败")}finally{m(a.requestGeneration,a.controller)&&y(!1)}},[d==null?void 0:d.id,x,m]),ae=i.useCallback(async()=>{const a=b==null?void 0:b.preview_id,n=x();if(a&&u==="preview")try{await Te(a,{signal:n.controller.signal})}catch(l){if(!m(n.requestGeneration,n.controller))return;console.error("清理批量铺货预检失败:",l)}m(n.requestGeneration,n.controller)&&(q(null),h("upload"))},[u,b==null?void 0:b.preview_id,x,m]),le=i.useCallback(async()=>{var n;const a=b==null?void 0:b.preview_id;if((n=f.current)==null||n.abort(),g.current+=1,q(null),h("upload"),o(!1),a&&u==="preview")try{await Te(a)}catch(l){console.error("关闭批量铺货弹窗时清理预检失败:",l)}},[u,b==null?void 0:b.preview_id]),re=i.useCallback(async()=>{if(!(d!=null&&d.id)||!Tt(d))return;const a=x();y(!0);try{if(await Dt(d.id,{signal:a.controller.signal}),!m(a.requestGeneration,a.controller))return;const n=await ee(d.id,{signal:a.controller.signal});if(!m(a.requestGeneration,a.controller))return;v(n),h("running")}catch(n){if(!m(a.requestGeneration,a.controller))return;alert((n==null?void 0:n.message)||"重试失败")}finally{m(a.requestGeneration,a.controller)&&y(!1)}},[d,x,m]);return i.useEffect(()=>{if(!r||!(d!=null&&d.id)||!Ie(d.status))return;const a=++g.current,n=async()=>{if(!T.current){T.current=!0;try{const p=await ee(d.id);if(!Kt(a,g.current))return;v(p),U(p),Ie(p.status)||(h("done"),await Promise.all([s.loadItems(),s.loadShippingRules()]))}catch(p){console.error("刷新批量铺货进度失败:",p)}finally{T.current=!1}}},l=window.setInterval(()=>void n(),3e3);return(()=>{window.clearInterval(l),g.current+=1})},[d==null?void 0:d.id,d==null?void 0:d.status,s.loadItems,s.loadShippingRules,r]),{showBatchModal:r,setShowBatchModal:o,batchLoading:Z,batchPhase:u,setBatchPhase:h,batchFile:j,setBatchFile:S,batchImagesZip:w,setBatchImagesZip:R,batchCategoryKeyword:C,setBatchCategoryKeyword:D,batchCategoryLoading:M,batchFallbackCategory:B,setBatchFallbackCategory:G,batchPreview:b,setBatchPreview:q,batchDetail:d,setBatchDetail:v,recentBatch:k,setRecentBatch:U,batchLocations:z,batchLocation:L,setBatchLocations:O,setBatchLocation:F,openBatchModal:K,handleRecommendBatchCategory:Y,openRecentBatchResult:H,handlePreviewBatch:V,handleStartBatch:se,handleCancelBatch:X,abandonBatchPreview:ae,closeBatchModal:le,handleRetryBatchFailed:re}},Ze=()=>({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),Ve=(s="")=>({cookie_id:s,title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),Ce=(s,r)=>{if(s instanceof Error)return s.message;const o=typeof s=="object"&&s!==null&&"message"in s?s.message:void 0;return typeof o=="string"?o:r},Zt=({selectedAccount:s,setSelectedAccount:r,setItems:o,loadItems:u,loadShippingRules:h,onConfigureDelivery:j,setBatchLocations:S,setBatchLocation:w})=>{const[R,C]=i.useState(!1),[D,M]=i.useState(!1),[E,B]=i.useState(!1),[G,b]=i.useState(!1),[q,d]=i.useState(!1),[v,k]=i.useState(!1),[U,z]=i.useState([]),[O,L]=i.useState(null),[F,Z]=i.useState(null),[y,T]=i.useState({}),[g,f]=i.useState(Ze),[x,m]=i.useState(Ve),[K,Y]=i.useState([]);i.useEffect(()=>{if(!q||x.images.length===0){Y([]);return}const l=x.images.map((p,I)=>({key:p.name+I,url:URL.createObjectURL(p)}));return Y(l),(()=>l.forEach(p=>URL.revokeObjectURL(p.url)))},[x.images,q]);const H=i.useCallback(async()=>{if(!s)return alert("请先选择账号");C(!0);try{const l=await Ft(s);await u(),alert((l==null?void 0:l.message)||"商品同步完成")}catch(l){console.error("同步商品失败:",l),alert(Ce(l,"同步失败,请重试"))}finally{C(!1)}},[u,s]),V=i.useCallback(l=>{Z(l),T({...l}),B(!0)},[]),se=i.useCallback(async()=>{if(F)try{await Ut(F.cookie_id,F.item_id,{item_title:y.item_title||"",item_description:y.item_description||"",item_category:y.item_category||"",item_price:y.item_price||"",item_detail:y.item_detail||F.item_detail||""}),await u(),await h(),B(!1),Z(null)}catch(l){console.error("更新商品失败:",l),alert("更新失败,请重试")}},[y,u,h,F]),X=i.useCallback(async l=>{if(confirm(`确认删除商品"${l.item_title}"吗?`))try{await Rt(l.cookie_id,l.item_id),o(p=>p.filter(I=>!(I.cookie_id===l.cookie_id&&I.item_id===l.item_id)))}catch(p){console.error("删除商品失败:",p),alert("删除失败,请重试")}},[o]),ae=i.useCallback(async()=>{try{if(!g.cookie_id||!g.item_id){alert("请选择账号并填写商品ID");return}await Lt(g.cookie_id,{item_id:g.item_id,item_title:g.item_title,item_price:g.item_price,item_detail:g.item_image?JSON.stringify({item_image:g.item_image}):""}),await u(),b(!1),f(Ze())}catch(l){console.error("添加商品失败:",l),alert("添加失败,请重试")}},[g,u]),le=i.useCallback(async()=>{if(!x.cookie_id)return alert("请选择发布账号");if(!x.title.trim())return alert("请填写商品标题");if(!x.price.trim())return alert("请填写商品价格");if(!x.quantity||Number(x.quantity)<=0)return alert("库存数量必须大于 0");if(x.images.length===0)return alert("至少上传 1 张商品图片");if(x.postage_mode==="fixed"&&!x.postage.trim())return alert("请填写一口价邮费");M(!0);try{const l=await At({...x,location:O||void 0});if(await u(),d(!1),m(Ve(s||"")),z([]),L(null),l!=null&&l.item_id){const p={id:l.item_id,cookie_id:x.cookie_id,item_id:l.item_id,item_title:l.item_title||x.title,item_price:l.item_price||x.price,item_image:l.item_image};j(p),alert("商品发布成功,ID: "+l.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(l){console.error("发布商品失败:",l);const p=l==null?void 0:l.payload;if((p==null?void 0:p.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert(Ce(l,"发布失败,请重试"))}finally{M(!1)}},[u,j,x,O,s]),re=i.useCallback(()=>{const I=[["账号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(je=>je.map(ve=>`"${String(ve).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),P=new Blob(["\uFEFF"+I],{type:"text/csv;charset=utf-8"}),ue=URL.createObjectURL(P),W=document.createElement("a");W.href=ue,W.download="批量铺货模板.csv",document.body.appendChild(W),W.click(),W.remove(),URL.revokeObjectURL(ue)},[]),me=i.useCallback(()=>{f(l=>({...l,cookie_id:s||l.cookie_id})),b(!0)},[s]),a=i.useCallback(()=>{m(l=>({...l,cookie_id:s||l.cookie_id})),d(!0)},[s]),n=i.useCallback(async l=>{if(!(l?s:x.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");k(!0),navigator.geolocation.getCurrentPosition(async I=>{try{const P=await Bt(I.coords.longitude,I.coords.latitude);if(!P.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");l?(S(P),w(P[0])):(z(P),L(P[0]))}catch(P){alert(Ce(P,"获取发货地失败"))}finally{k(!1)}},I=>{k(!1),alert(I.code===I.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},[x.cookie_id,s,w,S]);return{selectedAccount:s,setSelectedAccount:r,loading:R,publishing:D,showEditModal:E,setShowEditModal:B,showAddModal:G,setShowAddModal:b,showPublishModal:q,setShowPublishModal:d,locationLoading:v,publishLocations:U,setPublishLocations:z,publishLocation:O,setPublishLocation:L,selectedItem:F,editForm:y,setEditForm:T,addForm:g,setAddForm:f,publishForm:x,setPublishForm:m,publishImagePreviews:K,handleSync:H,handleEdit:V,handleSaveEdit:se,handleDelete:X,handleAddItem:ae,handlePublishItem:le,downloadPublishTemplate:re,openAddModal:me,openPublishModal:a,locateForPublish:n}},Vt=({phase:s})=>{const r=[["upload","1 上传"],["preview","2 预检"],["running","3 发布"],["done","4 结果"]];return e.jsx("div",{className:"grid grid-cols-4 gap-2",children:r.map(([o,u])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${s===o?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:u},o))})},Wt=s=>{const r=String(s||"").trim();return r?/^[¥¥]/.test(r)?r:`¥${r}`:"-"},es=({onConfigureDelivery:s})=>{const[r,o]=i.useState([]),[u,h]=i.useState([]),[j,S]=i.useState([]),[w,R]=i.useState(""),[C,D]=i.useState(""),M=i.useRef(0),E=i.useRef(0),B=i.useCallback(async()=>{const t=++M.current,c=await Oe();t===M.current&&o(c)},[]),G=i.useCallback(async()=>{const t=++E.current,c=await ze();t===E.current&&h(c)},[]),b=Jt({selectedAccount:w,loadItems:B,loadShippingRules:G}),{showBatchModal:q,batchLoading:d,batchPhase:v,batchFile:k,setBatchFile:U,batchImagesZip:z,setBatchImagesZip:O,batchCategoryKeyword:L,setBatchCategoryKeyword:F,batchCategoryLoading:Z,batchFallbackCategory:y,setBatchFallbackCategory:T,batchPreview:g,batchDetail:f,recentBatch:x,setRecentBatch:m,batchLocations:K,batchLocation:Y,setBatchLocations:H,setBatchLocation:V,openBatchModal:se,handleRecommendBatchCategory:X,openRecentBatchResult:ae,handlePreviewBatch:le,handleStartBatch:re,handleCancelBatch:me,abandonBatchPreview:a,closeBatchModal:n,handleRetryBatchFailed:l}=b,p=Zt({selectedAccount:w,setSelectedAccount:R,setItems:o,loadItems:B,loadShippingRules:G,onConfigureDelivery:s,setBatchLocations:H,setBatchLocation:V}),{loading:I,publishing:P,showEditModal:ue,setShowEditModal:W,showAddModal:je,setShowAddModal:ve,showPublishModal:Qe,setShowPublishModal:et,locationLoading:he,publishLocations:pe,setPublishLocations:tt,publishLocation:st,setPublishLocation:Se,selectedItem:Pe,editForm:J,setEditForm:ge,addForm:A,setAddForm:ne,publishForm:N,setPublishForm:$,publishImagePreviews:Be,handleSync:at,handleEdit:lt,handleSaveEdit:rt,handleDelete:nt,handleAddItem:it,handlePublishItem:ct,downloadPublishTemplate:ot,openAddModal:dt,openPublishModal:xt,locateForPublish:qe}=p;i.useEffect(()=>{const t=new AbortController,c=++M.current,_=++E.current;let ce=!0;return Promise.all([qt({signal:t.signal}),Oe(void 0,{signal:t.signal}),ze({signal:t.signal}),Xe(20,{signal:t.signal})]).then(([Q,ut,ht,Ae])=>{if(!ce||t.signal.aborted||c!==M.current||_!==E.current)return;S(Q),o(ut),h(ht);const pt=Ae.find(Ne=>["running","canceling"].includes(Ne.status))||Ae.find(Ne=>Ne.status!=="preview");m(pt||null)}).catch(Q=>{t.signal.aborted||console.error("加载商品配置失败:",Q)}),(()=>{ce=!1,t.abort()})},[]);const mt=t=>u.filter(c=>c.cookie_id===t.cookie_id&&c.item_id===t.item_id).length>0?u.filter(c=>c.cookie_id===t.cookie_id&&c.item_id===t.item_id):u.filter(c=>c.cookie_id===t.cookie_id&&!c.item_id),Fe=i.useMemo(()=>new Map(j.map(t=>[t.id,t])),[j]),Re=i.useMemo(()=>C?r.filter(t=>t.cookie_id===C):r,[C,r]),ie=t=>{const c=Fe.get(t),_=(c==null?void 0:c.remark)||(c==null?void 0:c.nickname);return _?`${_} · ${t.slice(0,6)}`:`账号 ${t.slice(0,8)}`},Le=t=>{const c=Fe.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(bt,{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:C,onChange:(t=>D(t.target.value)),children:[e.jsx("option",{value:"",children:"全部账号"}),j.map(t=>e.jsx("option",{value:t.id,children:ie(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(Me,{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:w,onChange:(t=>R(t.target.value)),children:[e.jsx("option",{value:"",children:"请选择账号"}),j.map(t=>e.jsx("option",{value:t.id,children:ie(t.id)},t.id))]})]})]}),e.jsxs("button",{onClick:at,disabled:I||!w,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(we,{className:`w-4 h-4 ${I?"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(Ee,{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(_e,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:(()=>void se()),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(ye,{className:"w-4 h-4"}),x&&["running","canceling"].includes(x.status)?"继续批量任务":"批量铺货"]}),x&&!["running","canceling"].includes(x.status)&&e.jsx("button",{onClick:(()=>void ae()),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:[Re.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:Wt(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:Le(t.cookie_id),children:[e.jsx(Me,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:Le(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(Ge,{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}`)}),Re.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"}),C?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),ue&&Pe&&be.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: ",Pe.item_id]})]}),e.jsx("button",{onClick:(()=>W(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(oe,{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:J.item_title||"",onChange:(t=>ge({...J,item_title:t.target.value}))}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:J.item_price||"",onChange:(t=>ge({...J,item_price:t.target.value}))}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:J.item_category||"",onChange:(t=>ge({...J,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:J.item_description||"",onChange:(t=>ge({...J,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),je&&be.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:(()=>ve(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(oe,{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:A.cookie_id,onChange:(t=>ne({...A,cookie_id:t.target.value})),children:[e.jsx("option",{value:"",children:"选择账号"}),j.map(t=>e.jsx("option",{value:t.id,children:ie(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:A.item_id,onChange:(t=>ne({...A,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:A.item_price,onChange:(t=>ne({...A,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:A.item_title,onChange:(t=>ne({...A,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:A.item_image,onChange:(t=>ne({...A,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(Ee,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),Qe&&be.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:(()=>et(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(oe,{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:N.cookie_id,onChange:(t=>{$({...N,cookie_id:t.target.value}),tt([]),Se(null)}),children:[e.jsx("option",{value:"",children:"选择账号"}),j.map(t=>e.jsx("option",{value:t.id,children:ie(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:N.title,onChange:(t=>$({...N,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:N.quantity,onChange:(t=>$({...N,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:N.description,onChange:(t=>$({...N,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:N.price,onChange:(t=>$({...N,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:N.original_price,onChange:(t=>$({...N,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:N.postage_mode,onChange:(t=>$({...N,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:"无需邮寄"})]})]})]}),N.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:N.postage,onChange:(t=>$({...N,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:he||!N.cookie_id,onClick:(()=>void qe(!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($e,{className:"h-4 w-4"}),he?"定位中...":"获取当前位置"]})]}),pe.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,pe.indexOf(st))),onChange:(t=>Se(pe[Number(t.target.value)]||null)),children:pe.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(ye,{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:N.images.length?"已选择 "+N.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:(t=>$({...N,images:Array.from(t.target.files||[]).slice(0,9)}))})]}),Be.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:Be.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:P,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(_e,{className:"w-4 h-4"}),P?"正在发布...":"发布到闲鱼"]})})]})}),document.body),q&&be.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 n()),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(oe,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx(Vt,{phase:v}),v==="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:w,onChange:(t=>{R(t.target.value),H([]),V(null)}),children:[e.jsx("option",{value:"",children:"选择账号"}),j.map(t=>e.jsx("option",{value:t.id,children:ie(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(De,{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:L,onChange:(t=>F(t.target.value)),onKeyDown:(t=>{t.key==="Enter"&&(t.preventDefault(),X())})})]}),e.jsxs("button",{type:"button",disabled:!w||!L.trim()||Z,onClick:(()=>void X()),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(De,{className:"h-4 w-4"}),Z?"匹配中...":"获取类目"]})]}),y.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(Ge,{className:"h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("span",{className:"truncate",children:y.catName})]}),e.jsxs("div",{className:"mt-1 font-mono text-xs text-gray-500",children:["类目 ",y.catId," · 频道 ",y.channelCatId]})]}),e.jsx("button",{type:"button",title:"清除默认类目",onClick:(()=>T({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(oe,{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:he||!w,onClick:(()=>void qe(!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($e,{className:"h-4 w-4"}),he?"定位中...":"获取当前位置"]})]}),K.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,K.indexOf(Y))),onChange:(t=>V(K[Number(t.target.value)]||null)),children:K.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:"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(ye,{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:k?k.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:(t=>{var c;return U(((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(ye,{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:z?z.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:(t=>{var c;return O(((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))})]})})]})]}),v==="preview"&&g&&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:g.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:g.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:g.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:g.rows.map(t=>{var c,_,ce,Q;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:[((ce=t.images)==null?void 0:ce.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((Q=t.errors)==null?void 0:Q.join(";"))||"-"})]},t.row_no)})})]})})]}),(v==="running"||v==="done")&&f&&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 ${Je(f.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:Ke(f.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:f.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:f.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:f.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:f.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:f.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 ${Je(t.status)}`,children:Ke(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:[v==="upload"&&e.jsxs("button",{disabled:d||!k||!w,onClick:le,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(we,{className:`w-4 h-4 ${d?"animate-spin":""}`}),d?"正在预检...":"开始预检"]}),v==="preview"&&g&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:d,onClick:(()=>void a()),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:d||g.valid<=0,onClick:re,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(_e,{className:"w-4 h-4"}),d?"启动中...":`确认发布 ${g.valid} 个商品`]})]}),(v==="running"||v==="done")&&f&&e.jsxs("div",{className:"flex gap-3 w-full",children:[f.status==="running"?e.jsx("button",{disabled:d,onClick:me,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):f.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/${f.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:"下载结果"}),f.retryable>0&&!["running","canceling"].includes(f.status)&&e.jsxs("button",{disabled:d,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(we,{className:`w-4 h-4 ${d?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(f.status)&&e.jsx("button",{onClick:(()=>{n(),B(),G()}),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{es as default};
|