table-form.vue 31 KB

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