用elementui 写一个表单,该表单有四列,九行。第一列是评分名称该列八行分别是工作相关的名词,第二列是自评分,该列的前八行都需要输入评分,第三列是一级评分前八行也需要输入评分,第四列为二级评分前八行也是输入评分 第二、三、四的第九行是分别计算每列输入分的总分
时间: 2024-10-21 20:08:22 浏览: 46
在Element UI中创建这样一个表格表单,你可以使用`el-form`、`el-table`以及一些其他的组件。这里是一个基本的示例:
```html
<template>
<div>
<el-form ref="scoreForm">
<el-table :data="items" style="width: 100%">
<el-table-column label="评分名称" prop="name" width="15%" />
<el-table-column label="自评分" type="textarea" v-for="(item, index) in ['工作能力', '责任心', '团队合作']" :key="index" :prop="'selfScore[' + index + ']'">
<template slot-scope="scope">{{ scope.row[selfScoreIndex(index)] }}</template>
<el-input @input="handleSelfScoreChange(index, $event)" v-model="scope.row[selfScoreIndex(index)]" placeholder="请输入评分" />
</el-table-column>
<el-table-column label="一级评分" type="textarea" v-for="level in ['一级', '二级']" :key="level" :prop="'levelOneScore[' + level + ']'">
<template slot-scope="scope">{{ scope.row[levelOneScoreIndex(index)] }}</template>
<el-input @input="handleLevelOneScoreChange(level, index, $event)" v-model="scope.row[levelOneScoreIndex(index)]" placeholder="请输入评分" />
</el-table-column>
<el-table-column label="二级评分" type="textarea" v-for="level in ['一级', '二级']" :key="level" :prop="'levelTwoScore[' + level + ']'">
<template slot-scope="scope">{{ scope.row[levelTwoScoreIndex(index)] }}</template>
<el-input @input="handleLevelTwoScoreChange(level, index, $event)" v-model="scope.row[levelTwoScoreIndex(index)]" placeholder="请输入评分" />
</el-table-column>
<el-row :span="4" class="total-score-row" v-for="(item, index) in ['工作能力', '责任心', '团队合作', '一级', '二级']" :key="item">
<el-col span="8">
<p>总分:</p>
<p>{{ getTotalScore(item, index) }}</p>
</el-col>
</el-row>
</el-table>
<el-button type="primary" @click="submitForm">提交</el-button>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
items: Array(9).fill({ name: '', selfScore: {}, levelOneScore: {}, levelTwoScore: {} }),
selfScoreIndex(index) { return `selfScore${index}` },
levelOneScoreIndex(level, index) { return `${level}OneScore${index}` },
levelTwoScoreIndex(level, index) { return `${level}TwoScore${index}` },
};
},
methods: {
handleSelfScoreChange(index, value) {
this.items[index].selfScore = Number(value);
},
handleLevelOneScoreChange(level, index, value) {
this.items[index][level + 'OneScore'] = Number(value);
},
handleLevelTwoScoreChange(level, index, value) {
this.items[index][level + 'TwoScore'] = Number(value);
},
getTotalScore(name, index) {
const total = this.items[index].selfScore + this.items[index]['一级OneScore'] + this.items[index]['二级TwoScore'];
return total;
},
submitForm() {
// 提交表单逻辑...
},
},
};
</script>
```
在这个例子中,我们首先定义了一个包含九行数据的对象数组,并通过循环渲染每一行。对于输入部分,我们使用了`el-input`作为文本框,并绑定了`@input`事件处理函数来更新分数。最后一行展示了每个项目的总分,由相应的分数字段相加得出。
阅读全文