import{d as U,k as g,l as Y,m as N,r as L,o as V,c as z,a as u,z as p,b as d,t as A,u as m,M as B,X as F,a0 as G,y as H,j as W,A as K,G as X,H as Q}from"./vue.1703796278973.js";import{M as E,aJ as Z,l as ee,av as te,aw as se,ax as oe,W as ae}from"./index.17037962789732.js";import"./index.170379627897337.js";import"./index.170379627897315.js";import"./index.1703796278973300.js";import"./index.170379627897317.js";import"./index.1703796278973301.js";import"./index.1703796278973302.js";import"./index.170379627897332.js";import"./index.1703796278973303.js";import"./index.170379627897339.js";import"./index.170379627897316.js";import"./index.170379627897314.js";import"./index.1703796278973304.js";import"./index.1703796278973305.js";import"./index.1703796278973306.js";import{_ as ne}from"./index.vue_vue_type_script_setup_true_lang.17037962789733.js";import{_ as ie}from"./index.170379627897313.js";import"./index.170379627897319.js";import"./index.170379627897327.js";import"./index.1703796278973312.js";import{a as re}from"./comm.1703796278973.js";import{a as le,b as ce,c as de,d as pe}from"./department.1703796278973.js";import{u as ue}from"./department.17037962789732.js";import{a as me}from"./dayjs.min.1703796278973.js";import{_ as _e}from"./_plugin-vue_export-helper.1703796278973.js";import"./index.17037962789733.js";import"./isArray.1703796278973.js";import"./editor.api.1703796278973.js";import"./preload-helper.1703796278973.js";import"./monaco.contribution.1703796278973.js";import"./index.170379627897333.js";import"./index.170379627897335.js";import"./system.1703796278973.js";import"./index.170379627897334.js";import"./default.1703796278973.js";import"./permission.1703796278973.js";import"./consts.1703796278973.js";import"./404.1703796278973.js";const q=y=>(X("data-v-6930449b"),y=y(),Q(),y),ve={class:"row"},fe={class:"row"},ge=q(()=>p("span",{style:{"margin-right":"8px"}},"批量配置",-1)),ye=["src"],he={class:"card-item-content-title",style:{"margin-bottom":"18px"}},we=q(()=>p("div",{class:"card-item-content-text"},"ID",-1)),be={style:{cursor:"pointer"},class:"card-item-content-value"},xe=q(()=>p("div",{class:"card-item-content-text"}," 资产权限 ",-1)),Ie=U({__name:"AddDeviceOrProductDialog",props:{visible:{type:Boolean},queryColumns:null,parentId:null,allPermission:null,assetType:null},emits:["confirm","update:visible"],setup(y,{emit:C}){const i=y,b=ue(),T=g(!1),P=g(0),O=()=>{if(o.selectedRows.length<1)return E.warning("请先勾选数据");console.log("table.selectedRows: ",o.selectedRows);const s=o.selectedRows.map(e=>({targetType:"org",targetId:i.parentId,assetType:i.assetType,assetIdList:[e.id],permission:e.selectPermissions.filter(r=>e.permissionList.map(a=>a.value).includes(r))}));b.setProductId(s[0].assetIdList[0]),T.value=!0,pe(i.assetType,s).then(()=>{E.success("操作成功"),C("confirm"),C("update:visible",!1)}).finally(()=>{T.value=!1})},v=g(!0),x=g(["read"]),M=Y(()=>i.allPermission.map(s=>({label:s.name,value:s.id,disabled:s.id==="read"}))),$=i.queryColumns.filter(s=>s.dataIndex!=="action"),j=g({}),o={_selectedRowKeys:g([]),backRowKeys:[],selectedRows:[],tableData:[],init:()=>{N([v,x,()=>o._selectedRowKeys],s=>{const e=s[2].value,r=o.backRowKeys;o.selectedRows.forEach(a=>{v.value?(a.selectPermissions=s[1],a.permissionList.forEach(l=>{l.disabled=!0})):a.permissionList.forEach(l=>{l.disabled=l.value==="read"})}),e&&e.length!e.includes(l)).forEach(l=>{const f=o.tableData.find(_=>_.id===l);f.permissionList.forEach(_=>_.disabled=!0),f.selectPermissions=["read"]}),e.length||o.tableData.forEach(a=>{a.selectPermissions=["read"]})},{deep:!0})},onSelectChange:s=>{if(!s.permissionList.find(a=>a.value==="share")){E.warning("该资产不支持共享");return}const e=o._selectedRowKeys.value,r=e.indexOf(s.id);o.backRowKeys=[...e],r===-1?(e.push(s.id),o.selectedRows.push(s)):(e.splice(r,1),o.selectedRows.splice(r,1))},cancelSelect:()=>{o.backRowKeys=[...o._selectedRowKeys.value],o._selectedRowKeys.value=[],o.selectedRows=[]},getData:(s,e)=>new Promise(r=>{(i.assetType==="product"?le:ce)(s).then(l=>{const{pageIndex:f,pageSize:_,total:I,data:h}=l.result,k=h.map(w=>w.id),D={read:0,save:1,delete:2,share:3};de(i.assetType,k).then(w=>{h.forEach(c=>{var t;c.permissionList=(t=w.result.find(n=>n.assetId===c.id).permissionInfoList)==null?void 0:t.map(n=>({label:n.name,value:n.id,disabled:!0})),c.selectPermissions=["read"],c.permissionList=c.permissionList.map(n=>({...n,idx:D[n.value]})).sort((n,R)=>n.idx-R.idx),i.assetType==="product"&&(c.state={value:c.state===1?"online":c.state===0?"offline":"",text:c.state===1?"正常":c.state===0?"禁用":""})}),r({code:200,result:{data:h.sort((c,t)=>c.createTime-t.createTime),pageIndex:f,pageSize:_,total:I},status:200})})})}),requestFun:async s=>{if(P.value+=1,i.parentId){const e=[{terms:[{column:"id",termType:"dim-assets$not",value:{assetType:i.assetType,targets:[{type:"org",id:i.parentId}]}},{column:"productId$product-info",type:"and",value:`id is ${b.productId}`}]}];(i.assetType!=="device"||!b.productId||P.value>1||b.optType==="handle")&&e[0].terms.pop(),s.terms&&s.terms.length>0&&e.unshift({terms:s.terms});const r={...s,sorts:[{name:"createTime",order:"desc"}],terms:e},a=await o.getData(r,i.parentId);return o.tableData=a.result.data,{code:a.status,result:a.result,status:a.status}}else return{code:200,result:{data:[],pageIndex:0,pageSize:0,total:0},status:200}}};o.init();const J=(s,e)=>{o.selectedRows=e,o._selectedRowKeys.value=s};return(s,e)=>{const r=L("AIcon"),a=Z,l=ee,f=L("pro-search"),_=L("Ellipsis"),I=te,h=se,k=ie,D=ne,w=oe,c=ae;return V(),z(c,{class:"add-device-or-product-dialog-container",title:"绑定",width:"1440px",onOk:O,confirmLoading:m(T),onCancel:e[5]||(e[5]=t=>C("update:visible",!1)),visible:""},{default:u(()=>[p("h5",ve,[d(r,{type:"ExclamationCircleOutlined",style:{"margin-right":"6px"}}),A(" 只能分配有“共享”权限的资产数据 ")]),p("div",fe,[ge,d(a,{checked:m(v),"onUpdate:checked":e[0]||(e[0]=t=>B(v)?v.value=t:null),"checked-children":"开","un-checked-children":"关",style:{width:"56px"}},null,8,["checked"])]),F(p("div",null,[d(l,{value:m(x),"onUpdate:value":e[1]||(e[1]=t=>B(x)?x.value=t:null),options:m(M)},null,8,["value","options"])],512),[[G,m(v)]]),d(f,{type:"simple",columns:i.queryColumns,target:"category",onSearch:e[2]||(e[2]=t=>j.value={...t})},null,8,["columns"]),d(w,{ref:"tableRef",request:o.requestFun,gridColumn:2,params:m(j),rowSelection:{selectedRowKeys:o._selectedRowKeys.value,onChange:J},onCancelSelect:o.cancelSelect,columns:m($)},{card:u(t=>{var n,R;return[d(k,H({value:t,actions:[{key:1}]},t,{active:o._selectedRowKeys.value.includes(t.id),onClick:o.onSelectChange,status:(n=t.state)==null?void 0:n.value,statusText:(R=t.state)==null?void 0:R.text,statusNames:{online:"processing",offline:"error",notActive:"warning"}}),{img:u(()=>[W(s.$slots,"img",{},()=>[p("img",{src:m(re)("/device-product.png"),style:{cursor:"pointer"}},null,8,ye)],!0)]),content:u(()=>[p("h3",he,[d(_,{style:{width:"calc(100% - 100px)"}},{default:u(()=>[A(K(t.name),1)]),_:2},1024)]),d(h,null,{default:u(()=>[d(I,{span:12},{default:u(()=>[we,p("div",be,K(t.id),1)]),_:2},1024),d(I,{span:12},{default:u(()=>[xe,p("div",{style:{cursor:"pointer"},class:"card-item-content-value",onClick:e[3]||(e[3]=S=>S.stopPropagation())},[d(l,{value:t.selectPermissions,"onUpdate:value":S=>t.selectPermissions=S,options:t.permissionList},null,8,["value","onUpdate:value","options"])])]),_:2},1024)]),_:2},1024)]),_:2},1040,["value","active","onClick","status","statusText"])]}),permission:u(t=>[p("div",{style:{cursor:"pointer"},class:"card-item-content-value",onClick:e[4]||(e[4]=n=>n.stopPropagation())},[d(l,{value:t.selectPermissions,"onUpdate:value":n=>t.selectPermissions=n,options:t.permissionList},null,8,["value","onUpdate:value","options"])])]),state:u(t=>[d(D,{status:t.state.value,text:t.state.text,statusNames:{online:"processing",offline:"error",notActive:"warning"}},null,8,["status","text"])]),registryTime:u(t=>[p("span",null,K(m(me)(t.registryTime).format("YYYY-MM-DD YY:mm:ss")),1)]),_:3},8,["request","params","rowSelection","onCancelSelect","columns"])]),_:3},8,["confirmLoading"])}}});const ct=_e(Ie,[["__scopeId","data-v-6930449b"]]);export{ct as default};