test-data.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div>
  3. <div class="flex-1" style="padding-left:20px">
  4. <HcNewSwitch :datas="tabTypeTab" :keys="tabTypeKey" :round="false" size="default" @change="tabTypeChange" />
  5. <el-select
  6. v-model="testReportId" :loading="insertDataSelectoading" :placeholder="placeholderType"
  7. class="ml-2 w-80" clearable @change="testReportIdchange"
  8. >
  9. <el-option v-for="item in testReportData" :key="item.pKeyId" :label="item.nodeName" :value="item.pKeyId" />
  10. </el-select>
  11. </div>
  12. <div class="dialog-table-box">
  13. <div class="copy-node-many-table">
  14. <el-scrollbar v-loading="insertDataTableLoading">
  15. <el-table :data="insertDataTable" border @selection-change="insertDataTableCheck">
  16. <el-table-column type="selection" width="55" />
  17. <el-table-column label="字段名称" prop="key" />
  18. <el-table-column label="数值" prop="value" />
  19. </el-table>
  20. </el-scrollbar>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import { onMounted, ref, watch } from 'vue'
  27. import { getArrValue, getObjValue, setPosInsert } from 'js-fast-way'
  28. import dataApi from '~api/tentative/detect/test'
  29. const props = defineProps({
  30. projectId: [String, Number],
  31. contractId: [String, Number],
  32. tableId: [String, Number],
  33. treeId: [String, Number],
  34. })
  35. //事件
  36. const emit = defineEmits(['change'])
  37. //参数变量
  38. const projectId = ref(props.projectId)
  39. const contractId = ref(props.contractId)
  40. const table_id = ref(props.tableId)
  41. const tree_id = ref(props.treeId)
  42. //监听
  43. watch(() => [
  44. props.projectId,
  45. props.contractId,
  46. props.tableId,
  47. props.treeId,
  48. ], ([pid, cid, tableId, treeId]) => {
  49. projectId.value = pid
  50. contractId.value = cid
  51. table_id.value = tableId
  52. tree_id.value = treeId
  53. })
  54. //渲染完成
  55. onMounted(() => {
  56. getSearchNodeTables()
  57. })
  58. //类型tab数据和相关处理
  59. const tabTypeKey = ref('2')
  60. const tabTypeTab = ref([
  61. { key: '1', name: '试验记录表' },
  62. { key: '2', name: '试验报告单' },
  63. ])
  64. const placeholderType = ref('试验报告单')
  65. const tabTypeChange = ({ key }) => {
  66. tabTypeKey.value = key
  67. if (tabTypeKey.value === '1') {
  68. placeholderType.value = '试验记录表'
  69. } else {
  70. placeholderType.value = '试验报告单'
  71. }
  72. getSearchNodeTables()
  73. }
  74. const insertDataSelectoading = ref(false)
  75. const testReportData = ref([])
  76. const getSearchNodeTables = async () => {
  77. insertDataSelectoading.value = true
  78. const { error, code, data } = await dataApi.searchNodeTables({
  79. id: table_id.value,
  80. projectId: projectId.value,
  81. contractId: contractId.value,
  82. primaryKeyId: tree_id.value,
  83. // type: authBtnTabKey.value,
  84. tableType: tabTypeKey.value,
  85. })
  86. //处理数据
  87. insertDataSelectoading.value = false
  88. if (!error && code === 200) {
  89. testReportData.value = getArrValue(data)
  90. if (testReportData.value.length > 0) {
  91. testReportId.value = testReportData.value[0].pKeyId
  92. getBussddataInfotrialData()
  93. }
  94. } else {
  95. testReportData.value = []
  96. }
  97. }
  98. const testReportId = ref('')
  99. const checPkd = ref('')
  100. const testReportIdchange = (key) => {
  101. testReportData.value.forEach((item) => {
  102. if (item.id == key) {
  103. checPkd.value = item.pKeyId
  104. }
  105. })
  106. getBussddataInfotrialData()
  107. }
  108. const insertDataTableLoading = ref(false)
  109. const insertDataTable = ref([])
  110. const multipleSelection = ref([])
  111. const insertDataTableCheck = (val) => {
  112. multipleSelection.value = val
  113. }
  114. //获取试验表中的data数据接口:
  115. const getBussddataInfotrialData = async () => {
  116. insertDataTableLoading.value = true
  117. const { error, code, data } = await dataApi.getBussddataInfotrialList({
  118. // id:testReportId.value,
  119. id: table_id.value,
  120. pkeyId: testReportId.value,
  121. })
  122. insertDataTableLoading.value = false
  123. if (!error && code === 200) {
  124. let arrobj = getObjValue(data)
  125. let arr = []
  126. for (let key of Object.keys(arrobj)) {
  127. arr.push({
  128. key: key,
  129. value: arrobj[key],
  130. })
  131. }
  132. insertDataTable.value = arr
  133. } else {
  134. insertDataTable.value = []
  135. }
  136. }
  137. //确定关联试验数据数据
  138. const submitinsertData = ({ KeyName, startPos, endPos, pkeyId }, itemForm) => {
  139. if (multipleSelection.value.length > 0) {
  140. const val = []
  141. multipleSelection.value.forEach((item) => {
  142. val.push(item['value'])
  143. })
  144. const newval = val.join('、')
  145. const formValue = setPosInsert(startPos, endPos, itemForm, newval)
  146. let posVal = startPos + newval.length
  147. return { code: 200, val: formValue, posVal }
  148. } else {
  149. window?.$message?.warning('请选择你要关联的数据')
  150. return { code: 300, val: '', posVal: '' }
  151. }
  152. }
  153. // 暴露出去
  154. defineExpose({
  155. submitinsertData,
  156. })
  157. </script>