subject-two/entry/src/main/ets/pages/compontents/judge/BoardPrePareSetPopup.ets

349 lines
12 KiB
Plaintext
Raw Normal View History

2024-07-05 09:34:03 +08:00
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 {
MarkRule,
SYSSET,
} from '../../judgeSDK/api/judgeSDK.d';
interface SEL {
fontColor: string
bgColor: string
}
@Component
export default struct DeductedPopup {
private context = getContext(this) as common.UIAbilityContext;
private avPlayer
@State name: string = ''
@State idCard: string = ''
@State lsh: string = ''
@State kszp: string = ''
@State ksdd: string = ''
@State kssycs: string = ''
@State kslx: string = ''
@State kfdmArr: {
xmdm: number,
kfdm: string,
markreal: number
}[] = []
//开始考试前判绕车一周评判是否开启
@State isOpen: boolean = false
//监管序列号
@State serialNumber: number = 0;
@State examSubject: number = 2;
@State markRuleListObj: MarkRule = {}
@State fontSize: number = 25
@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<string> = ['#4D4136', '#26231E']
@State selectedLine: number = undefined
private closePopup: Function = () => {
}
private confirmMark: Function = (itemno: number, serial: string) => {
}
@State selectedLineStyle: SEL = {
fontColor: '#FFF',
bgColor: '#B36E00'
}
aboutToAppear() {
//上车准备
// this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+''))
const {isTrajectoryOpen} = judgeConfig;
if (isTrajectoryOpen) {
this.initDb()
} else {
this.initSysset()
this.initMarkRules()
}
this.avPlayer = new VoiceAnnounce();
}
//本地数据初始化
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()
}
//获取sysset表数据
async initSysset(sysset?: SYSSET[]) {
const syssetParams = sysset || await getSyncData('MA_SYSSET');
//@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'])
}
}
})
}
//获取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) {
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} = stuInfo;
this.name = xm || '测试考生';
this.idCard = sfzmhm || '01234567891010';
this.lsh = lsh;
this.kszp = kszp;
this.ksdd = ksdd;
this.kssycs = kssycs;
this.kslx = kslx;
}
//上一页 下一页
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(36).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(36).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(160)
.height(80)
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Center)
.backgroundImage($rawfile(`judge/km3/button_nor.png`))
.backgroundImageSize({ width: '100%', height: '100%' })
.onClick(() => {
const index = this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex;
const mark = this.universalMarkRules[index * 7 + this.selectedLine];
const {avPlayer,kssycs} = this;
this.kfdmArr.push({ xmdm: 1, kfdm: mark.markserial, markreal: mark.markreal })
//计算总扣分
let score = this.kfdmArr.reduce((p, n) => {
p += n.markreal
return p
}, 0);
avPlayer.playAudio([`voice/${mark.markcatalog}.mp3`]);
console.info('surenjun',score)
if(!globalThis.singlePlay){
if (score < -90) {
avPlayer.playAudio([
'voice/exam_waiting.mp3',
kssycs == '1' ? 'voice/unqualified_one.wav' : 'voice/unqualified_two.wav'
]);
};
}
this.confirmMark(this.kfdmArr.map((kf) => ({
xmdm:kf.xmdm,
kfdm:kf.kfdm,
})))
})
}
}.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: '15%', 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(() => {
this.closePopup()
})
}.width('100%').height('100%').position({ y: 0 }).backgroundColor('rgba(0,0,0,0.7)')
}
}