| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <template>
- <view class="container" @click="playGlobalSound">
- <!-- 任务列表 -->
- <view class="task-list">
- <template v-if="!loading">
- <view
- v-if="taskList.length > 0"
- v-for="(item, index) in taskList"
- :key="index"
- class="task-card"
- @click="handleTaskClick(item)"
- >
- <view class="task-header">
- <text class="task-no">作业单号:{{ item.taskCode }}</text>
- </view>
- <view class="task-content">
- <view class="flex-a mb-10">
- <text class="label">仓库:</text>
- <text class="value">{{ item.godownName }}</text>
- </view>
- <view class="flex-a mb-10">
- <text class="label">订单数量:</text>
- <text class="value">{{ item.orderNum }}</text>
- </view>
- <view class="flex-a mb-10">
- <text class="label">创建时间:</text>
- <text class="value">{{ item.createTime }}</text>
- </view>
- <view class="flex-a">
- <text class="label">作业状态:</text>
- <text class="value">{{ getTaskStatusText(item.taskStatus) }}</text>
- </view>
- </view>
- </view>
- <view v-else class="empty-state">
- <text>暂无任务数据</text>
- </view>
- </template>
- <view v-else class="loading-state">
- <u-loading-icon></u-loading-icon>
- <text>加载中...</text>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import { ref, onMounted } from "vue";
- // 搜索文本
- const searchText = ref("");
- // 点击全局音效
- function playGlobalSound(){
- uni.$u.playClickSound()
- }
- // 任务列表数据
- const taskList = ref([]);
- // 加载状态
- const loading = ref(false);
- // 作业状态枚举
- const taskStatusEnum = {
- 1: "待作业",
- 2: "作业中",
- 3: "已完成",
- 4: "已关闭",
- };
- // 获取状态文本
- const getTaskStatusText = (status) => {
- return taskStatusEnum[status] || "未知状态";
- };
- // 获取任务列表
- const fetchTaskList = async () => {
- loading.value = true;
- try {
- const response = await uni.$u.http.post("/app/appstock/getNeedStockList");
- console.log(response);
- taskList.value = response;
- if (response.code === 200) {
- taskList.value = response.data || [];
- } else {
- uni.showToast({
- title: response.msg || "获取任务列表失败",
- icon: "none",
- });
- }
- } catch (error) {
- uni.showToast({
- title: "获取任务列表失败",
- icon: "none",
- });
- } finally {
- loading.value = false;
- }
- };
- // 搜索处理
- const onSearch = () => {
- fetchTaskList();
- };
- // 打开扫码
- const openScan = () => {
- // #ifdef APP-PLUS || MP-WEIXIN
- uni.scanCode({
- success: (res) => {
- searchText.value = res.result;
- onSearch();
- },
- fail: (err) => {
- uni.showToast({
- title: "扫码失败",
- icon: "error",
- });
- },
- });
- // #endif
- // #ifdef H5
- uni.showToast({
- title: "H5环境不支持扫码",
- icon: "none",
- });
- // #endif
- };
- // 点击任务卡片
- const handleTaskClick = (task) => {
- uni.showModal({
- title: "领取确认",
- content: "是否确认领取下架任务?",
- cancelText: "取消",
- confirmText: "确认",
- success: async (res) => {
- playGlobalSound()
- if (res.confirm) {
- try {
- const response = await uni.$u.http.post(`/app/appstock/lockStockTask?taskCode=${task.taskCode}`);
- if (response.code === 200) {
- uni.navigateTo({
- url: `/pages/index/wms/task-detail?taskCode=${task.taskCode}`,
- });
- } else {
- uni.showToast({
- title: response.msg || "任务锁定失败",
- icon: "none",
- });
- }
- } catch (error) {
- uni.showToast({
- title: error,
- icon: "none",
- });
- }
- }
- },
- });
- };
- // 页面加载时获取任务列表
- onMounted(() => {
- fetchTaskList();
- });
- </script>
- <style scoped>
- .task-card {
- background-color: #ffffff;
- padding: 20rpx;
- margin-top: 16rpx;
- box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
- }
- .task-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 16rpx;
- }
- .task-no {
- font-size: 28rpx;
- font-weight: bold;
- }
- .empty-state {
- text-align: center;
- padding: 40rpx;
- color: #999;
- }
- .loading-state {
- text-align: center;
- padding: 40rpx;
- }
- .loading-state text {
- margin-left: 12rpx;
- color: #666;
- font-size: 28rpx;
- }
- </style>
|