Newer
Older
xc-business-system / src / views / equipement / standard / book / components / config / fifth / templateTable.vue
<script lang="ts" setup name="ThirdTemplateTable">
import type { Ref } from 'vue'
import { ElTable } from 'element-plus'
import { defineExpose, ref } from 'vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { clickAdd, clickSub } from '@/views/business/measure/item/useCalculateResolution'
import SelectByDict from '@/components/SelectByDict/index.vue'
// ------------------定义props、 emit-------------------
const props = defineProps({
  pageType: {
    type: String,
    default: 'detail',
  },
  // 数据
  data: {
    type: Array,
    default() {
      return []
    },
  },
  // 表格高度
  height: {
    type: Number,
    default() {
      return null
    },
  },
  // 数据列配置
  columns: {
    type: Array<TableColumn>,
    default() {
      return []
    },
  },
  // 表格大小
  size: {
    type: String,
    default: 'default',
  }, // 表格大小,默认,small,mini等,与el-table条件相同
  title: {
    type: String,
  },
  tableType: {
    type: String,
  },
})
const emit = defineEmits(['change', 'selectionChange', 'rowClick', 'rowDbClick', 'multiSelect', 'filterChange'])
// ------------------------------------------字典----------------------------------------------
const checkTypeList = ref<dictType[]>([]) // 核查类型
const resistanceUnitList = ref<dictType[]>([]) // 核查类型

/**
 * 获取字典
 */
function getDict() {
  // 核查类型
  getDictByCode('bizFirstStandardCheckType').then((response) => {
    checkTypeList.value = response.data
  })
  // 电阻单位--用于测温仪电阻核查
  getDictByCode('standardResistance').then((response) => {
    resistanceUnitList.value = response.data
  })
}

getDict()
// -------定义数据--------------
interface columnsCheckInfo {
  text: string
  show: boolean
}
const columnsChecked: Ref<columnsCheckInfo[]> = ref([])
const table = ref<InstanceType<typeof ElTable>>()
const singleChecked = ref('') // 单选选中id
// 初始化列显示状态
function initColumnsState() {
  columnsChecked.value = []
  for (const column of props.columns) {
    columnsChecked.value.push({ text: column.text, show: !!column.show })
  }
}

// 最终展示列
const columnsFiltered: Ref<TableColumn[]> = ref([])
// 切换列
function changeColumns() {
  columnsFiltered.value = []
  for (const i in props.columns) {
    if (columnsChecked.value[i].show === true) {
      columnsFiltered.value.push(props.columns[i])
    }
  }
}
// 刷新
function refresh() {
  emit('change')
}

// 多选选中结果
function selectionChange(selection: []) {
  emit('selectionChange', selection)
}
// 点击行
function rowClick(row: object, column?: any, event?: any) {
  emit('rowClick', row)
}
// 双击行
function rowDbClick(row: object, column?: any, event?: any) {
  emit('rowDbClick', row)
}
// 监听columns
watch(props.columns, (val) => {
  initColumnsState()
  changeColumns()
})
// 多选
const handleSelectionChange = (val: any) => {
  emit('selectionChange', val)
}
// 清除多选选中
const clearMulti = () => {
  console.log('清理选中')
  table.value!.clearSelection()
  singleChecked.value = ''
}
defineExpose({
  clearMulti, initColumnsState,
})
onBeforeMount(() => {
  initColumnsState()
  changeColumns()
})
</script>

<template>
  <el-table
    id="print"
    ref="table"
    :data="data"
    :height="height"
    border
    stripe
    :size="size"
    style="width: 100%;"
    @selection-change="handleSelectionChange"
    @row-click="rowClick"
    @row-dblclick="rowDbClick"
  >
    <el-table-column v-if="pageType !== 'detail'" type="selection" width="38" />
    <el-table-column align="center" label="序号" width="80" type="index" />
    <el-table-column
      v-for="item in columns"
      :key="item.value"
      :prop="item.value"
      :label="item.text"
      :width="item.width"
      align="center"
    >
      <template #header>
        <span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span>
      </template>
      <template #default="scope">
        <!-- 循环次数 -->
        <el-input-number
          v-if="item.value === 'cycleNumber' && pageType !== 'detail'"
          v-model="scope.row[item.value]"
          :placeholder="`${item.text}`"
          :step="1"
          :precision="0"
          disabled
          class="full-width-input"
        />
        <!-- 测量标准相对扩展不确定度Urel -->
        <!-- <el-input-number
          v-if="props.pageType !== 'detail' && item.value === 'urel'"
          v-model="scope.row[item.value]"
          clearable
          placeholder="Urel"
          class="full-width-input"
        /> -->
        <!-- 核查类型 -->
        <el-select v-if="props.pageType !== 'detail' && item.value === 'checkType'" v-model="scope.row[item.value]" disabled clearable multiple placeholder="请选择">
          <el-option
            v-for="item in checkTypeList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
        <!-- 温度值--温度点 -->
        <select-by-dict
          v-if="props.tableType === '温度值' && props.pageType !== 'detail' && item.value === 'checkPoint'"
          v-model:model-value="scope.row[item.value]"
          placeholder="温度点"
          dict-code="standard5TemperatureSpots"
        />
        <!-- 温度值--扩展不确定度Urel -->
        <select-by-dict
          v-if="props.tableType === '温度值' && props.pageType !== 'detail' && item.value === 'urel'"
          v-model:model-value="scope.row[item.value]"
          placeholder="urel"
          dict-code="standard5Urel"
        />
        <!-- RTP值--水相三点 -->
        <select-by-dict
          v-if="props.tableType === 'RTP值' && props.pageType !== 'detail' && item.value === 'checkPoint'"
          v-model:model-value="scope.row[item.value]"
          placeholder="水相三点"
          dict-code="standard5Water"
        />
        <!-- RTP值--允许值 -->
        <select-by-dict
          v-if="props.tableType === 'RTP值' && props.pageType !== 'detail' && item.value === 'allowValue'"
          v-model:model-value="scope.row[item.value]"
          placeholder="允许值"
          dict-code="standard5AllowableValue"
        />
        <!-- 绝缘电阻表校准--确认点 -->
        <select-by-dict
          v-if="props.tableType === '绝缘电阻表校准' && props.pageType !== 'detail' && item.value === 'checkPoint'"
          v-model:model-value="scope.row[item.value]"
          placeholder="确认点"
          dict-code="standard5AffirmPoint"
        />
        <!-- 绝缘电阻表校准--最大允许误差 -->
        <select-by-dict
          v-if="props.tableType === '绝缘电阻表校准' && props.pageType !== 'detail' && item.value === 'maximumError'"
          v-model:model-value="scope.row[item.value]"
          placeholder="最大允许误差"
          dict-code="standard5MaximumErrors"
        />

        <!-- 测温仪电阻核查-确认点、最大允许误差绝对值|MPE| -->
        <el-input-number
          v-if="props.tableType === '测温仪电阻核查' && props.pageType !== 'detail' && (item.value === 'maximumError' || item.value === 'checkPoint')"
          v-model="scope.row[item.value]"
          clearable
          :placeholder="item.text"
          class="full-width-input"
        />
        <!-- 单位 -->
        <el-select v-if="props.tableType === '测温仪电阻核查' && props.pageType !== 'detail' && item.value === 'unit'" v-model="scope.row[item.value]" :disabled="props.pageType === 'detail'" clearable placeholder="请选择">
          <el-option
            v-for="item in resistanceUnitList"
            :key="item.value"
            :label="item.name"
            :value="item.name"
          />
        </el-select>
      </template>
    </el-table-column>
  </el-table>
</template>

<style lang="scss" scoped>
.single-table {
  width: 100%;

  :deep(.el-table th.el-table__cell:nth-child(1) .cell) {
    visibility: hidden;
  }
}
</style>

<style lang="scss">
.normal-table {
  .el-radio__label {
    display: none !important;
  }
}
</style>