commission.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <hc-body split :project-nmae="projectInfo?.projectName">
  3. <template #tree>
  4. <TestTree
  5. :auto-expand-keys="treeAutoExpandKeys" :project-id="projectId" :tenant-id="userInfo?.tenant_id"
  6. :wbs-temp-id="projectInfo?.referenceWbsTemplateIdTrial" :wbs-type="2" @node-tap="wbsElTreeClick"
  7. />
  8. </template>
  9. <hc-new-card w-to="1919">
  10. <template #headerToSearch>
  11. <div class="w-50">
  12. <el-select v-model="searchForm.contractId" placeholder="选择合同段" filterable block>
  13. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  14. </el-select>
  15. </div>
  16. <div class="ml-2 w-40">
  17. <el-select v-model="searchForm.status" placeholder="委托单状态" filterable clearable block>
  18. <el-option v-for="item in entrustStatus" :key="item.value" :label="item.label" :value="item.value" />
  19. </el-select>
  20. </div>
  21. <div class="ml-2 w-250px">
  22. <hc-search-input v-model="searchForm.entrustName" @search="searchClick" />
  23. </div>
  24. </template>
  25. <template #extraToHeader>
  26. <el-button hc-btn type="primary" @click="addFormData">
  27. <hc-icon name="add-circle" />
  28. <span>新增</span>
  29. </el-button>
  30. <el-button v-del-com:[delModalClick] :disabled="tableCheckedKeys.length <= 0" hc-btn type="danger">
  31. <hc-icon name="delete-bin-2" />
  32. <span>删除</span>
  33. </el-button>
  34. <el-button :disabled="tableCheckedKeys.length <= 0" hc-btn color="#567722" @click="batchPrinting">
  35. <hc-icon name="printer" />
  36. <span>批量打印</span>
  37. </el-button>
  38. <el-button :disabled="tableCheckedKeys.length <= 0" class="text-white" hc-btn color="#FF976A" @click="reportClick">
  39. <HcIcon name="send-plane-2" />
  40. <span>上报</span>
  41. </el-button>
  42. <el-button hc-btn color="#567722" @click="printerNull">
  43. <hc-icon name="printer" />
  44. <span>打印空表</span>
  45. </el-button>
  46. </template>
  47. <hc-table
  48. :column="tableColumn" :datas="tableData" :loading="tableLoading" is-check
  49. :index-style="{ width: 60 }" :check-style="{ width: 29 }" @selection-change="tableSelection"
  50. >
  51. <template #status="{ row }">
  52. <el-tag v-if="row.status === 1" type="info" effect="dark">未上报</el-tag>
  53. <el-tag v-if="row.status === 2" type="warning" effect="dark">已上报-待审批</el-tag>
  54. <el-tag v-if="row.status === 3" type="primary" effect="dark">待试验</el-tag>
  55. <el-tag v-if="row.status === 4" type="success" effect="dark">委托完成</el-tag>
  56. </template>
  57. <template #action="{ row }">
  58. <el-link v-if="row.status === 1" type="primary" @click="rowEdit(row)">修改</el-link>
  59. <el-link v-else type="success" @click="rowView(row)">查看</el-link>
  60. <el-link v-if="row.status === 4" type="info" disabled>创建成功</el-link>
  61. <el-link v-else-if="!isNullES(row.testId)" type="danger" :disabled="row.status !== 3" @click="rowFillReports(row)">填写报告</el-link>
  62. <el-link v-else type="danger" :disabled="row.status !== 3" @click="rowReports(row)">创建报告</el-link>
  63. </template>
  64. </hc-table>
  65. <template #action>
  66. <hc-pages :pages="searchForm" @change="pageChange" />
  67. </template>
  68. </hc-new-card>
  69. <!-- 新增委托 -->
  70. <hc-new-dialog v-model="delegateModal" ui="hc-delegate-html-modal" is-footer-center is-table :title="`${editHtmlId ? '修改' : '新增'}委托`" widths="60rem" @close="delegateModalClose">
  71. <div class="hc-delegate-contract hc-flex h-40px">
  72. <el-select v-model="delegateContractId" placeholder="请先选择合同段" filterable class="w-400px" @change="delegateContractChange">
  73. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  74. </el-select>
  75. </div>
  76. <div class="hc-delegate-html" :class="delegateContractId ? 'is-show' : ''">
  77. <hc-table-form ref="htmlRef" :pkey="nodeErTreeId" :form="delegateHtmlForm" :html="delegateHtml" :loading="delegateHtmlLoading" @render="delegateHtmlRender" />
  78. </div>
  79. <template #footer>
  80. <el-button @click="delegateModalClose">取消</el-button>
  81. <el-button hc-btn type="warning" @click="linkSamplingModal = true">关联取样材料</el-button>
  82. <el-button v-if="editHtmlId" hc-btn type="primary" @click="creatingDelegate">保存</el-button>
  83. <el-button v-else hc-btn type="primary" @click="creatingDelegate">创建</el-button>
  84. </template>
  85. </hc-new-dialog>
  86. <!-- 关联取样材料 -->
  87. <SamplingPage v-model="linkSamplingModal" v-model:id="delegateHtmlForm.sampleId" />
  88. <!-- 创建报告 -->
  89. <hc-new-dialog v-model="rowActionModal" is-footer-center title="创建报告" widths="40rem" @close="rowActionModalClose">
  90. <el-form ref="formRef" :model="formModel" :rules="formRules" label-position="top" label-width="auto">
  91. <el-row :gutter="20">
  92. <el-col :span="12">
  93. <el-form-item label="委托单位:">
  94. <el-input v-model="formModel.entrustInfo" placeholder="委托单位" disabled />
  95. </el-form-item>
  96. </el-col>
  97. <el-col :span="12">
  98. <el-form-item label="委托单位名称:">
  99. <el-input v-model="formModel.entrustName" placeholder="委托单位名称" disabled />
  100. </el-form-item>
  101. </el-col>
  102. <el-col :span="12">
  103. <el-form-item label="取样名称:">
  104. <el-input v-model="formModel.materialName" placeholder="取样名称" disabled />
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="12">
  108. <el-form-item label="取样数量:">
  109. <el-input v-model="formModel.materialCount" placeholder="取样数量" disabled />
  110. </el-form-item>
  111. </el-col>
  112. <el-col :span="12">
  113. <el-form-item label="样品编号:">
  114. <el-input v-model="formModel.entrustNo" placeholder="样品编号" disabled />
  115. </el-form-item>
  116. </el-col>
  117. <el-col :span="12">
  118. <el-form-item label="试验数量:" prop="expCount">
  119. <el-input v-model="formModel.expCount" placeholder="试验数量" />
  120. </el-form-item>
  121. </el-col>
  122. <el-col :span="12">
  123. <el-form-item label="规格型号:">
  124. <el-input v-model="formModel.specificationModel" placeholder="规格型号" disabled />
  125. </el-form-item>
  126. </el-col>
  127. <el-col :span="12">
  128. <el-form-item label="计算单位:">
  129. <el-input v-model="formModel.calculationUnit" placeholder="计算单位" disabled />
  130. </el-form-item>
  131. </el-col>
  132. </el-row>
  133. </el-form>
  134. <template #footer>
  135. <el-button @click="rowActionModalClose">取消</el-button>
  136. <el-button hc-btn type="primary" :loading="rowActionLoading" @click="rowActionSave">创建</el-button>
  137. </template>
  138. </hc-new-dialog>
  139. <!-- 上报审批 -->
  140. <hc-report-modal
  141. :show="showReportModal"
  142. :classify-type="classifyType"
  143. :addition="reportAddition"
  144. :contract-id="reportContractId"
  145. :ids="reportIds"
  146. :project-id="projectId"
  147. :task-name="reportTaskName"
  148. :trial-self-inspection-record-id="2"
  149. title="上报审批" type="wbs"
  150. url="informationWriteQuery/batchTask"
  151. @finish="showReportFinish"
  152. @hide="hideReport"
  153. />
  154. </hc-body>
  155. </template>
  156. <script setup>
  157. import { onActivated, ref } from 'vue'
  158. import { useAppStore } from '~src/store'
  159. import { useRouter } from 'vue-router'
  160. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  161. import { arrToId, deepClone, formValidate, getArrValue, getObjValue, isNullES, isString } from 'js-fast-way'
  162. import { toPdfPage } from '~uti/btn-auth'
  163. import { getDictionaryData } from '~uti/tools'
  164. import { getErtractInfo } from '~api/other'
  165. import mainApi from '~api/tentative/detect/commission'
  166. import samplingApi from '~api/tentative/material/sampling'
  167. import TestTree from '~src/views/tentative/material/components/TestTree.vue'
  168. import SamplingPage from './commission/sampling.vue'
  169. //变量
  170. const router = useRouter()
  171. const useAppState = useAppStore()
  172. const userInfo = ref(useAppState.getUserInfo)
  173. const projectId = ref(useAppState.getProjectId)
  174. const contractId = ref(useAppState.getContractId)
  175. const projectInfo = ref(useAppState.getProjectInfo)
  176. const contractInfo = ref(useAppState.getContractInfo)
  177. //渲染完成
  178. onActivated(() => {
  179. getContractData()
  180. getEntrustStatusData()
  181. })
  182. //搜索表单
  183. const searchForm = ref({ entrustName: null, current: 1, size: 20, total: 0 })
  184. //自动展开缓存
  185. const treeAutoExpandKeys = ref(getStoreValue('testTreeExpandKeys') || [])
  186. //树被点击
  187. const nodeDataInfo = ref({})
  188. const nodeErTreeId = ref('')
  189. const wbsElTreeClick = ({ data, keys }) => {
  190. nodeDataInfo.value = data
  191. nodeErTreeId.value = data['erTreeId'] || ''
  192. //缓存自动展开
  193. treeAutoExpandKeys.value = keys
  194. setStoreValue('testTreeExpandKeys', keys)
  195. searchForm.value.nodeId = data['primaryKeyId'] || ''
  196. //获取表格
  197. searchClick()
  198. }
  199. //获取合同段信息
  200. const contractData = ref([])
  201. const getContractData = async () => {
  202. const { data } = await getErtractInfo({
  203. projectId: projectId.value,
  204. contractId: contractId.value,
  205. })
  206. const res = getArrValue(data)
  207. contractData.value = res
  208. if (res.length > 0) {
  209. searchForm.value.contractId = res[0].id
  210. }
  211. }
  212. //获取状态
  213. const entrustStatus = ref([])
  214. const getEntrustStatusData = async () => {
  215. entrustStatus.value = await getDictionaryData('entrust_status', true)
  216. }
  217. //搜索
  218. const searchClick = () => {
  219. searchForm.value.current = 1
  220. getTableData()
  221. }
  222. //分页被点击
  223. const pageChange = ({ current, size }) => {
  224. searchForm.value.current = current
  225. searchForm.value.size = size
  226. getTableData()
  227. }
  228. //表格数据
  229. const tableData = ref([])
  230. const tableColumn = ref([
  231. { key: 'entrustInfo', name: '委托单位' },
  232. { key: 'entrustNo', name: '委托单编号' },
  233. { key: 'entrustName', name: '委托单名称' },
  234. { key: 'materialName', name: '关联材料名称' },
  235. { key: 'status', name: '委托单状态', width: 120, align: 'center' },
  236. { key: 'action', name: '操作', width: 120, align: 'center', fixed: 'right' },
  237. ])
  238. //获取数据
  239. const tableLoading = ref(false)
  240. const getTableData = async () => {
  241. tableLoading.value = true
  242. const { error, code, data } = await mainApi.page(searchForm.value)
  243. //处理数据
  244. tableLoading.value = false
  245. if (!error && code === 200) {
  246. tableData.value = getArrValue(data['records'])
  247. searchForm.value.total = data.total || 0
  248. } else {
  249. tableData.value = []
  250. searchForm.value.total = 0
  251. }
  252. }
  253. //多选
  254. const tableCheckedKeys = ref([])
  255. const tableSelection = (rows) => {
  256. tableCheckedKeys.value = rows
  257. }
  258. //删除
  259. const delModalClick = async (_, resolve) => {
  260. const rows = tableCheckedKeys.value
  261. if (rows.length <= 0) {
  262. window.$message.warning('请先勾选需要删除的数据')
  263. return
  264. }
  265. const { error, code, msg } = await mainApi.remove(arrToId(rows))
  266. resolve()
  267. if (!error && code === 200) {
  268. window.$message.success('删除成功')
  269. getTableData().then()
  270. } else {
  271. window.$message.error(msg || '删除失败')
  272. }
  273. }
  274. //委托单变量
  275. const htmlRef = ref(null)
  276. const delegateHtml = ref('')
  277. const delegateHtmlForm = ref({})
  278. const delegateHtmlLoading = ref(false)
  279. const delegateContractId = ref(null)
  280. //新增
  281. const delegateModal = ref(false)
  282. const addFormData = () => {
  283. delegateModal.value = true
  284. editHtmlId.value = ''
  285. const { contractId } = deepClone(searchForm.value)
  286. delegateContractId.value = contractId
  287. if (!isNullES(contractId)) {
  288. delegateContractChange()
  289. }
  290. }
  291. //合同段被选择
  292. const delegateContractChange = async () => {
  293. delegateHtmlLoading.value = true
  294. if (!isNullES(editHtmlId.value)) {
  295. await getDelegateDataInfo(editHtmlId.value)
  296. }
  297. await getDelegateExcelHtml()
  298. delegateHtmlLoading.value = false
  299. }
  300. //获取委托html
  301. const getDelegateExcelHtml = async () => {
  302. const { primaryKeyId } = nodeDataInfo.value
  303. const { error, code, msg, data } = await samplingApi.getExcelHtml({
  304. primaryKeyId: nodeErTreeId.value,
  305. projectId: projectId.value,
  306. contractId: delegateContractId.value,
  307. nodeId: primaryKeyId,
  308. })
  309. if (!error && code === 200) {
  310. delegateHtml.value = isString(data) ? data : ''
  311. } else {
  312. delegateHtml.value = ''
  313. window.$message.error(msg || '获取委托信息失败')
  314. }
  315. }
  316. //获取委托数据
  317. const getDelegateDataInfo = async (editId) => {
  318. const { primaryKeyId } = nodeDataInfo.value
  319. const { error, code, msg, data } = await samplingApi.getBussDataInfoTrialEntrust({
  320. id: editId,
  321. pkeyId: nodeErTreeId.value,
  322. projectId: projectId.value,
  323. contractId: delegateContractId.value,
  324. nodeId: primaryKeyId,
  325. })
  326. if (!error && code === 200) {
  327. delegateHtmlForm.value = getObjValue(data[0])
  328. } else {
  329. delegateHtmlForm.value = {}
  330. window.$message.error(msg || '获取委托信息失败')
  331. }
  332. }
  333. //委托单html渲染完成
  334. const delegateHtmlRender = (form) => {
  335. delegateHtmlForm.value = form
  336. }
  337. //修改
  338. const editHtmlId = ref('')
  339. const rowEdit = (row) => {
  340. delegateModal.value = true
  341. editHtmlId.value = row.id
  342. const { contractId } = deepClone(searchForm.value)
  343. delegateContractId.value = contractId
  344. if (!isNullES(contractId)) {
  345. delegateContractChange()
  346. }
  347. }
  348. //关联取样材料
  349. const linkSamplingModal = ref(false)
  350. //创建委托
  351. const creatingDelegate = async () => {
  352. if (isNullES(delegateHtml.value)) {
  353. window.$message.error('暂无委托单信息')
  354. return
  355. }
  356. const form = delegateHtmlForm.value
  357. if (isNullES(delegateContractId.value)) {
  358. window.$message.warning('请先选择合同段')
  359. return
  360. }
  361. if (isNullES(form.sampleId)) {
  362. window.$message.warning('请先关联取样材料')
  363. return
  364. }
  365. //修改时的id
  366. if (!isNullES(editHtmlId.value)) {
  367. form.id = editHtmlId.value
  368. }
  369. //处理数据
  370. const { primaryKeyId } = nodeDataInfo.value
  371. form.contractId = delegateContractId.value
  372. form.nodeErTreeId = nodeErTreeId.value
  373. form.nodeId = primaryKeyId
  374. console.log(form)
  375. //发起请求
  376. const { error, code, msg } = await mainApi.htmlSave(form)
  377. if (!error && code === 200) {
  378. window.$message.success('创建成功')
  379. delegateModalClose()
  380. } else {
  381. window.$message.error(msg || '创建失败')
  382. }
  383. }
  384. //关闭委托
  385. const delegateModalClose = () => {
  386. delegateModal.value = false
  387. delegateHtmlForm.value = {}
  388. delegateHtml.value = ''
  389. delegateContractId.value = null
  390. delegateHtmlLoading.value = false
  391. }
  392. //查看
  393. const rowView = ({ entrustPdf }) => {
  394. if (isNullES(entrustPdf)) {
  395. window.$message.warning('暂无数据')
  396. return
  397. }
  398. toPdfPage(entrustPdf)
  399. }
  400. //表单数据
  401. const formRef = ref(null)
  402. const formModel = ref({})
  403. const formRules = {
  404. expCount: {
  405. required: true,
  406. trigger: 'blur',
  407. message: '请填写试验数量',
  408. },
  409. }
  410. //创建报告
  411. const rowActionModal = ref(false)
  412. const rowReports = async (row) => {
  413. rowActionModal.value = true
  414. const { data } = await mainApi.detail(row.id)
  415. formModel.value = getObjValue(data)
  416. }
  417. //提交保存
  418. const rowActionLoading = ref(false)
  419. const rowActionSave = async () => {
  420. const isForm = await formValidate(formRef.value)
  421. if (!isForm) return
  422. rowActionLoading.value = true
  423. const { contractType } = contractInfo.value
  424. const { id, expCount } = formModel.value
  425. const { primaryKeyId } = nodeDataInfo.value
  426. setStoreValue('testTreeItem', nodeDataInfo.value)
  427. setStoreValue('prenodeDataInfo', nodeDataInfo.value)
  428. const { error, code, msg } = await mainApi.update({ id, expCount, sampleStatus: 4 })
  429. if (!error && code === 200) {
  430. window.$message.success('创建成功')
  431. rowActionLoading.value = false
  432. rowActionModalClose()
  433. router.push({
  434. path: '/tentative/detect/test-form',
  435. query: {
  436. nodeId: primaryKeyId || '',
  437. dataType: contractType > 0 ? contractType + '' : '1',
  438. commissionId: id,
  439. isaddType: true,
  440. },
  441. }).then()
  442. } else {
  443. rowActionLoading.value = false
  444. window.$message.error(msg || '创建失败')
  445. }
  446. }
  447. //关闭弹窗
  448. const rowActionModalClose = () => {
  449. rowActionModal.value = false
  450. formModel.value = {}
  451. }
  452. //填写报告
  453. const rowFillReports = async ({ id, testId }) => {
  454. const { error, code, data, msg } = await mainApi.selfDetail(testId)
  455. if (!error && code === 200) {
  456. const res = getObjValue(data)
  457. setStoreValue('test-form', res)
  458. setStoreValue('testTreeItem', nodeDataInfo.value)
  459. setStoreValue('prenodeDataInfo', nodeDataInfo.value)
  460. router.push({
  461. path: '/tentative/detect/test-form',
  462. query: {
  463. id: testId,
  464. nodeId: res.nodeId,
  465. dataType: res.type,
  466. commissionId: id,
  467. tabTypeKey: 1,
  468. },
  469. }).then()
  470. } else {
  471. window.$message.error(msg || '操作失败')
  472. }
  473. }
  474. //批量打印
  475. const batchPrinting = () => {
  476. }
  477. //上报
  478. const classifyType = ref('')
  479. const reportIds = ref('')
  480. const reportTaskName = ref('')
  481. const showReportModal = ref(false)
  482. const reportAddition = ref({})
  483. const reportContractId = ref('')
  484. const reportClick = () => {
  485. const rows = tableCheckedKeys.value
  486. if (rows.length <= 0) {
  487. window.$message.warning('请先勾选一条需要上报的数据')
  488. return
  489. } else if (rows.length > 1) {
  490. window.$message.warning('只能选择其中一条数据进行上报')
  491. return
  492. }
  493. //判断状态
  494. const { id, status, entrustName, contractId: contractIds } = { ...rows[0] }
  495. if (status !== 1) {
  496. window.$message.warning('只能选择未上报的数据进行上报')
  497. return
  498. }
  499. console.log(contractIds)
  500. reportContractId.value = contractIds
  501. //处理类型
  502. const { contractType } = contractInfo.value
  503. classifyType.value = contractType > 0 ? contractType + '' : '1'
  504. //其它数据
  505. reportIds.value = rows[0].id //数据ID
  506. reportTaskName.value = entrustName //任务名称
  507. //附加数据
  508. const { contractIdRelation } = nodeDataInfo.value
  509. reportAddition.value = {
  510. taskType: '1', //说是用来区分委托单
  511. classify: classifyType.value,
  512. contractIdRelation: contractIdRelation,
  513. }
  514. //显示任务上报
  515. showReportModal.value = true
  516. }
  517. //上报完成
  518. const showReportFinish = () => {
  519. hideReport()
  520. getTableData()
  521. }
  522. //关闭上报弹窗
  523. const hideReport = () => {
  524. showReportModal.value = false
  525. classifyType.value = ''
  526. reportAddition.value = {}
  527. reportIds.value = ''
  528. reportTaskName.value = ''
  529. }
  530. //打印空表
  531. const printerNull = () => {
  532. }
  533. </script>
  534. <style lang="scss">
  535. .el-overlay-dialog .el-dialog.hc-new-dialog.hc-delegate-html-modal {
  536. .hc-new-dialog-body {
  537. padding: 0;
  538. }
  539. .hc-table-form-data-item {
  540. padding: 0;
  541. .el-scrollbar__bar.is-vertical {
  542. right: 0;
  543. }
  544. }
  545. }
  546. .hc-delegate-html-modal {
  547. .hc-delegate-html {
  548. position: relative;
  549. height: calc(100% - 40px);
  550. .hc-table-form-data-item {
  551. background-color: #efefef;
  552. }
  553. &::after {
  554. content: "";
  555. position: absolute;
  556. inset: 0;
  557. background: rgb(161 161 161 / 40%);
  558. z-index: 22;
  559. }
  560. &.is-show {
  561. &::after {
  562. display: none;
  563. z-index: -1;
  564. }
  565. }
  566. }
  567. }
  568. </style>