<template>
|
<view class="account-detail">
|
<PageHeader title="下发" @back="goBack" />
|
<up-form ref="formRef" :model="form" :rules="rules" label-width="110">
|
<up-form-item label="产品名称">
|
<up-input v-model="form.productName" disabled placeholder="自动填充" />
|
</up-form-item>
|
<up-form-item label="规格型号">
|
<up-input v-model="form.model" disabled placeholder="自动填充" />
|
</up-form-item>
|
<up-form-item label="计划完成时间" prop="planCompleteTime" required>
|
<up-input v-model="form.planCompleteTime" placeholder="请选择" readonly @click="showPlanDatePicker = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showPlanDatePicker = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="生产数量" prop="totalAssignedQuantity" required>
|
<up-input v-model="form.totalAssignedQuantity" type="number" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="可下发数量">
|
<up-input :model-value="String(maxQuantity)" disabled placeholder="自动计算" />
|
</up-form-item>
|
</up-form>
|
|
<FooterButtons :loading="loading" confirmText="确定下发" @cancel="goBack" @confirm="handleSubmit" />
|
|
<up-datetime-picker
|
:show="showPlanDatePicker"
|
v-model="planDateValue"
|
mode="date"
|
@confirm="onPlanDateConfirm"
|
@cancel="showPlanDatePicker = false"
|
/>
|
</view>
|
</template>
|
|
<script setup>
|
import { ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import { formatDateToYMD } from "@/utils/ruoyi";
|
import { productionPlanCombine } from "@/api/productionManagement/productionPlan";
|
|
const formRef = ref();
|
const loading = ref(false);
|
|
const maxQuantity = ref(0);
|
const showPlanDatePicker = ref(false);
|
const planDateValue = ref(Date.now());
|
|
const form = ref({
|
productName: "",
|
model: "",
|
totalAssignedQuantity: "",
|
planCompleteTime: "",
|
productId: undefined,
|
ids: [],
|
});
|
|
const rules = {
|
planCompleteTime: [{ required: true, message: "请选择计划完成时间", trigger: "change" }],
|
totalAssignedQuantity: [{ required: true, message: "请输入生产数量", trigger: "blur" }],
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const onPlanDateConfirm = e => {
|
const value = e?.value ?? planDateValue.value;
|
form.value.planCompleteTime = formatDateToYMD(value);
|
showPlanDatePicker.value = false;
|
};
|
|
const handleSubmit = async () => {
|
const valid = await formRef.value.validate().catch(() => false);
|
if (!valid) return;
|
|
const qty = Number(form.value.totalAssignedQuantity);
|
if (!qty || qty <= 0) {
|
uni.showToast({ title: "生产数量必须大于0", icon: "none" });
|
return;
|
}
|
if (qty > Number(maxQuantity.value || 0)) {
|
uni.showToast({ title: "生产数量不能大于可下发数量", icon: "none" });
|
return;
|
}
|
if (!Array.isArray(form.value.ids) || form.value.ids.length === 0) {
|
uni.showToast({ title: "请选择要下发的计划", icon: "none" });
|
return;
|
}
|
|
loading.value = true;
|
const payload = {
|
...form.value,
|
totalAssignedQuantity: Number(qty.toFixed(4)),
|
};
|
productionPlanCombine(payload)
|
.then(res => {
|
if (res?.code && Number(res.code) !== 200) {
|
const msg = res?.msg || res?.message || "下发失败";
|
uni.showToast({ title: String(msg), icon: "none" });
|
return;
|
}
|
uni.showToast({ title: "下发成功", icon: "success" });
|
uni.$emit("mainProductionPlan:refresh");
|
goBack();
|
})
|
.catch(err => {
|
const msg = err?.msg || err?.message || err?.data?.msg || err?.data?.message;
|
uni.showToast({ title: msg ? String(msg) : "下发失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
onLoad(options => {
|
if (!options?.data) return;
|
try {
|
const payload = JSON.parse(decodeURIComponent(options.data));
|
form.value.productName = payload.productName || "";
|
form.value.model = payload.model || "";
|
form.value.productId = payload.productId ?? undefined;
|
form.value.ids = Array.isArray(payload.ids) ? payload.ids : [];
|
form.value.planCompleteTime = payload.planCompleteTime || "";
|
form.value.totalAssignedQuantity = String(payload.totalAssignedQuantity ?? "");
|
maxQuantity.value = Number(payload.maxQuantity ?? 0);
|
if (!form.value.planCompleteTime) {
|
form.value.planCompleteTime = formatDateToYMD(Date.now());
|
}
|
} catch {
|
uni.showToast({ title: "数据加载失败", icon: "none" });
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|