zhangwencui
6 天以前 bd5f7c8da7a46fe8fb12cd68373739931b268890
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
  <view class="invoice-add">
    <!-- 使用通用页面头部组件 -->
    <PageHeader title="生产报工"
                @back="goBack" />
    <!-- 表单内容 -->
    <u-form @submit="submitForm"
            ref="formRef"
            label-width="110"
            input-align="right"
            error-message-align="right">
      <!-- 基本信息 -->
      <view class="form-section">
        <u-form-item label="待生产数量"
                     prop="planQuantity"
                     required>
          <u-input v-model="form.planQuantity"
                   placeholder="自动填充"
                   disabled />
        </u-form-item>
        <u-form-item label="本次生产数量"
                     prop="quantity"
                     required>
          <u-input v-model="form.quantity"
                   placeholder="请输入"
                   type="number" />
          <!-- <u-number-box v-model="form.quantity"
                        step="0.1"
                        bgColor="#fff"
                        decimal-length="1"
                        :min="0"></u-number-box> -->
        </u-form-item>
        <u-form-item label="班组信息"
                     prop="schedulingUserId"
                     required>
          <u-input v-model="form.userName"
                   placeholder="请选择生产人"
                   readonly />
        </u-form-item>
      </view>
      <!-- 使用FooterButtons组件 -->
      <FooterButtons @cancel="goBack"
                     @confirm="submitForm"
                     :loading="submitting" />
      <!-- 为底部按钮留出空间 -->
      <view style="height: 80px;"></view>
    </u-form>
    <!-- 生产人选择器 -->
    <up-action-sheet :show="showProducerPicker"
                     :actions="producerList"
                     title="选择生产人"
                     @select="onProducerConfirm"
                     @close="showProducerPicker = false" />
  </view>
</template>
 
<script setup>
  import { ref, onMounted } from "vue";
  import { onLoad } from "@dcloudio/uni-app";
  import FooterButtons from "@/components/FooterButtons.vue";
 
  const showToast = message => {
    uni.showToast({
      title: message,
      icon: "none",
    });
  };
  import { addProductMain } from "@/api/productionManagement/productionReporting";
  import { getInfo } from "@/api/login";
 
  // 表单引用
  const formRef = ref();
 
  // 表单数据
  let form = ref({
    planQuantity: 0,
    quantity: 0,
    userName: "",
    workOrderId: "",
    reportWork: "",
    productProcessRouteItemId: "",
    userId: "",
    productMainId: null,
  });
  let schedulingUserName = ref("");
 
  // 日期选择器状态
  const showEnterDatePicker = ref(false);
  const enterDateValue = ref(Date.now());
 
  // 生产人选择器状态
  const showProducerPicker = ref(false);
  const producerList = ref([]);
 
  // 生产人选择确认
  const onProducerConfirm = e => {
    form.value.schedulingUserId = e.value;
    schedulingUserName.value = e.name;
    showProducerPicker.value = false;
  };
 
  // 提交状态
  const submitting = ref(false);
 
  // 返回上一页
  const goBack = () => {
    uni.navigateBack();
  };
  // 提交表单
  const submitForm = async () => {
    submitting.value = true;
    // 校验表单
    if (!form.value.quantity) {
      submitting.value = false;
      showToast("请输入本次生产数量");
      return;
    }
    if (form.value.quantity > form.value.planQuantity) {
      submitting.value = false;
      showToast("本次生产数量不能大于待生产数量");
      return;
    }
    console.log(form.value, "form.value");
 
    addProductMain(form.value).then(res => {
      if (res.code === 200) {
        showToast("报工成功");
        submitting.value = false;
        setTimeout(() => {
          goBack();
        }, 1000);
      } else {
        showToast(res.msg || "报工失败");
        submitting.value = false;
      }
    });
  };
 
  // 页面加载时初始化数据
  onLoad(options => {
    console.log(options, "options");
    try {
      const orderRow = JSON.parse(options.orderRow);
      console.log(orderRow, "orderRow======########");
      form.value.planQuantity = orderRow.planQuantity;
      form.value.quantity = orderRow.quantity;
      form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId;
      form.value.workOrderId = orderRow.id;
      form.value.reportWork = orderRow.reportWork;
      form.value.productMainId = orderRow.productMainId;
      getInfo().then(res => {
        form.value.userId = res.user.userId;
        form.value.userName = res.user.userName;
      });
    } catch (error) {
      modal.msgError("订单解析失败");
      goBack();
      return;
    }
  });
</script>
 
<style scoped lang="scss">
  @import "@/static/scss/form-common.scss";
</style>