<template>
|
<view class="work-order">
|
<PageHeader title="生产工单" @back="goBack" />
|
|
<!-- 搜索区域 -->
|
<view class="search-section">
|
<view class="search-bar">
|
<view class="search-input">
|
<up-input class="search-text"
|
v-model="data.searchForm.workOrderNo"
|
placeholder="工单编号"
|
@confirm="handleQuery"
|
clearable />
|
</view>
|
<view class="search-input">
|
<up-input class="search-text"
|
v-model="data.searchForm.npsNo"
|
placeholder="生产订单号"
|
@confirm="handleQuery"
|
clearable />
|
</view>
|
<view class="filter-button" @click="handleQuery">
|
<up-icon name="search" size="24" color="#999"></up-icon>
|
</view>
|
</view>
|
<view class="switch-row">
|
<text class="switch-label">仅看我的</text>
|
<up-switch v-model="filterMine" @change="handleQuery" size="18" />
|
</view>
|
</view>
|
|
<!-- 工单列表 -->
|
<scroll-view scroll-y class="ledger-list" v-if="tableData.length > 0" @scrolltolower="loadMore">
|
<view v-for="(item, index) in tableData" :key="item.id || index" class="ledger-item">
|
<view class="item-header">
|
<view class="item-left">
|
<view class="document-icon">
|
<up-icon name="file-text" size="16" color="#ffffff"></up-icon>
|
</view>
|
<text class="item-id">{{ item.workOrderNo }}</text>
|
</view>
|
<view class="item-right">
|
<text class="item-tag tag-type">{{ item.workOrderType }}</text>
|
</view>
|
</view>
|
|
<up-divider></up-divider>
|
|
<view class="item-details">
|
<view class="detail-row">
|
<text class="detail-label">生产订单号</text>
|
<text class="detail-value">{{ item.npsNo || '-' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">产品名称</text>
|
<text class="detail-value">{{ item.productName }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">规格型号</text>
|
<text class="detail-value">{{ item.model }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">工序名称</text>
|
<text class="detail-value">{{ item.operationName }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">需求/完成数量</text>
|
<text class="detail-value">{{ item.planQuantity }} / {{ item.completeQuantity }} {{ item.unit }}</text>
|
</view>
|
|
<view class="progress-section">
|
<text class="detail-label">完成进度</text>
|
<view class="progress-bar">
|
<up-line-progress
|
:percentage="toProgressPercentage(item.completionStatus)"
|
activeColor="#2979ff"
|
:showText="true"
|
></up-line-progress>
|
</view>
|
</view>
|
|
<view class="detail-row">
|
<text class="detail-label">计划开始</text>
|
<text class="detail-value">{{ item.planStartTime }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">计划结束</text>
|
<text class="detail-value">{{ item.planEndTime }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">实际开始</text>
|
<text class="detail-value">{{ item.actualStartTime || '-' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">实际结束</text>
|
<text class="detail-value">{{ item.actualEndTime || '-' }}</text>
|
</view>
|
</view>
|
|
<view class="item-actions">
|
<up-button v-if="showStartReport(item)"
|
class="action-btn"
|
size="small"
|
type="primary"
|
@click="handleStartWork(item)">开始报工</up-button>
|
<up-button v-if="showEndReport(item)"
|
class="action-btn"
|
size="small"
|
type="success"
|
@click="goReport(item)">结束报工</up-button>
|
</view>
|
</view>
|
<up-loadmore :status="loadStatus" />
|
</scroll-view>
|
|
<view v-else-if="!loading" class="no-data">
|
<up-empty mode="data" text="暂无工单数据"></up-empty>
|
</view>
|
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, reactive } from "vue";
|
import { onShow } from '@dcloudio/uni-app';
|
import { productWorkOrderPage, startWork } from "@/api/productionManagement/workOrder.js";
|
import PageHeader from "@/components/PageHeader.vue";
|
import useUserStore from "@/store/modules/user";
|
|
const userStore = useUserStore();
|
|
const loading = ref(false);
|
const tableData = ref([]);
|
const loadStatus = ref('loadmore');
|
const filterMine = ref(false);
|
|
const page = reactive({
|
current: 1,
|
size: 10,
|
total: 0,
|
});
|
|
const data = reactive({
|
searchForm: {
|
workOrderNo: "",
|
npsNo: "",
|
},
|
});
|
|
const isCompleted = row => {
|
const status = Number(row?.completionStatus);
|
return Number.isFinite(status) && status >= 100;
|
};
|
|
const canOperate = row => !row.endOrder && !isCompleted(row);
|
|
const showStartReport = row => canOperate(row) && !row.actualStartTime;
|
|
const showEndReport = row => canOperate(row) && !!row.actualStartTime;
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const handleQuery = () => {
|
page.current = 1;
|
tableData.value = [];
|
getList();
|
};
|
|
const getList = () => {
|
if (loading.value) return;
|
loading.value = true;
|
|
const params = { ...data.searchForm, ...page };
|
if (filterMine.value) {
|
params.filterMine = true;
|
}
|
|
productWorkOrderPage(params).then((res) => {
|
loading.value = false;
|
const records = res.data.records || [];
|
tableData.value = page.current === 1 ? records : [...tableData.value, ...records];
|
page.total = res.data.total;
|
|
if (tableData.value.length >= page.total) {
|
loadStatus.value = 'nomore';
|
} else {
|
loadStatus.value = 'loadmore';
|
}
|
}).catch(() => {
|
loading.value = false;
|
uni.showToast({ title: '加载失败', icon: 'error' });
|
});
|
};
|
|
const loadMore = () => {
|
if (loadStatus.value === 'nomore' || loading.value) return;
|
page.current++;
|
getList();
|
};
|
|
const toProgressPercentage = (val) => {
|
const n = Number(val);
|
if (!Number.isFinite(n)) return 0;
|
if (n <= 0) return 0;
|
if (n >= 100) return 100;
|
return Math.round(n);
|
};
|
|
const handleStartWork = (row) => {
|
uni.showModal({
|
title: "提示",
|
content: "确认开始报工?",
|
success: res => {
|
if (res.confirm) {
|
startWork({
|
productionOperationTaskId: row.id,
|
userId: userStore.id,
|
})
|
.then(() => {
|
uni.showToast({ title: "开始报工成功" });
|
handleQuery();
|
})
|
.catch(() => {
|
uni.showToast({ title: "开始报工失败", icon: "error" });
|
});
|
}
|
},
|
});
|
};
|
|
const goReport = (row) => {
|
uni.navigateTo({
|
url: `/pages/productionManagement/productionReport/index?orderRow=${encodeURIComponent(
|
JSON.stringify(row)
|
)}`,
|
});
|
};
|
|
onShow(() => {
|
handleQuery();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import '@/styles/sales-common.scss';
|
|
.work-order {
|
min-height: 100vh;
|
background: #f8f9fa;
|
}
|
|
.tag-type {
|
background-color: #e3f2fd;
|
color: #2196f3;
|
padding: 2px 8px;
|
border-radius: 4px;
|
font-size: 12px;
|
}
|
|
.progress-section {
|
margin: 15px 0;
|
.detail-label {
|
display: block;
|
margin-bottom: 8px;
|
font-size: 13px;
|
color: #666;
|
}
|
}
|
|
.item-actions {
|
display: flex;
|
justify-content: flex-end;
|
gap: 10px;
|
padding: 12px 0;
|
border-top: 1px solid #f5f5f5;
|
|
.action-btn {
|
margin: 0;
|
width: auto;
|
}
|
}
|
|
.no-data {
|
padding-top: 100px;
|
}
|
</style>
|