approach.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. <template>
  2. <div class="hc-page-box">
  3. <HcNewCard>
  4. <template #header>
  5. <HcTooltip keys="tentative_material_approach_add">
  6. <el-button hc-btn type="primary" @click="addFormModalClick">
  7. <HcIcon name="add-circle" />
  8. <span>新增</span>
  9. </el-button>
  10. </HcTooltip>
  11. <HcTooltip keys="tentative_material_approach_edit">
  12. <el-button
  13. :disabled="tableCheckedKeys.length <= 0" hc-btn type="primary" color="#12C060"
  14. style="color: white;"
  15. @click="editFormModalClick"
  16. >
  17. <HcIcon name="edit" />
  18. <span>编辑</span>
  19. </el-button>
  20. </HcTooltip>
  21. <HcTooltip keys="tentative_material_approach_copy">
  22. <el-button :disabled="tableCheckedKeys.length <= 0" hc-btn color="#A16222" @click="copyTableModalClick">
  23. <HcIcon name="file-copy-2" />
  24. <span>复制</span>
  25. </el-button>
  26. </HcTooltip>
  27. <HcTooltip keys="tentative_material_approach_del">
  28. <el-button v-del-com:[delModalClick] :disabled="tableCheckedKeys.length <= 0" hc-btn color="#e03997">
  29. <HcIcon name="delete-bin-2" />
  30. <span>删除</span>
  31. </el-button>
  32. </HcTooltip>
  33. <!-- <HcTooltip keys="tentative_material_approach_printer">
  34. <el-button
  35. :disabled="tableCheckedKeys.length <= 0" :loading="printerLoading" hc-btn color="#567722"
  36. @click="printerClick"
  37. >
  38. <HcIcon name="printer" />
  39. <span>打印</span>
  40. </el-button>
  41. </HcTooltip>
  42. <HcTooltip keys="tentative_material_approach_import">
  43. <el-button hc-btn color="#567722" @click="importModalClick">
  44. <HcIcon name="folder-upload" />
  45. <span>导入</span>
  46. </el-button>
  47. </HcTooltip> -->
  48. </template>
  49. <template #search>
  50. <div class="w-40">
  51. <el-select v-model="searchForm.materialType" clearable placeholder="请选择材料类型">
  52. <el-option
  53. v-for="item in typeData" :key="item.value" :label="item.dictValue"
  54. :value="item.dictKey"
  55. />
  56. </el-select>
  57. </div>
  58. <div class="ml-2 w-64">
  59. <HcDatePicker :dates="betweenTime" clearable @change="betweenTimeUpdate" />
  60. </div>
  61. <div class="ml-2 w-72">
  62. <el-input
  63. v-model="searchForm.queryValue" clearable placeholder="请输入名称、规格、材料编号进行查询"
  64. @keyup="keyUpEvent"
  65. />
  66. </div>
  67. <div class="ml-2">
  68. <el-button type="primary" @click="searchClick">
  69. <HcIcon name="search-2" />
  70. <span>搜索</span>
  71. </el-button>
  72. </div>
  73. </template>
  74. <HcTable
  75. ref="tableRef" :column="tableColumn" :datas="tableData" :loading="tableLoad"
  76. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  77. @selection-change="tableSelection"
  78. >
  79. <template #materialType="{ row }">{{ getRowTableMaterialType(row.materialType) }}</template>
  80. <template #materialCount="{ row }">{{ row.materialCount === -1 ? "" : row.materialCount }}</template>
  81. <template #materialPrice="{ row }">{{ row.materialPrice === -1 ? "" : row.materialPrice }}</template>
  82. <template #action="{ row }">
  83. <HcTooltip keys="tentative_material_approach_annex">
  84. <el-button plain size="small" type="primary" @click="viewAttachmentModalClick(row)">
  85. 附件
  86. </el-button>
  87. </HcTooltip>
  88. <HcTooltip keys="tentative_material_approach_sampling">
  89. <el-button plain size="small" type="primary" @click="samplingRecordModalClick(row)">
  90. 取样记录
  91. </el-button>
  92. </HcTooltip>
  93. </template>
  94. </HcTable>
  95. <template #action>
  96. <HcPages :pages="searchForm" @change="pageChange" />
  97. </template>
  98. </HcNewCard>
  99. <!-- 新增/编辑 -->
  100. <hc-new-dialog
  101. v-model="addEditFormModal" :loading="addEditFormLoading" :title="`${addEditFormModel.id ? '编辑' : '新增'}材料进场`"
  102. widths="45rem" @close="addEditFormModalClose" @save="addEditFormClick"
  103. >
  104. <el-form
  105. ref="addEditFormRef" :model="addEditFormModel" :rules="addEditFormRules" label-width="auto"
  106. size="large"
  107. >
  108. <div class="hc-form-item">
  109. <el-form-item label="材料类型" prop="materialType">
  110. <el-select v-model="addEditFormModel.materialType" block>
  111. <el-option v-for="item in typeData" :label="item.dictValue" :value="item.dictKey" />
  112. </el-select>
  113. </el-form-item>
  114. <el-form-item label="材料单价" prop="materialPrice">
  115. <el-input-number v-model="addEditFormModel.materialPrice" :controls="false" />
  116. </el-form-item>
  117. </div>
  118. <div class="hc-form-item">
  119. <el-form-item label="材料名称" prop="materialName">
  120. <el-input v-model="addEditFormModel.materialName" />
  121. </el-form-item>
  122. <el-form-item label="材料数量" prop="materialCount">
  123. <el-input
  124. v-model="addEditFormModel.materialCount"
  125. onkeyup="value = value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g,'$1')"
  126. />
  127. </el-form-item>
  128. </div>
  129. <div class="hc-form-item">
  130. <el-form-item label="规格型号" prop="specificationModel">
  131. <el-input v-model="addEditFormModel.specificationModel" />
  132. </el-form-item>
  133. <el-form-item label="计算单位">
  134. <el-input v-model="addEditFormModel.calculationUnit" />
  135. </el-form-item>
  136. </div>
  137. <div class="hc-form-item">
  138. <el-form-item label="材料编号" prop="materialNumber">
  139. <el-input v-model="addEditFormModel.materialNumber" />
  140. </el-form-item>
  141. <el-form-item label="生产批号">
  142. <el-input v-model="addEditFormModel.batchNumber" />
  143. </el-form-item>
  144. </div>
  145. <div class="hc-form-item">
  146. <el-form-item label="进场日期">
  147. <el-date-picker
  148. v-model="addEditFormModel.mobilizationDate" :clearable="false" class="block"
  149. type="date" value-format="YYYY-MM-DD"
  150. />
  151. </el-form-item>
  152. <el-form-item label="拟用部位">
  153. <el-input v-model="addEditFormModel.proposedPosition" />
  154. </el-form-item>
  155. </div>
  156. <div class="hc-form-item">
  157. <el-form-item label="供应商单位">
  158. <el-input v-model="addEditFormModel.supplierUnit" />
  159. </el-form-item>
  160. <el-form-item label="生产地/厂家">
  161. <el-input v-model="addEditFormModel.placeOfProduction" />
  162. </el-form-item>
  163. </div>
  164. <el-form-item label="生产合格证">
  165. <FormItemUpload v-model="addEditFormModel.productionCertificate" :file-name="productionCertificateName" />
  166. </el-form-item>
  167. <el-form-item label="厂家质检报告">
  168. <FormItemUpload v-model="addEditFormModel.qualityInspectionReport" :file-name="qualityInspectionReportName" />
  169. </el-form-item>
  170. <el-form-item label="其他附件">
  171. <FormItemUpload v-model="addEditFormModel.otherAccessories" :file-name="otherAccessoriesName" />
  172. </el-form-item>
  173. </el-form>
  174. </hc-new-dialog>
  175. <!-- 复制材料登记信息 -->
  176. <hc-new-dialog
  177. v-model="copyTableModal" :loading="copyTableLoading" is-table title="复制材料登记信息" widths="60rem"
  178. @close="copyTableModalClose" @save="copyTableClick"
  179. >
  180. <HcTable :column="copyTableColumn" :datas="copyTableData" is-new :index-style="{ width: 60 }">
  181. <template #materialNumber="{ row }">
  182. <el-input
  183. v-model="row.materialNumber" :class="row.isMaterialNumber ? 'is-error' : ''"
  184. placeholder="请输入材料编号" @blur="materialNumberBlur(row)"
  185. />
  186. </template>
  187. <template #action="{ index }">
  188. <el-button plain size="small" type="danger" @click="materialNumberDel(index)">删除</el-button>
  189. </template>
  190. </HcTable>
  191. </hc-new-dialog>
  192. <!-- 导入 -->
  193. <hc-new-dialog v-model="importModal" is-row-footer title="导入" widths="38rem" @close="importModalClose">
  194. <HcDragUpload
  195. ref="uploadRef" api="/api/blade-business/material/" :datas="uploadData" action="mobilization/import"
  196. @finished="uploadFinished" @progress="uploadprogress"
  197. />
  198. <template #leftRowFooter>
  199. <el-button size="large" @click="downloadImportClick">
  200. <HcIcon name="download-2" />
  201. <span>下载模板</span>
  202. </el-button>
  203. </template>
  204. <template #rightRowFooter>
  205. <el-button size="large" @click="importModalClose">
  206. <HcIcon name="close" />
  207. <span>取消导入</span>
  208. </el-button>
  209. <el-button :loading="importModalLoading" hc-btn type="primary" @click="importModalYesClick">
  210. <HcIcon name="folder-upload" />
  211. <span>确认导入</span>
  212. </el-button>
  213. </template>
  214. </hc-new-dialog>
  215. <!-- 查看附件 -->
  216. <hc-new-dialog
  217. v-model="viewAttachmentModal" is-table title="查看附件" widths="70rem" is-row-footer
  218. @close="viewAttachmentModalClose"
  219. >
  220. <template #extra>
  221. <HcNewSwitch :datas="tabTypeTab" :disabled="tableRowPdfDisabled" :keys="tabTypeKey" size="default" @change="tabTypeChange" />
  222. </template>
  223. <div class="hc-switch-tab-content">
  224. <div class="h-full w-full">
  225. <div v-if="tableRowData[tabTypeKey]" style="text-align:center;height:100%">
  226. <div class="hc-no-table-form">
  227. <div class="table-form-no" style="margin-top:100px">
  228. <HcDragUpload
  229. accept="image/png,image/jpg,image/jpeg,application/pdf,.doc,.docx,application/msword" action="endpoint/put-file-attach" format-tip=":jpg/png/pdf/excel/word.pdf"
  230. auto-upload
  231. @finished="tableRowPdfFinished"
  232. @progress="tableRowPdfProgress"
  233. />
  234. <el-link style="margin-top:10px" type="primary" @click="tableItemClick(tableRowData)">
  235. <!-- {{ splitFileName(tableRowData[tabTypeKey]) }} -->
  236. {{ `${tableRowData[`${tabTypeKey}Name`]}` }}
  237. </el-link>
  238. </div>
  239. </div>
  240. </div>
  241. <div v-else class="hc-no-table-form">
  242. <div class="table-form-no">
  243. <img :src="notableform" alt="">
  244. <div class="desc">暂无 文件 数据,请上传</div>
  245. <HcDragUpload
  246. accept="image/png,image/jpg,image/jpeg,application/pdf" action="endpoint/put-file-attach" format-tip=":jpg/png/pdf/excel/word.pdf"
  247. auto-upload
  248. @finished="tableRowPdfFinished"
  249. @progress="tableRowPdfProgress"
  250. />
  251. </div>
  252. </div>
  253. </div>
  254. </div>
  255. <template #rightRowFooter>
  256. <el-button v-if="tableRowData[tabTypeKey]" hc-btn size="large" type="primary" @click="deleteFile">
  257. <HcIcon name="delete-bin-2" />
  258. <span>删除</span>
  259. </el-button>
  260. </template>
  261. </hc-new-dialog>
  262. <!-- 取样记录 -->
  263. <hc-new-dialog v-model="samplingRecordModal" :footer="false" is-table title="取样记录" widths="60%" @close="samplingRecordModalClose">
  264. <HcTable
  265. :column="samplingTableColumn" :datas="samplingTableData" :is-index="false"
  266. :loading="samplingTableLoading" is-new
  267. >
  268. <template #isOutsourcing="{ row }">
  269. <span>{{ row.isOutsourcing === 1 ? '是' : '否' }}</span>
  270. </template>
  271. </HcTable>
  272. </hc-new-dialog>
  273. </div>
  274. </template>
  275. <script setup>
  276. import { onMounted, ref } from 'vue'
  277. import { useAppStore } from '~src/store'
  278. import HcDragUpload from './components/HcDragUpload.vue'
  279. import FormItemUpload from './components/FormItemUpload.vue'
  280. import notableform from '~src/assets/view/notableform.svg'
  281. import approachApi from '~api/tentative/material/approach'
  282. import dataApi from '~api/basic/code'
  283. import { arrIndex, arrToId, deepClone, formValidate, getArrValue, isNullES } from 'js-fast-way'
  284. import { getDictionary } from '~api/other'
  285. import { toPdfPage } from '~uti/btn-auth'
  286. import Dayjs from 'dayjs'
  287. import { getObjVal } from 'js-fast-way'
  288. //初始变量
  289. const useAppState = useAppStore()
  290. //全局变量
  291. const projectId = ref(useAppState.getProjectId)
  292. const contractId = ref(useAppState.getContractId)
  293. //渲染完成
  294. onMounted(() => {
  295. getMaterialType()
  296. getTableData()
  297. })
  298. //获取材料类型
  299. const typeData = ref([])
  300. const getMaterialType = async () => {
  301. const { data } = await getDictionary({
  302. code: 'material_type',
  303. })
  304. typeData.value = getArrValue(data)
  305. //dictValue, dictKey
  306. }
  307. //获取材料类型
  308. const getRowTableMaterialType = (type) => {
  309. if (type > 0) {
  310. const nodeData = typeData.value
  311. const index = arrIndex(nodeData, 'dictKey', type)
  312. return nodeData[index]?.dictValue ?? type
  313. } else {
  314. return ''
  315. }
  316. }
  317. //搜索表单
  318. const searchForm = ref({
  319. materialType: null, startTime: null, endTime: null, queryValue: null,
  320. current: 1, size: 20, total: 0,
  321. })
  322. //日期时间被选择
  323. const betweenTime = ref(null)
  324. const betweenTimeUpdate = ({ arr }) => {
  325. betweenTime.value = arr
  326. if (arr.length > 0) {
  327. searchForm.value.startTime = arr[0]
  328. searchForm.value.endTime = arr[1]
  329. } else {
  330. searchForm.value.startTime = ''
  331. searchForm.value.endTime = ''
  332. }
  333. }
  334. //回车搜索
  335. const keyUpEvent = (e) => {
  336. if (e.key === 'Enter') {
  337. searchForm.value.current = 1
  338. getTableData()
  339. }
  340. }
  341. //搜索
  342. const searchClick = () => {
  343. searchForm.value.current = 1
  344. getTableData()
  345. }
  346. //分页被点击
  347. const pageChange = ({ current, size }) => {
  348. searchForm.value.current = current
  349. searchForm.value.size = size
  350. getTableData()
  351. }
  352. //表格数据
  353. const tableRef = ref(null)
  354. const tableColumn = ref([
  355. { key: 'materialNumber', name: '材料编号' },
  356. { key: 'mobilizationDate', name: '进场日期' },
  357. { key: 'materialName', name: '材料名称' },
  358. { key: 'materialType', name: '材料类型' },
  359. { key: 'specificationModel', name: '规格型号' },
  360. { key: 'supplierUnit', name: '供应商单位' },
  361. { key: 'materialPrice', name: '材料单价' },
  362. { key: 'materialCount', name: '材料数量' },
  363. { key: 'calculationUnit', name: '计算单位' },
  364. { key: 'batchNumber', name: '生产批号' },
  365. { key: 'placeOfProduction', name: '生产地/厂家' },
  366. { key: 'proposedPosition', name: '拟用部位' },
  367. { key: 'userName', name: '记录人' },
  368. { key: 'action', name: '操作', width: 150, fixed: 'right', align: 'center' },
  369. ])
  370. const tableRowData = ref({})
  371. const tableItemClick = (row) => {
  372. toPdfPage(row[`${tabTypeKey.value}PdfUrl`])
  373. }
  374. //获取数据
  375. const tableLoad = ref(true)
  376. const tableData = ref([])
  377. const getTableData = async () => {
  378. tableLoad.value = true
  379. const { error, code, data } = await approachApi.queryPage({
  380. projectId: projectId.value,
  381. contractId: contractId.value,
  382. ...searchForm.value,
  383. })
  384. //处理数据
  385. tableLoad.value = false
  386. if (!error && code === 200) {
  387. tableData.value = getArrValue(data['records'])
  388. searchForm.value.total = data.total || 0
  389. } else {
  390. tableData.value = []
  391. searchForm.value.total = 0
  392. }
  393. }
  394. //多选
  395. const tableCheckedKeys = ref([])
  396. const tableSelection = (rows) => {
  397. tableCheckedKeys.value = rows.filter((item) => {
  398. return (item ?? '') !== ''
  399. })
  400. }
  401. //新增 材料进场
  402. const addEditFormModal = ref(false)
  403. const addFormModalClick = () => {
  404. addEditFormModel.value = {
  405. mobilizationDate: new Dayjs().format('YYYY-MM-DD'),
  406. }
  407. addEditFormModal.value = true
  408. getMaterialNumber()
  409. }
  410. //获取材料编号
  411. const backObj = ref({})
  412. const getMaterialNumber = async () => {
  413. const { error, code, data } = await dataApi.getTrialNumber({
  414. projectId: projectId.value,
  415. contractId: contractId.value,
  416. type: 1,
  417. })
  418. //处理数据
  419. if (!error && code === 200) {
  420. backObj.value = getObjVal(data)
  421. } else {
  422. backObj.value = {}
  423. }
  424. }
  425. //编辑 材料进场
  426. const editFormModalClick = () => {
  427. const keys = tableCheckedKeys.value
  428. if (keys.length === 1) {
  429. addEditFormModel.value = { ...keys[0] }
  430. const editobj = { ...addEditFormModel.value }
  431. addEditFormModel.value.materialType = editobj.materialType + ''
  432. addEditFormModel.value.materialCount = editobj.materialCount === -1 ? '' : editobj.materialCount
  433. addEditFormModel.value.materialPrice = editobj.materialPrice === -1 ? '' : editobj.materialPrice
  434. productionCertificateName.value = editobj.productionCertificateName
  435. otherAccessoriesName.value = editobj.otherAccessoriesName
  436. qualityInspectionReportName.value = editobj.qualityInspectionReportName
  437. addEditFormModal.value = true
  438. } else if (keys.length > 1) {
  439. window?.$message?.warning('只能选择一条数据编辑')
  440. }
  441. }
  442. const addEditFormModalClose = () => {
  443. addEditFormModal.value = false
  444. addEditFormModel.value = {}
  445. }
  446. //新增/编辑 表单
  447. const addEditFormRef = ref(null)
  448. const addEditFormModel = ref({})
  449. const otherAccessoriesName = ref('')
  450. const productionCertificateName = ref('')
  451. const qualityInspectionReportName = ref('')
  452. const addEditFormRules = {
  453. materialType: {
  454. required: true,
  455. trigger: 'change',
  456. message: '请选择材料类型',
  457. },
  458. materialName: {
  459. required: true,
  460. trigger: 'blur',
  461. message: '请输入材料名称',
  462. },
  463. specificationModel: {
  464. required: true,
  465. trigger: 'blur',
  466. message: '请输入规格型号',
  467. },
  468. materialNumber: {
  469. required: false,
  470. validator: async (rule, value, callback) => {
  471. if (!value) {
  472. return
  473. } else {
  474. const ver = await verification(value)
  475. if (!ver) {
  476. callback(new Error('材料编号必须是惟一的'))
  477. } else {
  478. callback()
  479. }
  480. }
  481. },
  482. trigger: 'blur',
  483. },
  484. materialPrice: {
  485. required: false,
  486. validator: async (rule, value, callback) => {
  487. if (!value) {
  488. return
  489. } else if (value.length > 8) {
  490. callback(new Error('材料单价长度不能超过八位数'))
  491. }
  492. },
  493. trigger: 'blur',
  494. },
  495. materialCount: {
  496. required: false,
  497. validator: async (rule, value, callback) => {
  498. if (!value) {
  499. callback()
  500. } else if (value.length > 10) {
  501. callback(new Error('材料数量长度不能超过10位数'))
  502. }
  503. },
  504. trigger: 'blur',
  505. },
  506. }
  507. //校验材料编号是否唯一
  508. const verification = async (val) => {
  509. const { error, code, data } = await approachApi.verification({
  510. projectId: projectId.value,
  511. contractId: contractId.value,
  512. materialNumber: val,
  513. id: addEditFormModel.value.id ?? '',
  514. })
  515. if (!error && code === 200) {
  516. return !data
  517. } else {
  518. return false
  519. }
  520. }
  521. //新增/编辑 保存
  522. const addEditFormLoading = ref(false)
  523. const addEditFormClick = async () => {
  524. const validate = await formValidate(addEditFormRef.value)
  525. if (validate) {
  526. addEditFormLoading.value = true
  527. addEditFormModel.value.materialCount = Number(addEditFormModel.value.materialCount)
  528. const { error, code, msg } = await approachApi.submitForm({
  529. ...addEditFormModel.value,
  530. projectId: projectId.value,
  531. contractId: contractId.value,
  532. trialAutoNumber: backObj.value?.trialAutoNumber,
  533. autoIncrementNumber: backObj.value?.autoIncrementNumber,
  534. })
  535. //处理数据
  536. if (!error && code === 200) {
  537. window?.$message?.success('操作成功')
  538. addEditFormModal.value = false
  539. addEditFormLoading.value = false
  540. await getTableData()
  541. } else {
  542. window?.$message?.error(msg || '操作失败')
  543. addEditFormLoading.value = false
  544. }
  545. }
  546. }
  547. //复制表格
  548. const copyTableColumn = ref([
  549. { key: 'materialName', name: '材料名称' },
  550. { key: 'materialNumber', name: '材料编号' },
  551. { key: 'action', name: '操作', width: 100 },
  552. ])
  553. const copyTableData = ref([])
  554. //复制
  555. const copyTableModal = ref(false)
  556. const copyTableModalClick = () => {
  557. copyTableModal.value = true
  558. copyTableData.value = deepClone(tableCheckedKeys.value)
  559. }
  560. //效验材料编号
  561. const materialNumberBlur = async (row) => {
  562. const number = row?.materialNumber ?? ''
  563. if (number) {
  564. const ver = await verification(number)
  565. row.isMaterialNumber = !ver
  566. } else {
  567. row.isMaterialNumber = true
  568. }
  569. }
  570. //删除
  571. const materialNumberDel = (index) => {
  572. copyTableData.value.splice(index, 1)
  573. const rows = copyTableData.value
  574. if (rows.length <= 0) {
  575. copyTableModal.value = false
  576. }
  577. }
  578. const copyTableModalClose = () => {
  579. copyTableModal.value = false
  580. }
  581. //复制 保存
  582. const copyTableLoading = ref(false)
  583. const copyTableClick = () => {
  584. const rows = copyTableData.value
  585. if (rows.length > 0) {
  586. //判断是否满足条件
  587. const result = rows.every(({ materialNumber }) => {
  588. return !isNullES(materialNumber)
  589. })
  590. //判断状态
  591. if (result) {
  592. tableCopyData(rows)
  593. } else {
  594. window.$message?.warning('材料编号不能为空')
  595. }
  596. } else {
  597. window.$message?.warning('请先在列表勾选要复制的数据')
  598. copyTableModal.value = false
  599. }
  600. }
  601. //复制数据请求
  602. const tableCopyData = async (rows) => {
  603. copyTableLoading.value = true
  604. const { error, code, msg } = await approachApi.copyData(rows)
  605. //处理数据
  606. copyTableLoading.value = false
  607. if (!error && code === 200) {
  608. window?.$message?.success('操作成功')
  609. copyTableModal.value = false
  610. await getTableData()
  611. }
  612. }
  613. //删除
  614. const delModalClick = async (_, resolve) => {
  615. await tableRemoveData()
  616. resolve()
  617. }
  618. //批量删除
  619. const tableRemoveData = async () => {
  620. const rows = tableCheckedKeys.value
  621. if (rows.length > 0) {
  622. const ids = arrToId(rows)
  623. //删除请求
  624. const { error, code, msg } = await approachApi.removeData({
  625. projectId: projectId.value,
  626. contractId: contractId.value,
  627. ids: ids,
  628. })
  629. //处理数据
  630. if (!error && code === 200) {
  631. window?.$message?.success('操作成功')
  632. searchClick()
  633. }
  634. }
  635. }
  636. //打印
  637. const printerLoading = ref(false)
  638. const printerClick = async () => {
  639. const rows = tableCheckedKeys.value
  640. if (rows.length > 0) {
  641. printerLoading.value = true
  642. const ids = arrToId(rows)
  643. //删除请求
  644. const { error, code, data } = await approachApi.exportPdf({
  645. projectId: projectId.value,
  646. contractId: contractId.value,
  647. ids: ids,
  648. })
  649. //处理数据
  650. printerLoading.value = false
  651. if (!error && code === 200) {
  652. toPdfPage(data)
  653. //window.open(data, '_blank')
  654. }
  655. }
  656. }
  657. //导入
  658. const uploadRef = ref(null)
  659. const uploadData = ref({})
  660. //导入弹窗
  661. const importModal = ref(false)
  662. const importModalClick = () => {
  663. importModal.value = true
  664. uploadData.value = {
  665. contractId: contractId.value,
  666. isCovered: 1,
  667. }
  668. }
  669. //上传进度
  670. const uploadprogress = (res) => {
  671. importModalLoading.value = res
  672. }
  673. //确认导入
  674. const importModalLoading = ref(false)
  675. const importModalYesClick = () => {
  676. uploadRef.value?.submit()
  677. }
  678. //上传完成
  679. const uploadFinished = () => {
  680. importModal.value = false
  681. getTableData()
  682. }
  683. //关闭导入
  684. const importModalClose = () => {
  685. importModal.value = false
  686. }
  687. //查看附件
  688. const viewAttachmentModal = ref(false)
  689. const viewAttachmentModalClick = (row) => {
  690. tableRowData.value = row
  691. viewAttachmentModal.value = true
  692. tabTypeKey.value = 'productionCertificate'
  693. const key = tabTypeKey.value
  694. // ispdf.value = getCaption(row[key])
  695. // tableItemClick(row)
  696. }
  697. //类型tab数据和相关处理
  698. const tabTypeKey = ref('')
  699. const tabTypeKeyType = ref(1)
  700. const ispdf = ref(-1)
  701. const tabTypeTab = ref([
  702. { key: 'productionCertificate', name: '生产合格证', type: 1 },
  703. { key: 'qualityInspectionReport', name: '厂家质检报告', type: 2 },
  704. { key: 'otherAccessories', name: '其他文件', type: 3 },
  705. ])
  706. const tabTypeChange = (item) => {
  707. tabTypeKey.value = item?.key
  708. tabTypeKeyType.value = item?.type
  709. const row = tableRowData.value, key = tabTypeKey.value
  710. ispdf.value = getCaption(row[key])
  711. }
  712. //截取文件名称
  713. const splitFileName = (str) => {
  714. // if(str.indexOf("https://bladex-test-info.oss-cn-chengdu.aliyuncs.com//upload") != -1){
  715. if (str.indexOf('https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload') !== -1 || str.indexOf('http://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload') !== -1) {
  716. let a = str.split('//')[2].split('/')[2]
  717. return a
  718. } else {
  719. return str
  720. }
  721. }
  722. //上传进度
  723. const tableRowPdfDisabled = ref(false)
  724. const tableRowPdfProgress = (res) => {
  725. tableRowPdfDisabled.value = res
  726. }
  727. //上传完成
  728. const tableRowPdfFinished = async (data1) => {
  729. console.log(data1, 'data')
  730. tableRowPdfDisabled.value = true
  731. const row = tableRowData.value, key = tabTypeKey.value
  732. row[key] = data1?.link
  733. row[key + 'Name'] = data1.originalName
  734. // //保存请求
  735. // const { error, code } = await approachApi.submitForm({
  736. // ...row,
  737. // projectId: projectId.value,
  738. // contractId: contractId.value
  739. // })
  740. // //处理数据
  741. // tableRowData.value = row
  742. // tableRowPdfDisabled.value = false
  743. // if (!error && code === 200) {
  744. // window?.$message?.success('操作成功')
  745. // await getTableData()
  746. // }
  747. const { error, code, data } = await approachApi.updateMobilizationFile(
  748. {
  749. id: row.id,
  750. type: tabTypeKeyType.value,
  751. url: data1?.link,
  752. })
  753. //处理数据
  754. tableRowData.value = row
  755. console.log(row, 'row111111111')
  756. tableRowPdfDisabled.value = false
  757. if (!error && code === 200) {
  758. // window?.$message?.success('操作成功')
  759. await getTableData()
  760. tableData.value.forEach(item => {
  761. if (item.id === row.id) {
  762. tableRowData.value = item
  763. }
  764. })
  765. }
  766. }
  767. const getCaption = (obj) => {
  768. if (obj) {
  769. const index = obj.lastIndexOf('pdf')
  770. return index
  771. }
  772. }
  773. //删除上传附件
  774. const deleteFile = () => {
  775. console.log('删除')
  776. console.log(tableRowData.value[tabTypeKey])
  777. tableRowData.value[tabTypeKey.value] = ''
  778. }
  779. //关闭查看附件
  780. const viewAttachmentModalClose = () => {
  781. viewAttachmentModal.value = false
  782. }
  783. //取样记录
  784. const samplingRecordModal = ref(false)
  785. const samplingRecordModalClick = async (row) => {
  786. samplingRecordModal.value = true
  787. samplingTableLoading.value = true
  788. const { data } = await approachApi.samplingRecord({
  789. projectId: projectId.value,
  790. contractId: contractId.value,
  791. id: row.id,
  792. })
  793. samplingTableLoading.value = false
  794. samplingTableData.value = getArrValue(data)
  795. }
  796. //取样记录数据
  797. const samplingTableColumn = ref([
  798. { key: 'specificationNumber', name: '样品编号' },
  799. { key: 'materialName', name: '样品名称' },
  800. { key: 'samplingDate', name: '取样日期' },
  801. { key: 'userName', name: '取样人' },
  802. { key: 'materialCount', name: '试样数量' },
  803. { key: 'isOutsourcing', name: '是否外委' },
  804. ])
  805. const samplingTableData = ref([])
  806. const samplingTableLoading = ref(false)
  807. //关闭取样记录
  808. const samplingRecordModalClose = () => {
  809. samplingRecordModal.value = false
  810. }
  811. //下载导入模板
  812. const downloadImportClick = () => {
  813. window.open('https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20221109/fea12aaee9d964d2d9f894cc6bf4a2f6.xlsx', '_blank')
  814. }
  815. </script>
  816. <style lang="scss" scoped>
  817. @import "../../../styles/tentative/material/approach.scss";
  818. </style>