test-file-cy.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div class="radio-box">
  3. <el-radio-group v-model="fileModalradio" @change="radioChange">
  4. <el-radio value="test">试验检测</el-radio>
  5. <el-radio :value="1">第三方检测</el-radio>
  6. <el-radio :value="0">外委检测</el-radio>
  7. </el-radio-group>
  8. </div>
  9. <div class="adding-form-dialog-box">
  10. <div class="dialog-tree-box">
  11. <el-scrollbar>
  12. <!-- 试验检测树 -->
  13. <HcLazyTree
  14. ref="ElTreeRefCy"
  15. :auto-expand-keys="treeAutoExpandKeys"
  16. tree-key="id"
  17. :h-props="treeProps"
  18. @load="treeLoadNode"
  19. @node-tap="fileModalElTreeClick"
  20. />
  21. </el-scrollbar>
  22. </div>
  23. <div class="dialog-table-box">
  24. <div class="dialog-search">
  25. <div class="ml-2 w-64">
  26. <HcDatePicker :dates="filebetweenTime" clearable @change="filebetweenTimeUpdate" />
  27. </div>
  28. <div class="ml-2">
  29. <el-button type="primary" @click="filesearchClick">
  30. <HcIcon name="search-2" />
  31. <span>搜索</span>
  32. </el-button>
  33. </div>
  34. </div>
  35. <div class="dialog-table">
  36. <HcTable
  37. ref="dialogTableRef1" :column="filedialogTableColumn"
  38. :datas="filedialogTableData" :loading="filedialogTableLoading"
  39. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  40. @selection-change="filedialogTableSelection1"
  41. >
  42. <template #reportNo="{ row }">
  43. <span :class="[row?.isSelectedStatus == 1 ? 'text-green' : '']">{{ row?.reportNo }}</span>
  44. </template>
  45. </HcTable>
  46. </div>
  47. <div class="dialog-pages">
  48. <HcPages :pages="filesearchFormPage" @change="filesearchFormPageChange" />
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <script setup>
  54. import { nextTick, ref, watch } from 'vue'
  55. import { getArrValue } from 'js-fast-way'
  56. import thirdApi from '~api/tentative/detect/third'
  57. import samplingApi from '~api/tentative/material/sampling'
  58. const props = defineProps({
  59. projectId: [String, Number],
  60. contractId: [String, Number],
  61. wbsId: [String, Number],
  62. tenantId: [String, Number],
  63. wbsType: [String, Number],
  64. treeId: [String, Number],
  65. })
  66. const projectId = ref(props.projectId)
  67. const contractId = ref(props.contractId)
  68. const wbsTempId = ref(props.wbsId)
  69. const tenant_id = ref(props.tenantId)
  70. const wbs_type = ref(props.wbsType)
  71. const isPrimaryKeyId = ref(props.treeId)
  72. const treeProps = {
  73. label: 'name',
  74. children: 'children',
  75. isLeaf: function (data) {
  76. return !data.hasChildren
  77. },
  78. }
  79. const treeAutoExpandKeys = ref([])
  80. const ElTreeRefCy = ref(null)
  81. //监听
  82. watch(() => [
  83. props.projectId,
  84. props.contractId,
  85. props.wbsId,
  86. props.tenantId,
  87. props.wbsType,
  88. props.treeId,
  89. ], ([pid, cid, wbs_id, tid, type, treeId]) => {
  90. projectId.value = pid
  91. contractId.value = cid
  92. wbsTempId.value = wbs_id
  93. tenant_id.value = tid
  94. wbs_type.value = type
  95. isPrimaryKeyId.value = treeId
  96. })
  97. const treeLoadNode = async ({ node, item, level }, resolve) => {
  98. let parentId = '0'
  99. if (level !== 0) {
  100. parentId = item?.id
  101. }
  102. //获取数据
  103. const { data } = await thirdApi.getTreeCy({
  104. contractId: contractId.value,
  105. projectId: projectId.value,
  106. parentId,
  107. })
  108. resolve(getArrValue(data))
  109. }
  110. //关联试验文件
  111. const filedialogTableData = ref([])
  112. const fileModalradio = ref('test')
  113. const radioChange = (val) => {
  114. getfileNodeData()
  115. }
  116. //节点被点击
  117. //节点被点击
  118. const filenodeItemInfo = ref({})
  119. const filenodeDataInfo = ref({})
  120. const fileModalElTreeClick = async ({ data, node }) => {
  121. filenodeItemInfo.value = node
  122. filenodeDataInfo.value = data
  123. getfileNodeData()
  124. }
  125. const filebetweenTime = ref([])
  126. const filesearchFormPage = ref({
  127. startTime: null, lastTime: null, wbsId: null, current: 1, size: 20, total: 0,
  128. })
  129. const filesearchFormPageChange = ({ current, size }) => {
  130. filesearchFormPage.value.current = current
  131. filesearchFormPage.value.size = size
  132. // getDialogTableData()
  133. getfileNodeData()
  134. }
  135. const filebetweenTimeUpdate = ({ arr }) => {
  136. filebetweenTime.value = arr
  137. filesearchFormPage.value.startTime = arr[0]
  138. filesearchFormPage.value.lastTime = arr[1]
  139. }
  140. const filesearchClick = () => {
  141. filesearchFormPage.value.current = 1
  142. getfileNodeData()
  143. }
  144. const filedialogTableLoading = ref(false)
  145. const filedialogTableColumn = ref([
  146. // reportNo
  147. { key: 'reportNo', name: '报告编号' },
  148. { key: 'reportDate', name: '报告日期' },
  149. { key: 'projectPositionName', name: '工程用途及部位' },
  150. { key: 'detectionResultName', name: '检测结果' },
  151. ])
  152. //多选
  153. const filetableCheckedKeys = ref([])
  154. const filedialogTableSelection1 = (rows) => {
  155. filetableCheckedKeys.value = rows.filter((item) => {
  156. return (item ?? '') !== ''
  157. })
  158. }
  159. //试验文件节点下的数据
  160. const getfileNodeData = async () => {
  161. if (!filenodeDataInfo.value?.pkeyId) {
  162. window.$message.warning('请先选择节点')
  163. return
  164. }
  165. // 获取数据
  166. filedialogTableLoading.value = true
  167. let apiResponse
  168. if (fileModalradio.value === 'test') {
  169. // 调用试验检测报告接口
  170. apiResponse = await thirdApi.getTrialDetectionReport({
  171. contractId: contractId.value,
  172. nodeId: filenodeDataInfo.value.pkeyId,
  173. current: filesearchFormPage.value.current,
  174. size: filesearchFormPage.value.size,
  175. startTime: filesearchFormPage.value.startTime,
  176. endTime: filesearchFormPage.value.lastTime,
  177. })
  178. } else {
  179. // 调用第三方报告接口
  180. apiResponse = await thirdApi.getThirdReport({
  181. contractId: contractId.value,
  182. nodeId: filenodeDataInfo.value.pkeyId,
  183. current: filesearchFormPage.value.current,
  184. size: filesearchFormPage.value.size,
  185. startTime: filesearchFormPage.value.startTime,
  186. endTime: filesearchFormPage.value.lastTime,
  187. type: fileModalradio.value,
  188. })
  189. }
  190. const { error, code, data } = apiResponse
  191. // 处理数据
  192. if (!error && code === 200) {
  193. filedialogTableData.value = getArrValue(data['records'])
  194. filesearchFormPage.value.total = data.total || 0
  195. filedialogTableLoading.value = false
  196. let defaultarr = []
  197. filedialogTableData.value.forEach((item) => {
  198. if (item.isSelectedStatus === 1) {
  199. defaultarr.push(item)
  200. }
  201. tabtoggleSelection(defaultarr)
  202. })
  203. } else {
  204. filedialogTableData.value = []
  205. filesearchFormPage.value.total = 0
  206. filedialogTableLoading.value = false // 修正了这里的赋值错误
  207. }
  208. }
  209. const dialogTableRef1 = ref(null)
  210. const tabtoggleSelection = (rows) => {
  211. if (rows) {
  212. rows.forEach(row => {
  213. nextTick(() => {
  214. dialogTableRef1.value?.toggleRowSelection(row, true)
  215. })
  216. })
  217. } else {
  218. dialogTableRef1.value?.clearSelection()
  219. }
  220. }
  221. //确认关联试验文件
  222. const savefileSubmit = async () => {
  223. const idarr = []
  224. filetableCheckedKeys.value.forEach((item) => {
  225. idarr.push(item.id)
  226. })
  227. const idval = idarr.join(',')
  228. await savesubmitRelationFile(idval)
  229. }
  230. //关联试验文件
  231. const savesubmitRelationFile = async (ids) => {
  232. const { error, code, data, msg } = await samplingApi.submitRelationFile({
  233. projectId: projectId.value,
  234. contractId: contractId.value,
  235. nodeId: filenodeDataInfo.value?.pkeyId,
  236. type: fileModalradio.value === 'test' ? 11 : fileModalradio.value === 1 ? 12 : 13,
  237. ids,
  238. qualityTestPKeyld:isPrimaryKeyId.value,
  239. })
  240. if (!error && code === 200) {
  241. window?.$message?.success('操作成功')
  242. } else {
  243. window?.$message?.error(msg || '操作失败')
  244. }
  245. }
  246. // 暴露出去
  247. defineExpose({
  248. savefileSubmit,
  249. })
  250. </script>
  251. <style lang="scss">
  252. </style>