sampling.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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" :entrust="1"
  7. @node-tap="wbsElTreeClick"
  8. />
  9. </template>
  10. <hc-new-card w-to="1919">
  11. <template #headerToSearch>
  12. <div class="w-50">
  13. <el-select v-model="searchForm.contractId" placeholder="选择合同段" filterable block>
  14. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  15. </el-select>
  16. </div>
  17. <div class="ml-2 w-250px">
  18. <hc-date-picker :dates="betweenTime" clearable @change="betweenTimeUpdate" />
  19. </div>
  20. <div class="ml-2 w-72">
  21. <el-input v-model="searchForm.queryValue" clearable placeholder="请输入名称、规格、样品编号查询" @keyup="keyUpEvent" />
  22. </div>
  23. <div class="ml-2">
  24. <el-button type="primary" @click="searchClick">
  25. <hc-icon name="search-2" />
  26. <span>搜索</span>
  27. </el-button>
  28. </div>
  29. </template>
  30. <template #extraToHeader>
  31. <hc-tooltip keys="tentative_material_sampling_add">
  32. <el-button :disabled="!primaryKeyId" hc-btn type="primary" @click="addFormModalClick">
  33. <hc-icon name="add-circle" />
  34. <span>新增</span>
  35. </el-button>
  36. </hc-tooltip>
  37. <hc-tooltip keys="tentative_material_sampling_edit">
  38. <el-button :disabled="tableCheckedKeys.length <= 0" hc-btn type="primary" color="#12C060" style="color: white;" @click="editFormModalClick">
  39. <hc-icon name="edit" />
  40. <span>编辑</span>
  41. </el-button>
  42. </hc-tooltip>
  43. <hc-tooltip keys="tentative_material_sampling_copy">
  44. <el-button :disabled="tableCheckedKeys.length <= 0" hc-btn color="#A16222" @click="copyTableModalClick">
  45. <hc-icon name="file-copy-2" />
  46. <span>复制</span>
  47. </el-button>
  48. </hc-tooltip>
  49. <hc-tooltip keys="tentative_material_sampling_del">
  50. <el-button v-del-com:[delModalClick] :disabled="tableCheckedKeys.length <= 0" hc-btn color="#e03997">
  51. <hc-icon name="delete-bin-2" />
  52. <span>删除</span>
  53. </el-button>
  54. </hc-tooltip>
  55. <hc-tooltip keys="tentative_material_sampling_printer">
  56. <el-button :disabled="tableCheckedKeys.length <= 0" :loading="printerLoading" hc-btn color="#567722" @click="printerClick">
  57. <hc-icon name="printer" />
  58. <span>打印</span>
  59. </el-button>
  60. </hc-tooltip>
  61. <hc-tooltip keys="tentative_material_sampling_import">
  62. <el-button :disabled="!primaryKeyId" hc-btn color="#567722" @click="importModalClick">
  63. <hc-icon name="folder-upload" />
  64. <span>导入</span>
  65. </el-button>
  66. </hc-tooltip>
  67. <hc-tooltip keys="tentative_material_sampling_delegation">
  68. <el-button hc-btn color="#E75643" :disabled="!nodeErTreeId" @click="delegationClick">
  69. <hc-icon name="slack" />
  70. <span>委托</span>
  71. </el-button>
  72. </hc-tooltip>
  73. </template>
  74. <hc-table
  75. ref="tableRef" :column="tableColumn" :datas="tableData" :loading="tableLoading" is-check
  76. :index-style="{ width: 60 }" :check-style="{ width: 29 }" @selection-change="tableSelection"
  77. >
  78. <template #materialCount="{ row }">{{ row.materialCount === -1 ? "" : row.materialCount }}</template>
  79. <template #representativeCount="{ row }">
  80. {{ row.representativeCount === -1 ? "" : row.representativeCount }}
  81. </template>
  82. </hc-table>
  83. <template #action>
  84. <hc-pages :pages="searchForm" @change="pageChange" />
  85. </template>
  86. </hc-new-card>
  87. <!-- 新增/编辑 -->
  88. <hc-new-dialog v-model="addEditFormModal" :title="`${addEditFormModel.id ? '编辑' : '新增'}样品信息`" is-row-footer widths="50rem" @close="addEditFormModalClose">
  89. <el-form ref="addEditFormRef" :model="addEditFormModel" :rules="addEditFormRules" label-width="auto" size="large">
  90. <div class="hc-form-item">
  91. <el-form-item label="样品名称" prop="materialName">
  92. <el-input v-model="addEditFormModel.materialName" />
  93. </el-form-item>
  94. <el-form-item label="进场日期">
  95. <el-date-picker v-model="addEditFormModel.mobilizationDate" :clearable="false" class="block" type="date" value-format="YYYY-MM-DD" />
  96. </el-form-item>
  97. </div>
  98. <div class="hc-form-item">
  99. <el-form-item label="样品编号" prop="specificationNumber">
  100. <el-input v-model="addEditFormModel.specificationNumber" />
  101. </el-form-item>
  102. <el-form-item label="取样日期">
  103. <el-date-picker v-model="addEditFormModel.samplingDate" :clearable="false" class="block" type="date" value-format="YYYY-MM-DD" />
  104. </el-form-item>
  105. </div>
  106. <div class="hc-form-item">
  107. <el-form-item label="规格型号">
  108. <el-input v-model="addEditFormModel.specificationModel" />
  109. </el-form-item>
  110. <el-form-item label="取样地点">
  111. <el-input v-model="addEditFormModel.samplingLocation" />
  112. </el-form-item>
  113. </div>
  114. <div class="hc-form-item">
  115. <el-form-item label="试样数量">
  116. <el-input v-model="addEditFormModel.materialCount" type="number" />
  117. </el-form-item>
  118. <el-form-item label="试样单位">
  119. <el-input v-model="addEditFormModel.calculationUnit" />
  120. </el-form-item>
  121. </div>
  122. <div class="hc-form-item">
  123. <el-form-item label="代表数量">
  124. <el-input v-model="addEditFormModel.representativeCount" type="number" />
  125. </el-form-item>
  126. <el-form-item label="代表单位">
  127. <el-input v-model="addEditFormModel.representativeUnit" />
  128. </el-form-item>
  129. </div>
  130. <div class="hc-form-item">
  131. <el-form-item label="是否外委">
  132. <el-radio-group v-model="addEditFormModel.isOutsourcing" size="large">
  133. <el-radio :value="1">是</el-radio>
  134. <el-radio :value="0">否</el-radio>
  135. </el-radio-group>
  136. </el-form-item>
  137. <el-form-item label="供应商">
  138. <el-input v-model="addEditFormModel.supplierUnit" />
  139. </el-form-item>
  140. </div>
  141. <div class="hc-form-item">
  142. <el-form-item label="生产批号">
  143. <el-input v-model="addEditFormModel.batchNumber" />
  144. </el-form-item>
  145. <el-form-item label="取样人">
  146. <el-select v-model="addEditFormModel.userId" block @change="changeusername">
  147. <el-option v-for="item in userListData" :key="item.userId" :label="item.userName" :value="item.userId" />
  148. </el-select>
  149. </el-form-item>
  150. </div>
  151. <div class="hc-form-item">
  152. <el-form-item label="拟用部位">
  153. <el-input v-model="addEditFormModel.proposedPosition" />
  154. </el-form-item>
  155. <el-form-item label="是否使用RFID">
  156. <el-radio-group v-model="addEditFormModel.isRfid" size="large">
  157. <el-radio :value="1">是</el-radio>
  158. <el-radio :value="0">否</el-radio>
  159. </el-radio-group>
  160. </el-form-item>
  161. </div>
  162. <el-form-item v-if="addEditFormModel.isRfid === 1" label="RFID编号">
  163. <el-select v-model="addEditFormModel.rfid" clearable block>
  164. <el-option v-for="item in deviceTable" :key="item.epc" :label="item.epc" :value="item.epc" />
  165. </el-select>
  166. </el-form-item>
  167. <el-form-item label="样品描述">
  168. <el-input v-model="addEditFormModel.sampleDescription" />
  169. </el-form-item>
  170. </el-form>
  171. <template #leftRowFooter>
  172. <hc-tooltip keys="tentative_material_sampling_links">
  173. <el-button hc-btn type="primary" @click="linksApproachModalClick(addEditFormModel.mobilizationId)">
  174. <hc-icon name="links" />
  175. <span>关联进场材料</span>
  176. </el-button>
  177. </hc-tooltip>
  178. </template>
  179. <template #rightRowFooter>
  180. <el-button size="large" @click="addEditFormModalClose">
  181. <hc-icon name="close" />
  182. <span>取消</span>
  183. </el-button>
  184. <el-button :loading="addEditFormLoading" hc-btn type="primary" @click="addEditFormClick">
  185. <hc-icon name="check" />
  186. <span>确认</span>
  187. </el-button>
  188. </template>
  189. </hc-new-dialog>
  190. <!-- 关联进场材料 -->
  191. <hc-new-dialog v-model="linksApproachModal" is-row-footer is-table title="关联进场材料信息" widths="60%" @close="linksApproachModalClose">
  192. <hc-table :column="linksApproachTableColumn" :datas="linksApproachTableData" :is-index="false" :loading="linksApproachTableLoading">
  193. <template #materialType="{ row }">{{ getRowTableMaterialType(row.materialType) }}</template>
  194. <template #action="{ row }">
  195. <hc-tooltip keys="tentative_material_approach_annex">
  196. <el-button v-if="mobilizationId === row.id" plain size="small" type="primary" @click="cancelApproachRow(row)">取消关联</el-button>
  197. <el-button v-else plain size="small" type="primary" @click="linksApproachRow(row)">关联</el-button>
  198. </hc-tooltip>
  199. </template>
  200. </hc-table>
  201. <template #leftRowFooter>
  202. <hc-pages :pages="ApproachSearchForm" @change="linksApproachPageChange" />
  203. </template>
  204. <template #rightRowFooter>
  205. <el-button size="large" @click="linksApproachModalClose">
  206. <hc-icon name="close" />
  207. <span>取消</span>
  208. </el-button>
  209. <el-button hc-btn type="primary" @click="linksApproachModalSave">
  210. <hc-icon name="check" />
  211. <span>确定</span>
  212. </el-button>
  213. </template>
  214. </hc-new-dialog>
  215. <!-- 复制样品登记信息 -->
  216. <hc-new-dialog v-model="copyTableModal" :loading="copyTableLoading" is-table title="复制样品登记信息" widths="60rem" @close="copyTableModalClose" @save="copyTableClick">
  217. <hc-table :column="copyTableColumn" :datas="copyTableData" is-new :index-style="{ width: 60 }">
  218. <template #specificationNumber="{ row }">
  219. <el-input v-model="row.specificationNumber" placeholder="请输入样品编号" />
  220. </template>
  221. <template #action="{ index }">
  222. <el-button plain size="small" type="danger" @click="specificationNumberDel(index)">删除</el-button>
  223. </template>
  224. </hc-table>
  225. </hc-new-dialog>
  226. <!-- 导入 -->
  227. <hc-new-dialog v-model="importModal" is-row-footer title="导入" widths="38rem" @close="importModalClose">
  228. <HcDragUpload ref="uploadRef" api="/api/blade-business/material/" :datas="uploadData" action="sample/import" @finished="uploadFinished" @progress="uploadprogress" />
  229. <template #leftRowFooter>
  230. <el-button size="large" @click="downloadImportClick">
  231. <hc-icon name="download-2" />
  232. <span>下载模板</span>
  233. </el-button>
  234. </template>
  235. <template #rightRowFooter>
  236. <el-button size="large" @click="importModalClose">
  237. <hc-icon name="close" />
  238. <span>取消导入</span>
  239. </el-button>
  240. <el-button :loading="importModalLoading" hc-btn type="primary" @click="importModalYesClick">
  241. <hc-icon name="folder-upload" />
  242. <span>确认导入</span>
  243. </el-button>
  244. </template>
  245. </hc-new-dialog>
  246. <!-- 创建委托 -->
  247. <hc-new-dialog v-model="delegateModal" ui="hc-delegate-html-modal" is-table is-footer-center title="创建委托" widths="60rem" @close="delegateModalClose">
  248. <div class="hc-delegate-contract hc-flex h-40px">
  249. <el-select v-model="delegateContractId" placeholder="请先选择合同段" filterable class="w-400px" @change="delegateContractChange">
  250. <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
  251. </el-select>
  252. </div>
  253. <div class="hc-delegate-html" :class="delegateContractId ? 'is-show' : ''">
  254. <hc-table-form ref="htmlRef" :pkey="nodeErTreeId" :form="delegateHtmlForm" :html="delegateHtml" :loading="delegateHtmlLoading" @render="delegateHtmlRender" />
  255. </div>
  256. <template #footer>
  257. <el-button @click="delegateModalClose">取消</el-button>
  258. <el-button hc-btn type="primary" :loading="creatingDelegateLoading" @click="creatingDelegate">创建</el-button>
  259. </template>
  260. </hc-new-dialog>
  261. </hc-body>
  262. </template>
  263. <script setup>
  264. import { onActivated, ref, watch } from 'vue'
  265. import { useAppStore } from '~src/store'
  266. import TestTree from './components/TestTree.vue'
  267. import HcDragUpload from './components/HcDragUpload.vue'
  268. import { getStoreValue, setStoreValue } from '~src/utils/storage'
  269. import commissionApi from '~api/tentative/detect/commission'
  270. import samplingApi from '~api/tentative/material/sampling'
  271. import approachApi from '~api/tentative/material/approach'
  272. import { getContractUserList, getDictionary } from '~api/other'
  273. import { arrIndex, arrToId, deepClone, formValidate, getArrValue, getObjValue, isNullES, isString } from 'js-fast-way'
  274. import { toPdfPage } from '~uti/btn-auth'
  275. import Dayjs from 'dayjs'
  276. //变量
  277. const useAppState = useAppStore()
  278. const userInfo = ref(useAppState.getUserInfo)
  279. const projectId = ref(useAppState.getProjectId)
  280. const contractId = ref(useAppState.getContractId)
  281. const projectInfo = ref(useAppState.getProjectInfo)
  282. const isCollapse = ref(useAppState.getCollapse)
  283. //监听
  284. watch(() => useAppState.getCollapse, (collapse) => {
  285. isCollapse.value = collapse
  286. })
  287. //自动展开缓存
  288. const treeAutoExpandKeys = ref(getStoreValue('testTreeExpandKeys') || [])
  289. //渲染完成
  290. onActivated(() => {
  291. getContractData()
  292. getUserListData()
  293. getMaterialType()
  294. })
  295. //获取材料类型
  296. const typeData = ref([])
  297. const getMaterialType = async () => {
  298. const { data } = await getDictionary({
  299. code: 'material_type',
  300. })
  301. typeData.value = getArrValue(data)
  302. }
  303. //获取材料类型
  304. const getRowTableMaterialType = (type) => {
  305. if (type > 0) {
  306. const nodeData = typeData.value
  307. const index = arrIndex(nodeData, 'dictKey', type)
  308. return nodeData[index]?.dictValue ?? type
  309. } else {
  310. return ''
  311. }
  312. }
  313. //获取合同段信息
  314. const contractData = ref([])
  315. const getContractData = async () => {
  316. const { data } = await samplingApi.getErtractInfo({
  317. projectId: projectId.value,
  318. contractId: contractId.value,
  319. })
  320. const res = getArrValue(data)
  321. contractData.value = res
  322. if (res.length <= 0) return
  323. let cid
  324. for (let i = 0; i < res.length; i++) {
  325. if (contractId.value == res[i].id) {
  326. cid = res[i].id
  327. }
  328. }
  329. searchForm.value.contractId = isNullES(cid) ? res[0].id : cid
  330. searchClick()
  331. }
  332. //获取用户列表
  333. const userListData = ref([])
  334. const getUserListData = async () => {
  335. const { data } = await getContractUserList({
  336. contractId: contractId.value,
  337. })
  338. userListData.value = getArrValue(data)
  339. }
  340. //搜索表单
  341. const searchForm = ref({
  342. startTime: null, endTime: null, queryValue: null, nodeId: '',
  343. current: 1, size: 20, total: 0,
  344. })
  345. //树相关的变量
  346. const primaryKeyId = ref('')
  347. const nodeErTreeId = ref('')
  348. const nodeItemInfo = ref({})
  349. const nodeDataInfo = ref({})
  350. //树被点击
  351. const wbsElTreeClick = ({ node, data, keys }) => {
  352. nodeItemInfo.value = node
  353. nodeDataInfo.value = data
  354. primaryKeyId.value = data['primaryKeyId'] || ''
  355. nodeErTreeId.value = data['erTreeId'] || ''
  356. //缓存自动展开
  357. treeAutoExpandKeys.value = keys
  358. setStoreValue('testTreeExpandKeys', keys)
  359. //改变搜索表单数据
  360. searchForm.value.nodeId = data['primaryKeyId'] || ''
  361. searchForm.value.current = 1
  362. getTableData()
  363. }
  364. //日期时间被选择
  365. const betweenTime = ref(null)
  366. const betweenTimeUpdate = ({ arr }) => {
  367. betweenTime.value = arr
  368. if (arr.length > 0) {
  369. searchForm.value.startTime = arr[0]
  370. searchForm.value.endTime = arr[1]
  371. } else {
  372. searchForm.value.startTime = ''
  373. searchForm.value.endTime = ''
  374. }
  375. }
  376. //回车搜索
  377. const keyUpEvent = (e) => {
  378. if (e.key === 'Enter') {
  379. searchForm.value.current = 1
  380. getTableData()
  381. }
  382. }
  383. //搜索
  384. const searchClick = () => {
  385. searchForm.value.current = 1
  386. getTableData()
  387. }
  388. //分页被点击
  389. const pageChange = ({ current, size }) => {
  390. searchForm.value.current = current
  391. searchForm.value.size = size
  392. getTableData()
  393. }
  394. //表格数据
  395. const tableRef = ref(null)
  396. const tableColumn = ref([
  397. { key: 'materialName', name: '取样名称', width: 160, align: 'center' },
  398. { key: 'samplingDate', name: '取样日期', width: 120, align: 'center' },
  399. { key: 'specificationNumber', name: '样品编号', width: 470, align: 'center' },
  400. { key: 'specificationModel', name: '规格型号', width: 180, align: 'center' },
  401. { key: 'materialCount', name: '试样数量', width: 70, align: 'center' },
  402. { key: 'calculationUnit', name: '试样单位', width: 70, align: 'center' },
  403. { key: 'proposedPosition', name: '拟用部位', width: 470, align: 'center' },
  404. { key: 'representativeCount', name: '代表数量', width: 70, align: 'center' },
  405. { key: 'representativeUnit', name: '代表单位', width: 70, align: 'center' },
  406. { key: 'userName', name: '取样人', width: 70, align: 'center' },
  407. ])
  408. //获取数据
  409. const tableLoading = ref(false)
  410. const tableData = ref([])
  411. const getTableData = async () => {
  412. const nodeId = primaryKeyId.value
  413. if (isNullES(nodeId)) return
  414. tableLoading.value = true
  415. const { error, code, data } = await samplingApi.queryPage({
  416. projectId: projectId.value,
  417. nodeId,
  418. ...searchForm.value,
  419. })
  420. //处理数据
  421. tableLoading.value = false
  422. if (!error && code === 200) {
  423. tableData.value = getArrValue(data['records'])
  424. searchForm.value.total = data.total || 0
  425. } else {
  426. tableData.value = []
  427. searchForm.value.total = 0
  428. }
  429. }
  430. //多选
  431. const tableCheckedKeys = ref([])
  432. const tableSelection = (rows) => {
  433. tableCheckedKeys.value = rows
  434. }
  435. //新增
  436. const addEditFormModal = ref(false)
  437. const addFormModalClick = () => {
  438. const toDayDate = new Dayjs().format('YYYY-MM-DD')
  439. addEditFormModel.value = {
  440. isRfid: 0,
  441. isOutsourcing: 0,
  442. mobilizationId: '',
  443. mobilizationDate: toDayDate,
  444. samplingDate: toDayDate,
  445. nodeId: primaryKeyId.value,
  446. userId: userInfo.value.user_id,
  447. }
  448. addEditFormModal.value = true
  449. requestDevice()
  450. }
  451. //编辑
  452. const editFormModalClick = () => {
  453. const keys = tableCheckedKeys.value
  454. if (keys.length === 1) {
  455. const obj = deepClone(keys[0])
  456. addEditFormModel.value = {
  457. ...obj,
  458. representativeCount: obj.representativeCount === -1 ? '' : obj.representativeCount,
  459. materialCount: obj.materialCount === -1 ? '' : obj.materialCount,
  460. isRfid: isNullES(obj.isRfid) ? 0 : obj.isRfid,
  461. }
  462. addEditFormModal.value = true
  463. requestDevice()
  464. } else if (keys.length > 1) {
  465. window?.$message?.warning('只能选择一条数据编辑')
  466. }
  467. }
  468. //获取读卡器设备
  469. let device
  470. const deviceTable = ref([])
  471. const requestDevice = async () => {
  472. if (isNullES(device)) {
  473. const devices = await navigator.hid.requestDevice({
  474. filters: [{ vendorId: 1240, productId: 831 }],
  475. })
  476. if (devices.length <= 0) return
  477. device = devices[0]
  478. }
  479. // 检查设备是否打开
  480. if (!device.opened) {
  481. await device.open() // 打开设备
  482. }
  483. // 电脑接收到来自设备的消息回调
  484. device.oninputreport = (event) => {
  485. const { isRfid, rfid } = addEditFormModel.value
  486. if (isRfid !== 1 ) return
  487. const array = new Uint8Array(event.data.buffer)
  488. const data = array.slice(10, array[0] - 1)
  489. let epc = ''
  490. const res = new Uint8Array(data)
  491. for (const data of res) {
  492. // 将字节数据转换成(XX )形式字符串
  493. epc += (Array(2).join(0) + data.toString(16).toUpperCase()).slice(-2) + ''
  494. }
  495. const index = arrIndex(deviceTable.value, 'epc', epc)
  496. if (index === -1) {
  497. deviceTable.value.push({ epc: epc })
  498. }
  499. if (isNullES(rfid)) {
  500. addEditFormModel.value.rfid = epc
  501. }
  502. }
  503. }
  504. //弹窗关闭
  505. const addEditFormModalClose = async () => {
  506. addEditFormModal.value = false
  507. addEditFormModel.value = {}
  508. if (!isNullES(device)) {
  509. await device.close() // 关闭设备
  510. await device.forget() // 遗忘设备
  511. device = null
  512. }
  513. }
  514. //新增/编辑 表单
  515. const addEditFormRef = ref(null)
  516. const addEditFormModel = ref({})
  517. const addEditFormRules = {
  518. materialName: {
  519. required: true,
  520. trigger: 'blur',
  521. message: '请输入样品名称',
  522. },
  523. specificationNumber: {
  524. required: false,
  525. validator: async (rule, value, callback) => {
  526. if (!value) {
  527. // callback(new Error('请输入样品编号'))
  528. } else {
  529. const ver = await verification(value)
  530. if (!ver) {
  531. callback(new Error('样品编号必须是惟一的'))
  532. } else {
  533. callback()
  534. }
  535. }
  536. },
  537. trigger: 'blur',
  538. },
  539. }
  540. //校验材料编号是否唯一
  541. const verification = async (val) => {
  542. const { error, code, data } = await samplingApi.verification({
  543. projectId: projectId.value,
  544. contractId: searchForm.value.contractId,
  545. specificationNumber: val,
  546. id: addEditFormModel.value.id ?? '',
  547. nodeId: primaryKeyId.value,
  548. })
  549. if (!error && code === 200) {
  550. return !data
  551. } else {
  552. return false
  553. }
  554. }
  555. //新增/编辑 保存
  556. const addEditFormLoading = ref(false)
  557. const addEditFormClick = async () => {
  558. const validate = await formValidate(addEditFormRef.value)
  559. if (validate) {
  560. addEditFormLoading.value = true
  561. const { error, code, msg } = await samplingApi.submitForm({
  562. ...addEditFormModel.value,
  563. projectId: projectId.value,
  564. contractId: searchForm.value.contractId,
  565. })
  566. //处理数据
  567. addEditFormLoading.value = false
  568. if (!error && code === 200) {
  569. window?.$message?.success('操作成功')
  570. addEditFormModal.value = false
  571. await getTableData()
  572. } else {
  573. window?.$message?.error(msg || '操作失败')
  574. }
  575. }
  576. }
  577. //复制表格
  578. const copyTableColumn = ref([
  579. { key: 'materialName', name: '样品名称' },
  580. { key: 'specificationNumber', name: '样品编号' },
  581. { key: 'action', name: '操作', width: 100 },
  582. ])
  583. const copyTableData = ref([])
  584. //复制
  585. const copyTableModal = ref(false)
  586. const copyTableModalClick = () => {
  587. copyTableModal.value = true
  588. copyTableData.value = deepClone(tableCheckedKeys.value)
  589. }
  590. //删除
  591. const specificationNumberDel = (index) => {
  592. copyTableData.value.splice(index, 1)
  593. const rows = copyTableData.value
  594. if (rows.length <= 0) {
  595. copyTableModal.value = false
  596. }
  597. }
  598. const copyTableModalClose = () => {
  599. copyTableModal.value = false
  600. }
  601. //复制 保存
  602. const copyTableLoading = ref(false)
  603. const copyTableClick = () => {
  604. copyTableModal.value = false
  605. const rows = copyTableData.value
  606. if (rows.length > 0) {
  607. for (let i = 0; i < rows.length; i++) {
  608. rows[i].dataNumber = i
  609. }
  610. tableCopyData(rows)
  611. } else {
  612. window.$message?.warning('请先在列表勾选要复制的数据')
  613. copyTableModal.value = false
  614. }
  615. }
  616. //复制数据请求
  617. const tableCopyData = async (rows) => {
  618. copyTableLoading.value = true
  619. const { error, code, msg } = await samplingApi.copyData(rows)
  620. //处理数据
  621. copyTableLoading.value = false
  622. if (!error && code === 200) {
  623. window?.$message?.success('操作成功')
  624. copyTableModal.value = false
  625. await getTableData()
  626. } else {
  627. window?.$message?.error(msg || '操作失败')
  628. }
  629. }
  630. //删除
  631. const delModalClick = async (_, resolve) => {
  632. await tableRemoveData()
  633. resolve()
  634. }
  635. //批量删除
  636. const tableRemoveData = async () => {
  637. const rows = tableCheckedKeys.value
  638. if (rows.length > 0) {
  639. const ids = arrToId(rows)
  640. //删除请求
  641. const { error, code, msg } = await samplingApi.removeData({
  642. projectId: projectId.value,
  643. contractId: searchForm.value.contractId,
  644. ids: ids,
  645. })
  646. //处理数据
  647. if (!error && code === 200) {
  648. window?.$message?.success('操作成功')
  649. searchClick()
  650. } else {
  651. window?.$message?.error(msg || '操作失败')
  652. }
  653. }
  654. }
  655. //打印
  656. const printerLoading = ref(false)
  657. const printerClick = async () => {
  658. const rows = tableCheckedKeys.value
  659. if (rows.length > 0) {
  660. printerLoading.value = true
  661. const ids = arrToId(rows)
  662. //删除请求
  663. const { error, code, data } = await samplingApi.exportPdf({
  664. projectId: projectId.value,
  665. contractId: searchForm.value.contractId,
  666. ids: ids,
  667. })
  668. //处理数据
  669. printerLoading.value = false
  670. if (!error && code === 200) {
  671. toPdfPage(data)
  672. //window.open(data, '_blank')
  673. }
  674. }
  675. }
  676. //导入
  677. const uploadRef = ref(null)
  678. const uploadData = ref({})
  679. //导入
  680. const importModal = ref(false)
  681. const importModalClick = () => {
  682. importModal.value = true
  683. uploadData.value = {
  684. contractId: searchForm.value.contractId,
  685. nodeId: primaryKeyId.value,
  686. isCovered: 1,
  687. }
  688. }
  689. //上传进度
  690. const uploadprogress = (res) => {
  691. importModalLoading.value = res
  692. }
  693. //确认导入
  694. const importModalLoading = ref(false)
  695. const importModalYesClick = () => {
  696. uploadRef.value?.submit()
  697. }
  698. //上传完成
  699. const uploadFinished = () => {
  700. importModal.value = false
  701. getTableData()
  702. }
  703. //关闭导入
  704. const importModalClose = () => {
  705. importModal.value = false
  706. }
  707. //更改取样人名称changeusername
  708. const changeusername = (item) => {
  709. userListData.value.forEach((ele) => {
  710. if (item == ele.userId) {
  711. addEditFormModel.value.userName = ele.userName
  712. }
  713. })
  714. }
  715. //关联进场材料
  716. const linksApproachModal = ref(false)
  717. const ApproachSearchForm = ref({
  718. current: 1, size: 20, total: 0,
  719. })
  720. const mobilizationId = ref('')
  721. const linksApproachModalClick = (mId) => {
  722. mobilizationId.value = mId ?? ''
  723. ApproachSearchForm.value.current = 1
  724. linksApproachModal.value = true
  725. getApproachTableData()
  726. }
  727. //分页被点击
  728. const linksApproachPageChange = ({ current, size }) => {
  729. ApproachSearchForm.value.current = current
  730. ApproachSearchForm.value.size = size
  731. getApproachTableData()
  732. }
  733. //关联进场材料数据
  734. const linksApproachTableColumn = ref([
  735. { key: 'materialNumber', name: '材料编号' },
  736. { key: 'mobilizationDate', name: '进场日期' },
  737. { key: 'materialName', name: '材料名称' },
  738. { key: 'materialType', name: '材料类型' },
  739. { key: 'specificationModel', name: '规格型号' },
  740. { key: 'supplierUnit', name: '供应商单位' },
  741. { key: 'proposedPosition', name: '拟用部位' },
  742. { key: 'userName', name: '记录人' },
  743. { key: 'action', name: '操作', width: 100, fixed: 'right', align: 'center' },
  744. ])
  745. const linksApproachTableData = ref([])
  746. //获取进场材料数据
  747. const linksApproachTableLoading = ref(false)
  748. const getApproachTableData = async () => {
  749. linksApproachTableLoading.value = true
  750. const { error, code, data } = await approachApi.queryPage({
  751. projectId: projectId.value,
  752. contractId: searchForm.value.contractId,
  753. ...ApproachSearchForm.value,
  754. })
  755. //处理数据
  756. linksApproachTableLoading.value = false
  757. if (!error && code === 200) {
  758. linksApproachTableData.value = getArrValue(data['records'])
  759. ApproachSearchForm.value.total = data.total || 0
  760. } else {
  761. linksApproachTableData.value = []
  762. ApproachSearchForm.value.total = 0
  763. }
  764. }
  765. //关联
  766. const linksApproachRow = (row) => {
  767. const toDayDate = new Dayjs().format('YYYY-MM-DD')
  768. const form = addEditFormModel.value
  769. form.materialName = row.materialName ?? '' //样品名称
  770. form.mobilizationDate = row.mobilizationDate ?? toDayDate //进场日期
  771. form.specificationNumber = row.materialNumber ?? '' //样品编号
  772. form.specificationModel = row.specificationModel ?? '' //规格型号
  773. form.supplierUnit = row.supplierUnit ?? '' //供应商
  774. form.calculationUnit = row.calculationUnit ?? '' //计算单位
  775. form.batchNumber = row.batchNumber ?? '' //生产批号
  776. form.proposedPosition = row.proposedPosition ?? '' //拟用部位
  777. form.mobilizationId = row.id //关联ID
  778. //更新数据
  779. addEditFormModel.value = form
  780. mobilizationId.value = row.id //关联ID
  781. }
  782. //取消关联
  783. const cancelApproachRow = (row) => {
  784. if (row.id === mobilizationId.value) {
  785. addEditFormModel.value.mobilizationId = ''
  786. mobilizationId.value = ''
  787. }
  788. }
  789. const linksApproachModalSave = () => {
  790. linksApproachModal.value = false
  791. }
  792. //关闭关联进场材料
  793. const linksApproachModalClose = () => {
  794. linksApproachModal.value = false
  795. }
  796. //下载导入模板
  797. const downloadImportClick = () => {
  798. window.open('https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20221109/1f1cc15e4e4918d8c793fa6ec0a2ae2a.xlsx', '_blank')
  799. }
  800. //委托
  801. const htmlRef = ref(null)
  802. const delegateModal = ref(false)
  803. const delegateHtml = ref('')
  804. const delegateHtmlForm = ref({})
  805. const delegateHtmlLoading = ref(false)
  806. const delegateContractId = ref(null)
  807. const delegationClick = () => {
  808. const rows = tableCheckedKeys.value
  809. if (rows.length <= 0) {
  810. window.$message.warning('请先勾选一条需要委托的数据')
  811. return
  812. } else if (rows.length > 1) {
  813. window.$message.warning('只能选择其中一条数据进行委托')
  814. return
  815. }
  816. const data = rows[0]
  817. if (!isNullES(data.testId)) {
  818. window.$message.warning('已上报的数据不允许委托')
  819. return
  820. }
  821. editHtmlId.value = data.id
  822. entrustId.value = data.entrustId
  823. delegateContractId.value = searchForm.value.contractId
  824. if (!isNullES(contractId)) {
  825. delegateContractChange()
  826. }
  827. }
  828. //合同段被选择
  829. const editHtmlId = ref('')
  830. const entrustId = ref('')
  831. const delegateContractChange = async () => {
  832. delegateHtmlLoading.value = true
  833. const res = await getCheckSample()
  834. if (!res) {
  835. delegateHtmlLoading.value = false
  836. return
  837. }
  838. delegateModal.value = true
  839. await getDelegateExcelHtml()
  840. await getDelegateDataInfo()
  841. delegateHtmlLoading.value = false
  842. }
  843. //校验是否关联
  844. const getCheckSample = async () => {
  845. const { code, msg } = await samplingApi.getCheckSample({
  846. nodeId: primaryKeyId.value,
  847. sampleId: editHtmlId.value,
  848. contractId: delegateContractId.value,
  849. })
  850. //如果是200,说明没有关联,可以委托
  851. if (code === 200) {
  852. return true
  853. } else {
  854. window.$message.error(msg)
  855. return false
  856. }
  857. }
  858. //获取委托数据
  859. const getDelegateDataInfo = async () => {
  860. const { error, code, msg, data } = await samplingApi.getBussDataInfoTrialEntrust({
  861. id: entrustId.value,
  862. sampleId: editHtmlId.value,
  863. pkeyId: nodeErTreeId.value,
  864. contractId: delegateContractId.value,
  865. })
  866. if (!error && code === 200) {
  867. delegateHtmlForm.value = getObjValue(data[0])
  868. } else {
  869. delegateHtmlForm.value = {}
  870. window.$message.error(msg || '获取委托信息失败')
  871. }
  872. }
  873. //获取委托html
  874. const getDelegateExcelHtml = async () => {
  875. const { error, code, msg, data } = await samplingApi.getExcelHtml({
  876. nodeId: primaryKeyId.value,
  877. contractId: contractId.value,
  878. })
  879. if (!error && code === 200) {
  880. delegateHtml.value = isString(data) ? data : ''
  881. nodeErTreeId.value = msg
  882. } else {
  883. delegateHtml.value = ''
  884. nodeErTreeId.value = ''
  885. window.$message.error(msg || '获取委托信息失败')
  886. }
  887. }
  888. //渲染完成
  889. const delegateHtmlRender = (form) => {
  890. delegateHtmlForm.value = form
  891. }
  892. //创建委托
  893. const creatingDelegateLoading = ref(false)
  894. const creatingDelegate = async () => {
  895. const rows = tableCheckedKeys.value
  896. if (isNullES(delegateHtml.value)) {
  897. window.$message.error('暂无委托单信息')
  898. return
  899. }
  900. const form = delegateHtmlForm.value
  901. if (isNullES(delegateContractId.value)) {
  902. window.$message.warning('请先选择合同段')
  903. return
  904. }
  905. creatingDelegateLoading.value = true
  906. form.contractId = delegateContractId.value
  907. form.nodeErTreeId = nodeErTreeId.value
  908. form.sampleId = editHtmlId.value
  909. form.nodeId = rows[0].nodeId
  910. const { error, code, msg } = await commissionApi.htmlSave(form)
  911. creatingDelegateLoading.value = false
  912. if (!error && code === 200) {
  913. window.$message.success('创建成功')
  914. delegateModalClose()
  915. } else {
  916. window.$message.error(msg || '创建失败')
  917. }
  918. }
  919. //关闭委托
  920. const delegateModalClose = () => {
  921. delegateModal.value = false
  922. delegateHtml.value = ''
  923. delegateHtmlForm.value = {}
  924. delegateHtmlLoading.value = false
  925. creatingDelegateLoading.value = false
  926. }
  927. </script>
  928. <style lang="scss" scoped>
  929. @import "../../../styles/tentative/material/sampling.scss";
  930. </style>
  931. <style lang="scss">
  932. .el-overlay-dialog .el-dialog.hc-new-dialog.hc-delegate-html-modal {
  933. .hc-new-dialog-body {
  934. padding: 0;
  935. }
  936. .hc-table-form-data-item {
  937. padding: 0;
  938. .el-scrollbar__bar.is-vertical {
  939. right: 0;
  940. }
  941. }
  942. }
  943. .hc-delegate-html-modal {
  944. .hc-delegate-html {
  945. position: relative;
  946. height: calc(100% - 40px);
  947. .hc-table-form-data-item {
  948. background-color: #efefef;
  949. }
  950. &::after {
  951. content: "";
  952. position: absolute;
  953. inset: 0;
  954. background: rgb(161 161 161 / 40%);
  955. z-index: 22;
  956. }
  957. &.is-show {
  958. &::after {
  959. display: none;
  960. z-index: -1;
  961. }
  962. }
  963. }
  964. }
  965. </style>