up
This commit is contained in:
@@ -345,7 +345,8 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
if from.ParentID != nil {
|
if from.ParentID != nil {
|
||||||
query = query.Where("parent_id = ?", *from.ParentID)
|
query = query.Where("parent_id = ?", *from.ParentID)
|
||||||
} else {
|
} else if from.Search == "" {
|
||||||
|
// 无搜索时默认只显示顶级容器
|
||||||
query = query.Where("parent_id IS NULL")
|
query = query.Where("parent_id IS NULL")
|
||||||
}
|
}
|
||||||
query.Count(&count)
|
query.Count(&count)
|
||||||
@@ -385,6 +386,35 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建父容器链(从根到当前)
|
||||||
|
type ParentItem struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
parentChain := []ParentItem{}
|
||||||
|
if c.ParentID != nil {
|
||||||
|
curID := *c.ParentID
|
||||||
|
visited := map[uint]bool{}
|
||||||
|
for curID != 0 {
|
||||||
|
if visited[curID] {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
visited[curID] = true
|
||||||
|
var parent TabWarehouseContainer
|
||||||
|
if err := models.DB.Select("id, title, parent_id").Where("id = ?", curID).First(&parent).Error; err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
parentChain = append([]ParentItem{{ID: parent.ID, Title: parent.Title}}, parentChain...)
|
||||||
|
if parent.ParentID == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
curID = *parent.ParentID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算当前容器深度(0=顶级,4=已达最大层级)
|
||||||
|
depth := len(parentChain)
|
||||||
|
|
||||||
// 关联图片
|
// 关联图片
|
||||||
var binds []TabWarehouseContainerFileBind
|
var binds []TabWarehouseContainerFileBind
|
||||||
models.DB.Where("container_id = ?", from.ID).Find(&binds)
|
models.DB.Where("container_id = ?", from.ID).Find(&binds)
|
||||||
@@ -400,10 +430,12 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
ReturnJson(ctx, "apiOK", gin.H{
|
ReturnJson(ctx, "apiOK", gin.H{
|
||||||
"container": c,
|
"container": c,
|
||||||
"photos": files,
|
"photos": files,
|
||||||
|
"parent_chain": parentChain,
|
||||||
|
"depth": depth,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 新增物品
|
// 新增物品(查重逻辑:Name+SerialNumber相同则更新容器)
|
||||||
r.POST("/add_item", func(ctx *gin.Context) {
|
r.POST("/add_item", func(ctx *gin.Context) {
|
||||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||||
if !isAuth {
|
if !isAuth {
|
||||||
@@ -438,6 +470,47 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
quantity = 1
|
quantity = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查重:Name + SerialNumber 相同则更新容器
|
||||||
|
var existingItem TabWarehouseItem
|
||||||
|
exists := models.DB.Where("name = ? AND serial_number = ?", from.Name, from.SerialNumber).First(&existingItem).Error == nil
|
||||||
|
|
||||||
|
var itemID uint
|
||||||
|
var oldContainer *uint
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
// 已有记录:更新容器
|
||||||
|
oldContainer = existingItem.ContainerID
|
||||||
|
|
||||||
|
// 同一容器无需操作,但仍然记录 commit
|
||||||
|
if !ptrEqUint(oldContainer, from.ContainerID) {
|
||||||
|
// 旧容器 ItemCount -1
|
||||||
|
if oldContainer != nil {
|
||||||
|
models.DB.Model(&TabWarehouseContainer{}).Where("id = ?", *oldContainer).Update("item_count", models.DB.Raw("item_count - 1"))
|
||||||
|
}
|
||||||
|
// 新容器 ItemCount +1
|
||||||
|
if from.ContainerID != nil {
|
||||||
|
models.DB.Model(&TabWarehouseContainer{}).Where("id = ?", *from.ContainerID).Update("item_count", models.DB.Raw("item_count + 1"))
|
||||||
|
}
|
||||||
|
// 更新物品容器
|
||||||
|
existingItem.ContainerID = from.ContainerID
|
||||||
|
models.DB.Save(&existingItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
itemID = existingItem.ID
|
||||||
|
|
||||||
|
// 写操作日志
|
||||||
|
newContent, _ := json.Marshal(from)
|
||||||
|
models.DB.Create(&TabWarehouseLog{
|
||||||
|
EntityType: "item",
|
||||||
|
EntityID: itemID,
|
||||||
|
UserID: user.ID,
|
||||||
|
ActionType: "update",
|
||||||
|
OldContent: ptrStrUint(oldContainer),
|
||||||
|
NewContent: string(newContent),
|
||||||
|
IP: ctx.ClientIP(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 无记录:新建物品
|
||||||
item := TabWarehouseItem{
|
item := TabWarehouseItem{
|
||||||
Name: from.Name,
|
Name: from.Name,
|
||||||
SerialNumber: from.SerialNumber,
|
SerialNumber: from.SerialNumber,
|
||||||
@@ -448,6 +521,7 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
ContainerID: from.ContainerID,
|
ContainerID: from.ContainerID,
|
||||||
}
|
}
|
||||||
models.DB.Create(&item)
|
models.DB.Create(&item)
|
||||||
|
itemID = item.ID
|
||||||
|
|
||||||
// 绑定图片
|
// 绑定图片
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
@@ -470,14 +544,42 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
newContent, _ := json.Marshal(from)
|
newContent, _ := json.Marshal(from)
|
||||||
models.DB.Create(&TabWarehouseLog{
|
models.DB.Create(&TabWarehouseLog{
|
||||||
EntityType: "item",
|
EntityType: "item",
|
||||||
EntityID: item.ID,
|
EntityID: itemID,
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
ActionType: "create",
|
ActionType: "create",
|
||||||
NewContent: string(newContent),
|
NewContent: string(newContent),
|
||||||
IP: ctx.ClientIP(),
|
IP: ctx.ClientIP(),
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ReturnJson(ctx, "apiOK", gin.H{"id": item.ID})
|
// 新增/更新时绑定图片
|
||||||
|
for _, hash := range from.Photos {
|
||||||
|
var findFile TabFileInfo_
|
||||||
|
if models.DB.Where(&TabFileInfo_{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
||||||
|
// 检查是否已绑定,避免重复
|
||||||
|
var count int64
|
||||||
|
models.DB.Model(&TabWarehouseItemFileBind{}).Where("item_id = ? AND file_id = ?", itemID, findFile.ID).Count(&count)
|
||||||
|
if count == 0 {
|
||||||
|
models.DB.Create(&TabWarehouseItemFileBind{
|
||||||
|
ItemID: itemID,
|
||||||
|
FileID: findFile.ID,
|
||||||
|
CreatorID: user.ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录 commit(无论新建还是更新容器都记录)
|
||||||
|
models.DB.Create(&TabWarehouseItemCommit{
|
||||||
|
ItemID: itemID,
|
||||||
|
UserID: user.ID,
|
||||||
|
OldContainer: oldContainer,
|
||||||
|
NewContainer: from.ContainerID,
|
||||||
|
Remark: from.Remark,
|
||||||
|
IP: ctx.ClientIP(),
|
||||||
|
})
|
||||||
|
|
||||||
|
ReturnJson(ctx, "apiOK", gin.H{"id": itemID, "updated": exists})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 编辑物品
|
// 编辑物品
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Photos []string `json:"photos"`
|
Photos []string `json:"photos"`
|
||||||
|
ItemID *uint `json:"item_id"`
|
||||||
}
|
}
|
||||||
var from FromAdd
|
var from FromAdd
|
||||||
if err := decodeJSON(data, &from); err != nil || from.Title == "" {
|
if err := decodeJSON(data, &from); err != nil || from.Title == "" {
|
||||||
@@ -174,6 +175,15 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 绑定物品
|
||||||
|
if from.ItemID != nil && *from.ItemID > 0 {
|
||||||
|
models.DB.Create(&TabWarehouseItemWorkOrderBind{
|
||||||
|
ItemID: *from.ItemID,
|
||||||
|
WorkOrderID: order.ID,
|
||||||
|
CreatorID: user.ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 写创建 commit
|
// 写创建 commit
|
||||||
models.DB.Create(&TabWorkOrderCommit{
|
models.DB.Create(&TabWorkOrderCommit{
|
||||||
WorkOrderID: order.ID,
|
WorkOrderID: order.ID,
|
||||||
@@ -403,12 +413,38 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
// 所有登录用户都可以提交进度
|
// 所有登录用户都可以提交进度
|
||||||
canCommit := true
|
canCommit := true
|
||||||
|
|
||||||
|
// 关联物品
|
||||||
|
type LinkedItem struct {
|
||||||
|
ID uint `json:"ID"`
|
||||||
|
Name string `json:"Name"`
|
||||||
|
SerialNumber string `json:"SerialNumber"`
|
||||||
|
}
|
||||||
|
var linkedItems []LinkedItem
|
||||||
|
var itemBinds []TabWarehouseItemWorkOrderBind
|
||||||
|
models.DB.Where("work_order_id = ?", from.ID).Find(&itemBinds)
|
||||||
|
if len(itemBinds) > 0 {
|
||||||
|
var itemIDs []uint
|
||||||
|
for _, b := range itemBinds {
|
||||||
|
itemIDs = append(itemIDs, b.ItemID)
|
||||||
|
}
|
||||||
|
var items []TabWarehouseItem
|
||||||
|
models.DB.Where("id IN ?", itemIDs).Find(&items)
|
||||||
|
for _, it := range items {
|
||||||
|
linkedItems = append(linkedItems, LinkedItem{
|
||||||
|
ID: it.ID,
|
||||||
|
Name: it.Name,
|
||||||
|
SerialNumber: it.SerialNumber,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ReturnJson(ctx, "apiOK", gin.H{
|
ReturnJson(ctx, "apiOK", gin.H{
|
||||||
"order": order,
|
"order": order,
|
||||||
"canModify": canModify,
|
"canModify": canModify,
|
||||||
"canCommit": canCommit,
|
"canCommit": canCommit,
|
||||||
"photos": files,
|
"photos": files,
|
||||||
"commits": commitsWithPhotos,
|
"commits": commitsWithPhotos,
|
||||||
|
"linkedItems": linkedItems,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@
|
|||||||
"not_found": "Work order not found",
|
"not_found": "Work order not found",
|
||||||
"confirm_delete": "Are you sure you want to delete this work order? This action cannot be undone.",
|
"confirm_delete": "Are you sure you want to delete this work order? This action cannot be undone.",
|
||||||
"confirm_delete_commit": "Are you sure you want to delete this progress?",
|
"confirm_delete_commit": "Are you sure you want to delete this progress?",
|
||||||
|
"linked_items": "Linked Items",
|
||||||
"submit": "Submit",
|
"submit": "Submit",
|
||||||
"save_changes": "Save Changes"
|
"save_changes": "Save Changes"
|
||||||
},
|
},
|
||||||
@@ -178,6 +179,7 @@
|
|||||||
"container_count": "Containers",
|
"container_count": "Containers",
|
||||||
"item_count": "Items",
|
"item_count": "Items",
|
||||||
"unstored_items": "Unstored",
|
"unstored_items": "Unstored",
|
||||||
|
"unstored": "Unstored",
|
||||||
"title_required": "Container name is required",
|
"title_required": "Container name is required",
|
||||||
"delete_confirm_title": "Delete Container",
|
"delete_confirm_title": "Delete Container",
|
||||||
"delete_confirm_msg": "Are you sure you want to delete \"{name}\"? This cannot be undone.",
|
"delete_confirm_msg": "Are you sure you want to delete \"{name}\"? This cannot be undone.",
|
||||||
@@ -301,6 +303,9 @@
|
|||||||
"pending_orders": "Pending orders"
|
"pending_orders": "Pending orders"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
|
"save": "Save",
|
||||||
|
"cancel": "Cancel",
|
||||||
|
"delete_success": "Deleted successfully",
|
||||||
"functionality_not_yet_developed": "Functionality not yet developed",
|
"functionality_not_yet_developed": "Functionality not yet developed",
|
||||||
"hello": "Hello",
|
"hello": "Hello",
|
||||||
"welcome": "Welcome",
|
"welcome": "Welcome",
|
||||||
|
|||||||
@@ -149,6 +149,7 @@
|
|||||||
"not_found": "工单不存在",
|
"not_found": "工单不存在",
|
||||||
"confirm_delete": "确定要删除此工单吗?此操作不可撤销。",
|
"confirm_delete": "确定要删除此工单吗?此操作不可撤销。",
|
||||||
"confirm_delete_commit": "确定要删除此进度吗?",
|
"confirm_delete_commit": "确定要删除此进度吗?",
|
||||||
|
"linked_items": "关联物品",
|
||||||
"submit": "提交",
|
"submit": "提交",
|
||||||
"save_changes": "保存修改"
|
"save_changes": "保存修改"
|
||||||
},
|
},
|
||||||
@@ -178,6 +179,7 @@
|
|||||||
"container_count": "容器数",
|
"container_count": "容器数",
|
||||||
"item_count": "物品数",
|
"item_count": "物品数",
|
||||||
"unstored_items": "未入库",
|
"unstored_items": "未入库",
|
||||||
|
"unstored": "未入库",
|
||||||
"title_required": "容器名称不能为空",
|
"title_required": "容器名称不能为空",
|
||||||
"delete_confirm_title": "删除容器",
|
"delete_confirm_title": "删除容器",
|
||||||
"delete_confirm_msg": "确定要删除容器「{name}」吗?此操作不可撤销。",
|
"delete_confirm_msg": "确定要删除容器「{name}」吗?此操作不可撤销。",
|
||||||
@@ -301,6 +303,9 @@
|
|||||||
"pending_orders": "待处理订单"
|
"pending_orders": "待处理订单"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
|
"save": "保存",
|
||||||
|
"cancel": "取消",
|
||||||
|
"delete_success": "删除成功",
|
||||||
"functionality_not_yet_developed": "功能未开发",
|
"functionality_not_yet_developed": "功能未开发",
|
||||||
"hello": "你好",
|
"hello": "你好",
|
||||||
"welcome": "欢迎",
|
"welcome": "欢迎",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, computed, onMounted } from 'vue'
|
import { ref, reactive, computed, onMounted, watch } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useToastStore } from '@/stores/toast'
|
import { useToastStore } from '@/stores/toast'
|
||||||
@@ -27,9 +27,20 @@ const usersStore = useUsersStore()
|
|||||||
|
|
||||||
const containerId = computed(() => parseInt(route.params.id))
|
const containerId = computed(() => parseInt(route.params.id))
|
||||||
|
|
||||||
|
// ── 路由参数变化时重新加载 ──
|
||||||
|
watch(containerId, async () => {
|
||||||
|
subPage.value = 1
|
||||||
|
itemPage.value = 1
|
||||||
|
await fetchContainer()
|
||||||
|
fetchSubContainers()
|
||||||
|
fetchItems()
|
||||||
|
})
|
||||||
|
|
||||||
// ── 容器详情 ──
|
// ── 容器详情 ──
|
||||||
const container = ref(null)
|
const container = ref(null)
|
||||||
const photos = ref([])
|
const photos = ref([])
|
||||||
|
const parentChain = ref([])
|
||||||
|
const containerDepth = ref(0)
|
||||||
const loadingDetail = ref(true)
|
const loadingDetail = ref(true)
|
||||||
const notFound = ref(false)
|
const notFound = ref(false)
|
||||||
|
|
||||||
@@ -89,12 +100,31 @@ const deleting = ref(false)
|
|||||||
// ── 时间格式化 ──
|
// ── 时间格式化 ──
|
||||||
function fmtTs(ts) {
|
function fmtTs(ts) {
|
||||||
if (!ts) return '—'
|
if (!ts) return '—'
|
||||||
const d = new Date(parseInt(ts) * 1000)
|
let d
|
||||||
|
if (typeof ts === 'number') {
|
||||||
|
// Unix timestamp in seconds (number)
|
||||||
|
d = new Date(ts * 1000)
|
||||||
|
} else if (typeof ts === 'string') {
|
||||||
|
// Check if it's a Unix timestamp string like "1712345678"
|
||||||
|
if (/^\d+$/.test(ts)) {
|
||||||
|
d = new Date(parseInt(ts, 10) * 1000)
|
||||||
|
} else {
|
||||||
|
// ISO 8601 or other string format
|
||||||
|
d = new Date(ts)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
d = new Date(ts)
|
||||||
|
}
|
||||||
|
if (isNaN(d.getTime())) return '—'
|
||||||
return d.toLocaleString()
|
return d.toLocaleString()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 拉取容器详情 ──
|
// ── 拉取容器详情 ──
|
||||||
async function fetchContainer() {
|
async function fetchContainer() {
|
||||||
|
container.value = null
|
||||||
|
photos.value = []
|
||||||
|
parentChain.value = []
|
||||||
|
containerDepth.value = 0
|
||||||
loadingDetail.value = true
|
loadingDetail.value = true
|
||||||
notFound.value = false
|
notFound.value = false
|
||||||
try {
|
try {
|
||||||
@@ -102,6 +132,8 @@ async function fetchContainer() {
|
|||||||
if (errCode === 0 && data) {
|
if (errCode === 0 && data) {
|
||||||
container.value = data.container
|
container.value = data.container
|
||||||
photos.value = data.photos ?? []
|
photos.value = data.photos ?? []
|
||||||
|
parentChain.value = data.parent_chain ?? []
|
||||||
|
containerDepth.value = data.depth ?? 0
|
||||||
} else {
|
} else {
|
||||||
notFound.value = true
|
notFound.value = true
|
||||||
}
|
}
|
||||||
@@ -114,6 +146,7 @@ async function fetchContainer() {
|
|||||||
|
|
||||||
// ── 拉取子容器 ──
|
// ── 拉取子容器 ──
|
||||||
async function fetchSubContainers() {
|
async function fetchSubContainers() {
|
||||||
|
subContainers.value = []
|
||||||
loadingSub.value = true
|
loadingSub.value = true
|
||||||
try {
|
try {
|
||||||
const { errCode, data } = await warehouseApi.getContainers({
|
const { errCode, data } = await warehouseApi.getContainers({
|
||||||
@@ -135,6 +168,7 @@ async function fetchSubContainers() {
|
|||||||
|
|
||||||
// ── 拉取物品 ──
|
// ── 拉取物品 ──
|
||||||
async function fetchItems() {
|
async function fetchItems() {
|
||||||
|
items.value = []
|
||||||
loadingItems.value = true
|
loadingItems.value = true
|
||||||
try {
|
try {
|
||||||
const { errCode, data } = await warehouseApi.getItems({
|
const { errCode, data } = await warehouseApi.getItems({
|
||||||
@@ -278,10 +312,17 @@ onMounted(async () => {
|
|||||||
|
|
||||||
<!-- 面包屑 + 操作栏 -->
|
<!-- 面包屑 + 操作栏 -->
|
||||||
<div class="flex items-center justify-between gap-3">
|
<div class="flex items-center justify-between gap-3">
|
||||||
<div class="flex items-center gap-2 text-sm">
|
<div class="flex items-center gap-1 text-sm flex-wrap">
|
||||||
<RouterLink to="/warehouse/container" class="text-blue-500 hover:underline">
|
<RouterLink to="/warehouse/container" class="text-blue-500 hover:underline">
|
||||||
{{ t('warehouse.container_list') }}
|
{{ t('warehouse.container_list') }}
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
|
<template v-for="p in parentChain" :key="p.id">
|
||||||
|
<span class="text-gray-400">/</span>
|
||||||
|
<RouterLink
|
||||||
|
:to="`/warehouse/container/${p.id}`"
|
||||||
|
class="text-blue-500 hover:underline"
|
||||||
|
>{{ p.title }}</RouterLink>
|
||||||
|
</template>
|
||||||
<span class="text-gray-400">/</span>
|
<span class="text-gray-400">/</span>
|
||||||
<span class="font-medium text-gray-900 dark:text-white">{{ container.Title }}</span>
|
<span class="font-medium text-gray-900 dark:text-white">{{ container.Title }}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -359,6 +400,7 @@ onMounted(async () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
v-if="containerDepth < 4"
|
||||||
class="inline-flex items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-blue-700"
|
class="inline-flex items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-blue-700"
|
||||||
@click="showAddSub = true"
|
@click="showAddSub = true"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import {
|
|||||||
IconEdit,
|
IconEdit,
|
||||||
IconTrash,
|
IconTrash,
|
||||||
IconArrowRight,
|
IconArrowRight,
|
||||||
|
IconArrowLeft,
|
||||||
IconSearch,
|
IconSearch,
|
||||||
|
IconPlus,
|
||||||
} from '@tabler/icons-vue'
|
} from '@tabler/icons-vue'
|
||||||
|
|
||||||
usePageTitle('warehouse.item_detail')
|
usePageTitle('warehouse.item_detail')
|
||||||
@@ -84,7 +86,22 @@ function getStatusLabel(status) {
|
|||||||
// ── 时间格式化 ──
|
// ── 时间格式化 ──
|
||||||
function fmtTs(ts) {
|
function fmtTs(ts) {
|
||||||
if (!ts) return '—'
|
if (!ts) return '—'
|
||||||
const d = new Date(parseInt(ts) * 1000)
|
let d
|
||||||
|
if (typeof ts === 'number') {
|
||||||
|
// Unix timestamp in seconds (number)
|
||||||
|
d = new Date(ts * 1000)
|
||||||
|
} else if (typeof ts === 'string') {
|
||||||
|
// Check if it's a Unix timestamp string like "1712345678"
|
||||||
|
if (/^\d+$/.test(ts)) {
|
||||||
|
d = new Date(parseInt(ts, 10) * 1000)
|
||||||
|
} else {
|
||||||
|
// ISO 8601 or other string format
|
||||||
|
d = new Date(ts)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
d = new Date(ts)
|
||||||
|
}
|
||||||
|
if (isNaN(d.getTime())) return '—'
|
||||||
return d.toLocaleString()
|
return d.toLocaleString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +167,21 @@ function getContainerName(id) {
|
|||||||
return containerNames[id] || `#${id}`
|
return containerNames[id] || `#${id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 关联工单 ──
|
||||||
|
function openLinkWorkOrder() {
|
||||||
|
if (!item.value) return
|
||||||
|
// 存储预填数据到 localStorage
|
||||||
|
const prefillData = {
|
||||||
|
itemId: item.value.ID,
|
||||||
|
title: item.value.SerialNumber
|
||||||
|
? `${item.value.Name}-${item.value.SerialNumber}`
|
||||||
|
: item.value.Name,
|
||||||
|
description: item.value.Remark || '',
|
||||||
|
}
|
||||||
|
localStorage.setItem('prefill_work_order', JSON.stringify(prefillData))
|
||||||
|
router.push('/work_order/add')
|
||||||
|
}
|
||||||
|
|
||||||
// ── 编辑 ──
|
// ── 编辑 ──
|
||||||
function openEdit() {
|
function openEdit() {
|
||||||
editForm.name = item.value?.Name ?? ''
|
editForm.name = item.value?.Name ?? ''
|
||||||
@@ -297,16 +329,23 @@ onMounted(() => {
|
|||||||
|
|
||||||
<template v-else-if="item">
|
<template v-else-if="item">
|
||||||
|
|
||||||
<!-- 面包屑 + 操作栏 -->
|
<!-- 操作栏 -->
|
||||||
<div class="flex items-center justify-between gap-3">
|
<div class="flex items-center justify-between gap-2">
|
||||||
<div class="flex items-center gap-2 text-sm">
|
<button
|
||||||
<RouterLink to="/warehouse/item" class="text-blue-500 hover:underline">
|
class="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:bg-dk-base dark:text-white dark:hover:bg-dk-muted"
|
||||||
{{ t('warehouse.item_list') }}
|
@click="router.back()"
|
||||||
</RouterLink>
|
>
|
||||||
<span class="text-gray-400">/</span>
|
<IconArrowLeft :size="14" />
|
||||||
<span class="font-medium text-gray-900 dark:text-white">{{ item.Name }}</span>
|
返回
|
||||||
</div>
|
</button>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
|
<button
|
||||||
|
class="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:bg-dk-base dark:text-white dark:hover:bg-dk-muted"
|
||||||
|
@click="openLinkWorkOrder"
|
||||||
|
>
|
||||||
|
<IconPlus :size="14" />
|
||||||
|
关联工单
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
class="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:bg-dk-base dark:text-white dark:hover:bg-dk-muted"
|
class="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:bg-dk-base dark:text-white dark:hover:bg-dk-muted"
|
||||||
@click="openMove"
|
@click="openMove"
|
||||||
|
|||||||
@@ -222,8 +222,8 @@ async function fetchItems() {
|
|||||||
items.value = data.items || []
|
items.value = data.items || []
|
||||||
itemTotal.value = data.all_count || 0
|
itemTotal.value = data.all_count || 0
|
||||||
itemStats.total = data.all_count || 0
|
itemStats.total = data.all_count || 0
|
||||||
itemStats.inContainer = items.value.filter(i => i.container_id != null).length
|
itemStats.inContainer = items.value.filter(i => i.ContainerID != null).length
|
||||||
itemStats.unstored = items.value.filter(i => i.container_id == null).length
|
itemStats.unstored = items.value.filter(i => i.ContainerID == null).length
|
||||||
}
|
}
|
||||||
} catch { toast.error(t('message.server_error')) }
|
} catch { toast.error(t('message.server_error')) }
|
||||||
finally { itemLoading.value = false }
|
finally { itemLoading.value = false }
|
||||||
@@ -260,7 +260,7 @@ const itemPageNumbers = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function goToItemDetail(item) {
|
function goToItemDetail(item) {
|
||||||
router.push(`/warehouse/item/${item.id}`)
|
router.push(`/warehouse/item/${item.ID}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteItemTarget = ref(null)
|
const deleteItemTarget = ref(null)
|
||||||
@@ -276,7 +276,7 @@ async function doDeleteItem() {
|
|||||||
if (!deleteItemTarget.value) return
|
if (!deleteItemTarget.value) return
|
||||||
deletingItem.value = true
|
deletingItem.value = true
|
||||||
try {
|
try {
|
||||||
const { errCode } = await warehouseApi.deleteItem(deleteItemTarget.value.id)
|
const { errCode } = await warehouseApi.deleteItem(deleteItemTarget.value.ID)
|
||||||
if (errCode === 0) {
|
if (errCode === 0) {
|
||||||
toast.success(t('message.delete_success'))
|
toast.success(t('message.delete_success'))
|
||||||
showDeleteItemConfirm.value = false
|
showDeleteItemConfirm.value = false
|
||||||
@@ -298,14 +298,36 @@ function getContainerTitle(cid) {
|
|||||||
function formatDate(dateStr) {
|
function formatDate(dateStr) {
|
||||||
if (!dateStr) return '—'
|
if (!dateStr) return '—'
|
||||||
try {
|
try {
|
||||||
const d = new Date(dateStr)
|
let d
|
||||||
|
if (typeof dateStr === 'string' && /^\d+$/.test(dateStr)) {
|
||||||
|
// Unix timestamp string like "1712345678"
|
||||||
|
d = new Date(parseInt(dateStr, 10) * 1000)
|
||||||
|
} else {
|
||||||
|
d = new Date(dateStr)
|
||||||
|
}
|
||||||
|
if (isNaN(d.getTime())) return '—'
|
||||||
return d.toLocaleDateString(isEn.value ? 'en-US' : 'zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' })
|
return d.toLocaleDateString(isEn.value ? 'en-US' : 'zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' })
|
||||||
} catch { return dateStr }
|
} catch { return dateStr }
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmtTs(ts) {
|
function fmtTs(ts) {
|
||||||
if (!ts) return '—'
|
if (!ts) return '—'
|
||||||
const d = new Date(parseInt(ts) * 1000)
|
let d
|
||||||
|
if (typeof ts === 'number') {
|
||||||
|
// Unix timestamp in seconds (number)
|
||||||
|
d = new Date(ts * 1000)
|
||||||
|
} else if (typeof ts === 'string') {
|
||||||
|
// Check if it's a Unix timestamp string like "1712345678"
|
||||||
|
if (/^\d+$/.test(ts)) {
|
||||||
|
d = new Date(parseInt(ts, 10) * 1000)
|
||||||
|
} else {
|
||||||
|
// ISO 8601 or other string format
|
||||||
|
d = new Date(ts)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
d = new Date(ts)
|
||||||
|
}
|
||||||
|
if (isNaN(d.getTime())) return '—'
|
||||||
return d.toLocaleString()
|
return d.toLocaleString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,23 +574,23 @@ onMounted(() => {
|
|||||||
</tr>
|
</tr>
|
||||||
<tr
|
<tr
|
||||||
v-else
|
v-else
|
||||||
v-for="item in items" :key="item.id"
|
v-for="item in items" :key="item.ID"
|
||||||
class="cursor-pointer border-b border-gray-100 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:hover:bg-dk-base"
|
class="cursor-pointer border-b border-gray-100 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:hover:bg-dk-base"
|
||||||
@click="goToItemDetail(item)"
|
@click="goToItemDetail(item)"
|
||||||
>
|
>
|
||||||
<td class="px-6 py-3 font-medium max-w-[200px] truncate">{{ item.name }}</td>
|
<td class="px-6 py-3 font-medium max-w-[200px] truncate">{{ item.Name }}</td>
|
||||||
<td class="px-6 py-3 max-w-[160px] truncate text-xs text-gray-500 dark:text-gray-400">{{ item.serial_number || '—' }}</td>
|
<td class="px-6 py-3 max-w-[160px] truncate text-xs text-gray-500 dark:text-gray-400">{{ item.SerialNumber || '—' }}</td>
|
||||||
<td class="px-6 py-3 text-center text-sm">{{ item.quantity }}</td>
|
<td class="px-6 py-3 text-center text-sm">{{ item.Quantity }}</td>
|
||||||
<td class="px-6 py-3">
|
<td class="px-6 py-3">
|
||||||
<span v-if="item.container_id != null" class="inline-flex items-center gap-1 text-sm text-blue-600">
|
<span v-if="item.ContainerID != null" class="inline-flex items-center gap-1 text-sm text-blue-600">
|
||||||
<IconArrowRight :size="13" />
|
<IconArrowRight :size="13" />
|
||||||
<span class="max-w-[140px] truncate">{{ getContainerTitle(item.container_id) }}</span>
|
<span class="max-w-[140px] truncate">{{ getContainerTitle(item.ContainerID) }}</span>
|
||||||
</span>
|
</span>
|
||||||
<span v-else class="inline-flex items-center gap-1 text-xs text-orange-500">
|
<span v-else class="inline-flex items-center gap-1 text-xs text-orange-500">
|
||||||
{{ t('warehouse.unstored_items') }}
|
{{ t('warehouse.unstored_items') }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-3 whitespace-nowrap text-xs text-gray-400 dark:text-gray-500">{{ formatDate(item.created_at) }}</td>
|
<td class="px-6 py-3 whitespace-nowrap text-xs text-gray-400 dark:text-gray-500">{{ formatDate(item.CreatedAt) }}</td>
|
||||||
<td class="px-6 py-3 text-right" @click.stop>
|
<td class="px-6 py-3 text-right" @click.stop>
|
||||||
<button
|
<button
|
||||||
class="flex h-7 w-7 items-center justify-center rounded text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20"
|
class="flex h-7 w-7 items-center justify-center rounded text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20"
|
||||||
|
|||||||
@@ -46,9 +46,27 @@ function getPhotoHashes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==================== 加载编辑数据 ====================
|
// ==================== 加载编辑数据 ====================
|
||||||
onMounted(async () => {
|
const linkedItemId = ref(null)
|
||||||
if (!isEdit.value) return
|
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// 新增模式:检查预填数据
|
||||||
|
if (!isEdit.value) {
|
||||||
|
const prefillStr = localStorage.getItem('prefill_work_order')
|
||||||
|
if (prefillStr) {
|
||||||
|
try {
|
||||||
|
const prefill = JSON.parse(prefillStr)
|
||||||
|
form.title = prefill.title || ''
|
||||||
|
form.description = prefill.description || ''
|
||||||
|
linkedItemId.value = prefill.itemId || null
|
||||||
|
localStorage.removeItem('prefill_work_order')
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编辑模式
|
||||||
pageLoading.value = true
|
pageLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await workOrderApi.get(orderId.value)
|
const res = await workOrderApi.get(orderId.value)
|
||||||
@@ -117,6 +135,7 @@ async function handleSubmit() {
|
|||||||
title: form.title,
|
title: form.title,
|
||||||
description: form.description,
|
description: form.description,
|
||||||
photos,
|
photos,
|
||||||
|
item_id: linkedItemId.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
IconX,
|
IconX,
|
||||||
IconSearch,
|
IconSearch,
|
||||||
IconExternalLink,
|
IconExternalLink,
|
||||||
|
IconPackage,
|
||||||
} from '@tabler/icons-vue'
|
} from '@tabler/icons-vue'
|
||||||
|
|
||||||
usePageTitle('work_order.detail_title')
|
usePageTitle('work_order.detail_title')
|
||||||
@@ -32,6 +33,7 @@ const orderId = computed(() => parseInt(route.params.id))
|
|||||||
const order = ref(null)
|
const order = ref(null)
|
||||||
const photos = ref([])
|
const photos = ref([])
|
||||||
const commits = ref([])
|
const commits = ref([])
|
||||||
|
const linkedItems = ref([])
|
||||||
const canModify = ref(false)
|
const canModify = ref(false)
|
||||||
const canCommit = ref(false)
|
const canCommit = ref(false)
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
@@ -136,6 +138,7 @@ async function fetchOrder() {
|
|||||||
canCommit.value = data.canCommit ?? false
|
canCommit.value = data.canCommit ?? false
|
||||||
photos.value = data.photos ?? []
|
photos.value = data.photos ?? []
|
||||||
commits.value = data.commits ?? []
|
commits.value = data.commits ?? []
|
||||||
|
linkedItems.value = data.linkedItems ?? []
|
||||||
// 初始化进度提交状态为当前状态
|
// 初始化进度提交状态为当前状态
|
||||||
if (order.value?.CurrentStatus) {
|
if (order.value?.CurrentStatus) {
|
||||||
commitStatus.value = order.value.CurrentStatus
|
commitStatus.value = order.value.CurrentStatus
|
||||||
@@ -426,6 +429,22 @@ onUnmounted(() => {
|
|||||||
<label class="mb-1 block text-xs font-medium text-gray-400">{{ t('work_order.description') }}</label>
|
<label class="mb-1 block text-xs font-medium text-gray-400">{{ t('work_order.description') }}</label>
|
||||||
<p class="whitespace-pre-wrap text-sm text-gray-700 dark:text-gray-300">{{ order.Description }}</p>
|
<p class="whitespace-pre-wrap text-sm text-gray-700 dark:text-gray-300">{{ order.Description }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 关联物品 -->
|
||||||
|
<div v-if="linkedItems.length > 0">
|
||||||
|
<label class="mb-1 block text-xs font-medium text-gray-400">{{ t('work_order.linked_items') }}</label>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<RouterLink
|
||||||
|
v-for="item in linkedItems"
|
||||||
|
:key="item.ID"
|
||||||
|
:to="`/warehouse/item/${item.ID}`"
|
||||||
|
class="inline-flex items-center gap-1 rounded-full border border-green-200 bg-green-50 px-2.5 py-1 text-xs font-medium text-green-700 transition-colors hover:bg-green-100 dark:border-green-800 dark:bg-green-900/30 dark:text-green-300 dark:hover:bg-green-900/50"
|
||||||
|
>
|
||||||
|
<IconPackage :size="12" />
|
||||||
|
{{ item.Name }}
|
||||||
|
<span v-if="item.SerialNumber" class="text-green-500">-{{ item.SerialNumber }}</span>
|
||||||
|
</RouterLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- 关联采购订单汇总(去重) -->
|
<!-- 关联采购订单汇总(去重) -->
|
||||||
<div v-if="allPurchaseOrders.length > 0">
|
<div v-if="allPurchaseOrders.length > 0">
|
||||||
<label class="mb-1 block text-xs font-medium text-gray-400">关联采购订单</label>
|
<label class="mb-1 block text-xs font-medium text-gray-400">关联采购订单</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user