import { JudgeConfig } from '../../judgeSDK/utils/judgeConfig'; import common from '@ohos.app.ability.common'; import VoiceAnnounce from '../../judgeSDK/utils/voiceAnnouncements'; import { MarkRule } from '../../judgeSDK/api/judgeSDK.d'; import { writeObjectOut } from '../../../api/judge'; import JudgeTask from '../../judgeSDK/utils/judgeTask'; import FilePhoto from '../../judgeSDK/utils/filePhoto'; import { CarInfoType, MASYSSETTableType, RegulatoryInterfaceParams, User } from '../../../model'; import { GetCurrentTime } from '../../../utils/Common'; import FileUtils from '../../../utils/FileUtils'; import { GetSyncData } from '../../../utils/table/Operation'; interface SEL { fontColor: string bgColor: string } interface kfdmItemType { xmdm: number, kfdm: string, markreal: number, markcatalog: string score: number } //考前模拟人工扣分 @Component export default struct DeductedPopup { @State name: string = '' @State idCard: string = '' @State lsh: string = '' @State kszp: string = '' @State ksdd: string = '' @State kssycs: string = '' @State kslx: string = '' @State ksxl: string = '' @State score: number = 100; @State judgeConfigObj: Record = {} @State kfdmArr: kfdmItemType[] = [] //开始考试前判绕车一周评判是否开启 @State isOpen: boolean = false //监管序列号 @State serialNumber: number = 0; @State examSubject: number = 2; @State markRuleListObj: MarkRule = {} @State fontSize: number = 28 @State unselected: SEL = { fontColor: '#000000', bgColor: '#CCC4B8' } @State selected: SEL = { fontColor: '#FFAD33', bgColor: '#26231E' } @State currentIndex: number = 0 @State currentPageIndex: number = 0 //通用评判扣分 @State currentUniversalPageIndex: number = 0; @State universalMarkRules: MarkRule[] = [] @State manualMarkRules: MarkRule[] = [] @State lineBg: Array = ['#4D4136', '#26231E'] @State selectedLine: number = -1 @State carInfo: CarInfoType = { carId: '', examinationRoomId: '', plateNo: '', isNeedCheck: '', examSubject: '', } @State singlePlay: boolean = false @State selectedLineStyle: SEL = { fontColor: '#FFF', bgColor: '#B36E00' } private context = getContext(this) as common.UIAbilityContext; private judgeTask!: JudgeTask private filePhoto!: FilePhoto // 过程照片拍照 getPhoto = async (empty?: boolean) => { //单机模式返回空照片 if (this.singlePlay) { return '' } else { const photoBase64: string = await this.filePhoto.getPhoto() || ""; return photoBase64 } } private avPlayer!: VoiceAnnounce async aboutToAppear() { this.carInfo = AppStorage.get('carInfo')! this.singlePlay = AppStorage.get('singlePlay')! this.avPlayer = new VoiceAnnounce(this.context); this.judgeTask = new JudgeTask(); const mediaTest = new FilePhoto(this.context); this.filePhoto = mediaTest //上车准备 // this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+'')) // const { isTrajectoryOpen } = judgeConfig; if (JudgeConfig.isTrajectoryOpen) { await this.initDb() } else { await this.initSysset() await this.initMarkRules() await this.initStudent() } // const {judgeTask} = this; // judgeTask.addTask(async () => { // await this.beginProject(); // }, { isDelay: true }) // judgeTask.addTask(async () => { // await this.uploadProgressPhoto(); // }, { isDelay: true }) } //本地数据初始化 async initDb() { // const { isTrajectoryOpen, trajectoryPath } = judgeConfig const examSubject = this.carInfo.examSubject; //轨迹回放读取 systemparam表、markrule表 const fileUtil = new FileUtils(this.context); const folderPath = await fileUtil.initFolder(JudgeConfig.trajectoryPath); const str = await fileUtil.readFile(folderPath); const strArr = str.split('\n'); // const [initData, beginData] = [strArr[0], strArr[1]]; const initData = strArr[0]; const beginData = strArr[1]; // TODO 补全类型 const initDataObj: ESObject = JSON.parse(initData); this.examSubject = Number(JudgeConfig.isTrajectoryOpen ? (initDataObj.kskm * 1) : examSubject); await this.initMarkRules(initDataObj.mark); await this.initSysset(initDataObj.sysset); await this.initStudent() } // 扣分操作 async pointsDedute() { const index = this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex; const mark = this.universalMarkRules[index * 7 + this.selectedLine]; // const { judgeConfigObj, kssycs, avPlayer, judgeTask } = this; this.kfdmArr.push({ xmdm: 1, kfdm: mark.markserial || "", markreal: mark.markreal || 0, markcatalog: mark.markcatalog || "", score: mark.score || 0 }) const kfdmArr = this.kfdmArr //计算总扣分 let score = kfdmArr.reduce((p, n) => { p += n.markreal * 1 return p }, 0); this.score = score // this.confirmMark(this.kfdmArr.map((kf) => ({ // xmdm: kf.xmdm.toString(), // kfdm: kf.kfdm, // }))) if (this.judgeConfigObj['418'] == '1' || JudgeConfig.kfVoiceOpen) { this.avPlayer.playAudio([`voice/${mark.markcatalog}.mp3`, `voice/mark_${Math.abs(mark.score!)}.mp3`], false, () => { this.closePopup(true) }); return } this.closePopup(); return; } //项目开始 async beginProject() { //项目开始 //过程照片 //扣分 //结束考试 // const carInfo: CarInfoType = this.carInfo; // const { examSubject, plateNo } = carInfo; // const { serialNumber, lsh, idCard, ksxl, kslx, ksdd } = this const time = GetCurrentTime(); const beginData: RegulatoryInterfaceParams = { xtlb: '17', jkxlh: this.serialNumber.toString(), jkid: '17C52', drvexam: { // 考试科目 身份证号码 lsh: this.lsh, kskm: this.carInfo.examSubject, sfzmhm: this.idCard, ksxm: '40100', ksxl: this.ksxl, kchp: decodeURI(this.carInfo.plateNo || ""), ksdd: decodeURI(this.ksdd), kslx: decodeURI(this.kslx) || '', kssj: time }, } const code = await writeObjectOut(beginData) //TODO code待处理 // if (code == 1) { // // } } //过程照片 async uploadProgressPhoto() { // const { serialNumber, lsh, idCard, ksdd, kfdmArr, getPhoto } = this; // const carInfo = this.carInfo; // const { examSubject, plateNo, carNo } = carInfo; const time = GetCurrentTime(); console.info('surenjun uploadProgressPhoto',) const photoBase64 = await this.getPhoto() const photoData: RegulatoryInterfaceParams = { xtlb: '17', jkxlh: this.serialNumber.toString(), jkid: '17C54', drvexam: { lsh: this.lsh, kskm: this.carInfo.examSubject, ksxm: '40100', sfzmhm: this.idCard, kchp: decodeURI(this.carInfo.plateNo || ""), zpsj: time, // zp: encodeURIComponent(photoBase64), zp: photoBase64, cs: 0, ksdd: decodeURI(this.ksdd) } }; const code = await writeObjectOut(photoData); console.info('surenjun uploadProgressPhoto end',) } // 扣分 async kfFn() { const kfLen = this.kfdmArr.length; const kf = this.kfdmArr[kfLen -1]; const time = GetCurrentTime(); const kfData: RegulatoryInterfaceParams = { xtlb: '17', jkxlh: this.serialNumber.toString(), jkid: '17C53', drvexam: { lsh: this.lsh, kskm: this.carInfo.examSubject, // 通用评判科二10000,科三30000 ksxm: "40100", kfxm: kf.markcatalog, kfxmmx: `${'1'},${kf.kfdm}`, sfzmhm: this.idCard, kchp: decodeURI(this.carInfo.plateNo || ""), kffs: 2, ksdd: decodeURI(this.ksdd), kfsj: time } } const code = await writeObjectOut(kfData); } // 项目结束 async endProject() { const time = GetCurrentTime(); const endProjectData: RegulatoryInterfaceParams = { xtlb: '17', jkxlh: this.serialNumber.toString(), jkid: '17C55', drvexam: { lsh: this.lsh, kskm: this.carInfo.examSubject, sfzmhm: this.idCard, ksxm: '40100', czlx: '1', ksxl: this.ksxl, kchp: decodeURI(this.carInfo.plateNo || ""), ksdd: decodeURI(this.ksdd), kslx: encodeURI(this.kslx) || '', jssj: time } } const code = await writeObjectOut(endProjectData); } //考试结束 async endFn() { const time = GetCurrentTime(); const photoBase64 = await this.getPhoto() const endData: RegulatoryInterfaceParams = { xtlb: '17', jkxlh: this.serialNumber.toString(), jkid: '17C56', drvexam: { lsh: this.lsh, kchp: decodeURI(this.carInfo.plateNo || ""), kskm: this.carInfo.examSubject, sfzmhm: this.idCard, // zp: encodeURIComponent(photoBase64), zp: photoBase64, jssj: time, kscj: (this.score * 1) > 0 ? this.score : 0, kslc: 0, dwlc: '', } } const code = await writeObjectOut(endData); } //获取sysset表数据 async initSysset(sysset?: MASYSSETTableType[]) { const syssetParams = sysset || await GetSyncData('MA_SYSSET'); console.info('surenjun syssetParams', JSON.stringify(syssetParams)); syssetParams.forEach(sys => { //监管序列号 if (sys.v_no == '901') { this.serialNumber = Number(sys.v_value) || 123456 } //364 绕车一周评判时机(1-开始考试后判 2-开始考试前判) if (sys.v_no == '364') { const isOpen = sys.v_value == "2" if (isOpen) { this.avPlayer.playAudio(['voice/上车准备.mp3']) } } if (sys.v_no) { this.judgeConfigObj[sys.v_no] = decodeURIComponent(sys.v_value || ''); } }) } //获取markrule表数据 async initMarkRules(markRules ?: MarkRule[]) { const markRuleParams = markRules || (await GetSyncData('MA_MARKRULE') as MarkRule[]) markRuleParams.forEach(mark => { const tempObj: MarkRule = { itemno: Number(mark.itemno), markcatalog: mark.markcatalog, markshow: decodeURI(mark.markshow || ""), markreal: Number(mark.markreal), markstandard: Number(mark.markstandard), markserial: mark.markserial, kfxh: mark.kfxh, OnlyOneKind: Number(mark.onlyoneid), NoCancelId: Number(mark.nocancelid), GPS_SID: mark.gps_sid == 0 ? false : true } if (mark.itemno == 1 && Number(mark.markserial) > 100 && Number(mark.markserial) < 200) { this.markRuleListObj[`${mark.itemno}_${mark.markserial}`] = { itemno: tempObj.itemno, markcatalog: tempObj.markcatalog, markshow: tempObj.markshow, markreal: tempObj.markreal, markstandard: tempObj.markstandard, markserial: mark.markserial, kfxh: tempObj.kfxh, OnlyOneKind: tempObj.OnlyOneKind, NoCancelId: tempObj.NoCancelId, GPS_SID: tempObj.GPS_SID, }; this.universalMarkRules.push(tempObj) } }) } // 获取考生信息 async initStudent() { const students = await GetSyncData('USER') const stuInfo: User = students[0]; // const { xm, sfzmhm, lsh, kszp, ksdd, kssycs, kslx, ksxl } = stuInfo; this.name = stuInfo.xm || '测试考生'; this.idCard = stuInfo.sfzmhm || '01234567891010'; this.lsh = stuInfo.lsh; this.kszp = stuInfo.kszp; this.ksdd = stuInfo.ksdd; this.kssycs = stuInfo.kssycs; this.kslx = stuInfo.kslx || ""; this.ksxl = stuInfo.ksxl; } //上一页 下一页 goPage(typeIndex: number) { const currentIndex = this.currentIndex if (currentIndex) { //通用评判 typeIndex ? (this.currentUniversalPageIndex += 1) : (this.currentUniversalPageIndex -= 1) } else { typeIndex ? (this.currentPageIndex += 1) : (this.currentPageIndex -= 1) } this.selectedLine = -1 } //选中扣分项 getSelectedLine(index: number) { if (this.selectedLine === index) { return this.selectedLineStyle.bgColor } if (index % 2 === 0) { return this.lineBg[0] } else { return this.lineBg[1] } } //获取当前页的数据 getCurrentMarkRuleList() { if (this.currentIndex) { //通用评判 return this.universalMarkRules.slice(this.currentUniversalPageIndex * 7, (this.currentUniversalPageIndex + 1) * 7) } else { return this.universalMarkRules.slice(this.currentPageIndex * 7, (this.currentPageIndex + 1) * 7) } } build() { Column() { Column() { Column() { Row() { Row() { ForEach(['人工评判'], (text: string, index) => { Row() { Text(text) .fontColor(index === this.currentIndex ? this.selected.fontColor : this.unselected.fontColor) .fontSize(this.fontSize) .fontWeight(500) } .width(180) .height(70) .backgroundColor(index === this.currentIndex ? this.selected.bgColor : this.unselected.bgColor) .justifyContent(FlexAlign.Center) .justifyContent(FlexAlign.Center) .borderRadius({ topLeft: 20, topRight: 20 }) .margin({ right: 10 }) .onClick(() => { this.currentIndex = index; this.selectedLine = -1; // if(index === 1) { // this.universalMarkRules = this.markRules.filter(item => item.itemno == 20 ) // }else{ // this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+'')) // } }) }) } Row() { if ( (Math.ceil(this.universalMarkRules.length / 7 - 1)) >= (this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex) && (this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex) > 0 ) { Row() { Row() { }.width(40).height(36).backgroundImage($rawfile(`judge/km3/zuo_nor.png`)).margin({ left: 24, top: 4 }) Text('上一页') { }.fontColor('#FFF').fontSize(this.fontSize) } .width(160) .height(80) .justifyContent(FlexAlign.Start) .alignItems(VerticalAlign.Center) .backgroundImage($rawfile(`judge/km3/button_nor.png`)) .backgroundImageSize({ width: '100%', height: '100%' }) .onClick(() => { this.goPage(0) }) } if ( (Math.ceil(this.universalMarkRules.length / 7 - 1)) > (this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex) ) { Row() { Text('下一页') { }.fontColor('#FFF').fontSize(this.fontSize).padding({ left: 30 }) Row() { }.width(40).height(36).backgroundImage($rawfile(`judge/km3/you_nor.png`)).margin({ left: 4, top: 4 }) } .width(160) .height(80) .justifyContent(FlexAlign.Start) .alignItems(VerticalAlign.Center) .backgroundImage($rawfile(`judge/km3/button_nor.png`)) .backgroundImageSize({ width: '100%', height: '100%' }) .onClick(() => { this.goPage(1) }) } Row() { Text('扣 分') { }.fontColor('#FFF').fontSize(this.fontSize).padding({ left: 49 }) } .width(180) .height(80) .justifyContent(FlexAlign.Start) .alignItems(VerticalAlign.Center) .backgroundImage($rawfile(`judge/km3/button_nor.png`)) .backgroundImageSize({ width: '100%', height: '100%' }) .onClick(async () => { this.pointsDedute() }) } }.width('100%').justifyContent(FlexAlign.SpaceBetween) Column() { ForEach(this.getCurrentMarkRuleList(), (item: MarkRule, index) => { Row() { Text(`${item.markshow} (${item.markcatalog})`).fontColor('#FFF').fontSize(this.fontSize).fontWeight(500) Row() { Text(item.markreal + '').fontColor('#FFF').fontSize(this.fontSize).fontWeight(500) } } .width('100%') .height(75) .justifyContent(FlexAlign.SpaceBetween) .alignItems(VerticalAlign.Center) .padding({ left: 20, right: 20 }) .backgroundColor(this.getSelectedLine(index)) .onClick(() => { this.selectedLine = index }) }) } } } .width(1300) .height(710) .position({ x: '10%', y: '10%' }) .backgroundColor('#E6E3DF') .padding({ top: 15, bottom: 15, left: 25, right: 25 }) .borderRadius(20) Row() { } .width(100) .height(100) .position({ y: '85%', x: '50%' }) .backgroundImage($rawfile('judge/km3/close_nor.png')) .backgroundImageSize({ width: '100%', height: '100%' }) .onClick(async () => { //没有扣分项目通过 this.closePopup(this.kfdmArr.length ? true : false) // judgeTask.addTask(async () => { // await this.endProject() // }, { isDelay: true }) }) }.width('100%').height('100%').position({ y: 0 }).backgroundColor('rgba(0,0,0,0.7)') } private closePopup: Function = () => { } private confirmMark: Function = (itemno: number, serial: string) => { } private endLoading: Function = () => { } }