spring
2025-11-19 1187936c713bae2ad43063900c7bee80502e091d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
  <view>
    <ProductCard
      :data="cardData"
      :map="{
        deviceModel: 'deviceModel',
        model: 'model',
        systemNo: 'systemNo',
        totalAmount: 'totalAmount',
        amount: 'amount',
        unAmount: 'unAmount',
      }"
    />
    <view class="mx-3">
      <wd-grid class="rounded-lg" clickable>
        <wd-grid-item icon="computer" @click="handleReportClick" text="报工" />
        <!-- <wd-grid-item
          icon="chart"
          text="自检"
          link-type="navigateTo"
          url="/pages/production/twist/selfInspect/index"
        /> -->
        <wd-grid-item
          icon="tips"
          link-type="navigateTo"
          :url="`/pages/production/twist/backman/index?id=${paramsId}`"
          text="杂工"
        />
        <wd-grid-item
          icon="wallet"
          link-type="navigateTo"
          :url="`/pages/production/twist/receive/index?id=${paramsId}`"
          text="材料领用"
        />
      </wd-grid>
    </view>
  </view>
</template>
 
<script lang="ts" setup>
import { onLoad } from "@dcloudio/uni-app";
import ProductCard from "@/components/product_card/index.vue";
import TwistApi from "@/api/product/twist";
import { getPrepareId, setPrepareId, clearPrepareId } from "@/utils/cache";
import HomeApi from "@/api/home";
 
const paramsId = ref();
const cardData = reactive({
  deviceModel: undefined,
  model: undefined,
  systemNo: undefined,
  totalAmount: undefined,
  amount: undefined,
  unAmount: undefined,
});
 
const getDetailData = async (id: string) => {
  const { data } = await TwistApi.getTwistDetailById({
    id: id,
  });
  cardData.deviceModel = data.deviceModel;
  cardData.model = data.model;
  cardData.systemNo = data.systemNo;
  cardData.totalAmount = data.totalLength;
  cardData.amount = data.length;
  cardData.unAmount = data.unLength;
};
 
// 获取并缓存生产准备ID
const initPrepareId = async () => {
  try {
    const { data } = await HomeApi.getIndex();
    if (data && data.prepareId) {
      setPrepareId(data.prepareId);
    } else {
      // 如果没有 prepareId,清空缓存
      clearPrepareId();
    }
  } catch (error) {
    console.error("获取生产准备ID失败:", error);
    // 获取失败时也清空缓存
    clearPrepareId();
  }
};
 
// 处理报工点击
const handleReportClick = () => {
  const prepareId = getPrepareId();
  console.log("绞线表格报工检查 - prepareId值:", prepareId);
 
  // 如果prepareId为空或未定义,说明生产准备未完成
  if (!prepareId) {
    console.log("绞线表格报工阻止 - 生产准备未完成");
    uni.showModal({
      title: "提示",
      content: "请在电脑端完成生产准备确认,再进行报工操作",
      showCancel: false,
      confirmText: "确定",
      success: () => {
        // 用户点击确定后,不做任何操作
      },
    });
    return;
  }
 
  // 如果有 prepareId,正常跳转
  uni.navigateTo({
    url: `/pages/production/twist/report/index?id=${paramsId.value}`,
  });
};
 
onLoad(async (options: any) => {
  paramsId.value = options.id;
  await getDetailData(options.id);
  // 获取并缓存生产准备ID
  await initPrepareId();
});
</script>
 
<style lang="scss" scoped></style>