sampling.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <!-- 关联取样材料 -->
  3. <hc-new-dialog v-model="isShow" is-footer-center is-table title="关联取样材料" widths="80%" @close="linkSamplingClose">
  4. <hc-body v-if="isShow" split>
  5. <template #left>
  6. <hc-new-card scrollbar>
  7. <TestTree
  8. :auto-expand-keys="treeAutoExpandKeys" :project-id="projectId" :tenant-id="userInfo?.tenant_id"
  9. :wbs-temp-id="projectInfo?.referenceWbsTemplateIdTrial" :wbs-type="2" :entrust="1"
  10. @node-tap="wbsElTreeClick"
  11. />
  12. </hc-new-card>
  13. </template>
  14. <hc-new-card>
  15. <template #header>
  16. <div class="w-50">
  17. <el-select v-model="searchForm.contractId" placeholder="选择合同段" filterable block>
  18. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  19. </el-select>
  20. </div>
  21. <div class="ml-2">
  22. <el-button type="primary" @click="searchClick">
  23. <hc-icon name="search-2" />
  24. <span>搜索</span>
  25. </el-button>
  26. </div>
  27. </template>
  28. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }">
  29. <template #action="{ row }">
  30. <el-link v-if="row.id == currentId" type="success" @click="rowCancel(row)">取消选择</el-link>
  31. <el-link v-else type="primary" :disabled="row.entrustId" @click="rowSelect(row)">选择</el-link>
  32. </template>
  33. </hc-table>
  34. <template #action>
  35. <hc-pages :pages="searchForm" @change="pageChange" />
  36. </template>
  37. </hc-new-card>
  38. </hc-body>
  39. <template #footer>
  40. <el-button @click="linkSamplingClose">取消</el-button>
  41. <el-button hc-btn type="primary" @click="linkSamplingClick">确定</el-button>
  42. </template>
  43. </hc-new-dialog>
  44. </template>
  45. <script setup>
  46. import { ref, watch } from 'vue'
  47. import { useAppStore } from '~src/store'
  48. import TestTree from '~src/views/tentative/material/components/TestTree.vue'
  49. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  50. import samplingApi from '~api/tentative/material/sampling'
  51. import { getArrValue } from 'js-fast-way'
  52. //参数
  53. const props = defineProps({
  54. cid: [String, Number],
  55. })
  56. //事件
  57. const emit = defineEmits(['change'])
  58. //变量
  59. const useAppState = useAppStore()
  60. const userInfo = ref(useAppState.getUserInfo)
  61. const projectId = ref(useAppState.getProjectId)
  62. const contractId = ref(useAppState.getContractId)
  63. const projectInfo = ref(useAppState.getProjectInfo)
  64. const isShow = defineModel('modelValue', {
  65. default: false,
  66. })
  67. //深度监听数据
  68. const curId = defineModel('id', {
  69. type: [String, Number],
  70. default: '',
  71. })
  72. //监听
  73. watch(() => curId.value, (id) => {
  74. currentId.value = id
  75. })
  76. //监听
  77. watch(() => isShow.value, (show) => {
  78. if (show) {
  79. tableData.value = []
  80. getContractData()
  81. }
  82. })
  83. //自动展开缓存
  84. const treeAutoExpandKeys = ref(getStoreValue('testTreeExpandKeys') || [])
  85. //搜索表单
  86. const searchForm = ref({ current: 1, size: 20, total: 0 })
  87. //监听
  88. watch(() => props.cid, (cid) => {
  89. searchForm.value.contractId = cid
  90. }, { immediate:true, deep:true })
  91. //获取合同段信息
  92. const contractData = ref([])
  93. const getContractData = async () => {
  94. const { data } = await samplingApi.getErtractInfo({
  95. projectId: projectId.value,
  96. contractId: contractId.value,
  97. })
  98. contractData.value = getArrValue(data)
  99. }
  100. //树被点击
  101. const nodeDataInfo = ref({})
  102. const wbsElTreeClick = ({ data, keys }) => {
  103. nodeDataInfo.value = data
  104. //缓存自动展开
  105. treeAutoExpandKeys.value = keys
  106. setStoreValue('testTreeExpandKeys', keys)
  107. //改变搜索表单数据
  108. searchForm.value.nodeId = data['primaryKeyId'] || ''
  109. searchForm.value.current = 1
  110. getTableData()
  111. }
  112. //搜索
  113. const searchClick = () => {
  114. searchForm.value.current = 1
  115. getTableData()
  116. }
  117. //分页被点击
  118. const pageChange = ({ current, size }) => {
  119. searchForm.value.current = current
  120. searchForm.value.size = size
  121. getTableData()
  122. }
  123. //表格数据
  124. const tableColumn = ref([
  125. { key: 'materialName', name: '取样名称' },
  126. { key: 'samplingDate', name: '取样日期', width: 100, align: 'center' },
  127. { key: 'specificationNumber', name: '样品编号' },
  128. { key: 'specificationModel', name: '规格型号', width: 80, align: 'center' },
  129. { key: 'materialCount', name: '试样数量', width: 80, align: 'center' },
  130. { key: 'calculationUnit', name: '计算单位', width: 80, align: 'center' },
  131. { key: 'proposedPosition', name: '拟用部位', width: 80, align: 'center' },
  132. { key: 'representativeCount', name: '代表数量', width: 80, align: 'center' },
  133. { key: 'userName', name: '取样人', width: 80, align: 'center' },
  134. { key: 'action', name: '操作', width: 80, align: 'center', fixed: 'right' },
  135. ])
  136. //获取数据
  137. const tableLoading = ref(false)
  138. const tableData = ref([])
  139. const getTableData = async () => {
  140. tableLoading.value = true
  141. const { error, code, data } = await samplingApi.queryPage({
  142. projectId: projectId.value,
  143. ...searchForm.value,
  144. })
  145. //处理数据
  146. tableLoading.value = false
  147. if (!error && code === 200) {
  148. tableData.value = getArrValue(data['records'])
  149. searchForm.value.total = data.total || 0
  150. } else {
  151. tableData.value = []
  152. searchForm.value.total = 0
  153. }
  154. }
  155. //选择
  156. const currentId = ref(null)
  157. const rowItem = ref({})
  158. const rowSelect = (row) => {
  159. currentId.value = row.id
  160. rowItem.value = row
  161. }
  162. //取消选择
  163. const rowCancel = () => {
  164. currentId.value = null
  165. }
  166. //确认关联取样材料
  167. const linkSamplingClick = () => {
  168. curId.value = currentId.value
  169. emit('change', rowItem.value)
  170. linkSamplingClose()
  171. }
  172. //取消关联取样材料
  173. const linkSamplingClose = () => {
  174. isShow.value = false
  175. }
  176. </script>