feat:模具管理-维修单-选择人员下拉交互修改

master
黄伟杰 7 days ago
parent 6fbb7fbc5a
commit b89757deb4

@ -22,10 +22,11 @@ export function getUserProfile() {
})
}
export function getSimpleUserList() {
export function getSimpleUserList(params) {
return request({
url: '/admin-api/system/user/simple-list',
method: 'get'
method: 'get',
params
})
}

@ -669,6 +669,13 @@
"navigationStyle": "custom"
}
},
{
"path": "moldRepair/userSelect",
"style": {
"navigationBarTitleText": "选择人员",
"navigationStyle": "custom"
}
},
{
"path": "moldInspectionItems/index",
"style": {

@ -37,16 +37,18 @@
<view class="form-item">
<text class="form-label">{{ t('moldRepair.acceptedBy') }}</text>
<picker :range="userLabels" :value="acceptedByIndex" :disabled="readonlyMeta" @change="(e) => onUserChange('acceptedBy', e)">
<view :class="['picker-field', !formData.acceptedBy ? 'is-placeholder' : '']">{{ acceptedByLabel }}</view>
</picker>
<view :class="['picker-field', !formData.acceptedBy ? 'is-placeholder' : '', readonlyMeta ? 'is-disabled' : '']" @click="openUserSelect('acceptedBy')">
<text>{{ acceptedByLabel }}</text>
<uni-icons v-if="!readonlyMeta" type="right" size="16" color="#9ca3af"></uni-icons>
</view>
</view>
<view class="form-item">
<text class="form-label">{{ t('moldRepair.confirmBy') }}</text>
<picker :range="userLabels" :value="confirmByIndex" :disabled="readonlyMeta" @change="(e) => onUserChange('confirmBy', e)">
<view :class="['picker-field', !formData.confirmBy ? 'is-placeholder' : '']">{{ confirmByLabel }}</view>
</picker>
<view :class="['picker-field', !formData.confirmBy ? 'is-placeholder' : '', readonlyMeta ? 'is-disabled' : '']" @click="openUserSelect('confirmBy')">
<text>{{ confirmByLabel }}</text>
<uni-icons v-if="!readonlyMeta" type="right" size="16" color="#9ca3af"></uni-icons>
</view>
</view>
<view class="form-item inline-radio">
@ -219,7 +221,7 @@
<script setup>
import { computed, reactive, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { useI18n } from 'vue-i18n'
import NavBar from '@/components/common/NavBar.vue'
import { getBrandList } from '@/api/mes/mold'
@ -240,6 +242,7 @@ const repairId = ref('')
const users = ref([])
const moldOptions = ref([])
const loading = ref(false)
const today = getTodayDate()
const formData = reactive({
id: undefined,
@ -249,9 +252,9 @@ const formData = reactive({
moldId: undefined,
moldCode: '',
moldName: '',
requireDate: '',
finishDate: '',
confirmDate: '',
requireDate: today,
finishDate: today,
confirmDate: today,
repairStatus: '0',
repairResult: '0',
acceptedBy: '',
@ -291,7 +294,6 @@ const statusLabel = computed(() => {
if (normalized === '2') return t('moldRepair.statusRejected')
return t('moldRepair.statusPending')
})
const userLabels = computed(() => users.value.map((item) => item.nickname || item.name || String(item.id || '')))
const moldLabels = computed(() => moldOptions.value.map((item) => item.label))
const faultLevelOptions = computed(() => {
const dicts = dictStore.getDict(DICT_TYPE.FAILURE_LEVEL) || []
@ -302,8 +304,6 @@ const faultLevelOptions = computed(() => {
value: String(item.value)
}))
})
const acceptedByIndex = computed(() => findUserIndex(formData.acceptedBy))
const confirmByIndex = computed(() => findUserIndex(formData.confirmBy))
const acceptedByLabel = computed(() => resolveUserLabel(formData.acceptedBy, t('moldRepair.placeholderAcceptedBy')))
const confirmByLabel = computed(() => resolveUserLabel(formData.confirmBy, t('moldRepair.placeholderConfirmBy')))
const moldIndex = computed(() => {
@ -327,6 +327,10 @@ onLoad(async (options) => {
}
})
onShow(() => {
applySelectedUser()
})
async function fetchUsers() {
try {
const res = await getSimpleUserList()
@ -373,9 +377,9 @@ async function fetchDetail(id) {
formData.moldId = detail?.moldId ?? detail?.machineryId
formData.moldCode = inputValue(detail?.moldCode ?? detail?.machineryCode)
formData.moldName = inputValue(detail?.moldName ?? detail?.machineryName)
formData.requireDate = formatPickerDate(detail?.requireDate)
formData.finishDate = formatPickerDate(detail?.finishDate)
formData.confirmDate = formatPickerDate(detail?.confirmDate)
formData.requireDate = defaultDateValue(detail?.requireDate)
formData.finishDate = defaultDateValue(detail?.finishDate)
formData.confirmDate = defaultDateValue(detail?.confirmDate)
formData.repairStatus = normalizedRepairStatus
formData.repairResult = normalizedRepairStatus
formData.acceptedBy = normalizeUserId(detail?.acceptedBy)
@ -423,12 +427,6 @@ function onDateChange(field, event) {
formData[field] = String(event?.detail?.value || '')
}
function onUserChange(field, event) {
const index = Number(event?.detail?.value || 0)
const current = users.value[index]
formData[field] = current ? String(current.id) : ''
}
function onMoldChange(event) {
const index = Number(event?.detail?.value || 0)
const current = moldOptions.value[index]
@ -501,12 +499,6 @@ function onRepairStatusChange(event) {
formData.repairResult = value
}
function findUserIndex(value) {
if (value === undefined || value === null || value === '') return 0
const index = users.value.findIndex((item) => String(item.id) === String(value) || item.nickname === String(value))
return index >= 0 ? index : 0
}
function resolveUserLabel(value, placeholder) {
if (value === undefined || value === null || value === '') return placeholder
const current = users.value.find((item) => String(item.id) === String(value) || item.nickname === String(value))
@ -529,6 +521,36 @@ function datePickerValue(value) {
return value || formatPickerDate(Date.now())
}
function openUserSelect(field) {
if (readonlyMeta.value) return
const selectedId = field === 'acceptedBy' ? formData.acceptedBy : formData.confirmBy
uni.navigateTo({
url: `/pages_function/pages/moldRepair/userSelect?field=${encodeURIComponent(field)}&selectedId=${encodeURIComponent(String(selectedId || ''))}`
})
}
function applySelectedUser() {
const result = getApp().globalData._moldRepairUserSelectResult
if (!result?.field || !result?.user) return
getApp().globalData._moldRepairUserSelectResult = null
const field = result.field === 'confirmBy' ? 'confirmBy' : 'acceptedBy'
const user = result.user
formData[field] = String(user.id || '')
if (user.id !== undefined && user.id !== null && !users.value.some((item) => String(item.id) === String(user.id))) {
users.value = [user, ...users.value]
}
}
function getTodayDate() {
return formatPickerDate(Date.now())
}
function defaultDateValue(value) {
const formatted = formatPickerDate(value)
if (formatted) return formatted
return mode.value === 'detail' ? '' : today
}
function formatPickerDate(value) {
if (value === undefined || value === null || value === '') return ''
const date = parseDate(value)
@ -817,6 +839,8 @@ function goBack() {
padding: 0 20rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.form-textarea {
@ -828,6 +852,10 @@ function goBack() {
color: #9ca3af;
}
.picker-field.is-disabled {
color: #9ca3af;
}
.code-row {
display: flex;
align-items: center;

@ -0,0 +1,257 @@
<template>
<view class="page-container">
<NavBar :title="pageTitle" />
<view class="search-bar">
<view class="search-input-wrap">
<text class="search-icon iconfont icon-search"></text>
<input
v-model="searchText"
class="search-input"
type="text"
:placeholder="t('moldRepair.placeholderUserSearch')"
placeholder-class="search-placeholder"
confirm-type="search"
@input="onSearchInput"
@confirm="loadUsers"
/>
<text v-if="searchText" class="search-clear" @click="clearSearch">x</text>
</view>
</view>
<scroll-view v-if="userList.length > 0" scroll-y class="user-list">
<view
v-for="user in userList"
:key="user.id"
class="user-card"
:class="{ active: String(selectedId) === String(user.id) }"
@click="selectedId = user.id"
>
<text class="user-name">{{ textValue(user.nickname) }}</text>
<view class="user-meta">
<text class="user-meta-text">ID: {{ textValue(user.id) }}</text>
<text v-if="user.deptName" class="user-meta-divider">|</text>
<text v-if="user.deptName" class="user-meta-text">{{ textValue(user.deptName) }}</text>
</view>
</view>
</scroll-view>
<view v-else class="empty-wrap">
<text v-if="loading" class="empty-text">{{ t('functionCommon.loading') }}</text>
<text v-else class="empty-text">{{ t('moldRepair.noUserData') }}</text>
</view>
<view class="bottom-actions">
<view class="bottom-btn confirm-btn" @click="handleConfirm">
{{ t('functionCommon.confirm') }}
</view>
</view>
</view>
</template>
<script setup>
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { useI18n } from 'vue-i18n'
import NavBar from '@/components/common/NavBar.vue'
import { getSimpleUserList } from '@/api/system/user'
const { t } = useI18n()
const field = ref('acceptedBy')
const selectedId = ref('')
const searchText = ref('')
const userList = ref([])
const loading = ref(false)
let searchTimer = null
const pageTitle = computed(() => {
return field.value === 'confirmBy' ? t('moldRepair.confirmBy') : t('moldRepair.acceptedBy')
})
onLoad(async (options) => {
field.value = String(options?.field || 'acceptedBy')
selectedId.value = String(options?.selectedId || '')
await loadUsers()
})
function onSearchInput() {
if (searchTimer) {
clearTimeout(searchTimer)
}
searchTimer = setTimeout(() => {
loadUsers()
}, 300)
}
function clearSearch() {
searchText.value = ''
loadUsers()
}
async function loadUsers() {
if (searchTimer) {
clearTimeout(searchTimer)
searchTimer = null
}
loading.value = true
try {
const nickname = searchText.value.trim()
const res = await getSimpleUserList({
nickname: nickname || undefined
})
const root = res && res.data !== undefined ? res.data : res
const data = Array.isArray(root) ? root : (Array.isArray(root?.data) ? root.data : [])
userList.value = Array.isArray(data) ? data : []
} catch (error) {
userList.value = []
} finally {
loading.value = false
}
}
function handleConfirm() {
if (!selectedId.value) {
uni.showToast({ title: t('moldRepair.validatorUserRequired'), icon: 'none' })
return
}
const user = userList.value.find((item) => String(item.id) === String(selectedId.value))
if (!user) {
uni.showToast({ title: t('moldRepair.validatorUserRequired'), icon: 'none' })
return
}
getApp().globalData._moldRepairUserSelectResult = {
field: field.value === 'confirmBy' ? 'confirmBy' : 'acceptedBy',
user
}
uni.navigateBack()
}
function textValue(value) {
if (value === 0) return '0'
if (value === null || value === undefined) return '-'
const text = String(value).trim()
return text || '-'
}
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background: #f5f6f8;
padding-bottom: 140rpx;
}
.search-bar {
padding: 16rpx 24rpx;
background: #fff;
}
.search-input-wrap {
display: flex;
align-items: center;
height: 72rpx;
padding: 0 16rpx;
background: #f5f6f8;
border-radius: 36rpx;
}
.search-icon {
font-size: 32rpx;
color: #999;
margin-right: 12rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
}
.search-placeholder {
color: #bbb;
}
.search-clear {
font-size: 28rpx;
color: #999;
padding: 8rpx;
}
.user-list {
padding: 16rpx 24rpx;
}
.user-card {
background: #fff;
border-radius: 14rpx;
padding: 28rpx 24rpx;
margin-bottom: 16rpx;
border: 2rpx solid transparent;
&.active {
border-color: #2563eb;
background: #f0f5ff;
}
}
.user-name {
font-size: 30rpx;
font-weight: 700;
color: #1a1a1a;
}
.user-meta {
display: flex;
align-items: center;
gap: 10rpx;
margin-top: 10rpx;
}
.user-meta-text {
font-size: 24rpx;
color: #7a8494;
line-height: 1.3;
}
.user-meta-divider {
font-size: 22rpx;
color: #c3cad5;
}
.empty-wrap {
padding: 120rpx 0;
text-align: center;
}
.empty-text {
font-size: 28rpx;
color: #999;
}
.bottom-actions {
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 18rpx 24rpx calc(18rpx + env(safe-area-inset-bottom));
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.06);
z-index: 99;
}
.bottom-btn {
width: 100%;
height: 84rpx;
line-height: 84rpx;
text-align: center;
border-radius: 16rpx;
font-size: 30rpx;
font-weight: 600;
}
.confirm-btn {
background: #1f4b79;
color: #fff;
}
</style>
Loading…
Cancel
Save