feat: 建档升级

This commit is contained in:
huxuejian 2026-08-31 09:14:04 +08:00
parent a368474ffb
commit 16c24b036f
8 changed files with 864 additions and 38 deletions

View File

@ -262,6 +262,20 @@
"disableScroll": true "disableScroll": true
} }
}, },
{
"path": "step-edit-archive",
"style": {
"navigationBarTitleText": "新增档案",
"disableScroll": true
}
},
{
"path": "fill-his-archive",
"style": {
"navigationBarTitleText": "完善信息",
"disableScroll": true
}
},
{ {
"path": "archive-result", "path": "archive-result",
"style": { "style": {

View File

@ -109,6 +109,15 @@ async function getMatchedHisArchive(data) {
customer.value = data; customer.value = data;
corpName.value = res.corpName || ''; corpName.value = res.corpName || '';
showBindHisPopup.value = true; showBindHisPopup.value = true;
} else if (res && res.isCustomerInfoNotMatchQueryPlans) {
try {
await confirm('请完善信息', { cancelText: '取消', confirmText: '确认' });
uni.navigateTo({
url: `/pages/archive/fill-his-archive?teamId=${teamId.value}&corpId=${corpId.value}&id=${data._id}`
});
} catch (error) {
//
}
} else { } else {
confirm(res?.message || '获取档案信息失败', { showCancel: false }) confirm(res?.message || '获取档案信息失败', { showCancel: false })
} }
@ -133,6 +142,7 @@ useLoad(options => {
}) })
useShow(() => { useShow(() => {
console.log('show~~~~~~')
if (teamId.value && corpId.value) { if (teamId.value && corpId.value) {
getMembers() getMembers()
} }

View File

@ -10,8 +10,9 @@
</view> </view>
</view> </view>
<template #footer> <template #footer>
<button-footer :showCancel="customerId ? true : false" cancelText="删除" <!-- :showCancel="customerId ? true : false" -->
:confirmText="healthTypes.length ? '下一步' : '保存'" @cancel="unBindArchive()" @confirm="confirm()" /> <button-footer :showCancel="false" cancelText="删除" :confirmText="healthTypes.length ? '下一步' : '保存'"
@cancel="unBindArchive()" @confirm="confirm()" />
</template> </template>
</full-page> </full-page>
<bind-popup :customers="customers" :corpName="corpName" :enableHis="enableHis" :visible="visible" <bind-popup :customers="customers" :corpName="corpName" :enableHis="enableHis" :visible="visible"
@ -49,9 +50,9 @@ const referenceCustomerId = ref('');
const customer = ref({}); const customer = ref({});
const customerId = ref(''); const customerId = ref('');
const customers = ref([]); const customers = ref([]);
const disableTitles = ref(['mobile']); // const disableTitles = ref(['mobile']);
const form = ref({}); const form = ref({});
const formItems = ref([]); const teamFormItems = ref([]);
const loading = ref(false); const loading = ref(false);
const teamId = ref(''); const teamId = ref('');
const tempRef = ref(null); const tempRef = ref(null);
@ -62,11 +63,33 @@ const healthTypes = ref([]);
const enableHis = ref(false); const enableHis = ref(false);
const source = ref(''); const source = ref('');
const redirectUrl = ref(''); const redirectUrl = ref('');
const archiveQueryPlans = ref([]);
const pageOptions = ref({});
const formData = computed(() => { const formData = computed(() => {
if (customerId.value) {
return { ...customer.value, ...form.value }
}
return { ...customer.value, ...form.value, mobile: account.value?.mobile } return { ...customer.value, ...form.value, mobile: account.value?.mobile }
}); });
const formItems = computed(() => {
return teamFormItems.value.map(i => {
if (i.title === 'mobile' && formData.value.mobile && formData.value.mobile === account.value?.mobile) {
return { ...i, appendText: '(授权手机号)' }
}
return i
})
})
const disableTitles = computed(() => {
const list = ['mobile'];
if (customer.value._id && customer.value.isConnectHis) {
list.push('name', 'idCard', 'sex', 'age', 'birthday')
}
return list
})
function change({ title, value }) { function change({ title, value }) {
if (title) { if (title) {
form.value[title] = value; form.value[title] = value;
@ -111,30 +134,6 @@ function preProcessFrom() {
} }
} }
/**
* 产品要求, 编辑的情况下 姓名身份证号性别年龄出生年月
* 建档成功或者绑定档案成功后姓名身份证号性别年龄出生年月如果有内容的都不允许修改没有内容的则允许编辑
*/
function setDisabledTitles(data) {
const list = ['mobile'];
if (data.name) {
list.push('name');
}
if (data.idCard) {
list.push('idCard');
}
if (data.sex) {
list.push('sex');
}
if (data.age) {
list.push('age');
}
if (data.birthday) {
list.push('birthday');
}
disableTitles.value = list;
}
async function addArchive() { async function addArchive() {
if (loading.value) return; if (loading.value) return;
loading.value = true; loading.value = true;
@ -230,6 +229,10 @@ async function bindArchive(customerId) {
} }
async function init() { async function init() {
if (await initArchiveQueryConfig()) return;
if (referenceCustomerId.value) {
getReferenceCustomer();
}
if (customerId.value) { if (customerId.value) {
await getCustomer(); await getCustomer();
} else { } else {
@ -251,6 +254,39 @@ async function init() {
} }
async function initArchiveQueryConfig() {
const res = await api('getCorpInfo', { corpId: corpId.value }, false);
const data = Array.isArray(res.data)
? res.data[0]
: Array.isArray(res.data?.data)
? res.data.data[0]
: res.data?.data || res.data || {};
const config = data.hisArchiveQueryConfig && typeof data.hisArchiveQueryConfig === 'object'
? data.hisArchiveQueryConfig
: {};
const plans = Array.isArray(config.plans)
? config.plans
: Array.isArray(config.schemes)
? config.schemes
: [];
archiveQueryPlans.value = plans.filter(plan => plan && Array.isArray(plan.fields) && plan.fields.length);
if (archiveQueryPlans.value.length) {
redirectArchivePage('step-edit-archive');
return true;
}
return false;
}
function redirectArchivePage(page) {
const query = Object.entries(pageOptions.value)
.filter(([, value]) => value !== undefined && value !== null && value !== '')
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
.join('&');
uni.redirectTo({
url: `/pages/archive/${page}${query ? `?${query}` : ''}`
});
}
async function getExperienceCouponBindArchive() { async function getExperienceCouponBindArchive() {
const res = await api('getCustomerByCustomerId', { corpId: corpId.value, customerId: bindCustomerId.value }); const res = await api('getCustomerByCustomerId', { corpId: corpId.value, customerId: bindCustomerId.value });
const data = res && res.success && res.data ? res.data : null; const data = res && res.success && res.data ? res.data : null;
@ -271,12 +307,7 @@ async function getArchives() {
async function getBaseForm() { async function getBaseForm() {
const res = await api('getTeamBaseInfo', { corpId: corpId.value, teamId: teamId.value }); const res = await api('getTeamBaseInfo', { corpId: corpId.value, teamId: teamId.value });
if (res && res.success) { if (res && res.success) {
formItems.value = Array.isArray(res.data) ? res.data : []; teamFormItems.value = Array.isArray(res.data) ? res.data : [];
const mobileIndex = formItems.value.findIndex(item => item.title === 'mobile');
if (mobileIndex > -1) {
formItems.value[mobileIndex].appendText = `(授权手机号)`;
}
} else { } else {
toast(res?.message || '查询失败'); toast(res?.message || '查询失败');
return Promise.reject() return Promise.reject()
@ -287,7 +318,6 @@ async function getCustomer() {
const res = await api('getCustomerByCustomerId', { customerId: customerId.value }); const res = await api('getCustomerByCustomerId', { customerId: customerId.value });
if (res && res.success && res.data) { if (res && res.success && res.data) {
customer.value = res.data; customer.value = res.data;
setDisabledTitles(res.data)
} else { } else {
await toast(res?.message || '查询档案信息失败'); await toast(res?.message || '查询档案信息失败');
uni.navigateBack(); uni.navigateBack();
@ -339,6 +369,7 @@ async function getTeam(corpId, teamId, customerId) {
onLoad(options => { onLoad(options => {
pageOptions.value = { ...options };
teamId.value = options.teamId; teamId.value = options.teamId;
corpId.value = options.corpId; corpId.value = options.corpId;
customerId.value = options.id || ''; customerId.value = options.id || '';
@ -347,9 +378,6 @@ onLoad(options => {
referenceCustomerId.value = options.referenceCustomerId || ''; referenceCustomerId.value = options.referenceCustomerId || '';
source.value = options.source || ''; source.value = options.source || '';
redirectUrl.value = options.redirectUrl || ''; redirectUrl.value = options.redirectUrl || '';
if (referenceCustomerId.value) {
getReferenceCustomer();
}
uni.setNavigationBarTitle({ title: customerId.value ? '编辑档案' : '新增档案' }) uni.setNavigationBarTitle({ title: customerId.value ? '编辑档案' : '新增档案' })
}) })

View File

@ -0,0 +1,213 @@
<template>
<full-page :customScroll="false">
<view v-if="configLoaded && !queryFields.length" class="flex items-center justify-center h-full">
<empty-data text="当前机构暂未配置院内档案查询方案" />
</view>
<view v-else-if="queryFields.length" class="p-15">
<view class="bg-white rounded shadow-lg">
<form-template ref="formRef" :items="queryFormItems" :form="formData" @change="change" />
</view>
</view>
<template #footer>
<button-footer v-if="queryFields.length" :showCancel="false" confirmText="保存" @confirm="save" />
</template>
</full-page>
</template>
<script setup>
import { computed, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import api from '@/utils/api';
import { toast } from '@/utils/widget';
import ButtonFooter from '@/components/button-footer.vue';
import EmptyData from '@/components/empty-data.vue';
import FullPage from '@/components/full-page.vue';
import formTemplate from '@/components/form-template/index.vue';
const corpId = ref('');
const teamId = ref('');
const customerId = ref('');
const customer = ref({});
const form = ref({});
const archiveQueryPlans = ref([]);
const configLoaded = ref(false);
const saving = ref(false);
const formRef = ref(null);
const queryFields = computed(() => {
const fields = [];
const fieldKeys = new Set();
archiveQueryPlans.value.forEach((plan) => {
(Array.isArray(plan?.fields) ? plan.fields : []).forEach((field) => {
const source = typeof field === 'string' ? { fieldKey: field } : field || {};
const fieldKey = String(source.fieldKey || source.feildKey || source.key || source.title || '').trim();
if (!fieldKey || fieldKeys.has(fieldKey)) return;
fieldKeys.add(fieldKey);
fields.push({
fieldKey,
label: source.label || source.labelSnapshot || source.name || fieldKey,
});
});
});
return fields;
});
//
const queryFormItems = computed(() => queryFields.value.map((field) => ({
title: field.fieldKey,
name: field.label,
type: 'input',
})));
const formData = computed(() => ({ ...customer.value, ...form.value }));
function change({ title, value }) {
if (title) form.value[title] = value;
}
async function initArchiveQueryConfig() {
try {
const res = await api('getCorpInfo', { corpId: corpId.value }, false);
const data = Array.isArray(res?.data)
? res.data[0]
: Array.isArray(res?.data?.data)
? res.data.data[0]
: res?.data?.data || res?.data || {};
const config = data?.hisArchiveQueryConfig && typeof data.hisArchiveQueryConfig === 'object'
? data.hisArchiveQueryConfig
: {};
const plans = Array.isArray(config.plans)
? config.plans
: Array.isArray(config.schemes)
? config.schemes
: [];
archiveQueryPlans.value = plans.filter((plan) => plan && Array.isArray(plan.fields) && plan.fields.length);
} finally {
configLoaded.value = true;
}
}
async function getCustomer() {
const res = await api('getCustomerByCustomerId', { customerId: customerId.value });
if (res?.success && res.data) {
customer.value = res.data;
return true;
}
await toast(res?.message || '查询档案信息失败');
uni.navigateBack();
return false;
}
async function save() {
// if (saving.value || !formRef.value?.verify()) return;
saving.value = true;
try {
const matchedPlans = archiveQueryPlans.value.filter(isQueryPlanSatisfied);
if (!matchedPlans.length) {
toast('请完善信息');
return;
}
const matchedArchive = await queryHisArchive(matchedPlans);
if (!matchedArchive) {
toast('没有查询到患者院内档案,可先前往医院建档。');
return;
}
if (!matchedArchive.archive.customerNumber) {
toast('院内档案缺少门诊ID无法关联');
return;
}
const updateRes = await api('updateCustomer', {
id: customerId.value,
params: {
...matchedArchive.conditions,
customerNumber: matchedArchive.archive.customerNumber,
isConnectHis: true,
},
});
if (!updateRes?.success) {
toast(updateRes?.message || '保存失败');
return;
}
await toast('保存并关联成功');
uni.$emit('reloadTeamCustomers');
uni.navigateBack();
} finally {
saving.value = false;
}
}
function getPlanFields(plan) {
return (Array.isArray(plan?.fields) ? plan.fields : [])
.map((field) => {
const source = typeof field === 'string' ? { fieldKey: field } : field || {};
const fieldKey = String(source.fieldKey || source.feildKey || source.key || source.title || '').trim();
if (!fieldKey) return null;
return { fieldKey };
})
.filter(Boolean);
}
function normalizeFieldValue(value) {
return value === undefined || value === null ? '' : String(value).trim();
}
function isQueryPlanSatisfied(plan) {
const fields = getPlanFields(plan);
return fields.length > 0 && fields.every((field) => normalizeFieldValue(formData.value[field.fieldKey]) !== '');
}
function getQueryConditions(plan) {
return getPlanFields(plan).reduce((conditions, field) => {
conditions[field.fieldKey] = formData.value[field.fieldKey];
return conditions;
}, {});
}
function isHisArchiveMatched(archive, conditions) {
return Object.keys(conditions).every((fieldKey) =>
normalizeFieldValue(archive?.[fieldKey]) === normalizeFieldValue(conditions[fieldKey])
);
}
async function queryHisArchive(plans) {
for (const plan of plans) {
const conditions = getQueryConditions(plan);
try {
const res = await api('getHisCustomerArchive', {
corpId: corpId.value,
planId: plan.planId || plan.schemeId || '',
...conditions,
}, false);
const archive = (Array.isArray(res?.list) ? res.list : [])
.find((item) => isHisArchiveMatched(item, conditions));
if (archive) return { archive, conditions };
} catch (error) {
//
}
}
return null;
}
async function init() {
await initArchiveQueryConfig();
if (!queryFields.value.length) return;
await getCustomer();
}
onLoad((options) => {
corpId.value = options.corpId || '';
teamId.value = options.teamId || '';
customerId.value = options.id || '';
if (!corpId.value || !customerId.value) {
toast('页面参数错误');
uni.navigateBack();
return;
}
init();
});
</script>
<style scoped></style>

View File

@ -0,0 +1,549 @@
<template>
<full-page v-if="!visible" :customScroll="empty" :title="queryHisTitles.length">
<view v-if="formItems.length === 0" class="flex items-center justify-center h-full">
<empty-data />
</view>
<view v-else class="p-15">
<view class="bg-white rounded shadow-lg">
<form-template v-if="step === 0" ref="tempRef" :disableTitles="disableTitles" :items="hisQueryFormItems"
:form="formData" @change="change($event)" />
<form-template v-else-if="step === 1" ref="tempRef" :disableTitles="disableTitles" :items="restFormItems"
:form="formData" @change="change($event)" />
</view>
</view>
<template #footer>
<!-- :showCancel="customerId ? true : false" -->
<button-footer v-if="step === 0" :showCancel="false" confirmText="下一步" @confirm="queryHisArchives()" />
<button-footer v-else-if="step === 1" :showCancel="false" cancelText="" confirmText=" 保存" @cancel="step = 0"
@confirm="confirm()" />
</template>
</full-page>
<bind-popup :customers="customers" :corpName="corpName" :enableHis="enableHis" :visible="visible"
@close="visible = false" @confirm="bindArchive($event)" />
<verify-popup :visible="verifyVisible" @close="verifyVisible = false" />
</template>
<script setup>
import { computed, ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
import { onLoad } from "@dcloudio/uni-app";
import dayjs from 'dayjs';
import useGuard from '@/hooks/useGuard';
import useAccount from '@/store/account';
import api from '@/utils/api';
import { toast, confirm as uniConfirm } from '@/utils/widget';
import validate from '@/utils/validate';
import { set } from "@/utils/cache";
import ButtonFooter from '@/components/button-footer.vue';
import EmptyData from '@/components/empty-data.vue';
import FullPage from '@/components/full-page.vue';
import bindPopup from './bind-popup.vue';
import verifyPopup from './verify-popup.vue';
import formTemplate from '@/components/form-template/index.vue';
const empty = ref(false)
const { useLoad } = useGuard();
const { account, externalUserId } = storeToRefs(useAccount());
const { getExternalUserId } = useAccount()
const corpId = ref('');
const corpName = ref('');
const corpUserId = ref('');
const bindCustomerId = ref('');
const referenceCustomerId = ref('');
const customer = ref({});
const customerId = ref('');
const customers = ref([]);
// const disableTitles = ref(['mobile']);
const form = ref({});
const teamFormItems = ref([]);
const loading = ref(false);
const teamId = ref('');
const tempRef = ref(null);
const verifyVisible = ref(false);
const visible = ref(false);
const referenceCustomer = ref(null)
const healthTypes = ref([]);
const enableHis = ref(false);
const source = ref('');
const redirectUrl = ref('');
const archiveQueryPlans = ref([]);
const pageOptions = ref({});
const step = ref(0);
const hisArchive = ref(null);
const queryingHisArchives = ref(false);
const queryHisTitles = computed(() => {
const res = archiveQueryPlans.value.length ? ['name', 'mobile'] : [];
archiveQueryPlans.value.forEach(item => {
getPlanFields(item).forEach(field => {
if (!res.includes(field.fieldKey.trim())) {
res.push(field.fieldKey.trim())
}
})
})
return customerId.value ? [] : res;
})
const formItems = computed(() => {
return teamFormItems.value.map(i => {
if (i.title === 'mobile' && formData.value.mobile && formData.value.mobile === account.value?.mobile) {
return { ...i, appendText: '(授权手机号)' }
}
return i
})
})
const hisQueryFormItems = computed(() => formItems.value.filter(i => queryHisTitles.value.includes(i.title)));
const restFormItems = computed(() => formItems.value.filter(i => !queryHisTitles.value.includes(i.title)));
const formData = computed(() => {
if (customerId.value) {
return { ...customer.value, ...form.value }
}
return { ...customer.value, ...form.value, mobile: account.value?.mobile }
});
const disableTitles = computed(() => {
const list = ['mobile'];
if (customer.value._id && customer.value.isConnectHis) {
list.push('name', 'idCard', 'sex', 'age', 'birthday')
}
return list
})
function change({ title, value }) {
if (title) {
form.value[title] = value;
}
if (title == 'idCard') {
const [isIdCard, birthday, gender] = validate.isChinaId(value);
if (isIdCard) {
form.value.birthday = birthday;
form.value.sex = gender == 'MALE' ? '男' : '女';
const age = dayjs().diff(birthday, 'year');
form.value.age = Math.max(1, age);
}
} else if (title === 'birthday' && formItems.value.some(i => i.title === 'age') && value && dayjs(value).valueOf()) {
const age = dayjs().diff(value, 'year');
form.value.age = Math.max(1, age);
}
}
async function queryHisArchives() {
if (queryingHisArchives.value) return;
const matchedPlans = archiveQueryPlans.value.filter(isQueryPlanSatisfied);
if (!matchedPlans.length) {
hisArchive.value = null;
step.value = 1;
return;
}
queryingHisArchives.value = true;
try {
const responses = await Promise.all(matchedPlans.map(async (plan) => {
const conditions = getQueryConditions(plan);
try {
const res = await api('getHisCustomerArchive', {
corpId: corpId.value,
planId: plan.planId || plan.schemeId || '',
...conditions,
}, false);
return {
plan,
conditions,
list: res && Array.isArray(res.list) ? res.list : [],
};
} catch (error) {
return { plan, conditions, list: [] };
}
}));
for (const response of responses) {
const archive = response.list.find((item) => isHisArchiveMatched(item, response.plan, response.conditions));
if (archive) {
hisArchive.value = archive;
step.value = 1;
return;
}
}
const responseWithArchives = responses.find((response) => response.list.length);
if (!responseWithArchives) {
await uniConfirm('没有查询到患者院内档案', { cancelText: '修改信息', confirmText: '新建档案' });
archiveQueryPlans.value = []
hisArchive.value = null;
return;
}
const mismatchMessage = getMismatchMessage(responseWithArchives);
try {
await uniConfirm(mismatchMessage, { cancelText: '修改信息', confirmText: '新建档案' });
archiveQueryPlans.value = []
hisArchive.value = null;
step.value = 1;
} catch (error) {
//
}
} finally {
queryingHisArchives.value = false;
}
}
function getPlanFields(plan) {
return (Array.isArray(plan?.fields) ? plan.fields : [])
.map((field) => {
const source = typeof field === 'string' ? { fieldKey: field } : field || {};
const fieldKey = source.fieldKey || source.feildKey || source.key || source.title;
if (!fieldKey) return null;
return {
fieldKey,
label: source.label || source.labelSnapshot || source.name || fieldKey,
};
})
.filter(Boolean);
}
function getCurrentFormValue(fieldKey) {
return formData.value[fieldKey];
}
function normalizeFieldValue(value) {
return value === undefined || value === null ? '' : String(value).trim();
}
function isQueryPlanSatisfied(plan) {
const fields = getPlanFields(plan);
return fields.length > 0 && fields.every((field) => normalizeFieldValue(getCurrentFormValue(field.fieldKey)));
}
function getQueryConditions(plan) {
return getPlanFields(plan).reduce((conditions, field) => {
conditions[field.fieldKey] = normalizeFieldValue(getCurrentFormValue(field.fieldKey));
return conditions;
}, {});
}
function getMatchFields(plan, conditions) {
const fields = getPlanFields(plan).map((field) => ({
...field,
value: conditions[field.fieldKey],
}));
['name', 'mobile'].forEach((fieldKey) => {
const value = normalizeFieldValue(getCurrentFormValue(fieldKey));
if (value && !fields.some((field) => field.fieldKey === fieldKey)) {
fields.push({ fieldKey, label: fieldKey === 'name' ? '姓名' : '手机号', value });
}
});
return fields;
}
function isHisArchiveMatched(archive, plan, conditions) {
return getMatchFields(plan, conditions).every((field) =>
normalizeFieldValue(archive?.[field.fieldKey]) === normalizeFieldValue(field.value)
);
}
function getMismatchMessage(response) {
const archive = response.list[0] || {};
const mismatch = getMatchFields(response.plan, response.conditions).find((field) =>
normalizeFieldValue(archive[field.fieldKey]) !== normalizeFieldValue(field.value)
);
if (!mismatch) return '院内档案信息与当前填写信息不一致,请确认后再继续。';
const actualValue = normalizeFieldValue(archive[mismatch.fieldKey]) || '为空';
return `${mismatch.label}不匹配`;
}
function confirm() {
if (!tempRef.value.verify()) return;
if (customerId.value) {
updateArchive();
} else {
addArchive();
}
}
/**
* 产品要求, 建档页面与联系人关系默认选中本人证件类型默认选中身份证
*/
function preProcessFrom() {
const relationItem = formItems.value.find(item => item.title === 'relationship');
const range = relationItem && Array.isArray(relationItem.range) ? relationItem.range : [];
if (range.includes('本人')) {
form.value.relationship = '本人';
}
const cardTypeItem = formItems.value.find(item => item.title === 'cardType');
const cardTypeRange = cardTypeItem && Array.isArray(cardTypeItem.range) ? relationItem.range : [];
if (cardTypeRange.includes('身份证')) {
form.value.cardType = '身份证';
}
}
async function addArchive() {
if (loading.value) return;
loading.value = true;
const params = {
...form.value,
addMethod: 'customerManual',
teamId: teamId.value,
corpId: corpId.value,
mobile: account.value.mobile,
miniAppId: account.value.openid,
externalUserId: externalUserId.value,
realUnionid: account.value.unionid || '',
}
if (hisArchive.value && hisArchive.value.customerNumber) {
params.customerNumber = hisArchive.value.customerNumber;
params.isConnectHis = true
}
if (externalUserId.value) {
const corpUserId = await getResponsiblePerson();
if (corpUserId) {
params.personResponsibles = [{ corpUserId, teamId: teamId.value }]
}
}
if (referenceCustomerId.value && !referenceCustomer.value) {
await getReferenceCustomer();
}
if (referenceCustomer.value) {
params.referenceCustomerId = referenceCustomer.value._id;
params.referenceUserId = '';
params.reference = referenceCustomer.value.name;
params.referenceType = '客户';
params.customerSource = ['客户推荐']
}
loading.value = false;
const res = await api('addCustomer', { params });
set('home-invite-team-info', { teamId: teamId.value })
if (res && res.success) {
uni.$emit('reloadTeamCustomers')
if (source.value === 'experienceCoupon') {
await toast('档案创建成功');
uni.navigateBack();
return;
}
if (redirectUrl.value) {
uni.redirectTo({ url: redirectUrl.value });
return;
}
// getTeam(corpId.value, teamId.value, res.data.id);
if (healthTypes.value.length) {
const nextType = healthTypes.value[0];
const nextTypes = healthTypes.value.slice(1);
const url = `/pages/health/record?type=${nextType}&teamId=${teamId.value}&corpId=${corpId.value}&customerId=${res.data.id}&nextTypes=${nextTypes.join(',')}&source=afterArchive`
uni.redirectTo({ url });
} else {
uni.redirectTo({
url: `/pages/archive/archive-result?corpId=${corpId.value}&teamId=${teamId.value}&customerId=${res.data.id}`
})
}
} else {
toast(res?.message || '新增档案失败');
}
}
async function getResponsiblePerson() {
const res = await api('getResponsiblePerson', { corpId: corpId.value, teamId: teamId.value, externalUserId: externalUserId.value, corpUserId: corpUserId.value });
return res && res.data ? res.data : ''
}
function shouldBackAfterArchiveBound() {
return ['experienceCoupon', 'appointmentRegistration'].includes(source.value)
}
function backAfterArchiveBound() {
if (shouldBackAfterArchiveBound()) {
uni.navigateBack()
return;
}
uni.switchTab({
url: '/pages/home/home'
})
}
async function bindArchive(customerId) {
let responsiblePerson = '';
if (externalUserId.value) {
const corpUserId = await getResponsiblePerson();
responsiblePerson = corpUserId || '';
}
const res = await api('bindMiniAppArchive', { id: customerId, corpId: corpId.value, teamId: teamId.value, miniAppId: account.value.openid, externalUserId: externalUserId.value, responsiblePerson });
if (res && res.success) {
await toast('绑定成功');
uni.$emit('reloadTeamCustomers')
backAfterArchiveBound()
} else {
toast(res?.message || '绑定失败');
}
}
async function init() {
if (await initArchiveQueryConfig()) return;
if (referenceCustomerId.value) {
getReferenceCustomer();
}
if (customerId.value) {
await getCustomer();
} else {
await getExternalUserId(corpId.value);
const res = bindCustomerId.value ? await getExperienceCouponBindArchive() : await getArchives();
if (res.length > 0) {
visible.value = true;
} else if (bindCustomerId.value || shouldBackAfterArchiveBound()) {
await toast('指定绑定档案不存在或已绑定');
uni.navigateBack();
return;
}
getTeam(corpId.value, teamId.value)
}
await getBaseForm();
if (!customerId.value) {
preProcessFrom()
}
}
async function initArchiveQueryConfig() {
const res = await api('getCorpInfo', { corpId: corpId.value }, false);
const data = Array.isArray(res.data)
? res.data[0]
: Array.isArray(res.data?.data)
? res.data.data[0]
: res.data?.data || res.data || {};
const config = data.hisArchiveQueryConfig && typeof data.hisArchiveQueryConfig === 'object'
? data.hisArchiveQueryConfig
: {};
const plans = Array.isArray(config.plans)
? config.plans
: Array.isArray(config.schemes)
? config.schemes
: [];
archiveQueryPlans.value = plans.filter(plan => plan && Array.isArray(plan.fields) && plan.fields.length);
if (!archiveQueryPlans.value.length) {
redirectArchivePage('edit-archive');
return true;
}
return false;
}
function redirectArchivePage(page) {
const query = Object.entries(pageOptions.value)
.filter(([, value]) => value !== undefined && value !== null && value !== '')
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
.join('&');
uni.redirectTo({
url: `/pages/archive/${page}${query ? `?${query}` : ''}`
});
}
async function getExperienceCouponBindArchive() {
const res = await api('getCustomerByCustomerId', { corpId: corpId.value, customerId: bindCustomerId.value });
const data = res && res.success && res.data ? res.data : null;
customers.value = data ? [data] : [];
corpName.value = res && res.corpName ? res.corpName : corpName.value;
enableHis.value = false;
return customers.value;
}
async function getArchives() {
const res = await api('getUnbindMiniAppCustomers', { corpId: corpId.value, mobile: account.value?.mobile || '', externalUserId: externalUserId.value });
customers.value = res && Array.isArray(res.data) ? res.data : [];
corpName.value = res && res.corpName ? res.corpName : '';
enableHis.value = res && res.enableHis ? res.enableHis : false;
return customers.value
}
async function getBaseForm() {
const res = await api('getTeamBaseInfo', { corpId: corpId.value, teamId: teamId.value });
if (res && res.success) {
teamFormItems.value = Array.isArray(res.data) ? res.data : [];
// const mobileIndex = formItems.value.findIndex(item => item.title === 'mobile');
// if (mobileIndex > -1) {
// formItems.value[mobileIndex].appendText = `()`;
// }
} else {
toast(res?.message || '查询失败');
return Promise.reject()
}
}
async function getCustomer() {
const res = await api('getCustomerByCustomerId', { customerId: customerId.value });
if (res && res.success && res.data) {
customer.value = res.data;
} else {
await toast(res?.message || '查询档案信息失败');
uni.navigateBack();
return Promise.reject()
}
}
async function updateArchive() {
if (Object.keys(form.value).length > 0) {
const res = await api('updateCustomer', { id: customerId.value, params: { ...form.value } });
if (res && res.success) {
await toast('修改成功');
uni.$emit('reloadTeamCustomers')
uni.navigateBack();
} else {
toast(res?.message || '修改失败');
}
} else {
uni.navigateBack();
}
}
async function unBindArchive() {
await uniConfirm('确定删除档案吗?')
const res = await api('unbindMiniAppArchive', { id: customer.value._id, corpId: corpId.value, teamId: teamId.value, miniAppId: account.value.openid });
if (res && res.success) {
await toast('删除成功');
uni.$emit('reloadTeamCustomers')
uni.navigateBack();
} else {
toast(res?.message || '删除失败')
}
}
async function getReferenceCustomer() {
const res = await api('getRefrencePeople', { corpId: corpId.value, id: referenceCustomerId.value });
referenceCustomer.value = res && res.data ? res.data : null;
}
async function getTeam(corpId, teamId, customerId) {
const res = await api('getTeamData', { teamId, corpId });
if (res && res.data) {
const team = res.data;
const qrcode = team && Array.isArray(team.qrcodes) ? team.qrcodes[0] : null;
const healthTempList = qrcode && Array.isArray(qrcode.healthTempList) ? qrcode.healthTempList : [];
healthTypes.value = healthTempList.filter(i => typeof i.templateType === 'string' && i.templateType.trim() && i.archiveRecommend === true).map(i => i.templateType);
}
}
onLoad(options => {
pageOptions.value = { ...options };
teamId.value = options.teamId;
corpId.value = options.corpId;
customerId.value = options.id || '';
bindCustomerId.value = options.bindCustomerId || '';
corpUserId.value = options.corpUserId || '';
referenceCustomerId.value = options.referenceCustomerId || '';
source.value = options.source || '';
redirectUrl.value = options.redirectUrl || '';
uni.setNavigationBarTitle({ title: customerId.value ? '编辑档案' : '新增档案' })
})
useLoad(options => {
init();
})
watch(hisQueryFormItems, (h) => {
if (h && h.length === 0 && step.value === 0) {
step.value = 1;
}
})
</script>
<style scoped></style>

View File

@ -48,6 +48,14 @@ export default [
path: 'pages/archive/edit-archive', path: 'pages/archive/edit-archive',
meta: { title: '新增档案', login: true } meta: { title: '新增档案', login: true }
}, },
{
path: 'pages/archive/step-edit-archive',
meta: { title: '新增档案', login: true }
},
{
path: 'pages/archive/fill-his-archive',
meta: { title: '完善信息', login: true }
},
{ {
path: 'pages/archive/archive-result', path: 'pages/archive/archive-result',
meta: { title: '团队服务' } meta: { title: '团队服务' }

View File

@ -90,6 +90,9 @@ const urlsConfig = {
bindHisArchive: 'bindHisArchive', bindHisArchive: 'bindHisArchive',
getMatchedHisArchive: 'getMatchedHisArchive', getMatchedHisArchive: 'getMatchedHisArchive',
}, },
customerHisSync: {
getHisCustomerArchive: 'getHisCustomerArchive',
},
wecom: { wecom: {
addContactWay: 'getCorpFriendQrcode' addContactWay: 'getCorpFriendQrcode'
}, },

View File

@ -173,6 +173,7 @@ const request = async (options = {}, showLoading = true) => {
return res.data; return res.data;
} }
return { return {
...(res && res.data && typeof res.data === "object" ? res.data : {}),
success: false, success: false,
message: res.data && res.data.message ? res.data.message : "请求失败", message: res.data && res.data.message ? res.data.message : "请求失败",
}; };