FillDailyReportForm.vue 38 KB

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