Jelajahi Sumber

fead:切换就诊人

lsw 9 bulan lalu
induk
melakukan
72de9e70e2

+ 1 - 1
app/App.vue

@@ -30,7 +30,7 @@ button::after {
 /**挂载iconfont字体图标*/
 @font-face {
 	font-family: 'iconfont';
-	src: url('https://at.alicdn.com/t/c/font_4620946_71l23z3aw5o.ttf?t=1721929654519') format('truetype');
+	src: url('https://at.alicdn.com/t/c/font_4620946_zhmq38l0vzq.ttf?t=1721980812832') format('truetype');
 	/* src: url('~@/static/font/iconfont.ttf') format('truetype'); */
 }
 .icon {

+ 0 - 1
app/pages/index/index.vue

@@ -192,7 +192,6 @@ page {
 	.gg {
 		font-weight: bold;
 		margin-bottom: 5px;
-		color: $font-c;
 		overflow: hidden;
 		.title {
 			margin-left: 10px;

+ 10 - 2
app/pages/user/bind/add.vue

@@ -2,7 +2,7 @@
 	<view class="main">
 		<view class="form_group">
 			<view class="lable re">手机号</view>
-			<input type="digit" v-model="item.money" placeholder="请输入手机号" />
+			<input type="digit" v-model="item.phone" placeholder="请输入手机号" />
 		</view>
 		<button class="btn" @click="add()">确认</button>
 	</view>
@@ -22,7 +22,15 @@ export default {
 				method: 'POST',
 				data: this.item,
 				success: (res) => {
-					
+					uni.showModal({
+						title: '提示',
+						content: '绑定成功',
+						showCancel: false,
+						success: (res) => {
+							uni.$emit('bind');
+							uni.navigateBack();
+						}
+					});
 				}
 			});
 		}

+ 35 - 25
app/pages/user/bind/index.vue

@@ -1,15 +1,12 @@
 <template>
 	<view class="main">
 		<view class="list">
-			<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/knowledge/detail?id=' + item.id)">
+			<view class="item" v-for="(item, index) in list" :key="index" @click="go(item)">
 				<view class="title omit">
-					<text class="icon" v-if="item.top === 1">&#xe61f;</text>
-					<text>{{ item.title }}</text>
-				</view>
-				<view class="desc">
-					<text>{{ item.type }}</text>
-					<text>发布于 {{ item.createTime }}</text>
+					<text>{{ item.patientName }}</text>
+					<text class="icon check" v-if="item.state == 1">&#xe63b;</text>
 				</view>
+				<view class="icon del" @click.stop="del(item)">&#xe641;</view>
 			</view>
 			<u-empty v-if="list.length == 0" text="你还未绑定就诊人"></u-empty>
 		</view>
@@ -31,20 +28,39 @@ export default {
 	},
 	onLoad(e) {
 		this.getData();
+		uni.$on('bind', (res) => {
+			this.getData();
+		});
 	},
 	methods: {
 		getData() {
 			this.http.request({
 				url: '/app/user/bind/list',
 				data: this.param,
-				loading: 'false',
 				success: (res) => {
 					this.list = res.data.data;
 				}
 			});
 		},
+		del(item) {
+			uni.showModal({
+				title: '提示',
+				content: '确定移除当前就诊人?',
+				success: (res) => {
+					if (res.confirm) {
+						this.http.request({
+							url: '/app/user/bind/remove/' + item.id,
+							success: (res) => {
+								uni.showToast({ title: '移除成功' });
+								this.list.splice(this.list.indexOf(item), 1);
+							}
+						});
+					}
+				}
+			});
+		},
 		go(url) {
-			uni.navigateTo({ url: url });
+			//uni.navigateTo({ url: url });
 		}
 	}
 };
@@ -52,31 +68,25 @@ export default {
 
 <style lang="scss">
 .list {
-	padding: 10px 12px;
 	background-color: white;
-	margin: 10px;
 	border-radius: 10px;
 	.item {
-		border-radius: 5px;
-		padding: 13px 12px 13px 12px;
-		margin-bottom: 10px;
-		overflow: hidden;
+		padding: 16px 12px 16px 12px;
 		border-bottom: 1px solid $line;
+		overflow: hidden;
 		.title {
 			font-size: 15px;
 			font-weight: bold;
-			.icon {
-				color: orangered;
-				padding-right: 3px;
+			.check {
+				color: $main-color;
+				padding-left: 5px;
 			}
 		}
-		.desc {
-			font-size: 14px;
-			padding-top: 10px;
-			color: $font-c;
-			text {
-				padding-right: 30px;
-			}
+		.del {
+			color: #f44336;
+			float: right;
+			margin-top: -20px;
+			font-size: 20px;
 		}
 	}
 }

+ 22 - 1
app/pages/user/index.vue

@@ -3,7 +3,10 @@
 		<view class="user" @click="go('/pages/user/bind/index')">
 			<image :src="user.avatar ? ip + user.avatar : '../../static/favicon.png'" class="head"></image>
 			<view class="con" v-if="user.id">
-				<view class="nickName">{{ user.patientName ? user.patientName : '还未绑定就诊人' }}</view>
+				<view class="nickName">
+					{{ user.patientName ? user.patientName : '还未绑定就诊人' }}
+					<text class="icon" v-if="user.bindUserList.length > 1" @click.stop="show = true">&#xe6a7;</text>
+				</view>
 				<view class="welcome">欢迎使用岑溪人民医院小程序</view>
 			</view>
 			<view class="con" v-else>
@@ -39,6 +42,7 @@
 				<text class="icon arrow">&#xe62b;</text>
 			</view>
 		</view>
+		<u-action-sheet round="20" :actions="user.bindUserList" key="patientName" @select="selectClick" cancelText="取消" :show="show" @close="show = false"></u-action-sheet>
 	</view>
 </template>
 <script>
@@ -70,6 +74,23 @@ export default {
 				}
 			});
 		},
+		//切换就诊人
+		selectClick(e) {
+			uni.showModal({
+				title: '提示',
+				content: '确定切换就诊人',
+				success: (res) => {
+					if (res.confirm) {
+						this.http.request({
+							url: '/app/user/bind/change/' + e.id,
+							success: (res) => {
+								this.getUserInfo();
+							}
+						});
+					}
+				}
+			});
+		},
 		go(url) {
 			if (this.hasLogin()) {
 				uni.navigateTo({ url: url });

+ 1 - 1
app/uni_modules/uview-ui/components/u-action-sheet/u-action-sheet.vue

@@ -68,7 +68,7 @@
 									<text
 									    class="u-action-sheet__item-wrap__item__name"
 									    :style="[itemStyle(index)]"
-									>{{ item.name }}</text>
+									>{{ item.patientName }}</text>
 									<text
 									    style="width: 90%;color: blue;margin-top: 5px;"
 									    v-if="item.subname"

+ 1 - 1
app/uni_modules/uview-ui/components/u-empty/u-empty.vue

@@ -89,7 +89,7 @@ $u-empty-slot-margin-top: 20rpx !default;
 		justify-content: center;
 		align-items: center;
 		margin-top: -10px;
-		padding-bottom: 10px;
+		padding-bottom: 20px;
 	}
 }
 .u-slot-wrap {

+ 11 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/work/api/Api_UserController.java

@@ -35,10 +35,20 @@ public class Api_UserController extends BaseController {
     }
 
     @PostMapping("/bind")
-    public AjaxResult bind(@Validated @RequestBody BindDto dto) {
+    public AjaxResult bind(@Validated @RequestBody BindDto dto) throws ServerException {
         return bindUserService.bind(dto);
     }
 
+    @GetMapping(value = "/bind/remove/{id}")
+    public AjaxResult remove(@PathVariable("id") Long id) throws ServerException {
+        return bindUserService.remove(id);
+    }
+
+    @GetMapping(value = "/bind/change/{id}")
+    public AjaxResult change(@PathVariable("id") Long id) throws ServerException {
+        return bindUserService.change(id);
+    }
+
     @GetMapping("/bind/list")
     public AjaxResult list(BindUser bindUser) {
         bindUser.setUserId(getUser().getId());

+ 6 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/work/domain/BindUser.java

@@ -27,20 +27,18 @@ public class BindUser{
     @ApiModelProperty(value = "小程序id")
     private Long userId;
 
+    @ApiModelProperty(value = "患者姓名")
+    private String patientName;
+
+    @ApiModelProperty(value = "状态:0=未启用,1=当前就诊人")
+    private Integer state;
+
     @TableField(fill = FieldFill.INSERT)
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
-    @ApiModelProperty(value = "患者姓名")
-    @TableField(exist = false)
-    private String patientName;
-
     @ApiModelProperty(value = "患者手机号")
     @TableField(exist = false)
     private String phone;
 
-    @ApiModelProperty(value = "患者身份证")
-    @TableField(exist = false)
-    private String sfzh;
-
 }

+ 5 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/work/domain/User.java

@@ -9,6 +9,8 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 
 import java.util.Date;
+import java.util.List;
+
 /**
  * @author lsw
  * @date 2024-07-16
@@ -48,6 +50,9 @@ public class User{
     private Date updateTime;
 
     @TableField(exist = false)
+    private List<BindUser> bindUserList;
+
+    @TableField(exist = false)
     private String token;
 
 }

+ 7 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/work/mapper/BindUserMapper.java

@@ -2,6 +2,7 @@ package com.ruoyi.web.work.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.web.work.domain.BindUser;
+import com.ruoyi.web.work.domain.Patient;
 
 import java.util.List;
 
@@ -12,4 +13,10 @@ import java.util.List;
 public interface BindUserMapper extends BaseMapper<BindUser> {
     List<BindUser> selectList(BindUser bindUser);
 
+    Patient selectPatient(Patient patient);
+
+    BindUser selectBindUser(BindUser bindUser);
+
+    boolean changeBindUser(BindUser bindUser);
+
 }

+ 20 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/work/service/IBindUserService.java

@@ -5,19 +5,37 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.web.work.domain.BindUser;
 import com.ruoyi.web.work.domain.dto.BindDto;
 
+import java.rmi.ServerException;
 import java.util.List;
 
 /**
  * @author lsw
  * @date 2024-07-26
  */
-public interface IBindUserService extends IService<BindUser>{
+public interface IBindUserService extends IService<BindUser> {
     List<BindUser> selectList(BindUser bindUser);
 
     /**
      * 绑定就诊人
+     *
      * @param dto
      * @return
      */
-    AjaxResult bind(BindDto dto);
+    AjaxResult bind(BindDto dto) throws ServerException;
+
+    /**
+     * 移除就诊人
+     *
+     * @param id
+     * @return
+     */
+    AjaxResult remove(Long id) throws ServerException;
+
+    /**
+     * 切换就诊人
+     *
+     * @param id
+     * @return
+     */
+    AjaxResult change(Long id) throws ServerException;
 }

+ 73 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/work/service/impl/BindUserServiceImpl.java

@@ -2,13 +2,20 @@ package com.ruoyi.web.work.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.web.work.api.config.TokenServices;
+import com.ruoyi.web.work.api.util.AppUtil;
 import com.ruoyi.web.work.domain.BindUser;
+import com.ruoyi.web.work.domain.Patient;
+import com.ruoyi.web.work.domain.User;
 import com.ruoyi.web.work.domain.dto.BindDto;
 import com.ruoyi.web.work.mapper.BindUserMapper;
 import com.ruoyi.web.work.service.IBindUserService;
+import com.ruoyi.web.work.service.IUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.rmi.ServerException;
 import java.util.List;
 
 /**
@@ -20,13 +27,77 @@ public class BindUserServiceImpl extends ServiceImpl<BindUserMapper, BindUser> i
     @Autowired
     private BindUserMapper bindUserMapper;
 
+    @Autowired
+    IUserService userService;
+
+    @Autowired
+    private TokenServices tokenService;
+
     @Override
     public List<BindUser> selectList(BindUser bindUser) {
         return bindUserMapper.selectList(bindUser);
     }
 
+    @Transactional
+    @Override
+    public AjaxResult bind(BindDto dto) throws ServerException {
+        Patient patient = bindUserMapper.selectPatient(new Patient().setPhone(dto.getPhone()));
+        if (patient == null) {
+            return AjaxResult.error("预留的就诊人手机号不存在");
+        }
+        BindUser bindUser = new BindUser();
+        bindUser.setPatientId(patient.getId());
+        bindUser.setUserId(AppUtil.getUser().getId());
+        bindUser.setPatientName(patient.getName());
+        if (bindUserMapper.selectBindUser(bindUser) != null) {
+            return AjaxResult.error("你已绑定过该就诊人");
+        }
+        //如果只有一个就诊人直接设置成当前就诊人
+        List<BindUser> bindUserList = bindUserMapper.selectList(new BindUser().setUserId(AppUtil.getUser().getId()));
+        if (bindUserList.size() == 0) {
+            bindUser.setState(1);
+            User user = AppUtil.getUser();
+            user.setPatientId(patient.getId());
+            user.setPatientName(patient.getName());
+            if (!userService.updateById(user)) {
+                throw new ServerException("绑定就诊人失败");
+            }
+        }
+        if (!save(bindUser)) {
+            throw new ServerException("绑定就诊人失败");
+        }
+        return AjaxResult.success();
+    }
+
+    @Override
+    public AjaxResult remove(Long id) throws ServerException {
+        BindUser bindUser = getById(id);
+        if (bindUser == null || !bindUser.getUserId().equals(AppUtil.getUser().getId())) {
+            return AjaxResult.error("数据不存在或非法操作");
+        }
+        if (!removeById(id)) {
+            throw new ServerException("删除就诊人失败");
+        }
+        return AjaxResult.success();
+    }
+
+    @Transactional
     @Override
-    public AjaxResult bind(BindDto dto) {
-        return null;
+    public AjaxResult change(Long id) throws ServerException {
+        BindUser bindUser = getById(id);
+        if (bindUser == null || !bindUser.getUserId().equals(AppUtil.getUser().getId())) {
+            return AjaxResult.error("数据不存在或非法操作");
+        }
+        bindUserMapper.changeBindUser(bindUser);
+        bindUser.setState(1);
+        updateById(bindUser);
+        User user = AppUtil.getUser();
+        user.setPatientId(bindUser.getPatientId());
+        user.setPatientName(bindUser.getPatientName());
+        if (!userService.updateById(user)) {
+            throw new ServerException("切换就诊人失败");
+        }
+        tokenService.setLoginUser(userService.getById(AppUtil.getUser().getId()).setToken(AppUtil.getUser().getToken()));
+        return AjaxResult.success();
     }
 }

+ 8 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/work/service/impl/UserServiceImpl.java

@@ -9,10 +9,12 @@ import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
 import com.ruoyi.web.work.api.config.TokenServices;
 import com.ruoyi.web.work.api.util.AppUtil;
+import com.ruoyi.web.work.domain.BindUser;
 import com.ruoyi.web.work.domain.User;
 import com.ruoyi.web.work.domain.dto.LoginDto;
 import com.ruoyi.web.work.domain.dto.UserEditDto;
 import com.ruoyi.web.work.mapper.UserMapper;
+import com.ruoyi.web.work.service.IBindUserService;
 import com.ruoyi.web.work.service.IUserService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +37,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     private TokenServices tokenService;
 
     @Autowired
+    IBindUserService bindUserService;
+
+    @Autowired
     private Environment env;
 
     @Override
@@ -90,6 +95,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
 
     @Override
     public AjaxResult info() {
-        return AjaxResult.success(getById(AppUtil.getUser().getId()));
+        User user =getById(AppUtil.getUser().getId());
+        user.setBindUserList(bindUserService.selectList(new BindUser().setUserId(user.getId())));
+        return AjaxResult.success(user);
     }
 }

+ 12 - 0
ruoyi-admin/src/main/resources/mapper/work/BindUserMapper.xml

@@ -19,4 +19,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
+    <select id="selectPatient" resultType="com.ruoyi.web.work.domain.Patient">
+        SELECT * FROM tb_patient WHERE phone=#{phone}
+    </select>
+
+    <select id="selectBindUser" resultType="com.ruoyi.web.work.domain.BindUser">
+        SELECT * FROM tb_bind_user WHERE user_id=#{userId} AND patient_id=#{patientId}
+    </select>
+
+    <update id="changeBindUser">
+        UPDATE tb_bind_user SET state = 0 WHERE user_id=#{userId}
+    </update>
+
 </mapper>