FillDailyReportForm.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  3. <!-- 第一部分:日报标题 -->
  4. <div class="daily-report-title">
  5. <h2>{{ isApprovalMode ? dailyReportApprovalTitle : dailyReportTitle }}</h2>
  6. <!-- 在审批模式下显示审批状态提示 -->
  7. <div v-if="isApprovalMode" class="approval-notice">
  8. <el-alert title="审批模式:所有字段均为只读" type="info" :closable="false" />
  9. </div>
  10. </div>
  11. <!-- 第二部分:项目/任务信息 -->
  12. <ContentWrap>
  13. <div class="info-table" style="margin-top: 1em">
  14. <!-- 表格行 -->
  15. <div class="table-row">
  16. <div class="table-cell">
  17. <div class="cell-content">
  18. <span class="cell-label">甲方:</span>
  19. <!-- 甲方字段:添加 single-line-ellipsis 类 + title 绑定完整内容 -->
  20. <span
  21. class="cell-value single-line-ellipsis"
  22. :title="dailyReportData.manufactureName || '-'"
  23. >
  24. {{ dailyReportData.manufactureName || '-' }}
  25. </span>
  26. </div>
  27. </div>
  28. <div class="table-cell">
  29. <div class="cell-content">
  30. <span class="cell-label">合同号:</span>
  31. <span class="cell-value">{{ dailyReportData.contractName || '-' }}</span>
  32. </div>
  33. </div>
  34. <div class="table-cell">
  35. <div class="cell-content">
  36. <span class="cell-label">井号:</span>
  37. <span class="cell-value">{{ dailyReportData.wellName || dailyReportData.taskName || '-' }}</span>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="table-row">
  42. <div class="table-cell">
  43. <div class="cell-content">
  44. <span class="cell-label">施工队伍:</span>
  45. <span class="cell-value">{{ dailyReportData.deptName || '-' }}</span>
  46. </div>
  47. </div>
  48. <div class="table-cell">
  49. <div class="cell-content">
  50. <span class="cell-label">施工地点:</span>
  51. <span class="cell-value">{{ dailyReportData.location || '-' }}</span>
  52. </div>
  53. </div>
  54. <div class="table-cell">
  55. <div class="cell-content">
  56. <span class="cell-label">工艺:</span>
  57. <span class="cell-value">{{ dailyReportData.techniqueNames || '-' }}</span>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="table-row">
  62. <div class="table-cell">
  63. <div class="cell-content">
  64. <span class="cell-label">搬迁日期:</span>
  65. <span class="cell-value">{{ formatDate(dailyReportData.dpDate) || '-' }}</span>
  66. </div>
  67. </div>
  68. <div class="table-cell">
  69. <div class="cell-content">
  70. <span class="cell-label">开工日期:</span>
  71. <span class="cell-value">{{ formatDate(dailyReportData.sgDate) || '-' }}</span>
  72. </div>
  73. </div>
  74. <div class="table-cell">
  75. <div class="cell-content">
  76. <span class="cell-label">完工日期:</span>
  77. <span class="cell-value">{{ formatDate(dailyReportData.wgDate) || '-' }}</span>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="table-row">
  82. <div class="table-cell">
  83. <div class="cell-content">
  84. <span class="cell-label">施工周期D:</span>
  85. <span class="cell-value">{{ constructionPeriod || 0 }}</span>
  86. </div>
  87. </div>
  88. <div class="table-cell">
  89. <div class="cell-content">
  90. <span class="cell-label">停待时间D:</span>
  91. <span class="cell-value">{{ dailyReportData.faultDowntime || 0 }}</span>
  92. </div>
  93. </div>
  94. <div class="table-cell">
  95. <div class="cell-content">
  96. <span class="cell-label">带班干部:</span>
  97. <span class="cell-value">{{ dailyReportData.responsiblePersonNames || '-' }}</span>
  98. </div>
  99. </div>
  100. </div>
  101. <!-- 第五行:设备配置(单独一行) -->
  102. <div class="table-row">
  103. <div class="table-cell full-width">
  104. <div class="cell-content">
  105. <span class="cell-label">设备配置:</span>
  106. <span class="cell-value indent-multiline">{{ dailyReportData.deviceNames || '-' }}</span>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </ContentWrap>
  112. <!-- 第三部分:日报填报表单 -->
  113. <ContentWrap class="section-padding">
  114. <el-form
  115. ref="formRef"
  116. :model="formData"
  117. :rules="isApprovalMode ? {} : formRules"
  118. v-loading="formLoading"
  119. style="margin-top: 1em"
  120. label-width="200px"
  121. :disabled="isApprovalMode"
  122. >
  123. <!-- 第一行:时间节点、施工状态 -->
  124. <el-row :gutter="30">
  125. <el-col :span="12">
  126. <el-form-item label="时间节点" prop="timeRange">
  127. <el-time-picker
  128. is-range
  129. v-model="formData.timeRange"
  130. range-separator="至"
  131. start-placeholder="开始时间"
  132. end-placeholder="结束时间"
  133. placeholder="选择时间范围"
  134. style="width: 100%"
  135. :readonly="isApprovalMode"
  136. />
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="12">
  140. <el-form-item label="施工状态" prop="rdStatus">
  141. <el-select v-model="formData.rdStatus" placeholder="请选择施工状态" style="width: 100%" :disabled="isApprovalMode">
  142. <el-option
  143. v-for="dict in rdStatusOptions"
  144. :key="dict.value"
  145. :label="dict.label"
  146. :value="dict.value"
  147. />
  148. </el-select>
  149. </el-form-item>
  150. </el-col>
  151. </el-row>
  152. <!-- 第二行:施工工艺 -->
  153. <el-row>
  154. <el-col :span="24">
  155. <el-form-item label="施工工艺" prop="techniqueIds">
  156. <el-select v-model="formData.techniqueIds" placeholder="请选择施工工艺"
  157. style="width: 100%" multiple :disabled="isApprovalMode">
  158. <el-option
  159. v-for="dict in techniqueOptions"
  160. :key="dict.value"
  161. :label="dict.label"
  162. :value="dict.value"
  163. />
  164. </el-select>
  165. </el-form-item>
  166. </el-col>
  167. </el-row>
  168. <!-- 动态属性区域:施工工艺与当日生产动态之间 -->
  169. <el-row v-if="dynamicAttrs.length > 0" :gutter="30">
  170. <el-col
  171. v-for="attr in dynamicAttrs"
  172. :key="attr.id"
  173. :span="attr.dataType === 'textarea' ? 24 : 12"
  174. >
  175. <el-form-item
  176. :label="attr.name + (attr.unit ? `(${attr.unit})` : '')"
  177. :prop="'dynamicFields.' + attr.identifier"
  178. :rules="isApprovalMode ? [] : getDynamicAttrRules(attr)"
  179. >
  180. <!-- 文本类型 -->
  181. <el-input
  182. v-if="attr.dataType === 'text'"
  183. v-model="formData.dynamicFields[attr.identifier]"
  184. :placeholder="`请输入${attr.name}`"
  185. :readonly="isApprovalMode"
  186. />
  187. <!-- 文本域类型 -->
  188. <el-input
  189. v-else-if="attr.dataType === 'textarea'"
  190. v-model="formData.dynamicFields[attr.identifier]"
  191. :placeholder="`请输入${attr.name}`"
  192. type="textarea"
  193. :rows="3"
  194. :readonly="isApprovalMode"
  195. />
  196. <!-- 数字类型 -->
  197. <el-input
  198. v-else-if="attr.dataType === 'double'"
  199. v-model="formData.dynamicFields[attr.identifier]"
  200. :placeholder="`请输入${attr.name}`"
  201. type="number"
  202. :min="attr.minValue || undefined"
  203. :max="attr.maxValue || undefined"
  204. :readonly="isApprovalMode"
  205. />
  206. <!-- 日期类型 -->
  207. <el-date-picker
  208. v-else-if="attr.dataType === 'date'"
  209. v-model="formData.dynamicFields[attr.identifier]"
  210. type="date"
  211. value-format="x"
  212. :placeholder="`选择${attr.name}`"
  213. style="width: 100%"
  214. :readonly="isApprovalMode"
  215. />
  216. <!-- 默认文本输入 -->
  217. <el-input
  218. v-else
  219. v-model="formData.dynamicFields[attr.identifier]"
  220. :placeholder="`请输入${attr.name}`"
  221. :readonly="isApprovalMode"
  222. />
  223. </el-form-item>
  224. </el-col>
  225. </el-row>
  226. <!-- 第三行:当日生产动态 -->
  227. <el-row>
  228. <el-col :span="24">
  229. <el-form-item label="当日生产动态" prop="productionStatus">
  230. <el-input
  231. v-model="formData.productionStatus"
  232. type="textarea"
  233. :rows="3"
  234. placeholder="请输入当日生产动态"
  235. :readonly="isApprovalMode"
  236. />
  237. </el-form-item>
  238. </el-col>
  239. </el-row>
  240. <!-- 第四行:下步工作计划 -->
  241. <el-row>
  242. <el-col :span="24">
  243. <el-form-item label="下步工作计划" prop="nextPlan">
  244. <el-input
  245. v-model="formData.nextPlan"
  246. type="textarea"
  247. :rows="3"
  248. placeholder="请输入下步工作计划"
  249. :readonly="isApprovalMode"
  250. />
  251. </el-form-item>
  252. </el-col>
  253. </el-row>
  254. <!-- 第五行:外租设备 -->
  255. <el-row>
  256. <el-col :span="24">
  257. <el-form-item label="外租设备" prop="externalRental">
  258. <el-input
  259. v-model="formData.externalRental"
  260. type="textarea"
  261. :rows="3"
  262. placeholder="请输入外租设备信息"
  263. :readonly="isApprovalMode"
  264. />
  265. </el-form-item>
  266. </el-col>
  267. </el-row>
  268. <!-- 第六行:上传附件 -->
  269. <el-row>
  270. <el-col :span="24">
  271. <el-form-item label="上传附件">
  272. <!-- 文件上传组件 -->
  273. <FileUpload
  274. v-if="!isApprovalMode"
  275. ref="fileUploadRef"
  276. :device-id="deviceId"
  277. :show-folder-button="false"
  278. @upload-success="handleUploadSuccess"
  279. />
  280. <!-- 已上传附件列表显示 -->
  281. <div v-if="formData.attachments && formData.attachments.length > 0" class="attachment-list">
  282. <div
  283. v-for="(attachment, index) in formData.attachments"
  284. :key="attachment.id || index"
  285. class="attachment-item"
  286. >
  287. <!-- 为附件名称添加点击事件,传递整个附件对象 -->
  288. <a class="attachment-name" @click="inContent(attachment)" style="cursor: pointer; color: #409eff; text-decoration: underline;">
  289. {{ attachment.filename }}
  290. </a>
  291. <el-button
  292. v-if="!isApprovalMode"
  293. type="danger"
  294. link
  295. size="small"
  296. @click="removeAttachment(index)"
  297. >
  298. 删除
  299. </el-button>
  300. </div>
  301. </div>
  302. <!-- 审批模式下只显示附件列表 -->
  303. <div v-else-if="isApprovalMode && (!formData.attachments || formData.attachments.length === 0)" class="no-attachment">
  304. 无附件
  305. </div>
  306. </el-form-item>
  307. </el-col>
  308. </el-row>
  309. </el-form>
  310. </ContentWrap>
  311. <!-- 第四部分:审批意见 - 只在审批模式下显示 -->
  312. <ContentWrap class="section-padding" v-if="isApprovalMode">
  313. <el-form
  314. ref="approvalFormRef"
  315. :model="approvalForm"
  316. style="margin-top: 1em"
  317. label-width="200px"
  318. >
  319. <el-row>
  320. <el-col :span="24">
  321. <el-form-item label="审批意见" prop="opinion">
  322. <el-input
  323. v-model="approvalForm.opinion"
  324. type="textarea"
  325. :rows="4"
  326. placeholder="请输入审批意见"
  327. maxlength="500"
  328. show-word-limit
  329. />
  330. </el-form-item>
  331. </el-col>
  332. </el-row>
  333. </el-form>
  334. </ContentWrap>
  335. <!-- 操作按钮 -->
  336. <ContentWrap class="section-padding" v-if="!isApprovalMode">
  337. <el-form>
  338. <el-form-item style="float: right">
  339. <el-button @click="submitForm" type="primary" :disabled="formLoading">
  340. {{ t('common.save') }}
  341. </el-button>
  342. <el-button @click="close">{{ t('common.cancel') }}</el-button>
  343. </el-form-item>
  344. </el-form>
  345. </ContentWrap>
  346. <!-- 审批模式下的操作按钮 -->
  347. <ContentWrap class="section-padding" v-if="isApprovalMode">
  348. <el-form>
  349. <el-form-item style="float: right">
  350. <el-button @click="handleApprove('pass')" type="success">
  351. 审批通过
  352. </el-button>
  353. <el-button @click="handleApprove('reject')" type="danger">
  354. 审批驳回
  355. </el-button>
  356. <el-button @click="close">{{ t('common.close') }}</el-button>
  357. </el-form-item>
  358. </el-form>
  359. </ContentWrap>
  360. </ContentWrap>
  361. </template>
  362. <script setup lang="ts">
  363. import { ref, reactive, computed, onMounted, nextTick, watch } from 'vue'
  364. import { useI18n } from '@/hooks/web/useI18n'
  365. import { useMessage } from '@/hooks/web/useMessage'
  366. import { useTagsViewStore } from '@/store/modules/tagsView'
  367. import { useRouter, useRoute } from 'vue-router'
  368. import {DICT_TYPE, getDictLabel, getStrDictOptions} from '@/utils/dict'
  369. import { IotRdDailyReportApi } from '@/api/pms/iotrddailyreport'
  370. import { IotDailyReportAttrsApi } from '@/api/pms/iotdailyreportattrs'
  371. import * as DeptApi from '@/api/system/dept'
  372. import { useUserStore } from '@/store/modules/user'
  373. import dayjs from 'dayjs'
  374. import FileUpload from "@/components/UploadFile/src/FileUpload.vue";
  375. const { t } = useI18n()
  376. const message = useMessage()
  377. const { delView } = useTagsViewStore()
  378. const { push, currentRoute } = useRouter()
  379. const { params } = useRoute()
  380. const userStore = useUserStore()
  381. /** 填报日报 表单 */
  382. defineOptions({ name: 'FillDailyReportForm' })
  383. const formLoading = ref(false)
  384. const formRef = ref()
  385. const id = params.id // 瑞都日报id
  386. // 日报数据
  387. const dailyReportData = ref<any>({})
  388. // 动态属性相关变量
  389. const dynamicAttrs = ref<any[]>([]) // 存储动态属性列表
  390. // 添加审批表单相关变量
  391. const approvalFormRef = ref()
  392. const approvalForm = reactive({
  393. opinion: '' // 审批意见
  394. })
  395. // 审批表单验证规则(可选,根据需求添加)
  396. const approvalFormRules = reactive({
  397. opinion: [
  398. { required: false, message: '请输入审批意见', trigger: 'blur' },
  399. { min: 0, max: 500, message: '审批意见长度不能超过500个字符', trigger: 'blur' }
  400. ]
  401. })
  402. // 添加文件上传组件的引用
  403. const fileUploadRef = ref()
  404. // 表单数据
  405. const formData = ref({
  406. id: undefined,
  407. deptId: undefined,
  408. companyId: undefined,
  409. deptName: undefined,
  410. constructionStartDate: undefined,
  411. contractName: undefined,
  412. projectDepartment: '',
  413. costCenterId: undefined,
  414. costCenter: '',
  415. // 新增日报填报字段
  416. timeRange: [ // 设置默认时间范围 8:00 - 8:00
  417. dayjs().hour(8).minute(0).second(0).toDate(),
  418. dayjs().hour(8).minute(0).second(0).toDate()
  419. ],
  420. startTime: undefined, // 开始时间
  421. endTime: undefined, // 结束时间
  422. rdStatus: '', // 施工状态
  423. techniqueIds: [], // 施工工艺
  424. productionStatus: '', // 当日生产动态
  425. nextPlan: '', // 下步工作计划
  426. externalRental: '', // 外租设备
  427. // 添加动态字段对象
  428. dynamicFields: {} as Record<string, any>,
  429. // 附件列表
  430. attachments: [] as any[]
  431. })
  432. // 添加上传成功处理函数
  433. const handleUploadSuccess = (result: any) => {
  434. console.log('上传成功:', result)
  435. try {
  436. // 检查响应是否成功
  437. if (!result.response) {
  438. message.error('上传响应数据异常')
  439. return
  440. }
  441. if (result.response.code !== 0) {
  442. message.error(result.response.msg || '文件上传失败')
  443. return
  444. }
  445. const responseData = result.response.data
  446. if (!responseData) {
  447. message.error('上传数据为空')
  448. return
  449. }
  450. // 处理返回的文件列表
  451. if (responseData.files && Array.isArray(responseData.files) && responseData.files.length > 0) {
  452. responseData.files.forEach((file: any) => {
  453. if (!file.filePath) {
  454. console.warn('文件缺少 filePath:', file)
  455. return
  456. }
  457. // 根据后端返回的数据结构构建附件对象
  458. const attachment = {
  459. id: undefined,
  460. category: 'daily_report',
  461. bizId: formData.value.id,
  462. type: 'attachment',
  463. filename: file.name || '未知文件',
  464. fileType: getFileType(file.name),
  465. filePath: file.filePath, //使用正确的 filePath
  466. fileSize: formatFileSize(file.size || 0),
  467. remark: ''
  468. }
  469. // 添加到附件列表
  470. if (!formData.value.attachments) {
  471. formData.value.attachments = []
  472. }
  473. formData.value.attachments.push(attachment)
  474. })
  475. message.success(`成功上传 ${responseData.files.length} 个文件`)
  476. } else {
  477. console.warn('上传成功但没有返回文件信息')
  478. message.warning('上传成功但未获取到文件信息')
  479. }
  480. } catch (error) {
  481. console.error('处理上传结果时发生错误:', error)
  482. message.error('处理上传结果失败')
  483. }
  484. }
  485. // 删除附件
  486. const removeAttachment = (index: number) => {
  487. if (formData.value.attachments && formData.value.attachments.length > index) {
  488. formData.value.attachments.splice(index, 1)
  489. }
  490. }
  491. // 附件名称点击事件
  492. const inContent = async (attachment) => {
  493. if (!attachment || !attachment.filePath) {
  494. message.error('附件路径不存在')
  495. return
  496. }
  497. try {
  498. // 直接使用 attachment.filePath
  499. const filePath = attachment.filePath
  500. // 确保 filePath 是编码后的格式
  501. const encodedPath = encodeURIComponent(filePath)
  502. // 打开预览窗口
  503. window.open(`http://doc.deepoil.cc:8012/onlinePreview?url=${encodedPath}`)
  504. } catch (error) {
  505. console.error('预览附件失败:', error)
  506. message.error('预览附件失败')
  507. }
  508. }
  509. // 获取文件类型辅助函数
  510. const getFileType = (filename: string) => {
  511. const ext = filename.split('.').pop()?.toLowerCase()
  512. if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(ext || '')) {
  513. return 'image'
  514. } else if (['pdf'].includes(ext || '')) {
  515. return 'pdf'
  516. } else if (['doc', 'docx'].includes(ext || '')) {
  517. return 'word'
  518. } else if (['xls', 'xlsx'].includes(ext || '')) {
  519. return 'excel'
  520. } else {
  521. return 'other'
  522. }
  523. }
  524. // 格式化文件大小辅助函数
  525. const formatFileSize = (bytes: number) => {
  526. if (bytes === 0) return '0 Bytes'
  527. const k = 1024
  528. const sizes = ['Bytes', 'KB', 'MB', 'GB']
  529. const i = Math.floor(Math.log(bytes) / Math.log(k))
  530. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
  531. }
  532. // 表单验证规则
  533. const formRules = reactive({
  534. timeRange: [{ required: true, message: '时间节点不能为空', trigger: 'change' }],
  535. rdStatus: [{ required: true, message: '施工状态不能为空', trigger: 'change' }],
  536. techniqueIds: [{ required: true, message: '施工工艺不能为空', trigger: 'change' }],
  537. productionStatus: [{ required: true, message: '当日生产动态不能为空', trigger: 'blur' }]
  538. })
  539. const queryParams = reactive({
  540. deptId: undefined,
  541. techniqueIds: [],
  542. })
  543. // 添加审批模式判断
  544. const isApprovalMode = computed(() => params.mode === 'approval')
  545. // 下拉选项
  546. const rdStatusOptions = getStrDictOptions(DICT_TYPE.PMS_PROJECT_RD_STATUS) // 施工状态
  547. const techniqueOptions = getStrDictOptions(DICT_TYPE.PMS_PROJECT_RD_TECHNOLOGY) // 瑞都施工工艺
  548. // 计算属性:日报标题
  549. const dailyReportTitle = computed(() => {
  550. if (!dailyReportData.value.wellName || !dailyReportData.value.constructionStartDate) {
  551. return '日报填报'
  552. }
  553. const dateStr = formatDate(dailyReportData.value.constructionStartDate)
  554. return `${dailyReportData.value.wellName} - ${dateStr} 生产日报`
  555. })
  556. // 日报审批:日报标题
  557. const dailyReportApprovalTitle = computed(() => {
  558. if (!dailyReportData.value.wellName || !dailyReportData.value.constructionStartDate) {
  559. return '日报审批'
  560. }
  561. const dateStr = formatDate(dailyReportData.value.constructionStartDate)
  562. return `${dailyReportData.value.wellName} - ${dateStr} 日报审批`
  563. })
  564. // 计算属性:施工周期
  565. const constructionPeriod = computed(() => {
  566. const start = dailyReportData.value.constructionStartDate
  567. const end = dailyReportData.value.constructionEndDate
  568. if (!start || !end) return 0
  569. const startDate = dayjs(start)
  570. const endDate = dayjs(end)
  571. return endDate.diff(startDate, 'day')
  572. })
  573. // 日期格式化函数
  574. const formatDate = (timestamp: number) => {
  575. if (!timestamp) return ''
  576. return dayjs(timestamp).format('YYYY-MM-DD')
  577. }
  578. const close = () => {
  579. delView(unref(currentRoute))
  580. push({ name: 'FillDailyReport', params: {} })
  581. }
  582. /** 提交表单 */
  583. const emit = defineEmits(['success'])
  584. const submitForm = async () => {
  585. // 验证表单
  586. try {
  587. await formRef.value.validate()
  588. } catch (error) {
  589. return
  590. }
  591. // 处理时间范围数据
  592. if (formData.value.timeRange && formData.value.timeRange.length === 2) {
  593. // 将时间范围转换为 LocalTime 格式的字符串
  594. const startDate = dayjs(formData.value.timeRange[0])
  595. const endDate = dayjs(formData.value.timeRange[1])
  596. // 格式化为 HH:mm:ss 字符串,后端会自动转换为 LocalTime
  597. formData.value.startTime = startDate.format('HH:mm:ss')
  598. formData.value.endTime = endDate.format('HH:mm:ss')
  599. }
  600. // 构建动态属性 extProperty 数组
  601. const extProperties = dynamicAttrs.value.map(attr => {
  602. return {
  603. name: attr.name,
  604. sort: attr.sort,
  605. unit: attr.unit,
  606. actualValue: formData.value.dynamicFields[attr.identifier] || '', // 从 dynamicFields 中获取用户填写的值
  607. dataType: attr.dataType,
  608. maxValue: attr.maxValue,
  609. minValue: attr.minValue,
  610. required: attr.required,
  611. accessMode: attr.accessMode,
  612. identifier: attr.identifier,
  613. defaultValue: attr.defaultValue
  614. }
  615. })
  616. // 准备提交数据,包含动态字段
  617. const submitData = {
  618. ...formData.value,
  619. // 将动态字段组装成 extProperty 数组
  620. extProperty: extProperties
  621. }
  622. // 提交请求
  623. formLoading.value = true
  624. try {
  625. // 调用更新接口
  626. await IotRdDailyReportApi.updateIotRdDailyReport(submitData)
  627. message.success(t('common.updateSuccess'))
  628. close()
  629. // 发送操作成功的事件
  630. emit('success')
  631. } catch (error) {
  632. console.error('提交失败:', error)
  633. } finally {
  634. formLoading.value = false
  635. }
  636. }
  637. /** 重置表单 */
  638. const resetForm = () => {
  639. formRef.value?.resetFields()
  640. }
  641. // 初始化动态属性
  642. const initDynamicAttrs = (reportData: any) => {
  643. if (reportData.dailyReportAttrs && reportData.dailyReportAttrs.length > 0) {
  644. dynamicAttrs.value = reportData.dailyReportAttrs
  645. // 初始化动态字段的值
  646. const initialDynamicFields: Record<string, any> = {}
  647. // 优先从 extProperty 中获取实际值(编辑时)
  648. if (reportData.extProperty && reportData.extProperty.length > 0) {
  649. reportData.extProperty.forEach((extProp: any) => {
  650. if (extProp.identifier) {
  651. initialDynamicFields[extProp.identifier] = extProp.actualValue || ''
  652. }
  653. })
  654. }
  655. reportData.dailyReportAttrs.forEach((attr: any) => {
  656. if (!initialDynamicFields.hasOwnProperty(attr.identifier)) {
  657. // 优先使用实际值,如果没有则使用默认值
  658. const value = (attr.extProperty && attr.extProperty.actualValue !== undefined &&
  659. attr.extProperty.actualValue !== null && attr.extProperty.actualValue !== '')
  660. ? attr.extProperty.actualValue
  661. : (attr.defaultValue || (attr.extProperty?.defaultValue || ''))
  662. initialDynamicFields[attr.identifier] = value
  663. }
  664. })
  665. formData.value.dynamicFields = initialDynamicFields
  666. }
  667. }
  668. // 获取动态字段的验证规则
  669. const getDynamicAttrRules = (attr: any) => {
  670. const rules = []
  671. if (attr.required === 1) {
  672. rules.push({
  673. required: true,
  674. message: `${attr.name}不能为空`,
  675. trigger: 'blur'
  676. })
  677. }
  678. // 数字类型验证
  679. if (attr.dataType === 'double') {
  680. rules.push({
  681. validator: (rule: any, value: any, callback: any) => {
  682. if (value === '' || value === null || value === undefined) {
  683. callback()
  684. return
  685. }
  686. const numValue = Number(value)
  687. if (isNaN(numValue)) {
  688. callback(new Error(`${attr.name}必须是数字`))
  689. } else if (attr.minValue && numValue < Number(attr.minValue)) {
  690. callback(new Error(`${attr.name}不能小于${attr.minValue}`))
  691. } else if (attr.maxValue && numValue > Number(attr.maxValue)) {
  692. callback(new Error(`${attr.name}不能大于${attr.maxValue}`))
  693. } else {
  694. callback()
  695. }
  696. },
  697. trigger: 'blur'
  698. })
  699. }
  700. return rules
  701. }
  702. // 更新动态属性(处理交集、新增和删除)
  703. const updateDynamicAttrs = async (newAttrs: any[], newTechniqueIds: string[], oldTechniqueIds?: string[]) => {
  704. const oldAttrs = [...dynamicAttrs.value]
  705. const oldDynamicFields = { ...formData.value.dynamicFields }
  706. // 计算需要保留的字段(交集)
  707. const commonAttrs = oldAttrs.filter(oldAttr =>
  708. newAttrs.some(newAttr => newAttr.identifier === oldAttr.identifier)
  709. )
  710. // 计算需要新增的字段
  711. const addedAttrs = newAttrs.filter(newAttr =>
  712. !oldAttrs.some(oldAttr => oldAttr.identifier === newAttr.identifier)
  713. )
  714. // 计算需要删除的字段
  715. const removedAttrs = oldAttrs.filter(oldAttr =>
  716. !newAttrs.some(newAttr => newAttr.identifier === oldAttr.identifier)
  717. )
  718. // 构建新的动态属性数组
  719. const updatedAttrs = [...commonAttrs, ...addedAttrs]
  720. // 构建新的动态字段对象
  721. const updatedDynamicFields = { ...oldDynamicFields }
  722. // 移除已删除的字段
  723. removedAttrs.forEach(attr => {
  724. delete updatedDynamicFields[attr.identifier]
  725. })
  726. // 初始化新增字段的值
  727. addedAttrs.forEach(attr => {
  728. if (!updatedDynamicFields[attr.identifier]) {
  729. // 如果有默认值使用默认值,否则为空
  730. updatedDynamicFields[attr.identifier] = attr.defaultValue ||
  731. (attr.extProperty?.defaultValue || '')
  732. }
  733. })
  734. // 更新响应式数据
  735. dynamicAttrs.value = updatedAttrs
  736. formData.value.dynamicFields = updatedDynamicFields
  737. }
  738. // 加载动态属性
  739. const loadDynamicAttrs = async (newTechniqueIds: string[], oldTechniqueIds?: string[]) => {
  740. try {
  741. formLoading.value = true
  742. const queryParams = {
  743. techniqueIds: newTechniqueIds.join(',')
  744. }
  745. const response = await IotDailyReportAttrsApi.dailyReportAttrs(queryParams)
  746. const newAttrs = response || []
  747. // 处理动态属性更新
  748. await updateDynamicAttrs(newAttrs, newTechniqueIds, oldTechniqueIds)
  749. } catch (error) {
  750. console.error('加载动态属性失败:', error)
  751. message.error('加载动态属性失败')
  752. } finally {
  753. formLoading.value = false
  754. }
  755. }
  756. // 监听施工工艺变化
  757. watch(() => formData.value.techniqueIds, async (newTechniqueIds, oldTechniqueIds) => {
  758. if (newTechniqueIds && newTechniqueIds.length > 0) {
  759. await loadDynamicAttrs(newTechniqueIds, oldTechniqueIds)
  760. } else {
  761. dynamicAttrs.value = []
  762. formData.value.dynamicFields = {}
  763. }
  764. }, { deep: true })
  765. // 初始化表单数据
  766. const initFormData = (reportData: any) => {
  767. formData.value = {
  768. ...formData.value,
  769. id: reportData.id,
  770. deptId: reportData.deptId,
  771. rdStatus: reportData.rdStatus || '',
  772. techniqueIds: reportData.techniqueIds ? reportData.techniqueIds.map((id: number) => id.toString()) : [],
  773. productionStatus: reportData.productionStatus || '',
  774. nextPlan: reportData.nextPlan || '',
  775. externalRental: reportData.externalRental || '',
  776. startTime: reportData.startTime || undefined,
  777. endTime: reportData.endTime || undefined,
  778. companyId: reportData.companyId || '',
  779. dynamicFields: {}, // 确保有初始值
  780. // 初始化附件数据
  781. attachments: reportData.attachments || []
  782. }
  783. queryParams.deptId = reportData.companyId
  784. // 设置时间范围选择器
  785. if (reportData.startTime && reportData.startTime[0] && reportData.endTime && reportData.endTime[0]) {
  786. formData.value.timeRange = [
  787. new Date(reportData.startTime[0]),
  788. new Date(reportData.endTime[0])
  789. ]
  790. }
  791. // 初始化动态属性
  792. initDynamicAttrs(reportData)
  793. }
  794. onMounted(async () => {
  795. formLoading.value = true
  796. try {
  797. // 加载当前登录人所属部门
  798. const deptId = userStore.getUser.deptId
  799. const dept = await DeptApi.getDept(deptId)
  800. // 查询瑞都日报详情
  801. if (id) {
  802. const response = await IotRdDailyReportApi.getIotRdDailyReport(id)
  803. dailyReportData.value = response || {}
  804. initFormData(dailyReportData.value)
  805. }
  806. } catch (error) {
  807. console.error('初始化数据失败:', error)
  808. message.error('数据加载失败')
  809. } finally {
  810. formLoading.value = false
  811. }
  812. })
  813. /** 审批操作 */
  814. const handleApprove = async (action: 'pass' | 'reject') => {
  815. try {
  816. // 验证审批表单(如果需要)
  817. // await approvalFormRef.value.validate()
  818. formLoading.value = true
  819. // 处理时间范围数据
  820. if (formData.value.timeRange && formData.value.timeRange.length === 2) {
  821. // 将时间范围转换为 LocalTime 格式的字符串
  822. const startDate = dayjs(formData.value.timeRange[0])
  823. const endDate = dayjs(formData.value.timeRange[1])
  824. // 格式化为 HH:mm:ss 字符串,后端会自动转换为 LocalTime
  825. formData.value.startTime = startDate.format('HH:mm:ss')
  826. formData.value.endTime = endDate.format('HH:mm:ss')
  827. }
  828. // 构建审批数据,包含审批意见
  829. const approveData = {
  830. ...formData.value,
  831. id: Number(id),
  832. opinion: approvalForm.opinion,
  833. auditStatus: action === 'pass' ? 20 : 30
  834. }
  835. // 这里可以调用审批API
  836. if (action === 'pass') {
  837. // 审批通过逻辑
  838. await IotRdDailyReportApi.approveRdDailyReport(approveData)
  839. message.success('审批通过')
  840. } else {
  841. // 审批驳回逻辑
  842. await IotRdDailyReportApi.approveRdDailyReport(approveData)
  843. message.success('审批驳回')
  844. }
  845. close()
  846. } catch (error) {
  847. console.error('审批操作失败:', error)
  848. message.error('审批操作失败')
  849. } finally {
  850. formLoading.value = false
  851. }
  852. }
  853. </script>
  854. <style scoped>
  855. .info-table {
  856. border: 1px solid #e0e0e0;
  857. border-radius: 4px;
  858. overflow: hidden;
  859. }
  860. .table-row {
  861. display: flex;
  862. border-bottom: 1px solid #e0e0e0;
  863. }
  864. .table-row:last-child {
  865. border-bottom: none;
  866. }
  867. .table-cell {
  868. flex: 1;
  869. border-right: 1px solid #e0e0e0;
  870. padding: 12px 8px;
  871. min-height: 44px;
  872. display: flex;
  873. align-items: center;
  874. }
  875. .table-cell:last-child {
  876. border-right: none;
  877. }
  878. .table-cell.full-width {
  879. flex: 1;
  880. border-right: none;
  881. }
  882. .cell-content {
  883. display: flex;
  884. align-items: center;
  885. width: 100%;
  886. }
  887. .cell-label {
  888. font-weight: 500;
  889. /* 统一字体大小为 14px(Element 表单默认) */
  890. font-size: 14px;
  891. color: #606266;
  892. min-width: 80px;
  893. margin-right: 8px;
  894. flex-shrink: 0;
  895. }
  896. .cell-value {
  897. /* 统一字体大小为 14px(Element 输入框默认) */
  898. font-size: 14px;
  899. color: #303133;
  900. /* 统一行高为 1.5(Element 组件默认行高) */
  901. line-height: 1.5;
  902. flex: 1;
  903. word-break: break-all;
  904. }
  905. /* 响应式设计 */
  906. @media (max-width: 768px) {
  907. .table-row {
  908. flex-direction: column;
  909. }
  910. .table-cell {
  911. border-right: none;
  912. border-bottom: 1px solid #e0e0e0;
  913. }
  914. .table-cell:last-child {
  915. border-bottom: none;
  916. }
  917. }
  918. .daily-report-title {
  919. text-align: center;
  920. margin: 20px 0;
  921. padding: 10px;
  922. border-bottom: 2px solid #409eff;
  923. }
  924. .daily-report-title h2 {
  925. margin: 0;
  926. color: #303133;
  927. font-size: 16px;
  928. font-weight: bold;
  929. }
  930. /* 为第二、三部分增加左右留白 */
  931. .section-padding {
  932. padding-left: 0px;
  933. padding-right: 40px;
  934. }
  935. .project-info-section {
  936. margin: 20px 0;
  937. padding: 20px;
  938. background-color: #f8f9fa;
  939. border-radius: 4px;
  940. border: 1px solid #e9ecef;
  941. }
  942. .info-row {
  943. padding: 12px 0;
  944. border-bottom: 1px solid #e9ecef;
  945. }
  946. .info-row:last-child {
  947. border-bottom: none;
  948. }
  949. .info-label {
  950. font-weight: bold;
  951. color: #495057;
  952. margin-right: 8px;
  953. }
  954. .info-value {
  955. color: #212529;
  956. }
  957. :deep(.el-textarea .el-textarea__inner) {
  958. min-height: 80px;
  959. }
  960. /* 确保表单label不换行 */
  961. :deep(.el-form-item__label) {
  962. white-space: nowrap;
  963. text-overflow: ellipsis;
  964. overflow: hidden;
  965. }
  966. /* 甲方字段:单行显示+超出省略 */
  967. .single-line-ellipsis {
  968. /* 强制文本单行显示 */
  969. white-space: nowrap;
  970. /* 超出容器部分隐藏 */
  971. overflow: hidden;
  972. /* 超出部分显示省略号 */
  973. text-overflow: ellipsis;
  974. /* 避免文本被截断(可选,根据需求调整) */
  975. word-break: normal;
  976. }
  977. /* 设备配置字段:换行缩进(与首行对齐) */
  978. .indent-multiline {
  979. /* 首行及换行后缩进 2em(与 label 宽度匹配,可根据需求调整) */
  980. text-indent: 0em;
  981. /* 允许长文本换行(覆盖原有 cell-value 的 break-all,确保中文换行正常) */
  982. word-break: break-word;
  983. /* 保证换行后文本正常显示(可选,清除可能的 nowrap 影响) */
  984. white-space: normal;
  985. }
  986. /* 添加审批模式下的样式 */
  987. .approval-notice {
  988. margin-top: 10px;
  989. }
  990. /* 审批模式下表单字段的只读样式 */
  991. :deep(.el-form-item.is-disabled .el-input__inner),
  992. :deep(.el-form-item.is-disabled .el-textarea__inner) {
  993. background-color: #f5f7fa;
  994. border-color: #e4e7ed;
  995. color: #c0c4cc;
  996. cursor: not-allowed;
  997. }
  998. :deep(.el-form-item.is-disabled .el-select .el-input__inner) {
  999. background-color: #f5f7fa;
  1000. border-color: #e4e7ed;
  1001. color: #c0c4cc;
  1002. cursor: not-allowed;
  1003. }
  1004. :deep(.el-form-item.is-disabled .el-date-editor .el-input__inner) {
  1005. background-color: #f5f7fa;
  1006. border-color: #e4e7ed;
  1007. color: #c0c4cc;
  1008. cursor: not-allowed;
  1009. }
  1010. /* 添加审批意见区域的样式 */
  1011. .approval-opinion-section {
  1012. margin-top: 20px;
  1013. border-top: 2px solid #f0f0f0;
  1014. padding-top: 20px;
  1015. }
  1016. /* 审批意见文本域样式 */
  1017. :deep(.approval-opinion .el-textarea__inner) {
  1018. min-height: 100px;
  1019. resize: vertical;
  1020. }
  1021. /* 审批意见标签样式 */
  1022. :deep(.approval-opinion .el-form-item__label) {
  1023. font-weight: bold;
  1024. color: #606266;
  1025. }
  1026. /* 附件列表样式 */
  1027. .attachment-list {
  1028. margin-top: 10px;
  1029. border: 1px solid #e0e0e0;
  1030. border-radius: 4px;
  1031. padding: 10px;
  1032. background-color: #fafafa;
  1033. }
  1034. .attachment-item {
  1035. display: flex;
  1036. justify-content: space-between;
  1037. align-items: center;
  1038. padding: 8px 12px;
  1039. border-bottom: 1px solid #f0f0f0;
  1040. }
  1041. .attachment-item:last-child {
  1042. border-bottom: none;
  1043. }
  1044. .attachment-name {
  1045. flex: 1;
  1046. color: #606266;
  1047. font-size: 14px;
  1048. }
  1049. .no-attachment {
  1050. color: #909399;
  1051. font-style: italic;
  1052. margin-top: 10px;
  1053. }
  1054. /* 附件名称链接样式 */
  1055. .attachment-name {
  1056. color: #409eff;
  1057. text-decoration: underline;
  1058. cursor: pointer;
  1059. }
  1060. .attachment-name:hover {
  1061. color: #66b1ff;
  1062. }
  1063. </style>