Newer
Older
xc-business-system / src / views / equipement / standard / book / components / config / eleventh / config.vue
dutingting on 2 Dec 16 KB 临时提交
<!-- 标准装置台账信息详情 配置核查项 微波衰减标准装置 -->
<script name="StandardBookEquipmentConfig" lang="ts" setup>
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IList } from './eleventh-interface'
import TemplateTable from './templateTable.vue'
import type { dictType } from '@/global'
import { useCheckList } from '@/commonMethods/useCheckList'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { config, getCheckItemDetail } from '@/api/equipment/standard/book'
import { calc } from '@/utils/useCalc'
import { getDictByCode } from '@/api/system/dict'
import { differenceArray, setSelectList } from '@/utils/Array'
import templateTable1 from '@/views/business/measure/item/components/second/templateTable.vue'

const textMap: { [key: string]: string } = {
  edit: '编辑',
  detail: '详情',
}// 页面类型字典
const form = ref({ // 表单
  equipmentNo: '', // 统一编号
  equipmentName: '', // 设备名称
  model: '', // 规格型号
  manufactureNo: '', // 出厂编号
  measureRange: '', // 测量范围
  uncertainty: '', // 不确定度或允许误差极限或准确度等级
  itemCategoryName: '', // 核查项分类名称
  itemCategoryId: '', // 核查项分类id
  remark: '', // 核查项备注
  belongStandardEquipment: '', // 检校标准装置
  belongStandardEquipmentName: '', // 检校标准装置名称
})
const pageType = ref('detail') // 页面类型: add, edit, detail
const infoId = ref('') // id
const $router = useRouter() // 路由实例
const loading = ref(false) // loading
const equipmentId = ref('') // 设备id
// -----------------------------------路由参数------------------------------------------------------
// 从路由中获取页面类型参数
const $route = useRoute()
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string
  if ($route.params.id) {
    infoId.value = $route.params.id as string
  }
}
// -------------------------------------------核查项-----------------------------------------------
const listAttenuationAmount = ref<IList[]>([]) // 衰减量

const form1 = ref({
  attenuationAmount: 1, // 是否衰减量
})
const listDict = ref<{ [key: string]: any }>()
watch(() => [listAttenuationAmount.value], () => {
  listDict.value = {
    '1-衰减量': listAttenuationAmount.value,
  }
}, {
  deep: true,
  immediate: true,
})
// 表格对应的 选择状态
let chekedDict = {
  '1-衰减量': form1.value.attenuationAmount,
} as { [key: string]: any }
watch(() => form1.value, () => {
  chekedDict = {
    '1-衰减量': form1.value.attenuationAmount,
  }
}, {
  deep: true,
  // immediate: true,
})
const columns_attenuation_amount = ref<TableColumn[]>([ // 衰减量表头
  { text: '核查项目', value: 'paramsName', align: 'center', required: false, type: 'text' },
  { text: '档位类型', value: 'gearType', align: 'center', required: true, type: 'select' },
  { text: '频率点', value: 'frequency', align: 'center', required: true, type: 'select-dict', code: 'eleventhFrequencyValue' },
  { text: '频率点单位', value: 'frequencyUnit', align: 'center', required: true, type: 'select' },
  { text: '衰减量', value: 'attenuationAmount', align: 'center', required: true, type: 'number' },
  { text: '衰减量单位', value: 'attenuationAmountUnit', align: 'center', required: true, type: 'select' },
  { text: '组合方式', value: 'composition', align: 'center', required: true, type: 'select' },
  { text: '幅度', value: 'amplitude', align: 'center', required: true, type: 'number' },
  { text: '幅度单位', value: 'amplitudeUnit', align: 'center', required: true, type: 'select' },
  { text: 'U(k=2)', value: 'urel', align: 'center', required: true, type: 'number' },
  { text: '循环次数', value: 'cycleNumber', align: 'center', required: true, type: 'number' },
  { text: '核查类型', value: 'checkType', align: 'center', required: false, type: 'select-multi' },
])

// 表格对应 columns字典
const columnsDict = ref<{ [key: string]: any }>(
  {
    '1-衰减量': columns_attenuation_amount.value,
  },
)
/**
 * 增加行公共方法
 * @param list 要操作的数组
 * @param title 操作的表格
 */
const addRow = (list: IList[], title: string, index: string, item: any) => {
  if (checkList(list, columnsDict.value[`${index}-${title}`], `${title}表格`)) {
    switch (title) {
      case '衰减量':
        if (item) {
          listAttenuationAmount.value.push({ ...JSON.parse(JSON.stringify({ ...item, id: `custom-${new Date().getTime()}` })), paramsName: '衰减量' })
        }
        else {
          listAttenuationAmount.value.length
            ? listAttenuationAmount.value.push(JSON.parse(JSON.stringify({ ...listAttenuationAmount.value[listAttenuationAmount.value.length - 1], id: `custom-${new Date().getTime()}` })))
            : listAttenuationAmount.value.push({
              paramsName: '衰减量',
              checkType: ['重复性', '稳定性'], // 核查类型
              params: '1',
              cycleNumber: '10',
              gearType: '',
              frequency: '',
              frequencyUnit: '',
              attenuationAmount: '',
              attenuationAmountUnit: '',
              composition: '',
              amplitude: '',
              amplitudeUnit: '',
              urel: '',
              id: `custom-${new Date().getTime()}`,
            } as any)
        }

        break
    }
  }
}
/**
 * 删除行公共方法
 * @param checkoutList 选中的数组
 * @param list 操作的数组
 */
const delRow = (checkoutList: IList[], list: IList[], title: string) => {
  if (!checkoutList.length) {
    ElMessage.warning('请选中要删除的行')
  }
  else {
    let data = [] as any[]
    data = differenceArray(list, checkoutList)
    switch (title) {
      case '衰减量':
        listAttenuationAmount.value = data
        break
    }
  }
}
// ---------------------------------------------校验---------------------------------------------------
// 校验表格(点击保存的时候用、生成标准器示值)
function checkList(list: any[], columns: any[], title: string) {
  return useCheckList(list, columns, title)
}
// 校验所有表格
function checkAllList() {
  let result = true
  for (const i in columnsDict.value) {
    const requireLength = !!((chekedDict[i] === '1' || chekedDict[i] === 1) && chekedDict[i])
    if (!useCheckList(listDict.value[i], columnsDict.value[i], i.substring(2), '', '', '', requireLength)) {
      result = false
      break
    }
  }
  console.log(result, 'result')
  return result
}

// -----------------------------------------------------------------------------------------------------
const clearAllList = () => {
  listAttenuationAmount.value = []
  form.value.remark = '' // 核查项备注清空
  form1.value.attenuationAmount = 1
}
const getList = () => {
  let result = [] as any[]
  for (const i in chekedDict) {
    if ((chekedDict[i] === '1' || chekedDict[i] === 1) && chekedDict[i]) {
      const data = listDict.value[i]
      result = [...result, ...data]
    }
  }
  return result
}
// ---------------------------------------按钮-----------------------------------------------------
// 点击关闭
const close = () => {
  $router.back()
}
// 清空配置
const clear = () => {
  ElMessageBox.confirm(
    '确认清空配置项吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  )
    .then(() => {
      clearAllList()
    })
}

// 点击保存
const save = () => {
  if (!getList().length) { ElMessage.warning('核查项不能为空'); return false }
  if (!checkAllList()) { return }
  const params = {
    itemCategoryId: form.value.itemCategoryId, // 核查项分类id
    checkItemDataMicrowaveAttenuationList: getList().map((item: any) => ({ ...item, params: '衰减量', equipmentId: equipmentId.value, id: '', remark: form.value.remark })),
    equipmentId: equipmentId.value,
    standardId: $route.query.standardId,
  }
  const loading = ElLoading.service({
    lock: true,
    text: '加载中',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  config(params).then((res) => {
    ElMessage.success('已保存')
    pageType.value = 'detail'
    loading.close()
  }).catch(() => {
    loading.close()
  })
}

// 获取详情
const getInfo = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  const params = {
    equipmentId: equipmentId.value, // 设备id
    belongStandardEquipment: form.value.belongStandardEquipment, // 检校标准装置code
    itemCategoryId: form.value.itemCategoryId, // 核查项分类id
    itemCategoryName: form.value.itemCategoryName, // 核查项分类名称
  }
  getCheckItemDetail(params).then((res) => {
    const data = res.data?.checkItemDataMicrowaveAttenuationList || []
    const dict = {
      1: '衰减量',
    }
    data.forEach((item: any) => {
      addRow([], item.params, '1', { ...item, checkType: ['重复性', '稳定性'] })
      form.value.remark = item.remark
    })

    form1.value.attenuationAmount = !res.data ? 1 : listAttenuationAmount.value.length ? 1 : 0
    loading.close()
  })
}

// ------------------------------------------钩子--------------------------------------------------

onMounted(() => {
  form.value.equipmentNo = $route.query.equipmentNo as string // 统一编号
  form.value.equipmentName = $route.query.equipmentName as string // 设备名称
  form.value.model = $route.query.model as string // 规格型号
  form.value.manufactureNo = $route.query.manufactureNo as string // 出厂编号
  form.value.measureRange = $route.query.measureRange as string // 测量范围
  form.value.uncertainty = $route.query.uncertainty as string // 不确定度或允许误差极限或准确度等级
  form.value.itemCategoryName = $route.query.itemCategoryName as string // 核查项分类名称
  form.value.itemCategoryId = $route.query.itemCategoryId as string // 核查项分类id
  form.value.belongStandardEquipment = $route.query.belongStandardEquipment as string // 核查项标准装置id
  form.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string // 核查项标准装置id
  equipmentId.value = $route.query.equipmentId as string // 设备id
  getInfo()
})

// 表格下拉框等内容是否禁用
const disabled = ({ scope, column }, fun: any) => {
  if (column.text === '核查类型' || column.text === '循环次数') {
    fun(true)
    return
  }
  fun(pageType.value === 'detail')
}
// 每个table对应的下拉框内容 字典
const tableDict = ref<{ [key: string]: { value: string;name: string;id: string }[] }>({})
const changeLoadSituationa = (value: any, index: number, text: string, type: string, list: any[], item: string) => {
  // if (item === '频率显示') {
  //   if (text === '标称值') {
  //     list[index].frequency = value
  //   }
  //   if (text === '标称值单位') {
  //     list[index].frequencyUnit = typeof value === 'string' ? value : ''
  //   }
  // }
}
// 获取字典
const checkTypeList = ref<{ value: string;name: string;id: string }[]>([]) // 核查类型
const frequencyUnitList = ref<{ value: string;name: string;id: string }[]>([]) // 频率
const amplitudeUnitList = ref<{ value: string;name: string;id: string }[]>([]) // 幅度
const levelComposition = ref<{ value: string;name: string;id: string }[]>([]) // 组合方式
const GearType = ref<{ value: string;name: string;id: string }[]>([]) // 组合方式
const fetchDict = async () => {
  // 核查类型
  const res1 = await getDictByCode('bizFirstStandardCheckType')
  checkTypeList.value = res1.data
  // 频率
  const res2 = await getDictByCode('standardFrequencyUnit')
  frequencyUnitList.value = res2.data
  // 幅度
  const res3 = await getDictByCode('standardAmplitudeUnit')
  amplitudeUnitList.value = res3.data
  const res4 = await getDictByCode('levelComposition')
  levelComposition.value = res4.data

  const res5 = await getDictByCode('eleventhGearType')
  GearType.value = res5.data

  // 组合方式
  // table字典
  tableDict.value = {
    核查类型: checkTypeList.value,
    频率点单位: frequencyUnitList.value,
    幅度单位: amplitudeUnitList.value,
    衰减量单位: amplitudeUnitList.value,
    组合方式: levelComposition.value,
    档位类型: GearType.value,
  }
}
fetchDict()
</script>

<template>
  <app-container>
    <detail-page v-loading="loading" :title="`配置核查项(${textMap[pageType]})`">
      <template #btns>
        <el-button v-if="pageType === 'edit'" type="warning" @click="clear">
          清空配置
        </el-button>
        <el-button v-if="pageType === 'edit'" type="primary" @click="save">
          保存
        </el-button>
        <el-button type="info" @click="close">
          关闭
        </el-button>
      </template>
      <el-form
        ref="ruleFormRef"
        :model="form"
        :label-width="130"
        label-position="right"
      >
        <el-row :gutter="24" class="marg">
          <el-col :span="6">
            <el-form-item label="统一编号:" prop="equipmentNo">
              <el-input
                v-model="form.equipmentNo"
                disabled
                :placeholder="pageType === 'detail' ? '' : '统一编号'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="设备名称:" prop="equipmentName">
              <el-input
                v-model="form.equipmentName"
                disabled
                :placeholder="pageType === 'detail' ? '' : '设备名称'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="规格型号:" prop="model">
              <el-input
                v-model="form.model"
                disabled
                :placeholder="pageType === 'detail' ? '' : '规格型号'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出厂编号:" prop="manufactureNo">
              <el-input
                v-model="form.manufactureNo"
                disabled
                :placeholder="pageType === 'detail' ? '' : '出厂编号'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="测量范围:" prop="measureRange">
              <el-input
                v-model="form.measureRange"
                disabled
                type="textarea"
                autosize
                :placeholder="pageType === 'detail' ? '' : '测量范围'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="260" label="不确定度或允许误差极限或准确度等级:" prop="uncertainty">
              <el-input
                v-model="form.uncertainty"
                type="textarea"
                autosize
                disabled
                :placeholder="pageType === 'detail' ? '' : '不确定度或允许误差极限或准确度等级'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核查项分类名称:" prop="itemCategoryName">
              <el-input
                v-model="form.itemCategoryName"
                disabled
                :placeholder="pageType === 'detail' ? '' : '核查项分类名称'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </detail-page>

    <!-- 衰减量 -->
    <template-table1
      :show="Boolean(form1.attenuationAmount)"
      :data="listAttenuationAmount" :columns="columns_attenuation_amount" :page-type="pageType" title="衰减量" index="1" :show-btn="pageType !== 'detail'"
      :select-all-list="tableDict"
      @disabled="disabled"
      @add-row="addRow"
      @del-row="delRow"
      @change-load-situationa="changeLoadSituationa"
    >
      <template #custom-check>
        <el-checkbox v-model="form1.attenuationAmount" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
          衰减量
        </el-checkbox>
      </template>
    </template-table1>

    <!-- 核查项备注 -->
    <el-form
      :model="form"
      label-width="120"
      label-position="right"
      style="margin-top: 20px;"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="核查项备注:" prop="remark">
            <el-input
              v-model="form.remark"
              class="full-width-input"
              autosize
              type="textarea"
              :disabled="pageType === 'detail'"
              :placeholder="pageType === 'detail' ? ' ' : '请输入核查项备注'"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </app-container>
</template>