feat:模具维修-选择模具交互优化
parent
1bbe6c7b90
commit
2db4fce017
@ -0,0 +1,283 @@
|
||||
<template>
|
||||
<view class="page-container">
|
||||
<NavBar :title="t('moldRepair.placeholderMold')" />
|
||||
|
||||
<view class="search-bar">
|
||||
<view class="search-input-wrap">
|
||||
<text class="search-icon iconfont icon-search"></text>
|
||||
<input
|
||||
id="mold-repair-mold-select-search-input"
|
||||
v-model="searchText"
|
||||
class="search-input"
|
||||
type="text"
|
||||
:placeholder="t('moldRepair.scanMoldPlaceholder')"
|
||||
placeholder-class="search-placeholder"
|
||||
confirm-type="search"
|
||||
@input="onSearchInput"
|
||||
@confirm="loadMolds"
|
||||
/>
|
||||
<text v-if="searchText" class="search-clear" @click="clearSearch">x</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<scroll-view v-if="moldList.length > 0" scroll-y class="mold-list">
|
||||
<view
|
||||
v-for="mold in moldList"
|
||||
:key="mold.id"
|
||||
class="mold-card"
|
||||
:class="{ active: String(selectedId) === String(mold.id) }"
|
||||
@click="selectedId = mold.id"
|
||||
>
|
||||
<text class="mold-name">{{ textValue(mold.name || mold.moldName || mold.brandName) }}</text>
|
||||
<view class="mold-meta">
|
||||
<text class="mold-meta-text">{{ textValue(mold.code || mold.moldCode || mold.brandCode) }}</text>
|
||||
<text v-if="mold.spec || mold.moldSpec || mold.machinerySpec" class="mold-meta-divider">|</text>
|
||||
<text v-if="mold.spec || mold.moldSpec || mold.machinerySpec" class="mold-meta-text">{{ textValue(mold.spec || mold.moldSpec || mold.machinerySpec) }}</text>
|
||||
</view>
|
||||
<view v-if="mold.brand || mold.moldBrand || mold.machineryBrand" class="mold-meta">
|
||||
<text class="mold-meta-text">{{ textValue(mold.brand || mold.moldBrand || mold.machineryBrand) }}</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.moldNotFound') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="bottom-actions">
|
||||
<view class="bottom-btn confirm-btn" @click="handleConfirm">
|
||||
{{ t('functionCommon.confirm') }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<sv-focus-no-keyboard ref="focusNoKeyboardRef"></sv-focus-no-keyboard>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { onLoad, onReady, onShow } from '@dcloudio/uni-app'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import NavBar from '@/components/common/NavBar.vue'
|
||||
import { getBrandList, getMoldBrandPage } from '@/api/mes/mold'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedId = ref('')
|
||||
const searchText = ref('')
|
||||
const moldList = ref([])
|
||||
const loading = ref(false)
|
||||
const focusNoKeyboardRef = ref(null)
|
||||
const searchInputSelector = '#mold-repair-mold-select-search-input input, input#mold-repair-mold-select-search-input'
|
||||
let searchTimer = null
|
||||
|
||||
onLoad(async (options) => {
|
||||
selectedId.value = String(options?.selectedId || '')
|
||||
focusSearchNoKeyboard()
|
||||
await loadMolds()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
focusSearchNoKeyboard()
|
||||
})
|
||||
|
||||
onReady(() => {
|
||||
focusSearchNoKeyboard()
|
||||
setTimeout(focusSearchNoKeyboard, 300)
|
||||
setTimeout(focusSearchNoKeyboard, 800)
|
||||
})
|
||||
|
||||
function focusSearchNoKeyboard() {
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
focusNoKeyboardRef.value?.focus(searchInputSelector)
|
||||
}, 80)
|
||||
})
|
||||
}
|
||||
function onSearchInput() {
|
||||
if (searchTimer) clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(() => {
|
||||
loadMolds()
|
||||
}, 300)
|
||||
}
|
||||
|
||||
function clearSearch() {
|
||||
searchText.value = ''
|
||||
loadMolds()
|
||||
}
|
||||
|
||||
async function loadMolds() {
|
||||
if (searchTimer) {
|
||||
clearTimeout(searchTimer)
|
||||
searchTimer = null
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const keyword = searchText.value.trim()
|
||||
const res = keyword
|
||||
? await getMoldBrandPage({ code: keyword, name: keyword, pageNo: 1, pageSize: 50 })
|
||||
: await getBrandList()
|
||||
moldList.value = normalizeMoldList(res)
|
||||
} catch (error) {
|
||||
moldList.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeMoldList(res) {
|
||||
const root = res && res.data !== undefined ? res.data : res
|
||||
const pageResult = root?.pageResult || root?.data?.pageResult || root?.data || root || {}
|
||||
const data = Array.isArray(root)
|
||||
? root
|
||||
: (Array.isArray(root?.data)
|
||||
? root.data
|
||||
: (pageResult?.list || pageResult?.rows || pageResult?.records || []))
|
||||
return (Array.isArray(data) ? data : []).filter((item) => item && item.id !== undefined && item.id !== null)
|
||||
}
|
||||
|
||||
function handleConfirm() {
|
||||
if (!selectedId.value) {
|
||||
uni.showToast({ title: t('moldRepair.validatorMoldRequired'), icon: 'none' })
|
||||
return
|
||||
}
|
||||
const mold = moldList.value.find((item) => String(item.id) === String(selectedId.value))
|
||||
if (!mold) {
|
||||
uni.showToast({ title: t('moldRepair.validatorMoldRequired'), icon: 'none' })
|
||||
return
|
||||
}
|
||||
getApp().globalData._moldRepairMoldSelectResult = { mold }
|
||||
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;
|
||||
}
|
||||
|
||||
.mold-list {
|
||||
padding: 16rpx 24rpx;
|
||||
}
|
||||
|
||||
.mold-card {
|
||||
background: #fff;
|
||||
border-radius: 14rpx;
|
||||
padding: 28rpx 24rpx;
|
||||
margin-bottom: 16rpx;
|
||||
border: 2rpx solid transparent;
|
||||
|
||||
&.active {
|
||||
border-color: #2563eb;
|
||||
background: #f0f5ff;
|
||||
}
|
||||
}
|
||||
|
||||
.mold-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.mold-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.mold-meta-text {
|
||||
font-size: 24rpx;
|
||||
color: #7a8494;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.mold-meta-divider {
|
||||
font-size: 22rpx;
|
||||
color: #c3cad5;
|
||||
}
|
||||
|
||||
.empty-wrap {
|
||||
padding: 120rpx 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.bottom-actions {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
padding: 20rpx 24rpx calc(20rpx + env(safe-area-inset-bottom));
|
||||
background: #fff;
|
||||
box-shadow: 0 -6rpx 18rpx rgba(15, 23, 42, 0.06);
|
||||
}
|
||||
|
||||
.bottom-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
border-radius: 18rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
background: #1f4b79;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue