|
|
|
|
@ -80,16 +80,6 @@
|
|
|
|
|
<text class="grid-label">{{ t('moldOperate.product') }}</text>
|
|
|
|
|
<text class="grid-value">{{ textValue(selectedMold.productName) }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="grid-cell">
|
|
|
|
|
<text class="grid-label">{{ t('moldOperate.mountTime') }}</text>
|
|
|
|
|
<text class="grid-value">{{ textValue(selectedMold.mountTime) }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="grid-row">
|
|
|
|
|
<view class="grid-cell full-width">
|
|
|
|
|
<text class="grid-label">{{ t('moldOperate.useCount') }}</text>
|
|
|
|
|
<text class="grid-value highlight">{{ formatUseCount(selectedMold.useCount) }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
@ -117,40 +107,15 @@
|
|
|
|
|
<view class="section-bar-line"></view>
|
|
|
|
|
<text class="section-title">{{ t('moldOperate.operator') + ' & ' + t('moldOperate.remark') }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="card-body-grid">
|
|
|
|
|
<view class="form-row">
|
|
|
|
|
<view class="form-cell">
|
|
|
|
|
<text class="form-label"><text class="required">*</text>{{ t('moldOperate.operator') }}</text>
|
|
|
|
|
<view class="select-dropdown" @click="toggleOperatorDropdown">
|
|
|
|
|
<view class="dropdown-input">
|
|
|
|
|
<text :class="['dropdown-value', { placeholder: !selectedOperator }]">
|
|
|
|
|
{{ selectedOperator ? selectedOperator.label : t('moldOperate.placeholderOperator') }}
|
|
|
|
|
</text>
|
|
|
|
|
<uni-icons type="bottom" size="14" color="#999" class="dropdown-arrow"></uni-icons>
|
|
|
|
|
</view>
|
|
|
|
|
<view v-if="showOperatorDropdown" class="dropdown-panel">
|
|
|
|
|
<scroll-view scroll-y class="dropdown-scroll">
|
|
|
|
|
<view
|
|
|
|
|
v-for="(item, idx) in operatorOptions"
|
|
|
|
|
:key="item.value"
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
:class="{ active: selectedOperator?.value === item.value }"
|
|
|
|
|
@click.stop="handleSelectOperator(item, idx)"
|
|
|
|
|
>
|
|
|
|
|
<text class="dropdown-item-text">{{ item.label }}</text>
|
|
|
|
|
<uni-icons
|
|
|
|
|
v-if="selectedOperator?.value === item.value"
|
|
|
|
|
type="checkmarkempty"
|
|
|
|
|
size="16"
|
|
|
|
|
color="#1f7cff"
|
|
|
|
|
></uni-icons>
|
|
|
|
|
</view>
|
|
|
|
|
<view v-if="!operatorOptions.length" class="dropdown-empty">暂无数据</view>
|
|
|
|
|
</scroll-view>
|
|
|
|
|
<view class="card-body-grid">
|
|
|
|
|
<view class="form-row">
|
|
|
|
|
<view class="form-cell">
|
|
|
|
|
<text class="form-label"><text class="required">*</text>{{ t('moldOperate.operator') }}</text>
|
|
|
|
|
<view class="dropdown-input readonly-input">
|
|
|
|
|
<text class="dropdown-value">{{ currentUserName }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="form-row">
|
|
|
|
|
<view class="form-cell">
|
|
|
|
|
<text class="form-label">{{ t('moldOperate.remark') }}</text>
|
|
|
|
|
@ -202,11 +167,17 @@ import { computed, reactive, ref } from 'vue'
|
|
|
|
|
import { onShow } from '@dcloudio/uni-app'
|
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
import NavBar from '@/components/common/NavBar.vue'
|
|
|
|
|
import { getLowerMoldList, getDeviceLedgerList, createMoldOperate } from '@/api/mes/moldoperate'
|
|
|
|
|
import { getDeviceLedgerList, createMoldOperate } from '@/api/mes/moldoperate'
|
|
|
|
|
import { getMoldBrandPage } from '@/api/mes/mold'
|
|
|
|
|
import useUserStore from '@/store/modules/user'
|
|
|
|
|
import { getDeviceLineTree } from '@/api/mes/deviceLine'
|
|
|
|
|
import { getSimpleUserList } from '@/api/system/user'
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
|
|
|
|
|
// 当前登录用户
|
|
|
|
|
const currentUserName = computed(() => userStore.name || '未知用户')
|
|
|
|
|
const currentUserId = computed(() => userStore.userId)
|
|
|
|
|
|
|
|
|
|
const lineInfoMap = ref(new Map()) // deviceLine id → { name, parentId, parentChain }
|
|
|
|
|
|
|
|
|
|
@ -282,10 +253,7 @@ const tempSelectedMoldId = ref(null)
|
|
|
|
|
|
|
|
|
|
// ---- 操作人与备注 ----
|
|
|
|
|
const remarkText = ref('')
|
|
|
|
|
const operatorOptions = ref([])
|
|
|
|
|
const selectedOperator = ref(null)
|
|
|
|
|
const operatorIndex = ref(-1)
|
|
|
|
|
const showOperatorDropdown = ref(false)
|
|
|
|
|
|
|
|
|
|
// ---- 工具函数 ----
|
|
|
|
|
function textValue(v) {
|
|
|
|
|
@ -295,12 +263,7 @@ function textValue(v) {
|
|
|
|
|
return s || '-'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatUseCount(count) {
|
|
|
|
|
if (count == null) return '-'
|
|
|
|
|
const num = Number(count)
|
|
|
|
|
if (isNaN(num)) return String(count)
|
|
|
|
|
return num.toLocaleString() + ' ' + t('moldOperate.countUnit')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatTime(time) {
|
|
|
|
|
if (!time) return '-'
|
|
|
|
|
@ -374,45 +337,20 @@ function findArr(obj, d = 0) {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadLowerMolds(deviceId) {
|
|
|
|
|
async function loadLowerMolds(deviceName) {
|
|
|
|
|
lowerMoldLoading.value = true
|
|
|
|
|
try {
|
|
|
|
|
// ====== 策略1:优先从持久化存储读取(按设备ID索引,不会互覆盖)======
|
|
|
|
|
let map = {}
|
|
|
|
|
try { map = uni.getStorageSync('_mountedMoldInfoMap') || {} } catch {}
|
|
|
|
|
const savedInfo = map[String(deviceId)] || null
|
|
|
|
|
|
|
|
|
|
console.log('[下模] 持久化在机模具信息 =', savedInfo ? JSON.stringify(savedInfo) : 'null', 'deviceId=', deviceId)
|
|
|
|
|
|
|
|
|
|
if (savedInfo && savedInfo.mold) {
|
|
|
|
|
console.log('[下模] 命中持久化数据, deviceId=', deviceId)
|
|
|
|
|
const m = savedInfo.mold
|
|
|
|
|
lowerMoldOptions.value = [{
|
|
|
|
|
id: m.id,
|
|
|
|
|
moldId: m.id,
|
|
|
|
|
moldName: m.name || m.moldName || '-',
|
|
|
|
|
moldCode: m.code || m.moldCode || '-',
|
|
|
|
|
productName: m.productName || '-',
|
|
|
|
|
mountTime: formatTime(savedInfo.mountTime),
|
|
|
|
|
useCount: '-'
|
|
|
|
|
}]
|
|
|
|
|
console.log('[下模] 使用持久化数据 =', JSON.stringify(lowerMoldOptions.value[0]))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
console.log('[下模] 未命中持久化数据,进入接口查询')
|
|
|
|
|
|
|
|
|
|
// ====== 策略2:fallback - 调用在机模具接口 ======
|
|
|
|
|
let list = []
|
|
|
|
|
try {
|
|
|
|
|
const res = await getLowerMoldList(deviceId)
|
|
|
|
|
const root = (res && res.data !== undefined) ? res.data : res
|
|
|
|
|
list = findArr(root)
|
|
|
|
|
} catch (apiErr) {
|
|
|
|
|
console.warn('[下模] getLowerMoldList 接口异常', apiErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lowerMoldOptions.value = list
|
|
|
|
|
console.log('[下模] loadLowerMolds 返回 list.length =', list.length)
|
|
|
|
|
const res = await getMoldBrandPage({ deviceName, pageSize: 100 })
|
|
|
|
|
const root = (res && res.data !== undefined) ? res.data : res
|
|
|
|
|
const pageData = root?.pageResult || root
|
|
|
|
|
const list = Array.isArray(pageData) ? pageData : (Array.isArray(pageData?.list) ? pageData.list : [])
|
|
|
|
|
lowerMoldOptions.value = list.map(m => ({
|
|
|
|
|
id: m.id,
|
|
|
|
|
moldId: m.id,
|
|
|
|
|
moldName: m.name || '-',
|
|
|
|
|
moldCode: m.code || '-',
|
|
|
|
|
productName: m.productName || '-'
|
|
|
|
|
}))
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('loadLowerMolds error', e)
|
|
|
|
|
} finally {
|
|
|
|
|
@ -450,8 +388,8 @@ function selectDevice(device) {
|
|
|
|
|
selectedDevice.value = device || {}
|
|
|
|
|
moldsLoaded.value = false
|
|
|
|
|
selectedMold.value = {}
|
|
|
|
|
if (device?.id) {
|
|
|
|
|
loadLowerMolds(device.id).then(() => {
|
|
|
|
|
if (device?.deviceName) {
|
|
|
|
|
loadLowerMolds(device.deviceName).then(() => {
|
|
|
|
|
moldsLoaded.value = true
|
|
|
|
|
if (lowerMoldOptions.value.length > 0) {
|
|
|
|
|
const first = lowerMoldOptions.value[0]
|
|
|
|
|
@ -459,9 +397,7 @@ function selectDevice(device) {
|
|
|
|
|
id: first.id || first.moldId,
|
|
|
|
|
moldName: first.moldName || first.name,
|
|
|
|
|
moldCode: first.moldCode || first.code,
|
|
|
|
|
productName: first.productName || '-',
|
|
|
|
|
mountTime: first.mountTime || '-',
|
|
|
|
|
useCount: first.useCount ?? '-'
|
|
|
|
|
productName: first.productName || '-'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -475,12 +411,12 @@ function openDevicePicker() {
|
|
|
|
|
|
|
|
|
|
// ---- 在机模具选择(更换下模对象)----
|
|
|
|
|
function openLowerMoldPicker() {
|
|
|
|
|
if (!selectedDevice.value?.id) {
|
|
|
|
|
if (!selectedDevice.value?.deviceName) {
|
|
|
|
|
uni.showToast({ title: t('moldOperate.validatorDeviceRequired'), icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
tempSelectedMoldId.value = selectedMold.value ? String(selectedMold.value.id || selectedMold.value.moldId) : null
|
|
|
|
|
loadLowerMolds(selectedDevice.value.id).then(() => {
|
|
|
|
|
loadLowerMolds(selectedDevice.value.deviceName).then(() => {
|
|
|
|
|
lowerMoldPickerRef.value?.open()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@ -494,9 +430,7 @@ function confirmLowerMoldSelection() {
|
|
|
|
|
id: mold.id || mold.moldId,
|
|
|
|
|
moldName: mold.moldName || mold.name,
|
|
|
|
|
moldCode: mold.moldCode || mold.code,
|
|
|
|
|
productName: mold.productName || '-',
|
|
|
|
|
mountTime: mold.mountTime || '-',
|
|
|
|
|
useCount: mold.useCount ?? '-'
|
|
|
|
|
productName: mold.productName || '-'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lowerMoldPickerRef.value?.close()
|
|
|
|
|
@ -504,34 +438,16 @@ function confirmLowerMoldSelection() {
|
|
|
|
|
|
|
|
|
|
function closeLowerMoldPicker() { lowerMoldPickerRef.value?.close() }
|
|
|
|
|
|
|
|
|
|
// ---- 操作人列表加载 ----
|
|
|
|
|
async function loadOperators() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await getSimpleUserList()
|
|
|
|
|
const data = Array.isArray(res) ? res : (Array.isArray(res?.data) ? res.data : [])
|
|
|
|
|
operatorOptions.value = data.map((u) => ({
|
|
|
|
|
value: u.id || u.userId,
|
|
|
|
|
label: u.nickname || u.userName || u.name || String(u.id || '')
|
|
|
|
|
}))
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('loadOperators error', e)
|
|
|
|
|
// ---- 操作人自动设置为当前登录用户 ----
|
|
|
|
|
function autoSetOperator() {
|
|
|
|
|
if (currentUserId.value && currentUserName.value) {
|
|
|
|
|
selectedOperator.value = {
|
|
|
|
|
value: currentUserId.value,
|
|
|
|
|
label: currentUserName.value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toggleOperatorDropdown() {
|
|
|
|
|
showOperatorDropdown.value = !showOperatorDropdown.value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeOperatorDropdown() {
|
|
|
|
|
showOperatorDropdown.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleSelectOperator(item, idx) {
|
|
|
|
|
selectedOperator.value = item
|
|
|
|
|
operatorIndex.value = idx
|
|
|
|
|
closeOperatorDropdown()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function goToHistory() {
|
|
|
|
|
uni.navigateTo({ url: '/pages_function/pages/moldoperate/history?type=down' })
|
|
|
|
|
}
|
|
|
|
|
@ -578,21 +494,11 @@ async function handleConfirm() {
|
|
|
|
|
console.log('[下模] 提交参数 =', JSON.stringify(payload))
|
|
|
|
|
await createMoldOperate(payload)
|
|
|
|
|
uni.showToast({ title: t('functionCommon.createSuccess'), icon: 'success' })
|
|
|
|
|
// 下模成功后清除该设备的持久化数据
|
|
|
|
|
if (selectedDevice.value?.id) {
|
|
|
|
|
try {
|
|
|
|
|
const map = uni.getStorageSync('_mountedMoldInfoMap') || {}
|
|
|
|
|
delete map[String(selectedDevice.value.id)]
|
|
|
|
|
uni.setStorageSync('_mountedMoldInfoMap', map)
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
|
|
|
|
// 重置表单
|
|
|
|
|
selectedDevice.value = {}
|
|
|
|
|
selectedMold.value = {}
|
|
|
|
|
lowerMoldOptions.value = []
|
|
|
|
|
remarkText.value = ''
|
|
|
|
|
selectedOperator.value = null
|
|
|
|
|
operatorIndex.value = -1
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('[下模] 保存失败 =', e)
|
|
|
|
|
const errMsg = e?.msg || (typeof e === 'string' ? e : e?.message) || '系统异常'
|
|
|
|
|
@ -608,7 +514,8 @@ function handleCancel() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onShow(async () => {
|
|
|
|
|
await Promise.allSettled([loadDevices(), loadLineTree(), loadOperators()])
|
|
|
|
|
autoSetOperator()
|
|
|
|
|
await Promise.allSettled([loadDevices(), loadLineTree()])
|
|
|
|
|
// 从 globalData 读取设备选择页回传的设备
|
|
|
|
|
const device = getApp().globalData._deviceSelectResult
|
|
|
|
|
if (device) {
|
|
|
|
|
@ -854,6 +761,11 @@ onShow(async () => {
|
|
|
|
|
font-size: 27rpx;
|
|
|
|
|
color: #333;
|
|
|
|
|
background: #f9fafb;
|
|
|
|
|
|
|
|
|
|
&.readonly-input {
|
|
|
|
|
background: #f8fafc;
|
|
|
|
|
border-color: #f0f0f0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dropdown-value {
|
|
|
|
|
|