index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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="state.filter" :inline="true" @submit.stop.prevent style="margin-bottom: -3vh;">
  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="state.filter.OilCompanyName" 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="state.filter.SerialNumber" 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-select v-model="state.filter.DeviceStatus" placeholder="请选择状态">
  22. <el-option label="所有" :value="''"></el-option>
  23. <el-option v-for="(value, key) in DeviceStatusEnum" :key="key" :label="value" :value="key" />
  24. </el-select>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  28. <el-form-item label="在线状态">
  29. <el-select v-model="state.filter.onlineStatus" placeholder="请选择在线状态">
  30. <el-option label="所有" :value="''"></el-option>
  31. <el-option v-for="(value, key) in OnlineStatusEnum" :key="key" :label="value" :value="key" />
  32. </el-select>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  36. <el-form-item label="安装时间">
  37. <el-date-picker
  38. v-model="state.dateRange"
  39. format="YYYY-MM-DD"
  40. value-format="YYYY-MM-DD"
  41. type="daterange"
  42. start-placeholder="开始时间"
  43. end-placeholder="结束时间"
  44. :clearable="false"
  45. ></el-date-picker>
  46. </el-form-item>
  47. </el-col>
  48. </el-form-item>
  49. </el-form>
  50. <hr>
  51. <div class="my-flex my-flex-start">
  52. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  53. <el-button type="primary" icon="ele-RefreshRight" @click="onReset" style="margin-left: 10px;"> 重置 </el-button>
  54. </div>
  55. </el-card>
  56. </el-col>
  57. <!-- 表格区域 -->
  58. <el-col :xs="24">
  59. <el-card style="height: 70vh" class="my-fill mt8" shadow="hover">
  60. <el-table
  61. ref="multipleTableRef"
  62. v-loading="state.loading"
  63. stripe
  64. :data="state.tableModel"
  65. row-key="id"
  66. style="width: 100%">
  67. <el-table-column
  68. v-for="column in state.dynamicColumns"
  69. :key="column.prop"
  70. :prop="column.prop"
  71. :label="column.label">
  72. <template #default="{ row }">
  73. <template v-if="column.prop === 'onlineStatus'">
  74. <StatusBox :status="row.onlineStatus" />
  75. </template>
  76. <template v-else-if="column.prop === 'deviceStatus'">
  77. <StatusBox :status="row.deviceStatus" />
  78. </template>
  79. <template v-else>
  80. {{ row[column.prop] }}
  81. </template>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. <div class="my-flex my-flex-end" style="margin-top: 20px">
  86. <el-pagination
  87. v-model:currentPage="pageState.pageInput.currentPage"
  88. v-model:page-size="pageState.pageInput.pageSize"
  89. :total="state.total"
  90. :page-sizes="[10, 15, 20, 50, 100]"
  91. small
  92. background
  93. @size-change="onSizeChange"
  94. @current-change="onCurrentChange"
  95. layout="total, sizes, prev, pager, next, jumper"
  96. />
  97. </div>
  98. </el-card>
  99. </el-col>
  100. </el-row>
  101. </div>
  102. </template>
  103. <script setup lang="ts">
  104. import { onBeforeMount, onMounted, reactive, ref, watch } from "vue";
  105. import { useRoute } from "vue-router";
  106. import eventBus from "/@/utils/mitt";
  107. import { PageInput, encodercontrolsDto } from "/@/api/admin/reportManagement/encodercontrols/encodercontrolsdto";
  108. import { Api } from "/@/api/admin/reportManagement/encodercontrols/encodercontrolsapi";
  109. import StatusBox from "/@/components/StatusBox.vue";
  110. import { useDynamicPageSize } from "/@/composables/useDynamicPageSize";
  111. import { ElMessage } from "element-plus";
  112. // 初始化路由实例(接收参数)
  113. const route = useRoute();
  114. const multipleTableRef = ref<any>(null);
  115. // 使用组合式函数获取分页状态
  116. const pageState = useDynamicPageSize(10, 15);
  117. /** 状态枚举 */
  118. enum OnlineStatusEnum {
  119. online = '在线',
  120. offline = '离线'
  121. }
  122. enum DeviceStatusEnum {
  123. unregister = "未备案",
  124. produce = "已生产",
  125. register = "已备案",
  126. bind = "已绑定油机",
  127. factory = "已出厂注册",
  128. enable = "已启用",
  129. disable = "维修中"
  130. }
  131. /** 数据对象 */
  132. const state = reactive({
  133. dateRange: [] as [string, string], // 用于存储日期范围
  134. /** 加载显示 */
  135. loading: false,
  136. /** 条件查询模块 */
  137. filter: {
  138. // 开始日期
  139. startDate: "",
  140. // 结束日期
  141. endDate: "",
  142. // 石油公司
  143. OilCompanyName: "",
  144. // 序列号(编码器编号)
  145. SerialNumber: "",
  146. // 绑定加油机厂商
  147. BindingDispenserManufacturer: "",
  148. // 安全装置状态
  149. DeviceStatus: "",
  150. // 安装时间
  151. FixTime: "",
  152. // 在线状态
  153. onlineStatus: "",
  154. // 出厂时间
  155. SoldTime: "",
  156. },
  157. /** 表格信息 */
  158. tableModel: [] as encodercontrolsDto[],
  159. /** 动态表头 */
  160. dynamicColumns: [
  161. { prop: 'oilCompanyName', label: '石油公司' },
  162. { prop: 'stationName', label: '加油站名称' },
  163. { prop: 'serialNumber', label: '编码器编号' },
  164. { prop: 'bindingDispenserManufacturer', label: '加油机厂商' },
  165. { prop: 'dispenserNumber', label: '油机号' },
  166. { prop: 'nozzleNumber', label: '油枪号' },
  167. { prop: 'deviceStatus', label: '编码器状态' },
  168. { prop: 'onlineStatus', label: '在线状态' },
  169. { prop: 'fixTime', label: '安装时间' },
  170. { prop: 'soldTime', label: '出厂时间' },
  171. ],
  172. /** 分页总数 */
  173. total: 0,
  174. /** 分页标识 */
  175. pageInput: {
  176. currentPage: 1,
  177. pageSize: 10,
  178. } as PageInput,
  179. })
  180. /** 页面加载时接收参数并查询 */
  181. onMounted(async () => {
  182. // 初始化分页大小
  183. state.pageInput.pageSize = pageState.pageInput.pageSize;
  184. // 从路由参数中获取编码器编号
  185. const { queryParam } = route.query;
  186. if (queryParam && typeof queryParam === 'string') {
  187. // 设置到序列号查询条件中
  188. state.filter.SerialNumber = queryParam;
  189. }
  190. // 触发查询
  191. await init();
  192. // 监听路由参数变化(防止同页面刷新参数丢失)
  193. watch(() => route.query, (newQuery) => {
  194. if (newQuery.queryParam && typeof newQuery.queryParam === 'string') {
  195. state.filter.SerialNumber = newQuery.queryParam;
  196. init(); // 参数变化时重新查询
  197. }
  198. }, { immediate: false });
  199. });
  200. /** 页条数变化 */
  201. const onSizeChange = (val: number) => {
  202. state.pageInput.pageSize = val;
  203. init();
  204. }
  205. /** 页数变化 */
  206. const onCurrentChange = (val: number) => {
  207. state.pageInput.currentPage = val;
  208. init();
  209. }
  210. /** 监听日期范围变化 */
  211. watch(
  212. () => state.dateRange,
  213. (newVal) => {
  214. if (newVal && newVal.length === 2) {
  215. state.filter.startDate = newVal[0]; // 开始时间
  216. state.filter.endDate = newVal[1]; // 结束时间
  217. } else {
  218. state.filter.startDate = "";
  219. state.filter.endDate = "";
  220. }
  221. }
  222. );
  223. /** 条件查询 */
  224. const onQuery = () => {
  225. init();
  226. }
  227. /** 重置查询条件 */
  228. const onReset = () => {
  229. state.dateRange = [] as [string, string];
  230. state.filter = {
  231. startDate: "",
  232. endDate: "",
  233. OilCompanyName: "",
  234. SerialNumber: "",
  235. BindingDispenserManufacturer: "",
  236. DeviceStatus: "",
  237. FixTime: "",
  238. onlineStatus: "",
  239. SoldTime: "",
  240. };
  241. state.pageInput.currentPage = 1;
  242. init();
  243. }
  244. /** 初始化查询接口 */
  245. const init = async () => {
  246. state.loading = true;
  247. try {
  248. // 调用编码器查询接口
  249. const res: any = await new Api().getList({
  250. ...state.pageInput,
  251. Filter: state.filter
  252. });
  253. state.total = res?.data?.total ?? 0;
  254. state.tableModel = res?.data?.list ?? [];
  255. } catch (error) {
  256. console.error('编码器查询失败:', error);
  257. ElMessage.error('数据加载失败,请重试');
  258. } finally {
  259. state.loading = false;
  260. }
  261. };
  262. // 清理事件监听
  263. onBeforeMount(() => {
  264. eventBus.off('refreshView');
  265. });
  266. </script>
  267. <style scoped lang="scss">
  268. .my-flex {
  269. margin-top: 20px;
  270. }
  271. .el-input,
  272. .el-select {
  273. width: 240px;
  274. }
  275. /* 输入框标签固定宽度 */
  276. ::v-deep .el-form-item__label {
  277. width: 14*5px + 12px;
  278. justify-content: start;
  279. }
  280. /* 数据表头样式 */
  281. ::v-deep .el-table th.el-table__cell {
  282. background-color: #F6F6F6;
  283. }
  284. </style>