<template>
|
<div class="apply-info">
|
<CommForm
|
:inline="true"
|
:list="formList"
|
@updateValue="updateValue"
|
ref="applyForm"
|
:formValues="formValues"
|
:formRules="formRules"
|
:conf="conf"
|
formType="info"
|
title="开票基本信息"
|
></CommForm>
|
<Dialog
|
v-model="isShowDialog"
|
icon="succ"
|
:iconText="`${isSave ? '保存' : '提交'}成功`"
|
:buttons="[{text: '确定', type: 'primary'}]"
|
@handleClick="commitSuccess"
|
></Dialog>
|
|
<el-dialog
|
:visible.sync="dialogTableVisible"
|
custom-class="comm-dialog"
|
:modal-append-to-body="false"
|
width="940px"
|
>
|
<Enterprise @checkedItem="checkedItem"></Enterprise>
|
</el-dialog>
|
</div>
|
</template>
|
<script>
|
// 开票基本信息
|
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
|
import CommForm from '@/components/CommForm'
|
import Dialog from '@/components/Dialog'
|
import Enterprise from '@/components/Enterprise'
|
import queryCodeValueList from '@/controller/queryCodeValueList'
|
import submitDiscountInvoice from '@/controller/submitDiscountInvoice'
|
import saveDiscountInvoice from '@/controller/saveDiscountInvoice'
|
import queryCodeObject from '@/controller/queryCodeObject'
|
|
export default {
|
components: {
|
CommForm,
|
Dialog,
|
Enterprise
|
},
|
props: {
|
conf: {
|
type: Object,
|
default: () => ({})
|
}
|
},
|
data() {
|
return {
|
query: {},
|
formList: [],
|
bankCodeObjectList: [],
|
model: null,
|
saveModel: null,
|
selectModel: null,
|
isSave: false,
|
isInit: false,
|
isShowDialog: false,
|
dialogTableVisible: false
|
}
|
},
|
created() {
|
this.init()
|
},
|
methods: {
|
init() {
|
const { $route } = this
|
const { query } = $route
|
// const { edit } = conf
|
const { pageId, transCode } = query
|
this.query = query
|
this.pageId = pageId
|
this.selectModel = queryCodeValueList()
|
this.model = submitDiscountInvoice({ pageId, transCode })
|
this.codeModel = queryCodeObject('PutOutAccountType')
|
this.saveModel = saveDiscountInvoice()
|
this.getInfo()
|
// taxpayerIdentifier
|
},
|
getInfo() {
|
const { query } = this
|
const { transCode, invoiceSerialno } = query
|
this.queryBaseDiscountInvoiceInfo({
|
transCode,
|
invoiceSerialno
|
})
|
},
|
async getDetail() {
|
const { info, mixInfo } = this
|
// const { fromButton } = query
|
if (Object.keys(info).length > 0) {
|
this.setEnterpriseInfo(mixInfo)
|
this.setInvoiceInfo(mixInfo)
|
this.setInvoiceAmount(mixInfo.applyMoney)
|
this.setForm()
|
// if (fromButton !== 'invoiceAdjustButton') {
|
// this.setInvoiceInfo(mixInfo)
|
// this.setInvoiceAmount(mixInfo.applyMoney)
|
// }
|
}
|
},
|
|
setForm() {
|
const { model, conf, mixInfo } = this
|
const formList = model.getFormList(mixInfo)
|
const { edit } = conf
|
if (edit === 'Y') {
|
this.formList = formList
|
this.setSelectOptions()
|
} else {
|
this.formList = formList.map(item =>
|
item.type === 'customer' ? { ...item, type: 'input' } : item
|
)
|
}
|
},
|
|
// 更新表单数据
|
updateValue(index, info, flg = true) {
|
const { formList, formValues } = this
|
if (isNaN(index)) {
|
// index is name
|
index = formList.findIndex(({ name }) => name === index)
|
}
|
|
if (!isNaN(index) && index > -1) {
|
const preInfo = formList[index]
|
if (flg && preInfo.name === 'enterpriseName') {
|
this.dialogTableVisible = true
|
return false
|
}
|
this.setInvoiceInfo({ ...formValues, [info.name]: info.value })
|
this.$set(formList, index, { ...preInfo, ...info })
|
}
|
},
|
|
setFetch(info) {
|
const { timmer } = this
|
clearTimeout(timmer)
|
this.timmer = setTimeout(() => {
|
this.getMoneyInfo(info)
|
}, 500)
|
},
|
|
// 选择合作商
|
checkedItem(item) {
|
this.setEnterpriseInfo(item)
|
this.updateCheckedInfo()
|
this.dialogTableVisible = false
|
},
|
|
// 选择合作商后更新数据
|
updateCheckedInfo() {
|
const updateKeys = [
|
'enterpriseName',
|
// 'enterprise',
|
'invoiceBuyer',
|
'contactsName',
|
'contactsPhone',
|
'mailingAddress',
|
'taxpayerIdentifier',
|
'taxpayerBankCode',
|
'taxpayerAccount',
|
'taxpayerPhone',
|
'taxpayerAddress'
|
]
|
const { enterpriseInfo, formList, formValues } = this
|
console.log('enterpriseInfo',enterpriseInfo)
|
const mixInfo = {
|
invoiceBuyer: enterpriseInfo.enterpriseName,
|
taxpayerIdentifier: enterpriseInfo.taxPayerNo,
|
...enterpriseInfo
|
}
|
let mixState = {}
|
updateKeys.forEach(key => {
|
const index = formList.findIndex(({ name }) => name === key)
|
if (index > -1) {
|
mixState[key] = mixInfo[key] || ''
|
this.$set(formList, index, {
|
...formList[index],
|
value: mixInfo[key] || ''
|
})
|
}
|
})
|
this.setInvoiceInfo({ ...formValues, ...mixState })
|
},
|
|
// 表单按钮事件处理
|
async submit(isSave = 0) {
|
const { model, query, info, conf, pageId } = this
|
const { transCode, invoiceSerialno } = query
|
const { edit } = conf
|
if (edit !== 'Y' || ['101', '102'].includes(pageId)) {
|
return false
|
}
|
this.isSave = false
|
|
if (isSave === 1) {
|
this.toSave()
|
this.isSave = true
|
return false
|
}
|
|
const values = this.$refs.applyForm.validate()
|
if (Number(values.applyMoney) <= 0) {
|
this.$message.warning('申请开票金额不能小于等于0')
|
return
|
}
|
|
if (values) {
|
// const loading = this.$loading({
|
// fullscreen: true
|
// })
|
try {
|
await model.request({
|
...info,
|
transCode,
|
invoiceSerialno,
|
...values
|
})
|
// loading.close()
|
// this.getDetail()
|
this.isShowDialog = true
|
} catch (e) {
|
// loading.close()
|
}
|
} else {
|
this.$message.warning('当前页面存在必填项未录入或数据录入错误,请检查!')
|
}
|
},
|
|
async toSave() {
|
const { query, info, formValues, saveModel } = this
|
const { transCode, invoiceSerialno } = query
|
try {
|
await saveModel.request({
|
...info,
|
transCode,
|
invoiceSerialno,
|
...formValues
|
})
|
this.isShowDialog = true
|
this.getInfo()
|
} catch (e) {}
|
},
|
|
// 设置表单下拉菜单
|
setSelectOptions() {
|
const { formList } = this
|
// -- 开票类型 VatinvoiceType 发票邮寄方式 InvoiceTake 项目类型 ZYorSH 纳税人开户行 BankCode 贴息类型 DiscountWay 开票状态 InvoiceFlag 回款状态 InvoiceReceivableStatus 贴息开票状态 DiscountInvoiceStatus
|
// -- 期限单位 TermUnit 贴利息类型、贴手续费类型、贴平台服务费类型、贴担保费类型 DiscountType01 提前还款额外贴息计算方式 PrepaymentCode
|
const selectKeys = {
|
invoiceType: 'VatinvoiceType', // 开票类型
|
orderWay: 'InvoiceTake'
|
}
|
formList.forEach(({ name }) => {
|
if (selectKeys[name]) {
|
this.queryCodeValueList(name, selectKeys[name])
|
}
|
|
if (name === 'taxpayerBankCode') {
|
this.getCodeObject(name, 'BankCode')
|
}
|
})
|
},
|
|
// 获取select中options数据
|
async queryCodeValueList(name, codeNo = '') {
|
const tempModel = queryCodeValueList()
|
const { list } = await tempModel.request({ codeNo })
|
this.updateValue(name, { options: list })
|
},
|
|
async getCodeObject(name, codeno) {
|
const { codeModel } = this
|
const { list } = await codeModel.request({
|
codeno
|
})
|
|
this.bankCodeObjectList = list
|
this.updateValue(
|
name,
|
{
|
options: list.map(({ itemname, attribute1 }) => ({
|
label: itemname,
|
value: attribute1
|
}))
|
},
|
false
|
)
|
},
|
|
// 提交成功后返回原列表页
|
commitSuccess() {
|
this.isShowDialog = false
|
const { isSave } = this
|
if (!isSave) {
|
this.$router.go(-1)
|
}
|
},
|
...mapMutations([
|
'setInvoiceAmount',
|
'setInvoiceInfo',
|
'setEnterpriseInfo'
|
]),
|
...mapActions(['queryBaseDiscountInvoiceInfo'])
|
},
|
computed: {
|
// 表单值信息
|
formValues() {
|
const { model, formList } = this
|
return model ? model.getFormValues(formList) : {}
|
},
|
formRules() {
|
const { model, formList } = this
|
if (model) {
|
return model.getFormRules(formList)
|
}
|
return {}
|
},
|
mixInfo() {
|
const { info, formValues, query } = this
|
const { fromButton } = query
|
const {
|
invoiceAmount,
|
relativeAmount,
|
unRelativeAmount,
|
applyMoney
|
} = info
|
const tempInfo =
|
fromButton !== 'invoiceAdjustButton'
|
? { invoiceAmount }
|
: { applyMoney }
|
return {
|
...info,
|
...formValues,
|
...tempInfo,
|
relativeAmount,
|
unRelativeAmount
|
}
|
},
|
...mapState({
|
invoiceAmount: state => state.tabsModule.invoiceAmount,
|
enterpriseInfo: state => state.tabsModule.enterpriseInfo,
|
info: state => state.tabsModule.baseDiscountInvoiceInfo
|
}),
|
...mapGetters(['isEdit'])
|
},
|
watch: {
|
invoiceSerialno() {
|
const { invoiceSerialno } = this
|
if (invoiceSerialno) {
|
this.getDetail()
|
}
|
},
|
invoiceAmount() {
|
const { invoiceAmount, formValues } = this
|
if (Number(formValues.applyMoney) !== Number(invoiceAmount)) {
|
this.updateValue('applyMoney', { value: invoiceAmount }, false)
|
}
|
},
|
info() {
|
this.getDetail()
|
}
|
}
|
}
|
</script>
|
<style lang="postcss" scoped>
|
.apply-info {
|
}
|
.apply-top-button {
|
& >>> .el-button {
|
margin-left: 20px;
|
}
|
}
|
|
.qrcode-content {
|
text-align: center;
|
& .qrode-close {
|
margin: 0;
|
padding: 0;
|
margin-bottom: 10px;
|
& i {
|
cursor: pointer;
|
font-size: 18px;
|
}
|
/* text-align: right; */
|
}
|
}
|
</style>
|