| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- <script setup lang="ts">
- import { VxeUI, type VxeFormProps, type VxeFormListeners } from 'vxe-pc-ui';
- import { useRequest } from 'alova/client';
- import { addDeviceRegisterMethod, getDeviceRegisterDetailMethod } from '@/request/api/device.api';
- import { branchMethod } from '@/request/api/system.api';
- import { notification } from 'ant-design-vue';
- import { getDictionaryMethod } from '@/request/api/dictionary.api';
- import type { EquirementModel } from '@/model/device.model';
- type FollowModel = Partial<EquirementModel>;
- const defaultModel = {
- deviceIds: [''],
- };
- const props = defineProps<{ data: FollowModel }>();
- const emits = defineEmits<{
- submit: [data?: EquirementModel];
- }>();
- const model = ref<EquirementModel>({ ...defaultModel });
- watchEffect(() => {
- if (props.data) {
- model.value = { ...defaultModel, ...props.data };
- }
- });
- // 确保processConfig始终存在
- // watchEffect(() => {
- // if (!model.value.processConfig) {
- // model.value.processConfig = {
- // archiving: false,
- // tongueDiagnosis: false,
- // tongueReport: 'none' as const,
- // pulseDiagnosis: false,
- // pulseReport: 'none' as const,
- // inquiry: false,
- // healthReport: 'none' as const,
- // conditioningPlan: 'none' as const
- // };
- // }
- // });
- // 获取详情
- const getDetail = async () => {
- const res = await getDeviceRegisterDetailMethod(props.data);
- if (res) {
- model.value = { ...defaultModel, ...res };
- model.value.deviceIds = [model.value.deviceCode ?? ''];
- }
- };
- onMounted(() => {
- if (props.data && props.data.id) {
- getDetail();
- }
- });
- const branch = ref<any[]>([]);
- const { loading: branchLoading } = useRequest(branchMethod(0, 1, 1)).onSuccess(({ data }) => {
- const to = (data?: any[]): any[] => {
- return Array.isArray(data)
- ? data.map((item) => {
- return {
- ...item,
- value: item.id,
- key: item.id.toString(),
- children: to(item.children),
- };
- })
- : [];
- };
- branch.value = to(data);
- });
- const { loading: submitting, send: submit } = useRequest(addDeviceRegisterMethod, { immediate: false }).onSuccess(({ data }) => {
- emits('submit');
- });
- // 获取设备类型
- const deviceTypes = ref<{ id: string; name: string }[]>([]);
- const deviceTypesLoading = ref(false);
- // 获取设备类型
- async function getDeviceType() {
- deviceTypesLoading.value = true;
- const res = await getDictionaryMethod('fdhb_device_type');
- if (res && res.length > 0) {
- deviceTypes.value = res.map((item: any) => ({
- id: item.value,
- name: item.label,
- }));
- }
- deviceTypesLoading.value = false;
- }
- const showDept = ref(false);
- const insArr = ref<any[]>([]);
- const insLoading = ref(false);
- async function getInstitution(orgId: string | number) {
- insLoading.value = true;
- const res = await branchMethod(1, 0, Number(orgId));
- if (res && res.length > 0) {
- insArr.value = res;
- }
- insLoading.value = false;
- }
- watch(
- () => model.value.orgId,
- async (newVal) => {
- showDept.value = !!newVal;
- if (showDept.value) {
- // 请求获取机构
- getInstitution(newVal ?? '');
- }
- if (!newVal || newVal !== model.value.institutionId) {
- model.value.institutionId = ''; // 或者 ''
- }
- }
- );
- const formItems = computed(() => {
- const baseItems: any[] = [
- {
- field: 'deviceType',
- title: '设备名称',
- span: 13,
- itemRender: {
- name: 'VxeSelect',
- props: {
- placeholder: '请选择',
- loading: deviceTypesLoading.value,
- options: computed(() => deviceTypes.value),
- optionProps: { value: 'id', label: 'name' },
- optionGroupProps: { options: 'groups' },
- clearable: true,
- filterable: true,
- },
- },
- },
- {
- field: 'id',
- title: '设备ID',
- span: 24,
- slots: {
- title: 'deviceIdTitleSlot',
- default: 'deviceIdSlot',
- },
- },
- {
- field: 'orgId',
- title: '组织名称',
- span: 13,
- itemRender: {
- name: 'VxeSelect',
- props: {
- placeholder: '请选择',
- loading: computed(() => branchLoading.value),
- options: computed(() => branch.value),
- optionProps: {
- value: 'value',
- label: 'label',
- },
- clearable: true,
- },
- },
- },
- // {
- // field: 'processConfig',
- // title: '',
- // span: 24,
- // slots: {
- // default: 'processConfigSlot',
- // },
- // },
- {
- field: 'remarks',
- title: '备注',
- span: 24,
- slots: {
- default: 'remarksSlot',
- },
- },
- { align: 'center', span: 24, slots: { default: 'active' } },
- ];
- // 如果 showDept 为 true,在 institutionId 后面插入 institutionId
- if (showDept.value) {
- baseItems.splice(3, 0, {
- field: 'institutionId',
- title: '机构名称',
- span: 13,
- itemRender: {
- name: 'VxeTreeSelect',
- props: {
- placeholder: '请选择',
- loading: computed(() => insLoading.value),
- options: computed(() => insArr.value),
- optionProps: { value: 'id', label: 'label' },
- clearable: true,
- },
- },
- });
- }
- return baseItems;
- });
- const formProps = reactive<VxeFormProps>({
- titleWidth: 100,
- titleAlign: 'right',
- titleColon: true,
- data: computed(() => model.value),
- items: [] as any, // 临时设置为空数组,我们将在模板中使用动态items
- rules: {
- deviceType: [{ required: true, message: '请选择设备名称' }],
- deviceIds: [{ required: true, message: '请输入设备ID' }],
- orgId: [{ required: true, message: '请选择组织名称' }],
- institutionId: [{ required: true, message: '请选择机构名称' }],
- },
- });
- const formEmits: VxeFormListeners = {
- submit({ data }) {
- // 验证必填字段
- if (!data.deviceType) {
- notification.error({
- message: '请选择设备名称',
- });
- return false; // 阻止表单提交
- }
- if (!data.deviceIds || data.deviceIds.length === 0 || data.deviceIds.every((id: string) => !id.trim())) {
- notification.error({
- message: '请输入设备ID',
- });
- return false; // 阻止表单提交
- }
- if (!data.orgId) {
- notification.error({
- message: '请选择组织名称',
- });
- return false; // 阻止表单提交
- }
- if (!data.institutionId) {
- notification.error({
- message: '请选择机构名称',
- });
- return false; // 阻止表单提交
- }
- if (data.id) {
- data.deviceCode = data.deviceIds[0];
- }
- submit(data).then(() => {
- notification.success({
- message: '操作成功',
- });
- VxeUI.modal.close('equipment-modal');
- });
- },
- };
- function cancel() {
- VxeUI.modal.close('equirement-modal');
- }
- function addDeviceId() {
- if (!model.value.deviceIds) {
- model.value.deviceIds = [''];
- }
- model.value.deviceIds.push('');
- }
- function removeDeviceId(index: number) {
- if (model.value.deviceIds && model.value.deviceIds.length > 1) {
- model.value.deviceIds.splice(index, 1);
- }
- }
- onBeforeMount(async () => {
- if (props.data) {
- model.value = { ...defaultModel, ...props.data };
- }
- // 获取设备名称·
- getDeviceType();
- });
- </script>
- <template>
- <div class="form-container">
- <vxe-form
- :title-width="formProps.titleWidth"
- :title-align="formProps.titleAlign"
- :title-colon="formProps.titleColon"
- :data="formProps.data"
- :items="formItems"
- :rules="formProps.rules"
- v-on="formEmits"
- :loading="submitting"
- >
- <template #deviceIdTitleSlot>
- <span style="color: #f56c6c;font-size: 20px;">*</span> 设备ID
- </template>
- <template #deviceIdSlot>
- <div class="device-ids-container">
- <div v-for="(deviceId, index) in model.deviceIds || []" :key="index" class="device-id-item">
- <vxe-input v-model="model.deviceIds[index]" placeholder="请输入" style="width: 200px" />
- <vxe-button v-if="(model.deviceIds || []).length > 1" type="text" style="color: #ff4d4f; margin-left: 8px" @click="removeDeviceId(index)">
- <template #default>×</template>
- </vxe-button>
- </div>
- <vxe-button type="text" style="border: 1px dashed #d9d9d9; width: 32px; height: 32px; margin-bottom: 8px" @click="addDeviceId" v-if="!model?.id">
- <template #default>+</template>
- </vxe-button>
- </div>
- </template>
- <!-- <template #processConfigSlot>
- <div class="section-container">
- <div class="section-title">流程配置</div>
- <div class="section-divider"></div>
- <div class="process-config">
- <div class="config-item">
- <span class="config-label">建档:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.archiving"
- :value="true"
- :checked="model.processConfig?.archiving"
- />
- <span>有</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.archiving"
- :value="false"
- :checked="!model.processConfig?.archiving"
- />
- <span>无</span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <span class="config-label">舌面诊:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.tongueDiagnosis"
- :value="true"
- :checked="model.processConfig?.tongueDiagnosis"
- disabled
- />
- <span>有</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.tongueDiagnosis"
- :value="false"
- :checked="!model.processConfig?.tongueDiagnosis"
- />
- <span>无</span>
- </label>
- </div>
- <span class="report-label">舌面分析报告:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.tongueReport"
- value="full"
- :checked="model.processConfig?.tongueReport === 'full'"
- />
- <span>完整展示</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.tongueReport"
- value="scan"
- :checked="model.processConfig?.tongueReport === 'scan'"
- />
- <span>扫码查看</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.tongueReport"
- value="none"
- :checked="model.processConfig?.tongueReport === 'none'"
- />
- <span>无</span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <span class="config-label">脉诊:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.pulseDiagnosis"
- :value="true"
- :checked="model.processConfig?.pulseDiagnosis"
- />
- <span>有</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.pulseDiagnosis"
- :value="false"
- :checked="!model.processConfig?.pulseDiagnosis"
- />
- <span>无</span>
- </label>
- </div>
- <span class="report-label">脉象分析报告:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.pulseReport"
- value="full"
- :checked="model.processConfig?.pulseReport === 'full'"
- />
- <span>完整展示</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.pulseReport"
- value="scan"
- :checked="model.processConfig?.pulseReport === 'scan'"
- />
- <span>扫码查看</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.pulseReport"
- value="none"
- :checked="model.processConfig?.pulseReport === 'none'"
- />
- <span>无</span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <span class="config-label">问诊:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.inquiry"
- :value="true"
- :checked="model.processConfig?.inquiry"
- />
- <span>有</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.inquiry"
- :value="false"
- :checked="!model.processConfig?.inquiry"
- />
- <span>无</span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <span class="config-label">健康分析报告:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.healthReport"
- value="full"
- :checked="model.processConfig?.healthReport === 'full'"
- />
- <span>完整展示</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.healthReport"
- value="scan"
- :checked="model.processConfig?.healthReport === 'scan'"
- />
- <span>扫码查看</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.healthReport"
- value="none"
- :checked="model.processConfig?.healthReport === 'none'"
- />
- <span>无</span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <span class="config-label">调理方案:</span>
- <div class="radio-group">
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.conditioningPlan"
- value="full"
- :checked="model.processConfig?.conditioningPlan === 'full'"
- />
- <span>完整展示</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.conditioningPlan"
- value="scan"
- :checked="model.processConfig?.conditioningPlan === 'scan'"
- />
- <span>扫码查看</span>
- </label>
- <label class="radio-item">
- <input
- type="radio"
- v-model="model.processConfig.conditioningPlan"
- value="none"
- :checked="model.processConfig?.conditioningPlan === 'none'"
- />
- <span>无</span>
- </label>
- </div>
- </div>
- </div>
- </div>
- </template> -->
- <template #remarksSlot>
- <div class="section-container">
- <textarea
- v-model="model.remark"
- placeholder="请输入"
- rows="3"
- style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px; resize: vertical; font-family: inherit"
- />
- </div>
- </template>
- <template #active>
- <vxe-button type="reset" content="取消" :disabled="submitting" @click="cancel"></vxe-button>
- <vxe-button type="submit" status="warning" content="确定" :loading="submitting"></vxe-button>
- </template>
- </vxe-form>
- </div>
- </template>
- <style scoped lang="scss">
- .form-container {
- padding: 20px;
- }
- .device-ids-container {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- gap: 8px;
- align-items: flex-start;
- .device-id-item {
- display: flex;
- align-items: center;
- gap: 8px;
- margin-bottom: 8px;
- }
- }
- .section-container {
- margin-bottom: 20px;
- .section-title {
- font-size: 16px;
- font-weight: bold;
- margin-bottom: 10px;
- color: #333;
- }
- .section-divider {
- height: 1px;
- background-color: #d9d9d9;
- margin-bottom: 15px;
- }
- }
- .process-config {
- .config-item {
- display: flex;
- align-items: center;
- margin-bottom: 16px;
- flex-wrap: wrap;
- gap: 8px;
- .config-label {
- font-weight: bold;
- min-width: 80px;
- }
- .report-label {
- margin-left: 40px;
- color: #666;
- margin-right: 10px;
- }
- .radio-group {
- display: flex;
- align-items: center;
- gap: 30px;
- .radio-item {
- display: flex;
- align-items: center;
- gap: 4px;
- cursor: pointer;
- input[type='radio'] {
- margin: 0;
- cursor: pointer;
- }
- span {
- font-size: 14px;
- }
- }
- .badge {
- background-color: #faad14;
- color: white;
- border-radius: 12px;
- padding: 2px 8px;
- font-size: 12px;
- min-width: 20px;
- text-align: center;
- }
- }
- }
- }
- :deep(.vxe-form--item) {
- .vxe-form--item-wrapper {
- .vxe-form--item-content {
- .vxe-input {
- width: 100%;
- }
- }
- }
- }
- .required-field {
- :deep(.vxe-form--item-title) {
- position: relative;
-
- &::before {
- content: '*';
- color: #ff4d4f;
- position: absolute;
- left: -8px;
- top: 0;
- }
- }
- }
- </style>
|