table-form.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. <template>
  2. <div class="hc-table-form-content">
  3. <div class="hc-content-box">
  4. <div class="hc-table-forem-box">
  5. <HcTableForm
  6. ref="tableFormRef"
  7. :form="tableFormData"
  8. :html="excelHtmlData"
  9. :loading="loading"
  10. :pkey="excelIdVal"
  11. @render="tableFormRender"
  12. />
  13. </div>
  14. <div v-if="formLogDataList.length > 1" class="hc-fixed-page">
  15. <el-scrollbar>
  16. <div class="hc-fixed-page-list-box">
  17. <template v-for="(item, index) in formLogDataList">
  18. <div
  19. :class="index === formLogIndex ? 'primary' : ''" class="fixed-page-item"
  20. @click="getBussDataInfo(index)"
  21. >
  22. <div class="name-box">
  23. <HcIcon name="sticky-note" />
  24. <span class="page">第{{ index + 1 }}页</span>
  25. </div>
  26. <div class="close-box" @click.stop="closeBussDataInfo(item, index)">
  27. <HcIcon name="close" />
  28. </div>
  29. </div>
  30. </template>
  31. </div>
  32. </el-scrollbar>
  33. </div>
  34. <div class="hc-right-pian-box hc-flex-column">
  35. <DateCalendar :date-data="dateData" :record-date="recordDates" @choice-date="dateCalendarChoice" />
  36. <el-alert show-icon title="蓝色代表当天已填写过日志" type="warning" />
  37. <div v-if="menuItem?.nodeType === 7 || menuItem?.nodeType === 11" class="my-4">
  38. <el-button hc-btn type="primary" @click="showProcessModal">
  39. <HcIcon name="add-circle" />
  40. <span>关联工序</span>
  41. </el-button>
  42. </div>
  43. <div v-if="menuItem?.nodeType === 7 || menuItem?.nodeType === 11" class="hc-process-box">
  44. <el-scrollbar>
  45. <div v-for="(item, index) in processDataList" class="process-item-box">
  46. <div class="process-item">
  47. {{ item.path }}
  48. </div>
  49. <HcIcon class="process-icon" fill name="close-circle" @click="deleProcess(index)" />
  50. </div>
  51. </el-scrollbar>
  52. </div>
  53. </div>
  54. </div>
  55. <div class="hc-footer-box">
  56. <HcTooltip keys="ledger_query_save_form">
  57. <el-button
  58. :disabled="!isTableForm || taskStatus === 3 || taskStatus === 4"
  59. :loading="tableFormSaveLoading" hc-btn color="#12C060" style="color: white;"
  60. @click="tableFormSaveClick"
  61. >
  62. <HcIcon name="save" />
  63. <span>保存</span>
  64. </el-button>
  65. </HcTooltip>
  66. <HcTooltip keys="ledger_query_report_form">
  67. <el-button
  68. :disabled="!isTableForm || taskStatus === 1 || taskStatus === 3 || taskStatus === 4" hc-btn
  69. color="#FF976A" style="color: white;" @click="reportModalClick"
  70. >
  71. <HcIcon name="send-plane-2" />
  72. <span>上报</span>
  73. </el-button>
  74. </HcTooltip>
  75. <HcTooltip keys="ledger_query_preview_form">
  76. <el-button
  77. :disabled="!isTableForm || taskStatus === 1 " :loading="previewLoading" hc-btn
  78. color="#A16222" @click="previewBussPdf"
  79. >
  80. <HcIcon name="eye" />
  81. <span>预览</span>
  82. </el-button>
  83. </HcTooltip>
  84. <HcTooltip keys="ledger_query_copy_form">
  85. <el-button
  86. :disabled="!isTableForm || taskStatus === 3 || taskStatus === 4" hc-btn
  87. color="#567722" @click="copyTableFormClick"
  88. >
  89. <HcIcon name="file-copy-2" />
  90. <span>复制当前表格及内容</span>
  91. </el-button>
  92. </HcTooltip>
  93. <HcTooltip keys="ledger_query_time_form">
  94. <el-button
  95. :disabled="!isTableForm || taskStatus === 3 || taskStatus === 4" hc-btn
  96. color="#567722" @click="copyTimeLogModal"
  97. >
  98. <HcIcon name="file-copy-2" />
  99. <span>复制任意时间</span>
  100. </el-button>
  101. </HcTooltip>
  102. <HcTooltip keys="ledger_query_add_form">
  103. <el-button
  104. :disabled="!isTableForm || taskStatus === 3 || taskStatus === 4" hc-btn
  105. color="#37c0fe" style="color: white;" @click="addTableFormClick"
  106. >
  107. <HcIcon name="add-circle" />
  108. <span>新增表格</span>
  109. </el-button>
  110. </HcTooltip>
  111. <HcTooltip keys="ledger_query_abolish_form">
  112. <el-button
  113. :disabled="!isTableForm || taskStatus === 1 || taskStatus === 2" hc-btn
  114. color="#FF976A" style="color: white;" @click="abolishTableFormClick"
  115. >
  116. <HcIcon name="delete-bin-3" />
  117. <span>废除</span>
  118. </el-button>
  119. </HcTooltip>
  120. </div>
  121. <!-- 关联工序 -->
  122. <hc-new-dialog v-model="processNodeModal" title="选择关联工序" widths="62rem" is-table @save="processNodeClick">
  123. <div class="node-many-tree">
  124. <!-- <el-tree
  125. ref="processElTree" :default-checked-keys="defaultChecked"
  126. :default-expanded-keys="defaultExpanded" :load="ElTreeLoadNode" :props="processTreeProps"
  127. check-strictly
  128. class="my-tree" lazy node-key="primaryKeyId"
  129. show-checkbox
  130. /> -->
  131. <HcLazyTree
  132. ref="processElTree"
  133. :h-props="processTreeProps"
  134. :auto-expand-keys="defaultExpanded"
  135. check-strictly show-checkbox
  136. :default-checked-keys="defaultChecked"
  137. @load="ElTreeLoadNode"
  138. />
  139. </div>
  140. </hc-new-dialog>
  141. <!-- 复制任意时间 -->
  142. <hc-new-dialog v-model="copyTimeModal" :loading="copyTimeLoading" :padding="false" is-table save-text="复制" title="复制任意时间" widths="62rem" @save="copyTimeSaveClick">
  143. <div class="hc-user-time-box">
  144. <div class="tree-box">
  145. <el-scrollbar>
  146. <el-tree
  147. :data="copyTimeTreeData" :default-expanded-keys="copyTimeTreeKeys"
  148. :props="copyTimeTreeProps"
  149. accordion class="hc-tree-node" highlight-current
  150. node-key="hierarchy" @node-click="copyTimeTreeNodeClick"
  151. />
  152. </el-scrollbar>
  153. </div>
  154. <div class="user-box">
  155. <HcTable
  156. ref="copyTimeTableRef" :column="copyTimeTableColumn" :datas="copyTimeTableData" :loading="copyTimeTableLoading"
  157. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  158. @selection-change="copyTimeTableSelection"
  159. />
  160. </div>
  161. </div>
  162. </hc-new-dialog>
  163. <!-- 批量上报审批 -->
  164. <HcReportModal
  165. :ids="logId"
  166. :addition="reportAddition" :contract-id="contractId" :project-id="projectId"
  167. :show="showReportModal" :task-name="reportTaskName" :type-data="menuItem.primaryKeyId"
  168. title="日志填报上报"
  169. type="log" url="contractLog/startTaskTheLog" @finish="showReportFinish"
  170. @hide="showReportModal = false"
  171. />
  172. </div>
  173. </template>
  174. <script setup>
  175. import { onActivated, onDeactivated, onMounted, onUnmounted, ref, watch } from 'vue'
  176. import { arrToId, getArrValue, getObjVal, getObjValue, isArrIndex, isNullES, isString } from 'js-fast-way'
  177. import DateCalendar from './dateCalendar/index.vue'
  178. //import HcTableForm from "~com/table-form/index.vue";
  179. import HTableForm from '~src/plugins/HTableForm'
  180. import wbsQueryApi from '~api/data-fill/query'
  181. import queryApi from '~api/ledger/query'
  182. import { useAppStore } from '~src/store'
  183. import { toPdfPage } from '~uti/btn-auth'
  184. //参数
  185. const props = defineProps({
  186. projectId: {
  187. type: [String, Number],
  188. default: '',
  189. },
  190. contractId: {
  191. type: [String, Number],
  192. default: '',
  193. },
  194. items: {
  195. type: Object,
  196. default: () => ({}),
  197. },
  198. userName: {
  199. type: [String, Number],
  200. default: '',
  201. },
  202. })
  203. const useAppState = useAppStore()
  204. //变量
  205. const projectId = ref(props.projectId)
  206. const contractId = ref(props.contractId)
  207. const menuItem = ref(props.items)
  208. const userName = ref(props.userName)
  209. const excelIdVal = ref('')
  210. const tableFormRef = ref(null)
  211. const contractInfo = ref(useAppState.getContractInfo)
  212. const { contractType } = contractInfo.value
  213. const classifyType = ref(contractType === 2 ? '2' : '1')
  214. //监听
  215. watch(() => [
  216. props.projectId,
  217. props.contractId,
  218. props.items,
  219. props.userName,
  220. ], ([pid, cid, item, name]) => {
  221. projectId.value = pid
  222. contractId.value = cid
  223. menuItem.value = item
  224. userName.value = name
  225. getQueryData()
  226. })
  227. //渲染完成
  228. onMounted(() => {
  229. setQueryDataDate()
  230. setMountOnEventKey()
  231. })
  232. //获取相关数据
  233. const getQueryData = () => {
  234. setQueryDataDate()
  235. const date = recordDate.value ?? {}, time = recordTime.value ?? ''
  236. getExcelBusinessData(date, time)
  237. }
  238. const setQueryDataDate = () => {
  239. const { excelId } = menuItem.value
  240. excelIdVal.value = excelId > 0 ? excelId + '' : ''
  241. }
  242. //日期日历回调
  243. const recordTime = ref('')
  244. const recordDate = ref({})
  245. const recordDates = ref({})
  246. const dateCalendarChoice = ({ date, choices, dates }) => {
  247. recordTime.value = choices
  248. recordDate.value = date
  249. recordDates.value = dates
  250. getExcelBusinessData(date, choices)
  251. }
  252. //获取数据
  253. const loading = ref(false)
  254. const getExcelBusinessData = async (date, choices) => {
  255. const { primaryKeyId } = menuItem.value
  256. loading.value = true
  257. await getTheLogBusinessData(excelIdVal.value, choices)
  258. await getExcelHtml(excelIdVal.value)
  259. loading.value = false
  260. await getSubmitLogDateList(date, primaryKeyId)
  261. await checkTheLogTaskStatus(choices, primaryKeyId)
  262. }
  263. //获取模板标签数据
  264. const isTableForm = ref(false)
  265. const excelHtmlData = ref('')
  266. const getExcelHtml = async (excelId) => {
  267. if (excelId) {
  268. //获取数据
  269. const { error, code, data } = await queryApi.getExcelHtml({
  270. contractId: contractId.value || '',
  271. pkeyId: excelId,
  272. }, false)
  273. //处理数据
  274. const resData = isString(data) ? data || '' : ''
  275. if (!error && code === 200 && resData) {
  276. excelHtmlData.value = resData
  277. } else {
  278. excelHtmlData.value = ''
  279. isTableForm.value = false
  280. window?.$message?.warning('暂无表单')
  281. }
  282. } else {
  283. isTableForm.value = false
  284. window?.$message?.error(`excelId: ${excelId || '-1 或 空'}`)
  285. }
  286. }
  287. //渲染表单完成
  288. const tableFormRender = (form) => {
  289. isTableForm.value = form.isRenderForm
  290. }
  291. //表单数据
  292. const formLogDataList = ref([])
  293. const getTheLogBusinessData = async (excelId, recordDate) => {
  294. const { primaryKeyId } = menuItem.value
  295. const { data } = await queryApi.getTheLogBusinessData({
  296. contractId: contractId.value || '',
  297. pkeyId: excelId,
  298. nodePrimaryKeyId: primaryKeyId,
  299. recordTime: recordDate,
  300. theLogId: '',
  301. }, false)
  302. //设置默认数据
  303. let formArrData = getArrValue(data)
  304. if (formArrData.length > 0) {
  305. logId.value = formArrData[0].logId
  306. for (let i = 0; i < formArrData.length; i++) {
  307. formArrData[i] = setFormDefaultData(formArrData[i])
  308. }
  309. } else {
  310. formArrData = [setFormDefaultData()]
  311. }
  312. formLogDataList.value = formArrData
  313. getBussDataInfo()
  314. }
  315. //获取表单初始数据
  316. const formLogIndex = ref(0)
  317. const tableFormData = ref({})
  318. const getBussDataInfo = (index = 0) => {
  319. const formLog = formLogDataList.value
  320. const info = getObjValue(formLog[index])
  321. formLogIndex.value = index
  322. if (getObjVal(info)) {
  323. tableFormData.value = info
  324. } else {
  325. tableFormData.value = {}
  326. }
  327. tableFormRef.value?.setExcelHtml()
  328. queryCurrentLogSelectProcessList(info?.id ?? '')
  329. }
  330. //获取日期记录
  331. const dateData = ref([])
  332. const getSubmitLogDateList = async ({ year }, pid) => {
  333. if (pid > 0 && year) {
  334. const { data } = await queryApi.getSubmitLogDateList({
  335. projectId: projectId.value,
  336. contractId: contractId.value,
  337. primaryKeyId: pid,
  338. year: year,
  339. }, false)
  340. //处理数据
  341. dateData.value = getArrValue(data)
  342. } else {
  343. dateData.value = []
  344. }
  345. }
  346. //获取当前资料的任务状态
  347. const taskStatus = ref(1)
  348. const checkTheLogTaskStatus = async (choices, primaryKeyId) => {
  349. if (primaryKeyId > 0) {
  350. const { error, code, data } = await queryApi.checkTheLogTaskStatus({
  351. projectId: projectId.value,
  352. contractId: contractId.value,
  353. nodePrimaryKeyId: primaryKeyId,
  354. recordTime: choices,
  355. }, false)
  356. //处理数据
  357. const res = isNullES(data) ? '' : data || ''
  358. if (!error && code === 200 && res) {
  359. //1和2的时候所有按钮皆可操作,废除 除外
  360. //3和4时, 除了预览和废除 都不行
  361. taskStatus.value = data
  362. } else {
  363. taskStatus.value = 1
  364. }
  365. } else {
  366. taskStatus.value = 1
  367. }
  368. }
  369. //关联工序
  370. const processNodeModal = ref(false)
  371. const showProcessModal = () => {
  372. processNodeModal.value = true
  373. defaultChecked.value = []
  374. processDataList.value.forEach((ele)=>{
  375. defaultChecked.value.push(ele?.primaryKeyId)
  376. })
  377. }
  378. //树的配置
  379. const processElTree = ref(null)
  380. const processTreeProps = { label: 'title', children: 'children', isLeaf: 'notExsitChild' }
  381. const defaultExpanded = ref([]) //默认展开
  382. const defaultChecked = ref([]) //默认选中
  383. //树形结构异步加载数据
  384. const ElTreeLoadNode = async ({ node, item, level }, resolve) => {
  385. if (node.level === 0) {
  386. const { error, code, data } = await wbsQueryApi.queryWbsTreeData({
  387. contractId: contractId.value || '',
  388. contractIdRelation: '',
  389. primaryKeyId: '',
  390. parentId: '',
  391. classifyType: classifyType.value,
  392. tableOwner:'1',
  393. })
  394. //处理数据
  395. if (!error && code === 200) {
  396. const resData = getArrValue(data)
  397. resolve(resData)
  398. defaultExpanded.value = [resData[0]?.primaryKeyId]
  399. } else {
  400. resolve([])
  401. }
  402. } else {
  403. const { id, contractIdRelation, primaryKeyId } = node.data
  404. const { error, code, data } = await wbsQueryApi.queryWbsTreeData({
  405. contractId: contractId.value || '',
  406. contractIdRelation: contractIdRelation || '',
  407. primaryKeyId: id,
  408. parentId: contractIdRelation ? primaryKeyId : id,
  409. classifyType: classifyType.value,
  410. tableOwner:'1',
  411. })
  412. //处理数据
  413. if (!error && code === 200) {
  414. // resolve(getArrValue(data))
  415. let resdata = getArrValue(data)
  416. resdata.forEach((ele)=>{
  417. ele.colorStatus = 1
  418. })
  419. resolve(resdata)
  420. } else {
  421. resolve([])
  422. }
  423. }
  424. }
  425. //数组对象去重
  426. const getNorepeatArr = (tempArr)=> {
  427. let newArr = []
  428. for (let i = 0; i < tempArr.length; i++) {
  429. if (newArr.indexOf(tempArr[i].primaryKeyId) == -1) {
  430. newArr.push(tempArr[i].primaryKeyId)
  431. } else {
  432. tempArr.splice(i, 1)
  433. i--
  434. }
  435. }
  436. return tempArr
  437. }
  438. //确认关联工序
  439. const processDataList = ref([])
  440. const processNodeClick = () => {
  441. const keys = processElTree.value.treeRef.getCheckedKeys()
  442. const formIndex = formLogIndex.value
  443. const formData = formLogDataList.value[formIndex]
  444. let linkTabIds = getArrValue(formData?.linkTabIds)
  445. if (keys.length === 0) {
  446. linkTabIds = []
  447. }
  448. //去出掉取消勾选的
  449. for (let index = 0; index < keys.length; index++) {
  450. linkTabIds = linkTabIds.filter((ele)=>{
  451. if (ele.primaryKeyId === keys[index]) {
  452. return ele
  453. }
  454. })
  455. }
  456. for (let index = 0; index < keys.length; index++) {
  457. let pathArr = []
  458. let node = processElTree.value.treeRef.getNode(keys[index])
  459. getPathName(node, pathArr)
  460. linkTabIds.push({
  461. path: pathArr.join('/'),
  462. primaryKeyId: keys[index],
  463. })
  464. }
  465. //去除掉重复的
  466. getNorepeatArr(linkTabIds)
  467. formLogDataList.value[formIndex]['linkTabIds'] = linkTabIds
  468. processDataList.value = linkTabIds
  469. processNodeModal.value = false
  470. }
  471. //获取节点的路径名字
  472. const getPathName = (node, pathArr) => {
  473. if (node.parent?.parent) {
  474. pathArr.unshift(node.data?.title.replace(/(^\s*)|(\s*$)/g, '')) //去掉头尾空格
  475. getPathName(node.parent, pathArr)
  476. } else {
  477. return //根节点结束
  478. }
  479. }
  480. //移除工序
  481. const deleProcess = (index) => {
  482. const formIndex = formLogIndex.value
  483. const formData = formLogDataList.value[formIndex]
  484. const linkTabIds = getArrValue(formData?.linkTabIds)
  485. linkTabIds.splice(index, 1)
  486. formLogDataList.value[formIndex]['linkTabIds'] = linkTabIds
  487. processDataList.value = linkTabIds
  488. }
  489. //保存数据
  490. const tableFormSaveLoading = ref(false)
  491. const tableFormSaveClick = async () => {
  492. const { primaryKeyId } = menuItem.value
  493. const res = await saveExcelBussData()
  494. if (res) {
  495. await checkTheLogTaskStatus(recordTime.value, primaryKeyId)
  496. // await getBussPdfInfo()
  497. tableFormSaveLoading.value = false
  498. }
  499. }
  500. //保存
  501. const logId = ref('')
  502. const saveExcelBussData = async () => {
  503. let isLinkTabIds = getLinkTabIds() //处理工序ID
  504. const { primaryKeyId } = menuItem.value
  505. if (isLinkTabIds) {
  506. tableFormSaveLoading.value = true
  507. const { error, code, msg, data } = await queryApi.saveExcelBussData({
  508. dataInfo: { orderList: formLogDataList.value },
  509. nodePrimaryKeyId: primaryKeyId,
  510. }, false)
  511. if (!error && code === 200) {
  512. logId.value = data
  513. window?.$message?.success(msg)
  514. return true
  515. } else {
  516. tableFormSaveLoading.value = false
  517. window?.$message?.warning(msg)
  518. return false
  519. }
  520. }
  521. }
  522. //处理工序数据
  523. const getLinkTabIds = () => {
  524. let { nodeType } = menuItem.value
  525. let isLink = false
  526. if (nodeType === 7 || nodeType === 11) {
  527. isLink = formLogDataList.value.some((item) => {
  528. const linkIds = getArrValue(item?.linkTabIds)
  529. return linkIds.length > 0
  530. })
  531. if (isLink) {
  532. return true
  533. } else {
  534. window?.$message?.warning('请先关联工序')
  535. return false
  536. }
  537. } else {
  538. return true
  539. }
  540. }
  541. //预览
  542. const previewLoading = ref(false)
  543. const previewBussPdf = () => {
  544. getBussPdfInfo()
  545. }
  546. //预览PDF
  547. const getBussPdfInfo = async () => {
  548. previewLoading.value = true
  549. const { primaryKeyId } = menuItem.value
  550. const { error, code, data } = await queryApi.getBussPdfInfo({
  551. contractId: contractId.value || '',
  552. pkeyId: excelIdVal.value,
  553. nodePrimaryKeyId: primaryKeyId,
  554. recordTime: recordTime.value,
  555. theLogId: '',
  556. }, false)
  557. //处理数据
  558. previewLoading.value = false
  559. const resData = isString(data) ? data || '' : ''
  560. if (!error && code === 200 && resData) {
  561. toPdfPage(resData)
  562. //window.open(resData, '_blank')
  563. } else {
  564. window?.$message?.warning('暂无PDF,无法预览')
  565. }
  566. }
  567. //获取当前日志资料关联的工序节点信息
  568. const queryCurrentLogSelectProcessList = async (bid) => {
  569. if (bid) {
  570. const { error, code, data, msg } = await queryApi.queryCurrentLogSelectProcessList({
  571. contractId: contractId.value || '',
  572. businessId: bid ?? '',
  573. }, false)
  574. //处理数据
  575. const formIndex = formLogIndex.value
  576. if (!error && code === 200) {
  577. let linkTabIds = getArrValue(data)
  578. formLogDataList.value[formIndex]['linkTabIds'] = linkTabIds
  579. processDataList.value = linkTabIds
  580. } else {
  581. processDataList.value = []
  582. defaultChecked.value = []
  583. if (msg) window?.$message?.warning(msg)
  584. }
  585. } else {
  586. const formIndex = formLogIndex.value
  587. const formData = formLogDataList.value[formIndex]
  588. processDataList.value = getArrValue(formData?.linkTabIds)
  589. }
  590. }
  591. //新增表格
  592. const addTableFormClick = () => {
  593. const defaultData = setFormDefaultData({})
  594. formLogDataList.value.push(defaultData)
  595. const index = formLogDataList.value.length - 1
  596. getBussDataInfo(index)
  597. }
  598. //复制表格内容
  599. const copyTableFormClick = () => {
  600. const formLog = formLogDataList.value
  601. const logIndex = formLogIndex.value
  602. const defaultData = setFormDefaultData(formLog[logIndex])
  603. formLogDataList.value.push({
  604. ...defaultData,
  605. id: '',
  606. })
  607. const index = formLogDataList.value.length - 1
  608. getBussDataInfo(index)
  609. }
  610. //复制任意时间
  611. const copyTimeModal = ref(false)
  612. const copyTimeLogModal = () => {
  613. copyTimeModal.value = true
  614. copyTimeLoading.value = false
  615. queryReportLogTimeTree()
  616. }
  617. //日期数
  618. const copyTimeTreeProps = {
  619. children: 'treeList', label: 'name',
  620. }
  621. const copyTimeTreeData = ref([])
  622. const copyTimeTreeKeys = ref([])
  623. //获取当前合同段下本日志节点的填报资料日期树
  624. const queryReportLogTimeTree = async () => {
  625. const { primaryKeyId } = menuItem.value
  626. const { data } = await queryApi.queryReportLogTimeTree({
  627. contractId: contractId.value || '',
  628. nodePrimaryKeyId: primaryKeyId,
  629. })
  630. const res = getArrValue(data)
  631. copyTimeTreeData.value = res
  632. if (res.length > 0) {
  633. copyTimeTreeKeys.value = [res[0]?.hierarchy]
  634. }
  635. }
  636. //日期树被点击
  637. const copyTimeTreeNodeClick = (data) => {
  638. queryLogTimeTreeList(data?.hierarchy)
  639. }
  640. //复制任意时间的记录人
  641. const copyTimeTableRef = ref(null)
  642. const copyTimeTableColumn = ref([
  643. { key: 'createUserName', name: '记录人' },
  644. { key: 'recordTime', name: '时间' },
  645. ])
  646. const copyTimeTableData = ref([])
  647. //获取填报记录
  648. const copyTimeTableLoading = ref(false)
  649. const queryLogTimeTreeList = async (time) => {
  650. copyTimeTableLoading.value = true
  651. const { primaryKeyId } = menuItem.value
  652. const { data } = await queryApi.queryLogTimeTreeList({
  653. contractId: contractId.value || '',
  654. nodePrimaryKeyId: primaryKeyId,
  655. time: time,
  656. })
  657. copyTimeTableLoading.value = false
  658. copyTimeTableData.value = getArrValue(data)
  659. }
  660. //多选
  661. const copyTimeTableKeys = ref([])
  662. const copyTimeTableSelection = (rows) => {
  663. copyTimeTableKeys.value = rows.filter((item) => {
  664. return (item ?? '') !== ''
  665. })
  666. }
  667. //确认复制
  668. const copyTimeLoading = ref(false)
  669. const copyTimeSaveClick = () => {
  670. const rows = copyTimeTableKeys.value
  671. if (rows.length > 0) {
  672. const ids = arrToId(rows)
  673. copyTheLogBusinessData(ids)
  674. } else {
  675. window.$message?.warning('请先勾选记录人')
  676. }
  677. }
  678. //复制任意时间
  679. const copyTheLogBusinessData = async (ids) => {
  680. copyTimeLoading.value = true
  681. const { primaryKeyId } = menuItem.value
  682. const { error, code, msg } = await queryApi.copyTheLogBusinessData({
  683. contractId: contractId.value || '',
  684. nodePrimaryKeyId: primaryKeyId,
  685. currentTime: recordTime.value,
  686. theLogId: ids,
  687. })
  688. //处理数据
  689. copyTimeLoading.value = false
  690. if (!error && code === 200) {
  691. copyTimeModal.value = false
  692. window?.$message?.success('复制成功')
  693. setTimeout(() => {
  694. // window?.location?.reload() //刷新页面
  695. setQueryDataDate()
  696. setMountOnEventKey()
  697. getQueryData()
  698. }, 1000)
  699. } else {
  700. window.$message.error(msg)
  701. }
  702. }
  703. //设置表单默认数据
  704. const setFormDefaultData = (formInfo = {}) => {
  705. return {
  706. linkTabIds: [],
  707. ...formInfo,
  708. projectId: projectId.value,
  709. contractId: contractId.value,
  710. recordTime: recordTime.value,
  711. pkeyId: excelIdVal.value,
  712. isTheLog: '1',
  713. theLogId: '',
  714. classify: 1,
  715. }
  716. }
  717. //删除记录
  718. const closeBussDataInfo = async (item, index) => {
  719. console.log(item, '删除')
  720. if (item?.id) {
  721. const { error, code, data } = await queryApi.removeLogTab({
  722. id:item?.id,
  723. })
  724. //处理数据
  725. if (!error && code === 200) {
  726. window.$message.success('删除成功')
  727. } else {
  728. window.$message.error('操作失败')
  729. }
  730. }
  731. formLogDataList.value.splice(index, 1)
  732. const logIndex = index <= 0 ? 0 : index - 1
  733. formLogIndex.value = logIndex
  734. getBussDataInfo(logIndex)
  735. }
  736. //批量上报
  737. const reportTaskName = ref('')
  738. const reportAddition = ref({})
  739. const showReportModal = ref(false)
  740. const reportModalClick = async () => {
  741. await tableFormSaveClick()
  742. const { primaryKeyId, title } = menuItem.value
  743. reportTaskName.value = `${recordTime.value} ${title} ${userName.value}`
  744. reportAddition.value = {
  745. nodePrimaryKeyId: primaryKeyId,
  746. recordTime: recordTime.value,
  747. }
  748. tableFormSaveLoading.value = false
  749. showReportModal.value = true
  750. }
  751. //上报完成
  752. const showReportFinish = () => {
  753. showReportModal.value = false
  754. window?.location?.reload() //刷新页面
  755. }
  756. //废除
  757. const abolishTableFormClick = () => {
  758. window?.$messageBox?.alert('是否废除已上报的文件?', '废除文件', {
  759. showCancelButton: true,
  760. confirmButtonText: '确定废除',
  761. cancelButtonText: '取消',
  762. callback: (action) => {
  763. if (action === 'confirm') {
  764. theLogOneAbolish()
  765. }
  766. },
  767. })
  768. }
  769. //确认废除
  770. const theLogOneAbolish = async () => {
  771. const { primaryKeyId } = menuItem.value
  772. const { error, code } = await queryApi.theLogOneAbolish({
  773. projectId: projectId.value,
  774. contractId: contractId.value,
  775. nodePrimaryKeyId: primaryKeyId,
  776. recordTime: recordTime.value,
  777. })
  778. //处理数据
  779. if (!error && code === 200) {
  780. window.$message?.success('废除成功')
  781. window?.location?.reload() //刷新页面
  782. }
  783. }
  784. //缓存被激活时
  785. onActivated(() => {
  786. setMountOnEventKey()
  787. })
  788. //缓存时被移除
  789. onDeactivated(() => {
  790. HTableForm.unmountEventKey()
  791. })
  792. const setMountOnEventKey = () => {
  793. HTableForm.setOnEventKey({
  794. //按下ctrl键 或 control 键
  795. onCtrlDown: () => {
  796. //window.$HcLog('全局按键', '按下ctrl键 或 control 键')
  797. tableFormRef.value?.setIsCtrlKey(true)
  798. },
  799. //按下复制快捷键
  800. onCtrlDownC: (event) => {
  801. //window.$HcLog('全局按键', '按下复制快捷键')
  802. tableFormRef.value?.setCopyKeyList(event)
  803. },
  804. //按下粘贴快捷键
  805. onCtrlDownV: async (event) => {
  806. //window.$HcLog('全局按键', '按下粘贴快捷键')
  807. await tableFormRef.value?.setPasteKeyList(event)
  808. },
  809. //放开ctrl键 或 control 键
  810. onCtrlUp: () => {
  811. //window.$HcLog('全局按键', '放开ctrl键 或 control 键')
  812. tableFormRef.value?.setIsCtrlKey(false)
  813. },
  814. })
  815. }
  816. //页面被卸载
  817. onUnmounted(() => {
  818. HTableForm.unmountEventKey()
  819. })
  820. </script>
  821. <style lang="scss" scoped>
  822. @import "./table-form.scss";
  823. </style>