02每周总结

02每周总结

发表时间:23.2.28

这周学会了前端页面的编写,用vue和ajax实现,学习了vue和ajax技术
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>

</head>
<body>
<div id="app">

    <!--搜索表单-->
    <el-form :inline="true" :model="brand" class="demo-form-inline">

        <el-form-item label="当前状态">
            <el-select v-model="brand.status" placeholder="当前状态">
                <el-option label="启用" value="1"></el-option>
                <el-option label="禁用" value="0"></el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="企业名称">
            <el-input v-model="brand.companyName" placeholder="企业名称"></el-input>
        </el-form-item>

        <el-form-item label="品牌名称">
            <el-input v-model="brand.brandName" placeholder="品牌名称"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>

    <!--按钮-->

    <el-row>

        <el-button type="danger" plain @click="deleteByIds">批量删除</el-button>
        <el-button type="primary" plain @click="dialogVisible = true">新增</el-button>

    </el-row>

    <el-dialog
            title="新增"
            :visible.sync="dialogVisible"
            width="30%"
            >
        <el-form ref="form" :model="brand" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="brand.brandName"></el-input>
            </el-form-item>

            <el-form-item label="企业名称">
                <el-input v-model="brand.companyName"></el-input>
            </el-form-item>

            <el-form-item label="排序">
                <el-input v-model="brand.ordered"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="brand.description"></el-input>
            </el-form-item>

            <el-form-item label="状态">
                <el-switch v-model="brand.status"
                           active-value="1"
                           inactive-value="0"
                ></el-switch>
            </el-form-item>


            <el-form-item>
                <el-button type="primary" @click="addBrand">提交</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!--表格-->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column
                    type="index"
                    width="50">
            </el-table-column>

            <el-table-column
                    prop="brandName"
                    label="品牌名称"
                    align="center"
            >
            </el-table-column>
            <el-table-column
                    prop="companyName"
                    label="企业名称"
                    align="center"
            >
            </el-table-column>
            <el-table-column
                    prop="ordered"
                    align="center"
                    label="排序">
            </el-table-column>
            <el-table-column
                    prop="statusStr"
                    align="center"
                    label="当前状态">
            </el-table-column>

            <el-table-column
                    align="center"
                    label="操作">


                    <template slot-scope="scope">
                    <el-button type="primary" >修改</el-button>
                    <el-button type="danger" @click="deletedata(scope.row)">删除</el-button>
                    </template>


            </el-table-column>
        </el-table>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentpage"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalCount">
            </el-pagination>


    </template>


</div>


<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
<script src="js/axios-0.18.0.js"></script>

<script>




    new Vue({
        el: "#app",

        mounted(){
            //当页面加载完成后,发送异步请求,获取数据
             this.selectAll();

        },

        methods: {
            addBrand(){
                var _this=this;
                axios(
                    {
                        method:"post",
                        url:"http://localhost:8080/brand-case/brand/add",
                        data:_this.brand
                    }
                ).then(function (resp) {
                   let data = resp.data;
                   if(data=="success")
                   {
                       _this.dialogVisible=false;
                       _this.selectAll();
                       _this.open2();
                   }

                })
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            selectAll(){
                var _this=this;
                axios(
                    {
                        method: "post",
                        url: "http://localhost:8080/brand-case/brand/selectbypageconditon?currentpage="+this.currentpage+"&pagesize="+this.pagesize,
                        data:this.brand
                    }
                ).then(function (resp) {
                    _this.totalCount=resp.data.totalCount;
                    _this.tableData=resp.data.rows;
                })
            },
            open2() {
                this.$message({
                    message: '恭喜你,这是一条成功消息',
                    type: 'success'
                });
            },
            deleteByIds()
            {
                //1.创建id数组
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    this.selectedIds[i]=this.multipleSelection[i].id;
                }
                this.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求
                    var _this=this;
                    axios(
                        {
                            method:"post",
                            url:"http://localhost:8080/brand-case/brand/deletebyids",
                            data:_this.selectedIds
                        }
                    ).then(function (resp) {
                        let data = resp.data;
                        if(data=="success")
                        {

                            _this.selectAll();

                        }

                    })
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },  handleSizeChange(val) {
               this.pagesize=val;
            },
            handleCurrentChange(val) {
                this.currentpage=val;
                this.selectAll();
            },
            onSubmit(){
                this.selectAll();
            },
            deletedata(row){
                var _this=this;
                this.deleteid= row.id;
                axios(
                    {
                        method:"post",
                        url:"http://localhost:8080/brand-case/brand/deletebyid",
                        data:this.deleteid
                    }).then(function (resp) {
                        _this.selectAll();
                    }

                )
            }



        },
        data() {
            return {
                // 品牌模型数据
                brand: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    id: "",
                    ordered: "",
                    description: ""
                },
                tableRowClassName({row, rowIndex}) {
                    if (rowIndex === 1) {
                        return 'warning-row';
                    } else if (rowIndex === 3) {
                        return 'success-row';
                    }
                    return '';
                },
                // 被选中的id数组
                selectedIds:[],
                // 复选框选中数据集合
                multipleSelection: [],
                // 表格数据
                tableData: [],
                dialogVisible: false,
                currentpage:1,
                pagesize:5,
                totalCount:0,
                deleteid:0
            }
        }
    })

</script>

</body>
</html>

 

 

posted @ 2023-02-22 19:18  樱花开到我身边  阅读(15)  评论(0)    收藏  举报