<!-- 设备信息表格 -->
<script lang="ts" setup name="DeviceInfoList">
import { reactive, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IlistObjType, IlistQueryType } from './interface'
import { delTextBtn, editTextBtn } from '@/utils/applyBtns'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import { bindTaskHandler, cancelInfo, deleteInfo, editInfo, exportDevice, getInfoList, getInfoListPage, getInfoListTogether, importDevice, submitInfo } from '@/api/eqpt/device/info'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import useTemplateDownload from '@/utils/useTemplateDownload'
import { exportFile } from '@/utils/exportUtils'
import { getDeviceNameList, getModelAllList, getModelList } from '@/api/eqpt/device/model'
import { getTaskList } from '@/api/eqpt/device/task'
import task from '@/views/tested/device/task/index.vue'
import { underlineToHump } from '@/utils/structure'
const $props = defineProps({
  statusName: {
    type: String,
    default: '',
  },
  // 设备类型(1受检设备;2特种设备)
  equipmentType: {
    type: String,
    default: '1',
  },
})
const applyDict = ref<{ [key: string]: string }>({
  审批: '',
  草稿箱: '1',
  审批中: '3',
  已通过: '4',
  未通过: '5',
  已取消: '6',
})
const normalTableRef = ref()
const { proxy } = getCurrentInstance() as any
const listQuery = reactive<IlistQueryType>({
  certificateValidStart: '',
  certificateValidEnd: '',
  deptIds: '', // 使用部门
  usageStatus: '', // 使用状态
  usePosition: '', // 使用岗位
  equipmentNo: '', // 统一编号
  equipmentName: '', // 设备名称
  equipmentType: $props.equipmentType, // 设备类型(1受检设备;2特种设备)
  offset: 1,
  limit: 20,
  approvalStatus: '',
  formId: SCHEDULE.DEVICE_INFO_APPROVAL,
  model: '', // 规格型号
  manufactureNo: '', // 出厂编号
  companyId: '', // 所在单位
  directorName: '', // 负责人
  useSign: '', // 再用信息
  installLocation: '', // 安装位置
  taskId: '', // 参试任务
  checkOrganization: '', // 检定机构
  meterIdentify: '', // 计量标识
  checkDateEnd: '',
  checkDateStart: '',
  sort: '',
  orderBy: '',
})
const columns = ref([
  {
    text: '统一编号',
    value: 'equipmentNo',
    align: 'center',
    sortable: 'custom',
  },
  {
    text: '设备名称',
    value: 'equipmentName',
    align: 'center',
  },
  {
    text: '规格型号',
    value: 'model',
    align: 'center',
    sortable: 'custom',
  },
  {
    text: '出厂编号',
    value: 'manufactureNo',
    align: 'center',
    sortable: 'custom',
  },
  {
    text: '使用岗位',
    value: 'usePosition',
    align: 'center',
  },
  {
    text: '计量标识',
    value: 'meterIdentifyName',
    align: 'center',
  },
  {
    text: '检定周期',
    value: 'checkCycle',
    align: 'center',
  },
  {
    text: '证书有效期',
    value: 'certificateValid',
    align: 'center',
    sortable: 'custom',
  },
])
const allColums = ref([
  {
    text: '使用状态',
    value: 'usageStatusName',
    align: 'center',
    sortable: 'custom',
  },
  {
    text: '备注',
    value: 'remark',
    align: 'center',
  },
])
const otherColums = ref([
  {
    text: '审批类型',
    value: 'approvalTypeName',
    align: 'center',
  },
  {
    text: '创建人',
    value: 'createUserName',
    align: 'center',
  },
  {
    text: '创建时间',
    value: 'createTime',
    align: 'center',
  },
  {
    text: '审批状态',
    value: 'approvalStatusName',
    align: 'center',
  },
])
// 切换表格标识   true:普通表格  false:聚合表格
const tableFlage = ref(true)
// 聚合表格实例
const togetherTableRef = ref()
// 展开表格实例
const expandTableRef = ref()
const list = ref([])
const total = ref(0)
const listLoading = ref(true)

// 获取列表数据
const fetchData = (isNowPage = true) => {
  list.value = []
  listLoading.value = true
  // if (!isNowPage) {
  //   // 是否显示当前页，否则跳转第一页
  //   listQuery.offset = 1
  // }
  getInfoListPage(listQuery, $props.statusName).then((response) => {
    list.value = response.data.rows
    total.value = parseInt(response.data.total)
    normalTableRef.value.handleChecked()
    listLoading.value = false
  }).catch((_) => {
    listLoading.value = false
  })
}
// 排序条件发生变化
const sortChange = ({ column }: any) => {
  if (column.order === 'ascending') {
    listQuery.sort = 'asc'
    // console.log(column.prop)
    // console.log('升序')
  }
  else if (column.order === 'descending') {
    listQuery.sort = 'desc'
    // console.log(column.prop)
    // console.log('倒叙')
  }
  console.log(underlineToHump(column.prop), column.prop)
  listQuery.orderBy = underlineToHump(column.prop)
  fetchData()
}
// 获取使用状态列表
const useStatusList = ref()
// 设备名称
const deviceNameList = ref<{ id: string; value: string; name: string }[]>([])
// 设备分类
const deviceTypeList = ref<{ id: string; value: string; name: string }[]>([])
// 再用信息
const useSignList = ref<{ id: string; value: string; name: string }[]>([])
// 任务列表
const taskList = ref<{ id: string; value: string; name: string }[]>([])
// 计量标识
const meterIdentifyList = ref<{ id: string; value: string; name: string }[]>()
// 规格型号
const modelList = ref<any[]>([])
const allList = ref<any[]>([])
const fetchUseStatus = () => {
  getDictByCode('eqptDeviceUseStatus').then((res) => {
    useStatusList.value = res.data
  })
  getDictByCode('eqptDeviceInUse').then((res) => {
    useSignList.value = res.data
  })
  // 设备分类
  getDictByCode('eqptDeviceType').then((res) => {
    deviceTypeList.value = res.data
  })
  // 设备名称
  getDeviceNameList().then((res) => {
    deviceNameList.value = res.data
  })
  // 规格型号
  getModelAllList({}).then((res) => {
    allList.value = res.data
    modelList.value = Array.from(new Set(res.data.filter(item => item.model).map(item => item.model)))
  })
  // 参试任务
  getTaskList({ limit: 9999, offset: 1 }).then((res) => {
    taskList.value = res.data.rows.map((item: any) => ({ name: item.taskName, value: item.id, id: item.id }))
  })
  getDictByCode('eqptMeterIdentify').then((res) => {
    meterIdentifyList.value = res.data
  })
}
fetchUseStatus()
// 监听设备名称下拉框，修改规格型号和辅助字段
watch(() => listQuery.equipmentName, (newVal) => {
  if (newVal) {
    listQuery.model = ''
    // 修改规格型号和辅助字段列表
    const data = allList.value.filter(item => item.equipmentName === newVal)
    modelList.value = Array.from(new Set(data.filter(item => item.model).map(item => item.model)))
  }
  else {
    listQuery.model = ''
    modelList.value = Array.from(new Set(allList.value.filter(item => item.model).map(item => item.model)))
  }
})
// 查询数据
const search = () => {
  fetchData(false)
}
// 证书有效期开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.certificateValidStart = ''
  listQuery.certificateValidEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.certificateValidStart = `${newVal[0]} 00:00:00`
      listQuery.certificateValidEnd = `${newVal[1]} 23:59:59`
    }
  }
})
const datetimerange1 = ref()
watch(() => datetimerange1.value, (newVal) => {
  listQuery.checkDateStart = ''
  listQuery.checkDateEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.checkDateStart = `${newVal[0]} 00:00:00`
      listQuery.checkDateEnd = `${newVal[1]} 23:59:59`
    }
  }
})
// 重置
const reset = () => {
  datetimerange.value = []
  datetimerange1.value = []
  listQuery.equipmentNo = ''
  listQuery.equipmentName = ''
  listQuery.usageStatus = ''
  listQuery.usePosition = ''
  listQuery.certificateValidEnd = ''
  listQuery.certificateValidStart = ''
  listQuery.model = ''
  listQuery.deptIds = ''
  listQuery.manufactureNo = ''
  listQuery.companyId = ''
  listQuery.directorName = ''
  listQuery.useSign = ''
  listQuery.installLocation = ''
  listQuery.checkOrganization = ''
  listQuery.checkDateStart = ''
  listQuery.checkDateEnd = ''
  listQuery.taskId = ''
  listQuery.meterIdentify = ''
  listQuery.sort = ''
  listQuery.orderBy = ''
  modelList.value = Array.from(new Set(allList.value.filter(item => item.model).map(item => item.model)))
  listQuery.offset = 1
  listQuery.limit = 20
  search()
}
// 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  // search()
  fetchData()
}
// 获取聚合表格数据
const togetherLoading = ref(true)
const togetherList = ref([])
const fetchTogetherData = () => {
  togetherLoading.value = true
  getInfoListTogether(listQuery).then((res) => {
    console.log('获取聚合表格数据')
    togetherList.value = res.data
    togetherLoading.value = false
  })
}
// 获取展开行内表格数据
const expandLoading = ref(true)
const expandList = ref([])
const fetchExpandData = (params: any) => {
  expandLoading.value = true
  getInfoList(params).then((res) => {
    expandList.value = res.data
    // 获取聚合表格选中，判断展开表格是否需要全选
    const selectList = togetherTableRef.value.getSelectionRows()
    if (selectList.length) {
      const select = selectList.filter((item: any) => item.equipmentName === params.equipmentName)
      if (select.length) {
        nextTick(() => {
          expandTableRef.value.toggleAllSelection()
        })
      }
    }
    expandLoading.value = false
  })
}
const getRowKeys = (row: any) => { // 获取当前行id
  return row.equipmentName // 这里看这一行中需要根据哪个属性值是id
}
// 监听聚合表格多选
// watch(() => togetherTableRef.value?.getSelectionRows(), (newVal, oldVal) => {
//   console.log(newVal, 'newVal')
// }, {
//   deep: true,
// })

// 表格被选中的行
const selectList = ref<any[]>([])
// 表格多选
const multiSelect = (row: any[]) => {
  selectList.value = row
}
// 控制展开行
const expands = ref()
const expandChange = (row: any, expandedRows: any) => {
  if (expandedRows.length) {
    expands.value = []
    if (row) {
      expands.value.push(row.equipmentName)
    }
  }
  else {
    expands.value = []
  }
}
watch(() => expands.value, (newVal) => {
  fetchExpandData({ equipmentName: newVal[0] })
},
{
  deep: true,
})
const togetherSelect = (selection: any, row: any) => {
  if (selection.includes(row)) {
    // 勾选
    console.log('勾选')
    if (expands.value && expands.value[0] === row.equipmentName) {
      expandTableRef.value.toggleAllSelection()
    }
  }
  else {
    // 取消勾选
    console.log('取消勾选')
    if (expands.value && expands.value[0] === row.equipmentName) {
      expandTableRef.value.toggleAllSelection()
    }
  }
}
const expandSelect = (selection: any, row: any) => {
  if (selection.length === expandList.value.length) {
    // 全选
    console.log('全选')
    // 获取聚合
    console.log(expands.value[0])
    const data = togetherList.value.filter((item: any) => item.equipmentName === expands.value[0])
    console.log(data)
    if (data.length) {
      nextTick(() => {
        togetherTableRef.value.toggleRowSelection(data[0], true)
      })
    }
  }
  else {
    // 全不选
    console.log('全不选')
    // 获取聚合
    const data = togetherList.value.filter((item: any) => item.equipmentName === expands.value[0])
    if (data.length) {
      nextTick(() => {
        togetherTableRef.value.toggleRowSelection(data[0], false)
      })
    }
  }
}
const $router = useRouter()
// 新建编辑操作
const handler = (row: IlistObjType, type: string) => {
  $router.push({
    path: `/${$props.equipmentType === '1' ? 'dinfo' : 'speciallist'}/${type}`,
    query: {
      row: JSON.stringify(row),
      id: row.id,
      statusName: $props.statusName,
      equipmentType: $props.equipmentType,
    },
  })
}
// 导出列表
const exportList = () => {
  if (list.value.length) {
    const loading = ElLoading.service({
      lock: true,
      text: 'Loading',
      background: 'rgba(255, 255, 255, 0.8)',
    })
    const data = {
      ...listQuery,
      offset: undefined,
      limit: undefined,
      ids: selectList.value.map(item => item.id),
    }
    exportDevice(data).then((res) => {
      exportFile(res.data, $props.equipmentType === '1' ? '设备信息' : '特种设备')
      loading.close()
    })
      .catch((_) => {
        loading.close()
      })
  }
  else {
    ElMessage.warning('无可导出内容')
  }
}
const fileRef = ref() // 文件上传input，获取input的引用
const onFileChange = (event: any) => {
  // 原生上传
  // console.log(event.target.files)
  if (event.target.files?.length !== 0) {
    // 创建formdata对象
    const fd = new FormData()
    fd.append('file', event.target.files[0])
    // fd.append('equipmentType', $props.equipmentType)
    const loading = ElLoading.service({
      lock: true,
      background: 'rgba(255, 255, 255, 0.8)',
    })
    importDevice(fd, $props.equipmentType).then((res) => {
      if (res.code === 200) {
        ElMessage.success('上传成功')
        fileRef.value.value = ''
        loading.close()
        fetchData(true)
      }
      else {
        // ElMessage.error(res.message)
        loading.close()
      }
    }).catch(() => {
      // ElMessage.error(err.message)
      loading.close()
    })
  }
}
// 导入
const importList = () => {
  fileRef.value.click()
}
// 绑定参试任务
const taskRef = ref()
const bindTask = () => {
  taskRef.value.initDialog()
}
// 确认绑定
const bindIds = (ids: string[]) => {
  console.log(ids, '参数任务ids')
  // bindTaskHandler()
  // 判断是 普通表格还是 聚合表格
  if (tableFlage.value) {
    // 普通表格
    const data = {
      equipmentIds: selectList.value.map(item => item.id),
      taskIds: ids,
    }
    bindTaskHandler(data).then((res) => {
      ElMessage.success('绑定成功')
      fetchData()
    })
  }
  else {
    const data = {
      equipmentNames: togetherTableRef.value.getSelectionRows().map((item: any) => item.equipmentName),
      equipmentIds: expandTableRef.value.getSelectionRows().map((item: any) => item.id),
      taskIds: ids,
    }
    bindTaskHandler(data).then((res) => {
      ElMessage.success('绑定成功')
      fetchTogetherData()
    })
  }
}
// 详情
const detail = (row: IlistObjType) => {
  if ($props.statusName === '草稿箱' || $props.statusName === '未通过' || $props.statusName === '已取消') {
    handler(row, 'update')
  }
  else {
    $router.push({
      path: `/${$props.equipmentType === '1' ? 'info' : 'speciallist'}/detail`,
      query: {
        row: JSON.stringify(row),
        id: row.id,
        statusName: $props.statusName,
        equipmentType: $props.equipmentType,
      },
    })
  }
}
// 删除
const valiate = (val: string | any) => {
  if (val) {
    return true
  }
  else {
    return false
  }
}
// 删除
const delHandler = (row: IlistObjType) => {
  if ($props.statusName === '全部') {
    // 删除设备
    ElMessageBox.prompt('请填写删除原因', '确认删除', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      inputValidator: valiate,
      inputErrorMessage: '请输入原因',
    })
      .then(({ value }) => {
        console.log(row, 'row')
        editInfo({
          approvalType: '3',
          equipmentId: row.id,
          id: null,
        }).then((res) => {
          // ElMessage.success('操作成功')
          // search()
          submitInfo({ id: res.data, formId: SCHEDULE.DEVICE_INFO_APPROVAL, reason: value, processId: row.processId }).then((res) => {
            ElMessage.success('操作成功')
            search()
          })
        })
        // ElMessage({
        //   type: 'success',
        //   message: `Your email is:${value}`,
        // })
      })
  }
  else {
    ElMessageBox.confirm(
      '确认删除此记录吗?',
      '确认',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    ).then(() => {
    // 分删除设备和删除记录
      deleteInfo({ id: row.id }).then((res) => {
        ElMessage.success('操作成功')
        // close()
        search()
      })
    })
  }
}
// 取消
const canHandler = (row: IlistObjType) => {
  ElMessageBox.confirm(
    '确认取消此申请吗?',
    '确认',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    cancelInfo({ id: row.id, processInstanceId: row.processId, comments: '' }).then((res) => {
      ElMessage.success('操作成功')
      // close()
      search()
    })
  })
}
// 提交
const submit = (row: any) => {
  ElMessageBox.confirm(
    '确认提交吗？',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then((res) => {
    submitInfo({ id: row.id, formId: SCHEDULE.DEVICE_INFO_APPROVAL }).then((res) => {
      ElMessage.success('已提交')
      search()
    })
  })
}
// 同意拒绝
const approvalDialogRef = ref()
const approveHandler = (row: any, type: string) => {
  approvalDialogRef.value.initDialog(type, row.taskId, row.processId, row.id)
}

const changeTable = () => {
  tableFlage.value = !tableFlage.value
  if (tableFlage.value) {
    //  获取普通表格数据
    fetchData()
  }
  else {
    // 获取聚合表格数据
    fetchTogetherData()
  }
}
// 审批状态发生变化
watch(() => $props.statusName, (newVal) => {
  if (newVal) {
    listQuery.approvalStatus = applyDict.value[newVal] as string
    fetchData()
    tableFlage.value = true
  }
},
{
  deep: true,
  immediate: true,
})
const permUrl = ref({
  edit: '/tested/device/info/edit',
  del: '/tested/device/info/delete',
  submit: '/tested/device/info/submit',
  cancel: '/tested/device/info/cancel',
  agree: '/tested/device/info/agree',
  reject: '/tested/device/info/reject',
})
</script>

<template>
  <app-container>
    <!-- 审批弹窗 -->
    <approval-dialog ref="approvalDialogRef" @on-success="search" />
    <!-- 参试任务弹窗 -->
    <task ref="taskRef" @confirm="bindIds" />
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-input v-model.trim="listQuery.equipmentNo" placeholder="统一编号" clearable />
      </search-item>
      <search-item>
        <el-select v-model.trim="listQuery.equipmentName" filterable placeholder="设备名称" clearable>
          <el-option v-for="(item, index) in deviceNameList" :key="index" :label="item" :value="item" />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model.trim="listQuery.model" filterable placeholder="规格型号" clearable>
          <el-option v-for="item in modelList" :key="item" :label="item" :value="item" />
        </el-select>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.usageStatus" placeholder="使用状态" clearable>
          <el-option v-for="item in useStatusList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <dept-select v-model="listQuery.companyId" placeholder="所在单位" />
      </search-item>
      <search-item>
        <dept-select v-model="listQuery.deptIds" placeholder="使用部门" />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.usePosition" placeholder="使用岗位" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.directorName" placeholder="负责人" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.useSign" placeholder="在用信息" clearable>
          <el-option v-for="item in useSignList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.installLocation" placeholder="安装位置" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.taskId" placeholder="参试任务" clearable>
          <el-option v-for="item in taskList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD"
          format="YYYY-MM-DD" range-separator="至" start-placeholder="证书有效期开始时间" end-placeholder="证书有效期结束时间"
        />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.checkOrganization" placeholder="检定(校准)机构" clearable />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="datetimerange1" type="daterange" value-format="YYYY-MM-DD"
          format="YYYY-MM-DD" range-separator="至" start-placeholder="检定(校准)开始时间" end-placeholder="检定(校准)结束时间"
        />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.meterIdentify" placeholder="计量标识" clearable>
          <el-option v-for="item in meterIdentifyList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
    </search-area>
    <table-container>
      <template v-if="$props.statusName === '全部'" #btns-right>
        <icon-button icon="icon-change" title="切换列表状态" @click="changeTable" />
        <icon-button icon="icon-sweep" title="扫描" />
        <icon-button icon="icon-add" title="新增" @click="handler({} as any, 'create')" />
        <icon-button icon="icon-import" title="批量导入" @click="importList" />
        <icon-button icon="icon-template" title="模板下载" @click="useTemplateDownload('设备信息管理模块')" />
        <icon-button icon="icon-export" title="导出" @click="exportList" />
        <icon-button icon="icon-task" title="参试任务" @click="bindTask" />
        <input ref="fileRef" style="display: none;" type="file" accept=".xls,.xlsx" @change="onFileChange">
      </template>
      <div v-if=" tableFlage ">
        <!-- 普通表格 -->
        <normal-table
          v-show=" tableFlage "
          ref="normalTableRef" :data="list" :total="total" :columns="columns" :query="listQuery"
          :list-loading="listLoading"
          :is-showmulti-select="true" :is-multi="true" @sort-change="sortChange" @change="changePage" @multi-select="multiSelect"
        >
          <template #columns>
            <!-- 全部状态 -->
            <template v-if="$props.statusName === '全部' ">
              <el-table-column
                v-for=" column of allColums " :key=" column.value "
                :label=" column.text " :prop=" column.value " :align=" column.align "
                :show-overflow-tooltip="true"
                :sortable="column.sortable"
              />
            </template>
            <!-- 其他审批状态 -->
            <template v-if="$props.statusName !== '全部' ">
              <el-table-column
                v-for=" column of otherColums " :key="column.value"
                :label=" column.text "
                :prop=" column.value " :align=" column.align "
                :show-overflow-tooltip="true"
              />
            </template>

            <el-table-column label="操作" width="160" align="center">
              <template #default=" scope ">
                <el-button link type="primary" size="small" @click="detail(scope.row)">
                  查看
                </el-button>
                <el-button
                  v-if="proxy.buttonPerm.edit.if({ approvalStatusName: $props.statusName }, permUrl.edit)" link type="primary" size="small"
                  @click="handler(scope.row, 'update')"
                >
                  编辑
                </el-button>
                <el-button
                  v-if="proxy.buttonPerm.agree.if({ approvalStatusName: $props.statusName }, permUrl.agree)" link type="primary" size="small"
                  @click="approveHandler(scope.row, 'agree')"
                >
                  同意
                </el-button>
                <el-button
                  v-if="proxy.buttonPerm.reject.if({ approvalStatusName: $props.statusName }, permUrl.reject)" link type="primary" size="small"
                  @click="approveHandler(scope.row, 'refuse')"
                >
                  拒绝
                </el-button>
                <el-button
                  v-if="proxy.buttonPerm.submit.if({ approvalStatusName: $props.statusName }, permUrl.submit)" link type="primary" size="small"
                  @click="submit(scope.row)"
                >
                  提交
                </el-button>
                <el-button
                  v-if="proxy.buttonPerm.cancel.if({ approvalStatusName: $props.statusName }, permUrl.cancel)" link type="primary" size="small"
                  @click="canHandler(scope.row)"
                >
                  取消
                </el-button>
                <el-button
                  v-if="proxy.buttonPerm.delete.if({ approvalStatusName: $props.statusName }, permUrl.del)" link type="danger" size="small"
                  @click="delHandler(scope.row)"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </template>
        </normal-table>
      </div>
      <div v-if=" !tableFlage ">
        <!-- 展开行表格 -->
        <!-- 头部 -->
        <normal-table
          v-show=" !tableFlage " class="nortable-header" :data=" [] " :total=" 0 " :columns=" columns.map(item => ({ ...item, sortable: undefined })) " :options="
            {
              needIndex: false, // 是否需要序号列
              border: true, // 是否需要上方边框
            }
          " :pagination=" false " :is-showmulti-select=" true " :query="{}"
        >
          <template #columns>
            <el-table-column label="操作" width="160" align="center" />
          </template>
        </normal-table>
        <!-- 身体 -->
        <el-table
          v-show=" !tableFlage "
          ref="togetherTableRef" v-loading=" togetherLoading " :data=" togetherList " border style="width: 100%;"
          :row-key=" getRowKeys " :expand-row-keys=" expands " :show-header=" false " @expand-change=" expandChange "
          @select="togetherSelect"
        >
          <el-table-column type="selection" width="38" />
          <el-table-column type="expand">
            <template #default>
              <!-- 展开表格身体 -->
              <!-- <normal-table
            <template #default>
              <normal-table
                :data=" expandList " :total=" 0 " :columns=" columns " :list-loading=" expandLoading " :options="
                  {
                    needIndex: false, // 是否需要序号列
                    border: true, // 是否需要上方边框
                  }
                " :pagination=" false " :is-showmulti-select=" true " :show-header=" false " :query="{}"
              /> -->
              <el-table
                ref="expandTableRef"
                v-loading=" expandLoading " :data=" expandList " border style="width: 100%;"
                :show-header=" false " @select="expandSelect"
              >
                <el-table-column type="selection" width="38" />
                <el-table-column v-for="item in columns" :key="item.value" :labe="item.text" :prop="item.value" align="center" />
                <el-table-column label="操作" width="160" align="center">
                  <template #default=" scope ">
                    <el-button link type="primary" size="small" @click="detail(scope.row)">
                      查看
                    </el-button>
                    <el-button
                      v-if="proxy.buttonPerm.edit.if({ approvalStatusName: $props.statusName }, permUrl.edit)" link type="primary" size="small"
                      @click="handler(scope.row, 'update')"
                    >
                      编辑
                    </el-button>
                    <el-button
                      v-if="proxy.buttonPerm.agree.if({ approvalStatusName: $props.statusName }, permUrl.agree)" link type="primary" size="small"
                      @click="approveHandler(scope.row, 'agree')"
                    >
                      同意
                    </el-button>
                    <el-button
                      v-if="proxy.buttonPerm.reject.if({ approvalStatusName: $props.statusName }, permUrl.reject)" link type="primary" size="small"
                      @click="approveHandler(scope.row, 'refuse')"
                    >
                      拒绝
                    </el-button>
                    <el-button
                      v-if="proxy.buttonPerm.submit.if({ approvalStatusName: $props.statusName }, permUrl.submit)" link type="primary" size="small"
                      @click="submit(scope.row)"
                    >
                      提交
                    </el-button>
                    <el-button
                      v-if="proxy.buttonPerm.cancel.if({ approvalStatusName: $props.statusName }, permUrl.cancel)" link type="primary" size="small"
                      @click="canHandler(scope.row)"
                    >
                      取消
                    </el-button>
                    <el-button
                      v-if="proxy.buttonPerm.delete.if({ approvalStatusName: $props.statusName }, permUrl.del)" link type="danger" size="small"
                      @click="delHandler(scope.row)"
                    >
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column label="设备名称" prop="equipmentName" align="center" />
          <el-table-column label="数量" align="center">
            <template #default=" scope ">
              共计{{ scope.row.count }}台
            </template>
          </el-table-column>
        </el-table>
      </div>
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
.nortable-header {
  ::v-deep(.el-table__body-wrapper) {
    display: none;
  }
}
</style>

