Commit 573db6aa by chenwq

对账单编辑

1 parent a68f29e1
<template>
<div class="dynamic-table-container">
员工标签:<el-button
type="default"
@click="addRow"
>
添加事由
</el-button>
<el-form :model="dynamicForm" ref="dynamicForm">
<el-table
:data="tableData"
border
style="width: 100%; margin-top: 20px"
>
<el-table-column
prop="index"
label="序号"
width="80"
align="center"
>
<template slot-scope="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
<el-table-column
prop="adjustAmount"
label="调整金额"
width="180"
>
<template slot-scope="scope">
<el-form-item
:prop="'tableData.' + scope.$index + '.adjustAmount'"
:rules="adjustAmountRules"
>
<el-input
v-model="scope.row.adjustAmount"
placeholder="请输入金额"
type="number"
></el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column
prop="adjustReason"
label="调整事由"
>
<template slot-scope="scope">
<el-form-item
:prop="'tableData.' + scope.$index + '.adjustReason'"
:rules="adjustReasonRules"
>
<el-input
v-model="scope.row.adjustReason"
placeholder="请输入调整事由"
></el-input>
</el-form-item>
</template>
</el-table-column>
<el-table-column
label="操作"
width="120"
align="center"
>
<template slot-scope="scope">
<el-button
size="mini"
type="danger"
@click="deleteRow(scope.$index)"
icon="el-icon-delete"
></el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<!-- <div style="margin-top: 20px">
<el-button type="info" @click="showTableData">显示表格数据</el-button>
<el-button type="success" @click="validateForm">提交验证</el-button>
</div> -->
</div>
</template>
<script>
export default {
name: 'DynamicAdjustmentTable',
data() {
return {
dynamicForm: {
tableData: []
},
adjustAmountRules: [
{ required: true, message: '请输入调整金额', trigger: 'blur' },
{
validator: (rule, value, callback) => {
if (value && isNaN(Number(value))) {
callback(new Error('请输入有效的数字'));
} else {
callback();
}
},
trigger: 'blur'
}
],
adjustReasonRules: [
{ required: true, message: '请输入调整事由', trigger: 'blur' },
{ min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' }
]
}
},
computed: {
tableData: {
get() {
return this.dynamicForm.tableData;
},
set(value) {
this.dynamicForm.tableData = value;
}
}
},
created() {
// 初始化一行数据
this.addRow();
},
methods: {
addRow() {
this.tableData.push({
adjustAmount: '',
adjustReason: ''
});
},
deleteRow(index) {
if (this.tableData.length <= 1) {
this.$message.warning('至少保留一行数据');
return;
}
this.tableData.splice(index, 1);
},
showTableData() {
const formattedData = this.tableData.map((row, index) => ({
序号: index + 1,
调整金额: row.adjustAmount,
调整事由: row.adjustReason
}));
console.log('当前表格数据:', formattedData);
this.$message.success('表格数据已打印到控制台');
},
validateForm() {
this.$refs.dynamicForm.validate(valid => {
if (valid) {
this.$message.success('验证通过,表单数据有效');
this.showTableData();
} else {
this.$message.error('请检查表单,确保所有必填项已填写');
return false;
}
});
}
}
}
</script>
<style scoped>
.dynamic-table-container {
padding: 20px;
}
.el-form-item {
margin-bottom: 0;
}
</style>
......@@ -61,7 +61,7 @@
</el-form-item>
<el-form-item v-if="isTmpl" label="对账模版:" prop="templateId">
<el-select v-model="infoForm.templateId" style="width:400px" @change="handleTmplChange">
<el-option v-for="item in baseData.templateList" :key="item.id" :label="item.templateName" :value="item.id" />
<el-option v-for="item in baseData[merchantTypeStr + 'TemplateList']" :key="item.id" :label="item.templateName" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item v-if="isTmpl" label="对账字段:" prop="fieldsJson">
......@@ -151,6 +151,13 @@ export default {
fieldsJson: ''
},
// 1 - traffic; 2 - service
merchantTypeStr: 'traffic',
typeObj: {
'2': 'traffic',
'7': 'service'
},
formRules: {
merchantType: [{ required: true, message: '请选择商户类型', trigger: 'change' }],
merchant: [
......@@ -190,7 +197,10 @@ export default {
confLabel: '门店收款'
}],
merchantList: [],
templateList: [],
// 流量方对账单
trafficTemplateList: [],
// 服务商对账单
serviceTemplateList: [],
shopMerchantList: []
},
yqCheckVisible: true
......@@ -279,6 +289,7 @@ export default {
*/
judgeTmpl() {
this.isTmpl = this.infoForm.merchantType == '2' || (this.infoForm.merchantType == '7' && this.infoForm.reportType == '4');
this.merchantTypeStr = this.typeObj[this.infoForm.merchantType]
this.resetTmplData()
},
......@@ -286,6 +297,9 @@ export default {
this.infoForm.shopMerchantId = ''
this.infoForm.templateId = ''
this.infoForm.fieldsJson = ''
this.infoForm.fieldsTxt = ''
this.infoForm.tmplType
this.tmplSelectList = []
const ruleAttrList = ['templateId', 'fieldsJson']
ruleAttrList.forEach(item => {
this.formRules[item][0].required = this.isTmpl
......@@ -326,13 +340,21 @@ export default {
pageSize: 9999,
currentPage: 1
}
getTmplList(params).then(res => {
this.baseData.templateList = res.list || []
// 流量方
getTmplList({...params, type: 1}).then(res => {
this.baseData.trafficTemplateList = res.list || []
})
// 服务商
getTmplList({...params, type: 2}).then(res => {
this.baseData.serviceTemplateList = res.list || []
})
},
handleTmplChange(e) {
const item = this.baseData.templateList.find(item => item.id == e)
if(!(Object.keys(this.typeObj)).includes(this.infoForm.merchantType)) {
return true
}
const item = this.baseData[this.merchantTypeStr + 'TemplateList'].find(item => item.id == e)
this.infoForm.fieldsTxt = item?.fieldNames
this.infoForm.tmplType = item?.type
this.tmplSelectList = item?.fieldIds
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!