import{a as l}from"./index-CWCutGkV.js";import{g as e,a,b as u}from"./index-nsQnTcne.js";import{az as n,d as i,c as t}from"./vue-vendor-DZekML78.js";import{h as r}from"./element-plus-DSMJnpwa.js";import"./index-mv7arXuk.js";function o(l,e,a="value"){const u=[];return function l(n){for(const i of n){if(u.push(i[a]),"houseId"===i.type&&i.value===e)return!0;if(i.children&&i.children.length>0&&l(i.children))return!0;u.pop()}return!1}(l),u}function s(l,e=","){return l.split(e).map(l=>({name:l.split("/").pop(),url:l})).filter(l=>l.name&&l.url)}function d(l){if(!(l&&l instanceof FormData))return!1;for(const e of l.entries())return!0;return!1}function v(l,e){const a=parseFloat(l),u=parseFloat(e);return isNaN(a)||isNaN(u)?l.localeCompare(e,"zh-CN",{numeric:!0}):a-u}const c=n("house",()=>{const n=i(),o=i(0),s=i([]),d=i([]),c=i([]),f=i({id:null,villageId:null,villageName:"",buildingName:"",buildingUse:null,buildToward:"",buildTall:"",buildStructure:"",unitCount:null,floorCount:null,remark:""}),g=i(null),h=t(()=>[...p.value].sort(v)),p=i(new Set),m=async l=>{c.value=[];const u=await e(n.value.villageId,l);if(c.value=u.data,f.value&&null===f.value.id||o.value!==l?f.value=u.data[0]:o.value===l&&(f.value=u.data.find(l=>l.id===f.value.id)),f.value&&f.value.id){const e=await a(f.value.id);g.value=e.data,p.value=new Set,g.value.units.forEach(l=>{l.floors.forEach(l=>{p.value.add(l.floorNo)})}),o.value!==l&&(o.value=l)}},b=i([]),N=l=>{l&&(f.value={id:null,villageId:null,villageName:"",buildingName:"",buildingUse:null,buildToward:"",buildTall:"",buildStructure:"",unitCount:null,floorCount:null,remark:""},g.value=null,a(l).then(e=>{g.value=e.data,f.value=c.value.find(e=>e.id===l),p.value.clear(),g.value.units.forEach(l=>{l.floors.forEach(l=>{p.value.add(l.floorNo)})})}))};return{currentVilageInfo:n,currentBuildingInfoList:c,currentBuildingInfo:f,currentHouseInfoList:g,currentFloorInfoList:h,checkoutHouses:b,buildingtype:o,buildingtypelist:s,treedata:d,updateVilageinfo:l=>{n.value=l},updateCureentBuilding:async()=>{g.value=null;const l=await a(f.value.id);g.value=l.data,p.value=new Set,g.value.units.forEach(l=>{l.floors.forEach(l=>{p.value.add(l.floorNo)})})},getviliageinfo:async e=>{const a=await l(e);return n.value=a.data,a.data},checkoutHousesFun:l=>{b.value=l},initHouse:m,switchHouseType:async l=>{c.value=[];const a=await e(n.value.villageId,l);c.value=a.data,(f.value&&null===f.value.id||o.value!==l)&&(a.data.length>0?f.value=a.data[0]:f.value={id:null,villageId:null,villageName:"",buildingName:"",buildingUse:null,buildToward:"",buildTall:"",buildStructure:"",unitCount:null,floorCount:null,remark:""}),null!==f.value.id?N(f.value.id):p.value=new Set,o.value=l,r.success("切换成功")},switchBuilding:N,updateHouse:()=>{m(o.value)},deleteBuildingFun:l=>{c.value=c.value.filter(e=>e.id!==l),f.value.id===l&&c.value[0]&&(f.value=c.value[0],N(f.value.id))},getCurrentVilageTreeHouse:async()=>{try{d.value=[];const e=await u(n.value.villageId);return d.value=(l=e.data.buildings||[])&&Array.isArray(l)?l.map(l=>{const e={label:l.buildingName||"未知楼栋",type:"buildingId",value:l.buildingId,children:[]},a=(l.units||[]).map(l=>{const e={label:`${l.unitNo} 单元`,value:l.unitNo,type:"unitNo",children:[]},a=[];return(l.floors||[]).forEach(l=>{const e=l.houses||[];a.push(...e)}),e.children=a.map(l=>({label:l.houseNo||"未知房屋",value:l.houseId,type:"houseId"})),e});return e.children=a,e}):[],d.value}catch(e){return d.value=[],d.value}var l}}},{persist:{storage:sessionStorage}});export{o as g,d as h,s,c as u};
