<template>
|
<view class="account-detail">
|
<PageHeader :title="pageTitle" @back="goBack" />
|
<up-form ref="formRef" :model="form" label-width="110">
|
<up-form-item label="设备编号" required>
|
<up-input v-model="form.equipmentNo" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="设备名称" required>
|
<up-input v-model="form.equipmentName" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="设备类别">
|
<up-input v-model="form.equipmentType" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="规格型号">
|
<up-input v-model="form.modelSpec" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="安装位置">
|
<up-input v-model="form.installLocation" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="使用单位">
|
<up-input v-model="form.useUnit" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="负责人">
|
<up-input v-model="managerName" placeholder="请选择" readonly @click="showManagerSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showManagerSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
</up-form>
|
|
<FooterButtons :loading="loading" confirmText="保存" @cancel="goBack" @confirm="handleSubmit" />
|
|
<up-action-sheet
|
:show="showManagerSheet"
|
title="选择负责人"
|
:actions="managerActions"
|
@select="onSelectManager"
|
@close="showManagerSheet = false"
|
/>
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import { userListNoPageByTenantId } from "@/api/system/user";
|
import {
|
specialEquipmentLedgerAdd,
|
specialEquipmentLedgerUpdate,
|
} from "@/api/safeProduction/specialEquipmentManagement";
|
|
const formRef = ref();
|
const loading = ref(false);
|
const showManagerSheet = ref(false);
|
const managerActions = ref([]);
|
const managerName = ref("");
|
|
const form = ref({
|
id: "",
|
equipmentNo: "",
|
equipmentName: "",
|
equipmentType: "",
|
modelSpec: "",
|
installLocation: "",
|
useUnit: "",
|
managerId: "",
|
managerName: "",
|
});
|
|
const pageTitle = computed(() => (form.value.id ? "编辑台账" : "新增台账"));
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const loadUsers = () => {
|
userListNoPageByTenantId()
|
.then(res => {
|
const rows = Array.isArray(res?.data) ? res.data : [];
|
managerActions.value = rows.map(u => ({
|
name: u.nickName || u.userName || "",
|
value: u.userId,
|
}));
|
})
|
.catch(() => {
|
managerActions.value = [];
|
});
|
};
|
|
const onSelectManager = action => {
|
form.value.managerId = action.value;
|
form.value.managerName = action.name;
|
managerName.value = action.name;
|
showManagerSheet.value = false;
|
};
|
|
const handleSubmit = async () => {
|
const equipmentNo = String(form.value.equipmentNo || "").trim();
|
if (!equipmentNo) {
|
uni.showToast({ title: "请输入设备编号", icon: "none" });
|
return;
|
}
|
const equipmentName = String(form.value.equipmentName || "").trim();
|
if (!equipmentName) {
|
uni.showToast({ title: "请输入设备名称", icon: "none" });
|
return;
|
}
|
|
loading.value = true;
|
const api = form.value.id ? specialEquipmentLedgerUpdate : specialEquipmentLedgerAdd;
|
api({ ...form.value, equipmentNo, equipmentName })
|
.then(() => {
|
uni.showToast({ title: "保存成功", icon: "success" });
|
uni.$emit("specialEquipmentManagement:refresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "保存失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
onLoad(options => {
|
if (!options?.data) return;
|
try {
|
const row = JSON.parse(decodeURIComponent(options.data));
|
form.value = { ...form.value, ...(row || {}) };
|
managerName.value = form.value.managerName || "";
|
} catch {
|
uni.showToast({ title: "数据加载失败", icon: "none" });
|
}
|
});
|
|
onMounted(() => {
|
loadUsers();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
</style>
|