flow.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <hc-card-item class="hc-test-sample-card-item">
  3. <template #header>
  4. <div class="w-200px">
  5. <el-select v-model="searchForm.contractId" placeholder="选择合同段" filterable block>
  6. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  7. </el-select>
  8. </div>
  9. <div class="ml-2 w-250px">
  10. <hc-date-picker :dates="betweenTime" clearable @change="betweenTimeUpdate" />
  11. </div>
  12. <div class="ml-2 w-250px">
  13. <hc-search-input v-model="searchForm.materialName" @search="searchClick" />
  14. </div>
  15. </template>
  16. <template #extra>
  17. <el-button type="primary" :disabled="tableCheckedKeys.length <= 0" @click="manualStorageClick">手动入库</el-button>
  18. </template>
  19. <hc-table
  20. :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }"
  21. is-check :check-style="{ width: 29 }" @selection-change="tableSelection"
  22. />
  23. <template #action>
  24. <hc-pages :pages="searchForm" @change="pageChange" />
  25. </template>
  26. </hc-card-item>
  27. </template>
  28. <script setup>
  29. import { onMounted, ref, watch } from 'vue'
  30. import { useAppStore } from '~src/store'
  31. import { getErtractInfo } from '~api/other'
  32. import { arrToId, getArrValue, getObjValue, isNullES } from 'js-fast-way'
  33. import mainApi from '~api/tentative/material/testSample'
  34. //参数
  35. const props = defineProps({
  36. tree: {
  37. type: Object,
  38. default: () => ({}),
  39. },
  40. })
  41. //变量
  42. const store = useAppStore()
  43. const projectId = ref(store.getProjectId)
  44. const contractId = ref(store.getContractId)
  45. //渲染完成
  46. onMounted(() => {
  47. getContractData()
  48. })
  49. //监听数据
  50. const treeInfo = ref(props.tree)
  51. watch(() => props.tree, (obj) => {
  52. treeInfo.value = getObjValue(obj)
  53. searchClick()
  54. })
  55. //搜索表单
  56. const searchForm = ref({
  57. status: 1, startTime: null, endTime: null, materialName: null,
  58. current: 1, size: 20, total: 0,
  59. })
  60. //获取合同段信息
  61. const contractData = ref([])
  62. const getContractData = async () => {
  63. const { data } = await getErtractInfo({
  64. projectId: projectId.value,
  65. contractId: contractId.value,
  66. })
  67. const res = getArrValue(data)
  68. contractData.value = res
  69. if (res.length <= 0) return
  70. let cid
  71. for (let i = 0; i < res.length; i++) {
  72. if (contractId.value == res[i].id) {
  73. cid = res[i].id
  74. }
  75. }
  76. searchForm.value.contractId = isNullES(cid) ? res[0].id : cid
  77. searchClick()
  78. }
  79. //日期时间被选择
  80. const betweenTime = ref(null)
  81. const betweenTimeUpdate = ({ arr }) => {
  82. betweenTime.value = arr
  83. if (arr.length > 0) {
  84. searchForm.value.startTime = arr[0]
  85. searchForm.value.endTime = arr[1]
  86. } else {
  87. searchForm.value.startTime = null
  88. searchForm.value.endTime = null
  89. }
  90. }
  91. //搜索
  92. const searchClick = () => {
  93. searchForm.value.current = 1
  94. getTableData()
  95. }
  96. //分页被点击
  97. const pageChange = ({ current, size }) => {
  98. searchForm.value.current = current
  99. searchForm.value.size = size
  100. getTableData()
  101. }
  102. //表格数据
  103. const tableColumn = ref([
  104. { key: 'materialName', name: '样品名称' },
  105. { key: 'specificationModel', name: '规格型号', align: 'center' },
  106. { key: 'materialCount', name: '试样数量', align: 'center' },
  107. { key: 'calculationUnit', name: '试样单位', align: 'center' },
  108. { key: 'proposedPosition', name: '拟用部位' },
  109. { key: 'representativeCount', name: '代表数量', align: 'center' },
  110. { key: 'representativeUnit', name: '代表单位' },
  111. { key: 'userName', name: '取样人', align: 'center' },
  112. { key: 'entrustTime', name: '委托单上报时间', align: 'center' },
  113. ])
  114. const tableData = ref([])
  115. //获取表格数据
  116. const tableLoading = ref(false)
  117. const getTableData = async () => {
  118. const { primaryKeyId } = treeInfo.value
  119. if (isNullES(primaryKeyId)) return
  120. tableLoading.value = true
  121. const { error, code, data } = await mainApi.queryPage({
  122. ...searchForm.value,
  123. projectId: projectId.value,
  124. nodeId: primaryKeyId || '',
  125. })
  126. //处理数据
  127. tableLoading.value = false
  128. if (!error && code === 200) {
  129. tableData.value = getArrValue(data?.records)
  130. searchForm.value.total = data.total || 0
  131. } else {
  132. tableData.value = []
  133. searchForm.value.total = 0
  134. }
  135. }
  136. //多选
  137. const tableCheckedKeys = ref([])
  138. const tableSelection = (rows) => {
  139. tableCheckedKeys.value = rows
  140. }
  141. //手动入库
  142. const manualStorageClick = async () => {
  143. const rows = tableCheckedKeys.value
  144. //判断是否满足条件
  145. const result = rows.every(({ rfId }) => {
  146. return !isNullES(rfId)
  147. })
  148. if (!result) {
  149. window.$message?.warning('存在材料未使用RFID,无法手动入库')
  150. return
  151. }
  152. const ids = arrToId(rows)
  153. console.log(ids)
  154. }
  155. </script>