index1.vue 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. <template>
  2. <ContentWrap>
  3. <el-tabs type="border-card" tab-position="left" v-loading="loading" style="height: 84vh">
  4. <el-tab-pane
  5. style="height: 100%"
  6. v-for="(deviceItem, deviceIndex) in list"
  7. :key="deviceIndex">
  8. <template #label>
  9. <span
  10. :class="['custom-label', { 'has-border': deviceItem.deviceName === '生产日报' }]"
  11. v-if="deviceItem.isFill === 1"
  12. @click="
  13. openFill(
  14. deviceItem.deviceCategoryId,
  15. deviceItem.deviceId,
  16. deviceItem.deptId,
  17. deviceItem.deviceName,
  18. deviceItem.deviceCode
  19. )
  20. ">
  21. {{ deviceItem.deviceCode }} ({{ deviceItem.deviceName }})
  22. </span>
  23. <span
  24. :class="['custom-label1', { 'has-border': deviceItem.deviceName === '生产日报' }]"
  25. v-else
  26. @click="
  27. openFill(
  28. deviceItem.deviceCategoryId,
  29. deviceItem.deviceId,
  30. deviceItem.deptId,
  31. deviceItem.deviceName,
  32. deviceItem.deviceCode
  33. )
  34. ">
  35. {{ deviceItem.deviceCode }} ({{ deviceItem.deviceName }})
  36. </span>
  37. </template>
  38. <div class="form-wrapper h-full">
  39. <el-form
  40. ref="formRef"
  41. size="default"
  42. label-width="120px"
  43. class="scrollable-form"
  44. :model="{ attrList: attrList, reportDetails, taskId }">
  45. <div style="margin-left: 24px">
  46. <el-form class="demo-form-inline" :inline="true">
  47. <el-form-item :label="t('common.createTime')" class="custom-label1">
  48. <span style="text-decoration: underline">
  49. {{ createTime }}
  50. </span>
  51. </el-form-item>
  52. <el-form-item :label="t('operationFillForm.team')" class="custom-label1">
  53. <span style="text-decoration: underline">
  54. {{ deviceItem.orgName }}
  55. </span>
  56. </el-form-item>
  57. <el-form-item
  58. v-if="
  59. deviceItem.deviceName === '生产日报' &&
  60. companyName !== 'ry' &&
  61. companyName !== 'rh'
  62. "
  63. label="井号"
  64. class="custom-label1">
  65. <span style="text-decoration: underline">
  66. {{ deviceItem.wellName }}
  67. </span>
  68. </el-form-item>
  69. <el-form-item
  70. v-else-if="
  71. deviceItem.deviceName === '生产日报' &&
  72. (companyName === 'ry' || companyName === 'rh') &&
  73. taskOptions.length > 0
  74. "
  75. label="井号"
  76. class="custom-label1"
  77. prop="taskId">
  78. <el-select
  79. v-model="taskId"
  80. placeholder="请选择井号"
  81. :options="taskOptions"
  82. class="w-40!" />
  83. </el-form-item>
  84. <el-form-item
  85. v-else-if="deviceItem.deviceName === '生产日报'"
  86. label="井号"
  87. class="custom-label1">
  88. <span style="text-decoration: underline">
  89. {{ deviceItem.wellName }}
  90. </span>
  91. </el-form-item>
  92. <el-row :gutter="20">
  93. <el-col
  94. v-for="(summaryItem, summaryIndex) in attrList1"
  95. :key="summaryIndex"
  96. :span="24">
  97. <el-form-item :label="summaryItem.name" class="custom-label1">
  98. <span style="text-decoration: underline">
  99. {{ summaryItem.totalRunTime }}
  100. </span>
  101. </el-form-item>
  102. </el-col>
  103. </el-row>
  104. <!-- <el-form-item :label="t('operationFillForm.sumTime')" class="custom-label1">
  105. <span style="text-decoration: underline;">
  106. {{totalRunTime1}}h
  107. </span>
  108. </el-form-item>-->
  109. </el-form>
  110. </div>
  111. <div
  112. v-for="(attrItem, attrIndex) in attrList.filter(
  113. (item) => !keys.includes(item.description)
  114. )"
  115. :key="attrIndex"
  116. style="margin-left: 24px">
  117. <!-- 添加提示文字 -->
  118. <div v-if="attrItem.isCollection === 1" class="plc-tip">
  119. <el-alert
  120. :title="t('operationFillForm.alert')"
  121. type="warning"
  122. :closable="false"
  123. center
  124. show-icon
  125. style="width: 320px" />
  126. </div>
  127. <el-form-item
  128. v-if="companyName === 'ry' ? attrItem.description !== 'productionStatus' : true"
  129. :label="attrItem.name"
  130. :prop="
  131. 'attrList.' +
  132. attrList.findIndex((i) => i.description === attrItem.description) +
  133. '.fillContent'
  134. "
  135. label-position="top"
  136. :rules="rules[attrItem.description]">
  137. <div v-if="fillStatus === '1'">
  138. <el-select
  139. disabled
  140. v-model="attrItem.fillContent"
  141. v-if="attrItem.type === 'enum' && attrItem.description !== null"
  142. style="width: 200px">
  143. <el-option
  144. v-for="dict in attrItem.name === '非生产原因'
  145. ? getIntDictOptions(attrItem.description)
  146. : getStrDictOptions(attrItem.description)"
  147. :key="dict.label"
  148. :label="dict.label"
  149. :value="
  150. attrItem.name === '非生产原因' ? Number(dict.value) : dict.value.toString()
  151. " />
  152. </el-select>
  153. <el-input
  154. v-else
  155. v-model="attrItem.fillContent"
  156. clearable
  157. style="width: 200px; margin-right: 10px"
  158. disabled />
  159. </div>
  160. <el-input
  161. v-else-if="attrItem.type === 'textarea'"
  162. v-model="attrItem.fillContent"
  163. type="textarea"
  164. clearable
  165. style="width: 200px" />
  166. <el-select
  167. v-model="attrItem.fillContent"
  168. clearable
  169. v-else-if="attrItem.type === 'enum' && attrItem.description !== null"
  170. style="width: 200px"
  171. filterable>
  172. <el-option
  173. v-for="dict in attrItem.name === '非生产原因'
  174. ? getIntDictOptions(attrItem.description)
  175. : getStrDictOptions(attrItem.description)"
  176. :key="dict.label"
  177. :label="dict.label"
  178. :value="
  179. attrItem.name === '非生产原因' ? Number(dict.value) : dict.value.toString()
  180. " />
  181. </el-select>
  182. <el-input
  183. v-else
  184. v-model="attrItem.fillContent"
  185. clearable
  186. style="width: 200px"
  187. :placeholder="
  188. attrItem.type === 'double'
  189. ? t('operationFillForm.enterNumber')
  190. : t('operationFillForm.enterContent')
  191. "
  192. @input="handleInput(attrItem)"
  193. :maxlength="
  194. attrItem.type === 'double' ? calculateMaxLength(attrItem) : undefined
  195. " />
  196. </el-form-item>
  197. </div>
  198. <div
  199. v-for="(attrItem, attrIndex) in attrList"
  200. :key="attrIndex"
  201. style="margin-left: 24px">
  202. <el-divider v-if="attrItem.description === 'repairTime'" content-position="left"
  203. >非生产时间</el-divider
  204. >
  205. <el-form-item
  206. v-if="
  207. keys.includes(attrItem.description) && attrItem.description !== 'otherNptReason'
  208. "
  209. label-position="top"
  210. :label="attrItem.name"
  211. :prop="'attrList.' + attrIndex + '.fillContent'"
  212. :rules="rules[attrItem.description]">
  213. <el-input-number
  214. class="w-80!"
  215. :min="0"
  216. :max="24"
  217. v-model="attrItem.fillContent"
  218. :controls="false"
  219. align="left"
  220. placeholder="请输入数字"
  221. :disabled="fillStatus === '1'" />
  222. </el-form-item>
  223. <el-form-item
  224. v-else-if="attrItem.description === 'otherNptReason'"
  225. label-position="top"
  226. :label="attrItem.name"
  227. :prop="'attrList.' + attrIndex + '.fillContent'"
  228. :rules="rules[attrItem.description]">
  229. <el-input
  230. class="w-80!"
  231. v-model="attrItem.fillContent"
  232. placeholder="请输入其他非生产原因"
  233. :disabled="fillStatus === '1'" />
  234. </el-form-item>
  235. </div>
  236. <div v-if="companyName === 'ry' && deviceItem.deviceName === '生产日报'">
  237. <div class="flex items-center justify-between mb-6">
  238. <div class="flex items-center gap-2">
  239. <div class="bg-[var(--el-color-primary)] w-1 h-5 rounded-full"></div>
  240. <div class="text-lg font-medium text-[var(--el-text-color-primary)]"
  241. >生产动态</div
  242. >
  243. </div>
  244. <el-button
  245. :disabled="fillStatus === '1'"
  246. type="primary"
  247. link
  248. :icon="Plus"
  249. @click="addProductionStatusRow">
  250. 添加一行
  251. </el-button>
  252. </div>
  253. <el-form-item prop="reportDetails" class="table-form-item">
  254. <ZmTable :data="reportDetails" :loading="false" class="mb-4">
  255. <ZmTableColumn label="日期" :width="180" prop="reportDate">
  256. <template #default="{ row, $index }">
  257. <el-form-item
  258. v-if="$index >= 0"
  259. class="mb-0!"
  260. :prop="`reportDetails.${$index}.reportDate`"
  261. :rules="{
  262. required: true,
  263. message: '请选择日期',
  264. trigger: ['change', 'blur'],
  265. type: 'number'
  266. }">
  267. <el-date-picker
  268. v-model="row.reportDate"
  269. placeholder="选择日期"
  270. clearable
  271. class="w-full!"
  272. value-format="x"
  273. :disabled="fillStatus === '1'"
  274. @change="inputCurrentDepth()" />
  275. </el-form-item>
  276. </template>
  277. </ZmTableColumn>
  278. <ZmTableColumn :width="130" label="开始时间" prop="startTime">
  279. <template #default="{ row, $index }">
  280. <el-form-item
  281. v-if="$index >= 0"
  282. class="mb-0!"
  283. :prop="`reportDetails.${$index}.startTime`"
  284. :rules="{
  285. required: true,
  286. message: '请选择开始时间',
  287. trigger: ['change', 'blur']
  288. }">
  289. <el-time-picker
  290. v-model="row.startTime"
  291. placeholder="选择开始时间"
  292. clearable
  293. format="HH:mm"
  294. value-format="HH:mm"
  295. class="w-full!"
  296. @change="acalculateDuration(row)"
  297. :disabled="fillStatus === '1'" />
  298. </el-form-item>
  299. </template>
  300. </ZmTableColumn>
  301. <ZmTableColumn :width="130" label="结束时间" prop="endTime">
  302. <template #default="{ row, $index }">
  303. <el-form-item
  304. v-if="$index >= 0"
  305. class="mb-0!"
  306. :prop="`reportDetails.${$index}.endTime`"
  307. :rules="{
  308. required: true,
  309. message: '请选择结束时间',
  310. trigger: ['change', 'blur']
  311. }">
  312. <el-time-picker
  313. v-model="row.endTime"
  314. placeholder="选择结束时间"
  315. clearable
  316. format="HH:mm"
  317. value-format="HH:mm"
  318. class="w-full!"
  319. @change="acalculateDuration(row)"
  320. :disabled="fillStatus === '1'" />
  321. </el-form-item>
  322. </template>
  323. </ZmTableColumn>
  324. <ZmTableColumn :width="80" label="时长(H)" prop="duration" />
  325. <ZmTableColumn label="工况" min-width="140">
  326. <template #default="{ row, $index }">
  327. <el-form-item
  328. v-if="$index >= 0"
  329. :prop="`reportDetails.${$index}.currentOperation`"
  330. :rules="{
  331. required: true,
  332. message: '请输入工况',
  333. trigger: ['change', 'blur']
  334. }"
  335. class="mb-0!">
  336. <el-input
  337. v-model="row.currentOperation"
  338. type="textarea"
  339. :autosize="{ minRows: 1 }"
  340. show-word-limit
  341. :maxlength="1000"
  342. placeholder="请输入工况"
  343. :disabled="fillStatus === '1'" />
  344. </el-form-item>
  345. </template>
  346. </ZmTableColumn>
  347. <ZmTableColumn v-if="showDepth" label="结束井深(m)" min-width="80">
  348. <template #default="{ row, $index }">
  349. <el-form-item
  350. v-if="$index >= 0"
  351. :prop="`reportDetails.${$index}.currentDepth`"
  352. :rules="[
  353. {
  354. required: true,
  355. message: '请输入结束井深',
  356. trigger: ['blur']
  357. }
  358. // { validator: validateLastCurrentDepth, trigger: ['change', 'blur'] }
  359. ]"
  360. class="mb-0!">
  361. <el-input-number
  362. v-model="row.currentDepth"
  363. :min="0"
  364. :controls="false"
  365. class="!w-full"
  366. align="left"
  367. placeholder="请输入结束井深"
  368. @input="() => inputCurrentDepth()"
  369. :disabled="fillStatus === '1'">
  370. <template #suffix> m </template>
  371. </el-input-number>
  372. </el-form-item>
  373. </template>
  374. </ZmTableColumn>
  375. <ZmTableColumn label="详细描述" min-width="200" align="center">
  376. <template #default="{ row, $index }">
  377. <el-form-item
  378. v-if="$index >= 0"
  379. :prop="`reportDetails.${$index}.constructionDetail`"
  380. :rules="{ required: true, message: '请输入详细描述', trigger: 'blur' }"
  381. class="mb-0!">
  382. <el-input
  383. v-model="row.constructionDetail"
  384. type="textarea"
  385. :autosize="{ minRows: 1 }"
  386. show-word-limit
  387. :maxlength="1000"
  388. placeholder="请输入详细描述"
  389. :disabled="fillStatus === '1'" />
  390. </el-form-item>
  391. </template>
  392. </ZmTableColumn>
  393. <ZmTableColumn label="操作" width="80" fixed="right" align="center">
  394. <template #default="{ $index }">
  395. <el-button
  396. link
  397. type="danger"
  398. :icon="Delete"
  399. @click="removeProductionStatusRow($index)"
  400. :disabled="fillStatus === '1'">
  401. 删除
  402. </el-button>
  403. </template>
  404. </ZmTableColumn>
  405. </ZmTable>
  406. </el-form-item>
  407. </div>
  408. <el-form-item>
  409. <el-button
  410. :loading="submitLoading"
  411. type="primary"
  412. @click="getFillInfo"
  413. v-show="showStatus"
  414. >{{ t('operationFillForm.confirm') }}</el-button
  415. >
  416. <el-button type="info" @click="deleteFillInfo" v-show="showStatus">{{
  417. t('operationFill.clear')
  418. }}</el-button>
  419. </el-form-item>
  420. </el-form>
  421. </div>
  422. </el-tab-pane>
  423. </el-tabs>
  424. </ContentWrap>
  425. </template>
  426. <script setup lang="ts">
  427. import { IotOpeationFillApi, IotOpeationFillVO } from '@/api/pms/iotopeationfill'
  428. import { ElMessage, FormInstance, FormRules } from 'element-plus'
  429. import moment from 'moment'
  430. import { getIntDictOptions, getStrDictOptions } from '@/utils/dict'
  431. import { useRoute } from 'vue-router'
  432. import { calculateDuration, formatT } from '@/utils/formatTime'
  433. import { Delete, Plus } from '@element-plus/icons-vue'
  434. import { useDebounceFn } from '@vueuse/core'
  435. import dayjs from 'dayjs'
  436. /** 运行记录填报 列表 */
  437. defineOptions({ name: 'FillOrderInfo' })
  438. const route = useRoute()
  439. const message = useMessage() // 消息弹窗
  440. const { t } = useI18n() // 国际化
  441. /** 提交表单 */
  442. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  443. const loading = ref(true) // 列表的加载中
  444. const { params } = useRoute() // 查询参数
  445. const deptId = params.id as string
  446. const list = ref<IotOpeationFillVO[]>([]) // 列表的数据
  447. const attrList = ref<IotOpeationFillVO[]>([]) // 非累计属性集合
  448. const attrList1 = ref<IotOpeationFillVO[]>([]) // 累计属性集合
  449. const attrList2 = ref<IotOpeationFillVO[]>([]) // 属性集合
  450. let companyName = ref('')
  451. let fillStatus = deptId.split(',')[4]
  452. let createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  453. let showStatus = true
  454. const queryParams = reactive<any>({
  455. pageNo: 1,
  456. pageSize: 10,
  457. deviceCode: undefined,
  458. deviceName: undefined,
  459. fillContent: undefined,
  460. deviceType: undefined,
  461. deviceComponent: undefined,
  462. deptId: undefined,
  463. orgName: undefined,
  464. proId: undefined,
  465. proName: undefined,
  466. teamId: undefined,
  467. teamName: undefined,
  468. dutyName: undefined,
  469. creDate: [],
  470. createTime: [],
  471. deviceCategoryId: 1,
  472. deviceId: undefined,
  473. threshold: undefined,
  474. defaultValue: undefined,
  475. isSum: undefined
  476. })
  477. interface ReportDetail {
  478. reportDate: number
  479. startTime: string
  480. endTime: string
  481. duration: number
  482. currentDepth: number
  483. currentOperation: string
  484. constructionDetail: string
  485. }
  486. const taskId = ref<number | undefined>(undefined)
  487. const taskOptions = ref<{ label: string; value: number }[]>([])
  488. const reportDetails = ref<ReportDetail[]>([])
  489. const addProductionStatusRow = () => {
  490. if (!reportDetails.value) {
  491. reportDetails.value = []
  492. }
  493. reportDetails.value.push({
  494. reportDate: createTime ? dayjs(createTime).valueOf() : dayjs().valueOf(),
  495. startTime: '',
  496. endTime: '',
  497. duration: 0,
  498. currentDepth: 0,
  499. currentOperation: '',
  500. constructionDetail: ''
  501. })
  502. }
  503. const removeProductionStatusRow = (index: number) => {
  504. if (index === 0) {
  505. message.warning('至少填写一条生产动态')
  506. return
  507. }
  508. reportDetails.value.splice(index, 1)
  509. }
  510. const acalculateDuration = (row: any) => {
  511. calculateDuration(row)
  512. inputCurrentDepth()
  513. }
  514. const inputCurrentDepth = useDebounceFn(function inputCurrentDepth() {
  515. const details = reportDetails.value
  516. if (Array.isArray(details) && details.length > 0) {
  517. const latestDetail = details.reduce((prev, current) => {
  518. const currentFullTime = dayjs(current.reportDate)
  519. .hour(parseInt(current.endTime.split(':')[0]))
  520. .minute(parseInt(current.endTime.split(':')[1]))
  521. .valueOf()
  522. const prevFullTime = dayjs(prev.reportDate)
  523. .hour(parseInt(prev.endTime.split(':')[0]))
  524. .minute(parseInt(prev.endTime.split(':')[1]))
  525. .valueOf()
  526. return currentFullTime >= prevFullTime ? current : prev
  527. })
  528. const currentDepth = attrList.value.find((item) => item.description === 'currentDepth')
  529. if (currentDepth) currentDepth.fillContent = latestDetail.currentDepth
  530. }
  531. }, 300)
  532. // const inputCurrentDepth = useDebounceFn(function inputCurrentDepth(val: any, index: number) {
  533. // if (reportDetails.value && index === reportDetails.value.length - 1) {
  534. // const currentDepth = attrList.value.find((item) => item.description === 'currentDepth')
  535. // if (currentDepth) currentDepth.fillContent = val
  536. // }
  537. // }, 300)
  538. const showDepth = computed(() => {
  539. return attrList.value.some((item) => item.description === 'currentDepth')
  540. })
  541. const NON_KEYS = [
  542. 'repairTime',
  543. 'selfStopTime',
  544. 'accidentTime',
  545. 'complexityTime',
  546. 'rectificationTime',
  547. 'waitingStopTime',
  548. 'partyaDesign',
  549. 'partyaPrepare',
  550. 'partyaResource',
  551. 'relocationTime',
  552. 'winterBreakTime',
  553. 'otherNptTime'
  554. ]
  555. const keys = [
  556. 'repairTime',
  557. 'selfStopTime',
  558. 'accidentTime',
  559. 'complexityTime',
  560. 'rectificationTime',
  561. 'waitingStopTime',
  562. 'partyaDesign',
  563. 'partyaPrepare',
  564. 'partyaResource',
  565. 'relocationTime',
  566. 'winterBreakTime',
  567. 'otherNptTime',
  568. 'drillingWorkingTime',
  569. 'otherProductionTime',
  570. 'ratedProductionTime',
  571. 'productionTime',
  572. 'dailyInjectGasTime',
  573. 'otherNptReason'
  574. ]
  575. const sumNonProdTimes = () => {
  576. let sum = 0
  577. NON_KEYS.forEach((field) => {
  578. sum += attrList.value.find((item) => item.description === field)?.fillContent || 0
  579. })
  580. return sum
  581. }
  582. const rhValidateTotalTime =
  583. (isNon: boolean = false) =>
  584. (_rule: any, _value: any, callback: any) => {
  585. const gasTime =
  586. attrList.value.find((item) => item.description === 'dailyInjectGasTime')?.fillContent || 0
  587. const nonProdSum = sumNonProdTimes()
  588. let total = 0
  589. let msg = ''
  590. total = parseFloat((gasTime + nonProdSum).toFixed(2))
  591. msg = `运转(${gasTime})+非生产(${nonProdSum})=${total}H,必须为24H`
  592. if (Math.abs(total - 24) > 0.01) {
  593. if (!isNon) callback(new Error(msg))
  594. else callback(new Error())
  595. } else {
  596. callback()
  597. }
  598. }
  599. // const ryXjValidateTotalTime =
  600. // (isNon: boolean = false) =>
  601. // (_rule: any, _value: any, callback: any) => {
  602. // const rateTime =
  603. // attrList.value.find((item) => item.description === 'ratedProductionTime')?.fillContent || 0
  604. // const time =
  605. // attrList.value.find((item) => item.description === 'productionTime')?.fillContent || 0
  606. // const nonProdSum = sumNonProdTimes()
  607. // let total = 0
  608. // let msg = ''
  609. // total = parseFloat((time + nonProdSum).toFixed(2))
  610. // msg = `生产(${time})+非生产(${nonProdSum})=${total}H,必须等于额定${rateTime}H`
  611. // if (Math.abs(total - rateTime) > 0.01) {
  612. // if (!isNon) callback(new Error(msg))
  613. // else callback(new Error())
  614. // } else {
  615. // callback()
  616. // }
  617. // }
  618. const ryValidateTotalTime =
  619. (isNon: boolean = false) =>
  620. (_rule: any, _value: any, callback: any) => {
  621. const drillingTime =
  622. attrList.value.find((item) => item.description === 'drillingWorkingTime')?.fillContent || 0
  623. const otherTime =
  624. attrList.value.find((item) => item.description === 'otherProductionTime')?.fillContent || 0
  625. const nonProdSum = sumNonProdTimes()
  626. let total = 0
  627. let msg = ''
  628. total = parseFloat((drillingTime + otherTime + nonProdSum).toFixed(2))
  629. msg = `进尺(${drillingTime})+其他(${otherTime})+非生产(${nonProdSum})=${total}H,必须为24H`
  630. if (Math.abs(total - 24) > 0.01) {
  631. if (!isNon) callback(new Error(msg))
  632. else callback(new Error())
  633. } else {
  634. callback()
  635. }
  636. }
  637. const validateOtherReason = (_rule: any, value: any, callback: any) => {
  638. const time = attrList.value.find((item) => item.description === 'otherNptTime')?.fillContent || 0
  639. if (time > 0 && !value) {
  640. callback(new Error('填写了其他时间,必须说明原因'))
  641. } else {
  642. callback()
  643. }
  644. }
  645. const rules = reactive<FormRules>({
  646. dailyInjectGasTime: [
  647. { required: true, message: '请输入当日运转时间' },
  648. { validator: rhValidateTotalTime() }
  649. ],
  650. drillingWorkingTime: [
  651. { required: true, message: '请输入进尺工作时间' },
  652. { validator: ryValidateTotalTime() }
  653. ],
  654. nightSupervisors: { required: true, message: '请输入夜班跟班干部' },
  655. daySupervisors: { required: true, message: '请输入白班跟班干部' },
  656. dailyGasInjection: [
  657. {
  658. validator: (_rule, value, callback) => {
  659. if (companyName.value !== 'rh' || !taskId.value || noGasTasks.value.includes(taskId.value))
  660. return callback()
  661. const dailyInjectGasTime =
  662. attrList.value.find((item) => item.description === 'dailyInjectGasTime')?.fillContent || 0
  663. // if (dailyInjectGasTime > 0 && !(value > 0)) {
  664. // return callback(new Error('当日运转时间大于0,注气量也需要大于0'))
  665. // }
  666. const hasDailyGasInjection = value !== undefined && value !== null && value !== ''
  667. if (dailyInjectGasTime > 0 && !hasDailyGasInjection) {
  668. return callback(new Error('当日运转时间大于0,需要填写当日注气量'))
  669. }
  670. callback()
  671. },
  672. trigger: ['blur', 'change']
  673. }
  674. ],
  675. otherProductionTime: [{ validator: ryValidateTotalTime() }],
  676. // ratedProductionTime: [
  677. // { required: true, message: '请输入额定生产时间', trigger: 'blur' },
  678. // { validator: ryXjValidateTotalTime(), trigger: 'blur' }
  679. // ],
  680. // productionTime: [
  681. // { required: true, message: '请输入生产时间', trigger: 'blur' },
  682. // { validator: ryXjValidateTotalTime(), trigger: 'blur' }
  683. // ],
  684. otherNptReason: [{ validator: validateOtherReason }]
  685. })
  686. const totalValidatorComputed = computed(() => {
  687. if (attrList.value.some((item) => item.description === 'dailyInjectGasTime')) {
  688. return rhValidateTotalTime
  689. }
  690. // else if (attrList.value.some((item) => item.description === 'ratedProductionTime')) {
  691. // return ryXjValidateTotalTime
  692. // }
  693. else if (attrList.value.some((item) => item.description === 'drillingWorkingTime')) {
  694. return ryValidateTotalTime
  695. }
  696. })
  697. nextTick(() => {
  698. const validator = totalValidatorComputed.value
  699. if (!validator) return
  700. NON_KEYS.forEach((field) => {
  701. rules[field] = [{ validator: validator(true) }]
  702. })
  703. })
  704. let cxStatus = true
  705. // 计算数字输入的最大长度(根据阈值动态计算)
  706. const calculateMaxLength = (item: any) => {
  707. if (item.type !== 'double' || !item.threshold) return undefined
  708. const max = parseFloat(item.threshold)
  709. if (isNaN(max)) return undefined
  710. // 整数部分长度 + 可能的小数点 + 两位小数
  711. return max.toString().length + (max.toString().includes('.') ? 0 : 3)
  712. }
  713. // 简单的节流函数,避免提示信息过于频繁
  714. const throttle = <T extends (...args: any[]) => any>(fn: T, delay: number) => {
  715. let lastTime = 0
  716. return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
  717. const now = Date.now()
  718. if (now - lastTime >= delay) {
  719. fn.apply(this, args)
  720. lastTime = now
  721. }
  722. }
  723. }
  724. const showComponent = () => {
  725. if (JSON.parse(fillStatus) === 1 || JSON.parse(fillStatus) === 3) {
  726. showStatus = false
  727. }
  728. }
  729. const noGasTasks = ref<number[]>([])
  730. /** 查询列表 */
  731. const getList = async () => {
  732. loading.value = true
  733. try {
  734. queryParams.deptId = deptId.split(',')[0]
  735. queryParams.userId = deptId.split(',')[1]
  736. queryParams.createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  737. queryParams.orderId = deptId.split(',')[3]
  738. const data = await IotOpeationFillApi.getIotOpeationFillPage(queryParams)
  739. list.value = data
  740. if (cxStatus) {
  741. queryParams.deviceCategoryId = list.value[0].deviceCategoryId
  742. queryParams.deptId = list.value[0].deptId
  743. queryParams.deviceCode = list.value[0].deviceCode
  744. queryParams.deviceName = list.value[0].deviceName
  745. queryParams.deviceId = list.value[0].deviceId
  746. }
  747. await getAttrList()
  748. const daily = list.value.find((item) => item.deviceName === '生产日报') ?? {
  749. wellNamePair: {},
  750. noGasTasks: []
  751. }
  752. taskOptions.value = Object.keys(daily.wellNamePair ?? {}).map((key) => ({
  753. label: daily.wellNamePair[key],
  754. value: Number(key)
  755. }))
  756. noGasTasks.value = (daily.noGasTasks ?? []).map(Number)
  757. taskId.value = taskOptions.value[0]?.value
  758. IotOpeationFillApi.getReportDetails(deptId.split(',')[3]).then((res) => {
  759. reportDetails.value = (res ? (res as any[]) : []).map((item) => ({
  760. reportDate: item.reportDate ?? dayjs(createTime).valueOf(),
  761. startTime: formatT(item.startTime),
  762. endTime: formatT(item.endTime),
  763. duration: item.duration,
  764. currentDepth: item.currentDepth,
  765. currentOperation: item.currentOperation,
  766. constructionDetail: item.constructionDetail
  767. }))
  768. if (!reportDetails.value.length) {
  769. addProductionStatusRow()
  770. }
  771. })
  772. } finally {
  773. loading.value = false
  774. }
  775. }
  776. function formatTimestamp(timestamp) {
  777. // const date = new Date(timestamp * 1000)
  778. return moment.unix(timestamp).format('YYYY-MM-DD')
  779. }
  780. const open = async (_type: string, id?: number) => {
  781. alert(id)
  782. }
  783. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  784. let devName = ''
  785. const openFill = (
  786. deviceCategoryId?: number,
  787. deviceId?: number,
  788. deptId?: number,
  789. deviceName?: string,
  790. deviceCode?: string
  791. ) => {
  792. queryParams.deviceCategoryId = deviceCategoryId
  793. queryParams.deptId = deptId
  794. queryParams.deviceCode = deviceCode
  795. queryParams.deviceName = deviceName
  796. if (queryParams.deviceName == '生产日报') {
  797. devName = '生产日报'
  798. }
  799. queryParams.deviceId = deviceId
  800. getAttrList()
  801. }
  802. // 处理输入事件,实时限制输入格式和最大值
  803. const handleInput = (item: any) => {
  804. if (item.type === 'double') {
  805. // 保存原始值用于后续比较
  806. const originalValue = item.fillContent
  807. // 1. 格式验证:只允许数字和小数点
  808. item.fillContent = item.fillContent.replace(/[^\d.]/g, '')
  809. // 确保只有一个小数点
  810. item.fillContent = item.fillContent.replace(/\.{2,}/g, '.')
  811. // 确保小数点不在开头
  812. item.fillContent = item.fillContent.replace(/^\./g, '')
  813. // 限制小数位数为两位
  814. item.fillContent = item.fillContent.replace(/(\d+)\.(\d{2}).*/, '$1.$2')
  815. // 2. 最大值验证
  816. if (item.threshold) {
  817. const value = parseFloat(item.fillContent)
  818. const max = parseFloat(item.threshold)
  819. if (!isNaN(value) && !isNaN(max) && value > max) {
  820. // 输入值超过阈值时,恢复到修改前的值
  821. item.fillContent = originalValue
  822. .replace(/[^\d.]/g, '')
  823. .replace(/\.{2,}/g, '.')
  824. .replace(/^\./g, '')
  825. .replace(/(\d+)\.(\d{2}).*/, '$1.$2')
  826. if (parseFloat(item.fillContent) > max) {
  827. item.fillContent = max.toString()
  828. }
  829. throttle(() => {
  830. ElMessage.warning(t('operationFillForm.exceedMax', { max }))
  831. }, 1000)()
  832. }
  833. }
  834. if (companyName.value === 'rd') {
  835. // 3. 累计值限制验证(改为弹窗提示但允许继续)
  836. if (item.maxAllowedValue !== undefined) {
  837. const value = parseFloat(item.fillContent)
  838. if (!isNaN(value) && value > item.maxAllowedValue) {
  839. // 不自动修改值,而是显示警告弹窗
  840. let limitDescription = ''
  841. if (item.limitType === 'km') {
  842. limitDescription = `当前累计值${item.currentSumValue} + 3000`
  843. } else if (item.limitType === 'time') {
  844. limitDescription = `当前累计值${item.currentSumValue} + 100`
  845. }
  846. ElMessage.warning(
  847. `填报值 ${value} 超过限制 ${item.maxAllowedValue} (${limitDescription}),请确认是否正确!`
  848. )
  849. }
  850. }
  851. }
  852. }
  853. }
  854. const getAttrList = async () => {
  855. loading.value = true
  856. try {
  857. queryParams.createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  858. const data = await IotOpeationFillApi.getAttrs(queryParams)
  859. const timeKeys = keys.filter((k) => k !== 'otherNptReason')
  860. attrList.value = data[0].nonSumList.map((item) => {
  861. if (timeKeys.includes(item.description)) {
  862. item.fillContent = item.fillContent ?? 0
  863. }
  864. return item
  865. })
  866. attrList1.value = data[0].sumList
  867. // 建立累计数据映射,用于后续验证
  868. const sumMap = new Map()
  869. attrList1.value.forEach((item) => {
  870. // 创建匹配规则:移除"填报"字样的差异,保留核心名称
  871. const coreName = item.name.replace(/填报/g, '')
  872. sumMap.set(coreName, item)
  873. })
  874. // 为非累计数据添加最大值限制
  875. attrList.value.forEach(function (item) {
  876. let strVal = String(item.fillContent || '').trim()
  877. if (strVal !== '') {
  878. const num = Number(strVal)
  879. if (!isNaN(num)) {
  880. if (strVal.includes('.')) {
  881. item.fillContent = Number(num.toFixed(2))
  882. } else {
  883. item.fillContent = num
  884. }
  885. }
  886. }
  887. // if (item.fillContent !== '' && item.fillContent !== null) {
  888. // const num = Number(item.fillContent)
  889. // if (!isNaN(num)) {
  890. // if (item.fillContent.includes('.')) {
  891. // item.fillContent = Number(num.toFixed(2))
  892. // } else {
  893. // item.fillContent = Math.floor(num)
  894. // }
  895. // }
  896. // }
  897. if (companyName.value === 'rd') {
  898. // 添加最大值限制逻辑
  899. const coreName = item.name.replace(/填报/g, '')
  900. const sumItem = sumMap.get(coreName)
  901. if (sumItem) {
  902. // 根据字段名称判断使用哪种限制规则
  903. if (item.name.includes('公里数填报')) {
  904. // 公里数限制:当前累计值 + 3000
  905. item.maxAllowedValue = sumItem.totalRunTime + 3000
  906. item.currentSumValue = sumItem.totalRunTime // 保存当前累计值用于提示
  907. item.limitType = 'km' // 标记为公里数限制
  908. } else if (item.name.includes('运转时长填报')) {
  909. // 运转时长限制:当前累计值 + 100
  910. item.maxAllowedValue = sumItem.totalRunTime + 100
  911. item.currentSumValue = sumItem.totalRunTime // 保存当前累计值用于提示
  912. item.limitType = 'time' // 标记为时长限制
  913. }
  914. }
  915. }
  916. item.deviceCode = queryParams.deviceCode
  917. item.deptId = queryParams.deptId
  918. item.deviceId = queryParams.deviceId
  919. item.deviceCategoryId = queryParams.deviceCategoryId
  920. item.modelId = item.id
  921. console.log(item.fillContent)
  922. })
  923. attrList1.value.forEach(function (item) {
  924. item.deviceCode = queryParams.deviceCode
  925. item.deptId = queryParams.deptId
  926. item.deviceId = queryParams.deviceId
  927. item.deviceCategoryId = queryParams.deviceCategoryId
  928. item.modelId = item.id
  929. })
  930. } finally {
  931. loading.value = false
  932. }
  933. }
  934. const formRef = ref<FormInstance[] | null>(null)
  935. const submitLoading = ref(false)
  936. /** 获取填写信息保存到后台*/
  937. const getFillInfo = async () => {
  938. if (!formRef.value) return
  939. submitLoading.value = true
  940. try {
  941. const validations = formRef.value.map((form) => form.validate())
  942. await Promise.all(validations)
  943. const company = await IotOpeationFillApi.getOrgName(route.params.id.toString().split(',')[0])
  944. if (devName != '生产日报') {
  945. // 检查必填字段
  946. const emptyFields = attrList.value.filter((item) => {
  947. // 只检查非disabled的字段
  948. return (
  949. !(item.isCollection === 1 || fillStatus === '1') &&
  950. (item.fillContent === undefined || item.fillContent === '')
  951. )
  952. })
  953. if (emptyFields.length > 0) {
  954. ElMessage.error(t('operationFillForm.fill'))
  955. return
  956. }
  957. }
  958. if (company === 'rd') {
  959. // 检查是否有超出累计值限制的字段
  960. const exceededFields = attrList.value.filter((item) => {
  961. if (
  962. item.type === 'double' &&
  963. item.maxAllowedValue !== undefined &&
  964. item.fillContent !== '' &&
  965. item.fillContent !== null
  966. ) {
  967. const value = parseFloat(item.fillContent)
  968. return !isNaN(value) && value > item.maxAllowedValue
  969. }
  970. return false
  971. })
  972. // 如果有超出限制的字段,提示用户确认
  973. if (exceededFields.length > 0) {
  974. let exceededMessage = ''
  975. exceededFields.forEach((field) => {
  976. let limitDescription = ''
  977. if (field.limitType === 'km') {
  978. limitDescription = `(${field.currentSumValue} + 3000)`
  979. } else if (field.limitType === 'time') {
  980. limitDescription = `(${field.currentSumValue} + 100)`
  981. }
  982. exceededMessage += `${field.name};\n`
  983. })
  984. // exceededMessage += '\n是否继续保存?'
  985. const confirmResult = await message.confirm(
  986. exceededMessage,
  987. '以下填报项超出限制,是否继续保存?',
  988. '继续保存',
  989. '取消'
  990. )
  991. if (!confirmResult) {
  992. return // 用户取消保存
  993. }
  994. }
  995. }
  996. attrList2.value = attrList.value.concat(attrList1.value)
  997. attrList2.value.forEach(function (item) {
  998. item.pointName = item.name
  999. item.createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  1000. item.userId = deptId.split(',')[1]
  1001. item.id = deptId.split(',')[3]
  1002. })
  1003. const data = attrList2.value as unknown as IotOpeationFillVO
  1004. const reqData = {
  1005. createReqVO: data,
  1006. reportDetails: reportDetails.value.map((item) => ({
  1007. ...item,
  1008. taskId: taskId.value
  1009. }))
  1010. }
  1011. await IotOpeationFillApi.insertLog(reqData)
  1012. message.success(t('common.createSuccess'))
  1013. // 发送操作成功的事件
  1014. emit('success')
  1015. cxStatus = false
  1016. getList()
  1017. } catch (error) {
  1018. console.error('保存失败:', error)
  1019. } finally {
  1020. submitLoading.value = false
  1021. }
  1022. }
  1023. /**清空填写信息*/
  1024. const deleteFillInfo = () => {
  1025. attrList.value.forEach(function (item) {
  1026. item.fillContent = ''
  1027. })
  1028. }
  1029. /** 初始化 **/
  1030. onMounted(async () => {
  1031. const company = await IotOpeationFillApi.getOrgName(route.params.id.toString().split(',')[0])
  1032. companyName.value = company
  1033. getList()
  1034. showComponent()
  1035. })
  1036. </script>
  1037. <style scoped>
  1038. .scrollable-form {
  1039. /* 设置最大高度,超过这个高度会出现滚动条 */
  1040. max-height: 100%; /* 根据你的需求调整 */
  1041. /* 可选:添加内边距和边框美化 */
  1042. padding: 16px;
  1043. /* 超出部分显示垂直滚动条 */
  1044. overflow-y: auto;
  1045. border: 1px solid #e5e7eb;
  1046. border-radius: 4px;
  1047. }
  1048. /* 可选:美化滚动条 */
  1049. .scrollable-form::-webkit-scrollbar {
  1050. width: 6px;
  1051. }
  1052. .scrollable-form::-webkit-scrollbar-track {
  1053. background: #f1f1f1;
  1054. border-radius: 3px;
  1055. }
  1056. .scrollable-form::-webkit-scrollbar-thumb {
  1057. background: #c1c1c1;
  1058. border-radius: 3px;
  1059. }
  1060. .scrollable-form::-webkit-scrollbar-thumb:hover {
  1061. background: #a8a8a8;
  1062. }
  1063. .back-red {
  1064. /* 红色背景 */
  1065. background-color: red;
  1066. }
  1067. .back-blue {
  1068. background-color: grey;
  1069. }
  1070. .step-container {
  1071. display: grid;
  1072. grid-template-columns: 220px 1fr;
  1073. gap: 10px;
  1074. height: 100%;
  1075. min-height: 600px;
  1076. }
  1077. .steps-nav {
  1078. padding-right: 15px;
  1079. overflow-y: auto;
  1080. }
  1081. .form-wrapper {
  1082. padding: 30px;
  1083. background: #fff;
  1084. border-radius: 8px;
  1085. box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
  1086. }
  1087. .navigation-controls {
  1088. margin-top: 40px;
  1089. text-align: center;
  1090. }
  1091. .custom-label {
  1092. padding: 0 10px;
  1093. font-size: 17px;
  1094. font-weight: 1000;
  1095. color: forestgreen;
  1096. }
  1097. .custom-label1 {
  1098. padding: 0 10px;
  1099. font-size: 17px;
  1100. font-weight: 1000;
  1101. }
  1102. .has-border {
  1103. padding: 3px 8px; /* 适当增加内边距,避免文字太贴近边框 */
  1104. font-size: 20px;
  1105. border: 2px solid #333; /* 加粗到2px,使用深灰色#333让边框更清晰 */
  1106. border-radius: 2px; /* 轻微圆角,可选 */
  1107. }
  1108. ::v-deep .el-step__icon {
  1109. color: #fff;
  1110. background-color: #409eff;
  1111. border: 0;
  1112. }
  1113. .step-title-wrapper {
  1114. position: relative;
  1115. display: inline-flex;
  1116. padding-right: 25px;
  1117. align-items: center;
  1118. gap: 8px;
  1119. }
  1120. /* 覆盖步骤条默认样式 */
  1121. :deep(.custom-steps) {
  1122. /* 调整头部位置 */
  1123. .el-step__head {
  1124. top: 3px;
  1125. }
  1126. /* 标题容器定位 */
  1127. .el-step__title {
  1128. display: inline-block;
  1129. padding-right: 0;
  1130. margin-left: 10px;
  1131. }
  1132. /* 步骤连接线 */
  1133. .el-step__line {
  1134. left: 11px;
  1135. background-color: #ebeef5;
  1136. }
  1137. /* 当前步骤样式 */
  1138. .is-process .title-text {
  1139. font-weight: 600;
  1140. color: #409eff;
  1141. }
  1142. /* 完成状态图标 */
  1143. .is-finish .tip-icon {
  1144. color: #67c23a;
  1145. }
  1146. }
  1147. .horizontal-container {
  1148. display: flex;
  1149. flex-wrap: wrap; /* 允许换行 */
  1150. gap: 20px; /* 项目间距 */
  1151. }
  1152. .form-item-container {
  1153. flex: 1; /* 等宽分布 */
  1154. min-width: 200px; /* 最小宽度防止挤压 */
  1155. }
  1156. /* 新增日报填报项的边框样式 */
  1157. .report-border {
  1158. padding: 2px 4px;
  1159. border: 2px solid #42b983; /* 使用Vue标志性的绿色边框 */
  1160. border-radius: 4px;
  1161. }
  1162. :deep(.table-form-item) {
  1163. .el-form-item__content {
  1164. margin-left: 0 !important;
  1165. }
  1166. }
  1167. </style>