state.vue
6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<template>
<u-navbar title="更改状态" :autoBack="true" bgColor="#fff" placeholder safeAreaInsetTop :titleStyle="{ color: '#000' }" leftIconColor="#000"></u-navbar>
<view class="state graybg">
<view class="flexJ" style="margin-bottom: 62rpx">
<view v-for="(_, index) in statelist" :key="index" class="stateBtn flexC" :class="{ activeBtn: params.state === _.value }" @click="params.state = _.value">{{ _.title }}</view>
</view>
<template v-if="params.state === 1">
<view class="state-title">问诊情况</view>
<view class="state-item topbr">
<view class="flexJ">
<view class="itemtitle">图文问诊</view>
<u-switch v-model="params.textState" size="28" :activeValue="1" :inactiveValue="0" activeColor="#06b8d2"></u-switch>
</view>
<u-line margin="32rpx 0 0 0"></u-line>
</view>
<view class="state-item">
<view class="flexJ">
<view class="itemtitle">视频问诊</view>
<u-switch v-model="params.videoState" size="28" :activeValue="1" :inactiveValue="0" activeColor="#06b8d2"></u-switch>
</view>
<u-line margin="32rpx 0 0 0"></u-line>
</view>
<view class="state-item botbr" style="padding-bottom: 32rpx">
<view class="flexJ">
<view class="itemtitle">电话问诊</view>
<u-switch v-model="params.phoneState" size="28" :activeValue="1" :inactiveValue="0" activeColor="#06b8d2"></u-switch>
</view>
</view>
<view class="state-title" style="margin-top: 32rpx">坐诊时间</view>
<view class="state-item topbr">
<view class="flexJ">
<view class="itemtitle">开始时间</view>
<view class="flexA">
<view style="font-size: 30rpx; color: #a6a6a6" @click=";(showTimePickerState = true), (flag = 'startTime')">
{{ params.startTime.length ? params.startTime : '请选择' }}
</view>
<u-icon name="arrow-right" color="#A6A6A6" size="18"></u-icon>
</view>
</view>
<u-line margin="32rpx 0 0 0"></u-line>
</view>
<view class="state-item botbr" style="padding-bottom: 32rpx">
<view class="flexJ">
<view class="itemtitle">截止时间</view>
<view class="flexA">
<view style="font-size: 30rpx; color: #a6a6a6" @click=";(showTimePickerState = true), (flag = 'endTime')">
{{ params.endTime.length ? params.endTime : '请选择' }}
</view>
<u-icon name="arrow-right" color="#A6A6A6" size="18"></u-icon>
</view>
</view>
</view>
<up-button color="#05B8D2" shape="circle" text="提交" throttleTime="1500" @click="submitMineStateHandler(params.state)"></up-button>
</template>
<view style="margin-top: 160rpx" v-if="params.state === 0">
<up-button color="#05B8D2" shape="circle" text="提交" throttleTime="1500" @click="submitMineStateHandler(params.state)"></up-button>
</view>
</view>
<u-datetime-picker :show="showTimePickerState" mode="time" @cancel="showTimePickerState = false" @confirm="confirmSelectTimeHandler"></u-datetime-picker>
</template>
<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import { ref, getCurrentInstance, ComponentPublicInstance } from 'vue'
import { updateChange_state, getState } from '../../api'
import { ChangeStateType } from '../../types'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
const { proxy } = getCurrentInstance() as { proxy: ComponentPublicInstance }
interface EventType {
state: string
}
const flag = ref<string>('')
const showTimePickerState = ref(false)
const params = ref({
state: 0,
textState: 0,
videoState: 0,
phoneState: 0,
startTime: '',
endTime: ''
})
const statelist = ref([
{ title: '在线坐诊', value: 1 },
{ title: '暂不接诊', value: 0 }
])
const confirmSelectTimeHandler = (e: { value: string; mode: string }) => {
const startTime = flag.value === 'startTime' ? e.value : params.value.startTime
const endTime = flag.value === 'endTime' ? e.value : params.value.endTime
const startTimeParts = startTime.split(':') // 将时间字符串拆分为小时和分钟
const endTimeParts = endTime.split(':')
const startHour = parseInt(startTimeParts[0], 10) // 将小时部分转换为整数
const startMinute = parseInt(startTimeParts[1], 10) // 将分钟部分转换为整数
const endHour = parseInt(endTimeParts[0], 10)
const endMinute = parseInt(endTimeParts[1], 10)
const startDate = new Date(0, 0, 0, startHour, startMinute) // 创建Date对象表示startTime
const endDate = new Date(0, 0, 0, endHour, endMinute) // 创建Date对象表示endTime
if (startDate > endDate) {
// console.log('startTime 晚于 endTime')
uni.$u.toast(`${flag.value === 'startTime' ? '开始时间' : '截止时间'}不能${flag.value === 'startTime' ? '晚于' : '早于'}${flag.value === 'startTime' ? '截止时间' : '开始时间'}`)
return
}
// else if (startDate < endDate) {
// console.log('startTime 早于 endTime')
// } else {
// console.log('startTime 和 endTime 相同')
// }
showTimePickerState.value = false
params.value[flag.value] = e.value
}
const submitMineStateHandler = async (state: number) => {
if (!params.value.startTime.length && state === 1) return uni.$u.toast('请选择开始时间')
if (!params.value.endTime.length && state === 1) return uni.$u.toast('请选择结束时间')
if (state === 0) {
await updateChange_state({ state: 0 })
} else {
await updateChange_state(params.value)
}
proxy.$h.timeCallBack('修改成功')
}
const getStateHandler = async () => {
const { result } = await getState()
const { videoState, textState, phoneState, startTime, endTime } = result
if ([videoState, textState, phoneState, startTime, endTime].includes(null)) return
params.value = result.state === 0 ? { ...result, state: 0 } : result
}
// (params.value = (await getState()).result)
onLoad((e: EventType) => {
params.value.state = Number(e.state)
getStateHandler()
})
</script>
<style lang="scss" scoped>
page {
/* background: #f7f8fa; */
}
.state {
box-sizing: border-box;
padding: 32rpx 24rpx;
&-title {
color: #999999;
margin-bottom: 26rpx;
font-size: 26rpx;
}
&-item {
box-sizing: border-box;
padding: 32rpx 32rpx 0 32rpx;
background: #fff;
}
.itemtitle {
color: #323233;
font-size: 30rpx;
font-weight: 700;
}
.topbr {
border-radius: 24rpx 24rpx 0 0;
}
.botbr {
border-radius: 0 0 24rpx 24rpx;
}
.stateBtn {
width: 48%;
border-radius: 24rpx;
background: #fff;
color: #323233;
font-size: 36rpx;
font-weight: 700;
height: 158rpx;
}
.activeBtn {
background: #05b8d2;
color: #fff;
}
}
</style>