ZaiZai пре 1 година
родитељ
комит
feb2148463

+ 8 - 0
src/api/modules/debit-pay/material/order.js

@@ -49,4 +49,12 @@ export default {
             params: form,
         }, false)
     },
+    //批量导入
+    async batchImportFile(form) {
+        return HcApi({
+            url: '/api/blade-meter/materialMeterForm/batchImportFile',
+            method: 'post',
+            data: form,
+        }, true)
+    },
 }

+ 1 - 1
src/config/index.json

@@ -5,7 +5,7 @@
     "target": "http://39.108.216.210:8090",
     "target4": "http://192.168.0.109:8090",
     "target5": "http://192.168.0.102:8090",
-    "socket1": "wss://39.108.216.210:19527/websocket",
+    "socket": "wss://measure.hczcxx.cn/websocket",
     "smsPhone": "",
     "vite": {
         "port": 5180,

+ 82 - 54
src/views/debit-pay/material/components/order/batchImport.vue

@@ -1,10 +1,10 @@
 <template>
-    <hc-new-dialog ui="hc-order-import-upload-file-box" widths="1200px" :show="isShow" title="材料计量单导入" @close="modalClose">
+    <hc-new-dialog ui="hc-order-batch-import-file-box" widths="1000px" :show="isShow" title="材料计量单导入" @close="modalClose">
         <div class="hc-upload-box">
             <el-upload
-                ref="uploadRef" :headers="getHeader()" drag :data="formData" accept=".xls,.xlsx"
-                :limit="1" :auto-upload="false" action="/api/blade-meter/materialMeterForm/importExcel"
-                :on-exceed="handleExceed" :on-success="handleSuccess" :on-error="handleError"
+                ref="uploadRef" :headers="getHeader()" drag accept=".xls,.xlsx"
+                action="/api/blade-resource/oss/endpoint/upload-file" multiple
+                :on-success="handleSuccess" :on-error="handleError"
             >
                 <div class="text-80px text-gray">
                     <i class="ri-upload-cloud-line" />
@@ -26,18 +26,17 @@
         </hc-card-item>
         <template #footer>
             <el-button @click="modalClose">取消</el-button>
-            <el-button type="primary" :loading="confirmLoading">确认并继续</el-button>
+            <el-button type="primary" :loading="confirmLoading" @click="confirmTap">确认并继续</el-button>
             <el-button type="primary" :loading="confirmLoading" @click="confirmClick">确认并退出</el-button>
         </template>
     </hc-new-dialog>
 </template>
 
 <script setup>
-import { ref, watch } from 'vue'
+import { nextTick, ref, watch } from 'vue'
 import { useAppStore } from '~src/store'
 import { getHeader } from 'hc-vue3-ui'
-import { genFileId } from 'element-plus'
-import { getArrValue, isNullES, newWindow } from 'js-fast-way'
+import { arrToId, getArrValue, getObjValue, isNullES } from 'js-fast-way'
 import mainApi from '~api/debit-pay/material/order'
 
 const props = defineProps({
@@ -45,10 +44,6 @@ const props = defineProps({
         type: [String, Number],
         default: '',
     },
-    data: {
-        type: Array,
-        default: () => ([]),
-    },
 })
 
 //事件
@@ -69,50 +64,27 @@ watch(() => props.ids, (id) => {
     ids.value = id
 }, { immediate: true, deep: true })
 
-//监听数据
-const tableData = ref([])
-watch(() => props.data, (data) => {
-    tableData.value = getArrValue(data)
-}, { deep: true, immediate: true })
-
 //双向绑定
 // eslint-disable-next-line no-undef
 const isShow = defineModel('modelValue', {
     default: false,
 })
 
+//监听是否显示
+watch(() =>isShow.value, (val) => {
+    if (val) getTableData()
+}, { deep: true })
+
 //上传文件
 const uploadRef = ref(null)
 
-//附加数据
-const formData = ref({})
-
-const handleExceed = (files) => {
-    uploadRef.value?.clearFiles()
-    const file = files[0]
-    file.uid = genFileId()
-    uploadRef.value?.handleStart(file)
-}
-
-//确认导入
-const confirmLoading = ref(false)
-const confirmClick = async () => {
-    formData.value = {
-        meterPeriodId: ids.value,
-        projectId: projectId.value,
-        contractId: contractId.value,
-    }
-    confirmLoading.value = true
-    uploadRef.value?.submit()
-}
-
 //上传成功
+const formDataFiles = ref([])
 const handleSuccess = (res) => {
     confirmLoading.value = false
     if (res.code === 200) {
-        window.$message.success('上传成功')
-        modalClose()
-        emit('finish')
+        const data = getObjValue(res.data)
+        formDataFiles.value.push(data)
     } else {
         window.$message.error(res.msg || '上传失败')
     }
@@ -129,16 +101,6 @@ const handleError = (error) => {
     }
 }
 
-//下载模板
-const downloadTemp = async () => {
-    const { data } = await mainApi.getImportTemplate()
-    if (isNullES(data)) {
-        window.$message.warning('暂无相关模板')
-        return
-    }
-    newWindow(data)
-}
-
 //选择材料
 const tableRef = ref(null)
 const tableColumn = [
@@ -147,6 +109,23 @@ const tableColumn = [
     { key: 'businessDate', name: '业务日期' },
     { key: 'meterMoney', name: '计量金额' },
 ]
+const tableData = ref([])
+
+//获取表格数据
+const tableLoading = ref(true)
+const getTableData = async () => {
+    tableLoading.value = true
+    const { data } = await mainApi.getPage({
+        projectId: projectId.value,
+        contractId: contractId.value,
+        meterPeriodId: ids.value,
+        current: 1,
+        size: 99999,
+        total: 0,
+    })
+    tableData.value = getArrValue(data?.records)
+    tableLoading.value = false
+}
 
 //表格选择
 const tableKeys = ref([])
@@ -154,6 +133,54 @@ const tableCheckChange = (rows) => {
     tableKeys.value = rows
 }
 
+//验证并组装数据
+const validateData = async () => {
+    const table = tableKeys.value
+    if (table.length <= 0) {
+        window.$message.warning('请先勾选材料')
+        return false
+    }
+    const files = formDataFiles.value
+    if (files.length <= 0) {
+        window.$message.warning('请先上传文件')
+        return false
+    }
+    const ids = arrToId(table)
+    const { isRes } = await mainApi.batchImportFile({
+        files: files,
+        materialMeterFormIds: ids,
+        projectId: projectId.value,
+        contractId: contractId.value,
+    })
+    return isRes
+}
+
+//确认并继续
+const confirmLoading = ref(false)
+const confirmTap = async () => {
+    confirmLoading.value = true
+    const isRes = await validateData()
+    confirmLoading.value = false
+    if (!isRes) return
+    window.$message.success('批量导入成功')
+    uploadRef.value?.clearFiles()
+    tableRef.value?.clearSelection()
+    await nextTick()
+    tableKeys.value = []
+    formDataFiles.value = []
+}
+
+//确认并退出
+const confirmClick = async () => {
+    confirmLoading.value = true
+    const isRes = await validateData()
+    confirmLoading.value = false
+    if (!isRes) return
+    window.$message.success('批量导入成功')
+    modalClose()
+    emit('finish')
+}
+
 //关闭弹窗
 const modalClose = () => {
     isShow.value = false
@@ -171,11 +198,12 @@ const modalClose = () => {
 </style>
 
 <style lang="scss">
-.el-overlay-dialog .el-dialog.hc-new-dialog.hc-order-import-upload-file-box .el-dialog__body {
+.el-overlay-dialog .el-dialog.hc-new-dialog.hc-order-batch-import-file-box .el-dialog__body {
     padding: 14px 4px;
 }
 .hc-card-item-box.hc-upload-card-item {
     padding: 10px;
+    margin-top: 24px;
     .hc-card-item-header {
         color: unset;
     }

+ 4 - 3
src/views/debit-pay/material/order.vue

@@ -13,11 +13,11 @@
             </div>
         </template>
         <template #extra>
-            <el-button hc-btn type="primary" @click="importClick">
+            <el-button hc-btn type="primary" :disabled="approveStatus !== 0" @click="importClick">
                 <hc-icon name="upload-cloud" />
                 <span>导入</span>
             </el-button>
-            <el-button hc-btn type="primary" @click="importBatchClick">
+            <el-button hc-btn type="primary" :disabled="approveStatus !== 0" @click="importBatchClick">
                 <hc-icon name="upload-cloud" />
                 <span>附件批量导入</span>
             </el-button>
@@ -126,8 +126,9 @@
 
         <!-- 导入 -->
         <HcImportFile v-model="isImportShow" :ids="searchForm.meterPeriodId" @finish="getTableData" />
+
         <!-- 批量导入 -->
-        <HcBatchImport v-model="importBatchShow" :data="tableData" :ids="searchForm.meterPeriodId" @finish="getTableData" />
+        <HcBatchImport v-model="importBatchShow" :ids="searchForm.meterPeriodId" @finish="getTableData" />
     </hc-new-card>
 </template>