commission.vue 21 KB

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