index1 copy.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. >
  9. <template #label>
  10. <span
  11. :class="['custom-label', { 'has-border': deviceItem.deviceName === '生产日报' }]"
  12. v-if="deviceItem.isFill === 1"
  13. @click="
  14. openFill(
  15. deviceItem.deviceCategoryId,
  16. deviceItem.deviceId,
  17. deviceItem.deptId,
  18. deviceItem.deviceName,
  19. deviceItem.deviceCode
  20. )
  21. "
  22. >
  23. {{ deviceItem.deviceCode }} ({{ deviceItem.deviceName }})
  24. </span>
  25. <span
  26. :class="['custom-label1', { 'has-border': deviceItem.deviceName === '生产日报' }]"
  27. v-else
  28. @click="
  29. openFill(
  30. deviceItem.deviceCategoryId,
  31. deviceItem.deviceId,
  32. deviceItem.deptId,
  33. deviceItem.deviceName,
  34. deviceItem.deviceCode
  35. )
  36. "
  37. >
  38. {{ deviceItem.deviceCode }} ({{ deviceItem.deviceName }})
  39. </span>
  40. </template>
  41. <div class="form-wrapper">
  42. <el-form label-width="120px" class="scrollable-form">
  43. <div style="margin-left: 24px">
  44. <el-form class="demo-form-inline" :inline="true">
  45. <el-form-item :label="t('common.createTime')" class="custom-label1">
  46. <span style="text-decoration: underline">
  47. {{ createTime }}
  48. </span>
  49. </el-form-item>
  50. <el-form-item :label="t('operationFillForm.team')" class="custom-label1">
  51. <span style="text-decoration: underline">
  52. {{ deviceItem.orgName }}
  53. </span>
  54. </el-form-item>
  55. <el-row :gutter="20">
  56. <el-col
  57. v-for="(summaryItem, summaryIndex) in attrList1"
  58. :key="summaryIndex"
  59. :span="24"
  60. >
  61. <el-form-item :label="summaryItem.name" class="custom-label1">
  62. <span style="text-decoration: underline">
  63. {{ summaryItem.totalRunTime }}
  64. </span>
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. <!-- <el-form-item :label="t('operationFillForm.sumTime')" class="custom-label1">
  69. <span style="text-decoration: underline;">
  70. {{totalRunTime1}}h
  71. </span>
  72. </el-form-item>-->
  73. </el-form>
  74. </div>
  75. <div
  76. v-for="(attrItem, attrIndex) in attrList"
  77. :key="attrIndex"
  78. style="margin-left: 24px"
  79. >
  80. {{ attrItem }}
  81. <!-- 添加提示文字 -->
  82. <div v-if="attrItem.isCollection === 1" class="plc-tip">
  83. <el-alert
  84. :title="t('operationFillForm.alert')"
  85. type="warning"
  86. :closable="false"
  87. center
  88. show-icon
  89. style="width: 320px"
  90. />
  91. </div>
  92. <el-form-item :label="attrItem.name" prop="deviceId" label-position="top">
  93. <div v-if="fillStatus === '1'">
  94. <el-select
  95. disabled
  96. v-model="attrItem.fillContent"
  97. v-if="attrItem.type === 'enum' && attrItem.description !== null"
  98. style="width: 200px"
  99. >
  100. <el-option
  101. v-for="dict in attrItem.name === '非生产原因'
  102. ? getIntDictOptions(attrItem.description)
  103. : getStrDictOptions(attrItem.description)"
  104. :key="dict.label"
  105. :label="dict.label"
  106. :value="
  107. attrItem.name === '非生产原因' ? Number(dict.value) : dict.value.toString()
  108. "
  109. />
  110. </el-select>
  111. <el-input
  112. v-else
  113. v-model="attrItem.fillContent"
  114. clearable
  115. style="width: 200px; margin-right: 10px"
  116. disabled
  117. />
  118. </div>
  119. <el-input
  120. v-else-if="attrItem.type === 'textarea'"
  121. v-model="attrItem.fillContent"
  122. type="textarea"
  123. clearable
  124. style="width: 200px"
  125. />
  126. <el-select
  127. v-model="attrItem.fillContent"
  128. clearable
  129. v-else-if="attrItem.type === 'enum' && attrItem.description !== null"
  130. style="width: 200px"
  131. filterable
  132. >
  133. <el-option
  134. v-for="dict in attrItem.name === '非生产原因'
  135. ? getIntDictOptions(attrItem.description)
  136. : getStrDictOptions(attrItem.description)"
  137. :key="dict.label"
  138. :label="dict.label"
  139. :value="
  140. attrItem.name === '非生产原因' ? Number(dict.value) : dict.value.toString()
  141. "
  142. />
  143. </el-select>
  144. <el-input
  145. v-else
  146. v-model="attrItem.fillContent"
  147. clearable
  148. style="width: 200px"
  149. :placeholder="
  150. attrItem.type === 'double'
  151. ? t('operationFillForm.enterNumber')
  152. : t('operationFillForm.enterContent')
  153. "
  154. @input="handleInput(attrItem)"
  155. :maxlength="attrItem.type === 'double' ? calculateMaxLength(attrItem) : undefined"
  156. />
  157. </el-form-item>
  158. </div>
  159. <el-form-item>
  160. <el-button type="primary" @click="getFillInfo" v-show="showStatus">{{
  161. t('operationFillForm.confirm')
  162. }}</el-button>
  163. <el-button type="info" @click="deleteFillInfo" v-show="showStatus">{{
  164. t('operationFill.clear')
  165. }}</el-button>
  166. </el-form-item>
  167. </el-form>
  168. </div>
  169. </el-tab-pane>
  170. </el-tabs>
  171. </ContentWrap>
  172. </template>
  173. <script setup lang="ts">
  174. import { IotOpeationFillApi, IotOpeationFillVO } from '@/api/pms/iotopeationfill'
  175. import { ElMessage } from 'element-plus'
  176. import moment from 'moment'
  177. import { getIntDictOptions, getStrDictOptions } from '@/utils/dict'
  178. import { useRoute } from 'vue-router'
  179. /** 运行记录填报 列表 */
  180. defineOptions({ name: 'FillOrderInfo' })
  181. const route = useRoute()
  182. const message = useMessage() // 消息弹窗
  183. const { t } = useI18n() // 国际化
  184. /** 提交表单 */
  185. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  186. const loading = ref(true) // 列表的加载中
  187. const { params } = useRoute() // 查询参数
  188. const deptId = params.id as string
  189. const list = ref<IotOpeationFillVO[]>([]) // 列表的数据
  190. const attrList = ref<IotOpeationFillVO[]>([]) // 非累计属性集合
  191. const attrList1 = ref<IotOpeationFillVO[]>([]) // 累计属性集合
  192. const attrList2 = ref<IotOpeationFillVO[]>([]) // 属性集合
  193. let companyName = ref('')
  194. let fillStatus = deptId.split(',')[4]
  195. let createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  196. let showStatus = true
  197. const queryParams = reactive<any>({
  198. pageNo: 1,
  199. pageSize: 10,
  200. deviceCode: undefined,
  201. deviceName: undefined,
  202. fillContent: undefined,
  203. deviceType: undefined,
  204. deviceComponent: undefined,
  205. deptId: undefined,
  206. orgName: undefined,
  207. proId: undefined,
  208. proName: undefined,
  209. teamId: undefined,
  210. teamName: undefined,
  211. dutyName: undefined,
  212. creDate: [],
  213. createTime: [],
  214. deviceCategoryId: 1,
  215. deviceId: undefined,
  216. threshold: undefined,
  217. defaultValue: undefined,
  218. isSum: undefined
  219. })
  220. let cxStatus = true
  221. // 计算数字输入的最大长度(根据阈值动态计算)
  222. const calculateMaxLength = (item: any) => {
  223. if (item.type !== 'double' || !item.threshold) return undefined
  224. const max = parseFloat(item.threshold)
  225. if (isNaN(max)) return undefined
  226. // 整数部分长度 + 可能的小数点 + 两位小数
  227. return max.toString().length + (max.toString().includes('.') ? 0 : 3)
  228. }
  229. // 简单的节流函数,避免提示信息过于频繁
  230. const throttle = <T extends (...args: any[]) => any>(fn: T, delay: number) => {
  231. let lastTime = 0
  232. return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
  233. const now = Date.now()
  234. if (now - lastTime >= delay) {
  235. fn.apply(this, args)
  236. lastTime = now
  237. }
  238. }
  239. }
  240. const showComponent = () => {
  241. if (JSON.parse(fillStatus) === 1 || JSON.parse(fillStatus) === 3) {
  242. showStatus = false
  243. }
  244. }
  245. /** 查询列表 */
  246. const getList = async () => {
  247. loading.value = true
  248. try {
  249. queryParams.deptId = deptId.split(',')[0]
  250. queryParams.userId = deptId.split(',')[1]
  251. queryParams.createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  252. queryParams.orderId = deptId.split(',')[3]
  253. const data = await IotOpeationFillApi.getIotOpeationFillPage(queryParams)
  254. list.value = data
  255. if (cxStatus) {
  256. queryParams.deviceCategoryId = list.value[0].deviceCategoryId
  257. queryParams.deptId = list.value[0].deptId
  258. queryParams.deviceCode = list.value[0].deviceCode
  259. queryParams.deviceName = list.value[0].deviceName
  260. queryParams.deviceId = list.value[0].deviceId
  261. }
  262. getAttrList()
  263. } finally {
  264. loading.value = false
  265. }
  266. }
  267. function formatTimestamp(timestamp) {
  268. // const date = new Date(timestamp * 1000)
  269. return moment.unix(timestamp).format('YYYY-MM-DD')
  270. }
  271. const open = async (_type: string, id?: number) => {
  272. alert(id)
  273. }
  274. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  275. let devName = ''
  276. const openFill = (
  277. deviceCategoryId?: number,
  278. deviceId?: number,
  279. deptId?: number,
  280. deviceName?: string,
  281. deviceCode?: string
  282. ) => {
  283. queryParams.deviceCategoryId = deviceCategoryId
  284. queryParams.deptId = deptId
  285. queryParams.deviceCode = deviceCode
  286. queryParams.deviceName = deviceName
  287. if (queryParams.deviceName == '生产日报') {
  288. devName = '生产日报'
  289. }
  290. queryParams.deviceId = deviceId
  291. getAttrList()
  292. }
  293. // 处理输入事件,实时限制输入格式和最大值
  294. const handleInput = (item: any) => {
  295. if (item.type === 'double') {
  296. // 保存原始值用于后续比较
  297. const originalValue = item.fillContent
  298. // 1. 格式验证:只允许数字和小数点
  299. item.fillContent = item.fillContent.replace(/[^\d.]/g, '')
  300. // 确保只有一个小数点
  301. item.fillContent = item.fillContent.replace(/\.{2,}/g, '.')
  302. // 确保小数点不在开头
  303. item.fillContent = item.fillContent.replace(/^\./g, '')
  304. // 限制小数位数为两位
  305. item.fillContent = item.fillContent.replace(/(\d+)\.(\d{2}).*/, '$1.$2')
  306. // 2. 最大值验证
  307. if (item.threshold) {
  308. const value = parseFloat(item.fillContent)
  309. const max = parseFloat(item.threshold)
  310. if (!isNaN(value) && !isNaN(max) && value > max) {
  311. // 输入值超过阈值时,恢复到修改前的值
  312. item.fillContent = originalValue
  313. .replace(/[^\d.]/g, '')
  314. .replace(/\.{2,}/g, '.')
  315. .replace(/^\./g, '')
  316. .replace(/(\d+)\.(\d{2}).*/, '$1.$2')
  317. if (parseFloat(item.fillContent) > max) {
  318. item.fillContent = max.toString()
  319. }
  320. throttle(() => {
  321. ElMessage.warning(t('operationFillForm.exceedMax', { max }))
  322. }, 1000)()
  323. }
  324. }
  325. if (companyName.value === 'rd') {
  326. // 3. 累计值限制验证(改为弹窗提示但允许继续)
  327. if (item.maxAllowedValue !== undefined) {
  328. const value = parseFloat(item.fillContent)
  329. if (!isNaN(value) && value > item.maxAllowedValue) {
  330. // 不自动修改值,而是显示警告弹窗
  331. let limitDescription = ''
  332. if (item.limitType === 'km') {
  333. limitDescription = `当前累计值${item.currentSumValue} + 3000`
  334. } else if (item.limitType === 'time') {
  335. limitDescription = `当前累计值${item.currentSumValue} + 100`
  336. }
  337. ElMessage.warning(
  338. `填报值 ${value} 超过限制 ${item.maxAllowedValue} (${limitDescription}),请确认是否正确!`
  339. )
  340. }
  341. }
  342. }
  343. }
  344. }
  345. const getAttrList = async () => {
  346. loading.value = true
  347. try {
  348. queryParams.createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  349. const data = await IotOpeationFillApi.getAttrs(queryParams)
  350. attrList.value = data[0].nonSumList
  351. attrList1.value = data[0].sumList
  352. // 建立累计数据映射,用于后续验证
  353. const sumMap = new Map()
  354. attrList1.value.forEach((item) => {
  355. // 创建匹配规则:移除"填报"字样的差异,保留核心名称
  356. const coreName = item.name.replace(/填报/g, '')
  357. sumMap.set(coreName, item)
  358. })
  359. // 为非累计数据添加最大值限制
  360. attrList.value.forEach(function (item) {
  361. if (item.fillContent !== '' && item.fillContent !== null) {
  362. const num = Number(item.fillContent)
  363. if (!isNaN(num)) {
  364. if (item.fillContent.includes('.')) {
  365. item.fillContent = Number(num.toFixed(2))
  366. } else {
  367. item.fillContent = Math.floor(num)
  368. }
  369. }
  370. }
  371. if (companyName.value === 'rd') {
  372. // 添加最大值限制逻辑
  373. const coreName = item.name.replace(/填报/g, '')
  374. const sumItem = sumMap.get(coreName)
  375. if (sumItem) {
  376. // 根据字段名称判断使用哪种限制规则
  377. if (item.name.includes('公里数填报')) {
  378. // 公里数限制:当前累计值 + 3000
  379. item.maxAllowedValue = sumItem.totalRunTime + 3000
  380. item.currentSumValue = sumItem.totalRunTime // 保存当前累计值用于提示
  381. item.limitType = 'km' // 标记为公里数限制
  382. } else if (item.name.includes('运转时长填报')) {
  383. // 运转时长限制:当前累计值 + 100
  384. item.maxAllowedValue = sumItem.totalRunTime + 100
  385. item.currentSumValue = sumItem.totalRunTime // 保存当前累计值用于提示
  386. item.limitType = 'time' // 标记为时长限制
  387. }
  388. }
  389. }
  390. item.deviceCode = queryParams.deviceCode
  391. item.deptId = queryParams.deptId
  392. item.deviceId = queryParams.deviceId
  393. item.deviceCategoryId = queryParams.deviceCategoryId
  394. item.modelId = item.id
  395. console.log(item.fillContent)
  396. })
  397. attrList1.value.forEach(function (item) {
  398. item.deviceCode = queryParams.deviceCode
  399. item.deptId = queryParams.deptId
  400. item.deviceId = queryParams.deviceId
  401. item.deviceCategoryId = queryParams.deviceCategoryId
  402. item.modelId = item.id
  403. })
  404. } finally {
  405. loading.value = false
  406. }
  407. }
  408. /** 获取填写信息保存到后台*/
  409. const getFillInfo = async () => {
  410. try {
  411. const company = await IotOpeationFillApi.getOrgName(route.params.id.toString().split(',')[0])
  412. if (devName != '生产日报') {
  413. // 检查必填字段
  414. const emptyFields = attrList.value.filter((item) => {
  415. // 只检查非disabled的字段
  416. return (
  417. !(item.isCollection === 1 || fillStatus === '1') &&
  418. (item.fillContent === undefined || item.fillContent === '')
  419. )
  420. })
  421. if (emptyFields.length > 0) {
  422. ElMessage.error(t('operationFillForm.fill'))
  423. return
  424. }
  425. }
  426. if (company === 'rd') {
  427. // 检查是否有超出累计值限制的字段
  428. const exceededFields = attrList.value.filter((item) => {
  429. if (
  430. item.type === 'double' &&
  431. item.maxAllowedValue !== undefined &&
  432. item.fillContent !== '' &&
  433. item.fillContent !== null
  434. ) {
  435. const value = parseFloat(item.fillContent)
  436. return !isNaN(value) && value > item.maxAllowedValue
  437. }
  438. return false
  439. })
  440. // 如果有超出限制的字段,提示用户确认
  441. if (exceededFields.length > 0) {
  442. let exceededMessage = ''
  443. exceededFields.forEach((field) => {
  444. let limitDescription = ''
  445. if (field.limitType === 'km') {
  446. limitDescription = `(${field.currentSumValue} + 3000)`
  447. } else if (field.limitType === 'time') {
  448. limitDescription = `(${field.currentSumValue} + 100)`
  449. }
  450. exceededMessage += `${field.name};\n`
  451. })
  452. // exceededMessage += '\n是否继续保存?'
  453. const confirmResult = await message.confirm(
  454. exceededMessage,
  455. '以下填报项超出限制,是否继续保存?',
  456. '继续保存',
  457. '取消'
  458. )
  459. if (!confirmResult) {
  460. return // 用户取消保存
  461. }
  462. }
  463. }
  464. attrList2.value = attrList.value.concat(attrList1.value)
  465. attrList2.value.forEach(function (item) {
  466. item.pointName = item.name
  467. item.createTime = formatTimestamp(JSON.parse(deptId.split(',')[2].substring(0, 10)))
  468. item.userId = deptId.split(',')[1]
  469. item.id = deptId.split(',')[3]
  470. })
  471. const data = attrList2.value as unknown as IotOpeationFillVO
  472. await IotOpeationFillApi.insertLog(data)
  473. message.success(t('common.createSuccess'))
  474. // 发送操作成功的事件
  475. emit('success')
  476. cxStatus = false
  477. getList()
  478. } catch (error) {
  479. console.error('保存失败:', error)
  480. }
  481. }
  482. /**清空填写信息*/
  483. const deleteFillInfo = () => {
  484. attrList.value.forEach(function (item) {
  485. item.fillContent = ''
  486. })
  487. }
  488. /** 初始化 **/
  489. onMounted(async () => {
  490. const company = await IotOpeationFillApi.getOrgName(route.params.id.toString().split(',')[0])
  491. companyName.value = company
  492. getList()
  493. showComponent()
  494. })
  495. </script>
  496. <style scoped>
  497. .scrollable-form {
  498. /* 设置最大高度,超过这个高度会出现滚动条 */
  499. max-height: 500px; /* 根据你的需求调整 */
  500. /* 可选:添加内边距和边框美化 */
  501. padding: 16px;
  502. /* 超出部分显示垂直滚动条 */
  503. overflow-y: auto;
  504. border: 1px solid #e5e7eb;
  505. border-radius: 4px;
  506. }
  507. /* 可选:美化滚动条 */
  508. .scrollable-form::-webkit-scrollbar {
  509. width: 6px;
  510. }
  511. .scrollable-form::-webkit-scrollbar-track {
  512. background: #f1f1f1;
  513. border-radius: 3px;
  514. }
  515. .scrollable-form::-webkit-scrollbar-thumb {
  516. background: #c1c1c1;
  517. border-radius: 3px;
  518. }
  519. .scrollable-form::-webkit-scrollbar-thumb:hover {
  520. background: #a8a8a8;
  521. }
  522. .back-red {
  523. /* 红色背景 */
  524. background-color: red;
  525. }
  526. .back-blue {
  527. background-color: grey;
  528. }
  529. .step-container {
  530. display: grid;
  531. grid-template-columns: 220px 1fr;
  532. gap: 10px;
  533. height: 100%;
  534. min-height: 600px;
  535. }
  536. .steps-nav {
  537. padding-right: 15px;
  538. overflow-y: auto;
  539. }
  540. .form-wrapper {
  541. padding: 30px;
  542. background: #fff;
  543. border-radius: 8px;
  544. box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
  545. }
  546. .navigation-controls {
  547. margin-top: 40px;
  548. text-align: center;
  549. }
  550. .custom-label {
  551. padding: 0 10px;
  552. font-size: 17px;
  553. font-weight: 1000;
  554. color: forestgreen;
  555. }
  556. .custom-label1 {
  557. padding: 0 10px;
  558. font-size: 17px;
  559. font-weight: 1000;
  560. }
  561. .has-border {
  562. padding: 3px 8px; /* 适当增加内边距,避免文字太贴近边框 */
  563. font-size: 20px;
  564. border: 2px solid #333; /* 加粗到2px,使用深灰色#333让边框更清晰 */
  565. border-radius: 2px; /* 轻微圆角,可选 */
  566. }
  567. ::v-deep .el-step__icon {
  568. color: #fff;
  569. background-color: #409eff;
  570. border: 0;
  571. }
  572. .step-title-wrapper {
  573. position: relative;
  574. display: inline-flex;
  575. padding-right: 25px;
  576. align-items: center;
  577. gap: 8px;
  578. }
  579. /* 覆盖步骤条默认样式 */
  580. :deep(.custom-steps) {
  581. /* 调整头部位置 */
  582. .el-step__head {
  583. top: 3px;
  584. }
  585. /* 标题容器定位 */
  586. .el-step__title {
  587. display: inline-block;
  588. padding-right: 0;
  589. margin-left: 10px;
  590. }
  591. /* 步骤连接线 */
  592. .el-step__line {
  593. left: 11px;
  594. background-color: #ebeef5;
  595. }
  596. /* 当前步骤样式 */
  597. .is-process .title-text {
  598. font-weight: 600;
  599. color: #409eff;
  600. }
  601. /* 完成状态图标 */
  602. .is-finish .tip-icon {
  603. color: #67c23a;
  604. }
  605. }
  606. .horizontal-container {
  607. display: flex;
  608. flex-wrap: wrap; /* 允许换行 */
  609. gap: 20px; /* 项目间距 */
  610. }
  611. .form-item-container {
  612. flex: 1; /* 等宽分布 */
  613. min-width: 200px; /* 最小宽度防止挤压 */
  614. }
  615. /* 新增日报填报项的边框样式 */
  616. .report-border {
  617. padding: 2px 4px;
  618. border: 2px solid #42b983; /* 使用Vue标志性的绿色边框 */
  619. border-radius: 4px;
  620. }
  621. </style>