tested.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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-search-input v-model="searchForm.materialName" @search="searchClick" />
  11. </div>
  12. </template>
  13. <template #extra>
  14. <el-button type="danger" :disabled="tableCheckedKeys.length <= 0" @click="batchCancel">取消待测</el-button>
  15. </template>
  16. <hc-table
  17. :column="tableColumn" :datas="tableData" :loading="tableLoading" is-check
  18. :index-style="{ width: 60 }" :check-style="{ width: 29 }" @selection-change="tableSelection"
  19. >
  20. <template #action="{ row }">
  21. <el-link type="primary" @click="rowReports(row)">创建报告</el-link>
  22. <el-link type="danger" @click="rowCancel(row)">取消待测</el-link>
  23. </template>
  24. </hc-table>
  25. <template #action>
  26. <hc-pages :pages="searchForm" @change="pageChange" />
  27. </template>
  28. <!-- 创建报告 -->
  29. <hc-new-dialog v-model="rowActionModal" is-footer-center title="创建报告" widths="40rem" @close="rowActionModalClose">
  30. <el-form ref="formRef" :model="formModel" :rules="formRules" label-position="top" label-width="auto">
  31. <el-row :gutter="20">
  32. <el-col :span="12">
  33. <el-form-item label="委托单位:">
  34. <el-input v-model="formModel.entrustInfo" placeholder="委托单位" disabled />
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="12">
  38. <el-form-item label="委托单位名称:">
  39. <el-input v-model="formModel.entrustName" placeholder="委托单位名称" disabled />
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="12">
  43. <el-form-item label="取样名称:">
  44. <el-input v-model="formModel.materialName" placeholder="取样名称" disabled />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="12">
  48. <el-form-item label="取样数量:">
  49. <el-input v-model="formModel.materialCount" placeholder="取样数量" disabled />
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="12">
  53. <el-form-item label="样品编号:">
  54. <el-input v-model="formModel.entrustNo" placeholder="样品编号" disabled />
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="12">
  58. <el-form-item label="试验数量:" prop="expCount">
  59. <el-input v-model="formModel.expCount" placeholder="试验数量" />
  60. </el-form-item>
  61. </el-col>
  62. <el-col :span="12">
  63. <el-form-item label="规格型号:">
  64. <el-input v-model="formModel.specificationModel" placeholder="规格型号" disabled />
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="12">
  68. <el-form-item label="计算单位:">
  69. <el-input v-model="formModel.calculationUnit" placeholder="计算单位" disabled />
  70. </el-form-item>
  71. </el-col>
  72. </el-row>
  73. </el-form>
  74. <template #footer>
  75. <el-button @click="rowActionModalClose">取消</el-button>
  76. <el-button hc-btn type="primary" :loading="saveLoading" @click="rowActionSave">创建</el-button>
  77. </template>
  78. </hc-new-dialog>
  79. </hc-card-item>
  80. </template>
  81. <script setup>
  82. import { onMounted, ref, watch } from 'vue'
  83. import { useAppStore } from '~src/store'
  84. import router from '~src/router/index'
  85. import { getErtractInfo } from '~api/other'
  86. import { HcDelMsg } from 'hc-vue3-ui'
  87. import { arrToId, formValidate, getArrValue, getObjValue, isNullES } from 'js-fast-way'
  88. import mainApi from '~api/tentative/material/testSample'
  89. import { setStoreValue } from '~uti/storage'
  90. //参数
  91. const props = defineProps({
  92. tree: {
  93. type: Object,
  94. default: () => ({}),
  95. },
  96. })
  97. //变量
  98. const store = useAppStore()
  99. const projectId = ref(store.getProjectId)
  100. const contractId = ref(store.getContractId)
  101. const contractInfo = ref(store.getContractInfo)
  102. //渲染完成
  103. onMounted(() => {
  104. getContractData()
  105. })
  106. //监听数据
  107. const treeInfo = ref(props.tree)
  108. watch(() => props.tree, (obj) => {
  109. treeInfo.value = getObjValue(obj)
  110. searchClick()
  111. })
  112. //搜索表单
  113. const searchForm = ref({ status: 3, materialName: null, current: 1, size: 20, total: 0 })
  114. //获取合同段信息
  115. const contractData = ref([])
  116. const getContractData = async () => {
  117. const { data } = await getErtractInfo({
  118. projectId: projectId.value,
  119. contractId: contractId.value,
  120. })
  121. const res = getArrValue(data)
  122. contractData.value = res
  123. if (res.length > 0) {
  124. searchForm.value.contractId = res[0].id
  125. searchClick()
  126. }
  127. }
  128. //搜索
  129. const searchClick = () => {
  130. searchForm.value.current = 1
  131. getTableData()
  132. }
  133. //分页被点击
  134. const pageChange = ({ current, size }) => {
  135. searchForm.value.current = current
  136. searchForm.value.size = size
  137. getTableData()
  138. }
  139. //表格数据
  140. const tableColumn = ref([
  141. { key: 'materialName', name: '样品名称' },
  142. { key: 'specificationModel', name: '规格型号', align: 'center' },
  143. { key: 'materialCount', name: '试样数量', align: 'center' },
  144. { key: 'calculationUnit', name: '计算单位', align: 'center' },
  145. { key: 'proposedPosition', name: '拟用部位' },
  146. { key: 'representativeCount', name: '代表数量', align: 'center' },
  147. { key: 'userName', name: '取样人', align: 'center' },
  148. { key: 'no-key', name: '待测时间', align: 'center' },
  149. { key: 'action', name: '操作', width: 150, align: 'center' },
  150. ])
  151. const tableData = ref([])
  152. //获取表格数据
  153. const tableLoading = ref(false)
  154. const getTableData = async () => {
  155. const { primaryKeyId } = treeInfo.value
  156. if (isNullES(primaryKeyId)) return
  157. tableLoading.value = true
  158. const { error, code, data } = await mainApi.queryPage({
  159. ...searchForm.value,
  160. projectId: projectId.value,
  161. contractId: contractId.value,
  162. nodeId: primaryKeyId || '',
  163. })
  164. //处理数据
  165. tableLoading.value = false
  166. if (!error && code === 200) {
  167. tableData.value = getArrValue(data?.records)
  168. searchForm.value.total = data.total || 0
  169. } else {
  170. tableData.value = []
  171. searchForm.value.total = 0
  172. }
  173. }
  174. //多选
  175. const tableCheckedKeys = ref([])
  176. const tableSelection = (rows) => {
  177. tableCheckedKeys.value = rows
  178. }
  179. //表单数据
  180. const formRef = ref(null)
  181. const formModel = ref({})
  182. const formRules = {
  183. expCount: {
  184. required: true,
  185. trigger: 'blur',
  186. message: '请填写试验数量',
  187. },
  188. }
  189. //弹窗
  190. const rowActionModal = ref(false)
  191. //创建报告
  192. const rowReports = (row) => {
  193. formModel.value = row
  194. rowActionModal.value = true
  195. }
  196. //提交保存
  197. const saveLoading = ref(false)
  198. const rowActionSave = async () => {
  199. const isForm = await formValidate(formRef.value)
  200. if (!isForm) return
  201. saveLoading.value = true
  202. const { id, expCount } = formModel.value
  203. let form = { id, expCount, sampleStatus: 4 }
  204. const { error, code, msg } = await mainApi.update(form)
  205. saveLoading.value = false
  206. if (!error && code === 200) {
  207. window.$message.success('创建成功')
  208. rowActionModalClose()
  209. getTableData().then()
  210. //跳转到试验填报的新增
  211. setStoreValue('testTreeItem', treeInfo.value)
  212. setStoreValue('prenodeDataInfo', treeInfo.value)
  213. const { contractType } = contractInfo.value
  214. const { primaryKeyId } = treeInfo.value
  215. router.push({
  216. path: '/tentative/detect/test-form',
  217. query: {
  218. nodeId: primaryKeyId || '',
  219. dataType: contractType > 0 ? contractType + '' : '1',
  220. commissionId: id,
  221. isaddType: true,
  222. },
  223. }).then()
  224. } else {
  225. window.$message.error(msg || '创建失败')
  226. }
  227. }
  228. //关闭弹窗
  229. const rowActionModalClose = () => {
  230. rowActionModal.value = false
  231. formModel.value = {}
  232. }
  233. //取消待测
  234. const rowCancel = (row) => {
  235. HcDelMsg({
  236. title: '确认取消提醒',
  237. text: '请谨慎考虑后,确认是否取消待测?',
  238. }, async (resolve) => {
  239. await tableDataCancel(row.id)
  240. resolve() //关闭弹窗的回调
  241. })
  242. }
  243. //批量取消待测
  244. const batchCancel = () => {
  245. const rows = tableCheckedKeys.value
  246. if (rows.length <= 0) {
  247. window.$message.warning('请先勾选需要取消的数据')
  248. return
  249. }
  250. HcDelMsg({
  251. title: '确认取消提醒',
  252. text: '请谨慎考虑后,确认是否取消待测?',
  253. }, async (resolve) => {
  254. await tableDataCancel(arrToId(rows))
  255. resolve() //关闭弹窗的回调
  256. })
  257. }
  258. //取消待测
  259. const tableDataCancel = async (ids) => {
  260. let form = { id: ids, sampleStatus: 2 }
  261. const { error, code, msg } = await mainApi.update(form)
  262. if (!error && code === 200) {
  263. window.$message.success('取消成功')
  264. getTableData().then()
  265. } else {
  266. window.$message.error(msg || '创建失败')
  267. }
  268. }
  269. </script>