table-form.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <div class="hc-table-form-content">
  3. <div class="hc-content-box">
  4. <div class="hc-table-forem-box">
  5. <el-scrollbar v-if="excelIdVal && isTableForm">
  6. <div class="hc-excel-table-form-view" :id="`table-form-${excelIdVal}`"></div>
  7. </el-scrollbar>
  8. <HcStatus :desc="statusDesc" v-else/>
  9. <div class="hc-fixed-page" v-if="formLogDataList.length > 1">
  10. <el-scrollbar>
  11. <template v-for="(item,index) in formLogDataList">
  12. <el-button :type="index === formLogIndex ? 'primary' : ''" hc-btn @click="getBussDataInfo(index)">
  13. <HcIcon name="sticky-note"/>
  14. <span>第{{index + 1}}页</span>
  15. </el-button>
  16. </template>
  17. </el-scrollbar>
  18. </div>
  19. </div>
  20. <div class="hc-right-pian-box hc-flex-column">
  21. <DateCalendar :dateData="dateData" @choice-date="dateCalendarChoice"/>
  22. <el-alert title="蓝色代表当天已填写过日志" type="warning" show-icon/>
  23. <div class="my-4" v-if="menuItem?.nodeType === 7 || menuItem?.nodeType === 11">
  24. <el-button type="primary" hc-btn @click="showProcessModal">
  25. <HcIcon name="add-circle"/>
  26. <span>关联工序</span>
  27. </el-button>
  28. </div>
  29. <div class="hc-process-box" v-if="menuItem?.nodeType === 7 || menuItem?.nodeType === 11">
  30. <el-scrollbar>
  31. <div class="process-item-box" v-for="(item,index) in processDataList">
  32. <div class="process-item">{{item.pathName}}</div>
  33. <HcIcon name="close-circle" fill class="process-icon" @click="deleProcess(index)"/>
  34. </div>
  35. </el-scrollbar>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="hc-footer-box">
  40. <HcTooltip keys="ledger_query_save_form">
  41. <el-button type="primary" hc-btn :disabled="!isTableForm" :loading="tableFormSaveLoading" @click="tableFormSaveClick">
  42. <HcIcon name="save"/>
  43. <span>保存</span>
  44. </el-button>
  45. </HcTooltip>
  46. <HcTooltip keys="ledger_query_report_form">
  47. <el-button hc-btn :disabled="!isTableForm">
  48. <HcIcon name="send-plane-2"/>
  49. <span>上报</span>
  50. </el-button>
  51. </HcTooltip>
  52. <HcTooltip keys="ledger_query_preview_form">
  53. <el-button hc-btn :disabled="!isTableForm" :loading="previewLoading" @click="previewBussPdf">
  54. <HcIcon name="eye"/>
  55. <span>预览</span>
  56. </el-button>
  57. </HcTooltip>
  58. <HcTooltip keys="ledger_query_copy_form">
  59. <el-button hc-btn :disabled="!isTableForm" @click="copyTableFormClick">
  60. <HcIcon name="file-copy-2"/>
  61. <span>复制当前表格及内容</span>
  62. </el-button>
  63. </HcTooltip>
  64. <HcTooltip keys="ledger_query_time_form">
  65. <el-button hc-btn :disabled="!isTableForm" @click="copyTimeLogModal">
  66. <HcIcon name="file-copy-2"/>
  67. <span>复制任意时间</span>
  68. </el-button>
  69. </HcTooltip>
  70. <HcTooltip keys="ledger_query_add_form">
  71. <el-button hc-btn :disabled="!isTableForm" @click="addTableFormClick">
  72. <HcIcon name="add-circle"/>
  73. <span>新增表格</span>
  74. </el-button>
  75. </HcTooltip>
  76. </div>
  77. <!--关联工序-->
  78. <HcDialog :show="processNodeModal" title="选择关联工序" widths="62rem" @close="processNodeModal = false" @save="processNodeClick">
  79. <div class="node-many-tree">
  80. <el-tree :load="ElTreeLoadNode" lazy class="my-tree" :props="processTreeProps" show-checkbox node-key="primaryKeyId"
  81. :default-checked-keys="defaultChecked" :default-expanded-keys="defaultExpanded" check-strictly ref="processElTree"/>
  82. </div>
  83. </HcDialog>
  84. <!--复制任意时间-->
  85. <HcDialog :show="copyTimeModal" title="复制任意时间" widths="360px" bg-color="#f1f5f8" saveText="复制" @close="copyTimeModal = false" :loading="copyTimeLoading" @save="copyTimeSaveClick">
  86. <DateCalendar :dateData="dateData" @choice-date="copyTimeChoice"/>
  87. <el-alert title="请选择一个日期复制" type="warning" show-icon/>
  88. </HcDialog>
  89. </div>
  90. </template>
  91. <script setup>
  92. import {ref, watch, nextTick} from "vue";
  93. import queryApi from '~api/ledger/query';
  94. import wbsQueryApi from '~api/data-fill/query';
  95. import {HTableForm} from "~src/plugins/HTableForm"
  96. import DateCalendar from "./dateCalendar/index.vue"
  97. import {getObjValue, getObjNullValue, isString, getArrValue} from "vue-utils-plus"
  98. //参数
  99. const props = defineProps({
  100. projectId: {
  101. type: [String,Number],
  102. default: ''
  103. },
  104. contractId: {
  105. type: [String,Number],
  106. default: ''
  107. },
  108. items: {
  109. type: Object,
  110. default: () => ({})
  111. }
  112. })
  113. //变量
  114. const projectId = ref(props.projectId);
  115. const contractId = ref(props.contractId);
  116. const menuItem = ref(props.items);
  117. const excelIdVal = ref('');
  118. const statusDesc = ref('');
  119. //监听
  120. watch(() => [
  121. props.projectId,
  122. props.contractId,
  123. props.items,
  124. ], ([pid, cid, item]) => {
  125. projectId.value = pid
  126. contractId.value = cid
  127. menuItem.value = item
  128. getQueryData()
  129. })
  130. //渲染完成
  131. nextTick(() => {
  132. getQueryData()
  133. })
  134. //获取相关数据
  135. const getQueryData = () => {
  136. const {excelId} = menuItem.value
  137. excelIdVal.value = excelId > 0 ? excelId + '' : ''
  138. }
  139. //日期日历回调
  140. const recordTime = ref('')
  141. const dateCalendarChoice = ({date, choices}) => {
  142. const {primaryKeyId} = menuItem.value
  143. recordTime.value = choices
  144. getExcelHtml(excelIdVal.value)
  145. getTheLogBusinessData(excelIdVal.value, choices)
  146. getSubmitLogDateList(date,primaryKeyId)
  147. queryCurrentLogSelectProcessList(choices)
  148. }
  149. //获取模板标签数据
  150. const isTableForm = ref(false)
  151. const excelHtmlData = ref('')
  152. const getExcelHtml = async (excelId) => {
  153. if (excelId) {
  154. //获取数据
  155. const { error, code, data } = await queryApi.getExcelHtml({
  156. pkeyId: excelId
  157. }, false)
  158. //处理数据
  159. const resData = isString(data) ? data || '' : ''
  160. excelHtmlData.value = resData
  161. if (!error && code === 200 && resData) {
  162. setHTableForm(resData,excelId,tableFormData.value)
  163. } else {
  164. isTableForm.value = false
  165. statusDesc.value = '暂无表单'
  166. window?.$message?.warning('暂无表单')
  167. }
  168. } else {
  169. statusDesc.value = `excelId: ${excelId || '-1 或 空'}`
  170. isTableForm.value = false
  171. }
  172. }
  173. //渲染表单
  174. const tableFormApp = ref(null)
  175. const setHTableForm = async (resData, excelId, info) => {
  176. //先卸载
  177. if (tableFormApp.value) {
  178. tableFormApp.value?.unmount()
  179. }
  180. if (resData) {
  181. isTableForm.value = true
  182. await nextTick(() => {
  183. tableFormApp.value = HTableForm({
  184. template: resData,
  185. tableForm: info,
  186. appId: `#table-form-${excelId}`
  187. })
  188. })
  189. } else {
  190. isTableForm.value = false
  191. statusDesc.value = '暂无表单'
  192. window?.$message?.warning('暂无表单')
  193. }
  194. }
  195. //表单数据
  196. const formLogDataList = ref([])
  197. const getTheLogBusinessData = async (excelId, recordDate) => {
  198. const {primaryKeyId} = menuItem.value
  199. const { data } = await queryApi.getTheLogBusinessData({
  200. pkeyId: excelId,
  201. nodePrimaryKeyId: primaryKeyId,
  202. recordTime: recordDate,
  203. theLogId: ""
  204. }, false)
  205. //设置默认数据
  206. let formArrData = getArrValue(data)
  207. for (let i = 0; i < formArrData.length; i++) {
  208. formArrData[i] = setFormDefaultData(formArrData[i])
  209. }
  210. formLogDataList.value = formArrData
  211. getBussDataInfo()
  212. }
  213. //获取表单初始数据
  214. const formLogIndex = ref(0)
  215. const tableFormData = ref({})
  216. const getBussDataInfo = (index = 0) => {
  217. const formLog = formLogDataList.value
  218. const info = getObjValue(formLog[index])
  219. formLogIndex.value = index
  220. if (getObjNullValue(info)) {
  221. const pickerKey = info['pickerKey'] || ''
  222. if (pickerKey) {
  223. const pickerKeys = pickerKey.split(',')
  224. for (let i = 0; i < pickerKeys.length; i++) {
  225. const val = info[pickerKeys[i]] || ''
  226. if (val) {
  227. const data = val.replace(/'/g,'"');
  228. info[pickerKeys[i]] = JSON.parse(data)
  229. } else {
  230. info[pickerKeys[i]] = []
  231. }
  232. }
  233. }
  234. //有数据,关联数据
  235. tableFormData.value = info
  236. } else {
  237. tableFormData.value = {}
  238. }
  239. if (excelHtmlData.value) {
  240. setHTableForm(excelHtmlData.value, excelIdVal.value, tableFormData.value)
  241. }
  242. }
  243. //获取日期记录
  244. const dateData = ref([])
  245. const getSubmitLogDateList = async ({year},pid) => {
  246. if (pid > 0) {
  247. const { data } = await queryApi.getSubmitLogDateList({
  248. projectId: projectId.value,
  249. contractId: contractId.value,
  250. primaryKeyId: pid,
  251. year: year
  252. }, false)
  253. //处理数据
  254. dateData.value = getArrValue(data)
  255. } else {
  256. dateData.value = []
  257. }
  258. }
  259. //关联工序
  260. const processNodeModal = ref(false)
  261. const showProcessModal = () => {
  262. processNodeModal.value = true
  263. }
  264. //树的配置
  265. const processElTree = ref(null)
  266. const processTreeProps = {label: 'title', children: 'children', isLeaf: 'notExsitChild'}
  267. const defaultExpanded = ref([]) //默认展开
  268. const defaultChecked = ref([]) //默认选中
  269. //树形结构异步加载数据
  270. const ElTreeLoadNode = async (node, resolve) => {
  271. if (node.level === 0) {
  272. const {error, code, data} = await wbsQueryApi.queryWbsTreeData({
  273. contractId: contractId.value ||'',
  274. contractIdRelation: '',
  275. primaryKeyId: '',
  276. parentId: ''
  277. })
  278. //处理数据
  279. if (!error && code === 200) {
  280. const resData = getArrValue(data)
  281. resolve(resData)
  282. defaultExpanded.value = [resData[0]?.primaryKeyId]
  283. } else {
  284. resolve([])
  285. }
  286. } else {
  287. const {id, contractIdRelation, primaryKeyId} = node.data
  288. const {error, code, data} = await wbsQueryApi.queryWbsTreeData({
  289. contractId: contractId.value || '',
  290. contractIdRelation: contractIdRelation,
  291. primaryKeyId: id,
  292. parentId: contractIdRelation ? primaryKeyId : id
  293. })
  294. //处理数据
  295. if (!error && code === 200) {
  296. resolve(getArrValue(data))
  297. } else {
  298. resolve([])
  299. }
  300. }
  301. }
  302. //确认关联工序
  303. const processDataList = ref([])
  304. const processNodeClick = () => {
  305. const keys = processElTree.value.getCheckedKeys();
  306. let NodesArr = []
  307. for (let index = 0; index < keys.length; index++) {
  308. let pathArr = [];
  309. let node = processElTree.value.getNode(keys[index]);
  310. getPathName(node, pathArr);
  311. NodesArr.push({
  312. primaryKeyId: keys[index],
  313. pathName: pathArr.join('/')
  314. })
  315. }
  316. processDataList.value = NodesArr
  317. processNodeModal.value = false
  318. }
  319. //获取节点的路径名字
  320. const getPathName = (node, pathArr) => {
  321. if (node.parent?.parent) {
  322. pathArr.unshift(node.data?.title.replace(/(^\s*)|(\s*$)/g, "")); //去掉头尾空格
  323. getPathName(node.parent, pathArr);
  324. } else {
  325. return; //根节点结束
  326. }
  327. }
  328. //移除工序
  329. const deleProcess = (index) => {
  330. processDataList.value.splice(index, 1);
  331. }
  332. //保存数据
  333. const tableFormSaveLoading = ref(false)
  334. const tableFormSaveClick = async () => {
  335. const res = await saveExcelBussData()
  336. if (res) {
  337. await getBussPdfInfo()
  338. }
  339. }
  340. //保存
  341. const saveExcelBussData = async () => {
  342. let linkTabIds = setProcessData(); //处理工序ID
  343. if (linkTabIds) {
  344. tableFormSaveLoading.value = true
  345. const { error, code } = await queryApi.saveExcelBussData({
  346. dataInfo: {orderList: formLogDataList.value}
  347. },false)
  348. tableFormSaveLoading.value = false
  349. if (!error && code === 200) {
  350. window?.$message?.success('保存成功')
  351. return true
  352. } else {
  353. window?.$message?.warning('保存失败')
  354. return false
  355. }
  356. }
  357. }
  358. //处理工序数据
  359. const setProcessData = () => {
  360. let linkTabIds = [], {nodeType} = menuItem.value;
  361. if (nodeType === 7 || nodeType === 11) {
  362. const nodes = processDataList.value || [];
  363. if (nodes.length > 0) {
  364. for (let i = 0; i < nodes.length; i++) {
  365. let item = nodes[i];
  366. linkTabIds.push({
  367. path: item['pathName'],
  368. primaryKeyId: item['primaryKeyId']
  369. })
  370. }
  371. return linkTabIds
  372. } else {
  373. window?.$message?.warning('请先关联工序')
  374. return false
  375. }
  376. } else {
  377. return true
  378. }
  379. }
  380. //预览
  381. const previewLoading = ref(false)
  382. const previewBussPdf = () => {
  383. getBussPdfInfo()
  384. }
  385. //预览PDF
  386. const getBussPdfInfo = async () => {
  387. previewLoading.value = true
  388. const {primaryKeyId} = menuItem.value
  389. const { error, code, data } = await queryApi.getBussPdfInfo({
  390. pkeyId: excelIdVal.value,
  391. nodePrimaryKeyId: primaryKeyId,
  392. recordTime: recordTime.value,
  393. theLogId: ""
  394. }, false)
  395. //处理数据
  396. previewLoading.value = false
  397. const resData = isString(data) ? data || '' : ''
  398. if (!error && code === 200 && resData) {
  399. window.open(resData,'_blank')
  400. } else {
  401. window?.$message?.warning('暂无PDF,无法预览')
  402. }
  403. }
  404. //获取当前日志资料关联的工序节点信息
  405. const queryCurrentLogSelectProcessList = async (dateVal) => {
  406. const {primaryKeyId} = menuItem.value
  407. const { data } = await queryApi.queryCurrentLogSelectProcessList({
  408. nodePrimaryKeyId: primaryKeyId,
  409. recordTime: dateVal,
  410. theLogId: ""
  411. }, false)
  412. //处理数据
  413. let dataKeys = getArrValue(data), NodesArr = []
  414. for (let i = 0; i < dataKeys.length; i++) {
  415. NodesArr.push({
  416. primaryKeyId: dataKeys[i]?.primaryKeyId,
  417. pathName: dataKeys[i]?.path
  418. })
  419. }
  420. processDataList.value = NodesArr
  421. }
  422. //新增表格
  423. const addTableFormClick = () => {
  424. const defaultData = setFormDefaultData({})
  425. formLogDataList.value.push(defaultData)
  426. const index = formLogDataList.value.length - 1
  427. getBussDataInfo(index)
  428. }
  429. //复制表格内容
  430. const copyTableFormClick = () => {
  431. const formLog = formLogDataList.value
  432. const logIndex = formLogIndex.value
  433. const defaultData = setFormDefaultData(formLog[logIndex])
  434. formLogDataList.value.push(defaultData)
  435. const index = formLogDataList.value.length - 1
  436. getBussDataInfo(index)
  437. }
  438. //复制任意时间
  439. const copyTimeLogModal = () => {
  440. copyTimeModal.value = true
  441. copyTimeLoading.value = false
  442. }
  443. const copyTimeModal = ref(false)
  444. //选择日期
  445. const copyTimeChoices = ref('')
  446. const copyTimeChoice = ({choices}) => {
  447. copyTimeChoices.value = choices
  448. }
  449. //确认复制
  450. const copyTimeLoading = ref(false)
  451. const copyTimeSaveClick = async () => {
  452. copyTimeLoading.value = true
  453. const {primaryKeyId} = menuItem.value
  454. const { error, code, data } = await queryApi.copyTheLogBusinessData({
  455. nodePrimaryKeyId: primaryKeyId,
  456. currentTime: recordTime.value,
  457. targetTime: copyTimeChoices.value
  458. }, false)
  459. //处理数据
  460. copyTimeLoading.value = false
  461. if (!error && code === 200) {
  462. window?.location?.reload() //刷新页面
  463. } else {
  464. window?.$message?.warning('复制失败')
  465. }
  466. }
  467. //设置表单默认数据
  468. const setFormDefaultData = (formInfo) => {
  469. return {
  470. ...formInfo,
  471. projectId: projectId.value,
  472. contractId: contractId.value,
  473. recordTime: recordTime.value,
  474. pkeyId: excelIdVal.value,
  475. isTheLog: "1",
  476. theLogId: "",
  477. classify: 1
  478. }
  479. }
  480. </script>
  481. <style lang="scss" scoped>
  482. .hc-table-form-content {
  483. flex: 1;
  484. display: flex;
  485. flex-direction: column;
  486. position: relative;
  487. margin-left: 24px;
  488. height: 100%;
  489. .hc-content-box {
  490. flex: 1;
  491. display: flex;
  492. position: relative;
  493. margin-bottom: 24px;
  494. height: calc(100% - 105px);
  495. .hc-table-forem-box {
  496. flex: 1;
  497. padding: 24px;
  498. margin-right: 24px;
  499. position: relative;
  500. background: #f1f5f8;
  501. border-radius: 10px;
  502. box-shadow: -2px 0px 10px 0px rgba(32,37,50,0.03), 0px 10px 21px 20px rgba(32,37,50,0.03);
  503. .hc-fixed-page {
  504. position: absolute;
  505. top: 4px;
  506. right: 4px;
  507. bottom: 4px;
  508. z-index: 99;
  509. overflow: hidden;
  510. }
  511. }
  512. .hc-right-pian-box {
  513. width: 360px;
  514. position: relative;
  515. padding: 24px 20px;
  516. background: #f1f5f8;
  517. border-radius: 10px;
  518. box-shadow: -2px 0px 10px 0px rgba(32,37,50,0.03), 0px 10px 21px 20px rgba(32,37,50,0.03);
  519. .hc-process-box {
  520. position: relative;
  521. flex: 1;
  522. overflow: hidden;
  523. .hc-scrollbar-box {
  524. display: contents;
  525. }
  526. .process-item-box {
  527. position: relative;
  528. color: #838791;
  529. font-size: 14px;
  530. padding: 8px 0;
  531. display: flex;
  532. align-items: flex-start;
  533. .process-item {
  534. position: relative;
  535. flex: 1;
  536. }
  537. .process-icon {
  538. font-size: 20px;
  539. cursor: pointer;
  540. margin-left: 16px;
  541. transition: color 0.2s;
  542. &:hover {
  543. color: var(--el-color-primary-light-3);
  544. }
  545. }
  546. }
  547. .process-item-box + .process-item-box {
  548. border-top: 0.5px solid #e9e9e9;
  549. }
  550. }
  551. }
  552. }
  553. .hc-footer-box {
  554. position: relative;
  555. height: 80px;
  556. background: #f1f5f8;
  557. border-radius: 10px;
  558. display: flex;
  559. align-items: center;
  560. padding: 20px 24px;
  561. box-shadow: -2px 0px 10px 0 rgba(32,37,50,0.03), 0 -10px 21px 3px rgba(32,37,50,0.03);
  562. overflow: hidden;
  563. }
  564. }
  565. </style>
  566. <style lang="scss">
  567. .node-many-tree {
  568. position: relative;
  569. .my-tree .el-tree-node .el-checkbox .el-checkbox__inner {
  570. display: none;
  571. }
  572. .my-tree .el-tree-node .is-leaf + .el-checkbox .el-checkbox__inner {
  573. display: inline-block;
  574. }
  575. }
  576. .hc-table-form-content .hc-content-box .hc-table-forem-box .hc-fixed-page {
  577. .el-button {
  578. display: block;
  579. margin: 20px;
  580. }
  581. }
  582. </style>