print.vue 6.7 KB

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