Files
income_payments_client/src/views/packManagement/modules/BatchIncomePaymentModule.vue
T

283 lines
7.6 KiB
Vue

<template>
<j-modal
:title="title"
:width="width"
:visible="visible"
:confirmLoading="confirmLoading"
switchFullscreen
@ok="handleOk"
@cancel="handleCancel"
cancelText="关闭">
<a-spin :spinning="confirmLoading">
<a-form :form="form">
<a-row>
<a-col :xl="12" :sm="24">
<a-form-item label="来款金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input placeholder="请输入来款金额"
v-decorator="['incomingAmount', validatorRules.incomingAmount]"
:maxLength='50'
@change="(e) => {e.target.value = (e.target.value.replace(/[^0-9.]/g,'')).trim()}"
@blur="incomingAmountBlur"></a-input>
</a-form-item>
</a-col>
<a-col :xl="12" :sm="24">
<a-form-item label="来款日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-date placeholder="请选择来款日期"
style="width: 100%;"
v-decorator="['paymentDate', validatorRules.paymentDate]"
:trigger-change="true"
date-format="YYYY-MM-DD"/>
</a-form-item>
</a-col>
</a-row>
</a-form>
<!-- /查询区域-->
<!-- 表格区域-->
<div>
<!-- :scroll="{x: 1000}"-->
<a-table
ref="table"
size="middle"
bordered
rowKey="id"
:columns="columns"
:dataSource="dataSource"
class="j-table-force-nowrap">
<!-- 输入-->
<template slot="input-text">
<a-input placeholder="请输入备注"
v-decorator="['remark']"
:maxLength='50'
@change="e => {e.target.value = (e.target.value + '').trim()}"></a-input>
</template>
<template slot="text" slot-scope="text">
<j-ellipsis :value="text" :length="18"></j-ellipsis>
</template>
</a-table>
</div>
</a-spin>
<template slot="footer">
<a-button @click="handleCancel">关闭</a-button>
<a-button @click="handleOk" type="primary" v-preventclick>确定</a-button>
</template>
</j-modal>
</template>
<script>
import JDate from '../../../components/tools/JDate'
import { money } from '../../../utils/validate'
import { addZero } from '../../../utils/util'
export default {
name: 'BatchIncomePaymentModule',
components: { JDate },
props: {
// 选中的项目
tableData: {
type: Array,
required: false,
default: []
},
visible: {
type: Boolean,
required: false,
default: false
}
},
watch: {
visible(value) {
if (value) {
this.open()
}
}
},
data() {
return {
title: '批量来款',
width: 1000,
confirmLoading: false,
form: this.$form.createForm(this),
labelCol: {
xs: { span: 24 },
sm: { span: 6 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 18 }
},
url: {
list: ''
},
validatorRules: {
incomingAmount: {
rules: [{ required: true, validator: this.checkMoney }],
validateTrigger: 'blur'
},
paymentDate: {
rules: [{ required: true, message: '请选择来款日期' }],
validateTrigger: 'change'
}
},
columns: [
{
title: '序号',
dataIndex: '',
key: 'rowIndex',
width: 60,
align: 'center',
customRender: function (t, r, index) {
return parseInt(index) + 1
}
}, {
title: '项目名称',
align: 'center',
// width: 200,
dataIndex: 'chargeProject',
scopedSlots: { customRender: 'text' }
}, {
title: '应收金额',
align: 'center',
width: 100,
dataIndex: 'receivableAmount'
}, {
title: '实收金额',
align: 'center',
width: 100,
dataIndex: 'paidAmount'
}, {
title: '欠款金额',
align: 'center',
width: 100,
dataIndex: 'amountOwed'
}, {
title: '本次来款金额',
align: 'center',
width: 140,
dataIndex: 'thisIncomingAmount'
}, {
title: '备注',
align: 'center',
width: 200,
dataIndex: 'remark',
scopedSlots: { customRender: 'input-text' }
}
],
dataSource: [],
inputIncomingAmount: null, // 输入的来款金额
disableMixinCreated: true,
sumAmountOwed: 0 // 总欠款金额
}
},
methods: {
addZero,
getAddZero(value) {
let e = {
target: {
value: value.toString()
}
}
this.addZero(e)
return e.target.value
},
loadData() {
// 计算项目欠款信息
this.dataSource.forEach(item => {
let amountOwed = Number(item.receivableAmount) - Number(item.paidAmount)
item.amountOwed = this.getAddZero(amountOwed)
this.sumAmountOwed += Number(item.amountOwed)
})
this.$forceUpdate()
},
handleOk() {
},
handleCancel() {
this.close()
},
open() {
this.dataSource = this.tableData
this.loadData()
},
close() {
this.form.resetFields()
this.clearThisTimeAmount()
this.$emit('update:visible', false)
},
/**
* 来款金额输入失去焦点,进行金额分配
* @param e
*/
incomingAmountBlur(e) {
this.addZero(e)
e.target.value = (e.target.value.replace(/[^0-9.]/g, '')).trim()
this.inputIncomingAmount = Number(e.target.value)
if (this.inputIncomingAmount > this.sumAmountOwed) {
this.$message.warn('来款金额大于总欠款金额,请修改')
return
}
this.clearThisTimeAmount()
this.calculateThisTimeAmount()
},
/**
* 清空本次来款金额
* @returns {Promise<unknown>}
*/
clearThisTimeAmount() {
this.dataSource.forEach(item => {
item.thisIncomingAmount = 0.00
})
},
/**
* 计算此次来款信息
*/
calculateThisTimeAmount() {
if (this.inputIncomingAmount <= 0) {
this.$message.warn('请输入大于0的来款金额')
return
}
this.dataSource.forEach((item, index) => {
// 当前项目欠款是否 >0
if (Number(item.amountOwed) > 0) {
// 输入的来款金额是否 >= 当前项目欠款
if (this.inputIncomingAmount >= Number(item.amountOwed)) {
item.thisIncomingAmount = this.getAddZero(Number(item.amountOwed))
this.inputIncomingAmount -= Number(item.amountOwed)
} else {
// 输入的来款金额小于当前项目欠款且剩余的输入来款金额大于0,则将剩余全部来款算入当前项目的此次来款
if (this.inputIncomingAmount > 0) {
item.thisIncomingAmount = this.getAddZero(this.inputIncomingAmount)
this.inputIncomingAmount = 0
}
}
}
this.$set(this.dataSource, index, item)
})
}
,
/**
* 校验金额格式
* @param rules
* @param value
* @param callback
*/
checkMoney(rules, value, callback) {
if (value) {
if (money(value)) {
callback()
return
}
callback('请输入正确格式的金额')
}
callback('请输入来款金额')
}
}
}
</script>
<style scoped>
</style>