85 lines
4.4 KiB
Vue
85 lines
4.4 KiB
Vue
<template>
|
|
<view v-if="user" class="page-shell portal-page home-page">
|
|
<PortalHeader ref="portalHeader" :title="user.warehouse ? `首页 · ${user.warehouse}` : '首页'" :user="user" :menu="!isBoundOperator" :warehouses="warehouses" :selected-warehouse-id="user.warehouseId" :warehouse-loading="warehouseLoading" :warehouse-error="warehouseError" @warehouse-select="changeWarehouse" @menu-change="menuOpen = $event" />
|
|
<view class="home-menu">
|
|
<view v-for="group in groups" :key="group.key" class="home-group" :class="{ 'home-group-disabled': !group.available }">
|
|
<view class="home-group-title"><view class="home-group-mark" :class="`home-group-mark-${group.key}`"></view><text>{{ group.name }}</text></view>
|
|
<view class="home-operation-grid">
|
|
<button v-for="operation in group.operations" :key="operation.name" class="home-operation" :class="{ 'home-operation-primary': operation.available, 'home-operation-disabled': !operation.available }" :disabled="!operation.available" @tap="openOperation(operation)">
|
|
<view class="home-operation-icon" aria-hidden="true"><uni-icons :type="operation.iconType" :color="operation.available ? '#135ee8' : '#9aa6b2'" size="28" /></view>
|
|
<text class="home-operation-name">{{ operation.name }}</text>
|
|
<text v-if="operation.available" class="home-operation-meta home-operation-pending">开始作业</text>
|
|
<text v-else class="home-operation-meta home-operation-unavailable">未开放</text>
|
|
</button>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import PortalHeader from '@/components/PortalHeader.vue'
|
|
import { MODULES } from '@/data/demo-data.js'
|
|
import { listPdaWarehouses } from '@/api/pda-loading.js'
|
|
import { session, requireSession, selectWarehouse, isDomesticPdaOperator } from '@/stores/session.js'
|
|
|
|
const ICON_TYPES = {
|
|
'一件代发清点组托': 'download',
|
|
'到货收货': 'download', '商品上架': 'upload', '入库质检': 'checkbox',
|
|
'一件代发': 'map', '出库拣货': 'cart', '出库复核': 'compose', '装箱交接': 'paperplane',
|
|
'库存盘点': 'list', '商品移库': 'loop', '库存调整': 'compose',
|
|
'商品查询': 'search', '库位查询': 'location', '任务查询': 'flag'
|
|
}
|
|
|
|
const HOME_GROUPS = MODULES.map((module) => ({
|
|
...module,
|
|
name: module.key === 'inventory' ? '库内作业' : module.name,
|
|
available: module.operations.some((operation) => operation.available),
|
|
operations: module.operations.filter((operation) => operation.visible)
|
|
.map((operation) => ({ ...operation, iconType: ICON_TYPES[operation.name] || 'circle' }))
|
|
})).filter((module) => module.operations.length)
|
|
|
|
export default {
|
|
components: { PortalHeader },
|
|
data() { return { user: session.currentUser, groups: HOME_GROUPS, menuOpen: false, warehouses: [], warehouseLoading: false, warehouseError: '' } },
|
|
computed: { isBoundOperator() { return isDomesticPdaOperator(this.user) } },
|
|
onShow() { if (!requireSession()) return; this.user = session.currentUser; this.loadWarehouses() },
|
|
onBackPress() {
|
|
if (!this.menuOpen) return false
|
|
this.$refs.portalHeader.closeMenu()
|
|
return true
|
|
},
|
|
methods: {
|
|
async loadWarehouses() {
|
|
if (this.warehouseLoading) return
|
|
this.warehouseLoading = true; this.warehouseError = ''
|
|
try {
|
|
const warehouses = await listPdaWarehouses()
|
|
if (this.isBoundOperator) {
|
|
const bound = warehouses.find((warehouse) => String(warehouse.id) === String(this.user.domesticWarehouseId || ''))
|
|
if (!bound) throw new Error('账号绑定的作业仓库不存在或已停用,请联系管理员')
|
|
this.user = selectWarehouse(bound)
|
|
this.warehouses = [bound]
|
|
} else {
|
|
this.warehouses = warehouses
|
|
if (!this.user.warehouseId) this.$nextTick(() => this.$refs.portalHeader.openMenu())
|
|
}
|
|
} catch (error) {
|
|
this.warehouseError = error.message || '仓库加载失败,请稍后重试'
|
|
} finally { this.warehouseLoading = false }
|
|
},
|
|
changeWarehouse(warehouse) { if (this.isBoundOperator) return; this.user = selectWarehouse(warehouse) },
|
|
openOperation(operation) {
|
|
if (!operation.available) return
|
|
if (!this.user.warehouseId) { this.$refs.portalHeader.openMenu(); return }
|
|
const routes = {
|
|
'一件代发': '/pages/dropship-tasks/dropship-tasks',
|
|
'出库拣货': '/pages/tasks/tasks',
|
|
'库位查询': `/pages/operation/operation?module=query&name=${encodeURIComponent('库位查询')}`
|
|
}
|
|
uni.navigateTo({ url: routes[operation.name] })
|
|
}
|
|
}
|
|
}
|
|
</script>
|