YYGH-1-医院管理

YYGH-医院管理

前言

我们之前通过Spring Cloud Nacos实现了对于医院列表的显示,接下来我们试着整合前端

做到一个这样的效果
请添加图片描述

这是我们现在接口查到的数据
请添加图片描述

医院列表

1.1 添加路由

在 src/router/index.js 文件添加路由

       {

        path: 'hosp/list',

        name: '医院列表',

        component: () => import('@/views/hosp/list'),

        meta: { title: '医院列表', icon: 'table' }

      },
1.2封装api请求

创建/api/hosp.js

  //医院设置列表方法
  getList(page, limit, searchObj) {
    return request({
      url: `/admin/hosp/hospital/list/${page}/${limit}`,
      method: 'get',
      params: searchObj // 使用json形式进行传递
    })
  },
  //根据dictcode查询相关子结点(所有省)
  findByDictCode(dictCode) {
    return request({
      url: `/admin/cmn/dict/findDictCode/${dictCode}`,
      method: 'get'
    })
  },
  findChildId(id) {
    return request({
      url: `/admin/cmn/dict/findChildData/${id}`,
      method: 'get'
    })
  },
1.3 添加组件

创建/views/hosp/hospital/list.vue组件

<template>
<div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
    <el-form-item>
        <el-select
            v-model="searchObj.provinceCode"
            placeholder="请选择省"
                @change="provinceChanged">
            <el-option
                v-for="item in provinceList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"/>
        </el-select>
    </el-form-item>

    <el-form-item>
        <el-select
        v-model="searchObj.cityCode"
        placeholder="请选择市"
        @change="cityChanged">
            <el-option
            v-for="item in cityList"
            :key="item.id"
            :label="item.name"
            :value="item.id"/>
        </el-select>
    </el-form-item>

    <el-form-item>
        <el-input v-model="searchObj.hosname" placeholder="医院名称"/>
    </el-form-item>

    <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
    <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

<!-- banner列表 -->
<el-table v-loading="listLoading" :data="list"
        border
      fit
      highlight-current-row>

    <el-table-column
    label="序号"
    width="60"
    align="center">
        <template slot-scope="scope">
                {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
    </el-table-column>

    <el-table-column label="医院logo">
        <template slot-scope="scope">
        <img :src="'data:image/jpeg;base64,'+scope.row.logoData" width="80">
        </template>
    </el-table-column>

    <el-table-column prop="hosname" label="医院名称"/>
    <el-table-column prop="param.hostypeString" label="等级" width="90"/>
    <el-table-column prop="param.fullAddress" label="详情地址"/>
    <el-table-column label="状态" width="80">
        <template slot-scope="scope">
                {{ scope.row.status === 0 ? '未上线' : '已上线' }}
        </template>
    </el-table-column>
    <el-table-column prop="createTime" label="创建时间"/>

        <el-table-column label="操作" width="230" align="center">
            <template slot-scope="scope">
                <router-link :to="'/hospSet/hospital/show/'+scope.row.id">
                    <el-button type="primary" size="mini">查看</el-button>
                </router-link>
                <router-link :to="'/hospSet/hospital/schedule/'+scope.row.hoscode">
                    <el-button type="primary" size="mini">排班</el-button>
                </router-link>

                <el-button v-if="scope.row.status == 1"  type="primary" size="mini" @click="updateStatus(scope.row.id, 0)">下线</el-button>
                <el-button v-if="scope.row.status == 0"  type="danger" size="mini" @click="updateStatus(scope.row.id, 1)">上线</el-button>
            </template>

        </el-table-column>

</el-table>

    <!-- 分页组件 -->
    <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
    />
</div>
</template>

<script>
import hospitalApi from '@/api/hosp'
export default {
    data() {
        return {
            listLoading: true, // 数据是否正在加载
            list: null, // banner列表
            total: 0, // 数据库中的总记录数
            page: 1, // 默认页码
            limit: 10, // 每页记录数
            searchObj: {}, // 查询表单对象
            provinceList: [],
            cityList: [],
            districtList: []
        }
    },

    // 生命周期函数:内存准备完毕,页面尚未渲染
    created() {
        console.log('list created......')
        this.fetchData()

        hospitalApi.findByDictCode('Province').then(response => {
            this.provinceList = response.data
        })
    },

    methods: {
        // 加载banner列表数据
        fetchData(page = 1) {
            console.log('翻页。。。' + page)
            // 异步获取远程数据(ajax)
            this.page = page
            hospitalApi.getList(this.page, this.limit, this.searchObj).then(
                response => {
                this.list = response.data.content
                this.total = response.data.totalElements

                    // 数据加载并绑定成功
                this.listLoading = false
                }
            )
        },

        // 当页码发生改变的时候
        changeSize(size) {
            console.log(size)
            this.limit = size
            this.fetchData(1)
        },

        // 重置查询表单
        resetData() {
            console.log('重置查询表单')
            this.searchObj = {}
            this.fetchData()
        },
        provinceChanged() {
            this.cityList = []
            this.searchObj.cityCode = null
            this.districtList = []
            this.searchObj.districtCode = null
            hospitalApi.findChildId(this.searchObj.provinceCode).then(response => {
            this.cityList = response.data
        })
        },

        //更新医院设置
        updateStatus(id,status){
            hospitalApi.updateStatus(id,status).then(
                response => {
                    this.fetchData(1)
                }
            )
        }
    }
}
</script>
1.4CMN设置

通过上面的代码可以很清楚的看到我们新添加了两个API

/admin/cmn/dict/findDictCode/:根据DictCode查询

/admin/cmn/dict/findChildData/:查询子结点

Controller类

@ApiOperation(value = "根据dictCode获取下级结点")
@GetMapping("findDictCode/{dictCode}")
public Result findByDictCode(@PathVariable String dictCode){
    List<Dict> list = dictService.findByDictCode(dictCode);
    return Result.ok(list);
}

//根据数据id查询子数据列表
@ApiOperation(value = "根据数据id查询子数据列表")
@GetMapping("findChildData/{id}")
public Result findChildData(@PathVariable long id) {
    List<Dict> childData = dictService.findChildData(id);
    return Result.ok(childData);
}

Service类

//根据数据id查询子数据列表
@Cacheable(value = "dict",keyGenerator = "keyGenerator")
@Override
public List<Dict> findChildData(long id) {
    log.info("通过数据库查询");
    QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("parent_id", id);
    List<Dict> dicts = baseMapper.selectList(queryWrapper);
    for (Dict dict : dicts) {
        Long id1 = dict.getId();
        boolean children = this.isChildren(id1);
        dict.setHasChildren(children);
    }
    return dicts;
}

public Dict getDictByDictCode(String dictCode){
    QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("dict_code",dictCode);
    Dict dict = baseMapper.selectOne(queryWrapper);
    return dict;
}

通过这两个设置我们可以实现这样的功能

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Xdijzcae-1647824108127)(C:\Users\86157\AppData\Local\Temp\1647791964594.png)]

省市联查

1.5Hosp设置
//医院列表
@GetMapping("list/{page}/{limit}")
public Result listHosp(@PathVariable("page") Integer page,
                       @PathVariable("limit") Integer limit,
                       HospitalQueryVo hospitalQueryVo) {
    Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
    return Result.ok(pageModel);
}

这个条件查询我们之前早已经准备好了在

package com.example.yygh.hosp.service.impl;

@Override
public Page<Hospital> selectHospPage(Integer page, Integer limit, HospitalQueryVo hospitalQueryVo) {
    //创建Pageable对象
    Pageable pageable = PageRequest.of(page - 1, limit);
    //创建条件匹配器
    //之所以能实现模糊查询是因为在这创建了条件匹配器
    ExampleMatcher matcher = ExampleMatcher.matching()
            .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
            .withIgnoreCase(true);
    //hospitalSetQueryVO转化为Hospital对象
    Hospital hospital = new Hospital();
    BeanUtils.copyProperties(hospitalQueryVo, hospital);
    //创建对象
    Example<Hospital> example = Example.of(hospital, matcher);
    Page<Hospital> all = hospitalRepository.findAll(example, pageable);
    //调用dictFeignClient
    //获取查询List集合,遍历进行医院等级封装
    all.getContent().stream().forEach(item -> {
        this.setHospitalHosType(item);
    });
    return all;
}

我们通过这个hospitalQueryVo将我们的条件封装进去进而得到我们的条件查询的值

医院状态更新

2.1前端部分
<el-button v-if="scope.row.status == 1"  type="primary" size="mini" @click="updateStatus(scope.row.id, 0)">下线</el-button>
<el-button v-if="scope.row.status == 0"  type="danger" size="mini" @click="updateStatus(scope.row.id, 1)">上线</el-button>

        //更新医院设置
        updateStatus(id,status){
            hospitalApi.updateStatus(id,status).then(
                response => {
                    this.fetchData(1)
                }
            )
        }

src.api.hosp.js

  //更新状态
  updateStatus(id, status) {
    return request({
      url: `/admin/hosp/hospital/updateHospSttatus/${id}/${status}`,
      method: 'get'
    })
  },
2.2Service类
//更新医院状态
@Override
public void updateHospStatus(String id, Integer status) {
    //根据id查询医院信息
    Hospital hospital = hospitalRepository.findById(id).get();
    //修改值
    hospital.setStatus(status);
    hospital.setUpdateTime(new Date());
    hospitalRepository.save(hospital);
}
2.3Controller类
@ApiOperation(value = "更新医院上线状态")
@GetMapping("updateHospSttatus/{id}/{status}")
public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status){
    hospitalService.updateHospStatus(id, status);
    return Result.ok();
}

医院详情

3.1Conrtoller类
//医院详情
@ApiOperation(value = "医院详情")
@GetMapping("showHospDetail/{id}")
public Result showHospDetail(@PathVariable String id){
    Map<String,Object> map = hospitalService.selectHospDetail(id);
    return Result.ok(map);
}
3.2Service类
@Override
public Map<String, Object> selectHospDetail(String id) {
    Hospital hospital = hospitalRepository.findById(id).get();
    Hospital hospital1 = this.setHospitalHosType(hospital);
    Map<String, Object> map = new HashMap<>();
    //医院基本信息
    map.put("hospital",hospital);
    //医院的预约信息
    map.put("bookingRule",hospital1.getBookingRule());
    return map;
}

之所有封装为一个map是为了我们以后做排版信息的时候方便

3.2前端部分

前端部分路由

      {
        path: 'hospital/show/:id',
        name: '查看',
        component: () => import('@/views/hosp/show'),
        meta: { title: '查看', noCache: true },
        hidden: true
      },

这里我们用的是隐匿路由

前端部分接口

  //查看医院详情
  getHospById(id) {
    return request({
      url: `/admin/hosp/hospital/showHospDetail/${id}`,
      method: 'get'
    })
  }

前端页面

<template>
  <div class="app-container">
    <h4>基本信息</h4>
    <table
      class="table table-striped table-condenseda table-bordered"
      width="100%"
    >
      <tbody>
        <tr>
          <th width="15%">医院名称</th>
          <td width="35%">
            <b style="font-size: 14px">{{ hospital.hosname }}</b> |
            {{ hospital.param.hostypeString }}
          </td>
          <th width="15%">医院logo</th>
          <td width="35%">
            <img
              :src="'data:image/jpeg;base64,' + hospital.logoData"
              width="80"
            />
          </td>
        </tr>
        <tr>
          <th>医院编码</th>
          <td>{{ hospital.hoscode }}</td>
          <th>地址</th>
          <td>{{ hospital.param.fullAddress }}</td>
        </tr>
        <tr>
          <th>坐车路线</th>
          <td colspan="3">{{ hospital.route }}</td>
        </tr>
        <tr>
          <th>医院简介</th>
          <td colspan="3">{{ hospital.intro }}</td>
        </tr>
      </tbody>
    </table>

    <h4>预约规则信息</h4>
    <table
      class="table table-striped table-condenseda table-bordered"
      width="100%"
    >
      <tbody>
        <tr>
          <th width="15%">预约周期</th>
          <td width="35%">{{ bookingRule.cycle }}天</td>
          <th width="15%">放号时间</th>
          <td width="35%">{{ bookingRule.releaseTime }}</td>
        </tr>
        <tr>
          <th>停挂时间</th>
          <td>{{ bookingRule.stopTime }}</td>
          <th>退号时间</th>
          <td>
            {{ bookingRule.quitDay == -1 ? "就诊前一工作日" : "就诊当日"
            }}{{ bookingRule.quitTime }} 前取消
          </td>
        </tr>
        <tr>
          <th>预约规则</th>
          <td colspan="3">
            <ol>
              <li v-for="item in bookingRule.rule" :key="item">{{ item }}</li>
            </ol>
          </td>
        </tr>
        <br />
        <el-row>
          <el-button @click="back">返回</el-button>
        </el-row>
      </tbody>
    </table>
  </div>
</template>
<script>
import hospApi from '@/api/hosp'
export default {
    data() {
        return {
            hospital: null,  //医院信息
            bookingRule: null //预约信息
        }
    },
    created() {
        //获取路由id
        const id = this.$route.params.id
        //调用方法,根据id查询医院详情
        this.fetachHospDetail(id)
    },
    methods:{
        //根据id查询医院详情
        fetachHospDetail(id) {
            hospApi.getHospById(id)
                .then(response => {
                    this.hospital = response.data.hospital
                    this.bookingRule = response.data.bookingRule
                })
        },
        //返回医院列表
        back() {
            this.$router.push({ path: '/hospSet/hosp/list' })
        }
    }
}
</script>


eated() {
        //获取路由id
        const id = this.$route.params.id
        //调用方法,根据id查询医院详情
        this.fetachHospDetail(id)
    },
    methods:{
        //根据id查询医院详情
        fetachHospDetail(id) {
            hospApi.getHospById(id)
                .then(response => {
                    this.hospital = response.data.hospital
                    this.bookingRule = response.data.bookingRule
                })
        },
        //返回医院列表
        back() {
            this.$router.push({ path: '/hospSet/hosp/list' })
        }
    }
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值