| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145 |
- <template>
- <el-row :gutter="20">
- <!-- 左侧部门树 -->
- <DeptTree @node-click="handleDeptNodeClick" v-model:collapsed="isLeftContentCollapsed" />
- <el-col :xs="24" :span="isLeftContentCollapsed ? 24 : 20">
- <ContentWrap style="border: none">
- <!-- 搜索工作栏 -->
- <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">
- <el-form-item label="计量器具名称" prop="measureName">
- <el-input
- v-model="queryParams.measureName"
- placeholder="请输入计量器具名称"
- clearable
- @keyup.enter="handleQuery"
- class="!w-150px" />
- </el-form-item>
- <el-form-item label="是否过期" prop="expired">
- <el-select
- v-model="queryParams.expired"
- placeholder="请选择是否过期"
- clearable
- style="width: 120px">
- <el-option
- v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value" />
- </el-select>
- </el-form-item>
- <el-form-item label="是否预警" prop="alertWarn">
- <el-select
- v-model="queryParams.alertWarn"
- placeholder="请选择是否预警"
- clearable
- style="width: 120px">
- <el-option
- v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value" />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button @click="handleAdd" type="primary"
- ><Icon icon="ep:plus" class="mr-5px" />新增</el-button
- >
- <el-button @click="handleQuery"
- ><Icon icon="ep:search" class="mr-5px" /> {{ t('devicePerson.search') }}</el-button
- >
- <el-button @click="resetQuery"
- ><Icon icon="ep:refresh" class="mr-5px" /> {{ t('devicePerson.reset') }}</el-button
- >
- <el-button @click="handleExport" type="success" plain :loading="exportLoading"
- ><Icon icon="ep:download" class="mr-5px" /> 导出</el-button
- >
- </el-form-item>
- </el-form>
- </ContentWrap>
- <!-- 列表 -->
- <ContentWrap class="flex-1 overflow-hidden mt-15px" style="border: none">
- <div class="stats-cards">
- <div class="stats-card stats-card--expired">
- <div class="stats-card__header">
- <el-icon class="stats-card__icon" :size="28">
- <Icon icon="ep:info-filled" />
- </el-icon>
- <div class="stats-card__label">已过期</div>
- </div>
- <div class="stats-card__value text-[40px]! pt-10 text-center!">
- <CountTo
- :duration="2600"
- :end-val="expired"
- :start-val="0"
- class="stats-card__value text-[40px]! pt-10 text-center! text-[#e35656]!"
- /></div>
- </div>
- <div class="stats-card stats-card--warn">
- <div class="stats-card__header">
- <el-icon class="stats-card__icon" :size="28">
- <Icon icon="ep:bell-filled" />
- </el-icon>
- <div class="stats-card__label">90天预警</div>
- </div>
- <div class="stats-card__value text-[40px]! pt-10 text-center!">
- <CountTo
- :duration="2600"
- :end-val="warn"
- :start-val="0"
- class="stats-card__value text-[40px]! pt-10 text-center! text-[#df8a28]!" />
- </div>
- </div>
- <div class="stats-chart-card">
- <div class="stats-card__label">分类统计</div>
- <div ref="staticChartRef" class="stats-chart"></div>
- </div>
- </div>
- <zm-table
- :loading="loading"
- :data="list"
- height="calc(46vh - 130px)"
- :show-overflow-tooltip="true"
- :row-style="tableRowStyle"
- :row-class-name="tableRowClassName">
- <zm-table-column :label="t('monitor.serial')" width="70" align="center" fixed="left">
- <template #default="scope">
- {{ scope.$index + 1 }}
- </template>
- </zm-table-column>
- <zm-table-column label="名称" align="center" prop="measureName" fixed="left" />
- <zm-table-column label="编码" align="center" prop="measureCode" fixed="left" />
- <zm-table-column label="部门名称" align="center" prop="deptName" />
- <zm-table-column label="计量单位" align="center" prop="measureUnit" />
- <zm-table-column label="责任人" align="center" prop="dutyPerson" />
- <zm-table-column label="品牌" align="center" prop="brand" />
- <zm-table-column label="规格型号" align="center" prop="modelName" />
- <zm-table-column label="分类" align="center" prop="classify" min-width="120px">
- <template #default="scope">
- <dict-tag :type="DICT_TYPE.MEASURE_TYPE" :value="scope.row.classify" />
- </template>
- </zm-table-column>
- <zm-table-column label="采购日期" align="center" prop="buyDate">
- <template #default="scope">
- {{ formatDateCorrectly(scope.row.buyDate) }}
- </template>
- </zm-table-column>
- <zm-table-column label="价格" align="center" prop="measurePrice">
- <template #default="scope">
- {{ scope.row.measurePrice }}
- </template>
- </zm-table-column>
- <zm-table-column label="备注" align="center" prop="remark" />
- <zm-table-column label="检测信息" align="center" fixed="right">
- <template #default="scope">
- <div>
- <el-button link type="primary" @click="handleView(scope.row.id)"> 查看 </el-button>
- </div>
- </template>
- </zm-table-column>
- <zm-table-column
- :label="t('devicePerson.operation')"
- align="center"
- fixed="right"
- action
- min-width="120px">
- <template #default="scope">
- <el-button link type="primary" @click="handleEdit(scope.row)"> 编辑 </el-button>
- <el-button link type="danger" @click="handleDelete(scope.row.id)"> 删除 </el-button>
- </template>
- </zm-table-column>
- </zm-table>
- <!-- 分页 -->
- <Pagination
- :total="total"
- v-model:page="queryParams.pageNo"
- v-model:limit="queryParams.pageSize"
- @pagination="getList" />
- </ContentWrap>
- <ContentWrap style="margin-top: -5px">
- <el-alert title="台账已过期红色预警" type="error" show-icon :closable="false">
- <template #icon>
- <Bell />
- </template>
- </el-alert>
- <el-alert
- title="台账90天橙色预警"
- type="warning"
- show-icon
- :closable="false"
- style="margin-top: 5px">
- <template #icon>
- <Bell />
- </template>
- </el-alert>
- </ContentWrap>
- </el-col>
- </el-row>
- <!-- 新增/编辑台账对话框 -->
- <el-dialog
- :title="dialogTitle"
- v-model="dialogVisible"
- width="800px"
- destroy-on-close
- @close="closeDialog">
- <el-form
- ref="formRef"
- :model="formData"
- :rules="formRules"
- label-width="120px"
- v-loading="formLoading">
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="计量器具名称" prop="measureName">
- <el-input v-model="formData.measureName" placeholder="请输入计量器具名称" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="责任人" prop="dutyPerson">
- <el-input v-model="formData.dutyPerson" placeholder="请输入责任人" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="部门" prop="deptId">
- <el-tree-select
- clearable
- v-model="formData.deptId"
- :data="deptList2"
- :props="defaultProps"
- :check-strictly="false"
- node-key="id"
- filterable
- placeholder="请选择所在部门" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="品牌" prop="brand">
- <el-input v-model="formData.brand" placeholder="请输入品牌" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="规格型号" prop="modelName">
- <el-input v-model="formData.modelName" placeholder="请输入规格型号" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="单位" prop="measureUnit">
- <el-input v-model="formData.measureUnit" placeholder="请输入单位" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="分类" prop="classify">
- <el-select
- v-model="formData.classify"
- placeholder="请选择分类"
- clearable
- class="!w-240px">
- <el-option
- v-for="dict in getStrDictOptions(DICT_TYPE.MEASURE_TYPE)"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="价格" prop="measurePrice">
- <el-input-number
- v-model="formData.measurePrice"
- :precision="2"
- :step="1"
- placeholder="请输入价格"
- style="width: 100%" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="采购日期" prop="buyDate">
- <el-date-picker
- v-model="formData.buyDate"
- type="date"
- value-format="x"
- placeholder="请选择采购日期"
- style="width: 100%" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="备注" prop="remark">
- <el-input v-model="formData.remark" type="textarea" placeholder="请输入描述" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <!-- <el-col :span="12">
- <el-form-item label="有效期" prop="validity">
- <el-date-picker
- v-model="formData.validity"
- type="date"
- value-format="x"
- placeholder="请选择有效期"
- style="width: 100%"
- />
- </el-form-item>
- </el-col> -->
- <!-- <el-col :span="12">
- <el-form-item label="证书编码" prop="measureCertNo">
- <el-input v-model="formData.measureCertNo" placeholder="请输入证书编码" />
- </el-form-item>
- </el-col> -->
- </el-row>
- <!-- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item label="备注" prop="remark">
- <el-input v-model="formData.remark" type="textarea" placeholder="请输入描述" />
- </el-form-item>
- </el-col>
- </el-row> -->
- </el-form>
- <template #footer>
- <el-button @click="closeDialog">取 消</el-button>
- <el-button type="primary" @click="submitForm" :loading="submitLoading">确 定</el-button>
- </template>
- </el-dialog>
- <el-drawer
- v-model="drawerVisible"
- title="检测信息"
- size="60%"
- direction="rtl"
- :before-close="closeDrawer">
- <div v-loading="drawerLoading">
- <zm-table
- :loading="loading"
- :data="measureDetectionData"
- :stripe="true"
- :row-style="tableRowStyle"
- :row-class-name="tableRowClassName"
- height="80vh"
- :show-overflow-tooltip="true">
- <zm-table-column :label="t('monitor.serial')" width="70" align="center" fixed="left">
- <template #default="scope">
- {{ scope.$index + 1 }}
- </template>
- </zm-table-column>
- <zm-table-column
- label="计量器具名称"
- align="center"
- prop="measureName"
- min-width="160"
- fixed="left" />
- <zm-table-column label="证书编码" align="center" prop="measureCertNo" min-width="160" />
- <zm-table-column label="检测/校准日期" align="center" prop="detectDate" width="140">
- <template #default="scope">
- <span class="iot-md-date">{{ formatDateCorrectly(scope.row.detectDate) }}</span>
- </template>
- </zm-table-column>
- <zm-table-column label="检测/校准机构" align="center" prop="detectOrg" min-width="160" />
- <zm-table-column
- label="检测/校准标准"
- align="center"
- prop="detectStandard"
- min-width="160" />
- <zm-table-column label="检测/校准内容" align="center" prop="detectContent" min-width="220">
- <template #default="scope">
- <div class="detect-content" v-html="scope.row.detectContent"></div>
- </template>
- </zm-table-column>
- <zm-table-column label="检测/校准有效期" align="center" prop="validityPeriod" width="140">
- <template #default="scope">
- <span class="iot-md-date">{{ formatDateCorrectly(scope.row.validityPeriod) }}</span>
- </template>
- </zm-table-column>
- <zm-table-column label="校准金额" align="center" prop="detectAmount" width="120" />
- <zm-table-column label="部门名称" align="center" prop="deptName" min-width="140" />
- <zm-table-column
- label="附件"
- align="center"
- prop="file"
- min-width="90"
- fixed="right"
- action>
- <template #default="scope">
- <el-button v-if="scope.row.file" link type="primary" @click="viewFile(scope.row.file)">
- 查看
- </el-button>
- <span v-else class="text-[#999ca1]">暂无附件</span>
- </template>
- </zm-table-column>
- </zm-table>
- <div class="iot-md-pagination absolute right-2 bottom-2">
- <Pagination
- :total="totalMsg"
- v-model:page="queryParams2.pageNo"
- v-model:limit="queryParams2.pageSize"
- @pagination="getList2" />
- </div>
- </div>
- </el-drawer>
- <el-dialog v-model="dialogFileView" title="附件" width="500">
- <div
- v-for="(file, index) in fileList"
- :key="index"
- class="flex items-center justify-between mt-5">
- <span class="file-name-text">{{ extractFileName(file) }}</span>
- <div>
- <el-button link type="primary" @click="viewFileInfo(file)">
- <Icon icon="ep:view" class="mr-2px" />查看</el-button
- >
- <el-button link type="primary" @click="handleDownload(file)">
- <Icon icon="ep:download" class="mr-2px" />下载</el-button
- >
- </div>
- </div>
- <template #footer>
- <div class="dialog-footer mt-10">
- <el-button type="primary" @click="dialogFileView = false"> 确认 </el-button>
- </div>
- </template>
- </el-dialog>
- </template>
- <script setup lang="ts">
- import * as echarts from 'echarts'
- import { IotInstrumentApi, IotMeasureDetectApi } from '@/api/pms/qhse/index'
- import DeptTree from '@/views/system/user/DeptTree2.vue'
- import { handleTree } from '@/utils/tree'
- import { defaultProps } from '@/utils/tree'
- import * as DeptApi from '@/api/system/dept'
- import { ElMessageBox } from 'element-plus'
- const deptList = ref<Tree[]>([]) // 树形结构
- const deptList2 = ref<Tree[]>([]) // 树形结构
- import { formatDate } from '@/utils/formatTime'
- import { useUserStore } from '@/store/modules/user'
- import { DICT_TYPE, getStrDictOptions, getBoolDictOptions } from '@/utils/dict'
- import { useTableComponents } from '@/components/ZmTable/useTableComponents'
- const { ZmTable, ZmTableColumn } = useTableComponents()
- const userStore = useUserStore()
- defineOptions({ name: 'IotQHSEMeasure' })
- const loading = ref(true) // 列表的加载中
- const formLoading = ref(false) // 表单加载中
- const submitLoading = ref(false) // 提交按钮加载中
- let exportLoading = ref(false)
- const isLeftContentCollapsed = ref(false)
- const { t } = useI18n()
- type StaticItem = {
- classify: string
- count: number
- }
- const list = ref([]) // 列表的数据
- const total = ref(0) // 列表的总页数
- const staticChartRef = ref<HTMLDivElement>()
- const queryParams = reactive({
- pageNo: 1,
- pageSize: 10,
- measureName: undefined,
- deptId: undefined,
- expired: undefined,
- alertWarn: undefined
- })
- const queryFormRef = ref(null) // 搜索的表单
- const tableRowStyle = ({ row }) => {
- if (row.expired) {
- return { backgroundColor: '#ffe6e6' }
- }
- if (row.alertWarn) {
- return { backgroundColor: '#e19f1a' }
- }
- return {}
- }
- const tableRowClassName = ({ row }) => {
- if (row.expired) {
- return 'expired-row'
- }
- if (row.alertWarn) {
- return 'alert-warn-row'
- }
- return ''
- }
- // 对话框相关
- const dialogVisible = ref(false)
- const dialogTitle = ref('')
- const isEdit = ref(false)
- // 表单相关
- const formRef = ref()
- const formData = ref({
- measureName: '',
- measureUnit: '',
- dutyPerson: '',
- brand: '',
- modelName: '',
- classify: '',
- buyDate: null,
- remark: '',
- deptId: '',
- measureCode: '',
- // validity: null, // 有效期
- measurePrice: 0, // 价格
- measureCertNo: ''
- })
- // 正确格式化日期的函数
- const formatDateCorrectly = (timestamp) => {
- if (!timestamp) return ''
- // 如果是秒级时间戳,转换为毫秒级
- let time = Number(timestamp)
- if (time < 10000000000) {
- // 小于这个数通常表示秒级时间戳
- time = time * 1000
- }
- return formatDate(time).substring(0, 10)
- }
- // 表单验证规则
- const formRules = {
- measureName: [{ required: true, message: '计量器具名称不能为空', trigger: 'blur' }],
- dutyPerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
- classify: [{ required: true, message: '分类不能为空', trigger: 'blur' }],
- deptId: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
- measureCertNo: [{ required: true, message: '证书编码不能为空', trigger: 'blur' }],
- validity: [{ required: true, message: '有效期不能为空', trigger: 'blur' }]
- }
- /** 查询列表 */
- const getList = async () => {
- loading.value = true
- try {
- const data = await IotInstrumentApi.getInstrumentList(queryParams)
- list.value = data.list
- total.value = data.total
- } finally {
- loading.value = false
- }
- }
- const downloadFile = (response: any) => {
- // 创建 blob 对象
- const blob = new Blob([response], {
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
- })
- // 获取文件名
- let fileName = '计量器具台账.xlsx'
- const disposition = response.headers ? response.headers['content-disposition'] : ''
- if (disposition) {
- const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
- const matches = filenameRegex.exec(disposition)
- if (matches != null && matches[1]) {
- fileName = matches[1].replace(/['"]/g, '')
- }
- }
- // 创建下载链接
- const url = window.URL.createObjectURL(blob)
- const link = document.createElement('a')
- link.href = url
- link.setAttribute('download', fileName)
- // 触发下载
- document.body.appendChild(link)
- link.click()
- // 清理
- document.body.removeChild(link)
- window.URL.revokeObjectURL(url)
- }
- const handleExport = async () => {
- try {
- exportLoading.value = true
- // 调用导出接口
- const response = await IotInstrumentApi.exportInstrument(queryParams)
- // 下载文件
- downloadFile(response)
- exportLoading.value = false
- } catch (error) {
- ElMessage.error('导出失败,请重试')
- console.error('导出错误:', error)
- } finally {
- }
- }
- /** 首页处理部门被点击 */
- const handleDeptNodeClick = async (row) => {
- queryParams.deptId = row.id
- await getList()
- await getStatic()
- }
- /** 搜索按钮操作 */
- const handleQuery = () => {
- queryParams.pageNo = 1
- getList()
- }
- /** 重置按钮操作 */
- const resetQuery = () => {
- queryFormRef.value?.resetFields()
- handleQuery()
- }
- // 显示新增对话框
- const handleAdd = () => {
- isEdit.value = false
- dialogTitle.value = '新增台账'
- resetForm()
- formData.value.deptId = userStore.getUser.deptId // 默认选择当前用户的部门
- dialogVisible.value = true
- }
- // 显示编辑对话框
- const handleEdit = (row) => {
- isEdit.value = true
- dialogTitle.value = '编辑台账'
- formData.value = {
- ...row,
- // 确保日期字段正确处理
- buyDate: row.buyDate ? ensureMillisecondTimestamp(row.buyDate) : null,
- validity: row.validity ? ensureMillisecondTimestamp(row.validity) : null
- }
- dialogVisible.value = true
- }
- // 关闭抽屉
- const closeDrawer = () => {
- drawerVisible.value = false
- measureDetectionData.value = []
- }
- // 抽屉相关响应式数据
- const drawerVisible = ref(false)
- const drawerLoading = ref(false)
- const measureDetectionData = ref([])
- let totalMsg = ref(0)
- let currentId = ref(null)
- let queryParams2 = reactive({
- pageNo: 1,
- pageSize: 10,
- measureId: null
- })
- const handleView = async (id: any) => {
- drawerLoading.value = true
- currentId.value = id
- try {
- const response = await IotMeasureDetectApi.getIotMeasureDetectPage({
- pageNo: queryParams2.pageNo,
- pageSize: queryParams2.pageSize,
- measureId: id
- })
- measureDetectionData.value = response.list || []
- totalMsg.value = response.total
- drawerVisible.value = true
- } catch (error) {
- console.error('获取检测信息失败:', error)
- } finally {
- drawerLoading.value = false
- }
- }
- const getList2 = async () => {
- drawerLoading.value = true
- try {
- const response = await IotMeasureDetectApi.getIotMeasureDetectPage({
- pageNo: queryParams2.pageNo,
- pageSize: queryParams2.pageSize,
- measureId: currentId.value
- })
- measureDetectionData.value = response.list || []
- totalMsg.value = response.total
- drawerVisible.value = true
- } catch (error) {
- console.error('获取检测信息失败:', error)
- } finally {
- drawerLoading.value = false
- }
- }
- // 确保时间戳是毫秒级的
- const ensureMillisecondTimestamp = (timestamp) => {
- let time = Number(timestamp)
- if (time < 10000000000) {
- // 秒级时间戳转为毫秒级
- return time * 1000
- }
- return time
- }
- //删除成套
- const handleDelete = async (id: number) => {
- ElMessageBox.confirm('确定要删除该台账吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- try {
- await IotInstrumentApi.deleteInstrument(id)
- ElMessage.success('删除成功')
- getList()
- } catch (error) {
- console.error(error)
- }
- })
- .catch(() => {
- // 取消操作
- })
- }
- // 重置表单
- const resetForm = () => {
- formData.value = {
- measureName: '',
- measureUnit: '',
- dutyPerson: '',
- brand: '',
- modelName: '',
- classify: '',
- buyDate: null,
- remark: '',
- deptId: '',
- measureCode: '',
- // validity: null, // 有效期
- measurePrice: 0, // 价格
- measureCertNo: ''
- }
- formRef.value?.clearValidate()
- }
- // 关闭对话框
- const closeDialog = () => {
- dialogVisible.value = false
- resetForm()
- }
- // 提交表单
- const submitForm = async () => {
- if (!formRef.value) return
- try {
- await formRef.value.validate()
- submitLoading.value = true
- // 准备提交数据
- const submitData = {
- ...formData.value,
- // 确保日期字段以正确的格式提交
- buyDate: formData.value.buyDate,
- validity: formData.value.validity
- }
- if (isEdit.value) {
- // 编辑
- await IotInstrumentApi.updateInstrument(submitData)
- ElMessage.success('编辑成功')
- } else {
- // 新增
- await IotInstrumentApi.createInstrument(submitData)
- ElMessage.success('新增成功')
- }
- dialogVisible.value = false
- getList()
- } catch (error) {
- console.error(error)
- } finally {
- submitLoading.value = false
- }
- }
- let dialogFileView = ref(false)
- let fileList = ref([])
- const viewFile = (file) => {
- fileList.value = file.split(',')
- dialogFileView.value = true
- // window.open(file)
- }
- const viewFileInfo = (file) => {
- window.open(
- 'http://doc.deepoil.cc:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(file))
- )
- }
- const extractFileName = (url: string): string => {
- try {
- // 移除查询参数和哈希
- const cleanUrl = url.split('?')[0].split('#')[0]
- // 获取最后一个斜杠后的内容
- const parts = cleanUrl.split('/')
- const fileName = parts[parts.length - 1]
- // URL 解码
- return decodeURIComponent(fileName) || url
- } catch {
- // 如果解析失败,返回原始 URL
- return url
- }
- }
- const handleDownload = async (url) => {
- try {
- const response = await fetch(url)
- const blob = await response.blob()
- const downloadUrl = window.URL.createObjectURL(blob)
- const link = document.createElement('a')
- link.href = downloadUrl
- link.download = url.split('/').pop() // 自动获取文件名:ml-citation{ref="3" data="citationList"}
- link.click()
- URL.revokeObjectURL(downloadUrl)
- } catch (error) {
- console.error('下载失败:', error)
- }
- }
- let staticData = ref<StaticItem[]>([])
- let expired = ref(0)
- let warn = ref(0)
- let staticChart: echarts.ECharts | null = null
- function getStaticChartOption(): echarts.EChartsOption {
- return {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow'
- }
- },
- grid: {
- left: 16,
- right: 16,
- top: 24,
- bottom: 16,
- containLabel: true
- },
- xAxis: {
- type: 'category',
- data: staticData.value.map((item) => item.classify),
- axisTick: {
- show: false
- },
- axisLine: {
- lineStyle: {
- color: '#d9e2ef'
- }
- },
- axisLabel: {
- color: '#6b7280',
- fontSize: 12,
- interval: 0
- }
- },
- yAxis: {
- type: 'value',
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- color: '#94a3b8',
- fontSize: 12
- },
- splitLine: {
- lineStyle: {
- color: '#edf2f7',
- type: 'dashed'
- }
- }
- },
- series: [
- {
- type: 'bar',
- barWidth: 32,
- data: staticData.value.map((item) => item.count),
- itemStyle: {
- borderRadius: [8, 8, 0, 0],
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: '#79b8ff' },
- { offset: 1, color: '#2f78f6' }
- ])
- },
- label: {
- show: true,
- position: 'top',
- color: '#2563eb',
- fontSize: 12,
- fontWeight: 700
- }
- }
- ]
- }
- }
- function renderStaticChart() {
- if (!staticChartRef.value) return
- if (!staticChart) {
- staticChart = echarts.init(staticChartRef.value)
- }
- staticChart.setOption(getStaticChartOption(), true)
- }
- function resizeStaticChart() {
- staticChart?.resize()
- }
- function destroyStaticChart() {
- if (staticChart) {
- staticChart.dispose()
- staticChart = null
- }
- }
- async function getStatic() {
- if (queryParams.deptId) {
- const res = await IotInstrumentApi.getInstrumentStatistics(queryParams.deptId)
- staticData.value = res.classify
- expired.value = res.expired
- warn.value = res.warn
- } else {
- const res = await IotInstrumentApi.getInstrumentStatistics(userStore.user.deptId)
- staticData.value = res.classify
- expired.value = res.expired
- warn.value = res.warn
- }
- nextTick(() => {
- renderStaticChart()
- })
- }
- onMounted(async () => {
- getList()
- getStatic()
- deptList.value = handleTree(await DeptApi.getSimpleDeptList())
- deptList2.value = handleTree(await DeptApi.getSimpleDeptList())
- window.addEventListener('resize', resizeStaticChart)
- })
- onUnmounted(() => {
- window.removeEventListener('resize', resizeStaticChart)
- destroyStaticChart()
- })
- </script>
- <style scoped>
- ::deep(.el-tree--highlight-current) {
- height: 200px !important;
- }
- ::deep(.el-transfer-panel__body) {
- height: 700px !important;
- }
- .stats-cards {
- display: grid;
- grid-template-columns: 180px 180px minmax(0, 1fr);
- gap: 12px;
- margin-bottom: 16px;
- align-items: stretch;
- }
- .stats-card {
- padding: 14px 16px;
- background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
- border: 1px solid #e4ecf7;
- border-radius: 10px;
- box-shadow: 0 4px 12px rgb(31 91 184 / 8%);
- }
- .stats-card__label {
- font-size: 14px;
- font-weight: 600;
- color: #6b7280;
- line-height: 1.4;
- }
- .stats-card__value {
- margin-top: 8px;
- font-size: 28px;
- font-weight: 700;
- line-height: 1;
- color: #1f5bb8;
- }
- .stats-card--expired {
- background: linear-gradient(180deg, #fff4f4 0%, #ffe8e8 100%);
- border-color: #ffcfcf;
- }
- .stats-card--expired .stats-card__value {
- color: #de3b3b;
- }
- .stats-card--warn {
- background: linear-gradient(180deg, #fff8ef 0%, #ffeed9 100%);
- border-color: #ffd7a1;
- }
- .stats-card--warn .stats-card__value {
- color: #d97706;
- }
- .stats-chart-card {
- padding: 14px 16px 10px;
- background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
- border: 1px solid #e4ecf7;
- border-radius: 10px;
- box-shadow: 0 4px 12px rgb(31 91 184 / 8%);
- }
- .stats-chart {
- height: 130px;
- margin-top: 6px;
- }
- .stats-card {
- padding: 14px 16px;
- background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
- border: 1px solid #e4ecf7;
- border-radius: 10px;
- box-shadow: 0 4px 12px rgb(31 91 184 / 8%);
- }
- .stats-card__header {
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .stats-card__icon {
- color: inherit;
- opacity: 0.85;
- }
- .stats-card__label {
- font-size: 14px;
- font-weight: 600;
- color: #6b7280;
- line-height: 1.4;
- }
- .stats-card__value {
- margin-top: 8px;
- font-size: 28px;
- font-weight: 700;
- line-height: 1;
- color: #1f5bb8;
- }
- .stats-card__desc {
- margin-top: 8px;
- font-size: 12px;
- color: #9ca3af;
- font-weight: 500;
- }
- .stats-card--expired {
- background: linear-gradient(180deg, #fff4f4 0%, #ffe8e8 100%);
- border-color: #ffcfcf;
- }
- .stats-card--expired .stats-card__value {
- color: #de3b3b;
- }
- .stats-card--expired .stats-card__icon {
- color: #de3b3b;
- }
- .stats-card--warn {
- background: linear-gradient(180deg, #fff8ef 0%, #ffeed9 100%);
- border-color: #ffd7a1;
- }
- .stats-card--warn .stats-card__value {
- color: #d97706;
- }
- .stats-card--warn .stats-card__icon {
- color: #d97706;
- }
- /* 过期行的红色背景 - 基础状态 */
- :deep(.el-table__body tr.expired-row > td.el-table__cell) {
- background-color: #ffe6e6 !important;
- }
- /* 过期行 - 鼠标悬浮状态 */
- :deep(.el-table__body tr.expired-row:hover > td.el-table__cell) {
- background-color: #ffcccc !important;
- }
- /* 确保斑马纹不影响过期行 */
- :deep(.el-table__body tr.expired-row.el-table__row--striped > td.el-table__cell) {
- background-color: #ffe6e6 !important;
- }
- :deep(.el-table__body tr.expired-row.el-table__row--striped:hover > td.el-table__cell) {
- background-color: #ffcccc !important;
- }
- /* 预警行的橙色背景 - 基础状态 */
- :deep(.el-table__body tr.alert-warn-row > td.el-table__cell) {
- background-color: #fff1df !important;
- }
- /* 预警行 - 鼠标悬浮状态 */
- :deep(.el-table__body tr.alert-warn-row:hover > td.el-table__cell) {
- background-color: #ffe2bf !important;
- }
- /* 确保斑马纹不影响预警行 */
- :deep(.el-table__body tr.alert-warn-row.el-table__row--striped > td.el-table__cell) {
- background-color: #fff1df !important;
- }
- :deep(.el-table__body tr.alert-warn-row.el-table__row--striped:hover > td.el-table__cell) {
- background-color: #ffe2bf !important;
- }
- </style>
|