| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028 |
- <template>
- <uni-navbar-lite :showLeft="true" title="工单自评">
- <view class="back-icon" slot="left" @click="goBack">
- <text class="iconfont icon-back">{{ orderType == '1' ? '维修工单自评' : '维保工单自评' }}</text>
- </view>
- </uni-navbar-lite>
-
- <scroll-view class="container" :scroll-y="true">
- <view class="header">
- <text class="title"></text>
- </view>
-
- <view class="form">
- <!-- 工单基本信息 -->
- <view class="info-card">
- <view class="info-item">
- <text class="info-label">工单编码</text>
- <text class="info-value">{{ selfEvaluationForm.workOrderProjectNo }}</text>
- </view>
- <view class="info-item">
- <text class="info-label">风机编号</text>
- <text class="info-value">{{ selfEvaluationForm.pcsDeviceName }}</text>
- </view>
- <view class="info-item">
- <text class="info-label">场站</text>
- <text class="info-value">{{ selfEvaluationForm.pcsStationName }}</text>
- </view>
- </view>
- <!-- 工单类型相关字段 -->
- <view v-if="selfEvaluationForm.orderType == '1'" class="info-card">
- <view class="form-item">
- <text class="label">检修类型<text style="color: red;">*</text></text>
- <view class="form-picker" @click="showMaintenanceTypePicker = true">
- <view class="picker-display">
- <text v-if="selfEvaluationForm.maintenanceType" class="selected-value">{{ getMaintenanceTypeLabel(selfEvaluationForm.maintenanceType) }}</text>
- <text v-else class="placeholder">请选择检修类型</text>
- <text class="arrow">▼</text>
- </view>
- </view>
- </view>
- </view>
- <!-- 自定义选择器弹窗 -->
- <view v-if="showMaintenanceTypePicker" class="picker-modal">
- <view class="modal-mask" @click="showMaintenanceTypePicker = false"></view>
- <view class="modal-content">
- <view class="modal-header">
- <text class="modal-title">检修类型</text>
- <text class="modal-close" @click="showMaintenanceTypePicker = false">取消</text>
- </view>
- <scroll-view class="modal-body" scroll-y="true">
- <view
- v-for="(option, index) in maintenanceTypeOptions"
- :key="index"
- class="picker-option"
- :class="{ 'selected': index == selectedMaintenanceTypeIndex }"
- @click="selectMaintenanceType(index)"
- >
- <text class="option-text">{{ option.label }}</text>
- <text v-if="index == selectedMaintenanceTypeIndex" class="option-check">✓</text>
- </view>
- </scroll-view>
- </view>
- </view>
- <view v-if="selfEvaluationForm.orderType == '2'" class="info-card">
- <view class="info-item">
- <text class="info-label">维保类型</text>
-
- <text v-for="(type, index) in selfEvaluationForm.inspectionType" :key="index">
- {{ getInspectionTypeLabel(type) }}
- </text>
- </view>
- <view class="info-item">
- <text class="info-label">分项完成系数<text style="color: red;">*</text></text>
- <input
- class="info-input"
- type="digit"
- :value="getItemCompletionFactorDisplayValue()"
- @input="onItemCompletionFactorInput"
- @blur="formatItemCompletionFactor()"
- placeholder="请输入分项完成系数"
- />
- </view>
- <view class="info-item">
- <text class="info-label">分项完成系数和<text style="color: red;">*</text></text>
- <input
- class="info-input"
- type="digit"
- :value="getItemCompletionFactorSumDisplayValue()"
- @input="onItemCompletionFactorSumInput"
- @blur="formatItemCompletionFactorSum()"
- placeholder="请输入分项完成系数和"
- />
- </view>
- </view>
- <!-- 总结内容 -->
- <view class="info-card">
- <view class="form-item">
- <text class="label">{{ selfEvaluationForm.orderType == '1' ? '维修总结' : '维保总结' }}<text style="color: red;">*</text></text>
- <textarea
- class="textarea"
- :value="selfEvaluationForm.workSummary"
- @input="onWorkSummaryInput"
- placeholder="请输入总结内容"
- :maxlength="200"
- />
- </view>
-
- <!-- 额外工作总结 - 仅维修工单显示 -->
- <view v-if="selfEvaluationForm.orderType == '1'" class="form-item">
- <text class="label">额外工作总结</text>
- <textarea
- class="textarea"
- :value="selfEvaluationForm.extraWork"
- @input="onExtraWorkInput"
- @blur="onExtraWorkChange"
- placeholder="请输入额外工作总结"
- :maxlength="200"
- />
- </view>
- </view>
- <!-- 人员信息和得分明细 -->
- <!-- <view class="info-card">
- <view class="form-item">
- <text class="label">外委人员数(人)</text>
- <text class="value">{{ selfEvaluationForm.wwryNum }}</text>
- </view>
- <view class="form-item">
- <text class="label">外来人员数(人)</text>
- <text class="value">{{ selfEvaluationForm.wlryNum }}</text>
- </view>
- </view> -->
- <!-- 得分明细 -->
- <view class="info-card">
- <view class="form-item">
- <text class="label">得分明细 ({{ isMixedZeroNonZeroInspectionTypes() ? '最少可评总分: ' : '可自评总分: ' }}{{ getSelfEvaluationTotalScore() == 0 ? '未规定' : (getSelfEvaluationTotalScore() != null ? getSelfEvaluationTotalScore().toFixed(2) : '0.00') + '分' }}, 已自评总分: {{ selfEvaluatedTotalScore != null ? selfEvaluatedTotalScore.toFixed(2) : '0.00' }}分)</text>
- </view>
- <view v-for="(person, index) in selfEvaluationForm.scorePersonList as UTSJSONObject[]" :key="index" class="person-score-item">
- <view class="person-info">
- <text class="person-name">{{ (person as UTSJSONObject).get('nickName') }}<text v-if="(person as UTSJSONObject).get('isLeader') == 1"> (工作负责人)</text></text>
- </view>
- <view class="score-inputs">
- <view class="score-item">
- <text class="score-label">检修工分<text style="color: red;">*</text></text>
- <input
- class="score-input"
- type="digit"
- :value="getPersonScore(person, 'selfScore')"
- @input="onScoreInput($event, index, 'selfScore')"
- @blur="formatScoreInput(index, 'selfScore');onScoreChange"
- placeholder="0.00"
- />
- </view>
- <!-- 额外工分 - 仅当维修工单且有额外工作总结时显示 -->
- <view v-if="selfEvaluationForm.orderType == '1' && hasExtraWorkFlag" class="score-item">
- <text class="score-label">额外工分</text>
- <input
- class="score-input"
- type="digit"
- :value="getPersonScore(person, 'extraScore')"
- @input="onScoreInput($event, index, 'extraScore')"
- @blur="formatScoreInput(index, 'extraScore');onScoreChange"
- placeholder="0.00"
- />
- </view>
- <!-- 工单得分 - 仅当维修工单且有额外工作总结时显示 -->
- <view v-if="selfEvaluationForm.orderType == '1' && hasExtraWorkFlag" class="score-item">
- <text class="score-label">工单得分</text>
- <input
- class="score-input"
- type="digit"
- :value="getPersonScore(person, 'totalScore')"
- readonly
- disabled
- placeholder="自动计算"
- style="pointer-events: none;"
- />
- </view>
- <!-- 额外工分和工单得分 - 仅当维保工单且维保类型包含其他/其它时显示 -->
- <view v-if="selfEvaluationForm.orderType == '2' && hasOtherOrQitaInspectionType()" class="score-item">
- <text class="score-label">额外工分</text>
- <input
- class="score-input"
- type="digit"
- :value="getPersonScore(person, 'extraScore')"
- @input="onScoreInput($event, index, 'extraScore')"
- @blur="formatScoreInput(index, 'extraScore');onScoreChange"
- placeholder="0.00"
- />
- </view>
- <view v-if="selfEvaluationForm.orderType == '2' && hasOtherOrQitaInspectionType()" class="score-item">
- <text class="score-label">工单得分</text>
- <input
- class="score-input"
- type="digit"
- :value="getPersonScore(person, 'totalScore')"
- readonly
- disabled
- placeholder="自动计算"
- style="pointer-events: none;"
- />
- </view>
- </view>
- </view>
- </view>
-
- <!-- 提交按钮 -->
- <view class="submit-btn" @click="submitSelfEvaluationForm">
- <text class="submit-text">提交自评</text>
- </view>
- </view>
- </scroll-view>
- </template>
- <script setup lang="uts">
- import { ref, onMounted, onLoad, onUnload } from 'vue'
- import { getOrderScoreDetail, submitSelfEvaluation, getMaintenanceTypes, listInspectionTypesByFanType } from '@/api/score/index'
- import { getDictDataByType } from '@/api/dict/index'
- import type { UserInfo } from '@/types/user'
- import type { SysDictData } from '@/types/dict'
- /* // 定义事件类型
- // 定义事件类型
- interface InputEvent {
- detail: any
- target: any
- } */
- // 页面参数
- const id = ref<string>('')
- const orderType = ref<string>('')
- const showMaintenanceTypePicker = ref<boolean>(false)
- // 添加额外工作总结状态变量
- const hasExtraWorkFlag = ref<boolean>(false)
- // 验证规则 - 使用UTS兼容的简单对象定义
- const validationRules: any = {
- workSummary: [
- { required: true, message: "总结不能为空", trigger: "blur" }
- ],
- maintenanceType: [
- { required: true, message: "请选择检修类型", trigger: "change" }
- ],
- inspectionType: [
- { required: true, message: "请选择维保类型", trigger: "change" }
- ],
- itemCompletionFactor: [
- { required: true, message: "分项完成系数不能为空", trigger: "change" }
- ],
- itemCompletionFactorSum: [
- { required: true, message: "分项完成系数和不能为空", trigger: "change" }
- ]
- }
- // 自评表单数据
- type SelfEvaluationFormData = {
- orderType: string
- id: number
- workOrderProjectNo: string
- pcsDeviceName: string
- pcsStationName: string
- model: string | null // 风机型号,用于获取维保类型选项
- workSummary: string
- extraWork: string
- maintenanceType: string | null
- inspectionType: string[]
- itemCompletionFactor: number | null
- itemCompletionFactorSum: number | null
- scorePersonList: UTSJSONObject[]
- wwryNum: number
- wlryNum: number
- }
- // 用于input绑定的字符串中转
- let itemCompletionFactorStr = ref<string>('')
- let itemCompletionFactorSumStr = ref<string>('')
- // 临时存储分项完成系数的原始输入值
- const tempItemCompletionFactorInput = ref<string>('')
- const tempItemCompletionFactorSumInput = ref<string>('')
- // 添加响应式变量来跟踪已自评总分
- let selfEvaluatedTotalScore = ref<number>(0)
- const selfEvaluationForm = ref<SelfEvaluationFormData>({
- orderType: '',
- id: 0,
- workOrderProjectNo: '',
- pcsDeviceName: '',
- pcsStationName: '',
- model: null as string | null,
- workSummary: '',
- extraWork: '',
- maintenanceType: '',
- inspectionType: [],
- itemCompletionFactor: null,
- itemCompletionFactorSum: null,
- scorePersonList: [],
- wwryNum: 0,
- wlryNum: 0
- })
- type MaintenanceTypeOption = {
- value: string
- label: string
- }
- // 检修类型选项
- const maintenanceTypeOptions = ref<MaintenanceTypeOption[]>([])
- const selectedMaintenanceTypeIndex = ref<number>(-1)
- // 维保类型选项
- const inspectionTypeOptions = ref<UTSJSONObject[]>([])
- // 维保类型字典
- const inspectionTypeDictList = ref<SysDictData[]>([])
- // 获取已自评总分
- function getSelfEvaluatedTotalScore(): number {
- const scorePersonList = selfEvaluationForm.value.scorePersonList as UTSJSONObject[]
- if (scorePersonList == null || scorePersonList.length == 0) {
- return 0
- }
-
- let totalSelfScore = 0
-
- for (let i = 0; i < scorePersonList.length; i++) {
- const person = scorePersonList[i]
- const selfScoreVal = person.get('selfScore')
- if (selfScoreVal != null) {
- // 统一处理分数值,无论是number还是string类型
- const scoreValue = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0);
- if (!isNaN(scoreValue) && scoreValue != 0) {
- totalSelfScore += scoreValue;
- }
- }
- }
- return totalSelfScore
- }
- // 更新已自评总分的响应式变量
- function updateSelfEvaluatedTotalScore(): void {
- selfEvaluatedTotalScore.value = getSelfEvaluatedTotalScore()
- }
- // 更新总分
- function updateTotalScores(): void {
- const scorePersonList = selfEvaluationForm.value.scorePersonList as UTSJSONObject[]
- if (scorePersonList == null || scorePersonList.length == 0) return
- for (let i = 0; i < scorePersonList.length; i++) {
- const person = scorePersonList[i]
- const selfScoreVal = person.get('selfScore')
- const extraScoreVal = person.get('extraScore')
- // 根据工单类型和条件决定是否计算总分
- // 检查当前工单类型并获取对应条件
- const isMaintenanceOrderWithExtraWork = selfEvaluationForm.value.orderType == '1' && hasExtraWorkFlag.value;
- const isMaintenanceOrderType = selfEvaluationForm.value.orderType == '2';
- // 手动实现hasOtherOrQitaInspectionType函数的逻辑
- let hasOtherOrQitaType = false;
- if (isMaintenanceOrderType) {
- if (selfEvaluationForm.value.orderType != '2') {
- hasOtherOrQitaType = false;
- } else if (!Array.isArray(selfEvaluationForm.value.inspectionType)) {
- hasOtherOrQitaType = false;
- } else {
- for (let i = 0; i < selfEvaluationForm.value.inspectionType.length; i++) {
- const typeId = selfEvaluationForm.value.inspectionType[i];
- // 内联getInspectionTypeLabel函数的逻辑
- let label = '';
- if (typeId == '') {
- label = '';
- } else {
- const list = inspectionTypeDictList.value;
- for (let j = 0; j < list.length; j++) {
- const item = list[j];
- if (item.dictValue == typeId) {
- label = (item.dictLabel != null ? item.dictLabel : typeId) as string;
- break;
- }
- }
- }
- if (label == '其他' || label == '其它') {
- hasOtherOrQitaType = true;
- break;
- }
- }
- }
- }
- if (isMaintenanceOrderWithExtraWork) {
- // 维修工单且有额外工作总结时,总分 = 自评分 + 额外工分
- if (selfScoreVal != null && extraScoreVal != null) {
- const selfScore = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0)
- const extraScore = typeof extraScoreVal == 'number' ? extraScoreVal : (extraScoreVal != '' ? parseFloat(extraScoreVal as string) : 0)
- person.set('totalScore', (selfScore + extraScore).toFixed(2))
- } else if (selfScoreVal != null) {
- // 如果只有自评分,没有额外工分
- const selfScore = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0)
- person.set('totalScore', selfScore.toFixed(2))
- }
- } else if (isMaintenanceOrderType && hasOtherOrQitaType) {
- // 维保工单且维保类型包含其他/其它时,总分 = 自评分 + 额外工分
- if (selfScoreVal != null && extraScoreVal != null) {
- const selfScore = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0)
- const extraScore = typeof extraScoreVal == 'number' ? extraScoreVal : (extraScoreVal != '' ? parseFloat(extraScoreVal as string) : 0)
- person.set('totalScore', (selfScore + extraScore).toFixed(2))
- } else if (selfScoreVal != null) {
- // 如果只有自评分,没有额外工分
- const selfScore = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0)
- person.set('totalScore', selfScore.toFixed(2))
- }
- } else {
- // 其他情况只显示自评分
- if (selfScoreVal != null) {
- const selfScore = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0)
- if (!isNaN(selfScore)) {
- person.set('totalScore', selfScore.toFixed(2))
- }
- } else {
- person.set('totalScore', 0)
- }
- }
- }
- // 同步分项完成系数和显示
- itemCompletionFactorStr.value = selfEvaluationForm.value.itemCompletionFactor != null ? selfEvaluationForm.value.itemCompletionFactor.toFixed(2) : ''
- itemCompletionFactorSumStr.value = selfEvaluationForm.value.itemCompletionFactorSum != null ? selfEvaluationForm.value.itemCompletionFactorSum.toFixed(2) : ''
-
- // 更新已自评总分显示
- updateSelfEvaluatedTotalScore()
- }
- // 计算得分 - 实际上在自评中,这是手动输入的,不需要自动计算
- function calculateScores(): void {
- // 在自评阶段,分数是手动输入的,不需要自动计算
- // 但我们需要根据工单类型和配置来验证总分是否符合规则
- updateTotalScores()
-
- // 更新已自评总分显示
- updateSelfEvaluatedTotalScore()
- }
- // 根据值获取维保类型标签
- function getInspectionTypeLabel(value: string): string {
- if (value == '') return ''
- const list = inspectionTypeDictList.value
- for (let i = 0; i < list.length; i++) {
- const item = list[i]
- if (item.dictValue == value) {
- return (item.dictLabel != null ? item.dictLabel : value) as string
- }
- }
- return value
- }
- // 检查维保类型是否包含'其他'或'其它'选项
- function hasOtherOrQitaInspectionType(): boolean {
- if (selfEvaluationForm.value.orderType != '2') return false
- if (!Array.isArray(selfEvaluationForm.value.inspectionType)) return false
-
- for (let i = 0; i < selfEvaluationForm.value.inspectionType.length; i++) {
- const typeId = selfEvaluationForm.value.inspectionType[i]
- const label = getInspectionTypeLabel(typeId)
- if (label == '其他' || label == '其它') {
- return true
- }
- }
- return false
- }
- // 检查维保类型是否既有零分又有非零分的情况
- function isMixedZeroNonZeroInspectionTypes(): boolean {
- if (selfEvaluationForm.value.orderType != '2') return false
- if (!Array.isArray(selfEvaluationForm.value.inspectionType)) return false
- if (selfEvaluationForm.value.inspectionType.length <= 1) return false // 单选不会出现混合情况
-
- let hasZeroScore = false;
- let hasNonZeroScore = false;
-
- const selectedInspectionTypes: string[] = selfEvaluationForm.value.inspectionType;
-
- for (let i = 0; i < selectedInspectionTypes.length; i++) {
- const typeId = selectedInspectionTypes[i];
- for (let j = 0; j < inspectionTypeOptions.value.length; j++) {
- const selectedType = inspectionTypeOptions.value[j];
- // 使用inspectionTypeId进行匹配
- if (selectedType.get('inspectionTypeId').toString() == typeId) {
- // 从标签中提取分数
- const score = selectedType.get('score');
- if (score != null && typeof score == 'number') {
- if (score == 0) {
- hasZeroScore = true;
- } else if (score > 0) {
- hasNonZeroScore = true;
- }
- }
- }
- }
- }
-
- // 如果既有零分又有非零分,则返回true
- return hasZeroScore && hasNonZeroScore;
- }
- // 获取工单总分
- function getTotalScore(): number {
- let totalScore = 0;
-
- if (selfEvaluationForm.value.orderType == '1') {
- // 维修工单:根据检修类型获取总分
- for (let i = 0; i < maintenanceTypeOptions.value.length; i++) {
- const typeOption = maintenanceTypeOptions.value[i]
- if (typeOption.value == selfEvaluationForm.value.maintenanceType) {
- // 从标签中提取分数
- const regex = /\((\d+(\.\d+)?)分\)/
- const match = typeOption.label.match(regex)
- if (match != null && match.length > 1 && match[1] != null) {
- totalScore = parseFloat(match[1] as string);
- break;
- }
- }
- }
- } else if (selfEvaluationForm.value.orderType == '2') {
- // 维保工单:根据选中的维保类型和分项完成系数获取总分
- // 检查分项完成系数是否为null,如果是null则视为无效
- if (selfEvaluationForm.value.itemCompletionFactor == null) {
- return 0;
- }
-
- const completionFactor = selfEvaluationForm.value.itemCompletionFactor;
-
- // 获取选中的维保项目(现在是多选)
- const selectedInspectionTypes: string[] = selfEvaluationForm.value.inspectionType != null ? selfEvaluationForm.value.inspectionType : [];
-
- // 计算所有选中维保项目的总分值
- let totalScoreFromDB = 0; // 默认值
-
- if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
- for (let i = 0; i < selectedInspectionTypes.length; i++) {
- const typeId = selectedInspectionTypes[i];
- for (let j = 0; j < inspectionTypeOptions.value.length; j++) {
- const selectedType = inspectionTypeOptions.value[j];
- const inspectionTypeId = selectedType.get('inspectionTypeId');
- const score = selectedType.get('score');
- // 使用toString()方法确保类型一致进行匹配
- if ((inspectionTypeId as number).toString() == typeId) {
- if (score != null && typeof score == 'number') {
- totalScoreFromDB += score;
- }
- }
- }
- }
- }
-
- // 计算总分:总分 = 所有选中维保类型组合的总得分 * 分项完成系数
- totalScore = totalScoreFromDB * completionFactor;
- }
- return totalScore;
- }
- // 获取可自评总分
- function getSelfEvaluationTotalScore(): number {
- // 获取工单总分
- const totalScore = getTotalScore();
-
- // 如果总分为0,返回0
- if (totalScore == 0) {
-
- // 特殊处理:对于维保工单且多选维保类型的情况,如果存在零分和非零分的混合情况
- if (selfEvaluationForm.value.orderType == '2' && Array.isArray(selfEvaluationForm.value.inspectionType) && selfEvaluationForm.value.inspectionType.length > 1) {
- // 获取选中的维保类型
- const selectedInspectionTypes: string[] = selfEvaluationForm.value.inspectionType != null ? selfEvaluationForm.value.inspectionType : [];
- // 计算所有选中维保类型的非零分值
- let minScoreFromDB = 0; // 非零分值总和
- let hasZeroScore = false; // 是否存在零分
-
- if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
- for (let i = 0; i < selectedInspectionTypes.length; i++) {
- const typeId = selectedInspectionTypes[i];
- for (let j = 0; j < inspectionTypeOptions.value.length; j++) {
- const selectedType = inspectionTypeOptions.value[j];
- const inspectionTypeId = selectedType.get('inspectionTypeId');
- const score = selectedType.get('score');
- // 使用toString()方法确保类型一致进行匹配
- if ((inspectionTypeId as number).toString() == typeId) {
- if (score != null && typeof score == 'number') {
- if (score == 0) {
- hasZeroScore = true;
- } else if (score > 0) {
- minScoreFromDB += score;
- }
- }
- }
- }
- }
- }
-
- // 如果存在零分且存在非零分的情况,返回非零分的总和加上工作负责人的0.5分
- if (hasZeroScore && minScoreFromDB > 0) {
- const completionFactor = selfEvaluationForm.value.itemCompletionFactor != null ? selfEvaluationForm.value.itemCompletionFactor : 1;
- const result = (minScoreFromDB * completionFactor) + 0.5;
- return result;
- }
- }
- return 0;
- }
- // 检查是否存在工作负责人
- const scorePersonList = selfEvaluationForm.value.scorePersonList as UTSJSONObject[];
- for (let i = 0; i < scorePersonList.length; i++) {
- const person = scorePersonList[i];
- const isLeader = person.get('isLeader');
- if (isLeader != null && isLeader as number == 1) {
- // 如果存在工作负责人,可自评总分加0.5分
- const result = totalScore + 0.5;
- return result;
- }
- }
- return totalScore;
- }
- // 人员评分验证
- function validatePersonScore(score: string, fieldName: string): string | null {
- if (score == null || score == '') {
- if (fieldName == 'selfScore') {
- return '检修工分不能为空';
- }
- return null; // 额外工分可以为空
- }
-
- const numScore = parseFloat(score);
- if (isNaN(numScore)) {
- return `${fieldName == 'selfScore' ? '检修工分' : '额外工分'}必须为数字`;
- }
-
- if (numScore < 0) {
- return `${fieldName == 'selfScore' ? '检修工分' : '额外工分'}不能小于0`;
- }
-
- if (fieldName == 'selfScore' && numScore <= 0) {
- return '检修工分必须大于0';
- }
- return null;
- }
- // 字段验证函数
- function validateField(fieldName: string, value: any): string | null {
- console.log('验证字段:', fieldName, '值:', value, '类型:', typeof value);
- // 根据字段名称确定验证规则
- if (fieldName == 'workSummary') {
- // 验证工作/维保总结
- if (value == null || value == '') {
- const summaryType = selfEvaluationForm.value.orderType == '1' ? '维修' : '维保';
- return `${summaryType}总结不能为空`;
- }
- } else if (fieldName == 'maintenanceType') {
- // 验证检修类型
- if (value == null || value == '') {
- return "请选择检修类型";
- }
- } else if (fieldName == 'inspectionType') {
- // 验证维保类型
- if (value == null || (Array.isArray(value) && value.length == 0)) {
- return "请选择维保类型";
- }
- } else if (fieldName == 'itemCompletionFactor') {
- // 验证分项完成系数
- if (value == null || value == '') {
- return "分项完成系数不能为空";
- }
- // 验证数值范围
- let numValue: number;
- if (typeof value == 'string' && value != '') {
- numValue = parseFloat(value);
- } else if (typeof value == 'number') {
- numValue = value;
- } else {
- return "分项完成系数类型错误";
- }
-
- if (isNaN(numValue) || numValue < 0 || numValue > 1) {
- return '分项完成系数必须在0到1之间';
- }
- } else if (fieldName == 'itemCompletionFactorSum') {
- // 验证分项完成系数和
- if (value == null || value == '') {
- return "分项完成系数和不能为空";
- }
- // 验证数值范围
- let numValue: number;
- if (typeof value == 'string' && value != '') {
- numValue = parseFloat(value);
- } else if (typeof value == 'number') {
- numValue = value;
- } else {
- return "分项完成系数和类型错误";
- }
-
- if (isNaN(numValue) || numValue < 0 || numValue > 1) {
- return '分项完成系数和必须在0到1之间';
- }
- }
- return null;
- }
- // 验证评分规则
- function validateScoringRules(): any {
- // 获取工单总分
- const totalScore = getTotalScore()
- // 获取自评分总和
- const totalSelfScore = getSelfEvaluatedTotalScore()
- const scorePersonList = selfEvaluationForm.value.scorePersonList as UTSJSONObject[]
- if (scorePersonList == null || scorePersonList.length == 0) {
- const result = new UTSJSONObject();
- result.set('valid', true);
- result.set('message', '');
- return result;
- }
- // 检查每个人员的评分
- let hasEmptyScore = false;
- let leaderScore: number | null = null;
- for (let i = 0; i < scorePersonList.length; i++) {
- const person = scorePersonList[i];
- // 验证自评分
- const selfScore = person.get('selfScore');
- if (selfScore == null || selfScore == '' || (typeof selfScore == 'number' && isNaN(selfScore as number))) {
- hasEmptyScore = true;
- } else {
- const scoreStr = typeof selfScore == 'number' ? selfScore.toFixed(2) : selfScore as string;
- const validationError = validatePersonScore(scoreStr, 'selfScore');
- if (validationError != null) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `${person.get('nickName')}:${validationError}`);
- return result;
- }
- const score = typeof selfScore == 'number' ? selfScore : parseFloat(selfScore as string);
- if (person.get('isLeader') != null && person.get('isLeader') as number == 1) {
- leaderScore = score;
- }
- }
- // 验证额外工分(如果存在)
- const extraScore = person.get('extraScore');
- if (extraScore != null && extraScore != '' && !(typeof extraScore == 'number' && isNaN(extraScore as number))) {
- const extraScoreStr = typeof extraScore == 'number' ? extraScore.toFixed(2) : extraScore as string;
- const extraScoreError = validatePersonScore(extraScoreStr, 'extraScore');
- if (extraScoreError != null) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `${person.get('nickName')}:${extraScoreError}`);
- return result;
- }
- }
- }
- // 如果有人没评分,返回错误
- if (hasEmptyScore) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', '部分人员未评分');
- return result;
- }
- // 检查工作负责人得分-0.5后是否小于等于0
- if (leaderScore != null) {
- const leaderScoreAfterReduction = leaderScore - 0.5
- if (leaderScoreAfterReduction <= 0) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `工作负责人得分减去0.5后不能小于等于0(当前:${leaderScore.toFixed(2)} - 0.5 = ${leaderScoreAfterReduction.toFixed(2)})`);
- return result;
- }
- }
- // 检查工单类型是否为维保工单且多选维保类型的情况,检查是否存在零分和非零分混合
- let isMultipleInspectionWithMixedScores = isMixedZeroNonZeroInspectionTypes();
- // 如果总分为0,则评分无上限
- if (totalScore == 0) {
- // 检查工作负责人得分-0.5后是否小于等于0
- if (leaderScore != null) {
- const leaderScoreAfterReduction = leaderScore - 0.5
- if (leaderScoreAfterReduction <= 0) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `工作负责人得分减去0.5后不能小于等于0(当前:${leaderScore.toFixed(2)} - 0.5 = ${leaderScoreAfterReduction.toFixed(2)})`);
- return result;
- }
- }
- const result = new UTSJSONObject();
- result.set('valid', true);
- result.set('message', '');
- return result;
- }
-
- // 检查自评分总和是否超过总分
- /* if (totalSelfScore > totalScore + 0.01) { // 使用0.01作为容差
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `检修工分总和不能超过工单总分 ${totalScore.toFixed(2)} 分(当前:${totalSelfScore.toFixed(2)} 分)`);
- return result;
- } */
-
- // 对于非零总分且非多选维保类型零分非零混合的情况,自评分总和必须小于等于总分+0.5
- if (totalScore > 0 && !isMultipleInspectionWithMixedScores) {
- // 计算理论总分(总分+0.5,因为工作负责人会额外加0.5分)
- const expectedTotal = totalScore + 0.5;
-
- // 总得分必须等于总分+0.5(使用容差比较)
- /* if (Math.abs(totalSelfScore - expectedTotal) > 0.01) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `总得分必须等于 ${expectedTotal.toFixed(2)} 分(当前:${totalSelfScore.toFixed(2)} 分)`);
- return result;
- } */
- if (totalSelfScore - expectedTotal > 0.01) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `总得分必须小于等于 ${expectedTotal.toFixed(2)} 分(当前:${totalSelfScore.toFixed(2)} 分)`);
- return result;
- }
- }
-
- // 如果是维保工单且多选维保类型且存在零分和非零分混合的情况,需要特殊处理
- if (isMultipleInspectionWithMixedScores) {
- // 在这种情况下,总分可能有最小值要求
- const completionFactor = selfEvaluationForm.value.itemCompletionFactor != null ? selfEvaluationForm.value.itemCompletionFactor : 1
- // 重新计算非零分项的总分
- let minScoreFromDB = 0;
- const selectedInspectionTypes: string[] = selfEvaluationForm.value.inspectionType != null ? selfEvaluationForm.value.inspectionType : []
-
- for (let i = 0; i < selectedInspectionTypes.length; i++) {
- const typeId = selectedInspectionTypes[i]
- for (let j = 0; j < inspectionTypeOptions.value.length; j++) {
- const selectedType = inspectionTypeOptions.value[j]
- // 使用inspectionTypeId进行匹配
- if (selectedType.get('inspectionTypeId').toString() == typeId) {
- const score = selectedType.get('score');
- if (score != null && typeof score == 'number' && score > 0) { // 只累加非零分
- minScoreFromDB += score;
- }
- }
- }
- }
-
- // 计算最低理论总分(非零项的总分 * 分项完成系数 + 0.5)
- const minExpectedTotal = (minScoreFromDB * completionFactor) + 0.5
-
- /* // 总得分不得低于最低理论总分
- if (totalSelfScore < minExpectedTotal - 0.01) { // 使用0.01作为容差
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', `总得分不得低于 ${minExpectedTotal.toFixed(2)} 分(当前:${totalSelfScore.toFixed(2)} 分)`);
- return result;
- } */
- }
- const result = new UTSJSONObject();
- result.set('valid', true);
- result.set('message', '');
- return result;
- }
- // 验证整个表单
- function validateForm(): any {
- console.log('开始验证表单,工单类型:', selfEvaluationForm.value.orderType);
- console.log('当前检修类型值:', selfEvaluationForm.value.maintenanceType);
- // 首先验证必填字段,按优先级排序
- // 验证工单类型为1(维修工单)时的检修类型
- if (selfEvaluationForm.value.orderType == '1') {
- console.log('验证维修工单的检修类型');
- console.log('当前maintenanceType值:', selfEvaluationForm.value.maintenanceType, '类型:', typeof selfEvaluationForm.value.maintenanceType);
- let validationMessage: string | null = null;
- try {
- validationMessage = validateField('maintenanceType', selfEvaluationForm.value.maintenanceType as any);
- } catch (error: any) {
- console.error('检修类型验证过程中出现异常:', error);
- validationMessage = '请选择检修类型';
- }
- console.log('检修类型验证结果:', validationMessage);
- if (validationMessage != null) {
- console.log('检修类型验证失败:', validationMessage);
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', validationMessage);
- return result;
- }
- }
- // 验证总结内容
- let summaryValidation: string | null = null;
- try {
- summaryValidation = validateField('workSummary', selfEvaluationForm.value.workSummary as any);
- } catch (error: any) {
- console.error('工作总结验证过程中出现异常:', error);
- summaryValidation = '工作总结验证失败';
- }
- if (summaryValidation != null) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', summaryValidation);
- return result;
- }
- // 验证工单类型为2(维保工单)时的分项完成系数
- if (selfEvaluationForm.value.orderType == '2') {
- // 检查分项完成系数是否为空字符串(即用户清空了输入框)
- if (itemCompletionFactorStr.value == '') {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', '分项完成系数不能为空');
- return result;
- }
- let validationMessage: string | null = null;
- try {
- validationMessage = validateField('itemCompletionFactor', selfEvaluationForm.value.itemCompletionFactor as any);
- } catch (error: any) {
- validationMessage = '分项完成系数验证失败';
- }
- if (validationMessage != null) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', validationMessage);
- return result;
- }
- // 验证分项完成系数和
- // 检查分项完成系数和是否为空字符串(即用户清空了输入框)
- if (itemCompletionFactorSumStr.value == '') {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', '分项完成系数和不能为空');
- return result;
- }
- validationMessage = null;
- try {
- validationMessage = validateField('itemCompletionFactorSum', selfEvaluationForm.value.itemCompletionFactorSum as any);
- } catch (error: any) {
- validationMessage = '分项完成系数和验证失败';
- }
- if (validationMessage != null) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', validationMessage);
- return result;
- }
- }
- // 验证维保类型(仅适用于维保工单)
- if (selfEvaluationForm.value.orderType == '2') {
- let validationMessage: string | null = null;
- try {
- validationMessage = validateField('inspectionType', selfEvaluationForm.value.inspectionType as any);
- } catch (error: any) {
- console.error('维保类型验证过程中出现异常:', error);
- validationMessage = '维保类型验证失败';
- }
- if (validationMessage != null) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', validationMessage);
- return result;
- }
- }
-
- // 验证评分规则
- let scoringValidation: UTSJSONObject;
- try {
- scoringValidation = validateScoringRules() as UTSJSONObject;
- } catch (error: any) {
- console.error('评分规则验证过程中出现异常:', error);
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', '评分规则验证失败');
- return result;
- }
- if (!(scoringValidation.get('valid') as boolean)) {
- const result = new UTSJSONObject();
- result.set('valid', false);
- result.set('message', scoringValidation.get('message') as string);
- return result;
- }
-
- const result = new UTSJSONObject();
- result.set('valid', true);
- result.set('message', '');
- return result;
- }
- // 加载检修类型选项
- async function loadMaintenanceTypes() {
- try {
- /* uni.showLoading({
- title: '加载中...'
- }) */
-
- const response: any = await getMaintenanceTypes()
- const resultObj = response as UTSJSONObject
- const code = resultObj.get('code') as number
-
- if (code == 200) {
- const data = resultObj.get('rows') as UTSJSONObject[]
- if (data != null && Array.isArray(data)) {
- // 将后端返回的数据转换为页面需要的格式
- const options: MaintenanceTypeOption[] = []
- for (let i = 0; i < data.length; i++) {
- const item = data[i]
- const option: MaintenanceTypeOption = {
- value: (item.get('maintenanceType') as string | null) ?? '',
- label: `${(item.get('projectName') as string | null) ?? ''}(${(item.get('scorePerCompletion') as number | null) ?? 0}分)`
- }
- options.push(option)
- }
- maintenanceTypeOptions.value = options
-
- // 设置选中项索引
- const mt = selfEvaluationForm.value.maintenanceType
- if (mt != null && mt != '') {
- const index = maintenanceTypeOptions.value.findIndex(item => item.value == mt)
- if (index >= 0) {
- selectedMaintenanceTypeIndex.value = index
- }
- } else {
- // 如果maintenanceType为空,重置选中索引
- selectedMaintenanceTypeIndex.value = -1
- selfEvaluationForm.value.maintenanceType = null
- }
- }
- } else {
- const msg = resultObj.get('msg') as string | null
- console.error('加载检修类型失败:', msg ?? '未知错误')
- }
- } catch (error: any) {
- console.error('加载检修类型失败:', error)
- } finally {
- //uni.hideLoading()
- }
- }
- // 加载维保类型选项
- async function loadInspectionTypeOptions() {
- try {
- // 加载维保类型选项
- if (orderType.value == '2') {
- // 根据风机型号获取维保类型选项
- const fanType = selfEvaluationForm.value.model; // 使用风机型号
-
- if (fanType != null && fanType != '') {
- const response: any = await listInspectionTypesByFanType(fanType as string);
- const resultObj = response as UTSJSONObject;
- const code = resultObj.get('code') as number;
-
- if (code == 200) {
- const data = resultObj.get('data') as UTSJSONObject[];
-
- if (data != null && Array.isArray(data)) {
- inspectionTypeOptions.value = data;
- }
- } else {
- console.error('API返回错误码:', code);
- console.error('错误信息:', resultObj.get('msg'));
- }
- } else {
- console.warn('风机型号为空,无法加载维保类型选项');
- }
- }
- } catch (e: any) {
- console.error('获取维保类型选项失败:', e.message);
- //console.error('错误堆栈:', e.stack);
- }
- }
- // 加载工单详情
- async function loadOrderDetail() {
- try {
- uni.showLoading({
- title: '加载中...'
- })
-
- const response: any = await getOrderScoreDetail(orderType.value, id.value)
- const resultObj = response as UTSJSONObject
- const code = resultObj.get('code') as number
-
- if (code == 200) {
- const data = resultObj.get('data') as UTSJSONObject
-
- // 设置表单数据
- const formData: SelfEvaluationFormData = {
- orderType: orderType.value,
- id: (data.get('id') as number | null) ?? 0,
- workOrderProjectNo: (data.get('workOrderProjectNo') as string | null) ?? '',
- pcsDeviceName: (data.get('pcsDeviceName') as string | null) ?? '',
- pcsStationName: (data.get('pcsStationName') as string | null) ?? '',
- workSummary: orderType.value == '1' ? ((data.get('content') as string | null) ?? '') : ((data.get('realContent') as string | null) ?? ''),
- extraWork: orderType.value == '1' ? ((data.get('extraWork') as string | null) ?? '') : '',
- maintenanceType: (data.get('maintenanceType') as string | null) ?? '',
- model: (data.get('model') as string | null), // 风机型号
- inspectionType: orderType.value == '2' ?
- (Array.isArray(data.get('inspectionType')) ?
- data.get('inspectionType') as string[] :
- (((data.get('inspectionType') as string | null)?.split(',') ?? []) as string[])) : [],
- itemCompletionFactor: (data.get('itemCompletionFactor') as number | null),
- itemCompletionFactorSum: (data.get('itemCompletionFactorSum') as number | null),
- scorePersonList: orderType.value == '1' ?
- ((data.get('repairOrderPersonList') as UTSJSONObject[] | null) ?? []) :
- ((data.get('workOrderPersonList') as UTSJSONObject[] | null) ?? []),
- wwryNum: (data.get('wwryNum') as number | null) ?? 0,
- wlryNum: (data.get('wlryNum') as number | null) ?? 0
- }
- selfEvaluationForm.value = formData
-
- // 为人员列表设置初始分数
- /* const list = (formData.scorePersonList as UTSJSONObject[])
- for (let i = 0; i < list.length; i++) {
- const person = list[i]
- if (person.get('selfScore') == null) {
- person.set('selfScore', '')
- }
- if (person.get('extraScore') == null) {
- person.set('extraScore', '')
- }
- if (person.get('totalScore') == null) {
- person.set('totalScore', '')
- }
- } */
- // 初始化字符串中转值,处理可能为null的情况
- itemCompletionFactorStr.value = formData.itemCompletionFactor != null ? formData.itemCompletionFactor.toFixed(2) : ''
- itemCompletionFactorSumStr.value = formData.itemCompletionFactorSum != null ? formData.itemCompletionFactorSum.toFixed(2) : ''
-
- // 加载检修类型选项
- if (orderType.value == '1') {
- await loadMaintenanceTypes()
- }
-
- // 加载维保类型选项
- if (orderType.value == '2') {
- await loadInspectionTypeOptions()
- }
-
- // 计算初始分数
- calculateScores()
-
- // 设置额外工作总结状态标志
- hasExtraWorkFlag.value = formData.extraWork != null && formData.extraWork.trim() != '';
-
- // 初始化已自评总分
- updateSelfEvaluatedTotalScore()
- } else {
- const msg = resultObj.get('msg') as string | null
- uni.showToast({
- title: msg ?? '加载失败',
- icon: 'none'
- })
- }
- } catch (error: any) {
- console.error('加载工单详情失败:', error)
- uni.showToast({
- title: '加载失败',
- icon: 'none'
- })
- } finally {
- uni.hideLoading()
- }
- }
- // 加载字典数据
- async function loadDictData() {
- try {
- // 加载维保类型字典
- if (orderType.value == '2') {
- const result = await getDictDataByType('gxt_inspection_type')
- const resultObj = result as UTSJSONObject
- if (resultObj.get('code') == 200) {
- const data = resultObj.get('data') as any[]
- const dictData: SysDictData[] = []
- if (data != null && data.length > 0) {
- for (let i = 0; i < data.length; i++) {
- const item = data[i] as UTSJSONObject
- // 只提取需要的字段
- const dictItem: SysDictData = {
- dictValue: item.get('dictValue') as string | null,
- dictLabel: item.get('dictLabel') as string | null,
- dictCode: null,
- dictSort: null,
- dictType: null,
- cssClass: null,
- listClass: null,
- isDefault: null,
- status: null,
- default: null,
- createTime: null,
- remark: null
- }
- dictData.push(dictItem)
- }
- }
- inspectionTypeDictList.value = dictData
- }
- }
- } catch (e: any) {
- console.error('获取维保类型字典失败:', e.message)
- }
- }
- // 检修类型选择变化
- function selectMaintenanceType(index: number) {
- selectedMaintenanceTypeIndex.value = index
- if (index >= 0 && index < maintenanceTypeOptions.value.length) {
- selfEvaluationForm.value.maintenanceType = maintenanceTypeOptions.value[index].value
- }
- showMaintenanceTypePicker.value = false
-
- // 选择后立即触发验证
- const validationMessage = validateField('maintenanceType', selfEvaluationForm.value.maintenanceType as any);
- if (validationMessage != null) {
- uni.showToast({
- title: validationMessage,
- icon: 'none'
- });
- }
- }
- // 根据值获取检修类型标签
- function getMaintenanceTypeLabel(value: string | null): string {
- if (value == null || value == '') return ''
- const item = maintenanceTypeOptions.value.find(item => item.value == value)
- return item != null ? item.label : value
- }
- // 工作总结输入处理
- function onWorkSummaryInput(e: UniInputEvent) {
- const value = e.detail?.value as string
- selfEvaluationForm.value.workSummary = value
- }
- // 格式化分项完成系数输入值
- function formatItemCompletionFactor() {
- const tempValue = tempItemCompletionFactorInput.value;
- let finalValue: number | null = null; // 明确定义类型
-
- if (tempValue.endsWith('.')) {
- // 如果以点结尾,去除点号
- const processedValue = tempValue.slice(0, -1);
-
- if (processedValue != '') {
- const numValue = parseFloat(processedValue);
-
- if (!isNaN(numValue) && isFinite(numValue)) {
- if (numValue >= 0 && numValue <= 1) {
- finalValue = numValue;
- } else {
- finalValue = numValue > 1 ? 1 : 0; // 根据数值大小决定边界值
- }
- } else {
- finalValue = 1; // 默认值
- }
- } else {
- // 去掉点后为空,设为null
- finalValue = null;
- }
- } else {
- // 正常数值处理
- const currentValue = selfEvaluationForm.value.itemCompletionFactor;
- if (currentValue != null && typeof currentValue == 'number') {
- // 格式化小数位数
- const currentStr = currentValue.toString();
- const parts = currentStr.split('.');
- if (parts.length > 1 && parts[1] != null && parts[1].length > 2) {
- // 创建一个局部变量确保类型安全
- const valueToFormat: number = currentValue;
- finalValue = parseFloat(valueToFormat.toFixed(2));
- } else {
- finalValue = currentValue;
- }
- }
- }
-
- // 更新数值
- selfEvaluationForm.value.itemCompletionFactor = finalValue;
-
- // 同步更新临时输入值为格式化后的字符串显示
- if (finalValue != null) {
- tempItemCompletionFactorInput.value = finalValue.toString();
- } else {
- tempItemCompletionFactorInput.value = '';
- }
- }
- function onItemCompletionFactorInput(e: UniInputEvent) {
- const value = e.detail?.value as string;
- // 更新临时输入值
- tempItemCompletionFactorInput.value = value;
-
- // 检查输入值是否为空
- if (value == '') {
- selfEvaluationForm.value.itemCompletionFactor = null;
- } else {
- // 检查是否为中间输入状态(如 '0.' 等以点结尾的数字)
- if (value.endsWith('.')) {
- // 如果是中间输入状态,不更新数值,保持原有值
- return;
- }
-
- // 验证输入值是否为有效数字
- const numValue = parseFloat(value);
- if (!isNaN(numValue) && isFinite(numValue)) {
- if( numValue >= 0 && numValue <= 1){
- // 在input事件中直接使用解析后的数值
- selfEvaluationForm.value.itemCompletionFactor = numValue;
- } else {
- // 当超出范围时,设置实际值为边界值
- selfEvaluationForm.value.itemCompletionFactor = numValue > 1 ? 1 : 0;
- }
-
- // 更新可自评总分显示
- //updateSelfEvaluatedTotalScore();
- }
- }
- calculateScores();
- }
- // 获取分项完成系数显示值
- function getItemCompletionFactorDisplayValue(): string {
- // 优先返回临时输入值,确保输入过程中的显示与用户操作一致
- if (tempItemCompletionFactorInput.value != null && tempItemCompletionFactorInput.value != '') {
- return tempItemCompletionFactorInput.value;
- }
-
- // 否则返回格式化后的数值
- const value = selfEvaluationForm.value.itemCompletionFactor;
- if (value == null) {
- return '';
- }
-
- if (typeof value == 'number') {
- return value.toString();
- }
-
- return value as string;
- }
- // 格式化分项完成系数和输入值
- function formatItemCompletionFactorSum() {
- const tempValue = tempItemCompletionFactorSumInput.value;
- let finalValue: number | null = null; // 明确定义类型
-
- if (tempValue.endsWith('.')) {
- // 如果以点结尾,去除点号
- const processedValue = tempValue.slice(0, -1);
-
- if (processedValue != '') {
- const numValue = parseFloat(processedValue);
-
- if (!isNaN(numValue) && isFinite(numValue)) {
- if (numValue >= 0 && numValue <= 1) {
- finalValue = numValue;
- } else {
- finalValue = numValue > 1 ? 1 : 0; // 根据数值大小决定边界值
- }
- } else {
- finalValue = 1; // 默认值
- }
- } else {
- // 去掉点后为空,设为null
- finalValue = null;
- }
- } else {
- // 正常数值处理
- const currentValue = selfEvaluationForm.value.itemCompletionFactorSum;
- if (currentValue != null && typeof currentValue == 'number') {
- // 格式化小数位数
- const currentStr = currentValue.toString();
- const parts = currentStr.split('.');
- if (parts.length > 1 && parts[1] != null && parts[1].length > 2) {
- // 创建一个局部变量确保类型安全
- const valueToFormat: number = currentValue;
- finalValue = parseFloat(valueToFormat.toFixed(2));
- } else {
- finalValue = currentValue;
- }
- }
- }
-
- // 更新数值
- selfEvaluationForm.value.itemCompletionFactorSum = finalValue;
-
- // 同步更新临时输入值为格式化后的字符串显示
- if (finalValue != null) {
- tempItemCompletionFactorSumInput.value = finalValue.toString();
- } else {
- tempItemCompletionFactorSumInput.value = '';
- }
- }
- function onItemCompletionFactorSumInput(e: UniInputEvent) {
- const value = e.detail?.value as string;
- // 更新临时输入值
- tempItemCompletionFactorSumInput.value = value;
-
- // 检查输入值是否为空
- if (value == '') {
- selfEvaluationForm.value.itemCompletionFactorSum = null;
- } else {
- // 检查是否为中间输入状态(如 '0.' 等以点结尾的数字)
- if (value.endsWith('.')) {
- // 如果是中间输入状态,不更新数值,保持原有值
- return;
- }
-
- // 验证输入值是否为有效数字
- const numValue = parseFloat(value);
- if (!isNaN(numValue) && isFinite(numValue)) {
- if( numValue >= 0 && numValue <= 1){
- // 在input事件中直接使用解析后的数值
- selfEvaluationForm.value.itemCompletionFactorSum = numValue;
- } else {
- // 当超出范围时,设置实际值为边界值
- selfEvaluationForm.value.itemCompletionFactorSum = numValue > 1 ? 1 : 0;
- }
- }
- }
- }
- // 获取分项完成系数和显示值
- function getItemCompletionFactorSumDisplayValue(): string {
- // 优先返回临时输入值,确保输入过程中的显示与用户操作一致
- if (tempItemCompletionFactorSumInput.value != null && tempItemCompletionFactorSumInput.value != '') {
- return tempItemCompletionFactorSumInput.value;
- }
-
- // 否则返回格式化后的数值
- const value = selfEvaluationForm.value.itemCompletionFactorSum;
- if (value == null) {
- return '';
- }
-
- if (typeof value == 'number') {
- return value.toString();
- }
-
- return value as string;
- }
- // 额外工作总结变化
- function onExtraWorkChange() {
- // 更新额外工作总结状态标志
- // 使用更严格的检查,包括检查长度
- let extraWorkStr = '';
- if (selfEvaluationForm.value.extraWork != null) {
- extraWorkStr = selfEvaluationForm.value.extraWork;
- }
- const trimmedStr = extraWorkStr.trim();
- const newHasExtraWork = trimmedStr.length > 0;
- hasExtraWorkFlag.value = newHasExtraWork;
-
- // 如果额外工作总结为空,则清空额外工分和总分字段
- if (trimmedStr.length == 0) {
- // 清空所有人员的额外工分和总分
- const scorePersonList = selfEvaluationForm.value.scorePersonList as UTSJSONObject[]
- for (let i = 0; i < scorePersonList.length; i++) {
- const person = scorePersonList[i]
- person.set('extraScore', 0)
- // 重新计算总分(此时额外工分为空,所以总分等于自评分)
- const selfScoreVal = person.get('selfScore');
- if (selfScoreVal != null) {
- const selfScore = typeof selfScoreVal == 'number' ? selfScoreVal : (selfScoreVal != '' ? parseFloat(selfScoreVal as string) : 0);
- if (!isNaN(selfScore)) {
- person.set('totalScore', selfScore);
- } else {
- person.set('totalScore', 0);
- }
- } else {
- person.set('totalScore', 0);
- }
- }
- }
-
- // 更新已自评总分显示
- updateSelfEvaluatedTotalScore()
-
- // 当额外工作总结变化时,可能需要重新计算总分
- updateTotalScores()
- }
- // 额外工作总结输入处理
- function onExtraWorkInput(e: UniInputEvent) {
- const value = e.detail?.value;
- // 确保当值为null时设置为空字符串
- if (value == null) {
- selfEvaluationForm.value.extraWork = '';
- } else {
- selfEvaluationForm.value.extraWork = value.toString();
- }
- // 每次输入都触发变化处理
- onExtraWorkChange()
- }
- // 获取人员评分
- function getPersonScore(person: UTSJSONObject, field: string): string {
- const value = person.get(field as string)
- if (value == null || value == '' || (typeof value == 'number' && isNaN(value))) {
- return ''
- }
- // 统一处理为字符串返回给UI
- if (typeof value == 'number') {
- const stringValue = value.toString();
- return stringValue;
- //return value.toFixed(2);
- }
- return value as string
- }
- // 设置人员评分
- function setPersonScore(person: UTSJSONObject, field: string, value: string) {
- person.set(field as string, value)
- }
- // 通用评分输入处理
- function onScoreInput(e: UniInputEvent, index: number, field: string) {
- const value = e.detail?.value as string
-
- if (index >= 0 && index < selfEvaluationForm.value.scorePersonList.length) {
- const person = selfEvaluationForm.value.scorePersonList[index] as UTSJSONObject
- if (person != null) {
- // 将输入的字符串转换为数字存储
- const numericValue = value == '' ? null : parseFloat(value);
- person.set(field, (numericValue != null && isNaN(numericValue)) ? null : numericValue);
-
- // 实时验证评分
- if (value != '') {
- const validationError = validatePersonScore(value, field)
- if (validationError != null) { // 修复条件判断
- // 显示验证错误(在实际应用中,这里可以显示在界面上)
- console.warn(`评分验证错误: ${validationError}`)
- // 可以考虑用uni.showToast显示错误信息
- /* uni.showToast({
- title: validationError,
- icon: 'none',
- duration: 2000
- }) */
- }
- }
-
- updateTotalScores()
- updateSelfEvaluatedTotalScore()
- }
- }
- }
- // 格式化评分输入值
- function formatScoreInput(index: number, field: string) {
- if (index >= 0 && index < selfEvaluationForm.value.scorePersonList.length) {
- const person = selfEvaluationForm.value.scorePersonList[index] as UTSJSONObject
- if (person != null) {
- const value = person.get(field as string);
- if (typeof value == 'number') {
- // 检查数值的小数位数是否超过2位
- const parts = value.toString().split('.');
- if (parts.length > 1) { // 确保有小数部分
- const decimalPart = parts[1];
- if (decimalPart != null && decimalPart.length > 2) {
- // 如果小数位数超过2位,使用格式化后的值
- const formattedValue = parseFloat((value as number).toFixed(2));
- person.set(field as string, formattedValue);
- }
- }
- }
- }
- }
- }
- // 分数变化
- function onScoreChange() {
- updateTotalScores()
- updateSelfEvaluatedTotalScore() // 更新已自评总分显示
- }
- // 返回按钮事件
- function goBack() {
- uni.navigateBack()
- }
- // 提交自评
- async function submitSelfEvaluationForm(): Promise<void> {
- try {
- console.log('开始提交验证');
- // 使用完整的表单验证
- const validation = validateForm() as UTSJSONObject;
- const isValid = validation.get('valid') as boolean;
- const validationMsg = validation.get('message') as string;
- console.log('验证结果:', isValid, '消息:', validationMsg);
- console.log('验证结果类型:', typeof isValid, '是否为false:', isValid == false);
- if (!isValid) {
- console.log('验证失败,显示错误:', validationMsg);
- // 在iOS平台中,有时需要稍作延迟才能正确显示toast
- setTimeout(() => {
- uni.showToast({
- title: validationMsg,
- icon: 'none'
- });
- }, 50);
- return;
- }
-
- uni.showLoading({
- title: '提交中...'
- })
-
- // 创建新的UTSJSONObject来存储表单数据
- const formValue = new UTSJSONObject();
-
- // 复制基本字段
- formValue.set('id', selfEvaluationForm.value.id);
- formValue.set('orderType', selfEvaluationForm.value.orderType);
- formValue.set('workOrderProjectNo', selfEvaluationForm.value.workOrderProjectNo);
- formValue.set('pcsDeviceName', selfEvaluationForm.value.pcsDeviceName);
- formValue.set('pcsStationName', selfEvaluationForm.value.pcsStationName);
- formValue.set('workSummary', selfEvaluationForm.value.workSummary);
- formValue.set('extraWork', selfEvaluationForm.value.extraWork);
- formValue.set('maintenanceType', selfEvaluationForm.value.maintenanceType);
- formValue.set('itemCompletionFactor', selfEvaluationForm.value.itemCompletionFactor);
- formValue.set('itemCompletionFactorSum', selfEvaluationForm.value.itemCompletionFactorSum);
- formValue.set('wwryNum', selfEvaluationForm.value.wwryNum);
- formValue.set('wlryNum', selfEvaluationForm.value.wlryNum);
-
- // 处理inspectionType字段:如果是数组则转换为字符串
- if (Array.isArray(selfEvaluationForm.value.inspectionType)) {
- const strValue = (selfEvaluationForm.value.inspectionType as string[]).join(',');
- formValue.set('inspectionType', strValue);
- } else {
- formValue.set('inspectionType', selfEvaluationForm.value.inspectionType);
- }
-
- // 复制scorePersonList数组
- const scorePersonListArray: UTSJSONObject[] = [];
- for (let i = 0; i < selfEvaluationForm.value.scorePersonList.length; i++) {
- const person = selfEvaluationForm.value.scorePersonList[i];
- // 将UTSJSONObject添加到数组中
- scorePersonListArray.push(person);
- }
- formValue.set('scorePersonList', scorePersonListArray);
- const response: any = await submitSelfEvaluation(formValue);
-
- const resultObj = response as UTSJSONObject
- const code = resultObj.get('code' as string) as number
-
- if (code == 200) {
- uni.showToast({
- title: '自评提交成功',
- icon: 'success'
- })
-
- // 设置标记,通知上一个页面需要刷新数据
- uni.setStorageSync('needRefresh', true)
-
- // 延迟返回上一页
- setTimeout(() => {
- uni.navigateBack()
- }, 1000)
- } else {
- const msg = resultObj.get('msg' as string) as string | null
- uni.showToast({
- title: msg ?? '提交失败',
- icon: 'none'
- })
- }
- } catch (error: any) {
- console.error('提交自评失败:', error)
- let msg: string | null = null
- if (error instanceof Error) {
- msg = error.message
- } else if (error instanceof UTSJSONObject && error.get('message') != null) {
- msg = error.get('message') as string
- }
- uni.showToast({
- title: msg ?? '提交失败',
- icon: 'none'
- })
- } finally {
- uni.hideLoading()
- }
- }
- // 页面初始化
- onLoad((options: any) => {
- const params = options as UTSJSONObject
- id.value = (params.get('id') != null ? params.get('id') as string : '')
- orderType.value = (params.get('orderType') != null ? params.get('orderType') as string : '')
-
-
- console.log("id.value==",id.value)
- console.log("orderType.value==",orderType.value)
- // 加载字典数据
- loadDictData()
- // 加载工单详情
- loadOrderDetail()
- })
-
- </script>
- <style lang="scss">
- .container {
- flex: 1;
- background-color: #e8f0f9;
- //height: 100vh;
- }
- .header {
- padding: 30rpx;
- text-align: center;
- }
- .title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- }
- .form {
- padding: 0 30rpx 30rpx;
- }
- .info-card {
- background-color: #ffffff;
- border-radius: 16rpx;
- padding: 30rpx;
- margin-bottom: 20rpx;
- }
- .info-item {
- flex-direction: row;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #f0f0f0;
- &:last-child {
- border-bottom: none;
- }
- .info-label {
- width: 240rpx;
- font-size: 28rpx;
- color: #666666;
- white-space: nowrap;
- }
- .info-value {
- flex: 1;
- font-size: 28rpx;
- color: #333333;
- text-align: right;
- }
-
- .info-input {
- flex: 1;
- font-size: 28rpx;
- color: #333333;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- padding: 10rpx;
- text-align: right;
- }
- }
- .form-item {
- margin-bottom: 30rpx;
- display: flex;
- flex-direction: column;
- }
- .label {
- font-size: 28rpx;
- color: #666;
- margin-bottom: 10rpx;
- font-weight: bold;
- }
- .value {
- font-size: 28rpx;
- color: #333;
- }
- .textarea {
- width: 100%;
- height: 200rpx;
- border: 1rpx solid #e5e5e5;
- border-radius: 8rpx;
- padding: 20rpx;
- font-size: 28rpx;
- color: #333;
- }
- .picker {
- width: 100%;
- }
- .picker-display {
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- padding: 10rpx;
- border: 1rpx solid #e5e5e5;
- border-radius: 8rpx;
- }
- .selected-value {
- font-size: 28rpx;
- color: #333;
- }
- .placeholder {
- font-size: 28rpx;
- color: #999;
- }
- .arrow {
- font-size: 24rpx;
- color: #999;
- }
- .selected-values {
- display: flex;
- flex-wrap: wrap;
- //gap: 10rpx;
- }
- .selected-value-tag {
- background-color: #f0f0f0;
- padding: 8rpx 16rpx;
- border-radius: 20rpx;
- font-size: 24rpx;
- color: #666;
- }
- .person-score-item {
- margin-bottom: 30rpx;
- padding: 20rpx;
- background-color: #f8f9fa;
- border-radius: 12rpx;
- }
- .person-info {
- margin-bottom: 15rpx;
- }
- .person-name {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- }
- .score-inputs {
- display: flex;
- flex-direction: column;
- //gap: 15rpx;
- }
- .score-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- }
- .score-label {
- font-size: 26rpx;
- color: #666;
- width: 120rpx;
- flex-shrink: 0;
- }
- .score-input {
- flex: 1;
- height: 60rpx;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- padding: 0 15rpx;
- font-size: 26rpx;
- color: #333;
- text-align: right;
- }
- .submit-btn {
- margin-top: 40rpx;
- height: 80rpx;
- background-color: #165DFF;
- border-radius: 10rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .submit-text {
- font-size: 32rpx;
- color: #fff;
- font-weight: bold;
- }
- /* 自定义选择器样式 */
- .picker-modal {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 1000;
- }
- .modal-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- }
- .modal-content {
- position: absolute;
- bottom: 0;
- left: 0;
- right: 0;
- background-color: #ffffff;
- border-top-left-radius: 16rpx;
- border-top-right-radius: 16rpx;
- min-height: 700rpx;
- }
- .modal-header {
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .modal-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- }
- .modal-close {
- font-size: 28rpx;
- color: #165DFF;
- }
- .modal-body {
- max-height: 600rpx;
- }
- .picker-option {
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- padding: 24rpx 30rpx;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .picker-option.selected {
- background-color: #f8f9fa;
- }
- .option-text {
- font-size: 28rpx;
- color: #333333;
- }
- .option-check {
- font-size: 28rpx;
- color: #165DFF;
- }
- .form-picker {
- flex: 1;
- }
- .picker-display {
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- min-height: 40rpx;
- }
- .selected-value {
- font-size: 28rpx;
- color: #333333;
- }
- .placeholder {
- font-size: 28rpx;
- color: #999999;
- }
- .arrow {
- font-size: 24rpx;
- color: #999999;
- margin-left: 12rpx;
- }
- </style>
|