batchImport.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <hc-new-dialog ui="hc-order-import-upload-file-box" widths="1200px" :show="isShow" title="材料计量单导入" @close="modalClose">
  3. <div class="hc-upload-box">
  4. <el-upload
  5. ref="uploadRef" :headers="getHeader()" drag :data="formData" accept=".xls,.xlsx"
  6. :limit="1" :auto-upload="false" action="/api/blade-meter/materialMeterForm/importExcel"
  7. :on-exceed="handleExceed" :on-success="handleSuccess" :on-error="handleError"
  8. >
  9. <div class="text-80px text-gray">
  10. <i class="ri-upload-cloud-line" />
  11. </div>
  12. <div class="mt-24px text-black">将文件拖动到此处,或点击上传</div>
  13. <div class="mt-8px text-12px">支持的文件格式:Excel(xls、xlsx)</div>
  14. </el-upload>
  15. </div>
  16. <hc-card-item class="hc-upload-card-item">
  17. <template #header>
  18. <span class="mr-10px">选择材料</span>
  19. <span class="text-12px" style="color: #FF7D43">温馨提示:可多选材料进行批量上传附件</span>
  20. </template>
  21. <hc-table
  22. ref="tableRef" :column="tableColumn" :datas="tableData" :is-current-row="false"
  23. is-check :check-style="{ width: 29 }" :index-style="{ width: 60 }"
  24. @selection-change="tableCheckChange"
  25. />
  26. </hc-card-item>
  27. <template #footer>
  28. <el-button @click="modalClose">取消</el-button>
  29. <el-button type="primary" :loading="confirmLoading">确认并继续</el-button>
  30. <el-button type="primary" :loading="confirmLoading" @click="confirmClick">确认并退出</el-button>
  31. </template>
  32. </hc-new-dialog>
  33. </template>
  34. <script setup>
  35. import { ref, watch } from 'vue'
  36. import { useAppStore } from '~src/store'
  37. import { getHeader } from 'hc-vue3-ui'
  38. import { genFileId } from 'element-plus'
  39. import { getArrValue, isNullES, newWindow } from 'js-fast-way'
  40. import mainApi from '~api/debit-pay/material/order'
  41. const props = defineProps({
  42. ids: {
  43. type: [String, Number],
  44. default: '',
  45. },
  46. data: {
  47. type: Array,
  48. default: () => ([]),
  49. },
  50. })
  51. //事件
  52. const emit = defineEmits(['finish', 'close'])
  53. const store = useAppStore()
  54. //监听数据
  55. const contractId = ref(store.getContractId)
  56. const projectId = ref(store.getProjectId)
  57. watch(() => [store.getContractId, store.getProjectId], ([cid, pid]) => {
  58. contractId.value = cid
  59. projectId.value = pid
  60. }, { immediate: true, deep: true })
  61. //监听
  62. const ids = ref(props.ids)
  63. watch(() => props.ids, (id) => {
  64. ids.value = id
  65. }, { immediate: true, deep: true })
  66. //监听数据
  67. const tableData = ref([])
  68. watch(() => props.data, (data) => {
  69. tableData.value = getArrValue(data)
  70. }, { deep: true, immediate: true })
  71. //双向绑定
  72. // eslint-disable-next-line no-undef
  73. const isShow = defineModel('modelValue', {
  74. default: false,
  75. })
  76. //上传文件
  77. const uploadRef = ref(null)
  78. //附加数据
  79. const formData = ref({})
  80. const handleExceed = (files) => {
  81. uploadRef.value?.clearFiles()
  82. const file = files[0]
  83. file.uid = genFileId()
  84. uploadRef.value?.handleStart(file)
  85. }
  86. //确认导入
  87. const confirmLoading = ref(false)
  88. const confirmClick = async () => {
  89. formData.value = {
  90. meterPeriodId: ids.value,
  91. projectId: projectId.value,
  92. contractId: contractId.value,
  93. }
  94. confirmLoading.value = true
  95. uploadRef.value?.submit()
  96. }
  97. //上传成功
  98. const handleSuccess = (res) => {
  99. confirmLoading.value = false
  100. if (res.code === 200) {
  101. window.$message.success('上传成功')
  102. modalClose()
  103. emit('finish')
  104. } else {
  105. window.$message.error(res.msg || '上传失败')
  106. }
  107. }
  108. //上传失败
  109. const handleError = (error) => {
  110. confirmLoading.value = false
  111. const { msg } = !isNullES(error.message) ? JSON.parse(error.message) : {}
  112. if (isNullES(msg)) {
  113. window.$message.error('上传失败')
  114. } else {
  115. window.$message.error(msg)
  116. }
  117. }
  118. //下载模板
  119. const downloadTemp = async () => {
  120. const { data } = await mainApi.getImportTemplate()
  121. if (isNullES(data)) {
  122. window.$message.warning('暂无相关模板')
  123. return
  124. }
  125. newWindow(data)
  126. }
  127. //选择材料
  128. const tableRef = ref(null)
  129. const tableColumn = [
  130. { key: 'contractMaterialName', name: '合同材料' },
  131. { key: 'materialArriveNumber', name: '材料到场编号' },
  132. { key: 'businessDate', name: '业务日期' },
  133. { key: 'meterMoney', name: '计量金额' },
  134. ]
  135. //表格选择
  136. const tableKeys = ref([])
  137. const tableCheckChange = (rows) => {
  138. tableKeys.value = rows
  139. }
  140. //关闭弹窗
  141. const modalClose = () => {
  142. isShow.value = false
  143. emit('close')
  144. }
  145. </script>
  146. <style scoped lang="scss">
  147. .hc-upload-box :deep(.el-upload) {
  148. --el-upload-dragger-padding-horizontal: 20px;
  149. }
  150. .hc-upload-text-tip {
  151. color: #FF7D43;
  152. }
  153. </style>
  154. <style lang="scss">
  155. .el-overlay-dialog .el-dialog.hc-new-dialog.hc-order-import-upload-file-box .el-dialog__body {
  156. padding: 14px 4px;
  157. }
  158. .hc-card-item-box.hc-upload-card-item {
  159. padding: 10px;
  160. .hc-card-item-header {
  161. color: unset;
  162. }
  163. }
  164. </style>