index.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. <template>
  2. <el-row :gutter="20">
  3. <!-- 左侧部门树 -->
  4. <DeptTree @node-click="handleDeptNodeClick" v-model:collapsed="isLeftContentCollapsed" />
  5. <el-col :xs="24" :span="isLeftContentCollapsed ? 24 : 20">
  6. <ContentWrap style="border: none">
  7. <!-- 搜索工作栏 -->
  8. <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">
  9. <el-form-item label="计量器具名称" prop="measureName">
  10. <el-input
  11. v-model="queryParams.measureName"
  12. placeholder="请输入计量器具名称"
  13. clearable
  14. @keyup.enter="handleQuery"
  15. class="!w-150px" />
  16. </el-form-item>
  17. <el-form-item label="是否过期" prop="expired">
  18. <el-select
  19. v-model="queryParams.expired"
  20. placeholder="请选择是否过期"
  21. clearable
  22. style="width: 120px">
  23. <el-option
  24. v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  25. :key="dict.value"
  26. :label="dict.label"
  27. :value="dict.value" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="是否预警" prop="alertWarn">
  31. <el-select
  32. v-model="queryParams.alertWarn"
  33. placeholder="请选择是否预警"
  34. clearable
  35. style="width: 120px">
  36. <el-option
  37. v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  38. :key="dict.value"
  39. :label="dict.label"
  40. :value="dict.value" />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button @click="handleAdd" type="primary"
  45. ><Icon icon="ep:plus" class="mr-5px" />新增</el-button
  46. >
  47. <el-button @click="handleQuery"
  48. ><Icon icon="ep:search" class="mr-5px" /> {{ t('devicePerson.search') }}</el-button
  49. >
  50. <el-button @click="resetQuery"
  51. ><Icon icon="ep:refresh" class="mr-5px" /> {{ t('devicePerson.reset') }}</el-button
  52. >
  53. <el-button @click="handleExport" type="success" plain :loading="exportLoading"
  54. ><Icon icon="ep:download" class="mr-5px" /> 导出</el-button
  55. >
  56. </el-form-item>
  57. </el-form>
  58. </ContentWrap>
  59. <!-- 列表 -->
  60. <ContentWrap class="flex-1 overflow-hidden mt-15px" style="border: none">
  61. <div class="stats-cards">
  62. <div class="stats-card stats-card--expired">
  63. <div class="stats-card__header">
  64. <el-icon class="stats-card__icon" :size="28">
  65. <Icon icon="ep:info-filled" />
  66. </el-icon>
  67. <div class="stats-card__label">已过期</div>
  68. </div>
  69. <div class="stats-card__value text-[40px]! pt-10 text-center!">
  70. <CountTo
  71. :duration="2600"
  72. :end-val="expired"
  73. :start-val="0"
  74. class="stats-card__value text-[40px]! pt-10 text-center! text-[#e35656]!"
  75. /></div>
  76. </div>
  77. <div class="stats-card stats-card--warn">
  78. <div class="stats-card__header">
  79. <el-icon class="stats-card__icon" :size="28">
  80. <Icon icon="ep:bell-filled" />
  81. </el-icon>
  82. <div class="stats-card__label">90天预警</div>
  83. </div>
  84. <div class="stats-card__value text-[40px]! pt-10 text-center!">
  85. <CountTo
  86. :duration="2600"
  87. :end-val="warn"
  88. :start-val="0"
  89. class="stats-card__value text-[40px]! pt-10 text-center! text-[#df8a28]!" />
  90. </div>
  91. </div>
  92. <div class="stats-chart-card">
  93. <div class="stats-card__label">分类统计</div>
  94. <div ref="staticChartRef" class="stats-chart"></div>
  95. </div>
  96. </div>
  97. <zm-table
  98. :loading="loading"
  99. :data="list"
  100. height="calc(46vh - 130px)"
  101. :show-overflow-tooltip="true"
  102. :row-style="tableRowStyle"
  103. :row-class-name="tableRowClassName">
  104. <zm-table-column :label="t('monitor.serial')" width="70" align="center" fixed="left">
  105. <template #default="scope">
  106. {{ scope.$index + 1 }}
  107. </template>
  108. </zm-table-column>
  109. <zm-table-column label="名称" align="center" prop="measureName" fixed="left" />
  110. <zm-table-column label="编码" align="center" prop="measureCode" fixed="left" />
  111. <zm-table-column label="部门名称" align="center" prop="deptName" />
  112. <zm-table-column label="计量单位" align="center" prop="measureUnit" />
  113. <zm-table-column label="责任人" align="center" prop="dutyPerson" />
  114. <zm-table-column label="品牌" align="center" prop="brand" />
  115. <zm-table-column label="规格型号" align="center" prop="modelName" />
  116. <zm-table-column label="分类" align="center" prop="classify" min-width="120px">
  117. <template #default="scope">
  118. <dict-tag :type="DICT_TYPE.MEASURE_TYPE" :value="scope.row.classify" />
  119. </template>
  120. </zm-table-column>
  121. <zm-table-column label="采购日期" align="center" prop="buyDate">
  122. <template #default="scope">
  123. {{ formatDateCorrectly(scope.row.buyDate) }}
  124. </template>
  125. </zm-table-column>
  126. <zm-table-column label="价格" align="center" prop="measurePrice">
  127. <template #default="scope">
  128. {{ scope.row.measurePrice }}
  129. </template>
  130. </zm-table-column>
  131. <zm-table-column label="备注" align="center" prop="remark" />
  132. <zm-table-column label="检测信息" align="center" fixed="right">
  133. <template #default="scope">
  134. <div>
  135. <el-button link type="primary" @click="handleView(scope.row.id)"> 查看 </el-button>
  136. </div>
  137. </template>
  138. </zm-table-column>
  139. <zm-table-column
  140. :label="t('devicePerson.operation')"
  141. align="center"
  142. fixed="right"
  143. action
  144. min-width="120px">
  145. <template #default="scope">
  146. <el-button link type="primary" @click="handleEdit(scope.row)"> 编辑 </el-button>
  147. <el-button link type="danger" @click="handleDelete(scope.row.id)"> 删除 </el-button>
  148. </template>
  149. </zm-table-column>
  150. </zm-table>
  151. <!-- 分页 -->
  152. <Pagination
  153. :total="total"
  154. v-model:page="queryParams.pageNo"
  155. v-model:limit="queryParams.pageSize"
  156. @pagination="getList" />
  157. </ContentWrap>
  158. <ContentWrap style="margin-top: -5px">
  159. <el-alert title="台账已过期红色预警" type="error" show-icon :closable="false">
  160. <template #icon>
  161. <Bell />
  162. </template>
  163. </el-alert>
  164. <el-alert
  165. title="台账90天橙色预警"
  166. type="warning"
  167. show-icon
  168. :closable="false"
  169. style="margin-top: 5px">
  170. <template #icon>
  171. <Bell />
  172. </template>
  173. </el-alert>
  174. </ContentWrap>
  175. </el-col>
  176. </el-row>
  177. <!-- 新增/编辑台账对话框 -->
  178. <el-dialog
  179. :title="dialogTitle"
  180. v-model="dialogVisible"
  181. width="800px"
  182. destroy-on-close
  183. @close="closeDialog">
  184. <el-form
  185. ref="formRef"
  186. :model="formData"
  187. :rules="formRules"
  188. label-width="120px"
  189. v-loading="formLoading">
  190. <el-row :gutter="20">
  191. <el-col :span="12">
  192. <el-form-item label="计量器具名称" prop="measureName">
  193. <el-input v-model="formData.measureName" placeholder="请输入计量器具名称" />
  194. </el-form-item>
  195. </el-col>
  196. <el-col :span="12">
  197. <el-form-item label="责任人" prop="dutyPerson">
  198. <el-input v-model="formData.dutyPerson" placeholder="请输入责任人" />
  199. </el-form-item>
  200. </el-col>
  201. </el-row>
  202. <el-row :gutter="20">
  203. <el-col :span="12">
  204. <el-form-item label="部门" prop="deptId">
  205. <el-tree-select
  206. clearable
  207. v-model="formData.deptId"
  208. :data="deptList2"
  209. :props="defaultProps"
  210. :check-strictly="false"
  211. node-key="id"
  212. filterable
  213. placeholder="请选择所在部门" />
  214. </el-form-item>
  215. </el-col>
  216. <el-col :span="12">
  217. <el-form-item label="品牌" prop="brand">
  218. <el-input v-model="formData.brand" placeholder="请输入品牌" />
  219. </el-form-item>
  220. </el-col>
  221. </el-row>
  222. <el-row :gutter="20">
  223. <el-col :span="12">
  224. <el-form-item label="规格型号" prop="modelName">
  225. <el-input v-model="formData.modelName" placeholder="请输入规格型号" />
  226. </el-form-item>
  227. </el-col>
  228. <el-col :span="12">
  229. <el-form-item label="单位" prop="measureUnit">
  230. <el-input v-model="formData.measureUnit" placeholder="请输入单位" />
  231. </el-form-item>
  232. </el-col>
  233. </el-row>
  234. <el-row :gutter="20">
  235. <el-col :span="12">
  236. <el-form-item label="分类" prop="classify">
  237. <el-select
  238. v-model="formData.classify"
  239. placeholder="请选择分类"
  240. clearable
  241. class="!w-240px">
  242. <el-option
  243. v-for="dict in getStrDictOptions(DICT_TYPE.MEASURE_TYPE)"
  244. :key="dict.value"
  245. :label="dict.label"
  246. :value="dict.value" />
  247. </el-select>
  248. </el-form-item>
  249. </el-col>
  250. <el-col :span="12">
  251. <el-form-item label="价格" prop="measurePrice">
  252. <el-input-number
  253. v-model="formData.measurePrice"
  254. :precision="2"
  255. :step="1"
  256. placeholder="请输入价格"
  257. style="width: 100%" />
  258. </el-form-item>
  259. </el-col>
  260. </el-row>
  261. <el-row :gutter="20">
  262. <el-col :span="12">
  263. <el-form-item label="采购日期" prop="buyDate">
  264. <el-date-picker
  265. v-model="formData.buyDate"
  266. type="date"
  267. value-format="x"
  268. placeholder="请选择采购日期"
  269. style="width: 100%" />
  270. </el-form-item>
  271. </el-col>
  272. <el-col :span="12">
  273. <el-form-item label="备注" prop="remark">
  274. <el-input v-model="formData.remark" type="textarea" placeholder="请输入描述" />
  275. </el-form-item>
  276. </el-col>
  277. </el-row>
  278. <el-row :gutter="20">
  279. <!-- <el-col :span="12">
  280. <el-form-item label="有效期" prop="validity">
  281. <el-date-picker
  282. v-model="formData.validity"
  283. type="date"
  284. value-format="x"
  285. placeholder="请选择有效期"
  286. style="width: 100%"
  287. />
  288. </el-form-item>
  289. </el-col> -->
  290. <!-- <el-col :span="12">
  291. <el-form-item label="证书编码" prop="measureCertNo">
  292. <el-input v-model="formData.measureCertNo" placeholder="请输入证书编码" />
  293. </el-form-item>
  294. </el-col> -->
  295. </el-row>
  296. <!-- <el-row :gutter="20">
  297. <el-col :span="12">
  298. <el-form-item label="备注" prop="remark">
  299. <el-input v-model="formData.remark" type="textarea" placeholder="请输入描述" />
  300. </el-form-item>
  301. </el-col>
  302. </el-row> -->
  303. </el-form>
  304. <template #footer>
  305. <el-button @click="closeDialog">取 消</el-button>
  306. <el-button type="primary" @click="submitForm" :loading="submitLoading">确 定</el-button>
  307. </template>
  308. </el-dialog>
  309. <el-drawer
  310. v-model="drawerVisible"
  311. title="检测信息"
  312. size="60%"
  313. direction="rtl"
  314. :before-close="closeDrawer">
  315. <div v-loading="drawerLoading">
  316. <zm-table
  317. :loading="loading"
  318. :data="measureDetectionData"
  319. :stripe="true"
  320. :row-style="tableRowStyle"
  321. :row-class-name="tableRowClassName"
  322. height="80vh"
  323. :show-overflow-tooltip="true">
  324. <zm-table-column :label="t('monitor.serial')" width="70" align="center" fixed="left">
  325. <template #default="scope">
  326. {{ scope.$index + 1 }}
  327. </template>
  328. </zm-table-column>
  329. <zm-table-column
  330. label="计量器具名称"
  331. align="center"
  332. prop="measureName"
  333. min-width="160"
  334. fixed="left" />
  335. <zm-table-column label="证书编码" align="center" prop="measureCertNo" min-width="160" />
  336. <zm-table-column label="检测/校准日期" align="center" prop="detectDate" width="140">
  337. <template #default="scope">
  338. <span class="iot-md-date">{{ formatDateCorrectly(scope.row.detectDate) }}</span>
  339. </template>
  340. </zm-table-column>
  341. <zm-table-column label="检测/校准机构" align="center" prop="detectOrg" min-width="160" />
  342. <zm-table-column
  343. label="检测/校准标准"
  344. align="center"
  345. prop="detectStandard"
  346. min-width="160" />
  347. <zm-table-column label="检测/校准内容" align="center" prop="detectContent" min-width="220">
  348. <template #default="scope">
  349. <div class="detect-content" v-html="scope.row.detectContent"></div>
  350. </template>
  351. </zm-table-column>
  352. <zm-table-column label="检测/校准有效期" align="center" prop="validityPeriod" width="140">
  353. <template #default="scope">
  354. <span class="iot-md-date">{{ formatDateCorrectly(scope.row.validityPeriod) }}</span>
  355. </template>
  356. </zm-table-column>
  357. <zm-table-column label="校准金额" align="center" prop="detectAmount" width="120" />
  358. <zm-table-column label="部门名称" align="center" prop="deptName" min-width="140" />
  359. <zm-table-column
  360. label="附件"
  361. align="center"
  362. prop="file"
  363. min-width="90"
  364. fixed="right"
  365. action>
  366. <template #default="scope">
  367. <el-button v-if="scope.row.file" link type="primary" @click="viewFile(scope.row.file)">
  368. 查看
  369. </el-button>
  370. <span v-else class="text-[#999ca1]">暂无附件</span>
  371. </template>
  372. </zm-table-column>
  373. </zm-table>
  374. <div class="iot-md-pagination absolute right-2 bottom-2">
  375. <Pagination
  376. :total="totalMsg"
  377. v-model:page="queryParams2.pageNo"
  378. v-model:limit="queryParams2.pageSize"
  379. @pagination="getList2" />
  380. </div>
  381. </div>
  382. </el-drawer>
  383. <el-dialog v-model="dialogFileView" title="附件" width="500">
  384. <div
  385. v-for="(file, index) in fileList"
  386. :key="index"
  387. class="flex items-center justify-between mt-5">
  388. <span class="file-name-text">{{ extractFileName(file) }}</span>
  389. <div>
  390. <el-button link type="primary" @click="viewFileInfo(file)">
  391. <Icon icon="ep:view" class="mr-2px" />查看</el-button
  392. >
  393. <el-button link type="primary" @click="handleDownload(file)">
  394. <Icon icon="ep:download" class="mr-2px" />下载</el-button
  395. >
  396. </div>
  397. </div>
  398. <template #footer>
  399. <div class="dialog-footer mt-10">
  400. <el-button type="primary" @click="dialogFileView = false"> 确认 </el-button>
  401. </div>
  402. </template>
  403. </el-dialog>
  404. </template>
  405. <script setup lang="ts">
  406. import * as echarts from 'echarts'
  407. import { IotInstrumentApi, IotMeasureDetectApi } from '@/api/pms/qhse/index'
  408. import DeptTree from '@/views/system/user/DeptTree2.vue'
  409. import { handleTree } from '@/utils/tree'
  410. import { defaultProps } from '@/utils/tree'
  411. import * as DeptApi from '@/api/system/dept'
  412. import { ElMessageBox } from 'element-plus'
  413. const deptList = ref<Tree[]>([]) // 树形结构
  414. const deptList2 = ref<Tree[]>([]) // 树形结构
  415. import { formatDate } from '@/utils/formatTime'
  416. import { useUserStore } from '@/store/modules/user'
  417. import { DICT_TYPE, getStrDictOptions, getBoolDictOptions } from '@/utils/dict'
  418. import { useTableComponents } from '@/components/ZmTable/useTableComponents'
  419. const { ZmTable, ZmTableColumn } = useTableComponents()
  420. const userStore = useUserStore()
  421. defineOptions({ name: 'IotQHSEMeasure' })
  422. const loading = ref(true) // 列表的加载中
  423. const formLoading = ref(false) // 表单加载中
  424. const submitLoading = ref(false) // 提交按钮加载中
  425. let exportLoading = ref(false)
  426. const isLeftContentCollapsed = ref(false)
  427. const { t } = useI18n()
  428. type StaticItem = {
  429. classify: string
  430. count: number
  431. }
  432. const list = ref([]) // 列表的数据
  433. const total = ref(0) // 列表的总页数
  434. const staticChartRef = ref<HTMLDivElement>()
  435. const queryParams = reactive({
  436. pageNo: 1,
  437. pageSize: 10,
  438. measureName: undefined,
  439. deptId: undefined,
  440. expired: undefined,
  441. alertWarn: undefined
  442. })
  443. const queryFormRef = ref(null) // 搜索的表单
  444. const tableRowStyle = ({ row }) => {
  445. if (row.expired) {
  446. return { backgroundColor: '#ffe6e6' }
  447. }
  448. if (row.alertWarn) {
  449. return { backgroundColor: '#e19f1a' }
  450. }
  451. return {}
  452. }
  453. const tableRowClassName = ({ row }) => {
  454. if (row.expired) {
  455. return 'expired-row'
  456. }
  457. if (row.alertWarn) {
  458. return 'alert-warn-row'
  459. }
  460. return ''
  461. }
  462. // 对话框相关
  463. const dialogVisible = ref(false)
  464. const dialogTitle = ref('')
  465. const isEdit = ref(false)
  466. // 表单相关
  467. const formRef = ref()
  468. const formData = ref({
  469. measureName: '',
  470. measureUnit: '',
  471. dutyPerson: '',
  472. brand: '',
  473. modelName: '',
  474. classify: '',
  475. buyDate: null,
  476. remark: '',
  477. deptId: '',
  478. measureCode: '',
  479. // validity: null, // 有效期
  480. measurePrice: 0, // 价格
  481. measureCertNo: ''
  482. })
  483. // 正确格式化日期的函数
  484. const formatDateCorrectly = (timestamp) => {
  485. if (!timestamp) return ''
  486. // 如果是秒级时间戳,转换为毫秒级
  487. let time = Number(timestamp)
  488. if (time < 10000000000) {
  489. // 小于这个数通常表示秒级时间戳
  490. time = time * 1000
  491. }
  492. return formatDate(time).substring(0, 10)
  493. }
  494. // 表单验证规则
  495. const formRules = {
  496. measureName: [{ required: true, message: '计量器具名称不能为空', trigger: 'blur' }],
  497. dutyPerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
  498. classify: [{ required: true, message: '分类不能为空', trigger: 'blur' }],
  499. deptId: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
  500. measureCertNo: [{ required: true, message: '证书编码不能为空', trigger: 'blur' }],
  501. validity: [{ required: true, message: '有效期不能为空', trigger: 'blur' }]
  502. }
  503. /** 查询列表 */
  504. const getList = async () => {
  505. loading.value = true
  506. try {
  507. const data = await IotInstrumentApi.getInstrumentList(queryParams)
  508. list.value = data.list
  509. total.value = data.total
  510. } finally {
  511. loading.value = false
  512. }
  513. }
  514. const downloadFile = (response: any) => {
  515. // 创建 blob 对象
  516. const blob = new Blob([response], {
  517. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
  518. })
  519. // 获取文件名
  520. let fileName = '计量器具台账.xlsx'
  521. const disposition = response.headers ? response.headers['content-disposition'] : ''
  522. if (disposition) {
  523. const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
  524. const matches = filenameRegex.exec(disposition)
  525. if (matches != null && matches[1]) {
  526. fileName = matches[1].replace(/['"]/g, '')
  527. }
  528. }
  529. // 创建下载链接
  530. const url = window.URL.createObjectURL(blob)
  531. const link = document.createElement('a')
  532. link.href = url
  533. link.setAttribute('download', fileName)
  534. // 触发下载
  535. document.body.appendChild(link)
  536. link.click()
  537. // 清理
  538. document.body.removeChild(link)
  539. window.URL.revokeObjectURL(url)
  540. }
  541. const handleExport = async () => {
  542. try {
  543. exportLoading.value = true
  544. // 调用导出接口
  545. const response = await IotInstrumentApi.exportInstrument(queryParams)
  546. // 下载文件
  547. downloadFile(response)
  548. exportLoading.value = false
  549. } catch (error) {
  550. ElMessage.error('导出失败,请重试')
  551. console.error('导出错误:', error)
  552. } finally {
  553. }
  554. }
  555. /** 首页处理部门被点击 */
  556. const handleDeptNodeClick = async (row) => {
  557. queryParams.deptId = row.id
  558. await getList()
  559. await getStatic()
  560. }
  561. /** 搜索按钮操作 */
  562. const handleQuery = () => {
  563. queryParams.pageNo = 1
  564. getList()
  565. }
  566. /** 重置按钮操作 */
  567. const resetQuery = () => {
  568. queryFormRef.value?.resetFields()
  569. handleQuery()
  570. }
  571. // 显示新增对话框
  572. const handleAdd = () => {
  573. isEdit.value = false
  574. dialogTitle.value = '新增台账'
  575. resetForm()
  576. formData.value.deptId = userStore.getUser.deptId // 默认选择当前用户的部门
  577. dialogVisible.value = true
  578. }
  579. // 显示编辑对话框
  580. const handleEdit = (row) => {
  581. isEdit.value = true
  582. dialogTitle.value = '编辑台账'
  583. formData.value = {
  584. ...row,
  585. // 确保日期字段正确处理
  586. buyDate: row.buyDate ? ensureMillisecondTimestamp(row.buyDate) : null,
  587. validity: row.validity ? ensureMillisecondTimestamp(row.validity) : null
  588. }
  589. dialogVisible.value = true
  590. }
  591. // 关闭抽屉
  592. const closeDrawer = () => {
  593. drawerVisible.value = false
  594. measureDetectionData.value = []
  595. }
  596. // 抽屉相关响应式数据
  597. const drawerVisible = ref(false)
  598. const drawerLoading = ref(false)
  599. const measureDetectionData = ref([])
  600. let totalMsg = ref(0)
  601. let currentId = ref(null)
  602. let queryParams2 = reactive({
  603. pageNo: 1,
  604. pageSize: 10,
  605. measureId: null
  606. })
  607. const handleView = async (id: any) => {
  608. drawerLoading.value = true
  609. currentId.value = id
  610. try {
  611. const response = await IotMeasureDetectApi.getIotMeasureDetectPage({
  612. pageNo: queryParams2.pageNo,
  613. pageSize: queryParams2.pageSize,
  614. measureId: id
  615. })
  616. measureDetectionData.value = response.list || []
  617. totalMsg.value = response.total
  618. drawerVisible.value = true
  619. } catch (error) {
  620. console.error('获取检测信息失败:', error)
  621. } finally {
  622. drawerLoading.value = false
  623. }
  624. }
  625. const getList2 = async () => {
  626. drawerLoading.value = true
  627. try {
  628. const response = await IotMeasureDetectApi.getIotMeasureDetectPage({
  629. pageNo: queryParams2.pageNo,
  630. pageSize: queryParams2.pageSize,
  631. measureId: currentId.value
  632. })
  633. measureDetectionData.value = response.list || []
  634. totalMsg.value = response.total
  635. drawerVisible.value = true
  636. } catch (error) {
  637. console.error('获取检测信息失败:', error)
  638. } finally {
  639. drawerLoading.value = false
  640. }
  641. }
  642. // 确保时间戳是毫秒级的
  643. const ensureMillisecondTimestamp = (timestamp) => {
  644. let time = Number(timestamp)
  645. if (time < 10000000000) {
  646. // 秒级时间戳转为毫秒级
  647. return time * 1000
  648. }
  649. return time
  650. }
  651. //删除成套
  652. const handleDelete = async (id: number) => {
  653. ElMessageBox.confirm('确定要删除该台账吗?', '提示', {
  654. confirmButtonText: '确定',
  655. cancelButtonText: '取消',
  656. type: 'warning'
  657. })
  658. .then(async () => {
  659. try {
  660. await IotInstrumentApi.deleteInstrument(id)
  661. ElMessage.success('删除成功')
  662. getList()
  663. } catch (error) {
  664. console.error(error)
  665. }
  666. })
  667. .catch(() => {
  668. // 取消操作
  669. })
  670. }
  671. // 重置表单
  672. const resetForm = () => {
  673. formData.value = {
  674. measureName: '',
  675. measureUnit: '',
  676. dutyPerson: '',
  677. brand: '',
  678. modelName: '',
  679. classify: '',
  680. buyDate: null,
  681. remark: '',
  682. deptId: '',
  683. measureCode: '',
  684. // validity: null, // 有效期
  685. measurePrice: 0, // 价格
  686. measureCertNo: ''
  687. }
  688. formRef.value?.clearValidate()
  689. }
  690. // 关闭对话框
  691. const closeDialog = () => {
  692. dialogVisible.value = false
  693. resetForm()
  694. }
  695. // 提交表单
  696. const submitForm = async () => {
  697. if (!formRef.value) return
  698. try {
  699. await formRef.value.validate()
  700. submitLoading.value = true
  701. // 准备提交数据
  702. const submitData = {
  703. ...formData.value,
  704. // 确保日期字段以正确的格式提交
  705. buyDate: formData.value.buyDate,
  706. validity: formData.value.validity
  707. }
  708. if (isEdit.value) {
  709. // 编辑
  710. await IotInstrumentApi.updateInstrument(submitData)
  711. ElMessage.success('编辑成功')
  712. } else {
  713. // 新增
  714. await IotInstrumentApi.createInstrument(submitData)
  715. ElMessage.success('新增成功')
  716. }
  717. dialogVisible.value = false
  718. getList()
  719. } catch (error) {
  720. console.error(error)
  721. } finally {
  722. submitLoading.value = false
  723. }
  724. }
  725. let dialogFileView = ref(false)
  726. let fileList = ref([])
  727. const viewFile = (file) => {
  728. fileList.value = file.split(',')
  729. dialogFileView.value = true
  730. // window.open(file)
  731. }
  732. const viewFileInfo = (file) => {
  733. window.open(
  734. 'http://doc.deepoil.cc:8012/onlinePreview?url=' + encodeURIComponent(Base64.encode(file))
  735. )
  736. }
  737. const extractFileName = (url: string): string => {
  738. try {
  739. // 移除查询参数和哈希
  740. const cleanUrl = url.split('?')[0].split('#')[0]
  741. // 获取最后一个斜杠后的内容
  742. const parts = cleanUrl.split('/')
  743. const fileName = parts[parts.length - 1]
  744. // URL 解码
  745. return decodeURIComponent(fileName) || url
  746. } catch {
  747. // 如果解析失败,返回原始 URL
  748. return url
  749. }
  750. }
  751. const handleDownload = async (url) => {
  752. try {
  753. const response = await fetch(url)
  754. const blob = await response.blob()
  755. const downloadUrl = window.URL.createObjectURL(blob)
  756. const link = document.createElement('a')
  757. link.href = downloadUrl
  758. link.download = url.split('/').pop() // 自动获取文件名‌:ml-citation{ref="3" data="citationList"}
  759. link.click()
  760. URL.revokeObjectURL(downloadUrl)
  761. } catch (error) {
  762. console.error('下载失败:', error)
  763. }
  764. }
  765. let staticData = ref<StaticItem[]>([])
  766. let expired = ref(0)
  767. let warn = ref(0)
  768. let staticChart: echarts.ECharts | null = null
  769. function getStaticChartOption(): echarts.EChartsOption {
  770. return {
  771. tooltip: {
  772. trigger: 'axis',
  773. axisPointer: {
  774. type: 'shadow'
  775. }
  776. },
  777. grid: {
  778. left: 16,
  779. right: 16,
  780. top: 24,
  781. bottom: 16,
  782. containLabel: true
  783. },
  784. xAxis: {
  785. type: 'category',
  786. data: staticData.value.map((item) => item.classify),
  787. axisTick: {
  788. show: false
  789. },
  790. axisLine: {
  791. lineStyle: {
  792. color: '#d9e2ef'
  793. }
  794. },
  795. axisLabel: {
  796. color: '#6b7280',
  797. fontSize: 12,
  798. interval: 0
  799. }
  800. },
  801. yAxis: {
  802. type: 'value',
  803. axisLine: {
  804. show: false
  805. },
  806. axisTick: {
  807. show: false
  808. },
  809. axisLabel: {
  810. color: '#94a3b8',
  811. fontSize: 12
  812. },
  813. splitLine: {
  814. lineStyle: {
  815. color: '#edf2f7',
  816. type: 'dashed'
  817. }
  818. }
  819. },
  820. series: [
  821. {
  822. type: 'bar',
  823. barWidth: 32,
  824. data: staticData.value.map((item) => item.count),
  825. itemStyle: {
  826. borderRadius: [8, 8, 0, 0],
  827. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  828. { offset: 0, color: '#79b8ff' },
  829. { offset: 1, color: '#2f78f6' }
  830. ])
  831. },
  832. label: {
  833. show: true,
  834. position: 'top',
  835. color: '#2563eb',
  836. fontSize: 12,
  837. fontWeight: 700
  838. }
  839. }
  840. ]
  841. }
  842. }
  843. function renderStaticChart() {
  844. if (!staticChartRef.value) return
  845. if (!staticChart) {
  846. staticChart = echarts.init(staticChartRef.value)
  847. }
  848. staticChart.setOption(getStaticChartOption(), true)
  849. }
  850. function resizeStaticChart() {
  851. staticChart?.resize()
  852. }
  853. function destroyStaticChart() {
  854. if (staticChart) {
  855. staticChart.dispose()
  856. staticChart = null
  857. }
  858. }
  859. async function getStatic() {
  860. if (queryParams.deptId) {
  861. const res = await IotInstrumentApi.getInstrumentStatistics(queryParams.deptId)
  862. staticData.value = res.classify
  863. expired.value = res.expired
  864. warn.value = res.warn
  865. } else {
  866. const res = await IotInstrumentApi.getInstrumentStatistics(userStore.user.deptId)
  867. staticData.value = res.classify
  868. expired.value = res.expired
  869. warn.value = res.warn
  870. }
  871. nextTick(() => {
  872. renderStaticChart()
  873. })
  874. }
  875. onMounted(async () => {
  876. getList()
  877. getStatic()
  878. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  879. deptList2.value = handleTree(await DeptApi.getSimpleDeptList())
  880. window.addEventListener('resize', resizeStaticChart)
  881. })
  882. onUnmounted(() => {
  883. window.removeEventListener('resize', resizeStaticChart)
  884. destroyStaticChart()
  885. })
  886. </script>
  887. <style scoped>
  888. ::deep(.el-tree--highlight-current) {
  889. height: 200px !important;
  890. }
  891. ::deep(.el-transfer-panel__body) {
  892. height: 700px !important;
  893. }
  894. .stats-cards {
  895. display: grid;
  896. grid-template-columns: 180px 180px minmax(0, 1fr);
  897. gap: 12px;
  898. margin-bottom: 16px;
  899. align-items: stretch;
  900. }
  901. .stats-card {
  902. padding: 14px 16px;
  903. background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
  904. border: 1px solid #e4ecf7;
  905. border-radius: 10px;
  906. box-shadow: 0 4px 12px rgb(31 91 184 / 8%);
  907. }
  908. .stats-card__label {
  909. font-size: 14px;
  910. font-weight: 600;
  911. color: #6b7280;
  912. line-height: 1.4;
  913. }
  914. .stats-card__value {
  915. margin-top: 8px;
  916. font-size: 28px;
  917. font-weight: 700;
  918. line-height: 1;
  919. color: #1f5bb8;
  920. }
  921. .stats-card--expired {
  922. background: linear-gradient(180deg, #fff4f4 0%, #ffe8e8 100%);
  923. border-color: #ffcfcf;
  924. }
  925. .stats-card--expired .stats-card__value {
  926. color: #de3b3b;
  927. }
  928. .stats-card--warn {
  929. background: linear-gradient(180deg, #fff8ef 0%, #ffeed9 100%);
  930. border-color: #ffd7a1;
  931. }
  932. .stats-card--warn .stats-card__value {
  933. color: #d97706;
  934. }
  935. .stats-chart-card {
  936. padding: 14px 16px 10px;
  937. background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
  938. border: 1px solid #e4ecf7;
  939. border-radius: 10px;
  940. box-shadow: 0 4px 12px rgb(31 91 184 / 8%);
  941. }
  942. .stats-chart {
  943. height: 130px;
  944. margin-top: 6px;
  945. }
  946. .stats-card {
  947. padding: 14px 16px;
  948. background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
  949. border: 1px solid #e4ecf7;
  950. border-radius: 10px;
  951. box-shadow: 0 4px 12px rgb(31 91 184 / 8%);
  952. }
  953. .stats-card__header {
  954. display: flex;
  955. align-items: center;
  956. gap: 8px;
  957. }
  958. .stats-card__icon {
  959. color: inherit;
  960. opacity: 0.85;
  961. }
  962. .stats-card__label {
  963. font-size: 14px;
  964. font-weight: 600;
  965. color: #6b7280;
  966. line-height: 1.4;
  967. }
  968. .stats-card__value {
  969. margin-top: 8px;
  970. font-size: 28px;
  971. font-weight: 700;
  972. line-height: 1;
  973. color: #1f5bb8;
  974. }
  975. .stats-card__desc {
  976. margin-top: 8px;
  977. font-size: 12px;
  978. color: #9ca3af;
  979. font-weight: 500;
  980. }
  981. .stats-card--expired {
  982. background: linear-gradient(180deg, #fff4f4 0%, #ffe8e8 100%);
  983. border-color: #ffcfcf;
  984. }
  985. .stats-card--expired .stats-card__value {
  986. color: #de3b3b;
  987. }
  988. .stats-card--expired .stats-card__icon {
  989. color: #de3b3b;
  990. }
  991. .stats-card--warn {
  992. background: linear-gradient(180deg, #fff8ef 0%, #ffeed9 100%);
  993. border-color: #ffd7a1;
  994. }
  995. .stats-card--warn .stats-card__value {
  996. color: #d97706;
  997. }
  998. .stats-card--warn .stats-card__icon {
  999. color: #d97706;
  1000. }
  1001. /* 过期行的红色背景 - 基础状态 */
  1002. :deep(.el-table__body tr.expired-row > td.el-table__cell) {
  1003. background-color: #ffe6e6 !important;
  1004. }
  1005. /* 过期行 - 鼠标悬浮状态 */
  1006. :deep(.el-table__body tr.expired-row:hover > td.el-table__cell) {
  1007. background-color: #ffcccc !important;
  1008. }
  1009. /* 确保斑马纹不影响过期行 */
  1010. :deep(.el-table__body tr.expired-row.el-table__row--striped > td.el-table__cell) {
  1011. background-color: #ffe6e6 !important;
  1012. }
  1013. :deep(.el-table__body tr.expired-row.el-table__row--striped:hover > td.el-table__cell) {
  1014. background-color: #ffcccc !important;
  1015. }
  1016. /* 预警行的橙色背景 - 基础状态 */
  1017. :deep(.el-table__body tr.alert-warn-row > td.el-table__cell) {
  1018. background-color: #fff1df !important;
  1019. }
  1020. /* 预警行 - 鼠标悬浮状态 */
  1021. :deep(.el-table__body tr.alert-warn-row:hover > td.el-table__cell) {
  1022. background-color: #ffe2bf !important;
  1023. }
  1024. /* 确保斑马纹不影响预警行 */
  1025. :deep(.el-table__body tr.alert-warn-row.el-table__row--striped > td.el-table__cell) {
  1026. background-color: #fff1df !important;
  1027. }
  1028. :deep(.el-table__body tr.alert-warn-row.el-table__row--striped:hover > td.el-table__cell) {
  1029. background-color: #ffe2bf !important;
  1030. }
  1031. </style>