table-form.vue 29 KB

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