Files
zkxw/mobile-oa-h5/src/market/components/ProjectAssignmentField.vue
T
zlwu bd62416263 feat(project): add team attribution and business statistics
Add tenant-scoped teams and projects, order attribution across four businesses, conversion inheritance, scoped statistics and audited reassignment. Reuse existing Web and mobile UI patterns; team regions and hospitals remain informational.

Include incremental SQL and isolated regression coverage. Actual MySQL and browser/WebView integration validation remains pending; relates to issue #13.
2026-11-02 15:29:43 +08:00

78 lines
3.3 KiB
Vue

<template>
<section class="market-form-section">
<h2>{{ filter ? '项目筛选' : '项目归属' }}<span v-if="required && !editing && !filter"> *</span></h2>
<template v-if="editing">
<van-cell title="所属项目" :value="projectLabel(record)" />
<van-cell title="项目组" :value="record.teamName || '—'" />
<van-cell label="归属调整请使用 Web 项目归属维护" />
</template>
<template v-else>
<PresignSelectField
:model-value="modelValue || ''"
:options="selectOptions"
:disabled="disabled || loading || Boolean(error)"
:loading="loading"
searchable
title="所属项目"
:placeholder="filter ? '全部项目' : '请选择所属项目'"
@update:model-value="emit('update:modelValue', $event)"
/>
<van-cell v-if="loading" title="正在加载项目…" />
<van-cell v-else-if="error" :label="error" title="项目加载失败,点击重试" is-link @click="load" />
<van-cell v-else-if="!options.length" :label="required && !filter ? '请联系管理员配置可选项目后再保存' : '当前没有可选项目'" />
</template>
</section>
</template>
<script setup>
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import { fetchProjectOptions } from '../../api/market.js'
import { projectLabel, projectOptions, projectValidation } from '../project-assignment.js'
import PresignSelectField from './PresignSelectField.vue'
const props = defineProps({
modelValue: { type: String, default: '' },
bizType: { type: String, required: true },
editing: { type: Boolean, default: false },
filter: { type: Boolean, default: false },
context: { type: Object, default: null },
disabled: { type: Boolean, default: false },
record: { type: Object, default: () => ({}) }
})
const emit = defineEmits(['update:modelValue'])
const options = ref([])
const required = ref(false)
const loading = ref(true)
const error = ref('')
let controller
const selectOptions = computed(() => [
...(!required.value || props.filter ? [{ text: props.filter ? '全部项目' : '暂不归属', value: '' }] : []),
...options.value
])
async function load() {
controller?.abort()
if (props.editing) { loading.value = false; return }
const current = new AbortController()
controller = current
loading.value = true
error.value = ''
options.value = []
try {
const data = await fetchProjectOptions(props.bizType, { signal: current.signal, filter: props.filter, context: props.context })
if (controller !== current) return
options.value = projectOptions(data)
required.value = Boolean(data.required)
} catch (cause) {
if (controller === current && cause?.name !== 'AbortError') error.value = cause?.message || '请稍后重试'
} finally {
if (controller === current) loading.value = false
}
}
watch(() => [props.bizType, props.editing], (next, previous) => {
if (previous && next[0] !== previous[0] && !props.editing) emit('update:modelValue', '')
load()
}, { immediate: true })
onBeforeUnmount(() => { controller?.abort(); controller = null })
defineExpose({ validate: () => projectValidation({ editing: props.editing || props.filter, loading: loading.value, error: error.value, required: required.value, projectId: props.modelValue }) })
</script>