index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="项目" prop="contractName">
  12. <el-input
  13. v-model="queryParams.contractName"
  14. placeholder="请输入项目"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="任务" prop="taskName">
  21. <el-input
  22. v-model="queryParams.taskName"
  23. placeholder="请输入任务"
  24. clearable
  25. @keyup.enter="handleQuery"
  26. class="!w-240px"
  27. />
  28. </el-form-item>
  29. <el-form-item label="创建时间" prop="createTime">
  30. <el-date-picker
  31. v-model="queryParams.createTime"
  32. value-format="YYYY-MM-DD HH:mm:ss"
  33. type="daterange"
  34. start-placeholder="开始日期"
  35. end-placeholder="结束日期"
  36. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  37. class="!w-220px"
  38. />
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  42. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  43. <el-button
  44. type="primary"
  45. plain
  46. @click="openForm('create')"
  47. v-hasPermi="['pms:iot-rd-daily-report:create']"
  48. >
  49. <Icon icon="ep:plus" class="mr-5px" /> 新增
  50. </el-button>
  51. <el-button
  52. type="success"
  53. plain
  54. @click="handleExport"
  55. :loading="exportLoading"
  56. v-hasPermi="['pms:iot-rd-daily-report:export']"
  57. >
  58. <Icon icon="ep:download" class="mr-5px" /> 导出
  59. </el-button>
  60. </el-form-item>
  61. </el-form>
  62. </ContentWrap>
  63. <!-- 列表 -->
  64. <ContentWrap ref="tableContainerRef">
  65. <el-table ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  66. <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
  67. <el-table-column
  68. label="创建时间"
  69. align="center"
  70. prop="createTime"
  71. :formatter="dateFormatter"
  72. :width="columnWidths.createTime"
  73. />
  74. <el-table-column label="施工队伍" align="center" prop="deptName" :width="columnWidths.deptName"/>
  75. <el-table-column label="项目" align="center" prop="contractName" :width="columnWidths.contractName"/>
  76. <el-table-column label="任务" align="center" prop="taskName" :width="columnWidths.taskName"/>
  77. <el-table-column label="时间节点" align="center" prop="timeRange" :width="columnWidths.timeRange"/>
  78. <el-table-column :label="t('project.status')" align="center" prop="rdStatus" :width="columnWidths.rdStatus">
  79. <template #default="scope">
  80. <dict-tag :type="DICT_TYPE.PMS_PROJECT_RD_STATUS" :value="scope.row.rdStatus" />
  81. </template>
  82. </el-table-column>
  83. <!--
  84. <el-table-column label="项目类别(钻井 修井 注氮 酸化压裂... )" align="center" prop="projectClassification" />
  85. <el-table-column label="施工工艺" align="center" prop="techniqueIds" /> -->
  86. <!--
  87. <el-table-column label="施工设备" align="center" prop="deviceIds" /> -->
  88. <!--
  89. <el-table-column label="时间节点-结束" align="center" prop="endTime" /> -->
  90. <el-table-column label="当日施工井" align="center" prop="cumulativeWorkingWell" :width="columnWidths.cumulativeWorkingWell"/>
  91. <el-table-column label="当日施工层" align="center" prop="cumulativeWorkingLayers" :width="columnWidths.cumulativeWorkingLayers"/>
  92. <el-table-column label="当日泵车台次" align="center" prop="dailyPumpTrips" :width="columnWidths.dailyPumpTrips"/>
  93. <el-table-column label="当日仪表/混砂" align="center" prop="dailyToolsSand" :width="columnWidths.dailyToolsSand"/>
  94. <el-table-column label="趟数" align="center" prop="runCount" :width="columnWidths.runCount"/>
  95. <el-table-column label="桥塞" align="center" prop="bridgePlug" :width="columnWidths.bridgePlug"/>
  96. <el-table-column label="水方量" align="center" prop="waterVolume" :width="columnWidths.waterVolume"/>
  97. <el-table-column label="时间H" align="center" prop="hourCount" :width="columnWidths.hourCount"/>
  98. <el-table-column
  99. label="施工开始日期"
  100. align="center"
  101. prop="constructionStartDate"
  102. :formatter="dateFormatter"
  103. :width="columnWidths.constructionStartDate"
  104. />
  105. <el-table-column
  106. label="施工结束日期"
  107. align="center"
  108. prop="constructionEndDate"
  109. :formatter="dateFormatter"
  110. :width="columnWidths.constructionEndDate"
  111. />
  112. <el-table-column label="当日生产动态" align="center" prop="productionStatus" :width="columnWidths.productionStatus"/>
  113. <el-table-column label="下步工作计划" align="center" prop="nextPlan" :width="columnWidths.nextPlan"/>
  114. <el-table-column label="外租设备" align="center" prop="externalRental" :width="columnWidths.externalRental"/>
  115. <el-table-column label="故障情况" align="center" prop="malfunction" :width="columnWidths.malfunction"/>
  116. <el-table-column label="故障误工H" align="center" prop="faultDowntime" :width="columnWidths.faultDowntime"/>
  117. <el-table-column label="操作" align="center" min-width="120px" fixed="right">
  118. <template #default="scope">
  119. <el-button
  120. link
  121. type="success"
  122. @click="handleDetail(scope.row.id)"
  123. v-hasPermi="['pms:iot-rd-daily-report:query']"
  124. >
  125. 查看
  126. </el-button>
  127. <el-button
  128. link
  129. type="warning"
  130. @click="handleApprove(scope.row.id)"
  131. v-hasPermi="['pms:iot-rd-daily-report:update']"
  132. v-if="scope.row.auditStatus === 10"
  133. >
  134. 审批
  135. </el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <!-- 分页 -->
  140. <Pagination
  141. :total="total"
  142. v-model:page="queryParams.pageNo"
  143. v-model:limit="queryParams.pageSize"
  144. @pagination="getList"
  145. />
  146. </ContentWrap>
  147. <!-- 表单弹窗:添加/修改 -->
  148. <IotRdDailyReportForm ref="formRef" @success="getList" />
  149. </template>
  150. <script setup lang="ts">
  151. import { dateFormatter } from '@/utils/formatTime'
  152. import download from '@/utils/download'
  153. import { IotRdDailyReportApi, IotRdDailyReportVO } from '@/api/pms/iotrddailyreport'
  154. import IotRdDailyReportForm from './IotRdDailyReportForm.vue'
  155. import {DICT_TYPE} from "@/utils/dict";
  156. import { useRoute } from 'vue-router'
  157. /** 瑞都日报 列表 */
  158. defineOptions({ name: 'IotRdDailyReport' })
  159. const message = useMessage() // 消息弹窗
  160. const { t } = useI18n() // 国际化
  161. const { push } = useRouter() // 路由跳转
  162. const loading = ref(true) // 列表的加载中
  163. const list = ref<IotRdDailyReportVO[]>([]) // 列表的数据
  164. const total = ref(0) // 列表的总页数
  165. const route = useRoute() // 路由信息
  166. const queryParams = reactive({
  167. pageNo: 1,
  168. pageSize: 10,
  169. deptId: undefined,
  170. projectId: undefined,
  171. contractName: undefined,
  172. taskId: undefined,
  173. taskName: undefined,
  174. projectClassification: undefined,
  175. techniqueIds: undefined,
  176. deviceIds: undefined,
  177. startTime: [],
  178. endTime: [],
  179. cumulativeWorkingWell: undefined,
  180. cumulativeWorkingLayers: undefined,
  181. dailyPumpTrips: undefined,
  182. dailyToolsSand: undefined,
  183. runCount: undefined,
  184. bridgePlug: undefined,
  185. waterVolume: undefined,
  186. hourCount: undefined,
  187. dailyFuel: undefined,
  188. dailyPowerUsage: undefined,
  189. productionTime: [],
  190. nonProductionTime: [],
  191. rdNptReason: undefined,
  192. constructionStartDate: [],
  193. constructionEndDate: [],
  194. productionStatus: undefined,
  195. externalRental: undefined,
  196. nextPlan: undefined,
  197. rdStatus: undefined,
  198. malfunction: undefined,
  199. faultDowntime: [],
  200. personnel: undefined,
  201. totalStaffNum: undefined,
  202. leaveStaffNum: undefined,
  203. extProperty: undefined,
  204. sort: undefined,
  205. remark: undefined,
  206. status: undefined,
  207. processInstanceId: undefined,
  208. auditStatus: undefined,
  209. createTime: [],
  210. })
  211. const queryFormRef = ref() // 搜索的表单
  212. const exportLoading = ref(false) // 导出的加载中
  213. // 表格引用
  214. const tableRef = ref()
  215. // 表格容器引用
  216. const tableContainerRef = ref()
  217. // 列宽度配置
  218. const columnWidths = ref({
  219. id: '80px',
  220. deptName: '120px',
  221. contractName: '120px',
  222. taskName: '120px',
  223. timeRange: '120px',
  224. rdStatus: '120px',
  225. cumulativeWorkingWell: '120px',
  226. cumulativeWorkingLayers: '120px',
  227. dailyPumpTrips: '120px',
  228. dailyToolsSand: '120px',
  229. runCount: '80px',
  230. bridgePlug: '80px',
  231. waterVolume: '100px',
  232. hourCount: '80px',
  233. constructionStartDate: '180px',
  234. constructionEndDate: '180px',
  235. productionStatus: '200px',
  236. nextPlan: '200px',
  237. externalRental: '120px',
  238. malfunction: '150px',
  239. faultDowntime: '120px',
  240. createTime: '180px',
  241. operation: '120px'
  242. })
  243. // 计算文本宽度
  244. const getTextWidth = (text: string, fontSize = 14) => {
  245. const span = document.createElement('span');
  246. span.style.visibility = 'hidden';
  247. span.style.position = 'absolute';
  248. span.style.whiteSpace = 'nowrap';
  249. span.style.fontSize = `${fontSize}px`;
  250. span.style.fontFamily = 'inherit';
  251. span.innerText = text;
  252. document.body.appendChild(span);
  253. const width = span.offsetWidth;
  254. document.body.removeChild(span);
  255. return width;
  256. };
  257. // 计算列宽度
  258. const calculateColumnWidths = () => {
  259. const MIN_WIDTH = 80; // 最小列宽
  260. const PADDING = 25; // 列内边距
  261. // 确保表格容器存在
  262. if (!tableContainerRef.value?.$el) return;
  263. const newWidths: Record<string, string> = {};
  264. // 计算各列宽度的函数
  265. const calculateColumnWidth = (key: string, label: string, getValue: Function) => {
  266. const headerWidth = getTextWidth(label) + PADDING;
  267. let contentMaxWidth = MIN_WIDTH;
  268. // 计算内容最大宽度
  269. list.value.forEach((row, index) => {
  270. let text = '';
  271. if (key === 'rdStatus') {
  272. // 特殊处理字典列,这里简化处理,实际应该获取字典标签
  273. text = String(row[key] || '');
  274. } else if (key.includes('Date') || key === 'createTime') {
  275. // 日期列使用格式化后的值
  276. text = dateFormatter(null, null, row[key]) || '';
  277. } else {
  278. text = String(getValue ? getValue(row, index) : (row[key] || ''));
  279. }
  280. const textWidth = getTextWidth(text) + PADDING;
  281. if (textWidth > contentMaxWidth) contentMaxWidth = textWidth;
  282. });
  283. // 取标题宽度和内容最大宽度的较大值
  284. const finalWidth = Math.max(headerWidth, contentMaxWidth, MIN_WIDTH);
  285. newWidths[key] = `${finalWidth}px`;
  286. };
  287. // 计算各列宽度
  288. calculateColumnWidth('deptName', '施工队伍', (row: any) => row.deptName);
  289. calculateColumnWidth('contractName', '项目', (row: any) => row.contractName);
  290. calculateColumnWidth('taskName', '任务', (row: any) => row.taskName);
  291. calculateColumnWidth('timeRange', '时间节点', (row: any) => row.timeRange);
  292. calculateColumnWidth('rdStatus', t('project.status'), (row: any) => row.rdStatus);
  293. calculateColumnWidth('cumulativeWorkingWell', '累计施工井', (row: any) => row.cumulativeWorkingWell);
  294. calculateColumnWidth('cumulativeWorkingLayers', '累计施工层', (row: any) => row.cumulativeWorkingLayers);
  295. calculateColumnWidth('dailyPumpTrips', '当日泵车台次', (row: any) => row.dailyPumpTrips);
  296. calculateColumnWidth('dailyToolsSand', '当日仪表/混砂', (row: any) => row.dailyToolsSand);
  297. calculateColumnWidth('runCount', '趟数', (row: any) => row.runCount);
  298. calculateColumnWidth('bridgePlug', '桥塞', (row: any) => row.bridgePlug);
  299. calculateColumnWidth('waterVolume', '水方量', (row: any) => row.waterVolume);
  300. calculateColumnWidth('hourCount', '时间H', (row: any) => row.hourCount);
  301. calculateColumnWidth('constructionStartDate', '施工开始日期', (row: any) => dateFormatter(null, null, row.constructionStartDate));
  302. calculateColumnWidth('constructionEndDate', '施工结束日期', (row: any) => dateFormatter(null, null, row.constructionEndDate));
  303. calculateColumnWidth('productionStatus', '当日生产动态', (row: any) => row.productionStatus);
  304. calculateColumnWidth('nextPlan', '下步工作计划', (row: any) => row.nextPlan);
  305. calculateColumnWidth('externalRental', '外租设备', (row: any) => row.externalRental);
  306. calculateColumnWidth('malfunction', '故障情况', (row: any) => row.malfunction);
  307. calculateColumnWidth('faultDowntime', '故障误工H', (row: any) => row.faultDowntime);
  308. calculateColumnWidth('createTime', '创建时间', (row: any) => dateFormatter(null, null, row.createTime));
  309. // 操作列固定宽度
  310. newWidths.operation = '120px';
  311. // id列固定宽度(虽然隐藏)
  312. newWidths.id = '80px';
  313. // 更新列宽配置
  314. columnWidths.value = newWidths;
  315. // 触发表格重新布局
  316. nextTick(() => {
  317. tableRef.value?.doLayout();
  318. });
  319. };
  320. /** 查询列表 */
  321. const getList = async () => {
  322. loading.value = true
  323. try {
  324. const data = await IotRdDailyReportApi.getIotRdDailyReportPage(queryParams)
  325. list.value = data.list
  326. total.value = data.total
  327. // 获取数据后计算列宽
  328. nextTick(() => {
  329. calculateColumnWidths();
  330. });
  331. } finally {
  332. loading.value = false
  333. }
  334. }
  335. /** 搜索按钮操作 */
  336. const handleQuery = () => {
  337. queryParams.pageNo = 1
  338. getList()
  339. }
  340. /** 重置按钮操作 */
  341. const resetQuery = () => {
  342. queryFormRef.value.resetFields()
  343. handleQuery()
  344. }
  345. /** 添加/修改操作 */
  346. const formRef = ref()
  347. const openForm = (type: string, id?: number) => {
  348. formRef.value.open(type, id)
  349. }
  350. /** 查看日报详情 */
  351. const handleDetail = async (id: number) => {
  352. try {
  353. // 跳转到 FillDailyReportForm 页面,传递审批模式和ID
  354. push({
  355. name: 'FillDailyReportForm',
  356. params: {
  357. id: id.toString(),
  358. mode: 'detail' // 添加详情模式标识
  359. }
  360. })
  361. } catch (error) {
  362. console.error('跳转详情页面失败:', error)
  363. }
  364. }
  365. /** 审批按钮操作 */
  366. const handleApprove = async (id: number) => {
  367. try {
  368. // 跳转到 FillDailyReportForm 页面,传递审批模式和ID
  369. push({
  370. name: 'FillDailyReportForm',
  371. params: {
  372. id: id.toString(),
  373. mode: 'approval' // 添加审批模式标识
  374. }
  375. })
  376. } catch (error) {
  377. console.error('跳转审批页面失败:', error)
  378. }
  379. }
  380. /** 删除按钮操作 */
  381. const handleDelete = async (id: number) => {
  382. try {
  383. // 删除的二次确认
  384. await message.delConfirm()
  385. // 发起删除
  386. await IotRdDailyReportApi.deleteIotRdDailyReport(id)
  387. message.success(t('common.delSuccess'))
  388. // 刷新列表
  389. await getList()
  390. } catch {}
  391. }
  392. /** 导出按钮操作 */
  393. const handleExport = async () => {
  394. try {
  395. // 导出的二次确认
  396. await message.exportConfirm()
  397. // 发起导出
  398. exportLoading.value = true
  399. const data = await IotRdDailyReportApi.exportIotRdDailyReport(queryParams)
  400. download.excel(data, '瑞都日报.xls')
  401. } catch {
  402. } finally {
  403. exportLoading.value = false
  404. }
  405. }
  406. // 声明 ResizeObserver 实例
  407. let resizeObserver: ResizeObserver | null = null;
  408. /** 初始化 **/
  409. onMounted(() => {
  410. // 检查是否有路由参数传递过来的 wellName
  411. if (route.query.wellName) {
  412. queryParams.taskName = route.query.wellName as string
  413. }
  414. getList()
  415. // 创建 ResizeObserver 监听表格容器尺寸变化
  416. if (tableContainerRef.value?.$el) {
  417. resizeObserver = new ResizeObserver(() => {
  418. // 使用防抖避免频繁触发
  419. clearTimeout((window as any).resizeTimer);
  420. (window as any).resizeTimer = setTimeout(() => {
  421. calculateColumnWidths();
  422. }, 100);
  423. });
  424. resizeObserver.observe(tableContainerRef.value.$el);
  425. }
  426. })
  427. onUnmounted(() => {
  428. // 清除 ResizeObserver
  429. if (resizeObserver && tableContainerRef.value?.$el) {
  430. resizeObserver.unobserve(tableContainerRef.value.$el);
  431. resizeObserver = null;
  432. }
  433. // 清除定时器
  434. if ((window as any).resizeTimer) {
  435. clearTimeout((window as any).resizeTimer);
  436. }
  437. })
  438. // 监听列表数据变化重新计算列宽
  439. watch(list, () => {
  440. nextTick(calculateColumnWidths)
  441. }, { deep: true })
  442. </script>
  443. <style scoped>
  444. /* 确保表格单元格内容不换行 */
  445. :deep(.el-table .cell) {
  446. white-space: nowrap;
  447. }
  448. /* 确保表格列标题不换行 */
  449. :deep(.el-table th > .cell) {
  450. white-space: nowrap;
  451. }
  452. /* 调整表格最小宽度,确保内容完全显示 */
  453. :deep(.el-table) {
  454. min-width: 100%;
  455. }
  456. </style>