| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- <template>
- <CommonRoot>
- <FlexCol padding="space.lg">
- <SimplePageContentLoader :loader="loader">
- <template v-if="loader.isFinished.value">
- <Result
- v-if="!currentForm"
- status="info"
- title="您还未填写评估表"
- >
- <Height :height="30" />
- <Button type="primary" @click="createForm">去填写评估表</Button>
- </Result>
- <FlexCol v-else gap="gap.md">
- <DynamicForm
- ref="form1Ref"
- :model="currentForm"
- :options="formOptions"
- />
- <Button @click="navTo('/pages/test/test')">test</Button>
- <H3>自查项目选择</H3>
- <FlexCol v-if="checkItemList && checkItemList.length > 0" gap="gap.md">
- <FlexCol v-for="(item, index) in checkItemList" :key="item.id" gap="gap.md">
- <Text fontConfig="subTitleText" :text="`${index + 1}. ${item.name}`" />
- <FlexCol v-if="item.checkType == 2" gap="gap.sm">
- <FlexRow v-for="child in item.children" :key="child.id" justify="space-between">
- <CheckBox
- :text="`${child.name} (${child.points}分)`"
- :modelValue="hasCheckedItem(child.id)"
- @update:modelValue="setCheckedItem(item as CheckItemInfo, child as CheckItemInfo, $event)"
- />
- <Stepper
- v-if="hasCheckedItem(child.id)"
- :min="0"
- :max="20"
- :step="1"
- :modelValue="getCheckedItemCount(child.id) ?? 0"
- @update:modelValue="setCheckedItem(item as CheckItemInfo, child as CheckItemInfo, $event)"
- />
- <view v-else></view>
- </FlexRow>
- </FlexCol>
- <FlexCol v-else gap="gap.sm">
- <CheckBox
- v-for="child in item.children" :key="child.id"
- :text="`${child.name} (${child.points}分)`"
- :modelValue="hasCheckedItem(child.id)"
- @update:modelValue="setCheckedItem(item as CheckItemInfo, child as CheckItemInfo, $event)"
- />
- </FlexCol>
- </FlexCol>
- </FlexCol>
- <DynamicForm
- ref="form3Ref"
- :model="currentForm"
- :options="formOptionsEnd"
- />
- <FlexRow align="center" justify="space-between">
- <H3>自评总分</H3>
- <Text fontSize="44rpx" fontFamily="HUNdin1451" :text="`${totalPoints}分`" />
- </FlexRow>
- <Button type="primary" block :loading="submitLoading" @click="saveForm">保存评估表</Button>
- <Button :loading="submitLoading" @click="downloadForm">下载评估表PDF</Button>
- </FlexCol>
- </template>
- </SimplePageContentLoader>
- <XBarSpace />
- </FlexCol>
- </CommonRoot>
- </template>
- <script setup lang="ts">
- import { computed, ref } from 'vue';
- import { useSimpleDataLoader } from '@/components/composeabe/loader/SimpleDataLoader';
- import { useAuthStore } from '@/store/auth';
- import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
- import { ArrayUtils, assertNotNull, formatError, waitTimeOut } from '@imengyu/imengyu-utils';
- import { toast, alert } from '@/components/dialog/CommonRoot';
- import AssessmentContentApi, {
- SelfAssessmentDetail,
- CheckItemInfo,
- SelfAssessmentCheckItemAnswer,
- } from '@/api/collect/AssessmentContent';
- import CommonRoot from '@/components/dialog/CommonRoot.vue';
- import Button from '@/components/basic/Button.vue';
- import Result from '@/components/feedback/Result.vue';
- import FlexCol from '@/components/layout/FlexCol.vue';
- import Height from '@/components/layout/space/Height.vue';
- import SimplePageContentLoader from '@/components/loader/SimplePageContentLoader.vue';
- import DynamicForm from '@/components/dynamic/DynamicForm.vue';
- import H3 from '@/components/typography/H3.vue';
- import FlexRow from '@/components/layout/FlexRow.vue';
- import Text from '@/components/basic/Text.vue';
- import XBarSpace from '@/components/layout/space/XBarSpace.vue';
- import CheckBox from '@/components/form/CheckBox.vue';
- import Stepper from '@/components/form/Stepper.vue';
- import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
- import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
- import type { FieldProps } from '@/components/form/Field.vue';
- import type { SignatureFieldProps } from '@/components/form/SignatureField.vue';
- import { useImageSimpleUploadCo } from '@/common/components/upload/ImageUploadCo';
- import { navTo } from '@/components/utils/PageAction';
- let loaded = false;
- const { querys } = useLoadQuerys({
- id: 0,
- }, () => {
- if (loaded)
- return;
- loaded = true;
- loader.load();
- });
- const currentForm = ref<SelfAssessmentDetail | null>(null);
- const currentFormCheckItems = ref<SelfAssessmentCheckItemAnswer[]>([]);
- const authStore = useAuthStore();
- const form1Ref = ref<IDynamicFormRef | null>(null);
- const form3Ref = ref<IDynamicFormRef | null>(null);
- const formOptions = ref<IDynamicFormOptions>({
- formAdditionaProps: {
- labelFlex: 4,
- inputFlex: 8,
- },
- formItems: [
- {
- type: 'flat-group',
- label: '传承人自查评估',
- name: 'selfAssessmentGroup',
- childrenColProps: { span: 24 },
- children: [
- {
- label: '传承人名称',
- name: 'inheritor',
- type: 'text',
- additionalProps: { placeholder: '请输入传承人名称' },
- },
- {
- label: '项目保护单位',
- name: 'unit',
- type: 'text',
- additionalProps: { placeholder: '请输入项目保护单位' },
- },
- {
- label: '项目名称',
- name: 'ichName',
- type: 'text',
- additionalProps: { placeholder: '请输入项目名称' },
- },
- {
- label: '联系电话',
- name: 'mobile',
- type: 'text',
- additionalProps: { placeholder: '请输入联系电话' },
- },
- {
- label: '身份证号',
- name: 'idCard',
- type: 'text',
- additionalProps: { placeholder: '请输入身份证号' },
- },
- {
- label: '级别',
- name: 'level',
- type: 'select-id',
- additionalProps: {
- placeholder: '请选择级别',
- loadData: async () => [
- { text: '国家级', value: 23 },
- { text: '省级', value: 24 },
- { text: '市级', value: 25 },
- ],
- },
- },
- {
- label: '家庭住址',
- name: 'address',
- type: 'text',
- additionalProps: { placeholder: '请输入家庭住址' },
- },
- {
- label: '自评报告',
- name: 'content',
- type: 'richtext',
- additionalProps: { placeholder: '请填写自评报告' },
- },
- ],
- },
- ],
- formRules: {
- inheritor: [{ required: true, message: '请输入传承人名称' }],
- unit: [{ required: true, message: '请输入项目保护单位' }],
- ichName: [{ required: true, message: '请输入项目名称' }],
- mobile: [{ required: true, message: '请输入联系电话' }],
- idCard: [{ required: true, message: '请输入身份证号' }],
- level: [{ required: true, message: '请选择级别' }],
- address: [{ required: true, message: '请输入家庭住址' }],
- content: [{ required: true, message: '请填写自评报告' }],
- self: [{ required: true, message: '请选择自我评估' }],
- },
- });
- const formOptionsEnd = ref<IDynamicFormOptions>({
- formAdditionaProps: {
- labelPosition: 'top',
- },
- formItems: [
- {
- type: 'flat-group',
- label: '传承人自查评估',
- name: 'selfAssessmentGroup',
- childrenColProps: { span: 24 },
- children: [
- {
- label: '其他相关情况(扣分内容)',
- name: 'deductContent',
- type: 'text',
- additionalProps: {
- showWordLimit: true,
- maxlength: 260,
- placeholder: '请输入其他相关情况(扣分内容)',
- } as FieldProps,
- },
- {
- label: '其他相关情况(扣分分值)',
- name: 'deductPoints',
- type: 'number',
- additionalProps: {
- placeholder: '请输入其他相关情况(扣分分值)',
- min: 0,
- max: 100,
- },
- },
- {
- label: '自我评估',
- name: 'self',
- type: 'radio-value',
- additionalProps: {
- options: [
- { text: '优秀', value: 1 },
- { text: '合格', value: 2 },
- { text: '不合格', value: 3 },
- { text: '丧失传承能力', value: 4 },
- { text: '取消资格', value: 5 },
- ],
- vertical: true,
- } as RadioValueProps,
- },
- {
- label: '传承人签名',
- name: 'sign',
- type: 'sign',
- formProps: {
- showRightArrow: true,
- },
- additionalProps: {
- upload: useImageSimpleUploadCo(),
- } as SignatureFieldProps,
- }
- ],
- },
- ],
- formRules: {
- self: [{ required: true, message: '请选择自我评估' }],
- sign: [{ required: true, message: '请传承人签名' }],
- },
- });
- const checkItemList = ref<CheckItemInfo[]>([]);
- const totalPoints = computed(() => {
- if (!currentForm.value)
- return 0;
- return currentFormCheckItems.value.reduce((acc, item) => acc + (item.count * item.points), 0);
- });
- async function loadBasicInfo() {
- const basicInfo = await AssessmentContentApi.getInheritorBasic(authStore.userInfo?.id);
- assertNotNull(currentForm.value, 'currentForm is null');
- currentForm.value.inheritor = basicInfo.name;
- currentForm.value.unit = basicInfo.unit;
- currentForm.value.ichName = basicInfo.ichName;
- currentForm.value.mobile = basicInfo.mobile;
- currentForm.value.level = basicInfo.level;
- currentForm.value.idCard = basicInfo.idCard;
- currentForm.value.address = basicInfo.address;
- }
- async function loadCheckItems() {
- assertNotNull(currentForm.value, 'currentForm is null');
- checkItemList.value = await AssessmentContentApi.getCheckItems(Number(currentForm.value.level));
- currentFormCheckItems.value = currentForm.value.checkItems.concat();
- }
- function hasCheckedItem(id: number) {
- return currentFormCheckItems.value.some(item => item.id === id);
- }
- function getCheckedItemCount(id: number) {
- console.log('getCheckedItemCount', id);
- return currentFormCheckItems.value.find(item => item.id === id)?.count;
- }
- function setCheckedItem(checkItem: CheckItemInfo, childItem: CheckItemInfo, count: number|boolean) {
- if (!currentForm.value)
- return;
- if (typeof count === 'boolean') {
- count = count ? 1 : 0;
- }
- console.log('setCheckedItem', childItem.id, count);
- let item = currentFormCheckItems.value.find(item => item.id === childItem.id);
- if (!item) {
- item = new SelfAssessmentCheckItemAnswer();
- currentFormCheckItems.value.push(item);
- }
- if (item.count === count)
- return;
- item.id = childItem.id;
- item.points = childItem.points;
- item.count = count;
- switch (checkItem.checkType) {
- case 1: {
- /** 单选,清除其他选项 */
- const allChildren = checkItem.children.map(child => child.id);
- currentFormCheckItems.value.forEach(item => {
- if (allChildren.includes(item.id) && item.id !== childItem.id)
- item.count = 0;
- });
- break;
- }
- }
- if (item.count === 0)
- ArrayUtils.remove(currentFormCheckItems.value, item);
- }
- const submitLoading = ref(false);
- async function createForm() {
- const detail = new SelfAssessmentDetail();
- detail.userId = authStore.userInfo!.id;
- detail.year = new Date().getFullYear();
- detail.checkItems = [];
- currentForm.value = detail;
- await loadBasicInfo();
- await loadCheckItems();
- }
- async function saveForm() {
- const detail = currentForm.value;
- try {
- await form1Ref.value?.validate();
- await form3Ref.value?.validate();
- } catch (error) {
- toast('请填写完整信息');
- return;
- }
- submitLoading.value = true;
- currentForm.value!.checkItems = currentFormCheckItems.value;
- try {
- assertNotNull(detail, 'currentForm is null');
- await AssessmentContentApi.saveSelfAssessment(detail as SelfAssessmentDetail);
- toast('保存评估表成功');
- } catch (error) {
- alert({
- title: '保存评估表失败',
- content: formatError(error),
- });
- }
- submitLoading.value = false;
- }
- async function downloadForm() {
- try {
- assertNotNull(currentForm.value, 'currentForm is null');
- throw new Error('没这个接口');
- } catch (error) {
- alert({
- title: '下载评估表失败',
- content: formatError(error),
- });
- }
- }
- const loader = useSimpleDataLoader(async () => {
- await waitTimeOut(1000);
- console.log('load');
-
- if (querys.value.id > 0) {
- const detail = await AssessmentContentApi.getSelfAssessmentDetail(querys.value.id);
- currentForm.value = detail;
- await loadCheckItems();
- return;
- }
- const list = await AssessmentContentApi.getSelfAssessmentList({
- userId: authStore.userInfo?.id,
- year: new Date().getFullYear(),
- });
- if (list.data.length > 0) {
- const detail = await AssessmentContentApi.getSelfAssessmentDetail(list.data[0].id);
- currentForm.value = detail;
- await loadCheckItems();
- } else {
- currentForm.value = null;
- createForm();
- }
- return currentForm.value;
- }, false);
- </script>
|