commission.vue 20 KB

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