elementui el-table+el-input多行数据复制和删除

效果图

<el-dialog title="添加/编辑" :visible.sync="dialogFormVisible" @opened="opendDialogForm()" @close='closeDialog'>
        <el-form :model="formData" :rules="rules" ref="formData" label-width="100px" >
           <el-form-item label="课程安排">
                <div class="item-wrap">
                    <div class="flex item flexcenter flexbetween outline-header">
                        <el-table :data="formData.outline" style="width: 100%">
                            <el-table-column prop="date" label="序号" width="60">
                                <template slot-scope="scope">
                                    第{{scope.$index +1}}讲
                                </template>
                            </el-table-column>
                            <el-table-column prop="outline_title" label="大纲标题" >
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.outline_title" placeholder="请输入内容"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column prop="course_day" label="上课日期" width="150">
                                <template slot-scope="scope">
                                    <el-date-picker
                                            v-model="scope.row.course_day"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>
                                </template>
                            </el-table-column>
                            <el-table-column prop="start_time" label="开始时间" width="150">
                                <template slot-scope="scope">
                                    <el-time-picker
                                            v-model="scope.row.start_time"
                                            type="time"
                                            placeholder="选择时间" value-format="HH:mm:ss" >
                                    </el-time-picker>
                                </template>
                            </el-table-column>
                            <el-table-column  prop="end_time" label="结束时间" width="150">
                                <template slot-scope="scope">
                                    <el-time-picker
                                            v-model="scope.row.end_time"
                                            type="time"
                                            placeholder="选择时间" value-format="HH:mm" >
                                    </el-time-picker>
                                </template>
                            </el-table-column>
                            <el-table-column  prop="end_time" label="结束时间" width="120">
                                <template slot="header" slot-scope="scope">
                                    <el-button size="middle" type="success" @click="applyCourseData">应用全部</el-button>
                                </template>
                                <template slot-scope="scope">
                                    <el-button size="middle" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit('formData')">确 定</el-button>
                <el-button @click="dialogFormVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
<script>
    var my = new Vue({
        el: "#myApp",
        data: {
            dialogFormVisible: false,
            formData: {
                id: 0,
                class_name: '',
                school_id:'',
                teacher_uid: '',
                class_type: '1',
                course_id: '',
                grade_id: '',
                outline: [
                    {
                        id: 0,
                        outline_title: '',
                        course_day: '',
                        start_time: '',
                        end_time: '',
                    }
                ]
            },
            rules: {
              
            },
        },
        methods: {
            applyCourseData(){
                var that = this;
                this.$confirm('应用全部项, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    for (var i = 1; i< that.formData.outline.length ; i++){
                        that.formData.outline[i]['outline_title'] = that.formData.outline[0]['outline_title'];
                        that.formData.outline[i]['course_day'] = that.formData.outline[0]['course_day'];
                        that.formData.outline[i]['start_time'] = that.formData.outline[0]['start_time'];
                        that.formData.outline[i]['end_time'] = that.formData.outline[0]['end_time'];
                        this.$set(that.formData.outline, 'outline_title'  ,that.formData.outline[1])
                    }

                }).catch(() => {

                });
            },
            handleDelete(index,item){
                console.log(item)
                var that = this;
                this.$confirm('删除后不能恢复, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(Url({a:'delCourse' , q:{id:item.id}})).then(res => {
                        this.$message({
                            message: res.data.msg,
                            type: res.data.code === 200 ? 'success' : 'error',
                        })
                    });
                    that.formData.outline.splice(index,1);
                }).catch(() => {

                });
            }
        },
        mounted(){
            this.doLoadRows()
        }
    });
</script>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值