前端-医院设置信息修改

1、添加编辑页面的路由(隐藏路由)

在这里插入图片描述

{
  path: 'edit/:id',//:id相当于一个占位符
  name: '医院设置信息修改',
  component: () => import('@/views/hosp/add'),
  meta: { title: '医院设置信息修改', noCache: 'true' },
  hidden:true
}

2、在list.vue页面添加修改按钮

<router-link :to="'/hospSet/edit/'+scope.row.id">
   <el-button type="primary" size="mini" icon="el-icon-edit">编辑</el-button>
</router-link>

其中路由跳转地址 “’/hospSet/edit/’+scope.row.id” 由index.js的路由路径组成。即点击了列表页的修改按钮后,也买你会跳转到隐藏路由—新增页面。
在这里插入图片描述

3、在hospital.js中编写方法调用后端接口

首先根据id查询医院设置信息;
在对医院信息做修改。
在这里插入图片描述

//根据id获取医院设置信息
getHospitalSet(id){
    return request({
        url: `/admin/hosp/hospitalSet/getHospSet/${id}`,
        method: 'get'
    })
},
//医院设置信息修改
updateHospitalSet(hospitalSet){
    return request({
        url: `/admin/hosp/hospitalSet/updateHospitalSet`,
        method: 'post',
        data: hospitalSet
    })
}

4、编写js代码

4.1、点击编辑,跳转到编辑页面,并进行数据回显的js代码

用户点击了编辑按钮后,路由会带上要修改的医院的id,并跳转到编辑页面(编辑页面和新增页面是同一个)
在这里插入图片描述

created () {//页面显示之前渲染
      //如果路由中有参数,并且参数是id
      if(this.$route.params && this.$route.params.id){
         //获取路由id值
         const id = this.$route.params.id
         //调用接口得到医院设置信息
         this.getHostSet(id)
      }
    },
methods: {
    //根据id查询的方法
    getHostSet(id){
      hospset.getHospitalSet(id)//调用js中根据id查询医院信息的方法
         .then(response =>{
            this.hospitalSet = response.data//将查询的信息赋值给hospitalSet对象,并在页面回显数据
         })
    },

4.2、在编辑页面修改数据,并保存

在add.vue页面定义三个方法,一个是添加,一个是修改,这两个方法执行时会调用hospital.js中对应的后端接口方法。

在这里插入图片描述

//根据id查询的方法
getHostSet(id){
  hospset.getHospitalSet(id)//调用js中根据id查询医院信息的方法
     .then(response =>{
        this.hospitalSet = response.data//将查询的信息赋值给hospitalSet对象,并在页面回显数据
     })
},
//添加方法
 save(){
     hospset.saveHospitalSet(this.hospitalSet)
         .then(response=>{
              //提示
                 this.$message({
                     type: 'success',
                     message: '添加成功!'
                 })
                 //跳转到列表页面,使用路由跳转方式实现
                 this.$router.push({path:'/hospset/list'})
         })
         .catch(error=>{

         })
 },
 //修改方法
  update(){
     hospset.updateHospitalSet(this.hospitalSet)
         .then(response=>{
              //提示
                 this.$message({
                     type: 'success',
                     message: '修改成功!'
                 })
                 //跳转到列表页面,使用路由跳转方式实现
                 this.$router.push({path:'/hospset/list'})
         })
         .catch(error=>{

         })
 },

第三个saveOrUpdate方法,用于判断用户的操作:是修改还是添加的操作。
在这里插入图片描述

//用户点击添加页面的保存,判断是添加还是修改
saveOrUpdate(){
   if(!this.hospitalSet.id){//如果没有id,做添加操作
      this.save()
   }else{//有id,做修改操作
      this.update()
   }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值