print.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="hc-page-layout-box">
  3. <div :style="'width:' + leftWidth + 'px;'" class="hc-layout-left-box">
  4. <div class="hc-project-box">
  5. <div class="hc-project-icon-box">
  6. <HcIcon name="stack"/>
  7. </div>
  8. <div class="ml-2 project-name-box">
  9. <span class="text-xl text-cut project-alias">{{ projectInfo['projectAlias'] }}</span>
  10. <div class="text-xs text-cut project-name">{{ projectInfo['name'] }}</div>
  11. </div>
  12. </div>
  13. <div class="hc-tree-box">
  14. <el-scrollbar>
  15. <!-- <WbsTree :autoExpandKeys="treeAutoExpandKeys" :projectId="projectId" :contractId="contractId" isColor @nodeTap="wbsElTreeClick"/> -->
  16. <TestTree
  17. :autoExpandKeys="treeAutoExpandKeys"
  18. :projectId="projectId"
  19. :tenantId="userInfo?.tenant_id"
  20. :wbsTempId="projectInfo?.referenceWbsTemplateIdTrial"
  21. :wbsType="2"
  22. @nodeTap="wbsElTreeClick"/>
  23. </el-scrollbar>
  24. </div>
  25. <!--左右拖动-->
  26. <div class="horizontal-drag-line" @mousedown="onmousedown"/>
  27. </div>
  28. <div class="hc-page-content-box">
  29. <HcCard :scrollbar="false" actionSize="lg">
  30. <template #header>
  31. <HcTooltip keys="tentative_laboratory_print_print">
  32. <el-button :loading="printLoading" hc-btn @click="batchPrint()">
  33. <HcIcon name="printer"/>
  34. <span>打印</span>
  35. </el-button>
  36. </HcTooltip>
  37. <HcTooltip keys="tentative_laboratory_print_print_all">
  38. <el-button :loading="allprintLoading" hc-btn @click="batchPrintall()">
  39. <HcIcon fill name="printer"/>
  40. <span>全部打印</span>
  41. </el-button>
  42. </HcTooltip>
  43. </template>
  44. <HcTable ref="tableRef" :column="tableColumn" :datas="tableData" :loading="tableLoading" isCheck
  45. @selection-change="tableSelection"/>
  46. <template #action>
  47. <HcPages :pages="searchForm" @change="pageChange"/>
  48. </template>
  49. </HcCard>
  50. </div>
  51. </div>
  52. </template>
  53. <script setup>
  54. import {ref, watch, onMounted} from "vue";
  55. import {useAppStore} from "~src/store";
  56. import WbsTree from "../../data-fill/components/WbsTree.vue"
  57. import TestTree from "../material/components/TestTree.vue"
  58. import {getStoreValue, setStoreValue} from '~src/utils/storage'
  59. import dataApi from "~api/tentative/laboratory/print"
  60. import {getArrValue, isString} from "js-fast-way"
  61. //变量
  62. const useAppState = useAppStore()
  63. const projectId = ref(useAppState.getProjectId);
  64. const contractId = ref(useAppState.getContractId);
  65. const projectInfo = ref(useAppState.getProjectInfo);
  66. const isCollapse = ref(useAppState.getCollapse)
  67. //监听
  68. watch(() => [
  69. useAppState.getCollapse
  70. ], ([Collapse]) => {
  71. isCollapse.value = Collapse
  72. })
  73. //自动展开缓存
  74. const treeAutoExpandKeys = ref(getStoreValue('wbsTreeExpandKeys') || [])
  75. //渲染完成
  76. onMounted(() => {
  77. })
  78. //搜索表单
  79. const searchForm = ref({
  80. contractId: null, type: null, approval: null, betweenTime: null,
  81. current: 1, size: 20, total: 0
  82. })
  83. //树相关的变量
  84. const primaryKeyId = ref('')
  85. const nodeItemInfo = ref({})
  86. const nodeDataInfo = ref({})
  87. const clicID = ref('')
  88. //树被点击
  89. const wbsElTreeClick = ({node, data, keys}) => {
  90. nodeItemInfo.value = node
  91. nodeDataInfo.value = data
  92. primaryKeyId.value = data['primaryKeyId'] || ''
  93. clicID.value = data['id'] || ''
  94. console.log(data, 'dtat');
  95. //缓存自动展开
  96. treeAutoExpandKeys.value = keys
  97. setStoreValue('wbsTreeExpandKeys', keys)
  98. //改变搜索表单数据
  99. searchForm.value.wbsId = projectInfo?.value.referenceWbsTemplateIdTrial
  100. //searchForm.value.contractIdRelation = data['contractIdRelation'] projectInfo?.referenceWbsTemplateIdTrial
  101. searchForm.value.current = 1;
  102. getTableData()
  103. }
  104. //分页被点击
  105. const pageChange = ({current, size}) => {
  106. searchForm.value.current = current
  107. searchForm.value.size = size
  108. getTableData()
  109. }
  110. //表格数据
  111. const tableRef = ref(null)
  112. const tableColumn = ref([
  113. {key: 'tableName', name: '表名'}
  114. ])
  115. //获取数据
  116. const tableLoading = ref(false)
  117. const tableData = ref([])
  118. const getTableData = async () => {
  119. tableLoading.value = true
  120. const {error, code, data} = await dataApi.queryPage({
  121. projectId: projectId.value,
  122. parentId: clicID.value,
  123. // contractId: contractId.value,
  124. ...searchForm.value,
  125. })
  126. //处理数据
  127. tableLoading.value = false
  128. if (!error && code === 200) {
  129. tableData.value = getArrValue(data)
  130. searchForm.value.total = data.total || 0
  131. } else {
  132. tableData.value = []
  133. searchForm.value.total = 0
  134. }
  135. }
  136. //多选
  137. const tableCheckedKeys = ref([]);
  138. const tableSelection = (rows) => {
  139. tableCheckedKeys.value = rows.filter((item) => {
  140. return (item ?? '') !== '';
  141. })
  142. }
  143. //拼接ID
  144. const rowsToId = (rows) => {
  145. return rows.map((obj) => {
  146. return obj.pkeyId;
  147. }).join(",")
  148. }
  149. //左右拖动,改变树形结构宽度
  150. const leftWidth = ref(382);
  151. const onmousedown = () => {
  152. const leftNum = isCollapse.value ? 142 : 272
  153. document.onmousemove = (ve) => {
  154. let diffVal = ve.clientX - leftNum;
  155. if (diffVal >= 310 && diffVal <= 900) {
  156. leftWidth.value = diffVal;
  157. }
  158. }
  159. document.onmouseup = () => {
  160. document.onmousemove = null;
  161. document.onmouseup = null;
  162. }
  163. }
  164. //打印
  165. const printLoading = ref(false)
  166. const allprintLoading = ref(false)
  167. const batchPrint = async () => {
  168. const rows = tableCheckedKeys.value;
  169. const ids = rowsToId(rows)
  170. //批量下载
  171. printLoading.value = true
  172. const {error, code, data} = await dataApi.batchPrint({pKeyIds: ids})
  173. //处理数据
  174. printLoading.value = false
  175. const res = isString(data) ? data ?? '' : ''
  176. if (!error && code === 200 && res) {
  177. window.open(res, '_blank')
  178. }
  179. }
  180. const batchPrintall = async () => {
  181. const rows = tableData.value;
  182. const ids = rowsToId(rows)
  183. //批量下载
  184. allprintLoading.value = true
  185. const {error, code, data} = await dataApi.batchPrint({pKeyIds: ids})
  186. //处理数据
  187. allprintLoading.value = false
  188. const res = isString(data) ? data ?? '' : ''
  189. if (!error && code === 200 && res) {
  190. window.open(res, '_blank')
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. </style>