import{s as L,E as O}from"./elementPlus.4833989a.js";import{u as U}from"./index.ad3efb29.js";import{d as q,ay as z,r as c,_ as H,Z as Y,w as A,ai as y,o as p,M as j,O as _,a as r,U as S,S as N,c as f,T as d,R as g,u as F,K,am as Z}from"./vue.adf17aba.js";import{g as $}from"./api.39068aff.js";import{M as J}from"./enum.111a4a5d.js";const Q={key:0},X={key:1},ee={key:2},te={key:3},ae={key:4},se={style:{display:"flex","align-items":"flex-start"}},oe={style:{"flex-shrink":"0"}},le=["src"],ne={style:{"margin-left":"10px"}},ie={class:"dialog-footer"},_e=q({__name:"select-target",props:{modelValue:{type:Boolean,required:!0},selectedTargetedRow:{type:Object,required:!0}},emits:["update:modelValue"],setup(k,{emit:C}){const D=U();z(D);const m=k,v=C,u=c(m.modelValue),{selectedTargetedRow:i}=H(m);c(m.adGroupId);const I=c(null),h=c(null),x=c([{field:"keywordText",title:"关键词",width:220},{field:"matchType",title:"匹配方式",formatter:({cellValue:t})=>w(t).label},{type:"checkbox",align:"right",width:55}]),T=c([{field:"expressionDesc",title:"品牌",slots:{default:"expressionDesc_default"}},{type:"checkbox",align:"right",width:55}]),R=c([{field:"itemName",title:"商品/分类",slots:{default:"itemName_default"}},{type:"checkbox",align:"right",width:55}]),s=Y({height:550,showOverflow:!0,loading:!1,checkboxConfig:{checkField:"isSelected"},rowConfig:{isHover:!0,height:85},columns:x,data:[]});async function b(){try{s.loading=!0;const t=await $({campaignType:i.value.campaignType,campaignId:i.value.campaignId,adGroupId:i.value.adGroupId});if(h.value=t.data.targetType,h.value==="keyword")s.columns=x,s.rowConfig.height=34,s.data=t.data.targetData.map(o=>({...o,isSelected:i.value.keywordInfo.some(a=>a.keywordId===o.keywordId)}));else if(h.value==="target"){s.rowConfig.height=85,s.columns=T,s.data=t.data.targetData.map(a=>({...a,isSelected:i.value.campaignTargetInfo.some(n=>n.targetId===a.targetId)}));const o=s.data.filter(a=>a.expressionDesc&&a.expressionDesc.ASIN_SAME_AS).map(a=>a.expressionDesc.ASIN_SAME_AS);if(o.length>0){s.columns=R,s.rowConfig.height=120;const a=await fetchProductsList(o),n=new Map(s.data.filter(l=>l.expressionDesc&&l.expressionDesc.ASIN_SAME_AS).map(l=>[l.expressionDesc.ASIN_SAME_AS,l]));s.data=a.map(l=>{const e=n.get(l.asin);return{...l,targetId:e==null?void 0:e.targetId,adGroup_id:e==null?void 0:e.adGroup_id,bid:e==null?void 0:e.bid,isSelected:i.value.campaignTargetInfo.some(E=>E.targetId===(e==null?void 0:e.targetId))}})}}I.value=s.data.filter(o=>o.isSelected),s.loading=!1}catch(t){console.error("Error fetching target rule list:",t),O.error("请求定向数据失败"),s.loading=!1}}function M({records:t,row:o,checked:a}){o?o.isSelected=a:t.forEach(n=>n.isSelected=a),I.value=s.data.filter(n=>n.isSelected)}function w(t){const o=J.find(a=>a.value===t);return o?{label:o.label,type:t}:{label:t,type:""}}function V(){u.value=!1}function B(){u.value=!1,v("confirm:selectTarget",{campaignInfo:I.value,targetType:h.value,adGroupId:i.value.adGroupId,campaignId:i.value.campaignId})}const G=t=>{t?window.open(t,"_blank"):console.warn("Product URL is not available")},P=()=>({fontSize:"13px"}),W=()=>({fontSize:"13px"});return A(()=>m.modelValue,t=>{u.value=t}),A(u,t=>{v("update:modelValue",t),b()}),A(()=>m.selectedTargetedRow,()=>{}),(t,o)=>{const a=y("el-button"),n=y("vxe-grid"),l=y("el-dialog");return p(),j(l,{modelValue:u.value,"onUpdate:modelValue":o[0]||(o[0]=e=>u.value=e),style:{"border-radius":"10px"},title:"关联广告活动 > 选择定向",width:"1158px"},{footer:_(()=>[r("div",ie,[S(a,{onClick:V},{default:_(()=>[N("取消")]),_:1}),S(a,{type:"primary",onClick:B},{default:_(()=>[N("确定")]),_:1})])]),default:_(()=>[S(n,K({"cell-style":W,"header-cell-style":P},s,Z(t.gridEvents),{onCheckboxChange:M}),{expressionDesc_default:_(({row:e})=>[e.expressionDesc.ASIN_CATEGORY_SAME_AS?(p(),f("div",Q,"分类:"+d(e.expressionDesc.ASIN_CATEGORY_SAME_AS),1)):g("",!0),e.expressionDesc.ASIN_BRAND_SAME_AS?(p(),f("div",X,"品牌:"+d(e.expressionDesc.ASIN_BRAND_SAME_AS),1)):g("",!0),e.expressionDesc.ASIN_PRICE_BETWEEN?(p(),f("div",ee,"商品价格:"+d(e.expressionDesc.ASIN_PRICE_BETWEEN),1)):g("",!0),e.expressionDesc.ASIN_REVIEW_RATING_BETWEEN?(p(),f("div",te,"评分:"+d(e.expressionDesc.ASIN_REVIEW_RATING_BETWEEN),1)):g("",!0),e.expressionDesc.ASIN_SAME_AS?(p(),f("div",ae,"asin:"+d(e.expressionDesc.ASIN_SAME_AS),1)):g("",!0)]),itemName_default:_(({row:e})=>[r("div",se,[r("div",oe,[r("img",{src:e.main_image,alt:"Product Image",height:"53",width:"53"},null,8,le)]),r("div",ne,[r("div",null,[r("strong",null,d(e.itemName),1)]),r("span",null,"ASIN: "+d(e.asin),1),S(a,{icon:F(L),link:"",type:"primary",onClick:E=>G(e.productUrl)},null,8,["icon","onClick"])])])]),_:1},16)]),_:1},8,["modelValue"])}}});export{_e as _};
