order.ts
2.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
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getConsultation_information_list, getConsultation_information_detail, getPrescription_detail, getUserinfo } from '@/api'
import type { PageListParamsType, ConsultationOrderListItemType, PageListType, ConsultationOrderDetailType, PrescriptionDetailType, UserInfoType } from '@/types'
import type { RootState } from '@/store'
// createAsyncThunk<返回值类型, 接受参数类型> 参数为payload
export const fetchOrderDataAction = createAsyncThunk<void, PageListParamsType>(
'fetchdata', (payload, { dispatch }) => {
getConsultation_information_list(payload).then(({ result }: { result: PageListType<ConsultationOrderListItemType[]> }) => {
console.log(result, '问诊订单列表')
dispatch(changeConsultationOrderAction(result?.records))
dispatch(changeConsultationOrderNumAction(result?.total))
})
}
)
export const fetchConsultationOrderDetailAction = createAsyncThunk<void, { id: string | number }>(
'ConsultationOrderDetailType', (payload, { dispatch }) => {
getConsultation_information_detail(payload).then(({ result }: { result: ConsultationOrderDetailType }) => {
dispatch(changeConsultationOrderDetailAction(result))
})
}
)
export const fetchPrescriptionDetailAction = createAsyncThunk<void, { id: string | number }>(
'PrescriptionDetail', (payload, { dispatch }) => {
getPrescription_detail(payload).then(({ result }: { result: PrescriptionDetailType }) => {
dispatch(changePrescriptionDetailAction(result))
})
}
)
export const fetchUserinfoAction = createAsyncThunk<void, void>('UserInfo', (payload, { dispatch }) => {
getUserinfo().then(({ result }: { result: UserInfoType }) => {
dispatch(changeUserInfoAction(result))
})
})
const orderSlice = createSlice({
name: 'order',
initialState: {
count: 100,
message: 'hello Redux',
name: 'HachimanC',
ConsultationOrderList: [],
ConsultationOrderDetailData: {},
PrescriptionDetailData: {},
UserInfo: {},
total: 0
},
reducers: {
changeConsultationOrderAction(state, { payload }) {
state.ConsultationOrderList = payload
},
changeConsultationOrderNumAction(state, { payload }) {
state.total = payload
},
changeConsultationOrderDetailAction(state, { payload }) {
state.ConsultationOrderDetailData = payload
},
changePrescriptionDetailAction(state, { payload }) {
state.PrescriptionDetailData = payload
},
changeUserInfoAction(state, { payload }) {
state.UserInfo = payload
}
}
})
export default orderSlice.reducer
export const { changeConsultationOrderAction, changeConsultationOrderNumAction, changeConsultationOrderDetailAction, changePrescriptionDetailAction, changeUserInfoAction } = orderSlice.actions