IotDeviceMainAlarm.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <el-row :gutter="20">
  3. <!-- 左侧部门树 -->
  4. <el-col :span="4" :xs="24">
  5. <ContentWrap class="h-1/1" v-if="treeShow">
  6. <DeptTree @node-click="handleDeptNodeClick" />
  7. </ContentWrap>
  8. </el-col>
  9. <el-col :span="contentSpan" :xs="24">
  10. <ContentWrap>
  11. <!-- 搜索工作栏 -->
  12. <el-form
  13. class="-mb-15px"
  14. :model="queryParams"
  15. ref="queryFormRef"
  16. :inline="true"
  17. label-width="68px"
  18. >
  19. <el-form-item :label="t('iotDevice.code')" prop="deviceCode" style="margin-left: 25px">
  20. <el-input
  21. v-model="queryParams.deviceCode"
  22. :placeholder="t('iotDevice.codeHolder')"
  23. clearable
  24. @keyup.enter="handleQuery"
  25. class="!w-200px"
  26. />
  27. </el-form-item>
  28. <el-form-item :label="t('iotDevice.name')" prop="deviceName">
  29. <el-input
  30. v-model="queryParams.deviceName"
  31. :placeholder="t('iotDevice.nameHolder')"
  32. clearable
  33. @keyup.enter="handleQuery"
  34. class="!w-200px"
  35. />
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button @click="handleQuery"
  39. ><Icon icon="ep:search" class="mr-5px" /> {{ t('file.search') }}</el-button
  40. >
  41. <el-button @click="resetQuery"
  42. ><Icon icon="ep:refresh" class="mr-5px" /> {{ t('file.reset') }}</el-button
  43. >
  44. <el-button
  45. type="success"
  46. plain
  47. @click="handleExport"
  48. :loading="exportLoading"
  49. v-hasPermi="['rq:iot-device:export']"
  50. >
  51. <Icon icon="ep:download" class="mr-5px" /> 导出
  52. </el-button>
  53. </el-form-item>
  54. </el-form>
  55. </ContentWrap>
  56. <!-- 列表 -->
  57. <ContentWrap>
  58. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  59. <el-table-column :label="t('monitor.serial')" width="70" align="center">
  60. <template #default="scope">
  61. {{ scope.$index + 1 }}
  62. </template>
  63. </el-table-column>
  64. <el-table-column :label="t('iotDevice.code')" align="center" prop="deviceCode" />
  65. <el-table-column :label="t('iotDevice.name')" align="center" prop="deviceName">
  66. <template #default="scope">
  67. <el-link :underline="false" type="primary" @click="handleDetail(scope.row.id)">
  68. {{ scope.row.deviceName }}
  69. </el-link>
  70. </template>
  71. </el-table-column>
  72. <el-table-column :label="t('bomList.serviceDue')" align="center">
  73. <template #default="scope">
  74. <template v-if="hasMaintenancePlan(scope.row.mainDistance)">
  75. <span :class="getDistanceClass(scope.row.mainDistance)">
  76. {{ scope.row.mainDistance }}
  77. </span>
  78. </template>
  79. <span v-else>无保养计划</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column :label="t('iotDevice.dept')" align="center" prop="deptName" />
  83. <el-table-column :label="t('devicePerson.rp')" align="center" prop="responsibleNames" />
  84. <el-table-column :label="t('monitor.status')" align="center" prop="deviceStatus">
  85. <template #default="scope">
  86. <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.deviceStatus" />
  87. </template>
  88. </el-table-column>
  89. <!-- 工单状态列 -->
  90. <el-table-column :label="t('operationFill.status')" align="center">
  91. <template #default="scope">
  92. <span v-if="scope.row.shouldWorkOrder && scope.row.runningWorkOrder">
  93. {{ t('mainPlan.generatedNotExecuted') }}
  94. </span>
  95. <span v-else-if="scope.row.shouldWorkOrder && !scope.row.runningWorkOrder">
  96. {{ t('mainPlan.notGenerated') }}
  97. </span>
  98. <span v-else>-</span>
  99. </template>
  100. </el-table-column>
  101. <el-table-column :label="t('monitor.operation')" align="center" min-width="60px">
  102. <template #default="scope">
  103. <el-button
  104. link
  105. type="primary"
  106. @click="openBomForm(scope.row)"
  107. v-hasPermi="['rq:iot-device:query']"
  108. v-if="hasMaintenancePlan(scope.row.mainDistance)"
  109. >
  110. {{ t('monitor.details') }}
  111. </el-button>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. <!-- 分页 -->
  116. <Pagination
  117. :total="total"
  118. v-model:page="queryParams.pageNo"
  119. v-model:limit="queryParams.pageSize"
  120. @pagination="getList"
  121. />
  122. </ContentWrap>
  123. </el-col>
  124. </el-row>
  125. <DeviceAlarmBomList ref="modelFormRef" :flag="flag" />
  126. </template>
  127. <script setup lang="ts">
  128. import download from '@/utils/download'
  129. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  130. import { IotMainWorkOrderApi } from '@/api/pms/iotmainworkorder'
  131. import { DICT_TYPE } from '@/utils/dict'
  132. import DeptTree from '@/views/system/user/DeptTree.vue'
  133. import { useCache } from '@/hooks/web/useCache'
  134. import DeviceAlarmBomList from '@/views/pms/iotmainworkorder/DeviceAlarmBomList.vue'
  135. /** 设备台账 列表 */
  136. defineOptions({ name: 'IotDeviceMainAlarm' })
  137. const message = useMessage() // 消息弹窗
  138. const { t } = useI18n() // 国际化
  139. const { push } = useRouter() // 路由跳转
  140. const modelFormRef = ref()
  141. const loading = ref(true) // 列表的加载中
  142. const ifShow = ref(false)
  143. const list = ref<IotDeviceVO[]>([]) // 列表的数据
  144. const total = ref(0) // 列表的总页数
  145. const queryParams = reactive({
  146. pageNo: 1,
  147. pageSize: 10,
  148. deviceCode: undefined,
  149. deviceName: undefined,
  150. brand: undefined,
  151. model: undefined,
  152. deptId: undefined,
  153. deviceStatus: undefined,
  154. assetProperty: undefined,
  155. picUrl: undefined,
  156. remark: undefined,
  157. manufacturerId: undefined,
  158. supplierId: undefined,
  159. manDate: [],
  160. nameplate: undefined,
  161. expires: undefined,
  162. plPrice: undefined,
  163. plDate: [],
  164. plYear: undefined,
  165. plStartDate: [],
  166. plMonthed: undefined,
  167. plAmounted: undefined,
  168. remainAmount: undefined,
  169. infoId: undefined,
  170. infoType: undefined,
  171. infoName: undefined,
  172. infoRemark: undefined,
  173. infoUrl: undefined,
  174. templateJson: undefined,
  175. creator: undefined,
  176. setFlag: ''
  177. })
  178. const queryFormRef = ref() // 搜索的表单
  179. const flag = ref() // 查询保养计划或保养工单的标识
  180. const exportLoading = ref(false) // 导出的加载中
  181. const contentSpan = ref(20)
  182. const treeShow = ref(true)
  183. /** 查询列表 */
  184. const getList = async () => {
  185. loading.value = true
  186. try {
  187. const data = await IotMainWorkOrderApi.deviceMainDistances(queryParams)
  188. list.value = data.list
  189. total.value = data.total
  190. } finally {
  191. loading.value = false
  192. }
  193. }
  194. /** 处理部门被点击 */
  195. const handleDeptNodeClick = async (row) => {
  196. queryParams.deptId = row.id
  197. await getList()
  198. }
  199. /** 搜索按钮操作 */
  200. const handleQuery = () => {
  201. queryParams.pageNo = 1
  202. getList()
  203. }
  204. /** 重置按钮操作 */
  205. const resetQuery = () => {
  206. queryFormRef.value.resetFields()
  207. handleQuery()
  208. }
  209. const getDistanceClass = (distance: number | string | null) => {
  210. if (distance === null || distance === undefined) return ''
  211. // 如果是数字类型,直接处理
  212. if (typeof distance === 'number') {
  213. return distance < 0 ? 'negative-distance' : distance > 0 ? 'positive-distance' : ''
  214. }
  215. // 如果是字符串,提取数字部分
  216. if (typeof distance === 'string') {
  217. // 使用正则提取数字部分(包括负号、小数点和科学计数法)
  218. const numericPart = distance.match(/[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/)?.[0]
  219. // 如果提取到数字部分,转换为数值
  220. if (numericPart) {
  221. const num = parseFloat(numericPart)
  222. return num < 0 ? 'negative-distance' : num > 0 ? 'positive-distance' : ''
  223. }
  224. }
  225. return ''
  226. }
  227. // 判断是否有保养计划
  228. const hasMaintenancePlan = (mainDistance: any) => {
  229. // 检查:非null、非undefined、非空字符串
  230. return mainDistance != null && mainDistance !== ''
  231. }
  232. const handleDetail = (id: number) => {
  233. push({ name: 'DeviceDetailInfo', params: { id } })
  234. }
  235. const drawerVisible = ref<boolean>(false)
  236. const showDrawer = ref()
  237. const openBomForm = async (row) => {
  238. // 构建设备信息对象,包含所有需要的属性
  239. const deviceInfo = {
  240. deviceId: row.id,
  241. deviceCode: row.deviceCode,
  242. deviceName: row.deviceName,
  243. model: row.model // 新增 model 属性
  244. }
  245. if (row.workOrderId) {
  246. flag.value = 'workOrder'
  247. modelFormRef.value.open(row.workOrderId, flag.value, row.id)
  248. } else if (row.planId) {
  249. flag.value = 'plan'
  250. modelFormRef.value.open(row.planId, flag.value, deviceInfo)
  251. }
  252. }
  253. /** 导出按钮操作 */
  254. const handleExport = async () => {
  255. try {
  256. exportLoading.value = true
  257. const data = await IotDeviceApi.exportIotDeviceMainAlarm(queryParams)
  258. download.excel(data, '保养查询.xls')
  259. } catch {
  260. } finally {
  261. exportLoading.value = false
  262. }
  263. }
  264. const { wsCache } = useCache()
  265. /** 初始化 **/
  266. onMounted(() => {
  267. getList()
  268. })
  269. </script>
  270. <style scoped>
  271. /* 正数样式 - 淡绿色 */
  272. .positive-distance {
  273. color: #67c23a; /* element-plus 成功色 */
  274. background-color: rgba(103, 194, 58, 0.1); /* 10% 透明度的淡绿色背景 */
  275. padding: 2px 8px;
  276. border-radius: 4px;
  277. display: inline-block;
  278. }
  279. /* 负数样式 - 淡红色 */
  280. .negative-distance {
  281. color: #f56c6c; /* element-plus 危险色 */
  282. background-color: rgba(245, 108, 108, 0.1); /* 10% 透明度的淡红色背景 */
  283. padding: 2px 8px;
  284. border-radius: 4px;
  285. display: inline-block;
  286. }
  287. </style>