qualityRleation.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <!-- -->
  2. <template>
  3. <hc-new-dialog v-model="qualityMoadal" is-table title="关联质检资料" widths="1200px" :loading="saveModalLoading" @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
  13. ref="qualTable" :column="tableColumn" :datas="tableData" is-new is-check is-reserve-selection :loading="tableLoading" row-key="selectId"
  14. @select="tableSelect"
  15. @selection-change="tableSelection"
  16. @select-all="tableSelectAll"
  17. >
  18. <template #appStatusName="{ row }">
  19. <el-tag
  20. v-if="row.appStatusName"
  21. :type="`${row.appStatusName === '已审批' ? 'success' : row.appStatusName === '待审批' ? 'warning' : row.appStatusName === '已废除' ? 'danger' : 'info'}`"
  22. class="mx-1" effect="dark"
  23. >
  24. {{ row.appStatusName }}
  25. </el-tag>
  26. </template>
  27. </HcTable>
  28. </div>
  29. </div>
  30. <template #action>
  31. <hc-pages :pages="searchForm" @change="pageChange" />
  32. </template>
  33. </hc-new-card>
  34. </hc-new-dialog>
  35. </template>
  36. <script setup>
  37. import { nextTick, ref, watch } from 'vue'
  38. import { arrUnion, getArrValue, getObjValue, getRandom, isArrIndex } from 'js-fast-way'
  39. import { useAppStore } from '~src/store'
  40. import unitApi from '~api/project/debit/contract/unit'
  41. import { queryWbsTreeData } from '~api/other'
  42. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  43. const props = defineProps({
  44. qualityMoadal: {
  45. type: Boolean,
  46. default: false,
  47. },
  48. cid:{
  49. type:String,
  50. default:'',
  51. },
  52. periodId:{
  53. type:String,
  54. default:'',
  55. },
  56. selectId:{
  57. type:String,
  58. default:'',
  59. },
  60. isRemianOldCheck:{
  61. type: Boolean,
  62. default: true,
  63. },
  64. saveModalLoading:{
  65. type: Boolean,
  66. default: false,
  67. },
  68. disabled:{
  69. type: Boolean,
  70. default: false,
  71. },
  72. })
  73. const emit = defineEmits([ 'close', 'finish'])
  74. const useAppState = useAppStore()
  75. const contractInfo = ref(useAppState.getContractInfo)
  76. const projectId = ref(useAppState.getProjectId || '')
  77. const { contractType } = contractInfo.value
  78. const classifyType = ref(contractType === 2 ? '2' : '1')
  79. const qualityMoadal = ref(props.qualityMoadal)
  80. const cid = ref(props.cid)
  81. const periodId = ref(props.periodId)
  82. const selectId = ref(props.selectId)
  83. const isRemianOldCheck = ref(props.isRemianOldCheck)
  84. const saveModalLoading = ref(props.saveModalLoading)
  85. const disabled = ref(props.disabled)
  86. //之前节点选中的数据
  87. const oriCheckRows = ref([])
  88. watch(() => [
  89. props.qualityMoadal,
  90. props.cid,
  91. props.qualityMoadal,
  92. props.selectId,
  93. props.isRemianOldCheck,
  94. props.saveModalLoading,
  95. props.disabled,
  96. ], ([qual, Cid, Pid, sle, isRemain, load, dis]) => {
  97. qualityMoadal.value = qual
  98. cid.value = Cid
  99. periodId.value = Pid
  100. selectId.value = sle
  101. isRemianOldCheck.value = isRemain
  102. saveModalLoading.value = load
  103. disabled.value = dis
  104. })
  105. const uuid = getRandom(4)
  106. //监听
  107. watch(qualityMoadal, (val) => {
  108. if (val) {
  109. nextTick(() => {
  110. setSplitRef()
  111. tableData.value = []
  112. oriCheckRows.value = getStoreValue('checkRows') || []
  113. if (!isRemianOldCheck.value) {
  114. oriCheckRows.value = []
  115. }
  116. })
  117. }
  118. })
  119. //初始化设置拖动分割线
  120. const setSplitRef = () => {
  121. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  122. try {
  123. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  124. sizes: [20, 80],
  125. snapOffset: 0,
  126. minSize: [50, 500],
  127. })
  128. } catch (error) {
  129. console.log(error)
  130. }
  131. }
  132. //懒加载的数据
  133. const treeLoading = ref(false)
  134. const treeLoadNode = async ({ node, item, level }, resolve) => {
  135. let contractIdRelation = '', parentId = '', primaryKeyId = ''
  136. if (level !== 0) {
  137. const nodeData = getObjValue(item)
  138. contractIdRelation = nodeData?.contractIdRelation || ''
  139. parentId = contractIdRelation ? nodeData?.primaryKeyId : nodeData?.id
  140. primaryKeyId = nodeData?.id || ''
  141. }
  142. treeLoading.value = true
  143. //获取数据
  144. const { data } = await queryWbsTreeData({
  145. contractId: cid.value || '',
  146. contractIdRelation,
  147. primaryKeyId,
  148. parentId,
  149. classifyType: classifyType.value,
  150. tableOwner:classifyType.value,
  151. })
  152. treeLoading.value = false
  153. resolve(getArrValue(data))
  154. }
  155. const tableColumn = [
  156. { key: 'partName', name: '分/子分项部位' },
  157. { key: 'dataName', name: '资料名称' },
  158. { key: 'appStatusName', name: '资料审核状态' },
  159. ]
  160. const qulModalClose = ()=>{
  161. qualityMoadal.value = false
  162. setStoreValue('checkRows', [])
  163. cancelcheck.value = []
  164. emit('close')
  165. }
  166. //搜索表单
  167. const searchForm = ref({
  168. current: 1, size: 20, total: 0,
  169. })
  170. const pageChange = ({ current, size }) => {
  171. searchForm.value.current = current
  172. searchForm.value.size = size
  173. getTableData()
  174. }
  175. const qualTable = ref(null)
  176. const tableData = ref([])
  177. const tableLoading = ref(false)
  178. const getTableData = async () => {
  179. tableData.value = []
  180. tableLoading.value = true
  181. const { data } = await unitApi.getCurrentNodeAllForm({
  182. ...searchForm.value,
  183. contractId:cid.value,
  184. projectId:projectId.value,
  185. nodeId:curTree.value.pKeyId,
  186. contractIdRelation:curTree.value?.contractIdRelation || '',
  187. classifyType: classifyType.value,
  188. selectIds:selectId.value,
  189. })
  190. tableData.value = getArrValue(data['records'])
  191. searchForm.value.total = data.total || 0
  192. tableLoading.value = false
  193. let defaultarr = []
  194. tableData.value.forEach((item) => {
  195. if (item.isSelect === 1) {
  196. defaultarr.push(item)
  197. }
  198. tabtoggleSelection(defaultarr)
  199. })
  200. }
  201. const tabtoggleSelection = (rows) => {
  202. if (rows) {
  203. rows.forEach(row => {
  204. nextTick(() => {
  205. qualTable.value?.toggleRowSelection(row, true)
  206. })
  207. })
  208. } else {
  209. qualTable.value?.clearSelection()
  210. }
  211. }
  212. const curTree = ref(null)
  213. const nodeElTreeClick = ({ data })=>{
  214. curTree.value = data
  215. searchForm.value.current = 1
  216. getTableData()
  217. }
  218. //多选
  219. const tableKeys = ref([])
  220. const tableSelection = (rows) => {
  221. tableKeys.value = rows.filter(obj => obj.appStatusName === '已审批')
  222. }
  223. const cancelcheck = ref([])
  224. const tableSelect = (rows)=>{
  225. const { selection, row } = rows
  226. const { appStatusName } = row
  227. if (appStatusName !== '已审批') {
  228. window.$message.warning('只能勾选已审批的数据')
  229. qualTable.value?.toggleRowSelection(row, false)
  230. }
  231. const isDel = isArrIndex( selection, 'selectId', row.selectId)
  232. if (!isDel) {
  233. cancelcheck.value.push( row.selectId)
  234. }
  235. }
  236. const tableSelectAll = (rows)=>{
  237. console.log(rows, 'rows')
  238. let arr = rows.filter(obj => obj.appStatusName !== '已审批')
  239. console.log(arr, 'arr')
  240. if (arr.length > 0) {
  241. window.$message.warning('只能勾选已审批的数据')
  242. qualTable.value?.clearSelection()
  243. return
  244. }
  245. }
  246. //之前选中的
  247. const saveQualModal = ()=>{
  248. if (disabled.value) {
  249. window.$message.warning('自动计量的数据,不允许重新编辑修改关联质检资料')
  250. return
  251. }
  252. qualityMoadal.value = false
  253. emit('close')
  254. let alarr = arrUnion(tableKeys.value, oriCheckRows.value)
  255. // 使用reduce方法进行去重
  256. const uniqueArray = alarr.reduce((acc, current) => {
  257. // 检查当前对象的某个字段是否已存在于累积数组中
  258. const x = acc.find(item => item.selectId === current.selectId)
  259. // 如果不存在,则将其添加到累积数组中
  260. if (!x) {
  261. return acc.concat([current])
  262. } else {
  263. return acc
  264. }
  265. }, [])
  266. alarr = uniqueArray
  267. emit('finish', alarr, cancelcheck.value)
  268. setStoreValue('checkRows', alarr)
  269. }
  270. </script>
  271. <style lang='scss' scoped>
  272. </style>