|
|
@@ -0,0 +1,717 @@
|
|
|
+<template>
|
|
|
+ <el-form ref="form" :model="form" :rules="rules">
|
|
|
+ <ele-pro-table
|
|
|
+ ref="table"
|
|
|
+ :needPage="false"
|
|
|
+ :columns="columns"
|
|
|
+ :datasource="form.datasource"
|
|
|
+ class="time-form"
|
|
|
+ >
|
|
|
+ <!-- 表头工具栏 -->
|
|
|
+ <template v-slot:toolbar>
|
|
|
+ <div class="headbox">
|
|
|
+ <!-- <el-button
|
|
|
+ size="small"
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-plus"
|
|
|
+ class="ele-btn-icon"
|
|
|
+ @click="handlAdd"
|
|
|
+ v-if="type!='view'"
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </el-button> -->
|
|
|
+
|
|
|
+ <!-- <div class="pricebox">
|
|
|
+ <span class="amount">比例合计:{{ allRatio }}元</span>
|
|
|
+ <span class="amount">计划收款金额合计:{{ allPrice }}元</span>
|
|
|
+ </div> -->
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-slot:headerPeriod="{ column }">
|
|
|
+ <span class="is-required">{{ column.label }}</span>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-slot:period="scope">
|
|
|
+ <span>第{{ scope.row.period }}期</span>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-slot:moneyName="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="margin-bottom: 20px"
|
|
|
+ :prop="'datasource.' + scope.$index + '.moneyName'"
|
|
|
+ :rules="{
|
|
|
+ required: true,
|
|
|
+ message: '请输入',
|
|
|
+ trigger: 'blur'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-input
|
|
|
+ v-model="scope.row.moneyName"
|
|
|
+ placeholder="请输入"
|
|
|
+ :disabled="type=='view'"
|
|
|
+
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <template v-slot:headerMoneyName="{ column }">
|
|
|
+ <span class="is-required">{{ column.label }}</span>
|
|
|
+ </template>
|
|
|
+ <template v-slot:ratio="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="margin-bottom: 20px"
|
|
|
+ :prop="'datasource.' + scope.$index + '.ratio'"
|
|
|
+ :rules="{
|
|
|
+ required: true,
|
|
|
+ pattern: numberReg,
|
|
|
+ message: '请输入正确的比例',
|
|
|
+ trigger: 'change'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-input
|
|
|
+ v-model="scope.row.ratio"
|
|
|
+ placeholder="请输入"
|
|
|
+ :disabled="type=='view'"
|
|
|
+ @input="(val) => ratioInput(val, scope.$index)"
|
|
|
+ >
|
|
|
+ <template slot="append">%</template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <template v-slot:type="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="margin-bottom: 20px"
|
|
|
+ :prop="'datasource.' + scope.$index + '.type'"
|
|
|
+ :rules="{
|
|
|
+ required: true,
|
|
|
+ message: '请选择款项类型',
|
|
|
+ trigger: 'change'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-select
|
|
|
+ v-model="scope.row.type"
|
|
|
+ placeholder="请选择"
|
|
|
+ style="width: 100%"
|
|
|
+ :disabled="type=='view'"
|
|
|
+
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in paymentTypeOp"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <template v-slot:headerRatio="{ column }">
|
|
|
+ <span class="is-required">{{ column.label }}</span>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-slot:headerPrice="{ column }">
|
|
|
+ <span class="is-required">{{ column.label }}</span>
|
|
|
+ </template>
|
|
|
+ <template v-slot:price="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="margin-bottom: 20px"
|
|
|
+ :prop="'datasource.' + scope.$index + '.price'"
|
|
|
+ :rules="{
|
|
|
+ required: true,
|
|
|
+ pattern: numberReg,
|
|
|
+ message: '请输入正确的金额',
|
|
|
+ trigger: 'change'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-input
|
|
|
+ type="number"
|
|
|
+ :min="0"
|
|
|
+ :disabled="type=='view'"
|
|
|
+ v-model="scope.row.price"
|
|
|
+ style="width: 100%"
|
|
|
+ placeholder="请输入"
|
|
|
+ >
|
|
|
+ <template slot="append">元</template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <template v-slot:deadLine="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="margin-bottom: 20px"
|
|
|
+ :prop="'datasource.' + scope.$index + '.deadLine'"
|
|
|
+ :rules="{
|
|
|
+ required: true,
|
|
|
+ message: '请选择日期',
|
|
|
+ trigger: 'change'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-date-picker
|
|
|
+ style="width: 140px"
|
|
|
+ v-model="scope.row.deadLine"
|
|
|
+ :disabled="type=='view'"
|
|
|
+ type="date"
|
|
|
+ placeholder="选择日期"
|
|
|
+ >
|
|
|
+ </el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <template v-slot:headerDeadLine="{ column }">
|
|
|
+ <span class="is-required">{{ column.label }}</span>
|
|
|
+ </template>
|
|
|
+ <template v-slot:remark="scope">
|
|
|
+ <el-form-item
|
|
|
+ style="margin-bottom: 20px"
|
|
|
+ :prop="'datasource.' + scope.$index + '.remark'"
|
|
|
+ >
|
|
|
+ <el-input
|
|
|
+ v-model="scope.row.remark"
|
|
|
+ type="textarea"
|
|
|
+ placeholder="请输入"
|
|
|
+ :disabled="type=='view'"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <!-- 操作列 -->
|
|
|
+ <template v-slot:action="{ row }">
|
|
|
+ <el-popconfirm
|
|
|
+ class="ele-action"
|
|
|
+ title="确定要删除吗?"
|
|
|
+ @confirm="remove(row)"
|
|
|
+ >
|
|
|
+ <template v-slot:reference>
|
|
|
+ <el-link type="danger" :underline="false" icon="el-icon-delete">
|
|
|
+ 删除
|
|
|
+ </el-link>
|
|
|
+ </template>
|
|
|
+ </el-popconfirm>
|
|
|
+ </template>
|
|
|
+ </ele-pro-table>
|
|
|
+ </el-form>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+ import { emailReg, phoneReg, numberReg } from 'ele-admin';
|
|
|
+ import { paymentTypeOp } from '@/enum/dict';
|
|
|
+ export default {
|
|
|
+ props: {
|
|
|
+ delDetailIds: Array,
|
|
|
+ type: String,
|
|
|
+ discountTotalPrice: {
|
|
|
+ type: [Number, String],
|
|
|
+ default: 0
|
|
|
+ },
|
|
|
+ menu: {
|
|
|
+ type: String,
|
|
|
+ default: 'sale'
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ const defaultForm = {
|
|
|
+ key: null,
|
|
|
+ deadLine: null,
|
|
|
+ moneyName: '',
|
|
|
+ price: null,
|
|
|
+ ratio: null,
|
|
|
+ remark: '',
|
|
|
+ type: '',
|
|
|
+ period: null
|
|
|
+ };
|
|
|
+ return {
|
|
|
+ // allPrice: 0,
|
|
|
+ // allRatio: 0,
|
|
|
+ numberReg,
|
|
|
+ defaultForm,
|
|
|
+ discountAmount: 0,
|
|
|
+ form: {
|
|
|
+ datasource: []
|
|
|
+ },
|
|
|
+ paymentTypeOp,
|
|
|
+
|
|
|
+ rules: {}
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ canHandl() {
|
|
|
+ return this.form.datasource.length;
|
|
|
+ },
|
|
|
+ columns() {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ width: 45,
|
|
|
+ type: 'index',
|
|
|
+ columnKey: 'index',
|
|
|
+ align: 'center',
|
|
|
+ fixed: 'left'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'detailNo',
|
|
|
+ label: this.menu === 'purchase' ? '付款计划编码' : '收款计划编码',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'invoiceOrderNo',
|
|
|
+ label: '发票号',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'relatedReceivableOrderNo',
|
|
|
+ label: this.menu === 'purchase' ? '关联应付编码' : '关联应收编码',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'issueNumber',
|
|
|
+ label: '期数',
|
|
|
+ // slot: 'period',
|
|
|
+ // headerSlot: 'headerPeriod',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'paymentType',
|
|
|
+ label: '款项类型',
|
|
|
+ // slot: 'paymentType',
|
|
|
+ // headerSlot: 'headerPaymentType',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'moneyName',
|
|
|
+ label: '款项名称',
|
|
|
+ // slot: 'moneyName',
|
|
|
+ // headerSlot: 'headerMoneyName',
|
|
|
+ align: 'center',
|
|
|
+ width: 170
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 150,
|
|
|
+ prop: 'paymentRatio',
|
|
|
+ label: '比例',
|
|
|
+ // slot: 'paymentRatio',
|
|
|
+ // headerSlot: 'headerRatio',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 170,
|
|
|
+ prop: 'planPaymentAmount',
|
|
|
+ label: this.menu === 'purchase' ? '计划付款金额' : '计划收款金额',
|
|
|
+ // slot: 'planPaymentAmount',
|
|
|
+ align: 'center',
|
|
|
+ // headerSlot: 'headerPrice',
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ width: 160,
|
|
|
+ prop: 'planPaymentDate',
|
|
|
+ label: this.menu === 'purchase' ? '计划付款日期' : '计划收款日期',
|
|
|
+ // slot: 'planPaymentDate',
|
|
|
+ // headerSlot: 'headerDeadLine',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'isInvoice',
|
|
|
+ label: '是否已开票',
|
|
|
+ align: 'center',
|
|
|
+ formatter: (row) => {
|
|
|
+ return row.isInvoice ? '是' : '否';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'invoiceAmount',
|
|
|
+ label: '已开票金额',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'invoiceDate',
|
|
|
+ label: '开票日期',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'isGenerateReceivablePayment',
|
|
|
+ label: this.menu === 'purchase' ? '是否生成应付款项' : '是否生成应收款项',
|
|
|
+ align: 'center',
|
|
|
+ formatter: (_row, _column, cellValue) => {
|
|
|
+ return cellValue == 1 ? '是' : '否';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'receivableAmount',
|
|
|
+ label: this.menu === 'purchase' ? '应付金额' : '应收金额',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'receivedAmount',
|
|
|
+ label: this.menu === 'purchase' ? '已付款金额' : '已收款金额',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'actualReceivablePaymentDate',
|
|
|
+ label: this.menu === 'purchase' ? '实际付款日期' : '实际收款日期',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'deliveryStatus',
|
|
|
+ label: this.menu === 'purchase' ? '收货货状态' : '发货状态',
|
|
|
+ align: 'center',
|
|
|
+ formatter: (_row, _column, cellValue) => {
|
|
|
+ let options = this.menu === 'purchase' ? [
|
|
|
+ { value: 0, label: '待收货' },
|
|
|
+ { value: 1, label: '部分收货' },
|
|
|
+ { value: 2, label: '全部收货' }
|
|
|
+ ] : [
|
|
|
+ { value: 0, label: '待发货' },
|
|
|
+ { value: 1, label: '部分发货' },
|
|
|
+ { value: 2, label: '全部发货' }
|
|
|
+ ];
|
|
|
+ return options.find(item => item.value == cellValue)?.label || '';
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'reconciliationStatus',
|
|
|
+ label: '对账状态',
|
|
|
+ align: 'center',
|
|
|
+ formatter: (_row, _column, cellValue) => {
|
|
|
+ let options = [
|
|
|
+ { value: 0, label: '未对账' },
|
|
|
+ { value: 1, label: '部分对账' },
|
|
|
+ { value: 2, label: '全部对账' }
|
|
|
+ ];
|
|
|
+ return options.find(item => item.value == cellValue)?.label || '';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 220,
|
|
|
+ prop: 'paymentStatus',
|
|
|
+ label: this.menu === 'purchase' ? '付款状态' : '收款状态',
|
|
|
+ slot: 'paymentStatus',
|
|
|
+ align: 'center',
|
|
|
+ formatter: (_row, _column, cellValue) => {
|
|
|
+ let options = this.menu === 'purchase' ? [
|
|
|
+ { value: 0, label: '未付款' },
|
|
|
+ { value: 1, label: '部分付款' },
|
|
|
+ { value: 2, label: '全部付款' }
|
|
|
+ ] : [
|
|
|
+ { value: 0, label: '未收款' },
|
|
|
+ { value: 1, label: '部分收款' },
|
|
|
+ { value: 2, label: '全部收款' }
|
|
|
+ ];
|
|
|
+ return options.find(item => item.value == cellValue)?.label || '';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ width: 120,
|
|
|
+ prop: 'overdueStatus',
|
|
|
+ label: '逾期状态',
|
|
|
+ align: 'center',
|
|
|
+ formatter: (_row, _column, cellValue) => {
|
|
|
+ return _row.overdueStatus == 1 ? '逾期中' : '未逾期';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // {
|
|
|
+ // columnKey: 'action',
|
|
|
+ // label: '操作',
|
|
|
+ // align: 'center',
|
|
|
+ // resizable: false,
|
|
|
+ // slot: 'action',
|
|
|
+ // showOverflowTooltip: true,
|
|
|
+ // show: this.type != 'view'
|
|
|
+ // }
|
|
|
+ ];
|
|
|
+ },
|
|
|
+ allRatio() {
|
|
|
+ return this.form.datasource.reduce((acc, cur) => acc + Number(cur.ratio), 0).toFixed(2);
|
|
|
+ },
|
|
|
+ allPrice() {
|
|
|
+ return this.form.datasource.reduce((acc, cur) => acc + Number(cur.price), 0).toFixed(2);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ discountAmount(newval) {
|
|
|
+ if (newval) {
|
|
|
+ this.refreshprice();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ setDiscountAmount(val) {
|
|
|
+ this.discountAmount = val;
|
|
|
+ },
|
|
|
+ //输入比例更新金额
|
|
|
+ async ratioInput(val, index = null) {
|
|
|
+ val = Number(val);
|
|
|
+ try {
|
|
|
+ if (index != null) {
|
|
|
+ await this.checkRatio();
|
|
|
+ }
|
|
|
+ let newval = (val / 100).toFixed(2);
|
|
|
+ let price = (this.discountAmount * newval).toFixed(2);
|
|
|
+ console.log(newval, price, index, '88888');
|
|
|
+ if (index != null) {
|
|
|
+ console.log(newval, price, index, '999999');
|
|
|
+ this.$set(this.form.datasource[index], 'price', price);
|
|
|
+ } else {
|
|
|
+ return price;
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //this.$set( this.form.datasource[index], 'price', price)
|
|
|
+ },
|
|
|
+ //检验比例
|
|
|
+ checkRatio() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let newData = this.form.datasource,
|
|
|
+ sum = 0;
|
|
|
+ newData.forEach((r) => {
|
|
|
+ if (r.ratio) {
|
|
|
+ sum += Number(r.ratio);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log(sum, '3333333');
|
|
|
+ if (sum > 100) {
|
|
|
+ this.$message.error('总共比例不能超过100');
|
|
|
+ this.$set(
|
|
|
+ this.form.datasource[this.form.datasource.length - 1],
|
|
|
+ 'ratio',
|
|
|
+ null
|
|
|
+ );
|
|
|
+ this.$set(
|
|
|
+ this.form.datasource[this.form.datasource.length - 1],
|
|
|
+ 'price',
|
|
|
+ 0.0
|
|
|
+ );
|
|
|
+ reject(false);
|
|
|
+ } else {
|
|
|
+ resolve(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ refreshprice() {
|
|
|
+ let newData = this.form.datasource;
|
|
|
+ newData.forEach(async (r, index) => {
|
|
|
+ if (r.ratio) {
|
|
|
+ console.log(this.ratioInput(Number(r.ratio)), '9999888888');
|
|
|
+ r.price = await this.ratioInput(Number(r.ratio));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 返回列表数据
|
|
|
+ getTableValue() {
|
|
|
+ return this.form.datasource;
|
|
|
+ },
|
|
|
+ //修改回显
|
|
|
+ putTableValue(data) {
|
|
|
+ if (data && data?.length) {
|
|
|
+ this.form.datasource = data;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ remove(row) {
|
|
|
+ let index = this.form.datasource.findIndex((n) => n.key == row.key);
|
|
|
+ if (index !== -1) {
|
|
|
+ this.form.datasource.splice(index, 1);
|
|
|
+ this.setSort();
|
|
|
+ if (row.id) {
|
|
|
+ this.delDetailIds.push(row.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 清空表格
|
|
|
+ restTable() {
|
|
|
+ this.form.datasource = [];
|
|
|
+ },
|
|
|
+ // 重新排序
|
|
|
+ setSort() {
|
|
|
+ this.form.datasource.forEach((n, index) => {
|
|
|
+ n.key = index + 1;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ defaultList(method, period, dateRange) {
|
|
|
+ console.log('method, period', method, period);
|
|
|
+ const tempList = []
|
|
|
+ if(dateRange) {
|
|
|
+ this.setDefaultList(dateRange, period);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(method == 3) {
|
|
|
+ let params = ['预付款', '交货款'];
|
|
|
+ for(let i = 0; i < period; i++) {
|
|
|
+ let i = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ i.moneyName = item;
|
|
|
+ i.type = i < params.length ? this.paymentTypeOp[index].value : '';
|
|
|
+ i.key = index + 1;
|
|
|
+ i.period = index + 1;
|
|
|
+ tempList.push(i);
|
|
|
+ }
|
|
|
+ // params.forEach((item, index) => {
|
|
|
+ // let i = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ // i.moneyName = item;
|
|
|
+ // i.type = this.paymentTypeOp[index].value;
|
|
|
+ // i.key = index + 1;
|
|
|
+ // i.period = index + 1;
|
|
|
+ // tempList.push(i);
|
|
|
+ // });
|
|
|
+ } else {
|
|
|
+ // method == 4 || method == 5 || method == 6 || method == 7 || method == 8
|
|
|
+ let params = [''];
|
|
|
+ params.forEach((item, index) => {
|
|
|
+ let i = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ i.key = index + 1;
|
|
|
+ i.period = index + 1;
|
|
|
+ tempList.push(i);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.form.datasource = tempList;
|
|
|
+ },
|
|
|
+
|
|
|
+ transformDaysFun(date) {
|
|
|
+ const startDate = new Date(date[0]);
|
|
|
+ const endDate = new Date(date[1]);
|
|
|
+ // 计算毫秒差并转换为天数,使用Math.ceil确保结果为整数
|
|
|
+ const days = Math.ceil((endDate - startDate) / (1000 * 60 * 60 * 24)) + 1;
|
|
|
+ console.log('包含两头的天数:', days);
|
|
|
+
|
|
|
+ // 生成包括头尾在内的所有日期
|
|
|
+ const allDates = [];
|
|
|
+ const current = new Date(startDate);
|
|
|
+
|
|
|
+ // 遍历从开始日期到结束日期的所有天数
|
|
|
+ while (current <= endDate) {
|
|
|
+ // 格式化日期为YYYY-MM-dd
|
|
|
+ const year = current.getFullYear();
|
|
|
+ const month = current.getMonth() + 1; // 月份从0开始,需要+1
|
|
|
+ const day = current.getDate();
|
|
|
+
|
|
|
+ const formattedMonth = String(month).padStart(2, '0');
|
|
|
+ const formattedDay = String(day).padStart(2, '0');
|
|
|
+ const formattedDateStr = `${year}-${formattedMonth}-${formattedDay}`;
|
|
|
+
|
|
|
+ allDates.push(formattedDateStr);
|
|
|
+
|
|
|
+ // 移动到下一天
|
|
|
+ current.setDate(current.getDate() + 1);
|
|
|
+ }
|
|
|
+ return allDates;
|
|
|
+ },
|
|
|
+
|
|
|
+ transformMonthFun(date, day) {
|
|
|
+ // 处理月份数据(转换为Date对象)
|
|
|
+ const parseMonthDate = (dateStr) => {
|
|
|
+ return dateStr instanceof Date ? dateStr : new Date(dateStr + '-01');
|
|
|
+ };
|
|
|
+
|
|
|
+ const start = parseMonthDate(date[0]);
|
|
|
+ const end = parseMonthDate(date[1]);
|
|
|
+
|
|
|
+ // 先生成所有月份的日期数组
|
|
|
+ const allMonthDates = [];
|
|
|
+ const currentDate = new Date(start);
|
|
|
+
|
|
|
+ // 遍历从开始月份到结束月份的所有月份
|
|
|
+ while (currentDate <= end) {
|
|
|
+ const year = currentDate.getFullYear();
|
|
|
+ const month = currentDate.getMonth() + 1; // 月份从0开始,需要+1
|
|
|
+ const receiptDate = day;
|
|
|
+
|
|
|
+ // 格式化日期为YYYY-MM-dd
|
|
|
+ const formattedMonth = String(month).padStart(2, '0');
|
|
|
+ const formattedDate = String(receiptDate).padStart(2, '0');
|
|
|
+ const deadLine = receiptDate ? `${year}-${formattedMonth}-${formattedDate}` : '';
|
|
|
+
|
|
|
+ allMonthDates.push(deadLine);
|
|
|
+
|
|
|
+ // 使用Date对象的setMonth方法正确移动到下一个月(自动处理年份变化)
|
|
|
+ currentDate.setMonth(currentDate.getMonth() + 1);
|
|
|
+ }
|
|
|
+ return allMonthDates;
|
|
|
+ },
|
|
|
+ setDefaultList(dateRange, period) {
|
|
|
+ const tempPeriod = period || 0;
|
|
|
+
|
|
|
+ // 计算基本比例
|
|
|
+ const basicRatio = 100 / tempPeriod;
|
|
|
+ let totalRatio = 0;
|
|
|
+
|
|
|
+ // 生成付款计划列表项
|
|
|
+ const tempList = [];
|
|
|
+
|
|
|
+ // 根据传入的period参数生成付款计划
|
|
|
+ for (let i = 0; i < tempPeriod; i++) {
|
|
|
+ let item = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ // 获取日期:如果i小于日期数组长度则使用对应日期,否则设为空
|
|
|
+ const deadLine = i < dateRange.length ? dateRange[i] : '';
|
|
|
+ const ratio = parseFloat(basicRatio.toFixed(2));
|
|
|
+
|
|
|
+ item.period = i + 1;
|
|
|
+ item.deadLine = deadLine;
|
|
|
+ item.ratio = ratio;
|
|
|
+
|
|
|
+ tempList.push(item);
|
|
|
+ totalRatio += ratio;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调整最后一项的比例,确保总和为100
|
|
|
+ if (tempList.length > 0) {
|
|
|
+ const difference = 100 - totalRatio;
|
|
|
+ if (difference !== 0) {
|
|
|
+ tempList[tempList.length - 1].ratio = parseFloat((tempList[tempList.length - 1].ratio + difference).toFixed(2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('付款计划列表:~~', tempList);
|
|
|
+ this.form.datasource = tempList;
|
|
|
+ // this.$set(this.form, 'datasource', tempList);
|
|
|
+ console.log('付款计划列表:', this.form.datasource);
|
|
|
+ },
|
|
|
+ // 添加
|
|
|
+ handlAdd() {
|
|
|
+ let item = JSON.parse(JSON.stringify(this.defaultForm));
|
|
|
+ item.key = this.form.datasource.length + 1;
|
|
|
+ this.form.datasource.push(item);
|
|
|
+ },
|
|
|
+
|
|
|
+ validateForm(callback) {
|
|
|
+ //开始表单校验
|
|
|
+ this.$refs.form.validate((valid) => {
|
|
|
+ callback(valid);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+</script>
|
|
|
+<style lang="scss" scoped>
|
|
|
+ .time-form .el-form-item {
|
|
|
+ margin-bottom: 0 !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ .headbox {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .amount {
|
|
|
+ font-size: 14px;
|
|
|
+ font-weight: bold;
|
|
|
+ padding-right: 30px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .pricebox {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-start;
|
|
|
+ align-items: center;
|
|
|
+ font-weight: bold;
|
|
|
+ }
|
|
|
+ :deep(.el-input-group__append) {
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+</style>
|