地址接口的视线

This commit is contained in:
czz
2025-06-21 17:55:47 +08:00
parent 41adcedad7
commit ca1995372c
16 changed files with 593 additions and 663 deletions

View File

@@ -13,17 +13,21 @@ import 'package:vbvs_app/component/img/img_preview_widget.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/mh_controller/apply_repair_controller.dart';
import 'package:vbvs_app/controller/mh_controller/repair_list_controller.dart';
import 'package:vbvs_app/controller/repair/repair_controller.dart';
import 'package:vbvs_app/model/api_response.dart';
import 'package:vbvs_app/pages/mh_page/applyRepair/apply_repair_success.dart';
class ApplyRepairPage extends GetView<ApplyRepairController> {
final scaffoldKey = GlobalKey<ScaffoldState>();
BoxConstraints? bodysize;
RepairController repairController = Get.find();
RepairListController repairListController = Get.find();
ApplyRepairController applyRepairController = Get.find();
ApplyRepairPage() {
controller.attr.value.listenlists.clear();
controller.getDeviceList();
controller.model.device_type = "";
controller.model.device_type = null;
controller.model.select_device = "";
controller.model.device_category = "";
controller.model.device_name = "";
@@ -37,9 +41,6 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
Widget build(BuildContext context) {
var tmpcontroller =
FormFieldController<String>(controller.model.select_device);
var typecontroller =
FormFieldController<String>(controller.model.device_type);
controller.model.address;
List<String> deviceTypeNames = ['', '床垫'];
List<String> deviceTypeIds = ['', '床垫'];
return LayoutBuilder(builder: (context, cc) {
@@ -259,9 +260,10 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
(val) {
var selectedDevice = controller.model.device_list!.firstWhere((device) => device['_id'].toString() == val);
controller.model.select_device = val;
controller.model.device_type = selectedDevice['type'] == 1 ? '' : '床垫';
controller.model.device_category = selectedDevice['deviceSeries']['name'] ?? '未知型号'; // 获取设备型号
controller.model.device_id = selectedDevice['mac'] ?? '未知设备ID'; // 获取设备ID
controller.model.device_type = selectedDevice['device_type'];
// controller.model.device_category = selectedDevice['deviceSeries']['name'] ?? '未知型号'; // 获取设备型号
controller.model.device_category = '未知型号';
controller.model.device_id = selectedDevice['_id'] ?? '未知设备ID'; // 获取设备ID
controller.model.device_name = selectedDevice['name'] ?? '未知设备'; // 获取设备名称
controller.updateAll();
},
@@ -373,107 +375,24 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
),
Expanded(
child: Container(
width: 100,
height: 100,
decoration:
BoxDecoration(
color: Colors
.white,
borderRadius:
BorderRadius
.circular(
8),
),
child:
TextFormField(
// autofocus: true,
onChanged:
(value) {
controller
.model
.device_type =
value;
},
obscureText:
false,
width: 100,
height: 100,
decoration:
InputDecoration(
isDense:
true,
labelStyle:
const TextStyle(
fontFamily:
'Readex Pro',
letterSpacing:
0,
),
hintStyle:
const TextStyle(
fontFamily:
'Readex Pro',
letterSpacing:
0,
),
enabledBorder:
OutlineInputBorder(
borderSide:
BorderSide(
color: const Color(
0x00000000),
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
AppConstants().normal_container_radius),
),
focusedBorder:
OutlineInputBorder(
borderSide:
BorderSide(
color: Colors
.transparent,
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
errorBorder:
OutlineInputBorder(
borderSide:
BorderSide(
//
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
focusedErrorBorder:
OutlineInputBorder(
borderSide:
BorderSide(
//
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
BoxDecoration(
color: Colors
.white,
borderRadius:
BorderRadius
.circular(8),
),
style: TextStyle(
letterSpacing:
0,
color: Colors
.black,
fontSize:
26.rpx),
),
),
child: Padding(
padding: EdgeInsets.only(left: 26.rpx),
child: Align(
alignment: Alignment.centerLeft,
child: Obx(() => Text(
getDeviceTypeName(controller.model.device_type),
style: TextStyle(fontSize: 26.rpx, color: Colors.black),
))))),
),
].divide(SizedBox(
width: 26.rpx)),
@@ -526,107 +445,24 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
),
Expanded(
child: Container(
width: 100,
height: 100,
decoration:
BoxDecoration(
color: Colors
.white,
borderRadius:
BorderRadius
.circular(
8),
),
child:
TextFormField(
// autofocus: true,
onChanged:
(value) {
controller
.model
.device_category =
value;
},
obscureText:
false,
width: 100,
height: 100,
decoration:
InputDecoration(
isDense:
true,
labelStyle:
const TextStyle(
fontFamily:
'Readex Pro',
letterSpacing:
0,
),
hintStyle:
const TextStyle(
fontFamily:
'Readex Pro',
letterSpacing:
0,
),
enabledBorder:
OutlineInputBorder(
borderSide:
BorderSide(
color: const Color(
0x00000000),
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
AppConstants().normal_container_radius),
),
focusedBorder:
OutlineInputBorder(
borderSide:
BorderSide(
color: Colors
.transparent,
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
errorBorder:
OutlineInputBorder(
borderSide:
BorderSide(
//
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
focusedErrorBorder:
OutlineInputBorder(
borderSide:
BorderSide(
//
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
BoxDecoration(
color: Colors
.white,
borderRadius:
BorderRadius
.circular(8),
),
style: TextStyle(
letterSpacing:
0,
color: Colors
.black,
fontSize:
26.rpx),
),
),
child: Padding(
padding: EdgeInsets.only(left: 26.rpx),
child: Align(
alignment: Alignment.centerLeft,
child: Obx(() => Text(
controller.model.device_category ?? '',
style: TextStyle(fontSize: 26.rpx, color: Colors.black),
))))),
),
].divide(SizedBox(
width: 26.rpx)),
@@ -679,107 +515,24 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
),
Expanded(
child: Container(
width: 100,
height: 100,
decoration:
BoxDecoration(
color: const Color(
0xFFF3F5F6),
borderRadius:
BorderRadius
.circular(
8),
),
child:
TextFormField(
// autofocus: true,
onChanged:
(value) {
controller
.model
.device_id =
value;
},
obscureText:
false,
width: 100,
height: 100,
decoration:
InputDecoration(
isDense:
true,
labelStyle:
const TextStyle(
fontFamily:
'Readex Pro',
letterSpacing:
0,
),
hintStyle:
const TextStyle(
fontFamily:
'Readex Pro',
letterSpacing:
0,
),
enabledBorder:
OutlineInputBorder(
borderSide:
BorderSide(
color: const Color(
0x00000000),
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
AppConstants().normal_container_radius),
),
focusedBorder:
OutlineInputBorder(
borderSide:
BorderSide(
color: Colors
.transparent,
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
errorBorder:
OutlineInputBorder(
borderSide:
BorderSide(
//
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
focusedErrorBorder:
OutlineInputBorder(
borderSide:
BorderSide(
//
width: 1
.rpx,
),
borderRadius:
BorderRadius.circular(
8.rpx),
),
BoxDecoration(
color: Colors
.white,
borderRadius:
BorderRadius
.circular(8),
),
style: TextStyle(
letterSpacing:
0,
color: Colors
.black,
fontSize:
26.rpx),
),
),
child: Padding(
padding: EdgeInsets.only(left: 26.rpx),
child: Align(
alignment: Alignment.centerLeft,
child: Obx(() => Text(
controller.model.device_id ?? '',
style: TextStyle(fontSize: 26.rpx, color: Colors.black),
))))),
),
].divide(SizedBox(
width: 26.rpx)),
@@ -833,21 +586,11 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
child: InkWell(
onTap: () async {
ApiResponse apiResponse =
await repairController
await applyRepairController
.uploadImg();
print(apiResponse);
if (apiResponse.code ==
HttpStatusCodes.ok) {
print(controller.model);
// setState(() {
// controller.model['path'] = apiResponse.data['path'];
// });
controller.model.issue_img!
.add(apiResponse
.data['path']);
repairController.repairList
.refresh(); // 通知 Obx 更新(如果用了 GetX
print(controller.model);
} else {
if (controller.model
.issue_img ==
@@ -1702,53 +1445,58 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
borderRadius: 16.rpx,
gradientDirection: GradientDirection.vertical,
onTap: () async {
TopSlideNotification.show(
context,
text: "功能开发中...",
);
// Get.toNamed("/applyRepairSuccess");
// String msg = checkRepairParam();
// if (msg.isNotEmpty) {
// TopSlideNotification.show(context,
// text: msg,
// textColor:
// themeController.currentColor.sc9);
// } else {
// String serviceAddress =
// ServiceConstant.service_address;
// String serviceName =
// ServiceConstant.server_service;
// String serviceApi =
// ServiceConstant.submit_repair;
// String queryUrl =
// "$serviceAddress$serviceName$serviceApi";
// var data = {
// "device": repairController.repairList.value,
// "type": repairController.device_type.value,
// "contacts": {
// "name": repairController.name.value,
// "phone": repairController.phone.value
// },
// };
// ApiResponse apiResponse = await requestWithLog(
// logTitle: "提交报修信息",
// method: MyHttpMethod.post,
// queryUrl: queryUrl,
// data: data,
// onSuccess: (res) {
// TopSlideNotification.show(context,
// text: res.msg!);
// // Get.back();
// Get.toNamed("/applyRepairSuccess");
// },
// onFailure: (res) {
// TopSlideNotification.show(context,
// text: res.msg!,
// textColor:
// themeController.currentColor.sc9);
// },
// );
//}
String msg = checkRepairParam();
if (msg.isNotEmpty) {
TopSlideNotification.show(context,
text: msg,
textColor:
themeController.currentColor.sc9);
} else {
String serviceAddress =
ServiceConstant.service_address;
String serviceName =
ServiceConstant.server_service;
String serviceApi =
ServiceConstant.submit_repair;
String queryUrl =
"$serviceAddress$serviceName$serviceApi";
var data = {
"type": controller.model.device_type,
"contacts": {
"name": controller.model.apply_name,
"phone": controller.model.tel,
},
"device": [
{
"mac": controller.model.device_id,
"desc": controller.model.desc,
"img": controller.model.issue_img,
}
],
};
ApiResponse apiResponse = await requestWithLog(
logTitle: "提交报修信息",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
TopSlideNotification.show(context,
text: res.msg!);
Get.toNamed("/applyRepairSuccess");
// repairListController.getRepairList();
},
onFailure: (res) {
TopSlideNotification.show(context,
text: res.msg!,
textColor:
themeController.currentColor.sc9);
},
);
controller.model =
ApplyRepairModel(); // 在 submitRepair 完成后执行
controller.updateAll();
}
},
colors: const [
Color(0xFFFCFCFC),
@@ -1819,61 +1567,54 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
}
String checkRepairParam() {
String errormsg = "";
String message = "";
// 检查报修项
for (var i = 0; i < repairController.repairList.length; i++) {
final item = repairController.repairList[i];
if (controller.model.device_type == null ||
controller.model.device_type == 0) {
message = '请选择设备类型!';
return message;
}
if (controller.model.device_category == null ||
controller.model.device_category!.isEmpty) {
message = '请输入设备型号!';
return message;
}
if (controller.model.device_id == null ||
controller.model.device_id!.isEmpty) {
message = '请输入设备序列号id';
return message;
}
if (controller.model.apply_name == null ||
controller.model.apply_name!.isEmpty) {
message = '请输入姓名!';
return message;
}
RegExp nameRegExp = RegExp(r'^[\u4e00-\u9fa5]{2,4}$');
if (item["path"] == null || item["path"].toString().isEmpty) {
_scrollToKey(repairItemKeys[i]);
// return "第 ${i + 1} 项图片未上传";
return "图片未上传".tr;
}
if (item["id"] == null || item["id"].toString().isEmpty) {
_scrollToKey(repairItemKeys[i]);
// return "第 ${i + 1} 项设备未选择";
return "设备未选择".tr;
}
if (item["param"] == null || item["param"].toString().isEmpty) {
_scrollToKey(repairItemKeys[i]);
// return "第 ${i + 1} 项参数未填写";
return "参数未填写".tr;
}
if (item["issue"] == null || item["issue"].toString().isEmpty) {
_scrollToKey(repairItemKeys[i]);
// return "第 ${i + 1} 项问题描述未填写";
return "问题描述未填写".tr;
}
if (item["issue"] != null && item["issue"].toString().trim().isNotEmpty) {
final issueText = item["issue"].toString().trim();
final charCount = issueText.runes.length;
if (!nameRegExp.hasMatch(controller.model.apply_name!)) {
message = '姓名必须为2到4个汉字';
if (charCount > 60) {
_scrollToKey(repairItemKeys[i]);
return "问题描述最多输入60个字".tr;
}
} else {
_scrollToKey(repairItemKeys[i]);
return "问题描述不能为空".tr;
}
return message;
}
if (controller.model.tel == null || controller.model.tel!.isEmpty) {
message = '请输入手机号!';
return message;
}
if (!MyUtils.isValidPhoneNumber(controller.model.tel!)) {
message = '无效的手机号!';
return message;
}
// 检查联系人
if (repairController.name.trim().isEmpty) {
_scrollToKey(contactKey);
return "联系人不能为空".tr;
if (controller.model.desc == null || controller.model.desc!.isEmpty) {
message = '请输入问题描述!';
return message;
}
if (repairController.phone.trim().isEmpty) {
_scrollToKey(phoneKey);
return "联系电话不能为空".tr;
if (controller.model.issue_img == null ||
controller.model.issue_img!.isEmpty) {
message = '请至少上传一张问题图片!';
return message;
}
if (!MyUtils.isValidPhoneNumber(repairController.phone.trim())) {
_scrollToKey(phoneKey);
return "无效的手机号码".tr;
}
return errormsg;
return message;
}
// 新增滚动方法
@@ -1886,4 +1627,18 @@ class ApplyRepairPage extends GetView<ApplyRepairController> {
);
});
}
String getDeviceTypeName(int? type) {
if (type == null) return '';
switch (type) {
case 1:
return '体征检测设备';
case 2:
return '智能床';
case 3:
return '智能床垫';
default:
return '未知设备';
}
}
}