后台管理系统【商品列表】

人生之路不会是一帆风顺的,我们会遇上顺境,也会遇上逆境,在所有成功路上折磨你的,背后都隐藏着激励你奋发向上的动机,人生没有如果,只有后果与结果,成熟,就是用微笑来面对一切小事。

导读:本篇文章讲解 后台管理系统【商品列表】,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

 后台管理系统【商品列表】

 

<template>
	<div>
		<!-- A面包屑导航区域 -->
		<el-breadcrumb separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>商品管理</el-breadcrumb-item>
			<el-breadcrumb-item>商品列表</el-breadcrumb-item>
		</el-breadcrumb>
		<!-- B卡片视图区域 -->
		<el-card>
			<el-row :gutter="20">
				<el-col :span="8">
					<div >
						<el-input
							placeholder="请输入内容"
                            v-model="queryInfo.query"
                            clearable
                            @clear="getGoodsList"
                         >
							<el-button @click="getGoodsList" slot="append" icon="el-icon- 
                               search">
                            </el-button>
						</el-input>
					</div>
				</el-col>
				<el-col :span="4">
                    <el-button type="primary" @click="goAddpage">添加商品</el-button>
                </el-col>
			</el-row>
           <!-- table表格区域 -->
            <el-table :data="goodsList" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column label="商品名称" prop="goods_name"></el-table-column>
                <el-table-column label="商品价格(元)" prop="goods_price" width="95px"> 
                </el-table-column>
                <el-table-column label="商品重量" prop="goods_weight" width="70px">
                </el-table-column>
                <el-table-column label="创建时间" prop="add_time" width="140px">
                    <template slot-scope="scope">
                           {{scope.row.add_time|dataFormat}}  <!--这里用到了自定义的时间过 
                                                      滤器 !!!!!???????-->
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="130px">
                     <!-- 操作  编辑 删除按钮-->
                  <template slot-scope="scope">
                    <!-- {{scope.row}} -->
                   <el-button size="mini" icon="el-icon-edit" type="primary"></el-button>
                   <el-button size="mini" icon="el-icon-delete" type="danger" 
                  @click="removeById(scope.row.goods_id)">
                   </el-button>
                  </template>
                </el-table-column>
            </el-table>
              <!-- 分页区域 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total" background>
            </el-pagination>
		</el-card>
	</div>
</template>

<script>
export default {
	name: "List",
	data() {
		return {
            //查询参数对象
            queryInfo:{
                query:"",
                pagenum:1,
                pagesize:10
            },
            goodsList:[],//商品列表
            total:0,//总数据条数

        };
	},
	created() {
        this.getGoodsList()
    },
	methods: {
        //获取商品列表(根据分页获取对应的商品列表)
       async getGoodsList(){
          const {data:res}=await this.$http.get("goods",{params:this.queryInfo})
            if(res.meta.status!==200){
               return this.$message.error("获取商品列表失败")
            }
            this.$message.success("获取商品列表成功")
            console.log("商品列表的res.data",res.data);
            this.goodsList=res.data.goods
            this.total=res.data.total
        },
        handleSizeChange(newSize){
         this.queryInfo.pagesize=newSize
         this.getGoodsList()
        },
        handleCurrentChange(newPage){
         this.queryInfo.pagenum=newPage
         this.getGoodsList()
        },
        // 根据id删除相应的商品项
        async removeById(id){
         const confirmResult=await this.$confirm('此操作将永久删除该商品, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).catch(err=>err)
        if(confirmResult!=="confirm"){
            return this.$message.info("已取消了删除")
        }//确认删除,继续执行后续操作
        const {data:res}=await this.$http.delete(`goods/${id}`)
          if(res.meta.status!==200){
          return this.$message.error("删除失败")
        }
        this.$message.success("删除成功")
        this.getGoodsList()
        },
        // 点击添加商品按钮时触发
        goAddpage(){
       this.$router.push("/goods/add")
        }
    },
};
</script>

<style lang="less" scoped>
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/126772.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!