<template>
|
<div class="app-container">
|
<!--工具栏-->
|
<div class="head-container">
|
<div v-if="crud.props.searchToggle">
|
<!-- 搜索 -->
|
<el-select v-model="query.contractId" filterable clearable placeholder="所属合同" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
|
<el-option
|
v-for="item in contractList"
|
:key="item.contractId"
|
:label="item.contractNumber + ' - ' + item.contractName"
|
:value="item.contractId"
|
/>
|
</el-select>
|
<el-select v-model="query.invoiceType" filterable clearable placeholder="发票类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
|
<el-option
|
v-for="item in dict[invoiceType]"
|
:key="item.id"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
<rrOperation :crud="crud" />
|
</div>
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
<crudOperation :permission="permission" />
|
<!--表单组件-->
|
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="630px">
|
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
|
<el-form-item label="所属合同" prop="contractId">
|
<el-select v-model="form.contractId" filterable clearable placeholder="请选择" style="width: 495px;" @change="contractIdChange">
|
<el-option
|
v-for="item in contractList"
|
:key="item.contractId"
|
:label="item.contractNumber + ' - ' + item.contractName"
|
:value="item.contractId"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="开票时间" prop="billingTime">
|
<el-date-picker v-model="form.billingTime" type="datetime" style="width: 200px;" />
|
</el-form-item>
|
<el-form-item label="发票类型" prop="invoiceType">
|
<el-select v-model="form.invoiceType" filterable placeholder="请选择" style="width: 200px;">
|
<el-option
|
v-for="item in dict[invoiceType]"
|
:key="item.id"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="税前金额" prop="beforeTaxAmount">
|
<money-input :key="random" v-model="form.beforeTaxAmount" :width="495" show-ch @change="amountOrRateChange" />
|
</el-form-item>
|
<el-form-item label="税率" prop="taxRate">
|
<el-input v-model="form.taxRate" style="width: 200px;" @change="amountOrRateChange">
|
<template slot="append">%</template>
|
</el-input>
|
</el-form-item>
|
<el-form-item label="税额" prop="taxAmount">
|
<money-input :key="randomAR" v-model="form.taxAmount" show-ch :width="495" />
|
</el-form-item>
|
<el-form-item label="税后金额" prop="afterTaxAmount">
|
<money-input :key="randomAR" v-model="form.afterTaxAmount" show-ch :width="495" />
|
</el-form-item>
|
<el-form-item label="相关文件" prop="relatedDocuments">
|
<file-upload :key="random" ref="fileUpload" :file-url="form.relatedDocuments == null || form.relatedDocuments === '' ? null : form.relatedDocuments" :limit="5" style="width: 495px;" @fileInfo="getFileInfo" />
|
</el-form-item>
|
<el-form-item label="相关付款">
|
<el-select v-model="form.contractPaymentIds" filterable multiple placeholder="请选择" style="width: 495px;">
|
<el-option
|
v-for="item in contractPaymentList"
|
:key="item.paymentId"
|
:label="item.paymentAmount"
|
:value="item.paymentId"
|
>
|
<span style="float: left">付款金额:{{ item.paymentAmount }}</span>
|
<span style="float: right; color: #8492a6; font-size: 13px">付款时间:{{ item.paymentTime }}</span>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="备注信息" prop="remarks">
|
<el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 495px;" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="text" @click="crud.cancelCU">取消</el-button>
|
<el-button :loading="crud.status.cu === 2" type="primary" @click="submitCU">确认</el-button>
|
</div>
|
</el-dialog>
|
<!--表格渲染-->
|
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
|
<el-table-column type="selection" width="55" />
|
<el-table-column :show-overflow-tooltip="true" prop="contractName" label="所属合同" />
|
<el-table-column :show-overflow-tooltip="true" prop="billingTime" label="开票时间" />
|
<el-table-column :show-overflow-tooltip="true" prop="invoiceType" label="发票类型">
|
<template slot-scope="scope">
|
{{ dict.label[invoiceType][scope.row.invoiceType] }}
|
</template>
|
</el-table-column>
|
<el-table-column :show-overflow-tooltip="true" prop="beforeTaxAmount" label="税前金额">
|
<template slot-scope="scope">
|
{{ crud.toMoney(scope.row.beforeTaxAmount) }}
|
</template>
|
</el-table-column>
|
<el-table-column :show-overflow-tooltip="true" prop="taxRate" label="税率">
|
<template slot-scope="scope">
|
{{ scope.row.taxRate }}%
|
</template>
|
</el-table-column>
|
<el-table-column :show-overflow-tooltip="true" prop="taxAmount" label="税额">
|
<template slot-scope="scope">
|
{{ crud.toMoney(scope.row.taxAmount) }}
|
</template>
|
</el-table-column>
|
<el-table-column :show-overflow-tooltip="true" prop="afterTaxAmount" label="税后金额">
|
<template slot-scope="scope">
|
{{ crud.toMoney(scope.row.afterTaxAmount) }}
|
</template>
|
</el-table-column>
|
<el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注信息" />
|
<el-table-column v-if="checkPer(['admin','contractInvoice:edit','contractInvoice:del'])" label="操作" width="150px" align="center">
|
<template slot-scope="scope">
|
<udOperation
|
:data="scope.row"
|
:permission="permission"
|
/>
|
</template>
|
</el-table-column>
|
</el-table>
|
<!--分页组件-->
|
<pagination />
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import crudContractInvoice from '@/api/contract/contractInvoice'
|
import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
import rrOperation from '@crud/RR.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
import udOperation from '@crud/UD.operation'
|
import pagination from '@crud/Pagination'
|
import moneyInput from '@/views/assembly/moneyInput/index.vue'
|
import fileUpload from '@/views/assembly/fileUpload/index.vue'
|
import constant from '@/utils/constant'
|
import crudContract from '@/api/contract/contract'
|
import crudContractPayment from '@/api/contract/contractPayment'
|
|
const defaultForm = { invoiceId: null, contractId: null, billingTime: null, invoiceType: null, beforeTaxAmount: null, taxRate: null, taxAmount: null, afterTaxAmount: null, relatedDocuments: null, remarks: null, contractPaymentIds: [], createBy: null, updateBy: null, createTime: null, updateTime: null }
|
export default {
|
name: 'ContractInvoice',
|
components: { pagination, crudOperation, rrOperation, udOperation, moneyInput, fileUpload },
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
dicts: [constant.INVOICE_TYPE],
|
cruds() {
|
return CRUD({ title: '合同发票', url: 'api/contractInvoice', idField: 'invoiceId', sort: 'invoiceId,desc', crudMethod: { ...crudContractInvoice }})
|
},
|
data() {
|
// 税前金额校验规则
|
var validateBeforeTaxAmount = (rule, value, callback) => {
|
if (value !== null) {
|
if (isNaN(Number(value))) {
|
callback(new Error('请输入数字值'))
|
} else {
|
if (value < 0 || value > 1000000000) {
|
callback(new Error('税前金额不能超过10亿'))
|
} else {
|
callback()
|
}
|
}
|
} else {
|
callback(new Error('税前金额不能为空'))
|
}
|
}
|
// 税率校验规则
|
var validateTaxRate = (rule, value, callback) => {
|
if (value !== null) {
|
if (isNaN(Number(value))) {
|
callback(new Error('请输入数字值'))
|
} else {
|
if (value < 0 || value > 100) {
|
callback(new Error('税率不能超过100%'))
|
} else {
|
callback()
|
}
|
}
|
} else {
|
callback()
|
}
|
}
|
return {
|
permission: {
|
add: ['admin', 'contractInvoice:add'],
|
edit: ['admin', 'contractInvoice:edit'],
|
del: ['admin', 'contractInvoice:del'],
|
download: ['admin', 'contractInvoice:download']
|
},
|
rules: {
|
contractId: [
|
{ required: true, message: '请选择所属合同', trigger: 'change' }
|
],
|
billingTime: [
|
{ required: true, message: '请选择开票时间', trigger: 'change' }
|
],
|
invoiceType: [
|
{ required: true, message: '请选择发票类型', trigger: 'change' }
|
],
|
beforeTaxAmount: [
|
{ required: true, validator: validateBeforeTaxAmount, trigger: 'blur' }
|
],
|
taxRate: [
|
{ validator: validateTaxRate, trigger: 'blur' }
|
]
|
},
|
queryTypeOptions: [
|
{ key: 'contractId', display_name: '所属合同' },
|
{ key: 'invoiceType', display_name: '发票类型' }
|
],
|
// 字典:发票类型
|
invoiceType: constant.INVOICE_TYPE,
|
// 随机数
|
random: 0,
|
randomAR: 0,
|
// 合同数据
|
contractList: [],
|
// 付款数据
|
contractPaymentList: []
|
}
|
},
|
methods: {
|
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
[CRUD.HOOK.beforeRefresh]() {
|
const that = this
|
// 获取合同数据
|
that.getContractList()
|
// 检索条件赋值
|
if (that.$route.query.contractId != null && that.crud.query.contractId === undefined) {
|
that.$set(that.crud.query, 'contractId', Number(that.$route.query.contractId))
|
}
|
return true
|
},
|
// 获取合同数据
|
getContractList() {
|
const that = this
|
// 获取合同数据
|
crudContract.getAll().then(res => {
|
// 获取合同数据
|
that.contractList = res
|
})
|
},
|
// 钩子:开始 "新建/编辑" - 之前
|
[CRUD.HOOK.beforeToCU]() {
|
const that = this
|
// 随机数
|
that.random = Math.random()
|
that.randomAR = Math.random()
|
},
|
// 钩子:新建 - 之前
|
[CRUD.HOOK.beforeToAdd]() {
|
const that = this
|
// 判断检索条件
|
if (that.crud.query.contractId !== undefined) {
|
// 表单赋值
|
that.$set(that.crud.form, 'contractId', Number(that.crud.query.contractId))
|
// 所属合同变更
|
that.contractIdChange()
|
}
|
},
|
// 钩子:编辑 - 之前
|
[CRUD.HOOK.beforeToEdit]() {
|
const that = this
|
// 获取付款数据
|
that.getContractPayment()
|
},
|
// 所属合同变更
|
contractIdChange() {
|
const that = this
|
// 相关付款
|
that.crud.form.contractPaymentIds = []
|
// 获取付款数据
|
that.contractPaymentList = []
|
// 判断所属合同是否为空
|
if (that.crud.form.contractId != null && that.crud.form.contractId !== '') {
|
// 获取付款数据
|
that.getContractPayment()
|
}
|
},
|
// 获取付款数据
|
getContractPayment() {
|
const that = this
|
// 获取付款数据
|
crudContractPayment.getAll({ contractId: that.crud.form.contractId }).then(res => {
|
// 获取付款数据
|
that.contractPaymentList = res
|
})
|
},
|
// 税前金额或税率变更
|
amountOrRateChange() {
|
const that = this
|
// 判断税前金额和税率是否为空
|
if (that.crud.form.beforeTaxAmount !== null && that.crud.form.beforeTaxAmount !== '' && that.crud.form.taxRate !== null && that.crud.form.taxRate !== '') {
|
// 税额
|
that.crud.form.taxAmount = that.crud.form.beforeTaxAmount * (that.crud.form.taxRate / 100)
|
// 税后金额
|
that.crud.form.afterTaxAmount = that.crud.form.beforeTaxAmount + that.crud.form.beforeTaxAmount * (that.crud.form.taxRate / 100)
|
// 随机数
|
that.randomAR = Math.random()
|
}
|
},
|
// 表单提交
|
submitCU() {
|
const that = this
|
// 通过“that.$refs.fileUpload”找到子页面,“submit”是子页面的方法。
|
that.$refs.fileUpload.submit()
|
},
|
// 获取文件信息
|
getFileInfo(info) {
|
const that = this
|
// 判断税率是否为空
|
if (that.crud.form.taxRate == null || that.crud.form.taxRate === '') {
|
// 税率
|
that.crud.form.taxRate = 0
|
}
|
// 判断税额是否为空
|
if (that.crud.form.taxAmount == null || that.crud.form.taxAmount === '') {
|
// 税额
|
that.crud.form.taxAmount = 0
|
}
|
// 判断税后金额是否为空
|
if (that.crud.form.afterTaxAmount == null || that.crud.form.afterTaxAmount === '') {
|
// 税后金额
|
that.crud.form.afterTaxAmount = that.crud.form.beforeTaxAmount
|
}
|
// 判断返回数据
|
if (info.length === 0) {
|
// 表单文件路径赋值
|
that.crud.form.relatedDocuments = null
|
// 表单提交
|
that.crud.submitCU()
|
// 终止
|
return
|
}
|
// 循环返回数据
|
for (let i = 0; i < info.length; i++) {
|
// 判断循环下标
|
if (i === 0) {
|
// 表单文件路径赋值
|
that.crud.form.relatedDocuments = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName
|
} else {
|
// 表单文件路径赋值
|
that.crud.form.relatedDocuments += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName
|
}
|
// 判断循环是否结束
|
if (i === info.length - 1) {
|
// 表单提交
|
that.crud.submitCU()
|
}
|
}
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|