qualityRleation.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!-- -->
  2. <template>
  3. <hc-new-dialog v-model="qualityMoadal" is-table title="关联质检资料" widths="1200px" @close="qulModalClose" @save="saveQualModal">
  4. <hc-new-card>
  5. <div class="relative h-full flex">
  6. <div :id="`hc_tree_card_${uuid}`" v-loading="treeLoading" class="hc_tree_card_border relative">
  7. <hc-body scrollbar padding="0px">
  8. <hc-lazy-tree tree-key="id" @load="treeLoadNode" @node-tap="nodeElTreeClick" />
  9. </hc-body>
  10. </div>
  11. <div :id="`hc_table_card_${uuid}`" class="relative flex-1">
  12. <HcTable ref="qualTable" :column="tableColumn" :datas="tableData" is-new is-check is-reserve-selection :loading="tableLoading" @selection-change="tableSelection">
  13. <template #appStatusName="{ row }">
  14. <el-tag
  15. v-if="row.appStatusName"
  16. :type="`${row.appStatusName === '已审批' ? 'success' : row.appStatusName === '待审批' ? 'warning' : row.appStatusName === '已废除' ? 'danger' : 'info'}`"
  17. class="mx-1" effect="dark"
  18. >
  19. {{ row.appStatusName }}
  20. </el-tag>
  21. </template>
  22. </HcTable>
  23. </div>
  24. </div>
  25. <template #action>
  26. <hc-pages :pages="searchForm" @change="pageChange" />
  27. </template>
  28. </hc-new-card>
  29. </hc-new-dialog>
  30. </template>
  31. <script setup>
  32. import { nextTick, ref, watch } from 'vue'
  33. import { getArrValue, getObjValue, getRandom } from 'js-fast-way'
  34. import { useAppStore } from '~src/store'
  35. import unitApi from '~api/project/debit/contract/unit'
  36. import { queryWbsTreeData } from '~api/other'
  37. const props = defineProps({
  38. qualityMoadal: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. cid:{
  43. type:String,
  44. default:'',
  45. },
  46. periodId:{
  47. type:String,
  48. default:'',
  49. },
  50. selectId:{
  51. type:String,
  52. default:'',
  53. },
  54. })
  55. const emit = defineEmits([ 'close', 'finish'])
  56. const useAppState = useAppStore()
  57. const contractInfo = ref(useAppState.getContractInfo)
  58. const projectId = ref(useAppState.getProjectId || '')
  59. const { contractType } = contractInfo.value
  60. const classifyType = ref(contractType === 2 ? '2' : '1')
  61. const qualityMoadal = ref(props.qualityMoadal)
  62. const cid = ref(props.cid)
  63. const periodId = ref(props.periodId)
  64. const selectId = ref(props.selectId)
  65. watch(() => [
  66. props.qualityMoadal,
  67. props.cid,
  68. props.qualityMoadal,
  69. props.selectId,
  70. ], ([qual, Cid, Pid, sle]) => {
  71. qualityMoadal.value = qual
  72. cid.value = Cid
  73. periodId.value = Pid
  74. selectId.value = sle
  75. })
  76. const uuid = getRandom(4)
  77. //监听
  78. watch(qualityMoadal, (val) => {
  79. if (val) {
  80. nextTick(() => {
  81. setSplitRef()
  82. tableData.value = []
  83. })
  84. }
  85. })
  86. //初始化设置拖动分割线
  87. const setSplitRef = () => {
  88. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  89. try {
  90. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  91. sizes: [20, 80],
  92. snapOffset: 0,
  93. minSize: [50, 500],
  94. })
  95. } catch (error) {
  96. console.log(error)
  97. }
  98. }
  99. //懒加载的数据
  100. const treeLoading = ref(false)
  101. const treeLoadNode = async ({ node, item, level }, resolve) => {
  102. let contractIdRelation = '', parentId = '', primaryKeyId = ''
  103. if (level !== 0) {
  104. const nodeData = getObjValue(item)
  105. contractIdRelation = nodeData?.contractIdRelation || ''
  106. parentId = contractIdRelation ? nodeData?.primaryKeyId : nodeData?.id
  107. primaryKeyId = nodeData?.id || ''
  108. }
  109. treeLoading.value = true
  110. //获取数据
  111. const { data } = await queryWbsTreeData({
  112. contractId: cid.value || '',
  113. contractIdRelation,
  114. primaryKeyId,
  115. parentId,
  116. classifyType: classifyType.value,
  117. tableOwner:classifyType.value,
  118. })
  119. treeLoading.value = false
  120. resolve(getArrValue(data))
  121. }
  122. const tableColumn = [
  123. { key: 'partName', name: '分/子分项部位' },
  124. { key: 'dataName', name: '资料名称' },
  125. { key: 'appStatusName', name: '资料审核状态' },
  126. ]
  127. const qulModalClose = ()=>{
  128. qualityMoadal.value = false
  129. emit('close')
  130. }
  131. //搜索表单
  132. const searchForm = ref({
  133. current: 1, size: 20, total: 0,
  134. })
  135. const pageChange = ({ current, size }) => {
  136. searchForm.value.current = current
  137. searchForm.value.size = size
  138. getTableData()
  139. }
  140. const qualTable = ref(null)
  141. const tableData = ref([])
  142. const tableLoading = ref(false)
  143. const getTableData = async () => {
  144. tableData.value = []
  145. tableLoading.value = true
  146. const { data } = await unitApi.getCurrentNodeAllForm({
  147. ...searchForm.value,
  148. contractId:cid.value,
  149. projectId:projectId.value,
  150. nodeId:curTree.value.pKeyId,
  151. contractIdRelation:curTree.value?.contractIdRelation || '',
  152. classifyType: classifyType.value,
  153. selectIds:selectId.value,
  154. })
  155. tableData.value = getArrValue(data['records'])
  156. searchForm.value.total = data.total || 0
  157. tableLoading.value = false
  158. let defaultarr = []
  159. tableData.value.forEach((item) => {
  160. if (item.isSelect === 1) {
  161. defaultarr.push(item)
  162. }
  163. tabtoggleSelection(defaultarr)
  164. })
  165. }
  166. const tabtoggleSelection = (rows) => {
  167. if (rows) {
  168. rows.forEach(row => {
  169. nextTick(() => {
  170. qualTable.value?.toggleRowSelection(row, true)
  171. })
  172. })
  173. } else {
  174. qualTable.value?.clearSelection()
  175. }
  176. }
  177. const curTree = ref(null)
  178. const nodeElTreeClick = ({ node, data, keys })=>{
  179. curTree.value = data
  180. getTableData()
  181. }
  182. //多选
  183. const tableKeys = ref([])
  184. const tableSelection = (rows) => {
  185. tableKeys.value = rows
  186. }
  187. const saveQualModal = ()=>{
  188. if ( tableKeys.value.length > 0) {
  189. qualityMoadal.value = false
  190. emit('close')
  191. emit('finish', tableKeys.value)
  192. } else {
  193. window.$message.warning('请先选择你要关联的质检资料')
  194. emit('close')
  195. emit('finish', tableKeys.value)
  196. }
  197. }
  198. </script>
  199. <style lang='scss' scoped>
  200. </style>