|
@@ -8,9 +8,12 @@ import { ElMessage } from "element-plus"
|
|
|
import Modal from "./modal.vue"
|
|
|
import OrderModal from "./order-modal.vue"
|
|
|
|
|
|
+
|
|
|
+const emit = defineEmits(['refresh'])
|
|
|
const props = withDefaults(defineProps<{
|
|
|
code: string;
|
|
|
payNo?: string;
|
|
|
+ invNo?: string;
|
|
|
invNumber: string;
|
|
|
mode?: 'sale' | 'purchase';
|
|
|
}>(),
|
|
@@ -37,27 +40,21 @@ const currentInvoiceItem = computed(() => {
|
|
|
const list = (invoiceDetailTask.data || [])
|
|
|
const item = list[state.index] || {}
|
|
|
const { status, OrderInfo } = item
|
|
|
-
|
|
|
- if(status == '2' || status == '1'){
|
|
|
- orders.value = OrderInfo.map((item) => ({
|
|
|
- id: item.id,
|
|
|
- goodNum: item.num,
|
|
|
- itemId: item.itemId,
|
|
|
- goodNo: item.spuCode,
|
|
|
- sequenceNo: item.code,
|
|
|
- cat_code: item.cat_code,
|
|
|
- cat_name: item.cat_name,
|
|
|
- goodName: item.good_name,
|
|
|
- goodPrice: item.good_price,
|
|
|
- totalPrice: item.total_amount,
|
|
|
- }))
|
|
|
+ if(status == '2' || status == '1'){ refreshOrders(OrderInfo) }
|
|
|
+ return item
|
|
|
+})
|
|
|
|
|
|
- calcTaxAfterAmount()
|
|
|
- }
|
|
|
|
|
|
- return item
|
|
|
+// 判断是否已经关联完了
|
|
|
+const isRelated = computed(() => {
|
|
|
+ const { mode } = props
|
|
|
+ console.log(mode === 'sale' && currentInvoiceItem.value.status != '0', mode, currentInvoiceItem.value.status)
|
|
|
+ if(mode === 'sale' && currentInvoiceItem.value.status != '0') return true
|
|
|
+ if(mode === 'purchase' && currentInvoiceItem.value.status == '1') return true
|
|
|
+ return false
|
|
|
})
|
|
|
|
|
|
+
|
|
|
/* 计算差值 = 当前发票明细总金额 - 订单总金额*/
|
|
|
const difference = computed(() => {
|
|
|
const money = Number(subtraction(currentInvoiceItem.value.total_amount, state.total)).toFixed(2)
|
|
@@ -67,8 +64,28 @@ const difference = computed(() => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+function refreshOrders(orderInfo: any = []) {
|
|
|
+ orders.value = orderInfo.map((item) => ({
|
|
|
+ id: item.id,
|
|
|
+ goodNum: item.num,
|
|
|
+ itemId: item.itemId,
|
|
|
+ goodNo: item.spuCode,
|
|
|
+ sequenceNo: item.code,
|
|
|
+ cat_code: item.cat_code,
|
|
|
+ cat_name: item.cat_name,
|
|
|
+ goodName: item.good_name,
|
|
|
+ goodPrice: item.good_price,
|
|
|
+ balance_amount: item.balance_amount,
|
|
|
+ open_amount: item.total_amount,
|
|
|
+ }))
|
|
|
+
|
|
|
+ calcTaxAfterAmount()
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+// 创建关联
|
|
|
const relationTask = useTask<any>()
|
|
|
+
|
|
|
// 订单相关处理
|
|
|
const orderDetailTask = useTask<any>({ initialData: [], root: false, success({ list = [] } = {}){
|
|
|
orderDetailTask.data = list.map(item => {
|
|
@@ -77,37 +94,45 @@ const orderDetailTask = useTask<any>({ initialData: [], root: false, success({ l
|
|
|
})
|
|
|
calcTaxAfterAmount()
|
|
|
}})
|
|
|
+
|
|
|
+
|
|
|
// 发票明细相关处理
|
|
|
const invoiceDetailTask = useTask<any>({ initialData: [], success(data = []) { state.count = data.length }})
|
|
|
|
|
|
-
|
|
|
+// 解除关联
|
|
|
const unRelationTask = useTask({
|
|
|
- success(){
|
|
|
+ success: async () => {
|
|
|
ElMessage.success('解除成功')
|
|
|
- initialData()
|
|
|
+ // 刷新发票明细
|
|
|
+ await refreshInvoiceDetail()
|
|
|
+ // 刷新绑定的订单信息
|
|
|
+ const item = ((invoiceDetailTask.data || [])[state.index]) || {}
|
|
|
+ const { OrderInfo } = item
|
|
|
+ refreshOrders(OrderInfo)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-const taskState = useTasks(orderDetailTask, invoiceDetailTask, relationTask, unRelationTask)
|
|
|
|
|
|
-const initialData = () => { invoiceDetailTask.run(httpInvoiceDetail({ code: props.code })) }
|
|
|
+const refreshInvoiceDetail = () => invoiceDetailTask.run(httpInvoiceDetail({ code: props.code }))
|
|
|
+const taskState = useTasks(orderDetailTask, invoiceDetailTask, relationTask, unRelationTask)
|
|
|
|
|
|
|
|
|
/* 计算税后金额 */
|
|
|
-const calcTaxAfterAmount = () => state.total = orders.value.reduce((prev, current) => Number(addition(current.totalPrice, prev)).toFixed(2), 0)
|
|
|
-
|
|
|
+const calcTaxAfterAmount = () => state.total = orders.value.reduce((prev, current) => Number(addition(current.open_amount, prev)).toFixed(2), 0)
|
|
|
function onUpdate(data: any, index: number){
|
|
|
modalState.visible = true
|
|
|
modalState.index = index
|
|
|
modalState.data = data
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-function handleOrderItemUpdate(openAmount: number, goodNum: number ,index: number){
|
|
|
- orders.value[index].totalPrice = openAmount
|
|
|
+/** 修改订单项 */
|
|
|
+function handleOrderItemUpdate(open_amount: number, goodNum: number ,index: number){
|
|
|
+ orders.value[index].open_amount = open_amount
|
|
|
orders.value[index].goodNum = goodNum
|
|
|
calcTaxAfterAmount()
|
|
|
}
|
|
|
+
|
|
|
+/** 添加订单项 */
|
|
|
function handleOrderUpdate(list: any[] = []){
|
|
|
const payNos = orders.value.map(({payNo}) => payNo)
|
|
|
const newList = []
|
|
@@ -117,20 +142,31 @@ function handleOrderUpdate(list: any[] = []){
|
|
|
})
|
|
|
|
|
|
orders.value = [...orders.value, ...newList]
|
|
|
- console.log(orders.value)
|
|
|
calcTaxAfterAmount()
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/** 切换到下一条发票明细 */
|
|
|
async function toNext(){
|
|
|
const { money, mode } = difference.value
|
|
|
- if(mode !== 'ok' && props.mode !== 'sale'){
|
|
|
- ElMessage.error(`发票明细税后金额与当前订单税后金额不符,${mode === 'up' ? '超出' : '还差'}:${money} 元`)
|
|
|
+ if(orders.value.length === 0){
|
|
|
+ ElMessage.error(`至少添加一条数据!`)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if(state.total <= 0){
|
|
|
+ ElMessage.error(`金额不能为零!`)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // if(currentInvoiceItem.value.status != '2'){
|
|
|
- const orderArr = orders.value.map(({ goodNo, sequenceNo, goodNum, totalPrice, goodPrice, goodName }) => ({
|
|
|
- total_amount: totalPrice,
|
|
|
+ if(mode !== 'ok' && props.mode !== 'sale' && currentInvoiceItem.value.status != '1'){
|
|
|
+ ElMessage.error(`发票明细税后金额与当前订单税后金额不符,${mode === 'up' ? '超出' : '还差'} ${money} 元`)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!isRelated.value){
|
|
|
+ const orderArr = orders.value.map(({ goodNo, sequenceNo, goodNum, open_amount, goodPrice, goodName }) => ({
|
|
|
+ total_amount: open_amount,
|
|
|
good_price: goodPrice,
|
|
|
good_name: goodName,
|
|
|
code: sequenceNo,
|
|
@@ -140,34 +176,50 @@ async function toNext(){
|
|
|
}))
|
|
|
|
|
|
const itemId = currentInvoiceItem.value.id
|
|
|
- const result = await relationTask.run(httpRelation({ orderArr, itemId }))
|
|
|
+ const result: any = await relationTask.run(httpRelation({ orderArr, itemId }))
|
|
|
|
|
|
if(result.code == '0'){
|
|
|
- orders.value = []
|
|
|
- state.index = state.index + 1
|
|
|
+ if(state.index + 1 === invoiceDetailTask.data.length){
|
|
|
+ emit('refresh')
|
|
|
+ }else{
|
|
|
+ state.total = 0
|
|
|
+ orders.value = []
|
|
|
+ state.index = state.index + 1
|
|
|
+ }
|
|
|
}else{
|
|
|
ElMessage.warning(result.message)
|
|
|
}
|
|
|
-
|
|
|
- // }else{
|
|
|
- // orders.value = []
|
|
|
- // state.index = state.index + 1
|
|
|
- // }
|
|
|
+ }else{
|
|
|
+ if(state.index + 1 === invoiceDetailTask.data.length){
|
|
|
+ emit('refresh')
|
|
|
+ }else{
|
|
|
+ state.total = 0
|
|
|
+ orders.value = []
|
|
|
+ state.index = state.index + 1
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function toPrev(){
|
|
|
+
|
|
|
+//
|
|
|
+async function toPrev(){
|
|
|
state.index = state.index - 1
|
|
|
- const orderAPI = props.mode === 'purchase' ? httpPurchaseOrders : httpPurchaseOrders
|
|
|
- orderDetailTask.run(orderAPI({ payNo: props.code }))
|
|
|
+ // 刷新发票明细
|
|
|
+ await refreshInvoiceDetail()
|
|
|
+ // 刷新绑定的订单信息
|
|
|
+ const item = ((invoiceDetailTask.data || [])[state.index]) || {}
|
|
|
+ const { OrderInfo } = item
|
|
|
+ refreshOrders(OrderInfo)
|
|
|
}
|
|
|
|
|
|
|
|
|
const onUnRelation = ({ id }) => unRelationTask.run(httpUnRelation({ id }))
|
|
|
|
|
|
-watch(() => props.invNumber, () => {
|
|
|
- if(!props.invNumber) return
|
|
|
- initialData()
|
|
|
-}, {
|
|
|
+
|
|
|
+watch(() => props.code, () => {
|
|
|
+ if(!props.code) return
|
|
|
+ refreshInvoiceDetail()
|
|
|
+},{
|
|
|
immediate: true
|
|
|
})
|
|
|
</script>
|
|
@@ -181,9 +233,11 @@ watch(() => props.invNumber, () => {
|
|
|
<ElButton @click="toPrev" :icon="useRenderIcon('arrow-left-s-line')" />
|
|
|
</ElTooltip>
|
|
|
|
|
|
- <ElTooltip content="下一条" placement="top">
|
|
|
+ <ElTooltip content="下一条" placement="top" v-if="state.index + 1 !== invoiceDetailTask.data.length">
|
|
|
<ElButton @click="toNext" :icon="useRenderIcon('arrow-right-s-line')" />
|
|
|
- </ElTooltip>
|
|
|
+ </ElTooltip>
|
|
|
+
|
|
|
+ <ElButton v-else @click="toNext">提交</ElButton>
|
|
|
</ElButtonGroup>
|
|
|
</div>
|
|
|
|
|
@@ -195,34 +249,40 @@ watch(() => props.invNumber, () => {
|
|
|
<ElTableColumn label="税率" prop="tax" width="80px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="税额" prop="tax_amount" width="80px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="税后总额" prop="total_amount" width="120px" show-overflow-tooltip />
|
|
|
- <ElTableColumn label="发票明细类目名称" prop="cat_code" min-width="140px" show-overflow-tooltip />
|
|
|
- <ElTableColumn label="发票明细类目编号" prop="cat_name" min-width="140px" show-overflow-tooltip />
|
|
|
+ <ElTableColumn label="发票明细类目编号" prop="cat_code" min-width="140px" show-overflow-tooltip />
|
|
|
+ <ElTableColumn label="发票明细类目名称" prop="cat_name" min-width="140px" show-overflow-tooltip />
|
|
|
</ElTable>
|
|
|
|
|
|
<div class="flex justify-between my-[10px]">
|
|
|
- <p>当前发票明细税后金额为:{{ currentInvoiceItem.total_amount }} 元,当前订单税后金额为 {{state.total}} 元,
|
|
|
- <span :style="`${difference.mode !== 'ok' ? 'color:red' : ''}`">
|
|
|
- {{ difference.mode === 'up' ? '超出' : '还差' }} {{ difference.money }} 元
|
|
|
- </span>
|
|
|
+ <p>当前发票明细税后金额为:{{ currentInvoiceItem.total_amount }} 元,
|
|
|
+ <template v-if="!isRelated">
|
|
|
+ 当前订单税后金额为 {{state.total}} 元,
|
|
|
+ <span :style="`${difference.mode !== 'ok' ? 'color:red' : ''}`">
|
|
|
+ {{ difference.mode === 'up' ? '超出' : '还差' }} {{ difference.money }} 元
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ 已关联完成。
|
|
|
+ </template>
|
|
|
</p>
|
|
|
</div>
|
|
|
|
|
|
<ElTable class="mb-[50px]" border size="small" :data="orders">
|
|
|
<ElTableColumn type="index" label="序号" width="60px" />
|
|
|
- <ElTableColumn label="采购单编号" prop="sequenceNo" width="160px" show-overflow-tooltip />
|
|
|
+ <ElTableColumn :label="`${mode === 'sale' ? '采购单' : '销售单'}编号`" prop="sequenceNo" width="160px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="商品编号" prop="goodNo" width="160px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="商品名称" prop="goodName" min-width="160px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="订单商品类目编号" prop="cat_code" min-width="140px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="订单商品类目名称" prop="cat_name" min-width="140px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="数量" prop="goodNum" width="80px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="单价" prop="goodPrice" width="80px" show-overflow-tooltip />
|
|
|
- <ElTableColumn label="开票金额" prop="totalPrice" width="120px" show-overflow-tooltip />
|
|
|
+ <ElTableColumn label="未关联金额" prop="balance_amount" width="80px" show-overflow-tooltip />
|
|
|
+ <ElTableColumn label="开票金额" prop="open_amount" width="120px" show-overflow-tooltip />
|
|
|
<ElTableColumn label="操作" width="80px" fixed="right">
|
|
|
<template #header>
|
|
|
<div class="flex justify-between items-center">
|
|
|
<p>操作</p>
|
|
|
- <!-- v-if="currentInvoiceItem.status != '2'" -->
|
|
|
- <ElTooltip content="添加采购单" placement="top">
|
|
|
+ <ElTooltip content="添加采购单" placement="top" v-if="!isRelated">
|
|
|
<ElButton
|
|
|
link
|
|
|
type="primary"
|
|
@@ -234,24 +294,17 @@ watch(() => props.invNumber, () => {
|
|
|
</template>
|
|
|
|
|
|
<template #="{ row, $index }">
|
|
|
- <!-- <ElTooltip content="解除关联" placement="top" v-if="currentInvoiceItem.status == '2'">
|
|
|
- <ElButton type="primary" link :icon="useRenderIcon('delete')" @click="onDelete(row)" />
|
|
|
- </ElTooltip> -->
|
|
|
-
|
|
|
<ElPopconfirm
|
|
|
title="是否确认解除关联?"
|
|
|
- v-if="currentInvoiceItem.status == '2'"
|
|
|
@confirm="onUnRelation(row)"
|
|
|
+ v-if="isRelated"
|
|
|
>
|
|
|
<template #reference>
|
|
|
<ElButton type="primary" link :icon="useRenderIcon('delete')" />
|
|
|
</template>
|
|
|
</ElPopconfirm>
|
|
|
|
|
|
-
|
|
|
- <!-- v-if="currentInvoiceItem.status != '2'" -->
|
|
|
-
|
|
|
- <ElTooltip content="修改" placement="top" >
|
|
|
+ <ElTooltip content="修改" placement="top" v-if="!isRelated">
|
|
|
<ElButton type="primary" link :icon="useRenderIcon('edits')" @click="onUpdate(row, $index)" />
|
|
|
</ElTooltip>
|
|
|
</template>
|
|
@@ -270,6 +323,8 @@ watch(() => props.invNumber, () => {
|
|
|
v-model:visible="orderModalVisible"
|
|
|
@confirm="handleOrderUpdate"
|
|
|
:payNo="payNo"
|
|
|
+ :invNo="invNo"
|
|
|
+ :mode="mode"
|
|
|
/>
|
|
|
</div>
|
|
|
</template>
|