index1.vue 17 KB

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