|
@@ -1,38 +1,24 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, h } from "vue";
|
|
|
-import { ElButton, ElDialog, ElMessage,ElMessageBox } from "element-plus";
|
|
|
+import { ref } from "vue";
|
|
|
+import { ElButton, ElDialog, ElMessage } from "element-plus";
|
|
|
import { execlUpload } from "/@/components/execlUpload";
|
|
|
-import { httpBatchAdd } from "/@/api/purchase/ticketReturn";
|
|
|
import { useResponseHandle } from "/@/hooks";
|
|
|
-import { useCompany } from "/@/hooks/core/useCompany";
|
|
|
-import { cg_inv_type_list } from "/@/utils/status";
|
|
|
import { useVModel } from "@vueuse/core";
|
|
|
-import dayjs from "dayjs"
|
|
|
|
|
|
-import {
|
|
|
- initheaders,
|
|
|
- columns,
|
|
|
- mapProp,
|
|
|
- requireHeaders
|
|
|
-} from "./columns-config";
|
|
|
+import { mapLabelToSource, mapLabelToType } from "../../config/shared";
|
|
|
+import { httpAdd } from "/@/api/invoiceInOut/inOutManager";
|
|
|
+import { columns, mapLabelToProp } from "./columns-config";
|
|
|
+import { mapLabelToInvtype } from "/@/utils/status";
|
|
|
+import { isImportDataValid } from "./validator";
|
|
|
|
|
|
|
|
|
const loading = ref(false);
|
|
|
const tableData = ref([]);
|
|
|
|
|
|
+const emit = defineEmits(["refresh"]);
|
|
|
const props = defineProps<{ visible: boolean }>()
|
|
|
-const emit = defineEmits(["onSuccess"]);
|
|
|
-
|
|
|
-const allTypes = cg_inv_type_list.map(({ label }) => label);
|
|
|
-const row = ref(1);
|
|
|
|
|
|
const visible = useVModel(props, 'visible')
|
|
|
-
|
|
|
-const createInvErrorMessage = (row: string) =>
|
|
|
- `导入数据第 ${row} 行 发票类型格式不正确,发票类型必须为${allTypes.join(",")}`;
|
|
|
-
|
|
|
-const { currentCompany } = useCompany();
|
|
|
-
|
|
|
const responseHandle = useResponseHandle();
|
|
|
|
|
|
const Uploadsuccess = ({ results, header }) => {
|
|
@@ -44,12 +30,13 @@ const Uploadsuccess = ({ results, header }) => {
|
|
|
}
|
|
|
|
|
|
let headok = true;
|
|
|
+
|
|
|
if (header.length !== columns.length - 1) {
|
|
|
headok = false;
|
|
|
} else {
|
|
|
columns.slice(1).forEach((si, sii) => {
|
|
|
- if (si.label !== header[sii]) {
|
|
|
- headok = false;
|
|
|
+ if (si.label !== header[sii]) {
|
|
|
+ headok = false;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -62,151 +49,19 @@ const Uploadsuccess = ({ results, header }) => {
|
|
|
|
|
|
tableData.value = [];
|
|
|
|
|
|
- for (const v1 of results) {
|
|
|
- const b = Object.values(v1);
|
|
|
- let model = {};
|
|
|
- b.forEach((si, sii) => { model["value" + sii] = si + ""; });
|
|
|
- tableData.value.push(model);
|
|
|
- row.value = row.value + 1;
|
|
|
- }
|
|
|
-
|
|
|
- const data = [];
|
|
|
- tableData.value.forEach((key, index) => {
|
|
|
- const obj: Record<string, string> = {};
|
|
|
-
|
|
|
- for (let i in key) {
|
|
|
- const prop = mapProp[i];
|
|
|
- const value = key[i];
|
|
|
- obj[prop] = value;
|
|
|
- }
|
|
|
-
|
|
|
- data.push(obj);
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- const typeErrors: string[] = [];
|
|
|
- const checkErrors: string[] = [];
|
|
|
- const codeErrors: string[] = [];
|
|
|
- const numberErrors: string[] = [];
|
|
|
- const priceErrors: string[] = [];
|
|
|
- const fullyElectionicPriceErrors: string[] = [];
|
|
|
-
|
|
|
-
|
|
|
- const openDateErrors: string[] = [];
|
|
|
- const now = dayjs(new Date()).format('YYYY-MM-DD');
|
|
|
-
|
|
|
- data.forEach((row, index) => {
|
|
|
- const source = row.invoiceType.trim();
|
|
|
- const target = cg_inv_type_list.find(({ label }) => label === source);
|
|
|
+ const result = []
|
|
|
+ for(const tableItem of results){
|
|
|
|
|
|
- if (!target) {
|
|
|
- typeErrors.push(String(index + 1));
|
|
|
- } else {
|
|
|
- row.invoiceType = target.value;
|
|
|
+ const item = {}
|
|
|
+ Object.keys(tableItem).forEach(label => {
|
|
|
+ const prop = mapLabelToProp[label]
|
|
|
+ item[prop] = tableItem[label]
|
|
|
+ })
|
|
|
|
|
|
- if (
|
|
|
- (target.value === "normal" || target.value === "electronic") &&
|
|
|
- !row.checkNumber
|
|
|
- ) {
|
|
|
- checkErrors.push(String(index + 1));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const isFullyElectionic = row.invoiceType === 'fully_digitalized_special_electronic' || row.invoiceType === 'fully_digitalized_normal_electronic'
|
|
|
-
|
|
|
- if(!row.open_time || (row.open_time && !dayjs(row.open_time).isSame(dayjs(now)) && !dayjs(row.open_time).isBefore(dayjs(now)))){
|
|
|
- openDateErrors.push(String(index + 1))
|
|
|
- }
|
|
|
-
|
|
|
- const reg = /^\d+(\.\d+)?$/;
|
|
|
-
|
|
|
- if (!reg.test(row.invoiceCode) && !isFullyElectionic) {
|
|
|
- codeErrors.push(String(index + 1));
|
|
|
- }
|
|
|
-
|
|
|
- if (!reg.test(row.invoiceNumber)) {
|
|
|
- numberErrors.push(String(index + 1));
|
|
|
- }
|
|
|
-
|
|
|
- if ((!reg.test(row.inv_subtotal_amount) || Number(row.inv_subtotal_amount) < 0) && !isFullyElectionic) {
|
|
|
- priceErrors.push(String(index + 1));
|
|
|
- }
|
|
|
-
|
|
|
- if ((!reg.test(row.inv_total) || Number(row.inv_total) < 0) && isFullyElectionic) {
|
|
|
- fullyElectionicPriceErrors.push(String(index + 1));
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (typeErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: createInvErrorMessage(typeErrors.join(","))
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (checkErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: `第 ${checkErrors.join(",")} 行,校验码不能为空。`
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- tableData.value = [];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (codeErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: `第 ${codeErrors.join(",")} 行,发票代码必须为数字。`
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- tableData.value = [];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (numberErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: `第 ${numberErrors.join(",")} 行,发票号码必须为数字。`
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- tableData.value = [];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (priceErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: `第 ${priceErrors.join(",")} 行,发票税前金额必须为数字且不能是负数`
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- tableData.value = [];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (fullyElectionicPriceErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: `第 ${fullyElectionicPriceErrors.join(",")} 行,发票税后金额必须为数字且不能是负数`
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- tableData.value = [];
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (openDateErrors.length > 0) {
|
|
|
- ElMessage({
|
|
|
- type: "error",
|
|
|
- message: `第 ${openDateErrors.join(",")} 行,开票日期不能为空且不能超过当前日期`
|
|
|
- });
|
|
|
- loading.value = false;
|
|
|
- tableData.value = [];
|
|
|
- return;
|
|
|
- }
|
|
|
+ result.push(item)
|
|
|
+ }
|
|
|
|
|
|
+ if(isImportDataValid(result)){ tableData.value = result }
|
|
|
loading.value = false;
|
|
|
};
|
|
|
|
|
@@ -215,59 +70,31 @@ const handleSubmit = async () => {
|
|
|
try {
|
|
|
if (loading.value) return;
|
|
|
loading.value = true;
|
|
|
- const data = [];
|
|
|
|
|
|
- tableData.value.forEach((key, index) => {
|
|
|
- const obj: Record<string, string> = {};
|
|
|
-
|
|
|
- for (let i in key) {
|
|
|
- const prop = mapProp[i];
|
|
|
- const value = key[i];
|
|
|
- obj[prop] = value;
|
|
|
- }
|
|
|
- data.push(obj);
|
|
|
- });
|
|
|
-
|
|
|
- data.forEach((row, index) => {
|
|
|
- const source = row.invoiceType.trim();
|
|
|
- const target = cg_inv_type_list.find(({ label }) => label === source);
|
|
|
- row.invoiceType = target.value;
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- const buyers = data.map(({ supplierNo }) => supplierNo);
|
|
|
- const setBuyers = [...new Set(buyers)];
|
|
|
-
|
|
|
- if (setBuyers.length > 1) {
|
|
|
- ElMessage.error("卖方公司编码不一致");
|
|
|
- loading.value = false;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const companyNo = data[0].supplierNo;
|
|
|
-
|
|
|
- if(companyNo != currentCompany.value.companyNo){
|
|
|
- ElMessage.error("卖方公司编码与当前选中的公司不一致");
|
|
|
- loading.value = false;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- data.forEach(item => {
|
|
|
- const isFullyElectionic = item.invoiceType === 'fully_digitalized_special_electronic' || item.invoiceType === 'fully_digitalized_normal_electronic'
|
|
|
- if(isFullyElectionic){ item.inv_subtotal_amount = item.inv_total }
|
|
|
-
|
|
|
- delete item['inv_total']
|
|
|
- delete item["supplierNo"];
|
|
|
- delete item["supplierName"];
|
|
|
- delete item["companyName"];
|
|
|
- delete item["companyNo"];
|
|
|
- });
|
|
|
- const { code, message,data: _d } = await httpBatchAdd({
|
|
|
- list: data,
|
|
|
- companyNo,
|
|
|
- is_comon: '0'
|
|
|
- // relaComNo: currentCompany.value.companyNo
|
|
|
- });
|
|
|
+ const list = [];
|
|
|
+
|
|
|
+ tableData.value.forEach(item => {
|
|
|
+ list.push({
|
|
|
+ ...item,
|
|
|
+ inv_type: mapLabelToInvtype[item.inv_type],
|
|
|
+ source: mapLabelToSource[item.source],
|
|
|
+ type: mapLabelToType[item.type],
|
|
|
+ buyer_name: item.inv_buyer_name,
|
|
|
+ buyer_code: item.inv_buyer_code,
|
|
|
+ platform_type: "1",
|
|
|
+ goodType: "1",
|
|
|
+ channel: "2",
|
|
|
+ relaArr: [{
|
|
|
+ id: item.relaGoodNo,
|
|
|
+ num: item.relaGoodNum
|
|
|
+ }]
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ // console.log(list)
|
|
|
+ // return
|
|
|
+
|
|
|
+ const { code, message,data: _d } = await httpAdd({ list });
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
@@ -277,21 +104,8 @@ const handleSubmit = async () => {
|
|
|
noMessage: false,
|
|
|
handler: () => {
|
|
|
ElMessage.success("数据导入成功!");
|
|
|
- emit("onSuccess");
|
|
|
+ emit("refresh");
|
|
|
visible.value = false;
|
|
|
- },
|
|
|
- onError() {
|
|
|
- if (Number(code) === 10004) {
|
|
|
- ElMessageBox({
|
|
|
- title: '以下对账单不符合要求',
|
|
|
- message: h('div', null, [
|
|
|
- h('p', null, '当前功能仅支持业务类型为采购订单的对账单,以下通用订单类型的对账单不支持该功能:'),
|
|
|
- h('p', null, _d.join('、')),
|
|
|
- ])
|
|
|
- })
|
|
|
- }else {
|
|
|
- ElMessage.warning(message)
|
|
|
- }
|
|
|
}
|
|
|
});
|
|
|
} catch (err) {
|
|
@@ -305,8 +119,8 @@ const cancel = () => {
|
|
|
|
|
|
<template>
|
|
|
<ElDialog
|
|
|
- :close-on-click-modal="false"
|
|
|
v-model="visible"
|
|
|
+ :close-on-click-modal="false"
|
|
|
title="非订单商品导入"
|
|
|
width="1040px"
|
|
|
top="8vh"
|
|
@@ -332,7 +146,7 @@ const cancel = () => {
|
|
|
:key="sii"
|
|
|
>
|
|
|
<template #header>
|
|
|
- <span v-if="!requireHeaders.includes(mapProp[si.prop]) || si.label === '序号' ">
|
|
|
+ <span v-if="!si.required">
|
|
|
{{ si.label }}
|
|
|
</span>
|
|
|
|