"use strict";const e=require("../../common/vendor.js"),t=require("../../request/api.js"),a=require("../../request/request.js");if(!Array){(e.resolveComponent("up-textarea")+e.resolveComponent("up-input")+e.resolveComponent("up-datetime-picker")+e.resolveComponent("up-checkbox")+e.resolveComponent("up-checkbox-group")+e.resolveComponent("u-popup")+e.resolveComponent("up-upload"))()}Math||((()=>"../../uni_modules/uview-plus/components/u-textarea/u-textarea.js")+(()=>"../../uni_modules/uview-plus/components/u-input/u-input.js")+(()=>"../../uni_modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js")+(()=>"../../uni_modules/uview-plus/components/u-checkbox/u-checkbox.js")+(()=>"../../uni_modules/uview-plus/components/u-checkbox-group/u-checkbox-group.js")+(()=>"../../uni_modules/uview-plus/components/u-popup/u-popup.js")+(()=>"../../uni_modules/uview-plus/components/u-upload/u-upload.js"))();const o={__name:"rectification",setup(o){const l=e.ref(""),n=e.ref(""),i=e.ref(""),s=e.ref(!1),u=e.reactive({rectifyPlan:"",rectifyResult:"",planCost:"",actualCost:""}),r=e.ref(!1),c=e.ref(Date.now());e.ref("");const d=e.ref([]),p=e.ref(!1),v=e.ref([]),m=e.ref([]),f=e.computed((()=>0===m.value.length?"":m.value.length<=2?m.value.map((e=>e.name)).join("、"):`${m.value[0].name}等${m.value.length}人`)),h=e=>{console.log("选中的ID:",e)},g=()=>{m.value=d.value.filter((e=>v.value.includes(e.id))),p.value=!1,console.log("选中的整改人员:",m.value)},y=e.ref([]),w=e=>{y.value.splice(e.index,1)},x=async e=>{let t=[].concat(e.file),a=y.value.length;t.map((e=>{y.value.push({...e,status:"uploading",message:"上传中"})}));for(let o=0;onew Promise(((o,l)=>{e.index.uploadFile({url:a.baseUrl+"/frontend/attachment/upload",filePath:t,name:"file",header:{Authorization:a.getToken()},success:e=>{const t=JSON.parse(e.data);0===t.code?o(t.data):l(t.msg||"上传失败")},fail:e=>{console.error("上传失败:",e),l(e)}})})),C=async()=>{if(!u.rectifyPlan)return void e.index.showToast({title:"请输入整改方案",icon:"none"});if(!u.rectifyResult)return void e.index.showToast({title:"请输入整改完成情况",icon:"none"});if(0===m.value.length)return void e.index.showToast({title:"请选择整改人员",icon:"none"});const a=y.value.map((e=>{let t="";"string"==typeof e.url?t=e.url:e.url&&"object"==typeof e.url&&(t=e.url.url||e.url.path||"");return{fileName:("string"==typeof t&&t?t.split("/").pop():e.name||"")||"",filePath:t||"",fileType:e.type||"image/png",fileSize:e.size||0}})),o={hazardId:l.value,assignId:n.value,rectifyPlan:u.rectifyPlan,rectifyResult:u.rectifyResult,planCost:Number(u.planCost)||0,actualCost:Number(u.actualCost)||0,attachments:a,rectifyUserIds:v.value.map((e=>Number(e)))};i.value&&(o.rectifyId=i.value);try{const a=await t.submitRectification(o);0===a.code?(e.index.showToast({title:s.value?"保存成功":"提交成功",icon:"success"}),setTimeout((()=>{e.index.navigateBack()}),1500)):e.index.showToast({title:a.msg||(s.value?"保存失败":"提交失败"),icon:"none"})}catch(r){console.error("提交整改失败:",r),e.index.showToast({title:"操作失败",icon:"none"})}},b=e.ref(!1),P=async()=>{if(l.value){b.value=!0;try{const a=await t.getHiddenDangerDetail({hazardId:l.value,assignId:n.value});if(0!==a.code||!a.data)return void e.index.showToast({title:"获取隐患详情失败",icon:"none"});const{title:o,description:i}=a.data,s=await t.generateRectifyPlan({title:o,description:i});0===s.code&&s.data?(s.data.rawResponse&&(u.rectifyPlan=s.data.rawResponse),e.index.showToast({title:"AI生成完成",icon:"success",duration:2e3})):e.index.showToast({title:s.msg||"AI生成失败",icon:"none"})}catch(a){console.error("AI生成整改方案失败:",a),e.index.showToast({title:"AI生成失败,请重试",icon:"none"})}finally{b.value=!1}}else e.index.showToast({title:"缺少隐患信息",icon:"none"})};return e.onLoad((o=>{o.hazardId&&(l.value=o.hazardId),o.assignId&&(n.value=o.assignId),(async()=>{console.log("当前hazardId:",l.value);try{const e=await t.getDeptUsersWithSubordinates({hazardId:l.value});if(0===e.code&&e.data){const t=[];e.data.forEach((e=>{e.users&&e.users.length>0&&e.users.forEach((a=>{t.push({id:String(a.userId),name:`${a.nickName}(${e.deptName})`})}))})),d.value=t,console.log("整改人员列表:",d.value)}}catch(e){console.error("获取部门人员失败:",e)}})(),o.rectifyId&&(i.value=o.rectifyId,s.value="1"===o.isEdit,(async()=>{try{e.index.showLoading({title:"加载中..."});const o=await t.getRectifyDetail({rectifyId:i.value});if(e.index.hideLoading(),0===o.code&&o.data){const t=o.data;if(u.rectifyPlan=t.rectifyPlan||"",u.rectifyResult=t.rectifyResult||"",u.planCost=t.planCost?String(t.planCost):"",u.actualCost=t.actualCost?String(t.actualCost):"",l.value=t.hazardId||"",n.value=t.assignId||"",t.attachments&&t.attachments.length>0&&(y.value=t.attachments.map((e=>({url:e.filePath.startsWith("http")?e.filePath:a.baseUrl.replace("/api","")+e.filePath,status:"success",message:"",name:e.fileName,type:e.fileType,filePath:e.filePath})))),t.memberIds){const e=t.memberIds.split(",").map((e=>String(e.trim())));v.value=e,setTimeout((()=>{m.value=d.value.filter((t=>e.includes(t.id)))}),500)}else t.rectifierId&&(v.value=[String(t.rectifierId)],setTimeout((()=>{m.value=d.value.filter((e=>e.id===String(t.rectifierId)))}),500));e.index.setNavigationBarTitle({title:"编辑整改信息"})}}catch(o){e.index.hideLoading(),console.error("获取整改详情失败:",o),e.index.showToast({title:"获取详情失败",icon:"none"})}})())})),(t,a)=>e.e({a:!b.value},(b.value,{}),{b:e.t(b.value?"AI生成中...":"AI生成整改方案"),c:b.value,d:b.value,e:e.o(P),f:e.o((e=>u.rectifyPlan=e)),g:e.p({placeholder:"请输入内容",maxlength:-1,autoHeight:!0,modelValue:u.rectifyPlan}),h:e.o((e=>u.rectifyResult=e)),i:e.p({placeholder:"请输入内容",modelValue:u.rectifyResult}),j:e.o((e=>u.planCost=e)),k:e.p({placeholder:"请输入内容",type:"number",modelValue:u.planCost}),l:e.o((e=>u.actualCost=e)),m:e.p({placeholder:"请输入内容",type:"number",modelValue:u.actualCost}),n:e.o((e=>c.value=e)),o:e.p({hasInput:!0,show:r.value,mode:"date",modelValue:c.value}),p:e.t(m.value.length>0?f.value:"请选择整改人员(可多选)"),q:0===m.value.length?1:"",r:e.o((e=>p.value=!0)),s:e.o((e=>p.value=!1)),t:e.f(d.value,((t,a,o)=>({a:"641bd0a1-7-"+o+",641bd0a1-6",b:e.p({label:t.name,name:t.id,activeColor:"#2667E9",shape:"square"}),c:t.id}))),v:e.o(h),w:e.o((e=>v.value=e)),x:e.p({placement:"column",modelValue:v.value}),y:e.o((e=>p.value=!1)),z:e.o(g),A:e.o((e=>p.value=!1)),B:e.p({show:p.value,mode:"bottom",round:"20"}),C:e.o(x),D:e.o(w),E:e.p({fileList:y.value,name:"1",multiple:!0,maxCount:10}),F:e.t(s.value?"保存修改":"提交整改"),G:e.o(C),H:e.gei(t,"")})}},l=e._export_sfc(o,[["__scopeId","data-v-641bd0a1"]]);wx.createPage(l);