<template>
  <div class="h5-container">
    <van-nav-bar title="台账详情" @click-left="onClickLeft">
      <!--      <template #left>-->
      <!--        <svg t="1749540528155" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"-->
      <!--             p-id="4132" width="6vw" height="6vh">-->
      <!--          <path-->
      <!--            d="M801.630938 934.023203m-36.203868 36.203867l0 0q-36.203867 36.203867-72.407734 0l-434.446406-434.446406q-36.203867-36.203867 0-72.407734l0 0q36.203867-36.203867 72.407734 0l434.446406 434.446406q36.203867 36.203867 0 72.407734Z"-->
      <!--            fill="#000000" p-id="4133"></path>-->
      <!--          <path-->
      <!--            d="M729.223203-8.030938m36.203867 36.203868l0 0q36.203867 36.203867 0 72.407734l-434.446406 434.446406q-36.203867 36.203867-72.407734 0l0 0q-36.203867-36.203867 0-72.407734l434.446406-434.446406q36.203867-36.203867 72.407734 0Z"-->
      <!--            fill="#000000" p-id="4134"></path>-->
      <!--        </svg>-->
      <!--      </template>-->
    </van-nav-bar>
    <!-- <van-nav-bar title="请假申请审批" left-arrow @click-left="onClickLeft" /> -->

    <van-tabs v-model:active="activeTab" @change="handleTabsClick" sticky>
      <van-tab title="业务详情">
        <van-form @submit="baocun" ref="formRef">
          <div style="color: #4C93E6;font-size: 14px;margin-left: 0px;background-color: #f5f5f5;padding: 8px 12px;
          margin: 0 -10px 10px -10px;">隐患信息</div>
          <div class="radio-group">
            <div class="radio-item" :class="{ 'active': form.hdSelect === '正常登记' }" @click="selectOption('正常登记')">
              标准流程
            </div>
            <div class="radio-item" :class="{ 'active': form.hdSelect === '即查即改' }" @click="selectOption('即查即改')">
              即查即改
            </div>
          </div>
          <van-field border v-model="form.hdId" name="隐患编号" label="隐患编号" :colon="true" placeholder=""
            :readonly="form.status > 0" />
          <van-field is-link :colon="true" readonly v-model="form.hdType" required label="隐患类型" placeholder="选择隐患类型"
            @click="showPicker = true" :rules="[{ required: true, message: '请选择内容' }]" />
          <van-popup v-model:show="showPicker" round position="bottom">
            <van-picker :columns="yhlxs" @cancel="showPicker = false" @confirm="onConfirmYhlx" />
          </van-popup>

          <van-field readonly v-model="form.discoveryTime" is-link name="datetime" label="发现时间" :colon="true"
            placeholder="点击选择日期和时间" @click="showDatetimePicker = true" required
            :rules="[{ required: true, message: '请选择内容' }]" />
          <van-popup v-if="!form.status > 0" v-model:show="showDatetimePicker" position="bottom" round
            style="height: 60%">
            <van-date-picker v-model="currentDate" title="选择日期" :min-date="minDate" :max-date="maxDate"
              @confirm="onDateConfirm" @cancel="showDatetimePicker = false" />
            <van-time-picker v-model="currentTime" title="选择时间" :columns-type="['hour', 'minute', 'second']"
              @confirm="onTimeConfirm" @cancel="showDatetimePicker = false" />
            <div style="display: flex; justify-content: space-between; padding: 10px;">
              <van-button type="danger" @click="showDatetimePicker = false">取消</van-button>
              <van-button type="primary" @click="onConfirmDatetime">确定</van-button>
            </div>
          </van-popup>

          <van-field readonly v-model="form.discovererDesc" :colon="true" label="发现人" name="发现人" placeholder="请选择发现人"
            required :rules="[{ required: true, message: '请选择' }]" @click="handleDepartmentLeaderName" />
          <OrganizationalWithLeafUserOne v-if="!form.status > 0" ref="PopupDepartmentLeaderNameRef"
            @receive-from-child="getDepartmentLeaderName" :main-key="leaderKey" />
          <van-field v-if="form.hdSelect !== '下发隐患'" readonly border v-model="form.discovererOtherDesc" name="其他发现人"
            label="其他发现人" :colon="true" placeholder="请选择其他发现人" @click="handleDepartmentLeaderName2" />
          <OrganizationalWithLeafUser v-if="!form.status > 0" ref="PopupDepartmentLeaderNameRef2"
            @receive-from-child="getDepartmentLeaderName2" :main-key="leaderKey2" />
          <van-field :readonly="form.status > 0" border v-model="form.hdDescription" name="隐患描述" label="隐患描述"
            :colon="true" placeholder="请输入内容" required :rules="[{ required: true, message: '请输入内容' }]" type="textarea"
            rows="1" autosize />

          <van-field v-if="form.hdSelect !== '下发隐患'" is-link :colon="true" readonly v-model="form.hdLevel" required
            label="隐患等级" placeholder="选择等级" @click="showPicker2 = true"
            :rules="[{ required: true, message: '请选择内容' }]" />
          <van-popup v-if="!form.status > 0" v-model:show="showPicker2" round position="bottom">
            <van-picker :columns="yhdjs" @cancel="showPicker2 = false" @confirm="onConfirmYhdj" />
          </van-popup>

          <van-field v-model="form.picBefore" :colon="true" readonly label="整改前图片" />
          <AttachmentS3Image :disabled="form.status > 0" :f-id="form.hdPicId" />

          <van-field v-if="form.hdSelect === '正常登记'" :colon="true" readonly label="附件上传" />
          <AttachmentS3 v-if="form.hdSelect === '正常登记'" :f-id="form.hdPicId + 'fjwj'" />

          <div v-if="form.status > 0" style="color: #4C93E6;font-size: 14px;margin-left: 0px;background-color: #f5f5f5;padding: 8px 12px;
          margin: 0 -10px 10px -10px;">隐患分析确认</div>
          <van-field v-if="form.status > 0" readonly v-model="form.repairLeaderDesc" :colon="true" label="整改人"
            name="整改人" placeholder="请选择整改人" required :rules="[{ required: true, message: '请选择' }]"
            @click="handleDepartmentLeaderNamezgr" />
          <OrganizationalWithLeafUserOne ref="PopupDepartmentLeaderNameRefzgr"
            @receive-from-child="getDepartmentLeaderNamezgr" :main-key="leaderKeyzgr" />
          <van-field v-if="form.hdSelect !== '下发隐患' && form.status > 0" readonly border v-model="form.repairOtherDesc"
            name="其他整改人" label="其他整改人" :colon="true" placeholder="请选择其他整改人" @click="handleDepartmentLeaderName2qtzgr"
            required :rules="[{ required: true, message: '请选择' }]" />
          <OrganizationalWithLeafUser ref="PopupDepartmentLeaderNameRef2qtzgr"
            @receive-from-child="getDepartmentLeaderName2qtzgr" :main-key="leaderKey2qtzgr" />

          <van-field v-if="form.hdSelect !== '下发隐患' && form.status > 0 && form.hdSelect !== '即查即改'" border
            v-model="form.repairSuggest" name="整改建议" label="整改建议" :colon="true" placeholder="请输入整改建议" required
            :rules="[{ required: true, message: '请输入整改建议' }]" type="textarea" rows="1" autosize />

          <van-field v-if="form.hdSelect !== '下发隐患' && form.status > 0 && form.hdSelect !== '即查即改'"
            v-model="form.repairDdl" is-link readonly name="datetime" label="整改期限" :colon="true" placeholder="点击选择整改期限"
            @click="showDatetimePicker2 = true" required :rules="[{ required: true, message: '请选择整改期限' }]" />
          <van-popup v-model:show="showDatetimePicker2" position="bottom" round style="height: 60%">
            <van-date-picker v-model="currentDate2" title="选择日期" :min-date="minDate2" :max-date="maxDate2"
              @confirm="onDateConfirm2" @cancel="showDatetimePicker2 = false" />
            <van-time-picker v-model="currentTime2" title="选择时间" :columns-type="['hour', 'minute', 'second']"
              @confirm="onTimeConfirm2" @cancel="showDatetimePicker2 = false" />
            <div style="display: flex; justify-content: space-between; padding: 10px;">
              <van-button type="danger" @click="showDatetimePicker2 = false">取消</van-button>
              <van-button type="primary" @click="onConfirmDatetime2">确定</van-button>
            </div>
          </van-popup>

          <!--        部门选择-->
          <van-field v-if="form.status > 0 && form.hdSelect !== '即查即改'" v-model="form.repairDept" 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 v-if="form.status > 0 && form.hdSelect !== '即查即改'" readonly v-model="form.acceptLeaderDesc"
            :colon="true" label="验收人" name="验收人" placeholder="请选择验收人" required
            :rules="[{ required: true, message: '请选择' }]" @click="handleDepartmentLeaderNameysr" />
          <OrganizationalWithLeafUserOne ref="PopupDepartmentLeaderNameRefysr"
            @receive-from-child="getDepartmentLeaderNameysr" :main-key="leaderKeyysr" />

          <van-field v-if="form.status > 0 && form.hdSelect !== '下发隐患' && form.hdSelect !== '即查即改'" readonly border
            v-model="form.acceptOtherDesc" name="其他验收人" label="其他验收人" :colon="true" placeholder="请选择其他验收人"
            @click="handleDepartmentLeaderName2qtysr" required :rules="[{ required: true, message: '请选择' }]" />
          <OrganizationalWithLeafUser ref="PopupDepartmentLeaderNameRef2qtysr"
            @receive-from-child="getDepartmentLeaderName2qtysr" :main-key="leaderKey2qtysr" />

          <van-field v-if="form.status > 1 && form.hdSelect !== '下发隐患'" :colon="true" readonly label="临时管控现场图片" />
          <AttachmentS3Image style="background-color: white;" v-if="form.status > 1 && form.hdSelect !== '下发隐患'"
            :f-id="form.hdPicId + 'lsgkxctp'" />
          <van-field v-if="form.status > 1 && form.hdSelect !== '即查即改' && form.hdSelect !== '下发隐患'" :colon="true"
            readonly label="临时管控告知书" />
          <AttachmentS3 style="background-color: white;"
            v-if="form.status > 1 && form.hdSelect !== '即查即改' && form.hdSelect !== '下发隐患'"
            :f-id="form.hdPicId + 'lsgkwj'" />
          <van-field v-if="form.status > 1 && form.hdSelect !== '即查即改' && form.hdSelect !== '下发隐患'" :colon="true"
            readonly label="销号单" />
          <AttachmentS3 style="background-color: white;"
            v-if="form.status > 1 && form.hdSelect !== '即查即改' && form.hdSelect !== '下发隐患'"
            :f-id="form.hdPicId + 'xhdwj'" />
          <van-field v-if="form.status > 1" v-model="form.picAfter" :colon="true" readonly label="整改后图片" />
          <AttachmentS3Image style="background-color: white;" v-if="form.status > 1" :f-id="form.hdPicId + 'zgh'" />

          <van-field v-if="form.status > 1" border v-model="form.repairDescription" name="整改后情况描述" label="整改后情况描述"
            :colon="true" placeholder="请输入整改后情况描述" required :rules="[{ required: true, message: '请输入内容' }]"
            type="textarea" rows="1" autosize />

          <van-field v-if="form.status > 3" border v-model="form.hdRoot" name="隐患溯源" label="隐患溯源" :colon="true"
            placeholder="请输入隐患溯源" required :rules="[{ required: true, message: '请输入内容' }]" type="textarea" rows="1"
            autosize />

        </van-form>

        <van-list :finished="isFinished" finished-text="没有更多了" style="background-color: white;">
          <h3 style="margin-left: 10px;margin-left: 0px;background-color: #f5f5f5;
 padding: 15px 12px;margin: 0 -10px 10px -10px;">审批历史</h3>
          <div v-for="item in tableData" :key="item.id">
            <van-cell>
              <template #title>
                <van-icon name="checked" size="15" color="#07c160" /><span style="margin-left: 4px;color: #07c160;">{{
                  item.actionname
                }}</span>
              </template>
              <template #label>
                <div class="label-content">
                  <div>操作时间：{{ item.actiontime }}</div>
                  <div>审批意见：{{ item.comments }}</div>
                  <div>节点名称：{{ item.nodename }}</div>
                  <div>用户名：{{ item.username }}</div>
                  <div>备注：{{ item.memo }}</div>
                </div>
              </template>
            </van-cell>
          </div>
          <div style="background-color: white;padding: 10px;height: 10px;"></div>
        </van-list>
      </van-tab>
      <van-tab title="流程图" name="image">
        <iframe :src="urlFrame" width="1800px" height="600px" ref="iframe"></iframe>
      </van-tab>
    </van-tabs>
  </div>


  <van-dialog v-model:show="showDialog" title="提示" show-cancel-button :confirm-button-text="confirmButtonText"
    :cancel-button-text="cancelButtonText" @confirm="handleJumpRejectStart" @cancel="handleCancel">
    <div>确定退回？</div>
  </van-dialog>

  <van-dialog v-model:show="showDialog2" title="提示" show-cancel-button :confirm-button-text="confirmButtonText"
    :cancel-button-text="cancelButtonText" @confirm="handleGetBack" @cancel="handleCancel">
    <div>确定退回？</div>
  </van-dialog>

  <van-dialog v-model:show="showDialog3" title="提示" show-cancel-button :confirm-button-text="confirmButtonText"
    :cancel-button-text="cancelButtonText" @confirm="handleStop" @cancel="handleCancel">
    <div>确定退回？</div>
  </van-dialog>

  <van-dialog v-model:show="showDialog4" title="提示" show-cancel-button :confirm-button-text="confirmButtonText"
    :cancel-button-text="cancelButtonText" @confirm="handleReaded" @cancel="handleCancel">
    <div>确定退回？</div>
  </van-dialog>

  <van-dialog v-model:show="showDialog5" title="提示" show-cancel-button :confirm-button-text="confirmButtonText"
    :cancel-button-text="cancelButtonText" @confirm="handleReject" @cancel="handleCancel">
    <div>确定退回？</div>
  </van-dialog>

  <van-dialog v-model:show="showDialog7" title="提示" show-cancel-button :confirm-button-text="confirmButtonText"
    :cancel-button-text="cancelButtonText" @confirm="handleConfirmSubmitQueDing" @cancel="handleCancel">
    <div>确定退回？</div>
  </van-dialog>
</template>

<script setup>
import {
  ref,
  toRaw,
  reactive,
  onMounted,
  onActivated,
  getCurrentInstance,
  nextTick,
  defineAsyncComponent
} from 'vue';

const onClickLeft = () => {
  history.back();
};
const {
  proxy
} = getCurrentInstance();
import {
  useRoute
} from 'vue-router';

const route = useRoute();

import { Toast } from 'vant';

//-1
const showDialog = ref(false);
// 显示对话框
const showConfirmDialog = () => {
  showDialog.value = true;
};
// 取消按钮点击事件
const handleCancel = () => {
  showToast({
    message: '已取消！'
  });
  showDialog.value = false;
  showDialog2.value = false;
  showDialog3.value = false;
  showDialog4.value = false;
  showDialog5.value = false;
  showDialog6.value = false;
  showDialog7.value = false;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handleJumpReject = () => {
  showConfirmDialog();
};
//-2
const showDialog2 = ref(false);
// 显示对话框
const showConfirmDialog2 = () => {
  showDialog2.value = true;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handleGet = () => {
  showConfirmDialog2();
};
//-3
const showDialog3 = ref(false);
// 显示对话框
const showConfirmDialog3 = () => {
  showDialog3.value = true;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handle = () => {
  showConfirmDialog3();
};
//-4
const showDialog4 = ref(false);
// 显示对话框
const showConfirmDialog4 = () => {
  showDialog4.value = true;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handleR = () => {
  showConfirmDialog4();
};
//-5
const showDialog5 = ref(false);
// 显示对话框
const showConfirmDialog5 = () => {
  showDialog5.value = true;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handleRe = () => {
  showConfirmDialog5();
};
//-6
const showDialog6 = ref(false);
// 显示对话框
const showConfirmDialog6 = () => {
  showDialog6.value = true;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handleConfirmS = () => {
  showConfirmDialog6();
};
//-7
const showDialog7 = ref(false);
// 显示对话框
const showConfirmDialog7 = () => {
  showDialog7.value = true;
};
// 示例：调用 showConfirmDialog() 来触发对话框显示
const handleConfirmSubmit = (nodeName) => {
  variables.value = oldVariables.value;
  if (sessionStorage.getItem('variables') !== null
    && sessionStorage.getItem('variables') !== undefined
    && sessionStorage.getItem('variables') !== '') {
    const newVariables = JSON.parse(sessionStorage.getItem('variables'));

    variables.value = { ...oldVariables.value, ...newVariables };
  }
  console.log('variables.value', variables.value);
  showConfirmDialog7();
};


const confirmButtonText = ref('确认');
const cancelButtonText = ref('取消');

const multipleSelection = ref([]);
const handleSelectionChange = (val) => {
  console.log(val);
  let repeat = false;

  for (let i = 0; i < val.length; i++) {
    console.log(val[i].user.id);
    repeat = false;
    for (let j = 0; j < multipleSelection.value.length; j++) {
      if (multipleSelection.value[j].user.id === val[i].user.id) {
        repeat = true;
        break;
      }
    }
    if (!repeat) {
      multipleSelection.value.push(val[i]);
    }
  }

  for (let i = 0; i < val.length; i++) {
    repeat = false;
    for (let j = 0; j < tableDataUser.value.length; j++) {
      if (tableDataUser.value[j].user.id === val[i].user.id) {
        repeat = true;
        break;
      }
    }
    if (!repeat) {
      tableDataUser.value.push(val[i]);
    }
  }

};

const buttonName = (buttonId) => {
  switch (buttonId) {
    case 'submit':
      return '同意';
    case 'readed':
      return '阅知';
    case 'reject':
      return '退回';
    case 'jumpreject':
      return 'warning';
    case 'jumprejectstart':
      return '驳回';
    case 'stop':
      return '终止';
    case 'move':
      return '转办';
    case 'getback':
      return '拿回';
    default:
      return 'default'; // 或者返回null/undefined，但Element UI的el-button有默认样式
  }
};

// 一个用于根据name返回button type的函数
const buttonType = (buttonId) => {
  switch (buttonId) {
    case 'submit':
      return 'success';
    case 'readed':
      return 'success';
    case 'reject':
      return 'default';
    case 'jumpreject':
      return 'warning';
    case 'jumprejectstart':
      return 'warning';
    case 'stop':
      return 'danger';
    case 'move':
      return 'primary';
    case 'getback':
      return 'primary';
    default:
      return 'default'; // 或者返回null/undefined，但Element UI的el-button有默认样式
  }
};
const shouldShowButton = (buttonId) => {
  return buttonId === 'submit'
    || buttonId === 'reject'
    // || buttonId === 'jumpreject'
    || buttonId === 'jumprejectstart'
    || buttonId === 'stop'
    || buttonId === 'getback'
    || buttonId === 'readed'
    || buttonId === 'move';
};

import style from '@/tools/style';

const cardBodyStyle = ref(style.card);

const dialogVisibleUser = ref(false);
const dialogVisibleNode = ref(false);
const radioNode = ref('');
const radioNodeValue = ref('');

const radioNodes = ref([]);
const radioNodeSelect = ref([]);

const openDialog = () => {
};

const defaultProps = ref({
  children: 'children',
  label: 'deptName'
});

const expandedKeys = ref([]);
const dataTree = ref([]);
const selectedDept = ref({
  id: '',
  deptCode: ''
});

const onRadioChange = (data) => {
  console.log(data);
  radioNodeValue.value = data;

};

const handleNodeClick = (data) => {
  selectedDept.value = data;
  getTableDataUserDept();
};

const getDataDeptTree = () => {
  if (deptIds.value === '') {
    var url = 'framework/SysDepartment/queryTree';
    var param = {};
    proxy.$axios.get(url, param).then(response => {
      dataTree.value = response.data.data;
      if (dataTree.value.length === 1) {
        for (var node of dataTree.value) {
          expandedKeys.value.push(node.id);
        }
        console.log(dataTree.value);
      }
    });
  } else {
    var url = 'framework/SysDepartment/queryByIds';
    var param = {
      ids: deptIds.value
    };
    proxy.$axios.get(url, param).then(response => {
      if (response.data.code == '0') {
        // var children = []
        // children.push(response.data.data)
        dataTree.value = [{
          id: '10010',
          deptCode: 'root',
          deptName: '部门',
          children: response.data.data
        }];
        for (var node of dataTree.value) {
          expandedKeys.value.push(node.id);
        }
      }
    });
  }
};

const defaultPropsPost = ref({
  children: 'children',
  label: 'postName'
});

const expandedKeysPost = ref([]);
const dataPost = ref([]);
const selectedPost = ref({
  id: '',
  postCode: ''
});

const getDataPost = () => {
  var url = 'framework/SysPost/queryByIds';
  var param = {
    page: 1,
    rows: 40,
    ids: postIds.value
  };
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {

      dataPost.value = [{
        id: '10086',
        postCode: 'root',
        postName: '岗位',
        children: response.data.data
      }];
      for (var node of dataPost.value) {
        expandedKeysPost.value.push(node.id);
      }
    }
  });
};

const handleNodeClickPost = (data) => {
  selectedPost.value = data;
  getTableDataUserPost();
};

const getTableDataUserPost = () => {
  var url = 'framework/SysUserPost/queryByPostId';
  var param = {
    postId: selectedPost.value.id
  };
  proxy.$axios.get(url, param).then(response => {
    tableDataUserDept.value = response.data.data;
  });
};


const tableDataUserDept = ref([]);

const getTableDataUserDept = () => {
  var url = 'framework/SysUserDept/queryByDeptId';
  var param = {
    deptId: selectedDept.value.id
  };
  proxy.$axios.get(url, param).then(response => {
    tableDataUserDept.value = response.data.data;
  });
};

const tableDataUser = ref([]);

const handleDeleteUserData = (row) => {

  for (let i = 0; i < multipleSelection.value.length; i++) {
    if (multipleSelection.value[i].id === row.id) {
      multipleSelection.value.splice(i, 1);
    }
  }

  for (let i = 0; i < tableDataUser.value.length; i++) {
    if (tableDataUser.value[i].id === row.id) {
      tableDataUser.value.splice(i, 1);
    }
  }
};


const handleSave = () => {
  handleConfirmSubmit(nextNodeName.value);
  dialogVisibleUser.value = false;
};

const handleCancelSave = () => {
  dialogVisibleUser.value = false;
};

const handleSaveNode = () => {
  // handleConfirmSubmit()
  radioNodeSelect.value = [];
  console.log(radioNodeValue.value);
  for (let i = 0; i < radioNodes.value.length; i++) {
    if (radioNodes.value[i].nodeId === radioNodeValue.value) {
      radioNodes.value[i].isSelect = 'true';
      radioNodeSelect.value.push(radioNodes.value[i]);
    }
  }

  nextNodeList.value = radioNodeSelect.value;
  console.log(nextNodeList.value);
  handlePreSubmit();
  dialogVisibleNode.value = false;
};

const handleCancelSaveNode = () => {
  dialogVisibleNode.value = false;
};

const activeTab = ref(0);
onMounted(() => {

  const workflowQuery = JSON.parse(sessionStorage.getItem('workflowQuery'));
  flowId.value = workflowQuery.flowId;
  workId.value = workflowQuery.workId;
  trackId.value = workflowQuery.trackId;
  subjectionId.value = workflowQuery.subjectionId;
  type.value = workflowQuery.type;
  if (type.value === undefined || type.value === null) {
    type.value = '0';
  }

  console.log('你还好吗', workflow.workId);
  var url = 'sgsafe/Hiddendanger/queryByWorkId';
  var param = {
    workId: workId.value
  };
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code == '0') {
      console.log(response.data.data);
      form.value = response.data.data;
    } else {
      ElMessage.error('操作失败！' + response.data.msg);
    }
  });

  openWorkflow();
  getTableData()
});

onActivated(() => {
  const workflowQuery = JSON.parse(sessionStorage.getItem('workflowQuery'));
  flowId.value = workflowQuery.flowId;
  workId.value = workflowQuery.workId;
  trackId.value = workflowQuery.trackId;
  subjectionId.value = workflowQuery.subjectionId;
  type.value = workflowQuery.type;
  if (type.value === undefined || type.value === null) {
    type.value = '0';
  }
  openWorkflow();
  // getBusinessPage()

});

// const loginName = ref(localStorage.getItem('userName'))
const handleTabsClick = (tab, event, item) => {
  if (activeTab.value == 'process') {
    getHistory();
  } else if (activeTab.value == 'image') {
    urlFrame.value =
      `${import.meta.env.VITE_WORKFLOW_ADDR}` + '/horizon-workflow-boot/workflow/module/designer/index.html?workid=' + workId
        .value + '&showtype=2&dataid=' + workId.value;
  }
};

const activeName = ref('business');
const flowId = ref('');
const workId = ref('');
const trackId = ref('');
const subjectionId = ref('');
const type = ref('');

const nextNodeList = ref([]);

const urlFrame = ref('');

const currentComponent = ref('');
const tableDataHistory = ref([]);

const getHistory = () => {
  var url = 'workflow/process/history';
  var param = {
    workId: workId.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == '0') {
      tableDataHistory.value = response.data.data.records;
    } else {
      showToast({
        type: 'error',
        message: '操作失败！' + response.data.msg
      });
    }
  });
};

const getBusinessPage = () => {
  var url = 'framework/BusinessProcess/queryBusinessPageByFlowId';
  var param = {
    flowId: flowId.value
  };
  console.log('flowId:::' + JSON.stringify(flowId.value));
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == '0') {
      console.log('getBusinessPage:::' + JSON.stringify(response.data.data));

      const modules = import.meta.glob('../**/*.vue');
      currentComponent.value = defineAsyncComponent(modules[`..${response.data.data.pathWeb}.vue`]);

    } else {
      showToast({
        type: 'error',
        message: '操作失败！' + response.data.msg
      });
    }
  });
};

const flowInfo = ref({});
const oldVariables = ref({});
const nextNodeName = ref('');

const postIds = ref('');

const deptIds = ref('');


import {
  useWorkflowStore
} from '@/stores/workflow';
import { showToast } from 'vant';
import OrganizationalWithLeaf from '@/components/OrganizationalWithLeaf.vue';
import AttachmentS3Image from '@/components/AttachmentS3Image.vue';
import AttachmentS3 from '@/components/AttachmentS3.vue';
import OrganizationalWithLeafUser from '@/components/OrganizationalWithLeafUser.vue';
import OrganizationalWithLeafUserOne from '@/components/OrganizationalWithLeafUserOne.vue';


const workflow = useWorkflowStore();

const openWorkflow = () => {
  var url = 'workflow/task/open';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == '0') {
      flowInfo.value = response.data.data;
      oldVariables.value = flowInfo.value['flowVars'];
    } else {
    }
    workflow.setWorkId(workId.value);
    getBusinessPage();
  });
};

const comment = ref('');

const handleClick = (item) => {
  console.log(item['buttonId']);
  console.log(item['buttonName']);
  if (item['buttonId'] === 'submit') {
    handlePreSubmit();
  } else if (item['buttonId'] === 'reject') {
    handleRe();
  } else if (item['buttonId'] === 'jumprejectstart') {
    handleJumpReject();
  } else if (item['buttonId'] === 'getback') {
    handleGet();
  } else if (item['buttonId'] === 'stop') {
    handle();
  } else if (item['buttonId'] === 'readed') {
    handleR();
  }

};
/**
 const handleSubmit = () => {
 if (comment.value === undefined || comment.value === '') {
 showToast({
 type: 'error',
 message: '请填写审批意见',
 })
 return
 }
 ElMessageBox.confirm(
 '确定通过?',
 '提示', {
 confirmButtonText: '确认',
 cancelButtonText: '取消',
 type: 'warning',
 draggable: true,
 }
 ).then(() => {
 var url = 'workflow/task/confirmSubmit'
 var param = {
 workId: workId.value,
 trackId: trackId.value,
 subjectionId: subjectionId.value,
 comment: comment.value
 }
 proxy.$axios.post(url, param).then(response => {

 if (response.data.code == 0) {
 var status = response.data.data.status

 // 选人
 if (status === 4) {
 var nextNodes = response.data.data.nextNodes;
 // 后续就只有一个节点，不需要选择节点
 if (nextNodes && nextNodes.length === 1) {

 // 选人
 if ((nextNodes[0].authors.Author && nextNodes[0].authors.Author.initAuthor)
 || nextNodes[0].authors.Author.selectAuthor === undefined) {

 var positions = undefined
 var depts = undefined
 if (nextNodes[0].authors.Author.initAuthor) {
 positions = nextNodes[0].authors.Author.initAuthor.positions
 depts = nextNodes[0].authors.Author.initAuthor.depts
 // 岗位
 if (positions) {
 postName.value = positions[0].name
 console.log('positions:' + postName.value)
 getDataPost();
 }

 // 部门
 if (depts) {
 deptIds.value = depts[0].id
 console.log('depts:' + deptIds.value)
 getDataDeptTree();
 }
 }

 if (nextNodes[0].authors.Author.initAuthor === undefined
 && nextNodes[0].authors.Author.selectAuthor === undefined) {
 getDataPost();
 getDataDeptTree();
 }

 // 打开弹出框
 dialogVisibleUser.value = true
 nextNodeList.value = nextNodes;

 }
 // 不选人
 else {
 handleConfirmSubmit();
 }

 }
 // 后续多个节点，需要选择节点
 else if (nextNodes && nextNodes.length > 1) {
 console.log(nextNodes.length)
 }
 // 没有后续节点
 else {
 console.log(nextNodes.length)
 }

 }
 // 选节点
 else if (status === 2) {
 console.log('请选择节点')
 console.log(status)
 console.log(response.data.data)
 radioNodes.value = response.data.data.nextNodes
 console.log(radioNodes.value)
 if (radioNodes.value.length > 0) {
 radioNode.value = radioNodes.value[0].nodeName;
 console.log(radioNode.value)
 }
 dialogVisibleNode.value = true

 }
 // 执行成功
 else if (status === 0) {
 showToast({
 type: 'success',
 message: '操作成功，流程已通过',
 })
 handleTodo()
 }
 } else {
 showToast({
 type: 'error',
 message: '操作失败'+response.data.msg,
 })
 }
 });
 }).catch(() => {
 showToast({
 type: 'info',
 message: '已取消',
 })
 })
 }**/

const variables = ref({});
const handlePreSubmit = () => {
  variables.value = oldVariables.value;
  if (sessionStorage.getItem('variables') !== null
    && sessionStorage.getItem('variables') !== undefined
    && sessionStorage.getItem('variables') !== '') {
    const newVariables = JSON.parse(sessionStorage.getItem('variables'));
    variables.value = { ...oldVariables.value, ...newVariables };
  }
  if (comment.value === undefined || comment.value === '') {
    showToast({
      type: 'error',
      message: '请填写审批意见'
    });
    return;
  }
  var url = 'workflow/task/submit';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value,
    comment: comment.value,
    variables: JSON.stringify(variables.value),
    nextNodes: JSON.stringify(nextNodeList.value)
  };
  console.log('valibles', JSON.stringify(variables.value));
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {

      console.log(response.data.data);
      var status = response.data.data.status;
      // 选人
      if (status === 4) {
        var nextNodes = response.data.data.nextNodes;
        // 后续就只有一个节点，不需要选择节点
        if (nextNodes && nextNodes.length === 1) {
          if ((nextNodes[0].authors.Author && nextNodes[0].authors.Author.initAuthor)
            || (nextNodes[0].authors.Author && nextNodes[0].authors.Author.selectAuthor === undefined)) {

            var positions = undefined;
            var depts = undefined;
            var others = undefined;
            if (nextNodes[0].authors.Author.initAuthor) {
              positions = nextNodes[0].authors.Author.initAuthor.positions;
              depts = nextNodes[0].authors.Author.initAuthor.depts;
              others = nextNodes[0].authors.Author.initAuthor.others;
              // 岗位
              if (positions) {
                postIds.value = '';
                for (let i = 0; i < positions.length; i++) {
                  postIds.value += positions[i].id + ',';
                }
                console.log('positions:' + postIds.value);
                getDataPost();
              }

              // 部门
              if (depts) {
                deptIds.value = '';
                for (let i = 0; i < depts.length; i++) {
                  deptIds.value += depts[i].id + ',';
                }
                console.log('depts:' + deptIds.value);
                getDataDeptTree();
              }
            }

            if (nextNodes[0].authors.Author.initAuthor === undefined
              && nextNodes[0].authors.Author.selectAuthor === undefined) {
              getDataPost();
              getDataDeptTree();
            }

            // 打开弹出框
            dialogVisibleUser.value = true;
            nextNodeList.value = nextNodes;
            nextNodeName.value = nextNodes[0].nodeName;
          }
          // 不选人
          else {
            handleConfirmSubmit(nextNodes[0].nodeName);
          }
        }
        // 后续多个节点，需要选择节点、给多节点赋值用户
        else if (nextNodes && nextNodes.length > 1) {
          console.log('后续多个节点，需要选择节点、给多节点赋值用户');
        }
        // 没有后续节点
        else {
          console.log('没有后续节点');
        }
      }
      // 选节点
      else if (status === 2) {
        radioNodes.value = response.data.data.nextNodes;
        console.log(radioNodes.value);
        if (radioNodes.value.length > 0) {
          radioNode.value = radioNodes.value[0].nodeName;
          console.log(radioNode.value);
        }
        dialogVisibleNode.value = true;
      }
      // 执行成功
      else if (status === 0) {
        var nextNodes = response.data.data.nextNodes;
        handleConfirmSubmit(nextNodes[0].nodeName);
      }
    } else {
      showToast({
        type: 'error',
        message: '操作失败'
      });
    }
  });
};

const handleConfirmSubmitQueDing = () => {
  var url = 'workflow/task/confirmSubmit';

  if (tableDataUser.value.length > 0) {
    var selectAuthor = '';
    var selectAuthorName = '';
    for (let i = 0; i < tableDataUser.value.length; i++) {
      selectAuthor = selectAuthor + tableDataUser.value[i].user.id + ';';
      selectAuthorName = selectAuthorName + tableDataUser.value[i].user.userDesc + ';';
    }
    var author = {
      'authorId': 'Author',
      'authorName': '主办',
      'selectType': 'radio',
      'isFree': 'true',
      'isUser': 'false',
      'isDefUser': 'false',
      'isSelect': 'true',
      'selectAuthor': selectAuthor,
      'selectAuthorName': selectAuthorName,
      'required': null,
      'initAuthor': null
    };
    nextNodeList.value[0].authors.Author = author;
  }

  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value,
    comment: comment.value,
    variables: JSON.stringify(variables.value),
    nextNodes: JSON.stringify(nextNodeList.value)
  };

  console.log('param' + JSON.stringify(param));

  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      console.log(response.data);
      showToast({
        type: 'success',
        message: '操作成功，流程已通过'
      });
      handleTodo();
    } else {
      showToast({
        type: 'error',
        message: '操作失败' + response.data.msg
      });
    }
  });
};

const handleReject = () => {
  var url = 'workflow/task/reject';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value,
    comment: comment.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      showToast({
        type: 'success',
        message: '操作成功，流程已退回'
      });
      handleTodo();
    } else {
      showToast({
        type: 'error',
        message: '操作失败' + response.data.msg
      });
    }
  });
};

const handleReaded = () => {
  var url = 'workflow/task/read';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      showToast({
        type: 'success',
        message: '操作成功，流程已读'
      });
      handleTodo();
    } else {
      showToast({
        type: 'error',
        message: '操作失败，请联系开发人员'
      });
    }
  });
};

const handleStop = () => {
  var url = 'workflow/task/stop';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      showToast({
        type: 'success',
        message: '操作成功，流程已终止'
      });
      handleTodo();
    } else {
      showToast({
        type: 'error',
        message: '操作失败，请联系开发人员'
      });
    }
  });
};

const handleGetBack = () => {
  var url = 'workflow/task/getBack';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      showToast({
        type: 'success',
        message: '操作成功，流程已拿回'
      });
      handleTodo();
    } else {
      showToast({
        type: 'error',
        message: '操作失败，流程已审批，不允许拿回'
      });
    }
  });
};

const handleJumpRejectStart = () => {
  var url = 'workflow/task/jumpRejectStart';
  var param = {
    workId: workId.value,
    trackId: trackId.value,
    subjectionId: subjectionId.value,
    comment: comment.value
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      showToast({
        type: 'success',
        message: '操作成功，流程已退回到提交人！'
      });
      handleTodo();
    } else {
      showToast({
        type: 'error',
        message: '操作失败！' + response.data.msg
      });
    }
  });
};

const handleTodo = () => {
  if (type.value === '2') {
    proxy.$router.push({
      path: '/workflow/haddone',
      query: {}
    });
  } else if (type.value === '3') {
    proxy.$router.push({
      path: '/schedule'
    });
  } else {
    proxy.$router.push({
      // path: '/workflow/todo',
      path: '/yinhuan/todo',
      query: {}
    });
  }
};


/**历史任务详情**/
const tableData = ref([]);
const date = ref(null);
const query = ref({
  hdType: ''
});
const isRefreshing = ref(false);
const isLoading = ref(false);
const isFinished = ref(false);
const currentPage = ref(1);
const pageSize = ref(10);
const totalRows = ref(0);

const getTableData = () => {
  const url = 'workflow/process/history';
  const param = {
    workId: workId.value
  };
  proxy.$axios.get(url, param).then(response => {
    if (response.data.code === 0) {

      tableData.value = response.data.data.records;

      tableData.value.forEach(item => {
        switch (item.status) {
          case '0':
            item.status = '隐患登记';
            break;
          case '1':
            item.status = '隐患分析确认';
            break;
          case '2':
            item.status = '隐患整改';
            break;
          case '3':
            item.status = '隐患验收';
            break;
          case '4':
            item.status = '隐患销号';
            break;
          case '5':
            item.status = '结束';
            break;
          case '-1':
            item.status = '待提交';
            break;
        }
      });
    } else {
      showToast({
        type: 'error',
        message: '操作失败！' + response.data.msg
      });
    }
  });
};

const onLoad = () => {
  if (!isFinished.value) {
    currentPage.value += 1;
    getTableData();
  }
};

//表单
/**表单*/
const form = ref({
  discovererOtherDesc: '',
  hdPicId: '',
  hdId: '',
  hdType: '',
  discoveryTime: '',
  hdSubtype: '',
  discoverer: '',
  discovererOther: '',
  hdDescription: '',
  hdLevel: '',
  bz: '',
  hdLocation: '',
  picBefore: '',

  equipmentId: '',
  hdmanageLevel: '',
  handlingProcesses: '',
  companyId: '',
  repairLeader: '',
  repairOther: '',
  repairSuggest: '',
  repairDdl: '',
  repairDept: '',
  acceptLeader: '',
  acceptOther: '',
  picAfter: '',
  picTemp: '',
  repairDescription: '',
  discovererDept: '',
  discovererDeptCode: '',
  hdLocationCode: '',
  hdLocationName: '',

  status: '',


  hdSelect: '正常登记',
  id: ''
});

//发现时间
const showDatetimePicker = ref(false);
const currentDate = ref([2024, 8, 1]);
const currentTime = ref([12, 0, 0]);
const minDate = new Date(2000, 0, 1);
const maxDate = new Date(2050, 11, 31);

const onDateConfirm = () => {
  // 日期选择确认后的处理
};

const onTimeConfirm = () => {
  // 时间选择确认后的处理
};

const onConfirmDatetime = () => {
  const year = currentDate.value[0];
  const month = currentDate.value[1].toString().padStart(2, '0');
  const day = currentDate.value[2].toString().padStart(2, '0');
  const hours = currentTime.value[0].toString().padStart(2, '0');
  const minutes = currentTime.value[1].toString().padStart(2, '0');
  const seconds = currentTime.value[2].toString().padStart(2, '0');

  form.value.discoveryTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  showDatetimePicker.value = false;
};

//整改期限
const showDatetimePicker2 = ref(false);
const currentDate2 = ref([2024, 8, 1]);
const currentTime2 = ref([12, 0, 0]);
const minDate2 = new Date(2000, 0, 1);
const maxDate2 = new Date(2050, 11, 31);

const onDateConfirm2 = () => {
  // 日期选择确认后的处理
};

const onTimeConfirm2 = () => {
  // 时间选择确认后的处理
};

const onConfirmDatetime2 = () => {
  const year = currentDate2.value[0];
  const month = currentDate2.value[1].toString().padStart(2, '0');
  const day = currentDate2.value[2].toString().padStart(2, '0');
  const hours = currentTime2.value[0].toString().padStart(2, '0');
  const minutes = currentTime2.value[1].toString().padStart(2, '0');
  const seconds = currentTime2.value[2].toString().padStart(2, '0');

  form.value.repairDdl = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  showDatetimePicker2.value = false;
};


const showPicker2 = ref(false);

const onConfirmYhdj = ({ selectedOptions }) => {
  showPicker2.value = false;
  form.value.hdLevel = selectedOptions[0].value;
  console.log('选择的内容', form.value);
};

const yhdjs = ref([{ text: '一般隐患', value: '一般隐患' },
{ text: '重大隐患', value: '重大隐患' }]
);

const formRef = ref(null);
const qvxiao = () => {
  showToast({
    type: 'fail',
    message: '操作取消！'
  });
  onClickLeft();
};
const baocun = async () => {

  console.log('保存的参数', form.value);

  // 原有保存逻辑保持不变
  var url = 'sgsafe/Hiddendanger/save';
  var param = {
    json: JSON.stringify(form.value)
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {
      showToast({
        type: 'success',
        message: '保存成功！'
      });
      orJsons();
    } else {
      showToast({
        type: 'fail',
        message: '操作失败！'
      });
    }
  });
};
const repairLL = ref('');
const repairOO = ref('');
const acceptLL = ref('');
const acceptOO = ref('');
const hdCancel = ref('');
const jsons = ref('');
const orJsons = () => {
  // console.log('forms',form.value)
  nextTick(() => {
    nextTick(() => {
      repairLL.value = qq('repairLL', form.value.repairLeader);
      nextTick(() => {
        repairOO.value = qq('repairOO', form.value.repairOther);
        nextTick(() => {
          acceptLL.value = qq('acceptLL', form.value.acceptLeader);
          nextTick(() => {
            acceptOO.value = qq('acceptOO', form.value.acceptOther);
          });
        });
      });
    });

  });
  hdCancel.value = qq('hdCancel', form.value.discoverer);

};
const qq = (a, val) => {
  let aa = '';
  var url = 'sgsafe/Hiddendanger/qqId';
  var param = {
    params: val
  };
  proxy.$axios.post(url, param).then(response => {
    if (response.data.code == 0) {

      aa = response.data.data;
      switch (a) {
        case 'repairLL':
          repairLL.value = response.data.data;
          // console.log('repairLL',repairLL.value); 
          break;
        case 'repairOO':
          repairOO.value = response.data.data;
          // console.log('repairOO',repairLL.value); 
          break;
        case 'acceptLL':
          acceptLL.value = response.data.data;
          // console.log('acceptLL',repairLL.value);
          break;
        case 'acceptOO':
          acceptOO.value = response.data.data;
          // console.log('acceptOO',repairLL.value);
          break;
        case 'hdCancel':
          hdCancel.value = response.data.data;
          break;
        default:
          break;
      }
      jsons.value = {
        repairL: repairLL.value,
        repairO: repairOO.value,
        acceptL: acceptLL.value,
        acceptO: acceptOO.value,
        hdCancel: hdCancel.value
      };
      // console.log('niadsiofjmowe',jsons.value)

      // 处理函数
      function processValue(value) {
        // 将逗号替换为分号
        const replacedValue = value.replace(/,/g, ';');
        // 分割值
        const parts = replacedValue.split(';');
        // 每个部分前加上 U_
        const processedParts = parts.map(part => `U_${part.trim()}`);
        // 重新组合
        return processedParts.join(';');
      }

      // 处理整个对象
      const processedData = {};
      for (const key in jsons.value) {
        if (jsons.value.hasOwnProperty(key)) {
          processedData[key] = processValue(jsons.value[key]);
        }
      }

      console.log('对象', toRaw(processedData));

      const b = {
        acceptL: processedData.acceptL,
        acceptO: processedData.acceptO,
        repairL: processedData.repairL,
        repairO: processedData.repairO,
        hdCancel: processedData.hdCancel,
        id: form.value.id,
        readPerson: form.value.readPerson
      };

      const aaa = JSON.stringify(toRaw(b));
      // workflow.setAcceptAndRepair(aaa)
      sessionStorage.setItem('variables', aaa);
      console.log('aaa', aaa);
    } else {
      ElMessage({
        type: 'error',
        message: '查询失败' + response.data.msg
      });
    }
  });
  return aa;
};

const handleChangeHdSelect = (value) => {
  form.value.hdSelect = value;
  if (value === '正常登记') {
    isStandardFlow.value = true;
  } else if (value === '即查即改') {
    isStandardFlow.value = false;
  }
  getYHID();
};

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

  return (S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4());
};
/* 发现人 */
const leaderKey = guid();
const PopupDepartmentLeaderNameRef = ref();
const handleDepartmentLeaderName = () => {
  PopupDepartmentLeaderNameRef.value.open();
};

const codeAndDesc = ref([]);
const getDepartmentLeaderName = (item) => {
  form.value.discoverer = item.user.userCode;
  form.value.discovererDesc = 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.discovererOther = codeList.join(',');
  form.value.discovererOtherDesc = descList.join(',');
};

//定义一个变量切换即查即改还是标准流程
const isStandardFlow = ref(false);

//当是即查即改时得到隐患编号并赋值
const getYHID = () => {
  //直接请求后端返回一个隐患编号
  console.log('getYHID');
  if (form.value.hdSelect === '即查即改') {
    var url = 'sgsafe/Hiddendanger/getYhbhTemp';
    var param = {};
    proxy.$axios.get(url, param).then(response => {
      if (response.data.code == '0') {
        form.value.hdId = response.data.data;
      } else {
        ElMessage.error('操作失败！' + response.data.msg);
      }
    });
  } else {
    form.value.hdId = '';
  }
};

/* 整改人 */
const leaderKeyzgr = guid();
const PopupDepartmentLeaderNameRefzgr = ref();
const handleDepartmentLeaderNamezgr = () => {
  PopupDepartmentLeaderNameRefzgr.value.open();
};

const codeAndDesczgr = ref([]);
const getDepartmentLeaderNamezgr = (item) => {
  form.value.repairLeader = item.user.userCode;
  form.value.repairLeaderDesc = item.user.userDesc;
  form.value.repairDept = item.dept.deptName;
};

/* 其他整改人 */
const leaderKey2qtzgr = guid();
const PopupDepartmentLeaderNameRef2qtzgr = ref();
const handleDepartmentLeaderName2qtzgr = () => {
  PopupDepartmentLeaderNameRef2qtzgr.value.open();
};

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

/* 验收人 */
const leaderKeyysr = guid();
const PopupDepartmentLeaderNameRefysr = ref();
const handleDepartmentLeaderNameysr = () => {
  PopupDepartmentLeaderNameRefysr.value.open();
};

const codeAndDescysr = ref([]);
const getDepartmentLeaderNameysr = (item) => {
  form.value.acceptLeader = item.user.userCode;
  form.value.acceptLeaderDesc = item.user.userDesc;
};

/* 其他验收人 */
const leaderKey2qtysr = guid();
const PopupDepartmentLeaderNameRef2qtysr = ref();
const handleDepartmentLeaderName2qtysr = () => {
  PopupDepartmentLeaderNameRef2qtysr.value.open();
};

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

/* 组织树选择 */
const showBottom = ref(false);
const handleTableDataUserDeptUpdate = async (nodeData) => {
  form.value.repairDept = nodeData.deptName;
  // form.value.repairDept = nodeData.deptCode + '-' + nodeData.deptName
  showBottom.value = false;
};
const showPickerHandle = () => {
  showBottom.value = true;
};

</script>

<style scoped>
/*自定义单选样式*/
:deep(.van-radio__core) {
  opacity: 1;
  cursor: not-allowed;
}

:deep(.van-radio__icon--checked .van-icon) {
  color: #999999;
  background-color: #f2f2f2;
  border-color: #999999;
}

:deep(.van-radio__label) {
  color: #999999;
}

.card {
  margin: 10px;
  border-radius: 8px;
  background-color: #fff;
}

.label-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #000000;
}

.h5-container {
  width: 100%;
  box-sizing: border-box;
  height: 100vh;
  background-color: white;
  padding: 10px;
}

.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>