index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div class="layout-pd">
  3. <el-row>
  4. <!--操作-->
  5. <el-col :xs="24">
  6. <el-card class="mt8" shadow="hover">
  7. <el-form :model="oilEngineData.filterModel" @submit.stop.prevent>
  8. <el-form-item prop="name" style="width:100%">
  9. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  10. <el-form-item label="油机号">
  11. <el-input v-model="oilEngineData.filterModel.name" placeholder="请输入油机号" clearable></el-input>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  15. <el-form-item label="加油站">
  16. <el-input v-model="oilEngineData.filterModel.gasStation" placeholder="请输入加油站" clearable></el-input>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  20. <el-form-item label="加油机机型">
  21. <el-input v-model="oilEngineData.filterModel.model" placeholder="请输入加油机机型" clearable></el-input>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  25. <el-form-item label="设备状态">
  26. <el-select v-model="oilEngineData.filterModel.deviceStatus" placeholder="请输入设备状态">
  27. <el-option label="所有" :value="''"></el-option>
  28. <el-option v-for="(value, key) in FuelDispenserEnum" :key="key" :label="value" :value="key" />
  29. </el-select>
  30. <!-- <el-input v-model="oilEngineData.filterModel.deviceStatus" placeholder="请输入设备状态" clearable></el-input> -->
  31. </el-form-item>
  32. </el-col>
  33. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  34. <el-form-item label="在线状态">
  35. <el-select v-model="oilEngineData.filterModel.onlineStatus" placeholder="请输入在线状态">
  36. <el-option label="所有" :value="''"></el-option>
  37. <el-option v-for="(value, key) in OnlineStatus" :key="key" :label="value" :value="key" />
  38. </el-select>
  39. <!-- <el-input v-model="oilEngineData.filterModel.onlineStatus" placeholder="请输入在线状态" clearable></el-input> -->
  40. </el-form-item>
  41. </el-col>
  42. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  43. <el-form-item label="序列号">
  44. <el-input v-model="oilEngineData.filterModel.serialNumber" placeholder="请输入序列号" clearable></el-input>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  48. <el-form-item label="安装时间">
  49. <el-date-picker
  50. v-model="oilEngineData.filterModel.createTimeRange"
  51. value-format="YYYY-MM-DD"
  52. type="daterange"
  53. range-separator="To"
  54. start-placeholder="开始时间"
  55. end-placeholder="结束时间"
  56. :clearable="false"
  57. ></el-date-picker>
  58. </el-form-item>
  59. </el-col>
  60. </el-form-item>
  61. </el-form>
  62. <hr>
  63. <!-- 按钮 -->
  64. <el-row justify="space-between" class="submit-button" style="margin-bottom:-6px">
  65. <el-row>
  66. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  67. <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
  68. </el-row>
  69. <el-button type="primary" icon="ele-Document" @click="exportDataToExcel"> 导出 </el-button>
  70. </el-row>
  71. </el-card>
  72. </el-col>
  73. <!--列表-->
  74. <el-col :xs="24">
  75. <el-card class="my-fill mt8" shadow="hover">
  76. <el-table v-loading="oilEngineData.loading" stripe :data="oilEngineData.tableModel" row-key="id"
  77. style="width: 100%" id="myTable" ref="myTable">
  78. <el-table-column prop="name" label="油机号" />
  79. <el-table-column prop="oilCompany" label="石油公司" />
  80. <el-table-column prop="gasStation" label="加油站" />
  81. <el-table-column prop="serialNumber" label="序列号" />
  82. <el-table-column prop="model" label="加油机机型" />
  83. <el-table-column prop="gunCount" label="加油机枪数量" />
  84. <!-- <el-table-column prop="manufacturer" label="加油机厂商" /> -->
  85. <el-table-column prop="manufactureDate" label="出厂时间" />
  86. <el-table-column prop="startupDate" label="启动时间" />
  87. <el-table-column prop="installationDate" label="安装时间" />
  88. <el-table-column prop="deviceStatus" label="设备状态">
  89. <template #default="{ row }">
  90. <div :style="{ color: getColor(getOilEngineStatus(row.deviceStatus)) }" class="bold-font">
  91. <StatusBox :status="getOilEngineStatus(row.deviceStatus)" />
  92. <!-- {{ getOilEngineStatus(row.deviceStatus) }} -->
  93. </div>
  94. </template>
  95. </el-table-column>
  96. <el-table-column prop="onlineStatus" label="在线状态">
  97. <template #default="{ row }">
  98. <div :style="{ color: getColor(getOilEngineStatus(row.onlineStatus)) }" class="bold-font">
  99. <StatusBox :status="getOilEngineStatus(row.onlineStatus)" />
  100. <!-- {{ getOilEngineStatus(row.onlineStatus) }} -->
  101. </div>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="操作" fixed="right" header-align="center" align="center" class="right-operation"
  105. width="100">
  106. <template #default="{ row }">
  107. <el-link class="my-el-link mr12 ml12" @click="toPage(row)" type="primary" icon="ele-Tickets"
  108. :underline="false" target="_blank">详情</el-link>
  109. </template>
  110. </el-table-column>
  111. </el-table>
  112. <div class="my-flex my-flex-end" style="margin-top: 20px">
  113. <el-pagination
  114. v-model:currentPage="pageState.pageInput.currentPage"
  115. v-model:page-size="pageState.pageInput.pageSize"
  116. :total="oilEngineData.total"
  117. :page-sizes="[5, 10, 15, 20, 50, 100]"
  118. layout="total, sizes, prev, pager, next, jumper"
  119. @size-change="onSizeChange"
  120. @current-change="onCurrentChange"
  121. />
  122. </div>
  123. </el-card>
  124. </el-col>
  125. </el-row>
  126. </div>
  127. </template>
  128. <script setup lang="ts">
  129. import { onBeforeMount, onMounted, reactive, ref, watch } from "vue";
  130. import { ListOfOilEnginesApi } from "/@/api/admin/reportManagement/listOfOilEngines/listOfOilEnginesApi";
  131. import { FuelDispenserDto_SearchFilter, PageInputFuelDispenserDto, FuelDispenserDto } from "/@/api/admin/reportManagement/listOfOilEngines/listOfOilEnginesDto";
  132. import eventBus from "/@/utils/mitt";
  133. import { useGlobalCacheStore } from "/@/stores/globalCacheStore";
  134. import router from "/@/router";
  135. import StatusBox from "../../../../components/StatusBox.vue";
  136. import { BoardListApi } from '/@/api/admin/PCBA/boardListApi';
  137. import dayjs from 'dayjs';
  138. import { useDynamicPageSize } from "/@/composables/useDynamicPageSize";
  139. // 使用组合式函数获取分页状态
  140. const pageState = useDynamicPageSize(10, 15);
  141. /**获取全局缓存*/
  142. const globalCacheStore = useGlobalCacheStore()
  143. // /**油机列表 - 列表状态 */
  144. // const oilEngineStatusType = ref(globalCacheStore.getGlobalStore().get('oilEngineStatusType'))
  145. /**油机列表 - 列表设备状态、在线状态 */
  146. const oilEngineStatus = ref(globalCacheStore.getGlobalStore().get('oilEngineStatus'))
  147. /**
  148. * 油机列表数据对象
  149. */
  150. const oilEngineData = reactive({
  151. time:'',
  152. loading: false,
  153. filterModel: {
  154. /**油机号*/
  155. name: "",
  156. oilCompany:"",
  157. /**加油站*/
  158. gasStation: "",
  159. createTimeRange: [], // 新增属性,用于存储时间范围
  160. /**加油机机型*/
  161. model: "",
  162. /**设备状态*/
  163. deviceStatus: "",
  164. /**在线状态*/
  165. onlineStatus: "",
  166. /**序列号*/
  167. serialNumber: "",
  168. /**开始时间*/
  169. startDate: null,
  170. /**结束时间*/
  171. endDate:null,
  172. installationDate:"",
  173. startupDate:"",
  174. } as FuelDispenserDto_SearchFilter,
  175. total: 0,
  176. pageInput: {
  177. currentPage: 1,
  178. pageSize: 10,
  179. } as PageInputFuelDispenserDto,
  180. tableModel: [] as Array<FuelDispenserDto>
  181. })
  182. /**设备状态*/
  183. enum FuelDispenserEnum {
  184. enable = '启用',
  185. register = '备案',
  186. disable = '维修',
  187. factory = '出产注册'
  188. }
  189. /**在线状态*/
  190. enum OnlineStatus {
  191. online = '在线',
  192. offline = '离线'
  193. }
  194. /**将filterModel对象成.的连接方式*/
  195. const flattenObject = (obj, parentKey = '') => {
  196. const result = {};
  197. for (const key in obj) {
  198. if (obj.hasOwnProperty(key)) {
  199. const newKey = parentKey ? `${parentKey}.${key}` : key;
  200. if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
  201. const flattened = flattenObject(obj[key], newKey);
  202. Object.assign(result, flattened);
  203. } else {
  204. result[newKey] = obj[key];
  205. }
  206. }
  207. }
  208. return result;
  209. }
  210. /** 导出 */
  211. const exportDataToExcel = async () => {
  212. const res: any = await new ListOfOilEnginesApi().onExportExcel({ ...oilEngineData.pageInput, filter: oilEngineData.filterModel })
  213. }
  214. /**重置 */
  215. const onReset = () => {
  216. resetQuery()
  217. init()
  218. }
  219. /**条件查询 */
  220. const onQuery = () => {
  221. init()
  222. }
  223. // 修改分页处理方法
  224. const onSizeChange = (val: number) => {
  225. pageState.pageInput.pageSize = val
  226. oilEngineData.pageInput.pageSize = val
  227. oilEngineData.pageInput.currentPage = 1 // 通常切换size会回到第一页
  228. init()
  229. }
  230. const onCurrentChange = (val: number) => {
  231. pageState.pageInput.currentPage = val
  232. oilEngineData.pageInput.currentPage = val
  233. init()
  234. }
  235. const toPage = (row) => {
  236. router.push({ path: `/statement/${row.fuelId}` })
  237. }
  238. /**
  239. * 监听时间变换
  240. */
  241. watch(
  242. () => oilEngineData.filterModel.createTimeRange,
  243. (newVal) => {
  244. if (newVal && newVal.length === 2) {
  245. oilEngineData.filterModel.startDate = newVal[0]; // yyyy-MM-dd 格式
  246. oilEngineData.filterModel.endDate = newVal[1];
  247. } else {
  248. oilEngineData.filterModel.startDate = null;
  249. oilEngineData.filterModel.endDate = null;
  250. }
  251. }
  252. );
  253. // /**油机列表 - 列表状态 */
  254. // const getOilEngineStatusType = (val) => {
  255. // val = String(val)
  256. // if(oilEngineStatusType.value?.has(val)){
  257. // return oilEngineStatusType.value.get(val)
  258. // }else {
  259. // return val
  260. // }
  261. // }
  262. /**油机列表 - 列表设备状态、在线状态 */
  263. const getOilEngineStatus = (val) => {
  264. val = String(val)
  265. if (oilEngineStatus.value.has(val)) {
  266. return oilEngineStatus.value.get(val)
  267. } else {
  268. return val
  269. }
  270. }
  271. /**初始化 */
  272. const init = async () => {
  273. oilEngineData.loading = true
  274. try {
  275. const res = await new ListOfOilEnginesApi().getPage({
  276. currentPage: oilEngineData.pageInput.currentPage, // 使用小写
  277. pageSize: oilEngineData.pageInput.pageSize, // 使用小写
  278. filter: oilEngineData.filterModel
  279. })
  280. console.log('API Response:', res)
  281. oilEngineData.tableModel = res?.data?.list ?? []
  282. oilEngineData.total = res?.data?.total ?? 0
  283. } finally {
  284. oilEngineData.loading = false
  285. }
  286. }
  287. /**重置查询条件 */
  288. const resetQuery = () => {
  289. oilEngineData.filterModel.name = ''
  290. oilEngineData.filterModel.gasStation = ''
  291. oilEngineData.filterModel.model = ''
  292. oilEngineData.filterModel.deviceStatus = ''
  293. oilEngineData.filterModel.onlineStatus = ''
  294. oilEngineData.filterModel.installationDate = ''
  295. oilEngineData.filterModel.serialNumber = ''
  296. oilEngineData.filterModel.createTimeRange = null
  297. }
  298. //设置不同设备状态、在线状态字体颜色
  299. const getColor = (value: string): string => {
  300. if (value === '在线' || value === '启用') {
  301. return '#41b584';
  302. } else if (value === '出厂注册') {
  303. return '#409eff';
  304. } else if (value === '备案') {
  305. return '#E6A23C';
  306. } else {
  307. return '#F34D37'
  308. }
  309. }
  310. // /**油机列表 - 列表状态 */
  311. // const getOilEngineStatusType = (val) => {
  312. // val = String(val)
  313. // if(oilEngineStatusType.value?.has(val)){
  314. // return oilEngineStatusType.value.get(val)
  315. // }else {
  316. // return val
  317. // }
  318. // }
  319. onMounted(() => {
  320. // 初始化分页大小
  321. oilEngineData.pageInput.pageSize = pageState.pageInput.pageSize;
  322. oilEngineData.pageInput.currentPage = 1; // 初始化时重置为第一页
  323. init()
  324. eventBus.off('refreshView')
  325. eventBus.on('refreshView', async () => {
  326. await init()
  327. })
  328. })
  329. onBeforeMount(() => {
  330. eventBus.off('refreshView')
  331. })
  332. </script>
  333. <style scoped lang="scss">
  334. .el-input,
  335. .el-select,
  336. {
  337. width: 240px;
  338. }
  339. .el-date-picker {
  340. width: 240px !important;
  341. }
  342. /* 输入框标签固定四个字符宽度 */
  343. ::v-deep .el-form-item__label {
  344. // 字体大小14,5个字符,12px右间距
  345. width: 14*5px+12px;
  346. justify-content: start;
  347. }
  348. /* 数据表头 设置灰色样式 */
  349. ::v-deep .el-table th.el-table__cell {
  350. background-color: #F6F6F6;
  351. }
  352. </style>