|
|
|
@ -97,7 +97,7 @@
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { onMounted, ref, reactive, watch, defineExpose, defineProps, defineEmits, h } from 'vue'
|
|
|
|
|
import { BasicTable, useTable } from '/@/components/Table'
|
|
|
|
|
import { GetBizList, BizSave } from '../../api'
|
|
|
|
|
import { GetBizList, GetCurrencies, BizSave } from '../../api'
|
|
|
|
|
import { businessColumns, searchFormSchema, currencyFormSchema } from '../columns'
|
|
|
|
|
import feeTable from '/@/components/CostEntry/components/feeTable.vue'
|
|
|
|
|
import { BasicForm, useForm } from '/@/components/Form'
|
|
|
|
@ -184,13 +184,13 @@
|
|
|
|
|
const allFeeData = {}
|
|
|
|
|
const feeTabel = ref(null)
|
|
|
|
|
const historyChange = async (v) => {
|
|
|
|
|
console.log(v)
|
|
|
|
|
if (v.length > 1) {
|
|
|
|
|
const a = getDataSource().filter(item => {
|
|
|
|
|
return item.id == v[0]
|
|
|
|
|
console.log(getDataSource())
|
|
|
|
|
const a = getDataSource().filter((item, index) => {
|
|
|
|
|
return item.id + index == v[0]
|
|
|
|
|
})[0]
|
|
|
|
|
const b = getDataSource().filter(item => {
|
|
|
|
|
return item.id == v[v.length - 1]
|
|
|
|
|
const b = getDataSource().filter((item, index) => {
|
|
|
|
|
return item.id + index == v[v.length - 1]
|
|
|
|
|
})[0]
|
|
|
|
|
if (a.customerId != b.customerId) {
|
|
|
|
|
return createMessage.warning('请选择结算对象一致的数据!')
|
|
|
|
@ -237,6 +237,9 @@
|
|
|
|
|
return createMessage.warning('结算对象与付费申请客户不一致,不能添加此费用明细!')
|
|
|
|
|
}
|
|
|
|
|
if (currency) {
|
|
|
|
|
props.setFieldsValue({
|
|
|
|
|
currency
|
|
|
|
|
})
|
|
|
|
|
// 汇率换算申请
|
|
|
|
|
let currencyList = []
|
|
|
|
|
// 过滤出所有跟业务币别不一致的币别
|
|
|
|
@ -256,92 +259,173 @@
|
|
|
|
|
return currencyList.find(item => item.currency === currency)
|
|
|
|
|
})
|
|
|
|
|
// 币别不同触发换算
|
|
|
|
|
exchangeRate.value.init(currency, currencyList)
|
|
|
|
|
exchangeRate.value.init(currency, currencyList, '1')
|
|
|
|
|
} else {
|
|
|
|
|
// 原币申请
|
|
|
|
|
emit('save', feeTableData.value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 保存填写汇率并提交
|
|
|
|
|
const saveExchangeRate = (list) => {
|
|
|
|
|
feeTableData.value.forEach(row => {
|
|
|
|
|
list.forEach(item => {
|
|
|
|
|
if (row.currency == item.currency) {
|
|
|
|
|
row.exchangeRate = item.value
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
emit('save', feeTableData.value)
|
|
|
|
|
}
|
|
|
|
|
// 按业务添加费用申请
|
|
|
|
|
const addInfos = () => {
|
|
|
|
|
const selectRows = getSelectRows()
|
|
|
|
|
if (props.formData.customerId) {
|
|
|
|
|
let flag = false
|
|
|
|
|
selectRows.forEach(item => {
|
|
|
|
|
if (item.customerId == props.formData.customerId) {
|
|
|
|
|
flag = true
|
|
|
|
|
}
|
|
|
|
|
const saveExchangeRate = (data) => {
|
|
|
|
|
if (data.type == '1') {
|
|
|
|
|
// 按费用明细保存
|
|
|
|
|
feeTableData.value.forEach(row => {
|
|
|
|
|
data.list.forEach(item => {
|
|
|
|
|
if (row.currency == item.currency) {
|
|
|
|
|
row.exchangeRate = item.value
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
if (!flag) {
|
|
|
|
|
return createMessage.warning('没有选择要添加的业务!')
|
|
|
|
|
}
|
|
|
|
|
emit('save', feeTableData.value)
|
|
|
|
|
} else {
|
|
|
|
|
if (state.historyRowKeys.length == 0 ) {
|
|
|
|
|
return createMessage.warning('没有选择要添加的业务!')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!props.formData.currency) {
|
|
|
|
|
// 原币申请
|
|
|
|
|
const postData = {
|
|
|
|
|
description: '按业务增加添加费用明细',
|
|
|
|
|
application: {
|
|
|
|
|
id: 0,
|
|
|
|
|
customerId: selectRows[0]?.customerId
|
|
|
|
|
},
|
|
|
|
|
items: [{
|
|
|
|
|
id: selectRows[0]?.id,
|
|
|
|
|
businessType: selectRows[0]?.businessType,
|
|
|
|
|
customerId: selectRows[0]?.customerId
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
// 按业务申请
|
|
|
|
|
const currencyConf = {}
|
|
|
|
|
data.list.forEach(item => {
|
|
|
|
|
currencyConf[item.currency] = item.value
|
|
|
|
|
})
|
|
|
|
|
bPostData.value.items.forEach(item => {
|
|
|
|
|
item.exchangeRates.forEach(row => {
|
|
|
|
|
row.exchangeRate = currencyConf[row.currency]
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
loading.value = true
|
|
|
|
|
BizSave(postData).then(res => {
|
|
|
|
|
BizSave(bPostData.value).then(res => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
if (res.succeeded) {
|
|
|
|
|
createMessage.success('增加成功!')
|
|
|
|
|
emit('refresh')
|
|
|
|
|
createMessage.success('添加成功!')
|
|
|
|
|
emit('refresh', res.data.id)
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 转换汇率申请
|
|
|
|
|
// 合并所有选择过的费用明细
|
|
|
|
|
let feeList = []
|
|
|
|
|
for(var key in allFeeData) {
|
|
|
|
|
feeList = [...feeList, ...allFeeData[key]]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 按业务申请提交数据
|
|
|
|
|
const bPostData = ref(null)
|
|
|
|
|
// 按业务添加费用申请
|
|
|
|
|
const addInfos = async () => {
|
|
|
|
|
const selectRows = getSelectRows()
|
|
|
|
|
// 主单是否有币别
|
|
|
|
|
const currency = getFieldsValue().currency
|
|
|
|
|
if (selectRows.length == 0) {
|
|
|
|
|
return createMessage.warning('没有选择要添加的业务!')
|
|
|
|
|
}
|
|
|
|
|
const postData = {
|
|
|
|
|
description: '按业务提交申请单',
|
|
|
|
|
application: getFieldsValue(),
|
|
|
|
|
items: []
|
|
|
|
|
}
|
|
|
|
|
const postCurrency = selectRows.map(item => {
|
|
|
|
|
return {
|
|
|
|
|
id: item.id,
|
|
|
|
|
businessType: item.businessType,
|
|
|
|
|
customerId: item.customerId
|
|
|
|
|
}
|
|
|
|
|
// 汇率换算申请
|
|
|
|
|
})
|
|
|
|
|
const items = await GetCurrencies(postCurrency).then(res => {
|
|
|
|
|
return res.data
|
|
|
|
|
})
|
|
|
|
|
postData.items = items
|
|
|
|
|
// 判断是是否是原币申请
|
|
|
|
|
if (currency) {
|
|
|
|
|
// 非原币申请
|
|
|
|
|
props.setFieldsValue({
|
|
|
|
|
currency
|
|
|
|
|
})
|
|
|
|
|
// 所有币别集合
|
|
|
|
|
let currencyList = []
|
|
|
|
|
// 过滤出所有跟业务币别不一致的币别
|
|
|
|
|
feeList.forEach((item, index) => {
|
|
|
|
|
if (item.currency != props.formData.currency) {
|
|
|
|
|
currencyList.push({
|
|
|
|
|
currency: item.currency,
|
|
|
|
|
feeType: item.feeType,
|
|
|
|
|
// 正向汇率
|
|
|
|
|
value: null,
|
|
|
|
|
// 逆向汇率
|
|
|
|
|
value1: null
|
|
|
|
|
items.forEach(item => {
|
|
|
|
|
if (item.exchangeRates) {
|
|
|
|
|
item.exchangeRates.forEach(c => {
|
|
|
|
|
if(c.currency != currency) {
|
|
|
|
|
currencyList.push({
|
|
|
|
|
currency: c.currency
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
currencyList = Array.from(new Set(currencyList.map(item => item.currency))).map(currency => {
|
|
|
|
|
return currencyList.find(item => item.currency === currency)
|
|
|
|
|
})
|
|
|
|
|
// 币别不同触发换算
|
|
|
|
|
feeTableData.value = feeList
|
|
|
|
|
exchangeRate.value.init(props.formData.currency, currencyList)
|
|
|
|
|
bPostData.value = postData
|
|
|
|
|
console.log(currencyList)
|
|
|
|
|
if (currencyList.length == 0) {
|
|
|
|
|
// 原币申请
|
|
|
|
|
BizSave(postData).then(res => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
if (res.succeeded) {
|
|
|
|
|
createMessage.success('添加成功!')
|
|
|
|
|
emit('refresh', res.data.id)
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
exchangeRate.value.init(currency, currencyList, '2')
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 原币申请
|
|
|
|
|
BizSave(postData).then(res => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
if (res.succeeded) {
|
|
|
|
|
createMessage.success('添加成功!')
|
|
|
|
|
emit('refresh', res.data.id)
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// if (!props.formData.currency) {
|
|
|
|
|
// // 原币申请
|
|
|
|
|
// const postData = {
|
|
|
|
|
// description: '按业务增加添加费用明细',
|
|
|
|
|
// application: {
|
|
|
|
|
// id: 0,
|
|
|
|
|
// customerId: selectRows[0]?.customerId
|
|
|
|
|
// },
|
|
|
|
|
// items: [{
|
|
|
|
|
// id: selectRows[0]?.id,
|
|
|
|
|
// businessType: selectRows[0]?.businessType,
|
|
|
|
|
// customerId: selectRows[0]?.customerId
|
|
|
|
|
// }]
|
|
|
|
|
// }
|
|
|
|
|
// loading.value = true
|
|
|
|
|
// BizSave(postData).then(res => {
|
|
|
|
|
// loading.value = false
|
|
|
|
|
// if (res.succeeded) {
|
|
|
|
|
// createMessage.success('增加成功!')
|
|
|
|
|
// emit('refresh', res.data.id)
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// } else {
|
|
|
|
|
// // 转换汇率申请
|
|
|
|
|
// let feeList = []
|
|
|
|
|
// for(var key in allFeeData) {
|
|
|
|
|
// feeList = [...feeList, ...allFeeData[key]]
|
|
|
|
|
// }
|
|
|
|
|
// // 汇率换算申请
|
|
|
|
|
// let currencyList = []
|
|
|
|
|
// // 过滤出所有跟业务币别不一致的币别
|
|
|
|
|
// feeList.forEach((item, index) => {
|
|
|
|
|
// if (item.currency != props.formData.currency) {
|
|
|
|
|
// currencyList.push({
|
|
|
|
|
// currency: item.currency,
|
|
|
|
|
// feeType: item.feeType,
|
|
|
|
|
// // 正向汇率
|
|
|
|
|
// value: null,
|
|
|
|
|
// // 逆向汇率
|
|
|
|
|
// value1: null
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// currencyList = Array.from(new Set(currencyList.map(item => item.currency))).map(currency => {
|
|
|
|
|
// return currencyList.find(item => item.currency === currency)
|
|
|
|
|
// })
|
|
|
|
|
// // 币别不同触发换算
|
|
|
|
|
// feeTableData.value = feeList
|
|
|
|
|
// exchangeRate.value.init(props.formData.currency, currencyList)
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
watch(
|
|
|
|
|
() => state.historyRowKeys, (v, old) => {
|
|
|
|
|