|
@@ -1,68 +1,40 @@
|
|
|
//设备点检
|
|
|
import ProcessRequest from '../common/util/request/ProcessRequest'
|
|
|
-import DeviceInfo from '../viewmodel/DeviceInfo'
|
|
|
-import RequestParamModel from '../viewmodel/RequestParamModel'
|
|
|
-import TimeUtil from "../common/util/TimeUtil"
|
|
|
-import PageInfo from '../viewmodel/PageInfo'
|
|
|
+import ProcessDeviceDailyCheck from '../viewmodel/process/ProcessDeviceDailyCheck'
|
|
|
+import DictValue from '../viewmodel/DictValue'
|
|
|
+import promptAction from '@ohos.promptAction'
|
|
|
+import HashMap from '@ohos.util.HashMap'
|
|
|
+
|
|
|
|
|
|
-//todo 需要后端接口
|
|
|
@CustomDialog
|
|
|
-export struct EquipmentInspectionDialog {
|
|
|
+export struct DeviceInspectionDialog {
|
|
|
private scrollerDevice: Scroller = new Scroller()
|
|
|
//查找设备编码
|
|
|
- @State queryDeviceNo:string = ''
|
|
|
+ @State queryDeviceNo: string = 'KLA-METRO01'
|
|
|
//当前日期
|
|
|
@State currentDate: string = ''
|
|
|
- //设备列表
|
|
|
- @State devicesList: DeviceInfo[] = [
|
|
|
- ];
|
|
|
+ // 设备点检列表
|
|
|
+ @Link deviceChecks: ProcessDeviceDailyCheck[]
|
|
|
//选中设备索引
|
|
|
- @State selectDeviceIndex:number=-1
|
|
|
+ @State selectDeviceIndex: number=-1
|
|
|
+ // 设备类型(key为数据字典值,value为数据字典标签)
|
|
|
+ @State deviceTypes: HashMap<string, string> = new HashMap()
|
|
|
+ @Consume('stationIp') stationIp: string
|
|
|
controller: CustomDialogController
|
|
|
onConfirm: () => void = () => {}
|
|
|
|
|
|
- onQueryDeviceCode = async ()=> {
|
|
|
- let res = await ProcessRequest.post('/api/v1/device/page', {
|
|
|
- deviceNo: this.queryDeviceNo
|
|
|
- } as RequestParamModel) as PageInfo;
|
|
|
- this.devicesList = res.records as DeviceInfo[] || []
|
|
|
- }
|
|
|
-
|
|
|
- //当前日期
|
|
|
- updateCurrentDate() {
|
|
|
- const now = new Date()
|
|
|
- const year = now.getFullYear()
|
|
|
- const month = (now.getMonth() + 1).toString().padStart(2, '0')
|
|
|
- const day = now.getDate().toString().padStart(2, '0')
|
|
|
- this.currentDate = `${year}/${month}/${day}`
|
|
|
- }
|
|
|
+ deviceTypeDictCode: string = 'device_type'
|
|
|
|
|
|
- //对比当前日期和有效期
|
|
|
- private compareDates(currentDate: string, targetDate: string): number {
|
|
|
- if (!targetDate) return -1; // 无效日期视为已过期
|
|
|
- const normalizeDate = (dateStr: string) => {
|
|
|
- let result = dateStr.split('/').join('-');
|
|
|
- result = result.split('年').join('-')
|
|
|
- .split('月').join('-')
|
|
|
- .split('日').join('-');
|
|
|
- return result;
|
|
|
- };
|
|
|
- try {
|
|
|
- const current = new Date(normalizeDate(currentDate));
|
|
|
- const target = new Date(normalizeDate(targetDate));
|
|
|
- if (isNaN(current.getTime()) || isNaN(target.getTime())) {
|
|
|
- return -1;
|
|
|
+ async aboutToAppear() {
|
|
|
+ let deviceDicts: DictValue[] = await ProcessRequest.get(`/api/v1/sys/dictData/queryByType/${this.deviceTypeDictCode}`)
|
|
|
+ if (deviceDicts) {
|
|
|
+ for (const dict of deviceDicts) {
|
|
|
+ console.log('hhtest', JSON.stringify(dict))
|
|
|
+ this.deviceTypes.set(dict.dictValue!, dict.dictLabel!);
|
|
|
}
|
|
|
- return target.getTime() - current.getTime();
|
|
|
- } catch (e) {
|
|
|
- return -1; // 日期解析异常视为已过期
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- aboutToAppear(): void {
|
|
|
- this.updateCurrentDate();
|
|
|
- this.onQueryDeviceCode();
|
|
|
- }
|
|
|
build() {
|
|
|
Column() {
|
|
|
Column() {
|
|
@@ -95,8 +67,21 @@ export struct EquipmentInspectionDialog {
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.enableKeyboardOnFocus(false)
|
|
|
- .onSubmit(() => {
|
|
|
- this.onQueryDeviceCode()
|
|
|
+ .onSubmit(async () => {
|
|
|
+ if (this.deviceChecks) {
|
|
|
+ for (const element of this.deviceChecks) {
|
|
|
+ if (element.deviceNo === this.queryDeviceNo) {
|
|
|
+ promptAction.showToast({
|
|
|
+ message: `设备今日已点检,无需重复点检!`,
|
|
|
+ duration: 1500,
|
|
|
+ bottom: 100
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let check: ProcessDeviceDailyCheck = await ProcessRequest.get(`/api/v1/process/equipDailyCheck/getServiceLifeByDeviceNo/${this.queryDeviceNo}`)
|
|
|
+ this.deviceChecks.unshift(check)
|
|
|
})
|
|
|
.onChange((value: string) => {
|
|
|
this.queryDeviceNo = value;
|
|
@@ -116,19 +101,19 @@ export struct EquipmentInspectionDialog {
|
|
|
.width('50%')
|
|
|
.margin({bottom:'1%',top:'1%'})
|
|
|
List({scroller: this.scrollerDevice }) {
|
|
|
- ForEach(this.devicesList, (item: DeviceInfo, index) => {
|
|
|
+ ForEach(this.deviceChecks, (item: ProcessDeviceDailyCheck, index) => {
|
|
|
ListItem() {
|
|
|
Row() {
|
|
|
Column(){
|
|
|
- Text(`${item.deviceName}`)
|
|
|
+ Text(`${item.deviceName!}`)
|
|
|
.fontSize($r('app.float.fontSize_24'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
- Text(`型号:${item.deviceType}`)
|
|
|
+ Text('型号:' + (this.deviceTypes && item.deviceType && this.deviceTypes.hasKey(item.deviceType) ? this.deviceTypes.get(item.deviceType) : ''))
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
|
.margin({top:'2%',bottom:'1%'})
|
|
|
- Text(`设备编码:${item.deviceNo}`)
|
|
|
+ Text(`设备编码:${item.deviceNo!}`)
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -144,19 +129,13 @@ export struct EquipmentInspectionDialog {
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
|
Row(){
|
|
|
- Image(this.compareDates(this.currentDate, item.meteringDate) > 0
|
|
|
- ?$r('app.media.device_normal') :$r('app.media.device_expire')
|
|
|
- )
|
|
|
+ Image(item.meteringState! === 1 ? $r('app.media.device_normal') : $r('app.media.device_expire'))
|
|
|
.width($r('app.float.virtualSize_24'))
|
|
|
.height($r('app.float.virtualSize_24'))
|
|
|
.margin({left:'2%'})
|
|
|
- Text(`${item.meteringDate}`)
|
|
|
+ Text(item.meteringDate ? `${item.meteringDate}` : '长期有效')
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
- .fontColor(
|
|
|
- this.compareDates(this.currentDate, item.meteringDate) > 0
|
|
|
- ? $r('app.color.30D158') // 有效期未过(绿色)
|
|
|
- : $r('app.color.FF453A') // 已过期(红色)
|
|
|
- )
|
|
|
+ .fontColor(item.meteringState! === 1 ? $r('app.color.30D158') : $r('app.color.FF453A'))
|
|
|
.margin({left:'2%'})
|
|
|
}
|
|
|
.width('65%')
|
|
@@ -175,19 +154,13 @@ export struct EquipmentInspectionDialog {
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
|
Row(){
|
|
|
- Image(this.compareDates(this.currentDate, item.updated) > 0
|
|
|
- ?$r('app.media.device_normal') :$r('app.media.device_expire')
|
|
|
- )
|
|
|
+ Image(item.warrantyState! === 1 ? $r('app.media.device_normal') :$r('app.media.device_expire'))
|
|
|
.width($r('app.float.virtualSize_24'))
|
|
|
.height($r('app.float.virtualSize_24'))
|
|
|
.margin({left:'2%'})
|
|
|
- Text(`${item.updated}`)
|
|
|
+ Text(item.warrantyPeriod ? `${item.warrantyPeriod}` : '长期有效')
|
|
|
.fontSize($r('app.float.fontSize_16'))
|
|
|
- .fontColor(
|
|
|
- this.compareDates(this.currentDate, item.updated) > 0
|
|
|
- ? $r('app.color.30D158')
|
|
|
- : $r('app.color.FF453A')
|
|
|
- )
|
|
|
+ .fontColor(item.warrantyState! === 1 ? $r('app.color.30D158') : $r('app.color.FF453A'))
|
|
|
.margin({left:'2%'})
|
|
|
}
|
|
|
.width('65%')
|
|
@@ -206,7 +179,7 @@ export struct EquipmentInspectionDialog {
|
|
|
.height($r('app.float.virtualSize_48'))
|
|
|
.fillColor($r('app.color.FF453A'))
|
|
|
.onClick(()=>{
|
|
|
- this.devicesList.splice(index, 1);
|
|
|
+ this.deviceChecks.splice(index, 1);
|
|
|
})
|
|
|
}
|
|
|
.width('10%')
|
|
@@ -258,7 +231,14 @@ export struct EquipmentInspectionDialog {
|
|
|
}
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
.width('50%')
|
|
|
- .onClick(() => {
|
|
|
+ .onClick(async () => {
|
|
|
+ if (!this.deviceChecks || this.deviceChecks.length <= 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for (const check of this.deviceChecks) {
|
|
|
+ check.stationIp = this.stationIp
|
|
|
+ }
|
|
|
+ await ProcessRequest.post('/api/v1/process/equipDailyCheck/batchSave', this.deviceChecks)
|
|
|
this.controller.close();
|
|
|
})
|
|
|
}
|