ykt-wxapp/pages/work/profile.vue

165 lines
5.3 KiB
Vue
Raw Normal View History

2026-01-20 16:30:03 +08:00
<template>
2026-01-23 14:36:28 +08:00
<full-page>
<view class="p-15">
<view class="bg-white px-10 mb-10 rounded">
<form-input :form="formData" required wordLimit="10" title="anotherName" name="姓名" @change="onChange($event)" />
<common-cell title="avatar" name="头像">
<view class="flex-grow flex items-center justify-end" @click="chooseAvatar()">
<image v-if="formData.avatar" class="avatar mr-5 rounded-full" :src="formData.avatar" />
<image v-else class="avatar mr-5 rounded-full" src="/static/default-avatar.png" />
<uni-icons color="#999" type="right" size="16" />
2026-01-20 16:30:03 +08:00
</view>
2026-01-23 14:36:28 +08:00
</common-cell>
<form-select :form="formData" name="性别" title="gender" :range="genderOptions" @change="onChange($event)" />
<form-input :form="formData" disableChange wordLimit="11" title="mobile" name="手机号 (不可修改)" />
</view>
<view class="bg-white px-10 mb-10 rounded">
<common-cell title="avatar" name="岗位">
<view class="flex-grow flex items-center justify-end">
<!-- <view class="mr-5 rounded-full" style="width: 64rpx;height: 64rpx;background: red;"></view> -->
<uni-icons color="#999" type="right" size="16" />
2026-01-20 16:30:03 +08:00
</view>
2026-01-23 14:36:28 +08:00
</common-cell>
<common-cell title="avatar" name="职称">
<view class="flex-grow flex items-center justify-end">
<!-- <view class="mr-5 rounded-full" style="width: 64rpx;height: 64rpx;background: red;"></view> -->
<uni-icons color="#999" type="right" size="16" />
</view>
</common-cell>
<common-cell title="avatar" name="科室">
<view class="flex-grow flex items-center justify-end">
<!-- <view class="mr-5 rounded-full" style="width: 64rpx;height: 64rpx;background: red;"></view> -->
<uni-icons color="#999" type="right" size="16" />
</view>
</common-cell>
</view>
2026-01-20 16:30:03 +08:00
2026-01-23 14:36:28 +08:00
<view class="bg-white rounded">
<form-textarea :border="false" :form="formData" title="intro" name="个人介绍" :wordLimit="300"
@change="onChange($event)" />
</view>
2026-01-20 16:30:03 +08:00
</view>
2026-01-23 14:36:28 +08:00
<template #footer>
<button-footer :cancelText="cancelText" :confirmText="confirmText" @confirm="save()" @cancel="back()" />
</template>
</full-page>
2026-01-20 16:30:03 +08:00
</template>
<script setup>
2026-01-23 14:36:28 +08:00
import { computed, ref } from "vue";
import { storeToRefs } from "pinia";
2026-01-20 16:30:03 +08:00
import useGuard from "@/hooks/useGuard.js";
import useAccountStore from "@/store/account.js";
2026-01-23 14:36:28 +08:00
import api from "@/utils/api.js";
import { upload } from "@/utils/http.js";
import { toast } from "@/utils/widget";
import buttonFooter from '@/components/button-footer.vue';
import commonCell from "@/components/form-template/common-cell.vue";
2026-01-21 13:37:54 +08:00
import FormInput from "@/components/form-template/form-cell/form-input.vue";
2026-01-20 16:30:03 +08:00
import FormSelect from "@/components/form-template/form-cell/form-select.vue";
import FormTextarea from "@/components/form-template/form-cell/form-textarea.vue";
2026-01-23 14:36:28 +08:00
import fullPage from '@/components/full-page.vue';
2026-01-21 13:37:54 +08:00
const { account, doctorInfo } = storeToRefs(useAccountStore());
2026-01-23 14:36:28 +08:00
const { useLoad, useShow } = useGuard();
2026-01-21 15:27:18 +08:00
const { getDoctorInfo } = useAccountStore();
2026-01-23 14:36:28 +08:00
const form = ref({});
const type = ref('')
const formData = computed(() => ({ ...(doctorInfo.value || {}), ...form.value, mobile: account.value?.mobile }));
const cancelText = computed(() => doctorInfo.value ? '取消' : '暂不填写');
const confirmText = computed(() => type.value === 'cert' ? '下一步' : '保存');
2026-01-20 16:30:03 +08:00
// 选项数据
2026-01-21 15:27:18 +08:00
const genderOptions = [
{ label: "男", value: "0" },
{ label: "女", value: "1" },
];
2026-01-20 16:30:03 +08:00
// 打开科室选择
const openDepartmentSelect = () => {
uni.navigateTo({
url: "/pages/work/department-select",
events: {
deptSelected: ({ name, deptId }) => {
formData.value.department = name || "";
formData.value.departmentName = name || "";
formData.value.departmentId = deptId || "";
},
},
});
};
2026-01-23 14:36:28 +08:00
function back() {
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack();
} else {
uni.switchTab({
url: "/pages/work/work",
});
2026-01-20 16:30:03 +08:00
}
}
2026-01-23 14:36:28 +08:00
function chooseAvatar() {
uni.chooseImage({
count: 1,
success: async (res) => {
const [path] = res.tempFilePaths;
const url = await upload(path);
if (url) {
form.value.avatar = url;
} else {
toast('上传失败')
}
}
})
2026-01-20 16:30:03 +08:00
}
2026-01-23 14:36:28 +08:00
function onChange({ title, value }) {
form.value[title] = value
2026-01-20 16:30:03 +08:00
}
2026-01-23 14:36:28 +08:00
async function save() {
if (typeof formData.value.anotherName !== 'string' || !formData.value.anotherName.trim()) {
return toast('请输入姓名')
}
if (type.value === 'cert' && !formData.value.departmentId) {
return toast('请输入岗位信息')
}
const apiName = doctorInfo.value ? 'updateCorpMemberFromWxapp' : 'addCorpMemberFromWxapp';
const data = {
...form.value,
weChatOpenId: account.value.openid,
mobile: account.value.mobile,
corpId: account.value.corpId,
}
const res = await api(apiName, data);
if (res && res.success) {
await toast('保存成功');
await getDoctorInfo()
back()
} else {
await toast(res?.message || '保存失败');
2026-01-20 16:30:03 +08:00
}
}
2026-01-23 14:36:28 +08:00
useLoad(opts => {
type.value = opts?.type;
})
2026-01-20 16:30:03 +08:00
2026-01-23 14:36:28 +08:00
useShow(() => {
getDoctorInfo()
});
2026-01-20 16:30:03 +08:00
2026-01-23 14:36:28 +08:00
</script>
2026-01-20 16:30:03 +08:00
2026-01-23 14:36:28 +08:00
<style lang="scss" scoped>
.avatar {
width: 64rpx;
height: 64rpx;
2026-01-20 16:30:03 +08:00
}
</style>