Files
xk-doctor-wx/subPackages/sub_reception/components/DoctorOrderModal.vue
2026-03-06 13:59:22 +08:00

393 lines
10 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<u-popup
v-model="show"
mode="bottom"
:closeable="true"
@close="handleClose"
:safe-area-inset-bottom="true"
:mask-close-able="false"
z-index="10078"
height="80%"
>
<view class="doctor-order-modal">
<view class="modal-header">
<d-text text="常用医嘱" className="fs-32 main-c"></d-text>
</view>
<view class="modal-content">
<!-- 我的医嘱 -->
<view class="section">
<view class="section-header">
<d-text text="我的医嘱" className="fs-28 content-c"></d-text>
<view class="add-btn" @click="showAddInput = true" v-if="!showAddInput">
<u-icon name="plus" size="16" color="#6ACDBB"></u-icon>
<text class="add-text">添加医嘱</text>
</view>
</view>
<!-- 添加输入框 -->
<view class="add-input-box" v-if="showAddInput">
<u-input
v-model="newOrderContent"
placeholder="输入内容后确认"
:custom-style="inputStyle"
@confirm="addMyDoctorOrder"
/>
<view class="input-actions">
<u-button
@click="cancelAdd"
size="mini"
plain
:custom-style="{ marginRight: '16rpx' }"
>取消</u-button>
<u-button
@click="addMyDoctorOrder"
size="mini"
:custom-style="{ backgroundColor: '#6ACDBB', color: '#fff' }"
>确认</u-button>
</view>
</view>
<!-- 我的医嘱列表 -->
<view class="tag-container">
<view
v-for="item in doctorOrderMyList"
:key="item.id"
class="tag-item"
:class="{ 'selected': item.isSelect === 1 }"
@click="selectDoctorOrder(item, 1)"
>
<text class="tag-text">{{ item.content }}</text>
<view class="tag-action" @click.stop="deleteMyDoctorOrder(item)">
<u-icon name="close" size="14" color="#999"></u-icon>
</view>
</view>
</view>
</view>
<!-- 公共医嘱 -->
<view class="section" v-if="doctorOrderCommonList.length > 0">
<view class="section-header">
<d-text text="公共医嘱" className="fs-28 content-c"></d-text>
</view>
<view class="tag-container">
<view
v-for="item in doctorOrderCommonList"
:key="item.id"
class="tag-item"
:class="{ 'selected': item.isSelect === 1 }"
@click="selectDoctorOrder(item, 2)"
>
<text class="tag-text">{{ item.content }}</text>
</view>
</view>
</view>
</view>
<!-- 底部按钮 -->
<view class="modal-footer">
<u-button
@click="handleClose"
:custom-style="{ backgroundColor: '#f5f5f5', color: '#333' }"
>取消</u-button>
<u-button
@click="handleConfirm"
:custom-style="{ backgroundColor: '#6ACDBB', color: '#fff' }"
>确定</u-button>
</view>
</view>
</u-popup>
</template>
<script>
import { getDoctorOrderList, getDoctorOrderCommonList, createDoctorOrder, deleteDoctorOrder } from '@/api/reception.js';
import { req } from '@/common/js/index.js';
export default {
name: 'DoctorOrderModal',
props: {
value: {
type: Boolean,
default: false
},
selectedDoctorOrder: {
type: String,
default: ''
}
},
data() {
return {
show: false,
doctorOrderCommonList: [],
doctorOrderMyList: [],
selectDoctorOrderList: '',
showAddInput: false,
newOrderContent: '',
inputStyle: {
fontSize: '28rpx',
backgroundColor: '#F3F4F5',
borderRadius: '8rpx',
height: '66rpx',
padding: '8rpx 16rpx'
}
};
},
watch: {
value(newVal) {
this.show = newVal;
if (newVal) {
this.selectDoctorOrderList = this.selectedDoctorOrder || '';
this.getDoctorOrderListData();
}
},
show(newVal) {
if (!newVal) {
this.$emit('input', false);
}
}
},
methods: {
// 获取医嘱列表
async getDoctorOrderListData() {
try {
// 获取我的医嘱
const myRes = await getDoctorOrderList();
if (myRes && (myRes.code === 0 || myRes.errcode === 0)) {
const list = myRes.data || myRes.result || [];
this.doctorOrderMyList = list.map((item) => {
item.isSelect = 0;
if (this.selectDoctorOrderList) {
const valuesArr = this.selectDoctorOrderList.split('');
valuesArr.forEach((value) => {
if (value === item.content) {
item.isSelect = 1;
}
});
}
return item;
});
} else {
this.doctorOrderMyList = [];
}
// 获取公共医嘱
const commonRes = await getDoctorOrderCommonList({
store_id: uni.getStorageSync('store_id') || 11001
});
if (commonRes && (commonRes.code === 0 || commonRes.errcode === 0)) {
const list = commonRes.data || commonRes.result || [];
this.doctorOrderCommonList = list.map((item) => {
item.isSelect = 0;
if (this.selectDoctorOrderList) {
const valuesArr = this.selectDoctorOrderList.split('');
valuesArr.forEach((value) => {
if (value === item.content) {
item.isSelect = 1;
}
});
}
return item;
});
} else {
this.doctorOrderCommonList = [];
}
} catch (error) {
console.error('获取医嘱列表失败:', error);
uni.showToast({ title: '获取失败', icon: 'none' });
}
},
// 选择医嘱
selectDoctorOrder(item, type = 1) {
let arr = this.selectDoctorOrderList ? this.selectDoctorOrderList.split('').filter(Boolean) : [];
if (type === 1) {
if (item.isSelect === 1) {
arr = arr.filter(name => name !== item.content);
item.isSelect = 0;
} else {
if (!arr.includes(item.content)) {
arr.push(item.content);
}
item.isSelect = 1;
}
} else {
// 公共医嘱
if (item.isSelect === 1) {
arr = arr.filter(name => name !== item.content);
item.isSelect = 0;
} else {
if (!arr.includes(item.content)) {
arr.push(item.content);
}
item.isSelect = 1;
}
}
this.selectDoctorOrderList = arr.join('');
},
// 添加自定义医嘱
async addMyDoctorOrder() {
if (!this.newOrderContent.trim()) {
uni.showToast({ title: '请输入医嘱内容', icon: 'none' });
return;
}
try {
const res = await createDoctorOrder(this.newOrderContent.trim());
if (res && (res.code === 0 || res.errcode === 0)) {
uni.showToast({ title: '添加成功', icon: 'success' });
this.newOrderContent = '';
this.showAddInput = false;
}
await this.getDoctorOrderListData();
} catch (error) {
console.error('添加医嘱失败:', error);
uni.showToast({ title: '添加失败', icon: 'none' });
}
},
// 删除我的医嘱
async deleteMyDoctorOrder(item) {
try {
const res = await deleteDoctorOrder(item.id);
if (res && (res.code === 0 || res.errcode === 0)) {
uni.showToast({ title: '删除成功', icon: 'success' });
}
await this.getDoctorOrderListData();
} catch (error) {
console.error('删除医嘱失败:', error);
uni.showToast({ title: '删除失败', icon: 'none' });
}
},
// 取消添加
cancelAdd() {
this.newOrderContent = '';
this.showAddInput = false;
},
// 确认
handleConfirm() {
this.$emit('confirm', this.selectDoctorOrderList);
this.handleClose();
},
// 关闭
handleClose() {
this.show = false;
this.$emit('input', false);
}
}
};
</script>
<style lang="scss" scoped>
.doctor-order-modal {
display: flex;
flex-direction: column;
height: 100%;
background-color: #fff;
}
.modal-header {
padding: 32rpx;
text-align: center;
border-bottom: 1rpx solid #eee;
}
.modal-content {
flex: 1;
overflow-y: auto;
padding: 32rpx;
}
.section {
margin-bottom: 32rpx;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 24rpx;
.add-btn {
display: flex;
align-items: center;
gap: 8rpx;
padding: 8rpx 16rpx;
border: 1rpx dashed #6ACDBB;
border-radius: 32rpx;
.add-text {
font-size: 24rpx;
color: #6ACDBB;
}
}
}
.add-input-box {
margin-bottom: 24rpx;
padding: 16rpx;
background-color: #f9fafb;
border-radius: 8rpx;
.input-actions {
display: flex;
justify-content: flex-end;
margin-top: 16rpx;
}
}
.tag-container {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.tag-item {
display: inline-flex;
align-items: center;
padding: 12rpx 24rpx;
background-color: #f9fafb;
border: 1rpx solid #e5e7eb;
border-radius: 9999rpx;
cursor: pointer;
transition: all 0.2s;
&.selected {
background-color: #eff6ff;
border-color: #6ACDBB;
.tag-text {
color: #6ACDBB;
font-weight: 500;
}
}
.tag-text {
font-size: 28rpx;
color: #4b5563;
}
.tag-action {
margin-left: 8rpx;
display: flex;
align-items: center;
}
}
.modal-footer {
display: flex;
gap: 24rpx;
padding: 32rpx;
border-top: 1rpx solid #eee;
.u-button {
flex: 1;
}
}
</style>