DeviceStatus.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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="资产编码" prop="deviceCode">
  20. <el-input
  21. v-model="queryParams.deviceCode"
  22. placeholder="请输入资产编码"
  23. clearable
  24. @keyup.enter="handleQuery"
  25. class="!w-200px"
  26. />
  27. </el-form-item>
  28. <el-form-item label="设备名称" prop="deviceName">
  29. <el-input
  30. v-model="queryParams.deviceName"
  31. placeholder="请输入设备名称"
  32. clearable
  33. @keyup.enter="handleQuery"
  34. class="!w-200px"
  35. />
  36. </el-form-item>
  37. <el-form-item label="品牌" prop="brand">
  38. <el-input
  39. v-model="queryParams.brand"
  40. placeholder="请输入品牌"
  41. clearable
  42. @keyup.enter="handleQuery"
  43. class="!w-200px"
  44. />
  45. </el-form-item>
  46. <el-form-item label="是否调整了状态" prop="setFlag" label-width="140px">
  47. <el-select
  48. v-model="queryParams.setFlag"
  49. placeholder="请选择"
  50. clearable
  51. class="!w-240px"
  52. >
  53. <el-option
  54. v-for="dict in resultOptions"
  55. :key="dict.value"
  56. :label="dict.label"
  57. :value="dict.value"
  58. />
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item v-show="ifShow" label="设备状态" label-width="85px" prop="deviceStatus">
  62. <el-select
  63. v-model="queryParams.deviceStatus"
  64. placeholder="设备状态"
  65. clearable
  66. class="!w-240px"
  67. >
  68. <el-option
  69. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_DEVICE_STATUS)"
  70. :key="dict.value"
  71. :label="dict.label"
  72. :value="dict.value"
  73. />
  74. </el-select>
  75. </el-form-item>
  76. <el-form-item v-show="ifShow" label="资产性质" prop="assetProperty">
  77. <el-select
  78. v-model="queryParams.assetProperty"
  79. placeholder="资产性质"
  80. clearable
  81. class="!w-240px"
  82. >
  83. <el-option
  84. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_ASSET_PROPERTY)"
  85. :key="dict.value"
  86. :label="dict.label"
  87. :value="dict.value"
  88. />
  89. </el-select>
  90. </el-form-item>
  91. <el-form-item>
  92. <el-button v-if="!ifShow" @click="moreQuery(true)" type="warning"
  93. ><Icon icon="ep:search" class="mr-5px" /> 更多查询</el-button
  94. >
  95. <el-button v-if="ifShow" @click="moreQuery(false)" type="danger"
  96. ><Icon icon="ep:search" class="mr-5px" /> 收起查询</el-button
  97. >
  98. <el-button @click="handleQuery"
  99. ><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button
  100. >
  101. <el-button @click="resetQuery"
  102. ><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button
  103. >
  104. <el-button
  105. type="primary"
  106. plain
  107. @click="openForm('create', undefined, queryParams.deptId)"
  108. v-hasPermi="['rq:iot-device:create']"
  109. >
  110. <Icon icon="ep:plus" class="mr-5px" /> 调整状态
  111. </el-button>
  112. <el-button
  113. type="success"
  114. plain
  115. @click="handleExport"
  116. :loading="exportLoading"
  117. v-hasPermi="['rq:iot-device:export']"
  118. >
  119. <Icon icon="ep:download" class="mr-5px" /> 导出
  120. </el-button>
  121. </el-form-item>
  122. </el-form>
  123. </ContentWrap>
  124. <!-- 列表 -->
  125. <ContentWrap>
  126. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  127. <el-table-column label="序号" width="60" align="center">
  128. <template #default="scope">
  129. {{ scope.$index + 1 }}
  130. </template>
  131. </el-table-column>
  132. <el-table-column label="资产编码" align="center" prop="deviceCode" />
  133. <el-table-column label="设备名称" align="center" prop="deviceName">
  134. <template #default="scope">
  135. <el-link :underline="false" type="primary" @click="handleDetail(scope.row.id)">
  136. {{ scope.row.deviceName }}
  137. </el-link>
  138. </template>
  139. </el-table-column>
  140. <el-table-column label="所在部门" align="center" prop="deptName" />
  141. <el-table-column label="设备状态" align="center" prop="deviceStatus">
  142. <template #default="scope">
  143. <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.deviceStatus" />
  144. </template>
  145. </el-table-column>
  146. <!--
  147. <el-table-column
  148. label="创建时间"
  149. align="center"
  150. prop="createTime"
  151. :formatter="dateFormatter"
  152. width="180px"
  153. /> -->
  154. <el-table-column label="操作" align="center" min-width="120px">
  155. <template #default="scope">
  156. <el-button
  157. link
  158. type="primary"
  159. @click="handleView(scope.row.id)"
  160. v-hasPermi="['rq:iot-device:query']"
  161. >
  162. 调整记录
  163. </el-button>
  164. </template>
  165. </el-table-column>
  166. </el-table>
  167. <!-- 分页 -->
  168. <Pagination
  169. :total="total"
  170. v-model:page="queryParams.pageNo"
  171. v-model:limit="queryParams.pageSize"
  172. @pagination="getList"
  173. />
  174. </ContentWrap>
  175. </el-col>
  176. </el-row>
  177. <DeviceStatusLogDrawer
  178. :model-value="drawerVisible"
  179. @update:model-value="val => drawerVisible = val"
  180. :device-id="currentDeviceId"
  181. ref="showDrawer"
  182. />
  183. </template>
  184. <script setup lang="ts">
  185. import download from '@/utils/download'
  186. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  187. import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
  188. import { dateFormatter } from '@/utils/formatTime'
  189. import DeptTree from '@/views/system/user/DeptTree.vue'
  190. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  191. import DeviceStatusLogDrawer from "@/views/pms/device/DeviceStatusLogDrawer.vue";
  192. /** 设备台账 列表 */
  193. defineOptions({ name: 'IotDeviceStatus' })
  194. const message = useMessage() // 消息弹窗
  195. const { t } = useI18n() // 国际化
  196. const { push } = useRouter() // 路由跳转
  197. const drawerVisible = ref<boolean>(false)
  198. const loading = ref(true) // 列表的加载中
  199. const ifShow = ref(false)
  200. const isDetail = ref(false) // 是否查看详情
  201. const list = ref<IotDeviceVO[]>([]) // 列表的数据
  202. const total = ref(0) // 列表的总页数
  203. const currentDeviceId = ref() // 设备id
  204. const queryParams = reactive({
  205. pageNo: 1,
  206. pageSize: 10,
  207. deviceCode: undefined,
  208. deviceName: undefined,
  209. brand: undefined,
  210. model: undefined,
  211. deptId: undefined,
  212. deviceStatus: undefined,
  213. assetProperty: undefined,
  214. picUrl: undefined,
  215. remark: undefined,
  216. manufacturerId: undefined,
  217. supplierId: undefined,
  218. manDate: [],
  219. nameplate: undefined,
  220. expires: undefined,
  221. plPrice: undefined,
  222. plDate: [],
  223. plYear: undefined,
  224. plStartDate: [],
  225. plMonthed: undefined,
  226. plAmounted: undefined,
  227. remainAmount: undefined,
  228. infoId: undefined,
  229. infoType: undefined,
  230. infoName: undefined,
  231. infoRemark: undefined,
  232. infoUrl: undefined,
  233. templateJson: undefined,
  234. creator: undefined,
  235. setFlag: ''
  236. })
  237. const queryFormRef = ref() // 搜索的表单
  238. const exportLoading = ref(false) // 导出的加载中
  239. const contentSpan = ref(20)
  240. const treeShow = ref(true)
  241. const shou = (tree) =>{
  242. treeShow.value = !tree
  243. if (tree) {
  244. contentSpan.value = 20
  245. } else {
  246. contentSpan.value = 24
  247. }
  248. }
  249. /** 查询列表 */
  250. const getList = async () => {
  251. loading.value = true
  252. try {
  253. const data = await IotDeviceApi.statusRelationDevices(queryParams)
  254. list.value = data.list
  255. total.value = data.total
  256. } finally {
  257. loading.value = false
  258. }
  259. }
  260. // 是否设置过责任人 下拉列表 模拟字典项
  261. const resultOptions = computed(() => [
  262. {
  263. label: '全部',
  264. value: 'A' // 空值会触发 clearable 效果
  265. },
  266. {
  267. label: '是',
  268. value: 'Y' // 空值会触发 clearable 效果
  269. },
  270. {
  271. label: '否',
  272. value: 'N' // 空值会触发 clearable 效果
  273. },
  274. ])
  275. const showDrawer = ref()
  276. /** 查看设备状态调整详情 */
  277. const handleView = async (deviceId) => {
  278. currentDeviceId.value = deviceId
  279. drawerVisible.value = true
  280. showDrawer.value.openDrawer()
  281. // 强制刷新物料数据
  282. // await showDrawer.value.loadMaterials(nodeId)
  283. }
  284. /** 处理部门被点击 */
  285. const handleDeptNodeClick = async (row) => {
  286. queryParams.deptId = row.id
  287. await getList()
  288. }
  289. /** 搜索按钮操作 */
  290. const handleQuery = () => {
  291. queryParams.pageNo = 1
  292. getList()
  293. }
  294. const moreQuery = (show) => {
  295. ifShow.value = show
  296. }
  297. /** 重置按钮操作 */
  298. const resetQuery = () => {
  299. queryFormRef.value.resetFields()
  300. handleQuery()
  301. }
  302. /** 添加/修改操作 */
  303. const formRef = ref()
  304. const openForm = (type: string, id?: number) => {
  305. //修改
  306. if (typeof id === 'number') {
  307. push({ name: 'DeviceDetailEdit', params: { id } })
  308. return
  309. }
  310. // 新增
  311. push({ name: 'ConfigDeviceStatus', params: {} })
  312. }
  313. /** 删除按钮操作 */
  314. const handleDelete = async (id: number) => {
  315. try {
  316. // 删除的二次确认
  317. await message.delConfirm()
  318. // 发起删除
  319. await IotDeviceApi.deleteIotDevice(id)
  320. message.success(t('common.delSuccess'))
  321. // 刷新列表
  322. await getList()
  323. } catch {}
  324. }
  325. const handleDetail = (id: number) => {
  326. push({ name: 'DeviceDetailInfo', params: { id } })
  327. }
  328. const handleUpload = (id: number) => {
  329. push({ name: 'DeviceUpload', params: { id } })
  330. }
  331. /** 导出按钮操作 */
  332. const handleExport = async () => {
  333. try {
  334. // 导出的二次确认
  335. await message.exportConfirm()
  336. // 发起导出
  337. exportLoading.value = true
  338. const data = await IotDeviceApi.exportIotDevice(queryParams)
  339. download.excel(data, '设备台账.xls')
  340. } catch {
  341. } finally {
  342. exportLoading.value = false
  343. }
  344. }
  345. const { wsCache } = useCache()
  346. /** 初始化 **/
  347. onMounted(() => {
  348. const user = wsCache.get(CACHE_KEY.USER)
  349. // queryParams.deptId = user.user.deptId
  350. getList()
  351. })
  352. </script>
  353. <style scoped></style>