DeviceAllotLogDrawer.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <el-drawer
  3. :append-to-body="true"
  4. :model-value="modelValue"
  5. :show-close="false"
  6. direction="rtl"
  7. :size="computedSize"
  8. class="allot-log-drawer"
  9. :before-close="handleClose"
  10. @update:model-value="$emit('update:modelValue', $event)">
  11. <template #header>
  12. <div class="drawer-header">
  13. <div class="drawer-header__main">
  14. <div class="drawer-header__icon">
  15. <Icon icon="ep:position" :size="22" />
  16. </div>
  17. <div>
  18. <div class="drawer-title">{{ t('configPerson.adjustmentRecords') }}</div>
  19. <div class="drawer-subtitle">查看设备调拨前后的部门变化记录</div>
  20. </div>
  21. </div>
  22. <el-button circle size="default" @click="handleClose">
  23. <Icon icon="ep:close" />
  24. </el-button>
  25. </div>
  26. </template>
  27. <template v-if="deviceId">
  28. <div v-loading="loading" class="drawer-body">
  29. <section class="info-card record-card">
  30. <div class="info-card__header">
  31. <div class="info-card__title">
  32. <span class="info-card__marker"></span>
  33. <span>{{ t('configPerson.adjustmentRecords') }}</span>
  34. </div>
  35. <span class="record-total">共 {{ total }} 条</span>
  36. </div>
  37. <div class="info-card__body record-card__body">
  38. <ZmTable
  39. :data="deviceAllots"
  40. :loading="loading"
  41. :show-border="true"
  42. settings-cache-key="pms-device-allot-log"
  43. class="record-table">
  44. <ZmTableColumn
  45. prop="deviceName"
  46. :label="t('deviceStatus.deviceName')"
  47. min-width="170" />
  48. <ZmTableColumn
  49. prop="deviceCode"
  50. :label="t('deviceStatus.deviceCode')"
  51. min-width="150" />
  52. <ZmTableColumn
  53. prop="oldDeptName"
  54. :label="t('deviceStatus.beforeDept')"
  55. min-width="170" />
  56. <ZmTableColumn
  57. prop="newDeptName"
  58. :label="t('deviceStatus.afterDept')"
  59. min-width="170" />
  60. <ZmTableColumn
  61. prop="reason"
  62. :label="t('configDevice.reasonForAdjustment')"
  63. min-width="220"
  64. align="left" />
  65. <ZmTableColumn
  66. prop="creatorName"
  67. :label="t('deviceStatus.adjuster')"
  68. min-width="130" />
  69. <ZmTableColumn
  70. :label="t('deviceStatus.adjustTime')"
  71. prop="createTime"
  72. min-width="170"
  73. :formatter="dateFormatter" />
  74. </ZmTable>
  75. <Pagination
  76. v-show="total > 0"
  77. :total="total"
  78. v-model:page="queryParams.pageNo"
  79. v-model:limit="queryParams.pageSize"
  80. @pagination="handlePagination" />
  81. </div>
  82. </section>
  83. </div>
  84. </template>
  85. </el-drawer>
  86. </template>
  87. <script setup lang="ts">
  88. import { ref } from 'vue'
  89. import { ElMessage } from 'element-plus'
  90. import { useTableComponents } from '@/components/ZmTable/useTableComponents'
  91. import { IotDeviceAllotLogApi, type IotDeviceAllotLogVO } from '@/api/pms/iotdeviceallotlog'
  92. import { dateFormatter } from '@/utils/formatTime'
  93. type DeviceAllotLogRow = IotDeviceAllotLogVO & {
  94. createTime?: string
  95. }
  96. const { t } = useI18n()
  97. const { ZmTable, ZmTableColumn } = useTableComponents<DeviceAllotLogRow>()
  98. const emit = defineEmits(['update:modelValue', 'add', 'delete'])
  99. defineOptions({
  100. name: 'DeviceAllotLogDrawer'
  101. })
  102. const queryParams = reactive({
  103. pageNo: 1,
  104. pageSize: 10,
  105. createTime: [],
  106. deviceId: undefined as number | undefined,
  107. name: '',
  108. code: ''
  109. })
  110. const windowWidth = ref(window.innerWidth)
  111. const computedSize = computed(() => {
  112. if (windowWidth.value <= 768) return '100%'
  113. return windowWidth.value > 1200 ? '60%' : '80%'
  114. })
  115. const loading = ref(false)
  116. const total = ref(0)
  117. const deviceAllots = ref<DeviceAllotLogRow[]>([])
  118. const props = defineProps({
  119. modelValue: Boolean,
  120. deviceId: Number
  121. })
  122. const updateWindowWidth = () => {
  123. windowWidth.value = window.innerWidth
  124. }
  125. const loadDeviceAllots = async (deviceId: number, resetPage = true) => {
  126. queryParams.deviceId = deviceId
  127. if (resetPage) {
  128. queryParams.pageNo = 1
  129. }
  130. try {
  131. loading.value = true
  132. const data = await IotDeviceAllotLogApi.getIotDeviceAllotLogPage(queryParams)
  133. deviceAllots.value = data.list || []
  134. total.value = data.total || 0
  135. } catch (error) {
  136. ElMessage.error('数据加载失败')
  137. } finally {
  138. loading.value = false
  139. }
  140. }
  141. const handlePagination = (pagination: any) => {
  142. queryParams.pageNo = pagination.page
  143. queryParams.pageSize = pagination.limit
  144. if (props.deviceId) {
  145. loadDeviceAllots(props.deviceId, false)
  146. }
  147. }
  148. const openDrawer = () => {
  149. emit('update:modelValue', true)
  150. }
  151. const closeDrawer = () => {
  152. handleClose()
  153. }
  154. const handleClose = () => {
  155. emit('update:modelValue', false)
  156. deviceAllots.value = []
  157. total.value = 0
  158. }
  159. defineExpose({ openDrawer, closeDrawer, loadDeviceAllots })
  160. onMounted(() => {
  161. window.addEventListener('resize', updateWindowWidth)
  162. })
  163. onUnmounted(() => {
  164. window.removeEventListener('resize', updateWindowWidth)
  165. })
  166. </script>
  167. <style lang="scss" scoped>
  168. .drawer-header {
  169. display: flex;
  170. align-items: center;
  171. justify-content: space-between;
  172. gap: 16px;
  173. width: 100%;
  174. padding-right: 4px;
  175. }
  176. .drawer-header__main {
  177. display: flex;
  178. align-items: center;
  179. min-width: 0;
  180. }
  181. .drawer-header__icon {
  182. display: flex;
  183. align-items: center;
  184. justify-content: center;
  185. width: 42px;
  186. height: 42px;
  187. margin-right: 12px;
  188. color: var(--el-color-primary);
  189. background: var(--el-color-primary-light-9);
  190. border: 1px solid var(--el-color-primary-light-7);
  191. border-radius: 6px;
  192. }
  193. .drawer-title {
  194. font-size: 18px;
  195. font-weight: 600;
  196. line-height: 24px;
  197. color: var(--el-text-color-primary);
  198. }
  199. .drawer-subtitle {
  200. margin-top: 4px;
  201. font-size: 13px;
  202. color: var(--el-text-color-secondary);
  203. }
  204. .drawer-body {
  205. display: flex;
  206. flex-direction: column;
  207. gap: 16px;
  208. min-height: 100%;
  209. }
  210. .info-card {
  211. overflow: hidden;
  212. background: var(--el-bg-color);
  213. border: 1px solid var(--el-border-color-lighter);
  214. border-radius: 6px;
  215. }
  216. .info-card__header {
  217. display: flex;
  218. align-items: center;
  219. justify-content: space-between;
  220. min-height: 56px;
  221. padding: 0 20px;
  222. background: #f4f9ff;
  223. border-bottom: 1px solid var(--el-border-color-lighter);
  224. }
  225. .info-card__title {
  226. display: flex;
  227. align-items: center;
  228. font-size: 16px;
  229. font-weight: 600;
  230. color: var(--el-text-color-primary);
  231. }
  232. .info-card__marker {
  233. width: 4px;
  234. height: 18px;
  235. margin-right: 10px;
  236. background: var(--el-color-primary);
  237. border-radius: 4px;
  238. }
  239. .info-card__body {
  240. padding: 20px;
  241. }
  242. .record-card {
  243. flex: 1;
  244. min-height: 0;
  245. }
  246. .record-total {
  247. font-size: 13px;
  248. color: var(--el-text-color-secondary);
  249. }
  250. .record-card__body {
  251. display: flex;
  252. flex-direction: column;
  253. min-height: 420px;
  254. }
  255. .record-table {
  256. flex: 1;
  257. width: 100%;
  258. }
  259. :global(.allot-log-drawer .el-drawer__body) {
  260. padding: 0 24px 24px;
  261. }
  262. :global(.allot-log-drawer .el-drawer__header) {
  263. padding: 24px;
  264. margin-bottom: 0;
  265. }
  266. @media (width <= 768px) {
  267. :global(.allot-log-drawer .el-drawer__body) {
  268. padding: 0 16px 16px;
  269. }
  270. }
  271. </style>