<template>

  <div class="h5-container">
    <van-nav-bar title="台账详情" @click-left="onClickLeft">
    </van-nav-bar>
    <van-button v-if="nextStepFlag!==1" type="primary" @click="onDateConfirmPlanPre">上一步</van-button>
    <van-form @submit="baocun" ref="formRef">
      <van-field
        border
        v-model="form.projectName"
        label="项目名称"
        :colon="true"
        placeholder="请输入项目名称"
        required
        :rules="[{ required: true, message: '请输入项目名称' }]"
        auto-size
      />
      
      <van-field
        readonly
        v-model="form.projectLeader"
        :colon="true"
        label="项目经理"
        name="项目经理"
        placeholder="请选择项目经理"
        required
        :rules="[{ required: true, message: '请选择' }]"
        @click="handleDepartmentProjectLeaderName"
      />
      <OrganizationalWithLeafUserOne ref="projectLeaderNameRef" @receive-from-child="getDepartmentProjectLeaderName"
                                     :main-key="projectLeaderKey" />

      <van-field
        border
        v-model="form.phone"
        label="联系电话"
        :colon="true"
        placeholder="请输入联系电话"
        required
        auto-size
        :rules="[{ required: true, message: '请输入联系电话' }]"
      />
      
      <van-field
        v-model="form.dept"
        label="责任部门"
        placeholder="请选择责任部门"
        readonly
        right-icon="arrow-down"
        @click="showPickerHandle"
        required
        :rules="[{ required: true, message: '请选择' }]"
      />
      <!--        部门弹出框-->
      <van-popup v-model:show="showBottom" position="bottom">
        <OrganizationalWithLeaf @update:selected-node="handleTableDataUserDeptUpdate" />
      </van-popup>

      <van-field
        readonly
        v-model="form.projectSafePerson"
        :colon="true"
        label="项目安全员"
        name="项目安全员"
        placeholder="请选择项目安全员"
        required
        :rules="[{ required: true, message: '请选择' }]"
        @click="handleDepartmentProjectSafeName"
      />
      <OrganizationalWithLeafUserOne ref="projectSafeNameRef" @receive-from-child="getDepartmentProjectSafeName"
                                     :main-key="projectSafeKey" />

      <van-field
        readonly
        border
        v-model="form.projectPeople"
        name="项目成员"
        label="项目成员"
        :colon="true"
        placeholder="请选择项目成员"
        required
        :rules="[{ required: true, message: '请选择' }]"
        @click="handleDepartmentLeaderName2"
      />
      <OrganizationalWithLeafUserCanSelectTop ref="PopupDepartmentLeaderNameRef2" @receive-from-child="getDepartmentLeaderName2"
                                  :main-key="leaderKey2" />

      <van-field
        :colon="true"
        readonly
        label="是否使用相关方"
        label-width="200"
      ></van-field>
      <van-radio-group v-model="form.companyYon" direction="horizontal">
        <van-radio style="margin-bottom: 11px;margin-left: 20px;" name="是">是</van-radio>
        <van-radio style="margin-bottom: 11px;margin-left: 20px;" name="否">否</van-radio>
      </van-radio-group>

      <van-field v-if="form.companyYon==='是'" is-link :colon="true" readonly v-model="form.contractorName" required label="相关方单位名称"
                 placeholder="选择相关方单位名称"
                 @click="showProjectNamePicker = true" :rules="[{ required: true, message: '请选择相关方单位名称' }]" />
      <van-popup v-model:show="showProjectNamePicker" round position="bottom">
        <van-picker :columns="projectNames" @cancel="showProjectNamePicker = false" @confirm="onConfirmProjectName" />
      </van-popup>
      
      <van-field
        v-if="form.companyYon==='是'"
        readonly
        v-model="form.contractorPerson"
        :colon="true"
        label="相关方负责人"
        name="相关方负责人"
        placeholder="请选择相关方负责人"
        required
        :rules="[{ required: true, message: '请选择' }]"
        @click="handleDepartmentContractorName"
        label-width="150px"
      />
      <OrganizationalWithLeafUserOne ref="contractorNameRef" @receive-from-child="getDepartmentContractorName"
                                     :main-key="contractorKey" />
      
      <van-field
        v-if="form.companyYon==='是' && false"
        v-model="form.contractorName"
        label="相关方单位名称"
        placeholder="请选择相关方单位名称"
        readonly
        right-icon="arrow-down"
        @click="showPickerHandleContractor"
        required
        label-width="150px"
        :rules="[{ required: true, message: '请选择' }]"
      />
      <!--        部门弹出框-->
      <van-popup v-if="false" v-model:show="showBottomContractor" position="bottom">
        <OrganizationalWithLeaf @update:selected-node="handleTableDataUserDeptUpdateContractor" />
      </van-popup>

      <van-field
        v-if="form.companyYon==='是'"
        border
        v-model="form.contractorPhone"
        label="相关方联系电话"
        :colon="true"
        placeholder="请输入相关方联系电话"
        auto-size
        required
        :rules="[{ required: true, message: '请输入' }]"
        label-width="150px"
      />
      <van-field
        v-if="form.companyYon==='是'"
        border
        v-model="form.contractorSiteSupervisor"
        label="现场负责人"
        :colon="true"
        placeholder="请输入现场负责人"
        required
        :rules="[{ required: true, message: '请输入' }]"
        label-width="150px"
      />
      <van-field
        v-if="form.companyYon==='是'"
        border
        v-model="form.contractorPeople"
        label="相关方人员"
        :colon="true"
        placeholder="请输入相关方人员"
        required
        :rules="[{ required: true, message: '请输入' }]"
        label-width="150px"
      />
      <van-field
        readonly
        v-if="form.companyYon==='是'"
        border
        label="证件"
        :colon="true"
        placeholder=""
        label-width="100px"
      />
      <AttachmentS3Image v-if="form.companyYon==='是'" :f-id="form.contractorPeopleCard" />
      

      <van-field
        border
        label="甲方安全协议"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 :f-id="form.ownerAgreement" />

      <van-field
        border
        label="施工方案"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 :f-id="form.constructionPlan" />

      <van-field
        border
        label="安全教育培训记录"
        :colon="true"
        placeholder=""
        label-width="120px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 :f-id="form.studyRecord" />

      <van-field
        border
        label="安全交底"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 :f-id="form.safetyDisclose" />

      <van-field
        border
        label="人员信息"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 :f-id="form.personInformation" />

      <van-field
        v-if="form.companyYon==='是'"
        border
        label="相关方单位资质审核材料"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 v-if="form.companyYon==='是'" :f-id="form.contractor" />

      <van-field
        v-if="form.companyYon==='是'"
        border
        label="相关方安全协议"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 v-if="form.companyYon==='是'" :f-id="form.contractorAgreement" />

      <van-field
        v-if="form.companyYon==='是'"
        border
        label="人员保险"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 v-if="form.companyYon==='是'" :f-id="form.personInsurance" />

      <van-field
        v-if="form.companyYon==='是'"
        border
        label="体检报告"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 v-if="form.companyYon==='是'" :f-id="form.testReport" />

      <van-field
        border
        label="其他附件"
        :colon="true"
        placeholder=""
        label-width="100px"
        type="textarea"
        auto-size
      />
      <AttachmentS3 :f-id="form.otherFile" />
      
      <van-button block round type="primary" native-type="submit" style="margin-bottom: 5px;">
        保存
      </van-button>
      <van-button block round plain type="default" @click="qvxiao">
        取消
      </van-button>
      <div style="height: 10px;"></div>
    </van-form>
  </div>
</template>

<script setup>
import { getUUID } from '@/axios/crypto.js';
import { ref, reactive, onMounted, getCurrentInstance, nextTick, toRaw } from 'vue';
import { closeToast, Dialog, showDialog, showFailToast, showLoadingToast, showSuccessToast, showToast } from 'vant';
import AttachmentS3 from '@/components/AttachmentS3.vue';
import AttachmentS3Image from '@/components/AttachmentS3Image.vue';
import OrganizationalWithLeafUserOne from '@/components/OrganizationalWithLeafUserOne.vue';
import OrganizationalWithLeafUser from '@/components/OrganizationalWithLeafUserSpecialWork.vue';
import OrganizationalWithLeafUserCanSelectTop from '@/components/OrganizationalWithLeafUserCanSelectTop.vue'
import OrganizationalWithLeaf from '@/components/OrganizationalWithLeaf.vue';

const { proxy } = getCurrentInstance();

const onClickLeft = () => {
  history.back();
};

const deptCode = ref('');
const dangerPoints = ref([]);
const safeMeasures = ref([]);
function formatDate(date, format) {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hours = date.getHours();
  const minutes = date.getMinutes();
  const seconds = date.getSeconds();

  return format
    .replace('yyyy', year)
    .replace('MM', month.toString().padStart(2, '0'))
    .replace('dd', day.toString().padStart(2, '0'))
    .replace('HH', hours.toString().padStart(2, '0'))
    .replace('mm', minutes.toString().padStart(2, '0'))
    .replace('ss', seconds.toString().padStart(2, '0'));
}
const date = ref(null)
onMounted(async () => {
  await getProjectNames()
  deptCode.value = JSON.parse(localStorage.getItem('dept'))[0].deptCode;
  date.value = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
  console.log(date.value)
  form.value.ownerAgreement = date.value + 'jfaqxy'
  form.value.constructionPlan = date.value + 'sgfa'
  form.value.studyRecord = date.value + 'aqjypxjl'
  form.value.safetyDisclose = date.value + 'aqjd'
  form.value.personInformation = date.value + 'ryxx'
  form.value.contractor = date.value + 'xgfdwzzshcl'
  form.value.contractorAgreement = date.value + 'xgfaqxy'
  form.value.personInsurance = date.value + 'rybx'
  form.value.testReport = date.value + 'tjbg'
  form.value.otherFile = date.value + 'tjbg'
  form.value.contractorPeopleCard=getUUID()
  console.log(form.value)
});


const formRef = ref(null);
const qvxiao = () => {

  showToast({
    type: 'fail',
    message: '操作取消！'
  });
  onClickLeft();
};

//提交审批流程
import { workflowSubmit, workflowCancel } from '@/tools/workflow.js';
import HandwrittenSignature from '@/components/HandwrittenSignature.vue';
import HandwrittenSignatureLook from '@/components/HandwrittenSignatureLook.vue';

const flowId = ref('');
const jsons = ref([]);
flowId.value = 'ProjectSingnatureQun';
const baocun = () => {

  console.log('保存的参数', form.value);
  // 原有保存逻辑保持不变
  var url = 'sgsafe/Project/save';
  var param = {
    json: JSON.stringify(form.value),
    deptCode:JSON.parse(localStorage.getItem('dept'))[0].deptCode
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      onClickLeft();
      showToast({
        type: 'success',
        message: '保存成功！'
      });
    } else {
      showToast({
        type: 'fail',
        message: '操作失败！'
      });
    }
  });
};

const guid = () => {
  function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  }

  return (S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4());
};

const headers = ref({
  token: localStorage.getItem('token'),
  userId: localStorage.getItem('userId')
});

/*********项目作业管理*******************/

//项目名称选择
const templateNameAll = ref([])
const projectNames = ref([]);
const showProjectNamePicker = ref(false);
const onConfirmProjectName = ({ selectedOptions }) => {
  showProjectNamePicker.value = false;
  form.value.contractorName = selectedOptions[0].value;
  templateNameAll.value.filter(item => item.companyName === selectedOptions[0].value).forEach(e=>{
    form.value.contractorPerson = e.corporation;
    form.value.contractorPhone = e.phone;
    form.value.contractor = e.companyCertification;
    form.value.contractorAgreement = e.safeAgreement;
  })
};

const getProjectNames = () => {
  var url = '/sgsafe/ContractorName/queryAll';
  var param = {};
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code === 0) {
      let a = response.data.data;
      templateNameAll.value = response.data.data;
      a.forEach(e => {
        projectNames.value.push({
          value: e.companyName,
          text: e.companyName,
        });
      });
    } else {
      showToast({
        type: 'fail',
        message: '操作失败' + response.data.msg
      });
    }
  });
};

/**表单*/
const form = ref({
  id: '',
  projectName: '',
  projectId: '',
  projectLeader: '',
  projectLeaderCode: '',
  workName: '',
  workDesc: '',
  timeStart: '',
  planEnd: '',
  realEnd: '',
  specialPerson: '',
  specialPersonCode: '',
  specialCard: '',

  dangerPoint: '',
  safeMeasure: '',
  ownerTime: '',
  ownerSignatureStart: '',
  protectClothin: '',
  specialType: '',
  specialPhoto: '',

  startPhoto: '',
  endPhoto: '',
  otherSignatureEnd: '',
  ownerSignatureEnd: '',
  leaderSignatureEnd: '',
  otherQuestion: '',

  projectSafePerson: '',
  projectSafePersonCode: '',
  companyYon:'否',
  contractorName:'',
  contractorCode:'',
  contractorPerson:'',
  contractorPersonCode:'',

  ownerAgreement:'',
  constructionPlan:'',
  studyRecord:'',
  safetyDisclose:'',
  personInformation:'',
  personInsurance:'',
  testReport:'',
  otherFile:'',
});

//最大最小日期
const minDate = ref();
const maxDate = ref();

//开始时间
const showDatetimePickerStart = ref(false);
const currentDateStart = ref();
const currentTimeStart = ref();
const dateOrTimeStart = ref(false);
const onDateConfirmStart = () => {
  // 日期选择确认后的处理
  dateOrTimeStart.value = true;
};

const resetDatetimeStart = () => {
  dateOrTimeStart.value = false;

  // 初始化日期和时间
  if (form.value.timeStart) {
    const dt = new Date(form.value.timeStart);
    currentDateStart.value = [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()];
    currentTimeStart.value = [
      String(dt.getHours()).padStart(2, '0'),
      String(dt.getMinutes()).padStart(2, '0'),
      String(dt.getSeconds()).padStart(2, '0')
    ];
  } else {
    const now = new Date();
    currentDateStart.value = [now.getFullYear(), now.getMonth() + 1, now.getDate()];
    currentTimeStart.value = [
      String(now.getHours()).padStart(2, '0'),
      String(now.getMinutes()).padStart(2, '0'),
      String(now.getSeconds()).padStart(2, '0')
    ];
  }
};
const onConfirmDatetimeStart = () => {
  const year = currentDateStart.value[0];
  const month = currentDateStart.value[1].toString().padStart(2, '0');
  const day = currentDateStart.value[2].toString().padStart(2, '0');
  const hours = currentTimeStart.value[0].toString().padStart(2, '0');
  const minutes = currentTimeStart.value[1].toString().padStart(2, '0');
  const seconds = currentTimeStart.value[2].toString().padStart(2, '0');

  form.value.timeStart = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  showDatetimePickerStart.value = false;
  dateOrTimeStart.value = false;
};
// 日期选择器取消
const cancelDatePickerStart = () => {
  showDatetimePickerStart.value = false;
  resetDatetimeStart();
};

// 时间选择器取消
const cancelTimePickerStart = () => {
  resetDatetimeStart();
  // 重置为当前时间或从表单获取时间
  if (form.value.timeStart) {
    const dt = new Date(form.value.timeStart);
    currentTimeStart.value = [
      String(dt.getHours()).padStart(2, '0'),
      String(dt.getMinutes()).padStart(2, '0'),
      String(dt.getSeconds()).padStart(2, '0')
    ];
  } else {
    const now = new Date();
    currentTimeStart.value = [
      String(now.getHours()).padStart(2, '0'),
      String(now.getMinutes()).padStart(2, '0'),
      String(now.getSeconds()).padStart(2, '0')
    ];
  }
};

//计划结束时间
const showDatetimePickerPlan = ref(false);
const currentDatePlan = ref();
const currentTimePlan = ref();
const dateOrTimePlan = ref(false);
const onDateConfirmPlan = () => {
  // 日期选择确认后的处理
  dateOrTimePlan.value = true;
};

const resetDatetimePlan = () => {
  dateOrTimePlan.value = false;

  // 初始化日期和时间
  if (form.value.planEnd) {
    const dt = new Date(form.value.planEnd);
    currentDatePlan.value = [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()];
    currentTimePlan.value = [
      String(dt.getHours()).padStart(2, '0'),
      String(dt.getMinutes()).padStart(2, '0'),
      String(dt.getSeconds()).padStart(2, '0')
    ];
  } else {
    const now = new Date();
    currentDatePlan.value = [now.getFullYear(), now.getMonth() + 1, now.getDate()];
    currentTimePlan.value = [
      String(now.getHours()).padStart(2, '0'),
      String(now.getMinutes()).padStart(2, '0'),
      String(now.getSeconds()).padStart(2, '0')
    ];
  }
};
const onConfirmDatetimePlan = () => {
  const year = currentDatePlan.value[0];
  const month = currentDatePlan.value[1].toString().padStart(2, '0');
  const day = currentDatePlan.value[2].toString().padStart(2, '0');
  const hours = currentTimePlan.value[0].toString().padStart(2, '0');
  const minutes = currentTimePlan.value[1].toString().padStart(2, '0');
  const seconds = currentTimePlan.value[2].toString().padStart(2, '0');

  form.value.planEnd = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  showDatetimePickerPlan.value = false;
  dateOrTimePlan.value = false;
};
// 日期选择器取消
const cancelDatePickerPlan = () => {
  showDatetimePickerPlan.value = false;
  resetDatetimePlan();
};

// 时间选择器取消
const cancelTimePickerPlan = () => {
  resetDatetimePlan();
  // 重置为当前时间或从表单获取时间
  if (form.value.planEnd) {
    const dt = new Date(form.value.planEnd);
    currentTimePlan.value = [
      String(dt.getHours()).padStart(2, '0'),
      String(dt.getMinutes()).padStart(2, '0'),
      String(dt.getSeconds()).padStart(2, '0')
    ];
  } else {
    const now = new Date();
    currentTimePlan.value = [
      String(now.getHours()).padStart(2, '0'),
      String(now.getMinutes()).padStart(2, '0'),
      String(now.getSeconds()).padStart(2, '0')
    ];
  }
};

//特种工作人员
const specialPersonKey = guid();
const PopupDepartmentSpecialPerson = ref();
const handleDepartmentSpecialPerson = () => {
  PopupDepartmentSpecialPerson.value.open();
};

const codeAndDescSpecialPerson = ref([]);
const getDepartmentSpecialPerson = (items) => {
  console.log('人员数据', items);
  let codeList = [];
  let descList = [];
  for (let item of items) {
    codeAndDescSpecialPerson.value.push(item.userCode + '-' + item.userDesc);
    codeList.push(item.userCode);
    descList.push(item.userDesc);
  }
  form.value.specialPersonCode = codeList.join(',');
  var url = '/sgsafe/Project/querySpecialCardFileByUserCode';
  var param = {
    userCode:form.value.specialPersonCode
  };
  proxy.$axios.get(url,param).then(response => {
    if (response.data.code===0){
      form.value.specialCard = response.data.data.cardFile
    }else{
      showToast({
        message: '操作失败！'+response.data.message,
      })
    }

  })
  form.value.specialPerson = descList.join(',');
};

//复选
const checkboxDangerPoint = ref([]);
const checkboxSafeMeasure = ref([]);

//控制是否需要管理单位签字
const ownerSignFlag = ref('false');

//管理单位许可作业时间
const showDatetimePickerOwner = ref(false);
const currentDateOwner = ref();
const currentTimeOwner = ref();
const dateOrTimeOwner = ref(false);
const onDateConfirmOwner = () => {
  // 日期选择确认后的处理
  dateOrTimeOwner.value = true;
};

const resetDatetimeOwner = () => {
  dateOrTimeOwner.value = false;

  // 初始化日期和时间
  if (form.value.ownerTime) {
    const dt = new Date(form.value.ownerTime);
    currentDateOwner.value = [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()];
    currentTimeOwner.value = [
      String(dt.getHours()).padStart(2, '0'),
      String(dt.getMinutes()).padStart(2, '0'),
      String(dt.getSeconds()).padStart(2, '0')
    ];
  } else {
    const now = new Date();
    currentDateOwner.value = [now.getFullYear(), now.getMonth() + 1, now.getDate()];
    currentTimeOwner.value = [
      String(now.getHours()).padStart(2, '0'),
      String(now.getMinutes()).padStart(2, '0'),
      String(now.getSeconds()).padStart(2, '0')
    ];
  }
};
const onConfirmDatetimeOwner = () => {
  const year = currentDateOwner.value[0];
  const month = currentDateOwner.value[1].toString().padStart(2, '0');
  const day = currentDateOwner.value[2].toString().padStart(2, '0');
  const hours = currentTimeOwner.value[0].toString().padStart(2, '0');
  const minutes = currentTimeOwner.value[1].toString().padStart(2, '0');
  const seconds = currentTimeOwner.value[2].toString().padStart(2, '0');

  form.value.ownerTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  showDatetimePickerOwner.value = false;
  dateOrTimeOwner.value = false;
};
// 日期选择器取消
const cancelDatePickerOwner = () => {
  showDatetimePickerOwner.value = false;
  resetDatetimeOwner();
};

// 时间选择器取消
const cancelTimePickerOwner = () => {
  resetDatetimeOwner();
  // 重置为当前时间或从表单获取时间
  if (form.value.ownerTime) {
    const dt = new Date(form.value.ownerTime);
    currentTimeOwner.value = [
      String(dt.getHours()).padStart(2, '0'),
      String(dt.getMinutes()).padStart(2, '0'),
      String(dt.getSeconds()).padStart(2, '0')
    ];
  } else {
    const now = new Date();
    currentTimeOwner.value = [
      String(now.getHours()).padStart(2, '0'),
      String(now.getMinutes()).padStart(2, '0'),
      String(now.getSeconds()).padStart(2, '0')
    ];
  }
};

//控制是否需要携带特种防护器具
const specialToolFlag = ref('false');

//特种防护器具类型
const specialTypes = ref([
  { value: '头部护具类', text: '头部护具类' },
  { value: '呼吸护具类', text: '呼吸护具类' },
  { value: '眼（面）护具类', text: '眼（面）护具类' },
  { value: '防护服类', text: '防护服类' },
  { value: '防护鞋类', text: '防护鞋类' },
  { value: '防坠落护具类', text: '防坠落护具类' }
]);
const showSpecialTypePicker = ref(false);
const onConfirmSpecialType = ({ selectedOptions }) => {
  showSpecialTypePicker.value = false;
  console.log('选择内容', selectedOptions);
  form.value.specialType = selectedOptions[0].text;
  console.log('选择的内容', form.value);
};

//用来控制下一步显示
const nextStepFlag = ref(1);

//发送消息
const sendMessageSignature = () => {
  var url = '/sgsafe/ProjectWork/sendMessageSignature';
  var param = {
    params: form.value.id
  };
  if (form.value) {
    proxy.$axios.post(url, param).then(response => {
      if (response.data.code === 0) {
        showToast({
          type: 'success',
          message: '成功抄送'
        });
      } else {
        showToast({
          type: 'fail',
          message: '操作失败' + response.data.msg
        });
      }
    });
  }
};

/**其他**/
const safeMeasure = ref(null);
const dangerPoint = ref(null);
const iconsSafeMeasure = () => {
  if (safeMeasure.value) {
    checkboxSafeMeasure.value.push(safeMeasure.value);

  }
};

const iconsDangerPoint = () => {
  if (dangerPoint.value) {
    checkboxDangerPoint.value.push(dangerPoint.value);
  }
};

//上一步
const onDateConfirmPlanPre = () =>{
  nextStepFlag.value --
}

//项目经理
const projectLeaderKey = guid();
const projectLeaderNameRef = ref();
const handleDepartmentProjectLeaderName = () => {
  projectLeaderNameRef.value.open();
};

const getDepartmentProjectLeaderName = (item) => {
  form.value.projectLeaderCode = item.user.userCode;
  form.value.projectLeader = item.user.userDesc;
  // form.value.discovererDeptCode = item.dept.deptCode;
  // form.value.discovererDept = item.dept.deptName;
};

//项目安全员
const projectSafeKey = guid();
const projectSafeNameRef = ref();
const handleDepartmentProjectSafeName = () => {
  projectSafeNameRef.value.open();
};

const getDepartmentProjectSafeName = (item) => {
  form.value.projectSafePersonCode = item.user.userCode;
  form.value.projectSafePerson = item.user.userDesc;
  // form.value.discovererDeptCode = item.dept.deptCode;
  // form.value.discovererDept = item.dept.deptName;
};

/* 组织树选择责任部门 */
const showBottom = ref(false);
const handleTableDataUserDeptUpdate = async (nodeData) => {
  form.value.dept = nodeData.split("-")[1];
  form.value.deptCode = nodeData.split("-")[0];
  // form.value.repairDept = nodeData.deptCode + '-' + nodeData.deptName
  showBottom.value = false;
};
const showPickerHandle = () => {
  showBottom.value = true;
};

/* 组织树选择相关方单位 */
const showBottomContractor = ref(false);
const handleTableDataUserDeptUpdateContractor = async (nodeData) => {
  form.value.contractorName = nodeData.split("-")[1];
  form.value.contractorCode = nodeData.split("-")[0];
  // form.value.repairDept = nodeData.deptCode + '-' + nodeData.deptName
  showBottomContractor.value = false;
};
const showPickerHandleContractor = () => {
  showBottomContractor.value = true;
};

//相关方负责人
const contractorKey = guid();
const contractorNameRef = ref();
const handleDepartmentContractorName = () => {
  contractorNameRef.value.open();
};

const getDepartmentContractorName = (item) => {
  form.value.contractorPersonCode = item.user.userCode;
  form.value.contractorPerson = item.user.userDesc;
  // form.value.discovererDeptCode = item.dept.deptCode;
  // form.value.discovererDept = item.dept.deptName;
};

/**项目成员**/
const leaderKey2 = guid();
const PopupDepartmentLeaderNameRef2 = ref();
const handleDepartmentLeaderName2 = () => {
  PopupDepartmentLeaderNameRef2.value.open();
};

const codeAndDesc2 = ref([]);
const getDepartmentLeaderName2 = (items) => {
  console.log('人员数据', items);
  let codeList = [];
  let descList = [];
  for (let item of items) {
    codeAndDesc2.value.push(item.userCode + '-' + item.userDesc);
    codeList.push(item.userCode);
    descList.push(item.userDesc);
  }
  form.value.projectPeopleCode = codeList.join(',');
  form.value.projectPeople = descList.join(',');
};

</script>

<style scoped>
.h5-container {
  width: 100%;
  box-sizing: border-box;
  height: 100vh;
  background-color: white;
  padding: 10px;
  padding-bottom: 20px;
}

.radio-group {
  display: flex;
  background-color: white;
  padding: 10px;
  border-radius: 5px;
  margin: 10px 0;
  gap: 10px;
}

.radio-item {
  padding: 8px 12px;
  border: 1px solid #222;
  border-radius: 4px;
  background-color: white;
  cursor: pointer;
  transition: background-color 0.3s ease;
  /* 添加过渡效果 */
}

.radio-item.active {
  background-color: #4285f4;
  /* 选中时的蓝色 */
  color: white;
  border-color: #4285f4;
}
</style>
