| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <!-- 收款明细表单公共组件 -->
- <!-- 职责:收款信息汇总区 + 新增按钮 + 可编辑表格(列/填写/校验/汇总内置),form 由父组件传入 -->
- <template>
- <div>
- <!-- 收款信息汇总区 -->
- <headerTitle :title="title"></headerTitle>
- <div style="margin: 10px 0; font-size: 14px; color: #606266;">
- <span>{{ totalLabel }}:{{ totalPrice || 0 }} 元</span>
- <span style="margin-left: 20px;">已收金额:{{ receivedAmount }} 元</span>
- <span style="margin-left: 20px;">未收金额:{{ unreceivedAmount }} 元</span>
- </div>
- <el-button
- v-if="!isView"
- size="small"
- type="primary"
- icon="el-icon-plus"
- class="ele-btn-icon"
- style="margin-bottom: 10px;"
- @click="addRow"
- >
- 新增
- </el-button>
- <el-form ref="form" :model="form" class="table-form">
- <ele-pro-table
- ref="table"
- :needPage="false"
- :columns="columns"
- :datasource="form.tableData"
- :toolkit="[]"
- >
- <!-- 收款时间 -->
- <template v-slot:receivedDate="{ row: r, $index }">
- <el-form-item
- :prop="`tableData.${$index}.receivedDate`"
- :rules="{ required: true, message: '请选择收款时间', trigger: 'change' }"
- class="table-form-item"
- >
- <el-date-picker
- v-model="r.receivedDate"
- type="date"
- placeholder="年/月/日"
- value-format="yyyy-MM-dd"
- style="width: 100%"
- size="small"
- :disabled="isView || r?.id"
- />
- </el-form-item>
- </template>
- <template v-slot:columnRequired="{ column }">
- <span class="is-required">{{ column.label }}</span>
- </template>
- <!-- 已收金额 -->
- <template v-slot:receivedTotalPrice="{ row: r, $index }">
- <el-form-item
- :prop="`tableData.${$index}.receivedTotalPrice`"
- :rules="{ required: true, message: '请输入已收金额', trigger: 'blur' }"
- class="table-form-item"
- >
- <el-input
- v-model="r.receivedTotalPrice"
- placeholder="请输入"
- size="small"
- :disabled="isView || r?.id"
- @input="calcAmount"
- />
- </el-form-item>
- </template>
- <!-- 支付类型 -->
- <template v-slot:paymentType="{ row: r, $index }">
- <el-form-item
- :prop="`tableData.${$index}.paymentType`"
- :rules="{ required: true, message: '请选择支付类型', trigger: 'change' }"
- class="table-form-item"
- >
- <DictSelection
- v-model="r.paymentType"
- dictName="支付类型"
- placeholder="请选择"
- class="payment-select"
- :disabled="isView || r?.id"
- />
-
- </el-form-item>
- </template>
- <!-- 附件 -->
- <template v-slot:files="{ row: r }">
- <fileMain v-model="r.files" :limit="1" :type="isView || r?.id ? 'view' : 'add'"></fileMain>
- </template>
- <!-- 备注 -->
- <template v-slot:remark="{ row: r }">
- <el-input
- v-model="r.remark"
- placeholder="请输入"
- size="small"
- :disabled="isView || r?.id"
- />
- </template>
- <!-- 操作 -->
- <template v-slot:action="{ row: r }">
- <el-link
- v-if="!isView && !r?.id"
- type="danger"
- :underline="false"
- @click="removeRow(r)"
- >
- 删除
- </el-link>
- </template>
- </ele-pro-table>
- </el-form>
- </div>
- </template>
- <script>
- import headerTitle from '@/components/header-title';
- import fileMain from '@/components/addDoc/index.vue';
- export default {
- name: 'CollectTableForm',
- components: {
- headerTitle,
- fileMain
- },
- props: {
- title: {
- type: String,
- default: '收款详情'
- },
- // 表单数据(含 tableData),.sync 双向,父组件传入
- form: {
- type: Object,
- default: () => ({ tableData: [] })
- },
- // 汇总区总金额(如预收金额/应收金额)
- totalPrice: {
- type: [Number, String],
- default: 0
- },
- // 汇总区总金额标签(如"预收金额"/"应收金额")
- totalLabel: {
- type: String,
- default: '预收金额'
- },
- // 新增行的空白模板
- rowTemplate: {
- type: Object,
- default: () => ({
- receivedDate: '',
- receivedTotalPrice: '',
- paymentType: '',
- files: [],
- remark: ''
- })
- },
- // 弹窗类型:view 查看模式禁用编辑,其它(add/update)可编辑
- dialogType: {
- type: String,
- default: 'update'
- }
- },
- data() {
- return {};
- },
- computed: {
- // 查看模式:禁用所有编辑
- isView() {
- return this.dialogType === 'view';
- },
- columns() {
- return [
- {
- type: 'index',
- label: '序号',
- width: 55,
- align: 'center',
- fixed: 'left'
- },
- {
- prop: 'receivedDate',
- headerSlot: 'columnRequired',
- label: '收款时间',
- align: 'center',
- minWidth: 160,
- slot: 'receivedDate'
- },
- {
- prop: 'receivedTotalPrice',
- headerSlot: 'columnRequired',
- label: '已收金额',
- align: 'center',
- minWidth: 140,
- slot: 'receivedTotalPrice'
- },
- {
- prop: 'paymentType',
- headerSlot: 'columnRequired',
- label: '支付类型',
- align: 'center',
- minWidth: 140,
- slot: 'paymentType'
- },
- {
- prop: 'files',
- label: '附件',
- align: 'center',
- minWidth: 120,
- slot: 'files'
- },
- {
- prop: 'remark',
- label: '备注',
- align: 'center',
- minWidth: 140,
- slot: 'remark'
- },
- {
- columnKey: 'action',
- label: '操作',
- width: 80,
- align: 'center',
- resizable: false,
- slot: 'action',
- fixed: 'right',
- show: !this.isView
- }
- ];
- },
- receivedAmount() {
- console.log('this.form.tableData', this.form.tableData)
- return this.form.tableData?.reduce((sum, item) => {
- const val = parseFloat(item.receivedTotalPrice);
- return sum + (isNaN(val) ? 0 : val);
- }, 0).toFixed(2);
- },
- unreceivedAmount() {
- const total = parseFloat(this.totalPrice) || 0;
- const received = parseFloat(this.receivedAmount) || 0;
- return (total - received).toFixed(2);
- }
- },
- methods: {
- addRow() {
- console.log('this.form.tableData', this.form.tableData)
- if (this.isView) return;
- this.form.tableData.push({ ...this.rowTemplate });
- this.calcAmount();
- },
- removeRow(row) {
- if (this.isView) return;
- const index = this.form.tableData.indexOf(row);
- if (index !== -1) {
- this.form.tableData.splice(index, 1);
- }
- this.calcAmount();
- },
- calcAmount() {
- this.$forceUpdate();
- },
- // 校验:查看模式直接通过,否则至少一条 + 各列必填
- validate() {
- return new Promise((resolve, reject) => {
- if (this.isView) {
- resolve(true);
- return;
- }
- if (this.form.tableData.length === 0) {
- this.$message.warning('请至少添加一条收款记录');
- reject(false);
- return;
- }
- this.$refs.form.validate((valid) => {
- valid ? resolve(true) : reject(false);
- });
- });
- },
- // 获取整个表单数据,供父组件提交
- getData() {
- return {
- form: this.form,
- tableData: this.form.tableData,
- receivedAmount: this.receivedAmount,
- unreceivedAmount: this.unreceivedAmount
- };
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .table-form-item {
- margin-bottom: 0 !important;
- }
- </style>
|