table-form.vue 15 KB

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