index.vue 18 KB

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