import { getSyncData } from '../../../common/service/initable'; import { judgeConfig } from '../../judgeSDK/utils/judgeConfig'; import FileUtil from '../../../common/utils/File'; import common from '@ohos.app.ability.common'; import VoiceAnnounce from '../../judgeSDK/utils/voiceAnnouncements'; import { getCurrentTime } from '../../../common/utils/tools'; import { MarkRule, SYSSET } from '../../judgeSDK/api/judgeSDK.d'; import { uploadExamProgressData, writeObjectOut } from '../../../api/judge'; import JudgeTask from '../../judgeSDK/utils/judgeTask'; import FilePhoto from '../../judgeSDK/utils/filePhoto'; interface SEL { fontColor: string bgColor: string } //考前模拟人工扣分 @Component export default struct DeductedPopup { private context = getContext(this) as common.UIAbilityContext; private judgeTask: JudgeTask private filePhoto: FilePhoto private avPlayer @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: { [k: string]: any } = {} @State kfdmArr: { xmdm: number, kfdm: string, markreal: number, markcatalog: string score:number }[] = [] //开始考试前判绕车一周评判是否开启 @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 = undefined private closePopup: Function = () => { } private confirmMark: Function = (itemno: number, serial: string) => { } private endLoading: Function = () => { } @State selectedLineStyle: SEL = { fontColor: '#FFF', bgColor: '#B36E00' } async aboutToAppear() { this.avPlayer = new VoiceAnnounce(); 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 (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 = globalThis.carInfo.examSubject; //轨迹回放读取 systemparam表、markrule表 const fileUtil = new FileUtil(this.context); const folderPath = await fileUtil.initFolder(trajectoryPath); const str = await fileUtil.readFile(folderPath); const strArr = str.split('\n'); const [initData, beginData] = [strArr[0], strArr[1]]; const initDataObj = JSON.parse(initData); this.examSubject = isTrajectoryOpen ? (initDataObj.kskm * 1) : examSubject; await this.initMarkRules(initDataObj.mark); await this.initSysset(initDataObj.sysset); await this.initStudent() } // 过程照片拍照 getPhoto = async (empty?: boolean) => { const singlePlay = globalThis.singlePlay //单机模式返回空照片 if (singlePlay) { return '' } else { const {filePhoto} = this; const photoBase64 = await filePhoto.getPhoto(); return photoBase64 } } // 扣分操作 async pointsDedute() { const singlePlay = globalThis.singlePlay 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, markcatalog: mark.markcatalog , score:mark.score }) 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, kfdm: kf.kfdm, }))) if (judgeConfigObj['418'] == '1' || judgeConfig.kfVoiceOpen) { avPlayer.playAudio([`voice/${mark.markcatalog}.mp3`,`voice/mark_${Math.abs(mark.score)}.mp3`], false, () => { this.closePopup(true) }); return } this.closePopup(); return; if (score < 90) { this.closePopup(true) avPlayer.playAudio(['voice/exam_waiting.mp3', `voice/kfdesc.mp3`]) judgeTask.addTask(async () => { //扣分 await this.kfFn(); }, { isDelay: true }) judgeTask.addTask(async () => { //项目结束 await this.endProject(); }, { isDelay: true }) judgeTask.addTask(async () => { //结束考试 await this.endFn() }, { isDelay: true }) } ; let voiceURL = score < 90 ? `voice/${kssycs == '1' ? 'exam_no_pass_finish' : 'exam_no_pass'}.mp3` : 'voice/exam_pass.mp3' let kfScore = 0; if (kfdmArr.length) { kfdmArr.forEach((kf, index) => { kfScore += Math.abs(Number(kf.markreal)); if (kfScore <= 100) { judgeTask.addTask(() => { if (index === kfdmArr.length - 1) { avPlayer.playAudio([`voice/${kf.markcatalog}.mp3`, voiceURL], false, () => { this.endLoading(true) }) } else { avPlayer.playAudio([`voice/${kf.markcatalog}.mp3`]) } }) } }) } this.confirmMark(this.kfdmArr.map((kf) => ({ xmdm: kf.xmdm, kfdm: kf.kfdm, }))) } //项目开始 async beginProject() { //项目开始 //过程照片 //扣分 //结束考试 const carInfo = globalThis.carInfo; const { examSubject,plateNo } = carInfo; const {serialNumber,lsh,idCard,ksxl,kslx,ksdd} = this const time = await getCurrentTime(); const beginData = { xtlb: '17', jkxlh: serialNumber, jkid: '17C52', drvexam: { // 考试科目 身份证号码 lsh, kskm: examSubject, sfzmhm: idCard, ksxm: '40100', ksxl, kchp: decodeURI(plateNo), ksdd: decodeURI(ksdd), kslx: decodeURI(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 = globalThis.carInfo; const { examSubject,plateNo,carNo } = carInfo; const time = await getCurrentTime(); console.info('surenjun uploadProgressPhoto',) const photoBase64 = await getPhoto() const photoData = { xtlb: '17', jkxlh: serialNumber, jkid: '17C54', drvexam: { lsh, kskm: examSubject, ksxm: '40100', sfzmhm: idCard, kchp: decodeURI(plateNo), zpsj: time, //@ts-ignore // zp: encodeURIComponent(photoBase64), zp: photoBase64, cs: 0, ksdd: decodeURI(ksdd) } }; const code = await writeObjectOut(photoData); console.info('surenjun uploadProgressPhoto end',) } // 扣分 async kfFn() { const {serialNumber,lsh,idCard,ksdd,kfdmArr} = this; const kfLen = kfdmArr.length; const kf = kfdmArr[kfLen -1]; const carInfo = globalThis.carInfo; const { examSubject} = carInfo; const time = await getCurrentTime(); const kfData = { xtlb: '17', jkxlh: serialNumber, jkid: '17C53', drvexam: { lsh, kskm: examSubject, // 通用评判科二10000,科三30000 ksxm: 40100, kfxm: kf.markcatalog, kfxmmx: `${'1'},${kf.kfdm}`, sfzmhm: idCard, kchp: decodeURI(carInfo.plateNo), kffs: 2, ksdd: decodeURI(ksdd), kfsj: time } } const code = await writeObjectOut(kfData); } // 项目结束 async endProject() { const carInfo = globalThis.carInfo; const { examSubject,plateNo,carNo } = carInfo; const {lsh,idCard,serialNumber,ksdd,kslx,ksxl,} = this; const time = await getCurrentTime(); const endProjectData = { xtlb: '17', jkxlh: serialNumber, jkid: '17C55', drvexam: { lsh, kskm: examSubject, sfzmhm: idCard, ksxm: '40100', czlx: '1', ksxl, kchp: decodeURI(plateNo), ksdd: decodeURI(ksdd), kslx: encodeURI(kslx) || '', jssj: time } } const code = await writeObjectOut(endProjectData); } //考试结束 async endFn() { const {serialNumber,lsh,idCard,score,getPhoto} = this; const carInfo = globalThis.carInfo; const { examSubject,plateNo } = carInfo; const time = await getCurrentTime(); const photoBase64 = await getPhoto(); const endData = { xtlb: '17', jkxlh: serialNumber, jkid: '17C56', drvexam: { lsh, kchp: decodeURI(plateNo), kskm: examSubject, sfzmhm: idCard, //@ts-ignore // zp: encodeURIComponent(photoBase64), zp: photoBase64, jssj: time, kscj: (score * 1) > 0 ? score : 0, kslc: 0, dwlc: '', } } const code = await writeObjectOut(endData); } //获取sysset表数据 async initSysset(sysset?: SYSSET[]) { const syssetParams = sysset || await getSyncData('MA_SYSSET'); console.info('surenjun syssetParams', JSON.stringify(syssetParams)); //@ts-ignore syssetParams.forEach(sys => { //监管序列号 if (sys.v_no == '901') { this.serialNumber = 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']) } } 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 = { itemno: mark.itemno * 1, markcatalog: mark.markcatalog, markshow: decodeURI(mark.markshow), markreal: mark.markreal * 1, markstandard: mark.markstandard * 1, markserial: mark.markserial, kfxh: mark.kfxh, OnlyOneKind: mark.onlyoneid * 1, NoCancelId: mark.nocancelid * 1, 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}`] = { ...tempObj, markserial: mark.markserial, }; this.universalMarkRules.push(tempObj) } }) } // 获取考生信息 async initStudent() { const students = await getSyncData('USER') const stuInfo = students[0] || {}; const {xm,sfzmhm,lsh,kszp,ksdd,kssycs,kslx,ksxl} = stuInfo; this.name = xm || '测试考生'; this.idCard = sfzmhm || '01234567891010'; this.lsh = lsh; this.kszp = kszp; this.ksdd = ksdd; this.kssycs = kssycs; this.kslx = kslx; this.ksxl = ksxl; } //上一页 下一页 goPage(typeIndex) { 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) { const {selectedLine,selectedLineStyle,lineBg} = this; if (selectedLine === index) { return selectedLineStyle.bgColor } if (index % 2 === 0) { return lineBg[0] } else { return lineBg[1] } } //获取当前页的数据 getCurrentMarkRuleList() { const {currentIndex,currentUniversalPageIndex,currentPageIndex,universalMarkRules} = this; if (currentIndex) { //通用评判 return universalMarkRules.slice(currentUniversalPageIndex * 7, (currentUniversalPageIndex + 1) * 7) } else { return universalMarkRules.slice(currentPageIndex * 7, (currentPageIndex + 1) * 7) } } build() { Column() { Column() { Column() { Row() { Row() { ForEach(['人工评判'], (text, 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, 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)') } }