| | |
| | | <PageHeader :title="operationType === 'edit' ? '编辑报修' : '新增报修'" @back="goBack" /> |
| | | |
| | | <!-- 表单内容 --> |
| | | <u-form @submit="sendForm" ref="formRef" :rules="formRules" label-width="110" input-align="right" error-message-align="right"> |
| | | <u-form @submit="sendForm" ref="formRef" :rules="formRules" :model="form" label-width="110"> |
| | | <!-- 基本信息 --> |
| | | <u-cell-group title="基本信息"> |
| | | <u-form-item label="设备名称" prop="deviceLedgerId" required border-bottom> |
| | |
| | | if (code == 200) { |
| | | form.value.deviceLedgerId = data.deviceLedgerId; |
| | | form.value.deviceModel = data.deviceModel; |
| | | form.value.repairTime = data.repairTime; |
| | | form.value.repairTime = dayjs(data.repairTime).format("YYYY-MM-DD"); |
| | | form.value.repairName = data.repairName; |
| | | form.value.remark = data.remark; |
| | | // 设置设备名称显示 |
| | |
| | | // 新增模式 |
| | | operationType.value = 'add'; |
| | | } |
| | | }; |
| | | |
| | | // 清除表单校验状态 |
| | | const clearValidate = () => { |
| | | formRef.value?.clearValidate(); |
| | | }; |
| | | |
| | | // 重置表单数据和校验状态 |
| | | const resetForm = () => { |
| | | form.value = { |
| | | deviceLedgerId: undefined, |
| | | deviceModel: undefined, |
| | | repairTime: dayjs().format("YYYY-MM-DD"), |
| | | repairName: undefined, |
| | | remark: undefined, |
| | | }; |
| | | deviceNameText.value = ''; |
| | | }; |
| | | |
| | | const resetFormAndValidate = () => { |
| | | resetForm(); |
| | | clearValidate(); |
| | | }; |
| | | |
| | | // 扫描二维码功能 |
| | |
| | | // 确认日期选择 |
| | | const onDateConfirm = (e) => { |
| | | form.value.repairTime = formatDateToYMD(e.value); |
| | | pickerDateValue.value = dayjs(e.value).format("YYYY-MM-DD"); |
| | | showDate.value = false; |
| | | }; |
| | | |
| | |
| | | const sendForm = async () => { |
| | | try { |
| | | // 手动验证表单 |
| | | await formRef.value?.validate(); |
| | | |
| | | let isValid = true; |
| | | let errorMessage = ''; |
| | | if (!form.value.deviceLedgerId) { |
| | | isValid = false; |
| | | errorMessage = '请选择设备名称'; |
| | | } else if (!form.value.repairTime || form.value.repairTime.trim() === '') { |
| | | isValid = false; |
| | | errorMessage = '请选择报修日期'; |
| | | } else if (!form.value.repairName || form.value.repairName.trim() === '') { |
| | | isValid = false; |
| | | errorMessage = '请输入报修人'; |
| | | } else if (!form.value.remark || form.value.remark.trim() === '') { |
| | | isValid = false; |
| | | errorMessage = '请输入故障现象'; |
| | | } |
| | | |
| | | if (!isValid) { |
| | | showToast(errorMessage); |
| | | return; |
| | | } |
| | | |
| | | loading.value = true; |
| | | const id = getPageId(); |
| | | |
| | | |
| | | // 准备提交数据 |
| | | const submitData = { ...form.value }; |
| | | |
| | | |
| | | const { code } = id |
| | | ? await editRepair({ id: id, ...submitData }) |
| | | : await addRepair(submitData); |
| | | |
| | | |
| | | if (code == 200) { |
| | | showToast(`${id ? "编辑" : "新增"}报修成功`); |
| | | setTimeout(() => { |
| | |
| | | |
| | | // 返回上一页 |
| | | const goBack = () => { |
| | | uni.removeStorageSync('repairId'); |
| | | uni.navigateBack(); |
| | | }; |
| | | |
| | | // 获取页面参数 |
| | | const getPageParams = () => { |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = currentPage.options; |
| | | // 使用uni.getStorageSync获取id |
| | | const id = uni.getStorageSync('repairId'); |
| | | |
| | | // 根据是否有id参数来判断是新增还是编辑 |
| | | if (options.id) { |
| | | if (id) { |
| | | // 编辑模式,获取详情 |
| | | loadForm(options.id); |
| | | loadForm(id); |
| | | // 可选:获取后清除存储的id,避免影响后续操作 |
| | | // uni.removeStorageSync('repairId'); |
| | | } else { |
| | | // 新增模式 |
| | | loadForm(); |
| | |
| | | |
| | | // 获取页面ID |
| | | const getPageId = () => { |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = currentPage.options; |
| | | return options.id; |
| | | // 使用uni.getStorageSync获取id |
| | | const id = uni.getStorageSync('repairId'); |
| | | return id; |
| | | }; |
| | | </script> |
| | | |