<template>
|
<div class="apply-info">
|
<SectionTitle title="补开发票信息"></SectionTitle>
|
<div class="middle-button" v-if="isEdit">
|
<el-button
|
type="primary"
|
@click="addRecord"
|
icon="el-icon-circle-plus-outline"
|
size="small"
|
>新增发票</el-button>
|
</div>
|
<CommTable
|
:list="list"
|
:header="tableHeader"
|
@doAction="doAction"
|
@updateValue="updateValue"
|
ref="fillTable"
|
></CommTable>
|
<Dialog
|
v-model="isShowDel"
|
title="删除确认"
|
:buttons="[{text: '取消'}, {text: '确定', type: 'primary'}]"
|
@handleClick="doDel"
|
>
|
<!-- <p class="del-id">{{tempRecord.serialNo || ''}}</p> -->
|
<p class="del-id">请确认是否删除该笔记录?</p>
|
</Dialog>
|
|
<Dialog
|
v-model="isShowSucc"
|
icon="succ"
|
iconText="提交成功"
|
:close="false"
|
:buttons="[{text: '确定', type: 'primary'}]"
|
@handleClick="sureSucc"
|
></Dialog>
|
</div>
|
</template>
|
<script>
|
// 补开发票信息
|
import { mapState, mapActions } from 'vuex'
|
import CommTable from '@/components/CommTable'
|
import Dialog from '@/components/Dialog'
|
import SectionTitle from '@/components/SectionTitle'
|
import queryFillOpenInvoiceInfo from '@/controller/queryFillOpenInvoiceInfo'
|
import saveFillOpenInvoice from '@/controller/saveFillOpenInvoice'
|
import delFillOpenInvoice from '@/controller/delFillOpenInvoice'
|
import invoiceAdjustSubmit from '@/controller/invoiceAdjustSubmit'
|
|
const addButtons = [
|
{ text: '取消', prop: 'cancleButton' },
|
{ text: '保存', prop: 'addButton' }
|
]
|
|
const normalButtons = [{ text: '删除', prop: 'deleteButton' }]
|
|
export default {
|
components: {
|
CommTable,
|
SectionTitle,
|
Dialog
|
},
|
props: {
|
conf: {
|
type: Object,
|
default: () => ({})
|
}
|
},
|
data() {
|
return {
|
isShowDel: false,
|
isShowSucc: false,
|
tableHeader: [],
|
model: null,
|
addModel: null,
|
delModel: null,
|
submitModel: null,
|
list: [],
|
pageInfo: {
|
currentPage: 1,
|
pageSize: 10
|
},
|
total: 0,
|
isDoingAdd: false,
|
currentIndex: 0,
|
records: [],
|
tempRecord: {}
|
}
|
},
|
created() {
|
this.init()
|
},
|
methods: {
|
init() {
|
const { $route, isEdit } = this
|
const { query } = $route
|
this.query = query
|
const model = queryFillOpenInvoiceInfo()
|
const tableHeader = model.getTableList()
|
this.delModel = delFillOpenInvoice()
|
this.tableHeader = isEdit
|
? tableHeader
|
: tableHeader.filter(({ type }) => type !== 'buttons')
|
this.model = model
|
this.addModel = saveFillOpenInvoice()
|
this.submitModel = invoiceAdjustSubmit()
|
this.getList()
|
},
|
async getList() {
|
const { model, query, pageInfo } = this
|
const { invoiceSerialno } = query
|
const { list = [] } = await model.request({
|
...pageInfo,
|
invoiceSerialno
|
})
|
this.list = list.map(item => ({
|
...item,
|
action: {
|
buttons: normalButtons
|
}
|
}))
|
this.tempRecord = {}
|
// this.total = parseInt(total)
|
},
|
|
// 新增
|
addRecord() {
|
const { isDoingAdd, list } = this
|
if (isDoingAdd) {
|
return false
|
}
|
this.list = [{ ...this.getEditRecord() }, ...list]
|
this.currentIndex = 0
|
this.isDoingAdd = true
|
},
|
|
getEditRecord() {
|
const { tableHeader, invoiceInfo, addModel } = this
|
const { invoiceSeller = '', invoiceBuyer = '' } = invoiceInfo
|
const formList = addModel.getFormList({ invoiceSeller, invoiceBuyer })
|
return tableHeader.reduce((pre, { prop, isMoney = false }) => {
|
if (prop === 'action') {
|
pre[prop] = {
|
buttons: addButtons
|
}
|
} else {
|
const inputItem = formList.find(({ name }) => name === prop)
|
if (inputItem) {
|
pre[prop] = { value: '', ...inputItem }
|
}
|
}
|
return pre
|
}, {})
|
},
|
|
updateValue(val, inputItem, parentName, recordIndex = 0) {
|
const { list } = this
|
const { name } = inputItem
|
const listItem = list[recordIndex]
|
const key = Object.keys(listItem).find(k => k === name)
|
this.$set(list, recordIndex, {
|
...listItem,
|
[key]: { ...listItem[key], value: val }
|
})
|
},
|
|
// 表格按钮事件处理
|
doAction(item, record, index) {
|
const { prop } = item
|
this.currentIndex = index
|
if (prop === 'deleteButton') {
|
this.tempRecord = { ...record }
|
this.isShowDel = true
|
}
|
if (prop === 'cancleButton') {
|
this.cancle()
|
}
|
if (prop === 'addButton') {
|
this.toSubmit()
|
}
|
},
|
|
async toSubmit() {
|
const { list, currentIndex, query, addModel, info } = this
|
const { invoiceSerialno } = query
|
const { unRelativeAmount = 0 } = info
|
const [err, values] = this.$refs.fillTable.validate(list[currentIndex])
|
if (err) {
|
this.$message.warning(err)
|
} else {
|
const unAmount = Math.abs(unRelativeAmount)
|
if (Number(values.invoiceAmt) > unAmount) {
|
// 财务开票阶段 提交时,当新增关联信息、删除关联信息、补开发票新增、删除
|
// 均需要刷新开票基本信息, 当开票金额> 申请开票金额 则提示 开票金额不能大于申请开票金额
|
this.$message.warning(
|
`开票金额不能大于未关联贴息金额 ${unAmount || ''}`
|
)
|
return false
|
}
|
|
await addModel.request({
|
invoiceSerialno,
|
...values
|
})
|
this.updateInfo()
|
this.isShowSucc = true
|
}
|
},
|
|
async submit() {
|
const { query, submitModel } = this
|
const { invoiceSerialno, fromButton } = query
|
if (fromButton === 'invoiceAdjustButton') {
|
await submitModel.request({
|
invoiceSerialno
|
})
|
this.isShowSucc = true
|
this.currentIndex = -1
|
this.updateInfo()
|
}
|
},
|
|
doDel(index) {
|
if (index === 0) {
|
this.isShowDel = false
|
} else {
|
this.toDel()
|
}
|
},
|
|
cancle() {
|
const { list } = this
|
this.list = list.filter((item, index) => index > 0)
|
this.isDoingAdd = false
|
},
|
|
sureSucc() {
|
const { currentIndex } = this
|
this.isShowSucc = false
|
if (currentIndex === -1) {
|
this.commitSuccess()
|
} else {
|
this.isDoingAdd = false
|
this.getList()
|
}
|
},
|
|
// 更新开票基本信息
|
updateInfo() {
|
const { transCode, invoiceSerialno } = this.query
|
this.queryBaseDiscountInvoiceInfo({
|
transCode,
|
invoiceSerialno
|
})
|
},
|
|
// 提交成功后返回原列表页
|
commitSuccess() {
|
this.$router.go(-1)
|
},
|
|
async toDel() {
|
const { tempRecord, delModel } = this
|
await delModel.request({
|
serialNo: tempRecord.serialNo
|
})
|
this.isShowDel = false
|
this.isShowSucc = true
|
this.updateInfo()
|
},
|
...mapActions(['queryBaseDiscountInvoiceInfo'])
|
},
|
computed: {
|
isEdit() {
|
const { conf } = this
|
return conf.edit === 'Y'
|
},
|
...mapState({
|
invoiceAmount: state => state.tabsModule.invoiceAmount,
|
invoiceInfo: state => state.tabsModule.invoiceInfo,
|
info: state => state.tabsModule.baseDiscountInvoiceInfo
|
})
|
},
|
watch: {
|
$route() {
|
const { invoiceSerialno } = this.$route.query
|
if (invoiceSerialno) {
|
this.init()
|
}
|
}
|
}
|
}
|
</script>
|
<style lang="postcss" scoped>
|
.middle-button {
|
margin-bottom: 20px;
|
}
|
.del-id {
|
text-align: center;
|
padding-bottom: 20px;
|
}
|
</style>
|