| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459 |
- <template>
- <el-dialog v-model="visible" :title="isView ? '查看' : isCollect ? '领取' : '归还'" width="75%" :close-on-click-modal="false" @close="onCancel">
- <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
- <el-tab-pane label="借用单信息" name="first">
- <el-form :model="form" label-width="110px" label-position="top" :rules="rules" ref="formRef">
- <el-row :gutter="16">
- <el-col :span="8">
- <el-form-item label="借用单编号" prop="application_no">
- <el-input v-model="form.application_no" placeholder="自动生成" disabled />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="借用人类型" prop="borrower_type">
- <el-select v-model="form.borrower_type" :placeholder="isView?'':'请选择借用人角色'" :disabled="true">
- <el-option label="管理员用户" :value=0 />
- <el-option label="应用用户" :value=1 />
- <el-option label="外部用户" :value=2 />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8" >
- <!-- <el-form-item label="借用人" prop="external_borrower_name" v-if="form.borrower_type !== 2">
- <el-input v-model="form.borrower_info.name" placeholder="请输入借用人" :disabled="true" />
- </el-form-item> -->
- <el-form-item label="借用人" prop="admin_borrower" v-if="form.borrower_type == 0">
-
- <el-select v-model="form.admin_borrower" :placeholder="isView?'':'请选择借用人'" :disabled="true" >
- <el-option :label="adminList.name" :value="adminList.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="借用人" prop="app_user_borrower" v-if="form.borrower_type == 1">
- <el-select v-model="form.app_user_borrower.id" :placeholder="isView?'':'请选择借用人'" :disabled="true" >
- <el-option v-for="item in allUserList" :key="item.id" :label="item.name" :value="item.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="借用人" prop="external_borrower_name" v-if="form.borrower_type == 2">
- <el-input v-model="form.external_borrower_name" :placeholder="isView?'':'请输入借用人'" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="8" v-if="form.borrower_type !== 2">
- <el-form-item label="学号/工号" prop="user_code" >
- <!-- {{ form.borrower_info.user_code }} -->
- <el-input v-model="form.app_user_borrower.user_code" :placeholder="isView?'':'请输入学号/工号'" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="联系电话" v-if="form.borrower_type !== 2">
- <el-input v-model="form.app_user_borrower.mobile" :placeholder="isView?'':'请输入联系电话'" :disabled="true" />
- </el-form-item>
- <el-form-item label="联系电话" v-if="form.borrower_type == 2">
- <el-input v-model="form.external_borrower_phone" :placeholder="isView?'':'请输入联系电话'" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="借用部门" prop="borrower_dept">
- <el-input v-model="form.borrower_dept" placeholder="请输入借用部门" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="预计归还时间" prop="expected_end_time">
- <el-date-picker v-model="form.expected_end_time" type="date"
- format="YYYY-MM-DD"
- value-format="YYYY-MM-DD"
- :disabledDate="disabledDate" placeholder="请选择预计归还时间" style="width: 100%" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="4">
- <el-form-item label="个人/团队" prop="team_type" >
- <el-select v-model="form.team_type" placeholder="请选择" :disabled="true">
- <el-option label="个人" :value="0" />
- <el-option label="团队" :value="1" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="4" v-show="form.team_type===1">
- <el-form-item label="团队人数" prop="team_members_count">
- <el-input v-model="form.team_members_count" :placeholder="isView?'':'请输入'" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="16" v-show="form.team_type===1">
- <el-form-item label="团队其他人员名单" prop="team_members">
- <el-input v-model="form.team_members" :placeholder="isView?'':'请输入团队其他人员名单'" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item label="借用原因" prop="purpose">
- <el-input v-model="form.purpose" type="textarea" :placeholder="isView?'':'请输入借用原因'" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="4">
- <!-- ||form.approver_info.name -->
- <el-form-item label="审批人" prop="applicant_remark_type">
- <el-select v-model="form.approver_info.name" placeholder="请选择" :disabled="true" >
- <el-option label="管理员" value="1"/>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="20">
- <el-form-item label="备注" prop="applicant_remark">
- <el-input v-model="form.applicant_remark" :placeholder="isView?'':'请输入备注'" :disabled="true"/>
- </el-form-item>
- </el-col>
- </el-row>
- <div style="margin: 16px 0 8px 0; font-weight: bold"> {{ isView ? '借用列表' : (isCollect ? '借用列表' : '归还列表') }}</div>
- <el-table :data="form.items.filter(item => item.device === null)" border style="width: 50%; margin-bottom: 12px">
- <el-table-column type="index" label="序号" width="60" />
- <el-table-column prop="device_category_name" label="设备分类" />
- <el-table-column :label="isView ? '数量' : (isCollect ? '借用数量' : '归还数量')">
- <template #default="{ row }">
- <el-input v-model="row.quantity" type="number" :min="1" prop="quantity" size="small" :disabled="true" />
- </template>
- </el-table-column>
- <el-table-column label="操作" width="80">
- <template #default="{ $index }">
- <el-button type="text" style="color: red" @click="removeItem($index)" :disabled="true">移除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-button type="primary" @click="addItem" v-if="!isView" :disabled="true">选择设备分类</el-button>
- <div style="margin: 16px 0 8px 0; font-weight: bold">预借配件信息</div>
- <el-input v-model="form.accessories" :placeholder="isView?'':'请输入预借配件信息'" :disabled="true"/>
- <div style="margin: 16px 0 8px 0; font-weight: bold" >附件</div>
- <!-- <el-upload
- action="#"
- drag
- :list-type="'picture'"
- accept=".bmp,.gif,.jpeg,.jpg,.png,.webp,.svg"
- multiple
- :show-file-list="true"
- :file-list="attachmentFileList"
- :on-success="handleUploadSuccess"
- :on-error="handleUploadError"
- :disabled="true"
- >
- <i class="el-icon-upload"></i>
- <div class="el-upload__text">将文件拖到此处,或 <em>点击上传</em></div>
- </el-upload> -->
- <el-upload
- :disabled="true"
- action="#"
- list-type="picture-card"
- :on-preview="handlePictureCardPreview"
- :on-remove="handleRemoves"
- :file-list="attachmentFileList"
- >
- <el-icon><Plus /></el-icon>
- </el-upload>
- <div v-if="isView && form.latest_renewal" style="margin-top: 8px;">
- <div style="font-weight: bold; margin-bottom: 8px">续借信息</div>
- <el-row :gutter="16">
- <el-col :span="4">
- <el-form-item label="续借天数">
- <el-input :model-value="form.latest_renewal?.renewal_days" :disabled="true">
- <template #append>天</template>
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="21">
- <el-form-item label="续借理由">
- <el-input :model-value="form.latest_renewal?.renewal_reason" type="textarea" :disabled="true" />
- </el-form-item>
- </el-col>
- </el-row>
- </div>
- </el-form>
-
- <!-- 审批信息流程展示 -->
- <!-- <div v-if="isView" style="margin-top: 24px; padding: 0 12px">
- <div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
- <el-steps :active="activeStep" align-center>
- <el-step
- title="创建申请"
- :description="`创建时间:${ timeline.create }`"
- icon="CircleCheck"
- :status="activeStep >= 1 ? 'finish' : 'wait'"
- />
- <el-step
- title="待审批"
- description="待审批人审批"
- icon="CircleCheck"
- :status="activeStep >= 2 ? 'finish' : 'wait'"
- />
- <el-step
- title="审批通过"
- :description="`审批人:${timeline.approver},时间:${timeline.approve}`"
- icon="CircleCheck"
- :status="activeStep >= 3 ? 'finish' : 'wait'"
- />
- <el-step
- title="流程完成"
- description="流程已结束"
- icon="CircleCheck"
- :status="activeStep >= 4 ? 'finish' : 'wait'"
- />
- </el-steps>
- </div> -->
- <div v-if="isView" style="margin-top: 24px; padding: 0 12px">
- <div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
- <el-steps :active="steps.length" align-center>
- <el-step
- v-for="(step, index) in steps"
- :key="index"
- :title="step.title"
- :description="step.description"
- icon="CircleCheck"
- :status="step.status"
- />
- </el-steps>
- </div>
- </el-tab-pane>
- <el-tab-pane v-if="isCollect && !shouldHideDeviceList" label="设备清单" name="second">
- <el-form :model="form" label-width="110px">
- <el-row :gutter="16">
- <el-col :span="24">
- <div style="margin: 8px 0">
- <textarea
- ref="searchInputRef"
- v-model="searchText"
- class="device-code-input"
- placeholder="设备编号(支持扫码枪/RFID批量录入)"
- :disabled="loading"
- autocomplete="off"
- rows="1"
- style="width: 300px; vertical-align: top;"
- @input="handleDeviceInput"
- @keydown="handleRFIDKeydown"
- @blur="handleDeviceBlur"
- @keydown.enter.prevent="handleDeviceEnter"
- ></textarea>
- <el-button type="primary" style="margin-left: 16px" @click="handleAdd">手动借用</el-button>
- </div>
- <el-table :data="deviceList" border style="width: 100%">
- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="device_code" label="设备编号" align="center" />
- <el-table-column prop="device_type" label="设备分类" align="center" />
- <el-table-column prop="device_name" label="设备名称" align="center" />
- <el-table-column prop="borrow_count" label="借用数量" align="center" width="150">
- <template #default="{ row }">
- <el-input-number v-model="row.borrow_count" :disabled="isView" :min="1" :max="row.available_quantity" size="small" />
- </template>
- </el-table-column>
- <el-table-column prop="brand" label="品牌" align="center" />
- <el-table-column prop="device_specification" label="规格型号" align="center" />
- <!-- <el-table-column prop="warehouse" label="存放仓库" align="center" /> -->
- <el-table-column label="操作" width="80" align="center">
- <template #default="{ $index }">
- <el-button type="text" style="color: red" :disabled="isView" @click="handleRemove($index)">移除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="24">
- <div style="font-weight: bold; margin-bottom: 8px">实借配件信息</div>
- <el-input v-if="isCollect" v-model="collectAccessories" :disabled="isView" type="textarea" :placeholder="isView?'':'请输入实借配件信息'" />
- <el-input v-else v-model="form.pre_borrow_accessories" :disabled="isView" type="textarea" :placeholder="isView?'':'请输入实借配件信息'" />
- </el-col>
- <el-col :span="24" style="margin-top: 16px">
- <div style="font-weight: bold; margin-bottom: 8px">备注</div>
- <el-input v-model="remark" type="textarea" :disabled="isView" :placeholder="isView?'':'请输入备注'" />
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="24">
- <div style="font-weight: bold; margin-bottom: 8px">异常记录 <span>{{
- abnormalList?.length ?
- abnormalList.reduce((sum, item) => sum + (Number(item?.condition) || 0), 0)
- : 0
- }}</span> 次</div>
- <el-table v-if="abnormalList.length > 0" :data="abnormalList" border style="width: 100%">
- <!-- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="application_no" label="借用单编号" align="center" /> -->
- <el-table-column prop="operator_name" label="借用人" align="center" />
- <el-table-column prop="user_code" label="学号" align="center" />
- <el-table-column prop="emergency_phone" label="借用人电话" align="center" />
- <!-- <el-table-column prop="time" label="发生时间" align="center" /> -->
- <el-table-column prop="type" label="异常" align="center">
- <template #default="{ row }">
- {{ row.type }}
- </template>
- </el-table-column>
- <el-table-column prop="condition" label="数量" align="center">
- <template #default="{ row }">
- {{ row.condition }}
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- </el-form>
- </el-tab-pane>
- <el-tab-pane v-else-if="!shouldHideDeviceList" label="设备清单" name="third">
- <el-form :model="form" label-width="110px">
- <el-row :gutter="16">
- <el-col :span="24">
- <div style="margin: 8px 0" v-if="!isView" >
- <textarea
- ref="returnSearchInputRef"
- v-model="returnSearchText"
- class="device-code-input"
- placeholder="设备编号(支持扫码枪/RFID批量录入)"
- :disabled="loading"
- autocomplete="off"
- rows="1"
- style="width: 300px; vertical-align: top;"
- @input="handleReturnDeviceInput"
- @keydown="handleReturnRFIDKeydown"
- @blur="handleReturnDeviceBlur"
- @keydown.enter.prevent="handleReturnDeviceEnter"
- ></textarea>
- <el-button type="primary" style="margin-left: 16px" @click="handleAdd" :disabled="isView">手动归还</el-button>
- </div>
- <el-table :data="returnDeviceList" border style="width: 100%" >
- <!-- <el-table-column type="selection" width="55" align="center" />@selection-change="handleSelectionChange" -->
- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="device_code" label="设备编号" align="center" />
- <!-- <el-table-column prop="device_type" label="设备分类" align="center" /> -->
- <el-table-column prop="device_name" label="设备名称" align="center" />
- <el-table-column prop="borrow_count" label="借用数量" align="center" width="150">
- <template #default="{ row }">
- <el-input-number v-model="row.borrow_count" :min="1" :max="row.available_quantity" size="small" :disabled="true" />
- </template>
- </el-table-column>
- <el-table-column prop="brand" label="品牌" align="center" />
- <el-table-column prop="model" label="规格型号" align="center" />
- <!-- <el-table-column prop="warehouse" label="存放仓库" align="center" /> -->
- <el-table-column prop="status" label="状态" align="center">
- <template #default="{ row }">
- {{ row.return_status.label }}
- <!-- <el-tag v-if="!isView" :type="row.status === '已归还' ? 'success' : 'warning'">{{ row.status }}</el-tag>
- <el-tag v-else-if="['已领取', '已归还'].includes(form.status_label)">{{ form.status_label }}</el-tag> -->
- <!-- <span v-else>{{ form.status_label }}</span> -->
- </template>
- </el-table-column>
- <el-table-column prop="status" label="归还时间" align="center">
- <template #default="{ row }">
- {{ row.return_time ? dayjs(row.return_time).format('YYYY-MM-DD HH:mm:ss') : (row.return_status?.label === '已归还' ? dayjs().format('YYYY-MM-DD HH:mm:ss') : '') }}
- </template>
- </el-table-column>
- <el-table-column label="操作" width="120" align="center">
- <template #default="{ $index,row }">
- <!-- && (!returnDeviceList[$index]?.condition || returnDeviceList[$index]?.photos?.length==0)&& row.problem_records?.length ==0 -->
- <el-button :disabled="isView" type="text" style="color: red;"
- v-if="!isView"
- @click="handleAbnormal($index)">异常操作</el-button>
- <el-button
-
- type="text"
- style="color: #409EFF;margin-left:0"
- @click="handleViewAbnormal($index)"
- v-if="row.problem_records?.length || (returnDeviceList[$index]?.condition || returnDeviceList[$index]?.photos?.length)"
- >查看异常</el-button>
- <!-- <el-button type="text" v-if="!isView" :disabled="isView" style="color: red" @click="handleReturnRemove($index)">移除</el-button> -->
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="16">
- <div style="font-weight: bold; margin-bottom: 8px">实借配件信息</div>
- <el-input v-model="form.pre_borrow_accessories" :disabled="true" :placeholder="isView?'':'请输入实借配件信息'" />
- </el-col>
- <el-col :span="8">
- <div style="font-weight: bold; margin-bottom: 8px">当前状态</div>
- <el-input v-model="returnStatus" v-if="!isView" :disabled="true" placeholder="" style="width: 150px" />
- <el-input :value="form.status==7?'已归还':returnStatus" v-else :disabled="true" placeholder="" style="width: 150px" />
- <el-button type="primary" v-if="!isView" style="margin-left: 16px" @click="clickReturn"
- :disabled="returnStatus=='已归还'||isView">归还</el-button>
- </el-col>
- <el-col :span="24" style="margin-top: 16px">
- <div style="font-weight: bold; margin-bottom: 8px">备注</div>
- <el-input
- v-model="displayReturnRemark"
- type="textarea"
- :disabled="isView"
- :placeholder="isView?'':'请输入备注'"
- />
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="24">
- <div style="font-weight: bold; margin-bottom: 8px">异常记录 <span>{{
- returnAbnormalList?.length ?
- returnAbnormalList.reduce((sum, item) => sum + (Number(item?.condition) || 0), 0)
- : 0
- }}</span> 次</div>
- <el-table v-if="returnAbnormalList?.length > 0" :data="returnAbnormalList" border style="width: 100%">
- <!-- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="application_no" label="借用单编号" align="center" /> -->
- <el-table-column prop="operator_name" label="借用人" align="center" />
- <el-table-column prop="user_code" label="学号" align="center" />
- <el-table-column prop="emergency_phone" label="借用人电话" align="center" />
- <!-- <el-table-column prop="time" label="发生时间" align="center" /> -->
- <el-table-column prop="type" label="异常" align="center">
- <template #default="{ row }">
- {{ row.type }}
- </template>
- </el-table-column>
- <el-table-column prop="condition" label="数量" align="center">
- <template #default="{ row }">
- {{ row.condition }}
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- </el-form>
- </el-tab-pane>
- </el-tabs>
- <template #footer>
- <el-button @click="onCancel">关闭</el-button>
- <el-button type="primary" @click="onSubmit" v-if="!isView"> {{ isCollect ? '提交' : '确认' }}</el-button>
- </template>
- </el-dialog>
- <SelectDeviceDialog
- v-model:visible="showSelectDeviceDialog"
- @confirm="onDeviceSelected"
- :device-ids="unreturnedDeviceIds"
- :return-mode="activeName === 'third'"
- :device-status-map="deviceStatusMap"
- :selected-device-codes="selectedDeviceCodes"
- :disabled-device-ids="disabledDeviceIds"
- />
- <SettlementDialog v-model:visible="showSettlementDialog" :settlement-data="settlementData" :modelValue="borrowForm" />
- <AbnormalDialog v-model:visible="showAbnormalDialog" @confirm="onAbnormalConfirm" />
- <ViewAbnormalDialog
- v-model:visible="showViewAbnormalDialog"
- :abnormal-data="currentAbnormalData"
- />
- <!-- 图片预览对话框 -->
- <el-dialog v-model="dialogVisible" title="图片预览" width="auto" center>
- <img width="100%" :src="dialogImageUrl" alt="Preview Image" style="max-width: 100%; max-height: 80vh;" />
- </el-dialog>
- </template>
- <script setup lang="ts">
- import { ref, watch, defineProps, defineEmits, onMounted, onBeforeUnmount, computed, nextTick } from 'vue';
- import SelectDeviceDialog from './SelectDeviceDialog/index.vue';
- import SettlementDialog from './SettlementDialog.vue';
- import AbnormalDialog from './AbnormalDialog/index.vue';
- import ViewAbnormalDialog from './ViewAbnormalDialog/index.vue';
- import dayjs from 'dayjs';
- import { ElMessage } from 'element-plus';
- import * as api from '../../api';
- import * as deviceApi from '../../../device/api';
- import { CollectEquipment, ReturnEquipment } from '../../api';
- import type { TabsPaneContext } from 'element-plus';
- import { getUserInfo } from '../../../login/api';
- import { request } from '/@/utils/service';
- // 禁止选择今天之前的日期
- const disabledDate = (time: Date) => {
- // 获取今天的开始时间(准确到日)
- const today = new Date()
- today.setHours(0, 0, 0, 0)
- // 返回true表示禁用,禁用今天之前的所有日期
- return time.getTime() < today.getTime()
- }
- /* 获取管理员列表 */
- const adminList = ref([]);
- async function getAdminList() {
- const res = await getUserInfo();
- adminList.value = res.data;
- console.log("adminList.value:::",adminList.value)
- }
- /* */
- /* 获取所有用户 */
- const allUserList = ref([]);
- let allUserLoaded = false;
- const allUserLoading = ref(false);
- async function getAllUserList() {
- if (allUserLoaded || allUserLoading.value) return;
- allUserLoading.value = true;
- try {
- // 分页拉取,避免一次性超大 limit 硬编码
- const pageSize = 100;
- let page = 1;
- const users: any[] = [];
- while (true) {
- const res = await api.GetAllUser({ page, limit: pageSize });
- const list = Array.isArray(res?.data) ? res.data : [];
- users.push(...list);
- if (list.length < pageSize) break;
- page += 1;
- }
- allUserList.value = users;
- // 设置默认选择(仅在当前未有选中时)
- if ((!form.value.app_user_borrower || !form.value.app_user_borrower.id) && allUserList.value.length > 0) {
- const first: any = allUserList.value[0];
- form.value.app_user_borrower = {
- id: first.id,
- name: first.name,
- user_code: first.user_code,
- mobile: first.mobile
- };
- }
- allUserLoaded = true;
- } catch (e) {
- /* empty */
- } finally {
- allUserLoading.value = false;
- }
- }
- interface ApiResponse {
- code: number;
- data?: any;
- message?: string;
- }
- // 用户最小结构用于表单回显
- interface AppUserBorrower {
- id: number | string;
- name?: string;
- user_code?: string;
- mobile?: string;
- }
- // 定义接口
- interface Device {
- id: string | number;
- category_name: string;
- name?: string;
- brand?: string;
- model?: string;
- warehouse: string;
- device_specification?: string;
- device_name?: string;
- }
- interface DeviceListItem {
- device_no: string | number;
- device_code?: string;
- device_type: string;
- device_name?: string; // 改为可选
- borrow_count: number;
- brand: string;
- model?: string; // 改为可选
- warehouse: string;
- status?: string;
- return_status?: {
- value?: number;
- label?: string;
- };
- return_time?: string;
- is_return?: boolean;
- condition?: string;
- photos?: Array<{
- filename: string;
- data: string;
- }>;
- device_specification?: string;
- available_quantity?:number;
- }
- interface FormItem {
- device: string | number;
- remark: string;
- quantity: number;
- location: string;
- device_name?: string;
- device_specification?: string;
- condition?: string;
- photos?: Array<{
- filename: string;
- data: string;
- }>;
- }
- interface FormData {
- application_no: string;
- emergency_contact: string;
- emergency_phone: string;
- app_user_borrower: AppUserBorrower | any;
- team_type: number;
- team_members_count: number;
- team_members: string;
- expected_start_time: string;
- expected_end_time: string;
- borrower_dept: string;
- purpose: string;
- applicant_remark_type: string;
- applicant_remark: string;
- items: FormItem[];
- accessory_info: string;
- borrow_type: number;
- return_location: string;
- status_label?: string;
- id?: number;
- records?: any[];
- borrower_info?: {
- user_code: string;
- };
- borrower_damage_count?: number;
- borrower_overdue_count?:number;
- accessories?: string;
- pre_borrow_accessories?:string;
- latest_renewal?: {
- renewal_days?: number | string;
- renewal_reason?: string;
- };
- problem_remarks?: string[];
- }
- interface AbnormalData {
- damage_type:number;
- condition: string;
- photos: Array<{
- filename: string;
- data: string;
- }>;
- }
- interface AbnormalRecord {
- application_no: string;
- operator_name: string;
- user_code: string;
- emergency_phone: string;
- type: '损坏' | '逾期';
- condition: number;
- create_time: string;
- }
- const now = dayjs().format('YYYY-MM-DD HH:mm:ss');
- const props = defineProps<{ visible: boolean; modelValue?: any }>();
- const isEdit = computed(() => props.modelValue?.mode === 'edit');
- const isView = computed(() => props.modelValue?.mode === 'view');
- const isAdd = computed(() => props.modelValue?.mode === 'add');
- const isCollect = computed(() => props.modelValue?.mode === 'collect');
- const isReturn = computed(() => props.modelValue?.mode === 'return');
- // 计算是否应该隐藏设备清单标签页
- const shouldHideDeviceList = computed(() => {
- if (!isView.value) return false;
- // 检查状态
- const status = (form.value as any).status;
- const statusLabel = (form.value as any).status_label;
- // 审批拒绝:隐藏设备清单
- const isRejected = status === 3 || (typeof statusLabel === 'string' && statusLabel.includes('拒绝'));
- if (isRejected) {
- return true;
- }
- // 强制显示:状态大于 5 或状态标签为"已借出"
- if ((typeof status === 'number' && status > 5) || statusLabel === '已借出') {
- return false;
- }
- // 审批通过:隐藏设备清单(不影响已借出/更高级状态的强制显示)
- const isApproved = typeof statusLabel === 'string' && statusLabel.includes('已批准');
- if (isApproved) {
- return true;
- }
- // 待审批状态:隐藏设备清单
- const isPendingApproval = status < 2 || statusLabel === '待审批';
- // 其他情况默认显示
- return isPendingApproval;
- });
- // 计算设备状态映射
- const deviceStatusMap = computed(() => {
- const statusMap: Record<string | number, any> = {};
- returnDeviceList.value.forEach(device => {
- if (device.device_no && device.return_status) {
- statusMap[device.device_no] = device.return_status;
- }
- });
- return statusMap;
- });
- const emit = defineEmits(['update:visible', 'update:modelValue', 'submit']);
- const visible = ref(props.visible);
- const formRef = ref();
- // 图片预览相关
- const dialogImageUrl = ref('');
- const dialogVisible = ref(false);
- const timeline = ref({
- create: '',
- approve: '',
- approver: ''
- });
- // const activeStep = ref(1);
- const activeName = ref('first');
- const returnStatus = ref('未归还'); // 添加独立的状态变量
- // 输入框引用
- const searchInputRef = ref<any>(null);
- const returnSearchInputRef = ref<any>(null);
- // 借用列表相关数据
- const searchText = ref('');
- const deviceList = ref<DeviceListItem[]>([]);
- const accessoryInfo = ref('');
- const remark = ref('');
- // 领取模式下的"实借配件信息"本地输入,不回显历史
- const collectAccessories = ref('');
- // RFID高速扫码缓冲相关
- const rfidInputBuffer = ref('');
- let rfidInputTimer: ReturnType<typeof setTimeout> | null = null;
- const loading = ref(false);
- // 记录最后一次输入时间,用于检测是否是高速扫码输入
- let lastInputTime = 0;
- // 记录连续输入次数,用于判断是否是扫码输入
- let consecutiveInputCount = 0;
- // RFID读取规则配置(简化版,可根据需要扩展)
- const readRuleConfig = ref({
- enableRFIDBuffer: true, // 是否启用RFID缓冲
- rfidInputTimeout: 120, // RFID缓冲判定时间(ms)
- separator: ' ', // 分隔符
- minInputSpeed: 30, // 最小输入速度(ms),低于此值认为是扫码输入
- });
- // 归还设备相关数据
- const returnSearchText = ref('');
- const returnDeviceList = ref<DeviceListItem[]>([]);
- const returnAccessoryInfo = ref('');
- const returnRemark = ref('');
- const selectedDevices = ref<DeviceListItem[]>([]); // 添加选中设备列表
- // 归还流程 RFID高速扫码缓冲相关
- const returnRfidInputBuffer = ref('');
- let returnRfidInputTimer: ReturnType<typeof setTimeout> | null = null;
- // 记录归还流程最后一次输入时间,用于检测是否是高速扫码输入
- let returnLastInputTime = 0;
- // 记录归还流程连续输入次数,用于判断是否是扫码输入
- let returnConsecutiveInputCount = 0;
- // 备注显示值计算属性:查看模式下显示 problem_remarks[0],否则显示 returnRemark
- const displayReturnRemark = computed({
- get: () => {
- if (isView.value && form.value.problem_remarks?.[0]) {
- return form.value.problem_remarks[0];
- }
- return returnRemark.value;
- },
- set: (val: string) => {
- if (!isView.value) {
- returnRemark.value = val;
- }
- }
- });
- // 统一判定设备是否已归还
- const isDeviceReturned = (device: any) => {
- if (device?.is_return === true) return true;
- const rs = device?.return_status;
- if (rs && (rs.value === 2 || rs.label === '已归还')) return true;
- if (device?.status === '已归还') return true;
- return false;
- };
- // 过滤未归还设备的 device_no 列表,用于设备选择弹窗的排除
- const unreturnedDeviceIds = computed(() =>
- returnDeviceList.value
- .filter((d) => !isDeviceReturned(d))
- .map((d) => d.device_no)
- );
- // 是否全部已归还(仅在归还页签生效)
- const allReturned = computed(() => unreturnedDeviceIds.value.length === 0);
- //审批步骤
- const steps = ref<any[]>([]);
- // 仓库映射(id -> name)
- const warehouseMap = ref<Record<string, string>>({});
- async function loadWarehouses() {
- try {
- const res = await request({
- url: '/api/system/warehouse/',
- method: 'get',
- params: { page: 1, limit: 999 }
- });
- if (res?.code === 2000 && Array.isArray(res.data)) {
- warehouseMap.value = Object.fromEntries(
- res.data.map((w: any) => [String(w.id), w.name])
- );
- }
- } catch (e) {
- /* empty */
- }
- }
- function getWarehouseName(id: any) {
- const key = id != null ? String(id) : '';
- return warehouseMap.value[key] ?? id;
- }
- // 添加结算单相关的状态
- const showSettlementDialog = ref(false);
- const settlementData = ref<any>(null);
- const borrowForm = ref<any>(null);
- // 添加异常操作相关的状态
- const showAbnormalDialog = ref(false);
- const currentAbnormalIndex = ref(-1);
- // 添加查看异常相关的状态
- const showViewAbnormalDialog = ref(false);
- const currentAbnormalData = ref<AbnormalData>({
- damage_type:0,
- condition: '',
- photos: []
- });
- //审批
- function buildSteps(data: any) {
- steps.value = [
- {
- title: '创建申请',
- description: `创建时间:${data.create_datetime ? dayjs(data.create_datetime).format('YYYY-MM-DD HH:mm:ss') : ''}`,
- status: 'finish'
- },
- {
- title: '待审批',
- description: `待审批人:${data.approval_records ?
- (() => {
- console.log('approval_records:', data.approval_records); // 调试信息
- const names = data.approval_records
- .filter((item:any) => {
- // 当状态为待审批时,只显示未通过的审批记录(过滤掉已通过的记录)
- if (data.status === 1) {
- return item.status !== 1; // 过滤掉审批通过的记录
- }
- // 其他状态下保持原有逻辑
- return item.status !== 0;
- })
- .map((item:any) => {
- console.log('item:', item, 'approver_name:', item.approver_name); // 调试信息
- // 支持多种字段名
- return item.approver_name || item.app_user_approver_name || item.name;
- })
- .filter(name => name && name.trim()); // 过滤空值和空字符串
- console.log('filtered names:', names); // 调试信息
- return names.join('、') || data.approver_info.name;
- })()
- : '未知'} 审批`,
- status: data.status >= 2 ? 'finish' : 'process'
- }
- ];
- const approverinfo = data.approver_info ?? data.admin_approver_info
- if (data.status >= 2&&data.status!=3 && data.borrow_type!=1) {
- // 将审批记录倒序排列
- const reversedApprovalRecords = [...data.approval_records]
- // 先找出所有审批通过的记录
- const approvedRecords = reversedApprovalRecords.filter((item:any) => item.status === 1)
- const lastApprovedIndex = approvedRecords.length - 1
-
- reversedApprovalRecords.forEach((item:any,index:number) => {
- if(item.status === 1){
- // 找到当前记录在审批通过记录中的索引
- const currentApprovedIndex = approvedRecords.findIndex((record:any) => record === item)
- // 判断是否是最后一个审批通过的记录
- const isLastApproved = currentApprovedIndex === lastApprovedIndex
-
- /* if(index == 1){1
- steps.value.push({
- title: '审批通过',
- description: `审批人:${item.approver_name||item.app_user_approver_name},时 间:${item.approve_time}`,
- status: 'finish'
- });
- }else{ */
- // 只在最后一个审批通过的记录中显示领取仓库
- const warehouseInfo = isLastApproved ? `,领取仓库:${getWarehouseName(data.warehouse)||'暂无仓库'}` : ''
- steps.value.push({
- title: '审批通过',
- description: `审批人:${item.approver_name||item.app_user_approver_name},时 间:${item.create_datetime ? dayjs(item.create_datetime).format('YYYY-MM-DD HH:mm:ss') : ''}${warehouseInfo}`,
- status: 'finish'
- });
- /* } */
- }
- });
- } else if (data.status === 3) {
- // console.log("data.approver_name:::",data.approver_info.name)
- const rejectNames = data.approval_records
- .filter((item:any) => item.status === 2)
- .map((item:any) => item.approver_name || item.app_user_approver_name || item.name)
- .filter((name:any) => name && name.trim());
- const rejectReason = data.approval_records
- .filter((item:any) => item.status === 2)
- .map((item:any) => item.approve_remark)
- .filter((reason:any) => reason && reason.trim());
- const rejectTime = data.approval_records
- .filter((item:any) => item.status === 2)
- .map((item:any) => item.approve_time)
- .filter((time:any) => time && time.trim());
- steps.value.push({
- title: '审批拒绝',
- description: `审批人:${rejectNames.join('、')},拒绝原因: ${rejectReason.join('、')},时间:${rejectTime.join('、')}`,
- status: 'error'
- });
- }
- if (data.status >= 4 ||data.borrow_type==1) {
- steps.value.push({
- title: '流程完成',
- description: '流程已结束',
- status: 'finish'
- });
- }
- }
- // 处理异常操作
- const handleAbnormal = (index: number) => {
- currentAbnormalIndex.value = index;
- showAbnormalDialog.value = true;
- console.log("showAbnormalDialog:::", showAbnormalDialog.value, "currentAbnormalIndex:::", currentAbnormalIndex.value);
- };
- // 处理异常操作确认
- const onAbnormalConfirm = (data: { condition: string; photos: any[] }) => {
- console.log("异常操作确认数据:", data);
- if (currentAbnormalIndex.value !== -1) {
- const device = returnDeviceList.value[currentAbnormalIndex.value];
- device.condition = data.condition;
- device.photos = data.photos;
- device.damage_type = data.damage_type;
- ElMessage.success('异常信息已保存');
- }
- console.log("returnDeviceList.value:::",returnDeviceList.value);
- };
- // 处理查看异常
- const handleViewAbnormal = (index: number) => {
- const device = returnDeviceList.value[index];
- console.log("device:::",device);
- if (device) {
- if(device.problem_records?.length){
- console.log(device.problem_records?.[0].damage_type.value)
- currentAbnormalData.value = {
- damage_type: Number(device.problem_records?.[0].damage_type.value) || 0,/* ||device.damage_type.value */
- condition: device.problem_records?.[0].device_condition_after ||'',
- photos: device.problem_records?.[0].returned_images.map((item:any)=>item.image_url) ||[]
- };
- }else{
- currentAbnormalData.value = {
- damage_type: device.damage_type ||0,
- condition: device.condition ||'',
- photos: device.photos ||[]
- };
- }
- showViewAbnormalDialog.value = true;
- }
- };
- // 清理RFID输入定时器
- const clearRFIDInputTimer = () => {
- if (rfidInputTimer) {
- clearTimeout(rfidInputTimer);
- rfidInputTimer = null;
- }
- };
- // 清理归还流程RFID输入定时器
- const clearReturnRFIDInputTimer = () => {
- if (returnRfidInputTimer) {
- clearTimeout(returnRfidInputTimer);
- returnRfidInputTimer = null;
- }
- };
- // 提交RFID缓冲区内容
- const submitRFIDBuffer = () => {
- if (!readRuleConfig.value.enableRFIDBuffer) {
- // 如果未启用RFID缓冲,直接使用 searchText 进行搜索
- if (searchText.value.trim()) {
- handleScanSearch();
- }
- return;
- }
- if (!rfidInputBuffer.value) {
- // 如果没有缓冲内容,使用 searchText 进行搜索
- if (searchText.value.trim()) {
- handleScanSearch();
- }
- return;
- }
- const bufferedValue = rfidInputBuffer.value;
- rfidInputBuffer.value = '';
- clearRFIDInputTimer();
- consecutiveInputCount = 0; // 重置计数
- lastInputTime = 0; // 重置时间
- searchText.value = bufferedValue;
- handleScanSearch();
- };
- // 调度RFID缓冲区提交(延迟提交)
- const scheduleRFIDBufferSubmit = () => {
- if (!readRuleConfig.value.enableRFIDBuffer) return;
- clearRFIDInputTimer();
- const delay = Math.max(readRuleConfig.value.rfidInputTimeout || 120, 30);
- rfidInputTimer = setTimeout(() => {
- submitRFIDBuffer();
- }, delay);
- };
- // 处理设备输入(用于同步 textarea 内容,仅在缓冲模式下使用)
- const handleDeviceInput = () => {
- // 如果缓冲区有内容,确保 textarea 显示与缓冲区一致
- // 这主要用于处理退格键等操作后的同步
- if (rfidInputBuffer.value && searchText.value !== rfidInputBuffer.value) {
- searchText.value = rfidInputBuffer.value;
- }
- // 注意:正常输入时,不干预 textarea 的内容,让默认行为处理
- };
- // 检测是否是高速扫码输入(通过输入速度判断)
- // 返回值:{ isHighSpeed: boolean, isFirstInput: boolean, isNormalInput: boolean, timeSinceLastInput: number }
- const checkInputSpeed = () => {
- const now = Date.now();
- const timeSinceLastInput = lastInputTime > 0 ? now - lastInputTime : 0;
- const isFirstInput = lastInputTime === 0;
-
- if (!isFirstInput) {
- lastInputTime = now;
- }
-
- return {
- isFirstInput,
- timeSinceLastInput,
- isHighSpeed: timeSinceLastInput > 0 && timeSinceLastInput < readRuleConfig.value.minInputSpeed,
- isNormalInput: timeSinceLastInput > 200
- };
- };
- // 处理RFID键盘输入(高速扫码)
- const handleRFIDKeydown = (event: KeyboardEvent) => {
- // 如果未启用RFID缓冲,直接返回,不拦截
- if (!readRuleConfig.value.enableRFIDBuffer) {
- return;
- }
-
- // 不拦截修饰键组合(如 Ctrl+C, Ctrl+V 等)
- if (event.ctrlKey || event.metaKey || event.altKey) {
- return;
- }
-
- // 处理回车键
- if (event.key === 'Enter') {
- // 回车键由 @keydown.enter.prevent="handleDeviceEnter" 处理
- // 这里不处理,让 handleDeviceEnter 统一处理
- return;
- }
-
- // 处理退格键
- if (event.key === 'Backspace') {
- // 如果有缓冲内容,处理缓冲
- if (rfidInputBuffer.value) {
- event.preventDefault();
- rfidInputBuffer.value = rfidInputBuffer.value.slice(0, -1);
- searchText.value = rfidInputBuffer.value;
- }
- // 否则让默认行为处理
- return;
- }
-
- // 处理普通字符输入
- if (event.key.length === 1) {
- const inputInfo = checkInputSpeed();
- const { isFirstInput, isHighSpeed, isNormalInput, timeSinceLastInput } = inputInfo;
-
- // 如果是第一次输入,不拦截,让默认行为处理,只记录时间戳
- if (isFirstInput) {
- lastInputTime = Date.now();
- // 不拦截,让字符正常输入到 textarea
- return;
- }
-
- // 如果检测到是正常输入(间隔 > 200ms),处理之前的缓冲内容
- if (isNormalInput) {
- // 如果之前有缓冲内容,先提交
- if (rfidInputBuffer.value) {
- submitRFIDBuffer();
- }
- // 重置状态
- consecutiveInputCount = 0;
- lastInputTime = Date.now();
- // 不拦截,让字符正常输入到 textarea
- return;
- }
-
- // 如果检测到是高速输入(间隔 < 30ms),使用缓冲模式
- if (isHighSpeed) {
- event.preventDefault();
- event.stopPropagation(); // 阻止事件冒泡,避免影响其他元素
-
- // 如果是第一次检测到高速输入(之前没有缓冲内容),需要将 textarea 中已有的内容也加入缓冲区
- if (rfidInputBuffer.value === '' && searchText.value) {
- // textarea 中已经有内容(第一个字符已经通过默认行为输入了)
- // 将整个内容作为缓冲区的初始值,然后追加当前字符
- rfidInputBuffer.value = searchText.value + event.key;
- } else {
- // 否则直接追加当前字符
- rfidInputBuffer.value += event.key;
- }
- searchText.value = rfidInputBuffer.value;
- consecutiveInputCount++;
- scheduleRFIDBufferSubmit();
- return;
- }
-
- // 如果输入间隔在 30-200ms 之间,可能是正常输入,不拦截
- // 但如果之前有缓冲内容,说明高速输入已结束,先提交
- if (rfidInputBuffer.value) {
- submitRFIDBuffer();
- consecutiveInputCount = 0;
- }
- lastInputTime = Date.now();
- // 不拦截,让字符正常输入到 textarea
- }
- };
- // 处理输入框失焦
- const handleDeviceBlur = (event: FocusEvent) => {
- // 如果焦点转移到其他输入元素(如表单输入框),不自动聚焦
- const relatedTarget = event.relatedTarget as HTMLElement;
- if (relatedTarget && (
- relatedTarget.tagName === 'INPUT' ||
- relatedTarget.tagName === 'TEXTAREA' ||
- relatedTarget.closest('.el-input') ||
- relatedTarget.closest('.el-textarea') ||
- relatedTarget.closest('form')
- )) {
- // 如果有缓冲内容,先提交
- if (rfidInputBuffer.value) {
- submitRFIDBuffer();
- }
- return;
- }
-
- // 其他情况(如点击按钮等),延迟后自动聚焦
- setTimeout(() => {
- if (searchInputRef.value && !loading.value) {
- searchInputRef.value.focus();
- }
- }, 10);
- };
- // 处理回车键
- const handleDeviceEnter = (event: KeyboardEvent) => {
- if (event.shiftKey) return;
- event.preventDefault();
- // 无论是否启用RFID缓冲,都调用 submitRFIDBuffer
- // submitRFIDBuffer 内部会判断是否有缓冲内容,如果没有则直接使用 searchText 搜索
- submitRFIDBuffer();
- };
- // 分割多个设备编号(支持分隔符)
- const splitDeviceCodes = (input: string): string[] => {
- const trimmed = input.trim();
- if (!trimmed) return [];
-
- const { separator } = readRuleConfig.value;
-
- // 优先处理换行符
- if (/[\r\n]/.test(trimmed)) {
- return trimmed.split(/[\r\n]+/).filter(code => code.trim());
- }
-
- // 处理配置的分隔符
- if (separator && separator.trim() !== '') {
- const escapedSeparator = separator.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
- const separatorPattern = new RegExp(escapedSeparator + '+', 'g');
- return trimmed.split(separatorPattern).filter(code => code.trim());
- }
-
- // 处理空格分隔
- if (/\s/.test(trimmed)) {
- return trimmed.split(/\s+/).filter(code => code.trim());
- }
-
- // 单个设备编号
- return [trimmed];
- };
- // 处理扫码搜索(支持批量,优化并发请求)
- const handleScanSearch = async (event?: Event) => {
- // 阻止默认行为,防止表单提交导致页面刷新
- if (event) {
- event.preventDefault();
- event.stopPropagation();
- }
-
- // 如果启用了RFID缓冲,先提交缓冲区
- if (readRuleConfig.value.enableRFIDBuffer && rfidInputBuffer.value) {
- const bufferedValue = rfidInputBuffer.value;
- rfidInputBuffer.value = '';
- clearRFIDInputTimer();
- searchText.value = bufferedValue;
- }
-
- if (!searchText.value.trim()) return;
-
- // 分割多个设备编号
- const codes = splitDeviceCodes(searchText.value);
- if (codes.length === 0) return;
-
- // 去重处理,避免重复请求同一个设备编号
- const uniqueCodes = Array.from(new Set(codes.map(code => code.trim()))).filter(Boolean);
- if (uniqueCodes.length === 0) return;
-
- loading.value = true;
- let successCount = 0;
- let failCount = 0;
- const errorMessages: string[] = [];
-
- try {
- // 批量并发处理设备编号(使用 Promise.allSettled 确保所有请求都完成)
- // 限制并发数量,避免同时发起过多请求
- const batchSize = 10; // 每批处理10个
- const batches: string[][] = [];
- for (let i = 0; i < uniqueCodes.length; i += batchSize) {
- batches.push(uniqueCodes.slice(i, i + batchSize));
- }
-
- // 逐批处理,每批内部并发
- for (const batch of batches) {
- const promises = batch.map(async (code) => {
- try {
- const res = await deviceApi.GetList({
- page: 1,
- limit: 1,
- code: code,
- status: 1
- });
-
- if (res.data && res.data.length > 0) {
- const device = res.data[0];
- if (device.available_quantity <= 0) {
- return { success: false, code, message: `设备 ${code} 当前无可用数量` };
- }
-
- // 检查是否已存在
- const existingDevice = deviceList.value.find(d => d.device_no === device.id);
- if (existingDevice) {
- existingDevice.borrow_count++;
- return { success: true, code, device: null };
- } else {
- // 添加新设备到列表
- const newDevice = {
- device_no: device.id,
- device_code: device.code,
- device_type: device.category_name,
- device_name: device.name || '',
- borrow_count: 1,
- brand: device.brand || device.device_brand || '',
- device_specification: device.specification,
- model: device.model || '',
- warehouse: device.warehouse,
- available_quantity: device.available_quantity
- };
- deviceList.value.push(newDevice);
- return { success: true, code, device: newDevice };
- }
- } else {
- return { success: false, code, message: `未找到设备编号: ${code}` };
- }
- } catch (error) {
- console.error(`处理设备编号 ${code} 失败:`, error);
- return { success: false, code, message: `处理设备编号 ${code} 失败` };
- }
- });
-
- // 等待当前批次完成
- const results = await Promise.allSettled(promises);
-
- // 统计结果
- results.forEach((result, index) => {
- if (result.status === 'fulfilled') {
- const { success, message } = result.value;
- if (success) {
- successCount++;
- } else {
- failCount++;
- if (message) {
- errorMessages.push(message);
- }
- }
- } else {
- failCount++;
- errorMessages.push(`处理设备编号 ${batch[index]} 时发生错误`);
- }
- });
- }
-
- // 显示批量处理结果
- if (uniqueCodes.length > 1) {
- if (successCount > 0 && failCount === 0) {
- ElMessage.success(`成功添加 ${successCount} 个设备`);
- } else if (successCount > 0 && failCount > 0) {
- ElMessage.warning(`成功添加 ${successCount} 个设备,失败 ${failCount} 个`);
- // 只显示前3个错误信息,避免消息过多
- if (errorMessages.length > 0) {
- console.warn('批量处理错误详情:', errorMessages.slice(0, 3));
- }
- } else if (failCount > 0) {
- ElMessage.error(`添加失败,共 ${failCount} 个设备编号`);
- }
- } else if (successCount > 0) {
- ElMessage.success('设备已添加到列表');
- } else if (failCount > 0 && errorMessages.length > 0) {
- ElMessage.warning(errorMessages[0]);
- }
- } catch (error) {
- console.error('批量处理设备失败:', error);
- ElMessage.error('搜索设备失败');
- } finally {
- searchText.value = ''; // 清空搜索框
- loading.value = false;
- // 重新聚焦输入框,保持选中状态
- nextTick(() => {
- if (searchInputRef.value) {
- searchInputRef.value.focus();
- searchInputRef.value.select();
- }
- });
- }
- };
- const normalizeReturnStatus = (status?: { value?: number | string; label?: string }) => {
- const candidate = status?.value;
- const numericValue =
- candidate === undefined || candidate === null || candidate === ''
- ? 2
- : Number(candidate);
- return {
- value: Number.isNaN(numericValue) ? 2 : numericValue,
- label: status?.label || '已归还'
- };
- };
- // 提交归还流程RFID缓冲区内容
- const submitReturnRFIDBuffer = () => {
- if (!readRuleConfig.value.enableRFIDBuffer) {
- // 如果未启用RFID缓冲,直接使用 returnSearchText 进行搜索
- if (returnSearchText.value.trim()) {
- handleReturnScanSearch();
- }
- return;
- }
- if (!returnRfidInputBuffer.value) {
- // 如果没有缓冲内容,使用 returnSearchText 进行搜索
- if (returnSearchText.value.trim()) {
- handleReturnScanSearch();
- }
- return;
- }
- const bufferedValue = returnRfidInputBuffer.value;
- returnRfidInputBuffer.value = '';
- clearReturnRFIDInputTimer();
- returnConsecutiveInputCount = 0; // 重置计数
- returnLastInputTime = 0; // 重置时间
- returnSearchText.value = bufferedValue;
- handleReturnScanSearch();
- };
- // 调度归还流程RFID缓冲区提交(延迟提交)
- const scheduleReturnRFIDBufferSubmit = () => {
- if (!readRuleConfig.value.enableRFIDBuffer) return;
- clearReturnRFIDInputTimer();
- const delay = Math.max(readRuleConfig.value.rfidInputTimeout || 120, 30);
- returnRfidInputTimer = setTimeout(() => {
- submitReturnRFIDBuffer();
- }, delay);
- };
- // 处理归还设备输入(用于同步 textarea 内容,仅在缓冲模式下使用)
- const handleReturnDeviceInput = () => {
- // 如果缓冲区有内容,确保 textarea 显示与缓冲区一致
- // 这主要用于处理退格键等操作后的同步
- if (returnRfidInputBuffer.value && returnSearchText.value !== returnRfidInputBuffer.value) {
- returnSearchText.value = returnRfidInputBuffer.value;
- }
- // 注意:正常输入时,不干预 textarea 的内容,让默认行为处理
- };
- // 检测归还流程是否是高速扫码输入(通过输入速度判断)
- // 返回值:{ isHighSpeed: boolean, isFirstInput: boolean, timeSinceLastInput: number }
- const checkReturnInputSpeed = () => {
- const now = Date.now();
- const timeSinceLastInput = returnLastInputTime > 0 ? now - returnLastInputTime : 0;
- const isFirstInput = returnLastInputTime === 0;
-
- if (!isFirstInput) {
- returnLastInputTime = now;
- }
-
- return {
- isFirstInput,
- timeSinceLastInput,
- isHighSpeed: timeSinceLastInput > 0 && timeSinceLastInput < readRuleConfig.value.minInputSpeed,
- isNormalInput: timeSinceLastInput > 200
- };
- };
- // 处理归还流程RFID键盘输入(高速扫码)
- const handleReturnRFIDKeydown = (event: KeyboardEvent) => {
- // 如果未启用RFID缓冲,直接返回,不拦截
- if (!readRuleConfig.value.enableRFIDBuffer) {
- return;
- }
-
- // 不拦截修饰键组合(如 Ctrl+C, Ctrl+V 等)
- if (event.ctrlKey || event.metaKey || event.altKey) {
- return;
- }
-
- // 处理回车键
- if (event.key === 'Enter') {
- // 回车键由 @keydown.enter.prevent="handleReturnDeviceEnter" 处理
- // 这里不处理,让 handleReturnDeviceEnter 统一处理
- return;
- }
-
- // 处理退格键
- if (event.key === 'Backspace') {
- // 如果有缓冲内容,处理缓冲
- if (returnRfidInputBuffer.value) {
- event.preventDefault();
- returnRfidInputBuffer.value = returnRfidInputBuffer.value.slice(0, -1);
- returnSearchText.value = returnRfidInputBuffer.value;
- }
- // 否则让默认行为处理
- return;
- }
-
- // 处理普通字符输入
- if (event.key.length === 1) {
- const inputInfo = checkReturnInputSpeed();
- const { isFirstInput, isHighSpeed, isNormalInput, timeSinceLastInput } = inputInfo;
-
- // 如果是第一次输入,不拦截,让默认行为处理,只记录时间戳
- if (isFirstInput) {
- returnLastInputTime = Date.now();
- // 不拦截,让字符正常输入到 textarea
- return;
- }
-
- // 如果检测到是正常输入(间隔 > 200ms),处理之前的缓冲内容
- if (isNormalInput) {
- // 如果之前有缓冲内容,先提交
- if (returnRfidInputBuffer.value) {
- submitReturnRFIDBuffer();
- }
- // 重置状态
- returnConsecutiveInputCount = 0;
- returnLastInputTime = Date.now();
- // 不拦截,让字符正常输入到 textarea
- return;
- }
-
- // 如果检测到是高速输入(间隔 < 30ms),使用缓冲模式
- if (isHighSpeed) {
- event.preventDefault();
- event.stopPropagation(); // 阻止事件冒泡,避免影响其他元素
-
- // 如果是第一次检测到高速输入(之前没有缓冲内容),需要将 textarea 中已有的内容也加入缓冲区
- if (returnRfidInputBuffer.value === '' && returnSearchText.value) {
- // textarea 中已经有内容(第一个字符已经通过默认行为输入了)
- // 将整个内容作为缓冲区的初始值,然后追加当前字符
- returnRfidInputBuffer.value = returnSearchText.value + event.key;
- } else {
- // 否则直接追加当前字符
- returnRfidInputBuffer.value += event.key;
- }
- returnSearchText.value = returnRfidInputBuffer.value;
- returnConsecutiveInputCount++;
- scheduleReturnRFIDBufferSubmit();
- return;
- }
-
- // 如果输入间隔在 30-200ms 之间,可能是正常输入,不拦截
- // 但如果之前有缓冲内容,说明高速输入已结束,先提交
- if (returnRfidInputBuffer.value) {
- submitReturnRFIDBuffer();
- returnConsecutiveInputCount = 0;
- }
- returnLastInputTime = Date.now();
- // 不拦截,让字符正常输入到 textarea
- }
- };
- // 处理归还输入框失焦
- const handleReturnDeviceBlur = (event: FocusEvent) => {
- // 如果焦点转移到其他输入元素(如表单输入框),不自动聚焦
- const relatedTarget = event.relatedTarget as HTMLElement;
- if (relatedTarget && (
- relatedTarget.tagName === 'INPUT' ||
- relatedTarget.tagName === 'TEXTAREA' ||
- relatedTarget.closest('.el-input') ||
- relatedTarget.closest('.el-textarea') ||
- relatedTarget.closest('form')
- )) {
- // 如果有缓冲内容,先提交
- if (returnRfidInputBuffer.value) {
- submitReturnRFIDBuffer();
- }
- return;
- }
-
- // 其他情况(如点击按钮等),延迟后自动聚焦
- setTimeout(() => {
- if (returnSearchInputRef.value && !loading.value) {
- returnSearchInputRef.value.focus();
- }
- }, 10);
- };
- // 处理归还回车键
- const handleReturnDeviceEnter = (event: KeyboardEvent) => {
- if (event.shiftKey) return;
- event.preventDefault();
- // 无论是否启用RFID缓冲,都调用 submitReturnRFIDBuffer
- // submitReturnRFIDBuffer 内部会判断是否有缓冲内容,如果没有则直接使用 returnSearchText 搜索
- submitReturnRFIDBuffer();
- };
- // 处理归还扫码搜索(支持批量,优化并发请求)
- const handleReturnScanSearch = async (event?: Event) => {
- // 阻止默认行为,防止表单提交导致页面刷新
- if (event) {
- event.preventDefault();
- event.stopPropagation();
- }
-
- // 如果启用了RFID缓冲,先提交缓冲区
- if (readRuleConfig.value.enableRFIDBuffer && returnRfidInputBuffer.value) {
- const bufferedValue = returnRfidInputBuffer.value;
- returnRfidInputBuffer.value = '';
- clearReturnRFIDInputTimer();
- returnSearchText.value = bufferedValue;
- }
-
- if (!returnSearchText.value.trim()) return;
-
- // 分割多个设备编号
- const codes = splitDeviceCodes(returnSearchText.value);
- if (codes.length === 0) return;
-
- // 去重处理,避免重复请求同一个设备编号
- const uniqueCodes = Array.from(new Set(codes.map(code => code.trim()))).filter(Boolean);
- if (uniqueCodes.length === 0) return;
-
- loading.value = true;
- let successCount = 0;
- let failCount = 0;
- const errorMessages: string[] = [];
-
- try {
- // 批量并发处理设备编号(使用 Promise.allSettled 确保所有请求都完成)
- // 限制并发数量,避免同时发起过多请求
- const batchSize = 10; // 每批处理10个
- const batches: string[][] = [];
- for (let i = 0; i < uniqueCodes.length; i += batchSize) {
- batches.push(uniqueCodes.slice(i, i + batchSize));
- }
-
- // 逐批处理,每批内部并发
- for (const batch of batches) {
- const promises = batch.map(async (code) => {
- try {
- const res = await deviceApi.GetList({
- page: 1,
- limit: 1,
- code: code,
- status: 1
- });
-
- if (res.data && res.data.length > 0) {
- const device = res.data[0];
- const normalizedStatus = normalizeReturnStatus(device.return_status);
-
- // 检查是否已存在
- const existingDeviceIndex = returnDeviceList.value.findIndex(d => d.device_no === device.id);
- if (existingDeviceIndex !== -1) {
- // 如果设备已存在,更新其状态
- returnDeviceList.value[existingDeviceIndex].return_status = normalizedStatus;
- returnDeviceList.value[existingDeviceIndex].is_return = true;
- returnDeviceList.value[existingDeviceIndex].return_time = dayjs().format('YYYY-MM-DD HH:mm:ss');
- return { success: true, code };
- } else {
- // 设备不存在于归还列表中
- return {
- success: false,
- code,
- message: `设备 ${device.code || device.category_name} 不在当前归还列表中,请先通过手动归还添加该设备`
- };
- }
- } else {
- return { success: false, code, message: `未找到设备编号: ${code}` };
- }
- } catch (error) {
- console.error(`处理设备编号 ${code} 失败:`, error);
- return { success: false, code, message: `处理设备编号 ${code} 失败` };
- }
- });
-
- // 等待当前批次完成
- const results = await Promise.allSettled(promises);
-
- // 统计结果
- results.forEach((result, index) => {
- if (result.status === 'fulfilled') {
- const { success, message } = result.value;
- if (success) {
- successCount++;
- } else {
- failCount++;
- if (message) {
- errorMessages.push(message);
- }
- }
- } else {
- failCount++;
- errorMessages.push(`处理设备编号 ${batch[index]} 时发生错误`);
- }
- });
- }
-
- // 显示批量处理结果
- if (uniqueCodes.length > 1) {
- if (successCount > 0 && failCount === 0) {
- ElMessage.success(`成功更新 ${successCount} 个设备状态为已归还`);
- } else if (successCount > 0 && failCount > 0) {
- ElMessage.warning(`成功更新 ${successCount} 个设备状态,失败 ${failCount} 个`);
- // 只显示前3个错误信息,避免消息过多
- if (errorMessages.length > 0) {
- console.warn('批量处理错误详情:', errorMessages.slice(0, 3));
- }
- } else if (failCount > 0) {
- ElMessage.error(`更新失败,共 ${failCount} 个设备编号`);
- }
- } else if (successCount > 0) {
- ElMessage.success('设备状态已更新为已归还');
- } else if (failCount > 0 && errorMessages.length > 0) {
- ElMessage.warning(errorMessages[0]);
- }
- } catch (error) {
- console.error('批量处理设备失败:', error);
- ElMessage.error('搜索设备失败');
- } finally {
- returnSearchText.value = ''; // 清空搜索框
- loading.value = false;
- // 重新聚焦输入框,保持选中状态
- nextTick(() => {
- if (returnSearchInputRef.value) {
- returnSearchInputRef.value.focus();
- returnSearchInputRef.value.select();
- }
- });
- }
- };
- // 异常记录列表数据
- const abnormalList = ref([
- /* {
- borrowNo: '202409002',
- borrower: '张同学',
- time: '2024-09-12 10:21:32',
- type: '逾期'
- },
- {
- borrowNo: '202505013',
- borrower: '张同学',
- time: '2025-05-13 15:12:35',
- type: '损坏'
- } */
- ]);
- /* 归还设备异常记录 */
- const returnAbnormalList = ref([
-
- ]);
- // 附件文件列表
- const attachmentFileList = ref<any[]>([]);
- // 查看异常记录详情
- const handleView = (row: any) => {
- console.log('查看异常记录:', row);
- // 这里可以添加查看详情的逻辑
- };
- const selectedDeviceCodes = ref<any[]>([]);
- // 计算已选中设备的ID列表(用于禁用已选中的设备)
- const disabledDeviceIds = computed(() => {
- if (activeName.value === 'first') {
- // first tab: 从 form.value.items 中获取 device ID
- return form.value.items.map((item: any) => item.device).filter(Boolean);
- } else if (activeName.value === 'second') {
- // second tab: 从 deviceList.value 中获取 device_no ID
- return deviceList.value.map((item: any) => item.device_no).filter(Boolean);
- }
- // third tab (归还模式) 不需要禁用,因为已经有特殊的处理逻辑
- return [];
- });
- // 借用列表相关方法
- const handleAdd = () => {
- if (activeName.value === 'third' && allReturned.value) {
- ElMessage.info('当前列表设备均已归还,无可选择设备');
- return;
- }
- if(activeName.value === 'third'){
- selectedDeviceCodes.value = [];
- returnDeviceList.value.forEach(item => {
- console.log("item:::",item);
- if(item.device_no){
- selectedDeviceCodes.value.push(item.device_code);
- }
- });
- console.log("selectedDeviceCodes.value:::",selectedDeviceCodes.value);
- }
- showSelectDeviceDialog.value = true;
- };
- const handleRemove = (index: number) => {
- deviceList.value.splice(index, 1);
- };
- const handleReturnRemove = (index: number) => {
- returnDeviceList.value.splice(index, 1);
- };
- // 处理表格多选变化
- const handleSelectionChange = (selection: DeviceListItem[]) => {
- selectedDevices.value = selection;
- };
- // 设备选择处理
- function onDeviceSelected(devices: Device[]) {
- console.log("devices:::",devices,"activeName:::",activeName.value);
- if (activeName.value === 'first') {
- // 获取已存在的设备ID列表
- const existingIds = new Set(form.value.items.map((item: any) => item.device).filter(Boolean));
-
- // 过滤掉已存在的设备,只添加新的
- const newDevices = devices.filter((d) => !existingIds.has(d.id));
-
- if (newDevices.length === 0) {
- ElMessage.warning('所选设备已存在,未添加重复项');
- return;
- }
-
- // 如果有部分重复,提示用户
- if (newDevices.length < devices.length) {
- ElMessage.warning(`已过滤 ${devices.length - newDevices.length} 个重复的设备`);
- }
-
- form.value.items.push(
- ...newDevices.map((d) => ({
- device: d.id,
- device_code: d.code,
- remark: d.category_name,
- quantity: 1,
- location: d.warehouse,
- device_name: d.name,
- device_specification: d.device_specification
- }))
- );
- } else if (activeName.value === 'second') {
- // 获取已存在的设备ID列表
- const existingIds = new Set(deviceList.value.map((item: any) => item.device_no).filter(Boolean));
-
- // 过滤掉已存在的设备,只添加新的
- const newDevices = devices.filter((d) => !existingIds.has(d.id));
-
- if (newDevices.length === 0) {
- ElMessage.warning('所选设备已存在,未添加重复项');
- return;
- }
-
- // 如果有部分重复,提示用户
- if (newDevices.length < devices.length) {
- ElMessage.warning(`已过滤 ${devices.length - newDevices.length} 个重复的设备`);
- }
-
- deviceList.value.push(
- ...newDevices.map(d => ({
- device_no: d.id,
- device_code: d.code,
- device_type: d.category_name,
- device_name: d.name || '',
- borrow_count: 1,
- brand: d.brand || '',
- model: d.model,
- device_specification: d.specification,
- warehouse: d.warehouse,
- available_quantity:d.available_quantity
- }))
- );
- }else if(activeName.value === 'third'){
- // 在添加前检查每个设备是否已存在
- devices.forEach(d => {
- const existingDeviceIndex = returnDeviceList.value.findIndex(item => item.device_no === d.id);
- if (existingDeviceIndex !== -1) {
- // 如果设备已存在,更新其状态
- returnDeviceList.value[existingDeviceIndex].return_status.value = 2;
- returnDeviceList.value[existingDeviceIndex].return_status.label = '已归还';
- returnDeviceList.value[existingDeviceIndex].is_return = true;
- returnDeviceList.value[existingDeviceIndex].return_time = dayjs().format('YYYY-MM-DD HH:mm:ss');
- returnDeviceList.value[existingDeviceIndex].brand = d.brand || '';
- ElMessage.success(`设备 ${d.category_name} 状态已更新为已归还`);
- } else {
- // 如果设备不存在,添加新记录
- /* returnDeviceList.value.push({
- device_no: d.id,
- device_type: d.category_name,
- device_name: d.name || '',
- borrow_count: 1,
- brand: d.brand || '',
- model: d.model || '',
- warehouse: d.warehouse,
- status: '已归还'
- }); */
- /* ElMessage.success(`设备 ${d.category_name} 已添加到归还列表`); */
- }
- });
- }
- }
- // 移除同步相关的 watch
- // const handleClick = (tab: TabsPaneContext, event: Event) => {
- // if (tab.props.name === 'second') {
- // deviceList.value = form.value.items.map(item => ({
- // device_no: item.device,
- // device_type: item.remark,
- // device_name: '',
- // borrow_count: item.quantity,
- // brand: '',
- // model: '',
- // warehouse: item.location
- // }));
- // }
- // }
- function handleClick(tab: TabsPaneContext) {
- console.log('Tab clicked:', tab.props.name);
- // 当切换到设备清单标签页时,自动聚焦输入框
- if (tab.props.name === 'second') {
- nextTick(() => {
- if (searchInputRef.value) {
- searchInputRef.value.focus();
- searchInputRef.value.select();
- }
- });
- } else if (tab.props.name === 'third') {
- // 当切换到归还设备清单标签页时,自动聚焦输入框
- nextTick(() => {
- returnSearchInputRef.value?.focus?.();
- });
- }
- }
- function handleUploadSuccess(response: any, file: any, fileList: any) {
- // eslint-disable-next-line no-console
- console.log('上传成功:', file.name);
- }
- function handleUploadError(err: any, file: any, fileList: any) {
- // eslint-disable-next-line no-console
- console.error('上传失败:', file.name);
- }
- // 图片预览处理函数
- const handlePictureCardPreview = (uploadFile: any) => {
- dialogImageUrl.value = uploadFile.url || uploadFile.response?.url || form.value.attachments;
- dialogVisible.value = true;
- };
- // 处理附件删除
- const handleRemoves = (file: any, fileList: any) => {
- // 由于是禁用状态,这里只是示例,实际不会执行删除
- console.log('删除附件:', file.name);
- };
- const form = ref<FormData>({
- borrower_info:{
- user_code:'',
- mobile:''
- },
- application_no: '',
- emergency_contact: '',
- emergency_phone: '',
- app_user_borrower: { id: '', name: '', user_code: '', mobile: '' },
- team_type: 0,
- team_members_count: 1,
- team_members: '',
- expected_start_time:'',
- expected_end_time: '',
- borrower_dept: '',
- purpose: '',
- applicant_remark_type: "1",
- applicant_remark: '',
- items: [],
- accessory_info: '',
- borrow_type: 2,
- return_location:'',
- approver_info: {
- name: ''
- }
- });
- const showSelectDeviceDialog = ref(false);
- const rules = {
- emergency_contact: [
- { required: true, message: '请输入借用人', trigger: 'change' },
- ],
- app_user_borrower: [
- { required: true, message: '请输入学号或工号', trigger: 'change' },
- ],
- emergency_phone: [
- { required: true, message: '请输入联系电话', trigger: 'change' },
- ],
- /* borrower_dept: [
- { required: true, message: '请输入借用部门', trigger: 'change' },
- ], */
- expected_end_time: [
- { required: true, message: '请输选择归还时间', trigger: 'change' },
- ],
- team_type: [
- { required: true, message: '请选择个人或者团队', trigger: 'change' },
- ],
- purpose: [
- { required: true, message: '请输入借用原因', trigger: 'change' },
- ],
- applicant_remark_type: [
- { required: true, message: '请选择审批人', trigger: 'change' },
- ],
- applicant_remark: [
- { required: false, message: '请输入备注', trigger: 'change' },
- ],
- };
- // 自动填充用户信息
- onMounted(() => {
- loadWarehouses()
- getAdminList()
- getAllUserList()
- try {
- const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
- if (userInfo) {
- form.value.emergency_contact = userInfo.username || '';
- // 借用人从用户列表加载完成后再统一回显/设置
- form.value.emergency_phone = userInfo.mobile || '';
- form.value.borrower_dept = userInfo.dept_info?.dept_name || '';
- }
- } catch (e) {
- /* empty */
- }
- });
- watch(
- () => props.visible,
- (v) => {
- visible.value = v;
- // 当对话框打开且当前标签页是设备清单时,自动聚焦输入框
- if (v && activeName.value === 'second' && isCollect.value) {
- nextTick(() => {
- if (searchInputRef.value) {
- searchInputRef.value.focus();
- searchInputRef.value.select();
- }
- });
- } else if (v && activeName.value === 'third' && !isView.value) {
- // 当对话框打开且当前标签页是归还设备清单时,自动聚焦输入框
- nextTick(() => {
- returnSearchInputRef.value?.focus?.();
- });
- }
- // 清理RFID缓冲状态
- if (v) {
- rfidInputBuffer.value = '';
- clearRFIDInputTimer();
- consecutiveInputCount = 0;
- lastInputTime = 0;
- // 清理归还流程RFID缓冲状态
- returnRfidInputBuffer.value = '';
- clearReturnRFIDInputTimer();
- returnConsecutiveInputCount = 0;
- returnLastInputTime = 0;
- }
- }
- );
- watch(() => props.modelValue, async (val) => {
- if (val && val.id) {
- try {
- const res = await api.GetApplicationDetail(val.id);
- console.log("res:::::",res)
- if (res.code === 2000 && res.data) {
- const data = res.data;
- Object.assign(form.value, data);
- buildSteps(data);
- // 领取模式下不回显历史配件内容
- if (isCollect.value) {
- collectAccessories.value = '';
- }
- timeline.value.create = data.create_datetime ? dayjs(data.create_datetime).format('YYYY-MM-DD HH:mm:ss') : '';
- timeline.value.approve = data.approve_time || '';
- const approverinfo = data.approver_info ?? data.admin_approver_info
- timeline.value.approver = approverinfo?.name || '审批人'
- // timeline.value.approver = data.admin_approver_info?.name || '审批人';
- // console.log("data:::",form.value);
- // activeStep.value = 1; // 创建
- // if (data.status >= 1) activeStep.value = 2; // 待审批
- // if (data.status >= 2) activeStep.value = 3; // 审批通过
- // if (data.status >= 3) activeStep.value = 4; // 完成
- // 同步 form.items 到 returnDeviceList
- if (form.value.items && form.value.items.length > 0) {
- returnDeviceList.value = form.value.items
- .filter(item => item.device !== null)
- .map(item => ({
- device_no: item.device,
- device_code: item.device_code,
- device_type: item.remark,
- device_name: item.device_name,
- borrow_count: item.quantity,
- brand: item.brand ||item.device_brand || '',
- model: item.device_specification,
- warehouse: item.location,
- problem_records: item.problem_records,
- /* status: '未归还' */
- return_status:item.return_status,
- return_time:item.return_times
- }));
- }
- // 同步 form.records 到 returnAbnormalList
- if (form.value.records && form.value.records.length > 0) {
- // 添加损坏类型记录
- const damageRecord: AbnormalRecord = {
- application_no: form.value.application_no,
- operator_name: form.value.app_user_borrower?.name||form.value.external_borrower_name||'',
- user_code: form.value.borrower_info?.user_code || form.value.app_user_borrower?.user_code||'',
- emergency_phone: form.value.external_borrower_phone || form.value.app_user_borrower?.mobile||'',
- type: '损坏',
- condition: form.value.borrower_damage_count || 0,
- create_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
- };
- // 添加逾期类型记录
- const overdueRecord: AbnormalRecord = {
- application_no: form.value.application_no,
- operator_name: form.value.app_user_borrower?.name||form.value.external_borrower_name||'',
- user_code: form.value.borrower_info?.user_code || form.value.app_user_borrower?.user_code||'',
- emergency_phone: form.value.external_borrower_phone || form.value.app_user_borrower?.mobile||'',
- type: '逾期',
- condition: form.value.borrower_overdue_count || 0, // 逾期数量设为1
- create_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
- };
- returnAbnormalList.value = [damageRecord, overdueRecord];
- abnormalList.value = [damageRecord, overdueRecord];
- }
-
- // 处理附件回显
- if (data.attachments) {
- if (typeof data.attachments === 'string') {
- // 如果attachments是字符串URL
- attachmentFileList.value = [{
- name: data.attachments.split('/').pop() || '附件',
- url: data.attachments,
- status: 'success'
- }];
- } else if (Array.isArray(data.attachments)) {
- // 如果attachments是数组
- attachmentFileList.value = data.attachments.map((item: any, index: number) => {
- if (typeof item === 'string') {
- return {
- name: item.split('/').pop() || `附件${index + 1}`,
- url: item,
- status: 'success'
- };
- } else if (typeof item === 'object' && item.url) {
- return {
- name: item.name || item.url.split('/').pop() || `附件${index + 1}`,
- url: item.url,
- status: 'success'
- };
- }
- return null;
- }).filter(Boolean);
- }
- }
- }
- } catch (e) {
- console.log("审判失败:::",e)
- ElMessage.error('获取审批信息失败');
- }
- }else if(val&& isEdit.value){
- try {
- const res = await api.GetApplicationDetail(val.id);
- if (res.code === 2000 && res.data) {
- const data = res.data;
- Object.assign(form.value, data);
- // 同步 form.items 到 returnDeviceList
- if (form.value.items && form.value.items.length > 0) {
- returnDeviceList.value = form.value.items
- .filter(item => item.device !== null)
- .map(item => ({
- device_no: item.device,
- device_type: item.remark,
- device_name: item.device_name,
- borrow_count: item.quantity,
- brand: item.brand ||item.device_brand || '',
- model: item.device_specification,
- warehouse: item.location,
- problem_records: item.problem_records,
- return_status:item.return_status,
- return_time:item.return_times
- }));
- }
-
- // 处理附件回显 (编辑模式)
- if (data.attachments) {
- if (typeof data.attachments === 'string') {
- attachmentFileList.value = [{
- name: data.attachments.split('/').pop() || '附件',
- url: data.attachments,
- status: 'success'
- }];
- } else if (Array.isArray(data.attachments)) {
- attachmentFileList.value = data.attachments.map((item: any, index: number) => {
- if (typeof item === 'string') {
- return {
- name: item.split('/').pop() || `附件${index + 1}`,
- url: item,
- status: 'success'
- };
- } else if (typeof item === 'object' && item.url) {
- return {
- name: item.name || item.url.split('/').pop() || `附件${index + 1}`,
- url: item.url,
- status: 'success'
- };
- }
- return null;
- }).filter(Boolean);
- }
- }
- }
- } catch (e) {
- ElMessage.error('获取审批信息失败');
- }
- }
- }, { immediate: true });
- // watch(
- // () => props.modelValue,
- // (v) => {
- // if (v) {
- // // eslint-disable-next-line no-console
- // console.log("val:::::",v);
- // Object.assign(form.value, v);
- // }
- // }, { immediate: true }
- // );
- // 监听借用人选择变化
- watch(() => form.value.app_user_borrower?.id, (newId) => {
- if (!newId || allUserList.value.length === 0) return;
- const selectedUser: any = allUserList.value.find((u: any) => String(u.id) === String(newId));
- if (selectedUser) {
- form.value.app_user_borrower = {
- id: selectedUser.id,
- name: selectedUser.name,
- user_code: selectedUser.user_code || '',
- mobile: selectedUser.mobile || ''
- };
- }
- });
- function addItem() {
- if (activeName.value === 'third' && allReturned.value) {
- ElMessage.info('当前列表设备均已归还,无可选择设备');
- return;
- }
- showSelectDeviceDialog.value = true;
- }
- function removeItem(index: number) {
- form.value.items.splice(index, 1);
- }
- function onCancel() {
- // 重置标签页到第一个
- activeName.value = 'first';
- // 清理异常记录列表
- returnAbnormalList.value = [];
- abnormalList.value = [];
- // 清理设备列表
- deviceList.value = [];
- returnDeviceList.value = [];
- // 清理搜索框
- searchText.value = '';
- returnSearchText.value = '';
- // 清理备注
- remark.value = '';
- // 清理领取模式配件信息
- collectAccessories.value = '';
- returnRemark.value = '';
- // 重置状态
- returnStatus.value = '未归还';
- // 清理选中的设备
- selectedDevices.value = [];
- // 清理附件文件列表
- attachmentFileList.value = [];
- // 清理RFID缓冲
- rfidInputBuffer.value = '';
- clearRFIDInputTimer();
- consecutiveInputCount = 0;
- lastInputTime = 0;
- // 清理归还流程RFID缓冲
- returnRfidInputBuffer.value = '';
- clearReturnRFIDInputTimer();
- returnConsecutiveInputCount = 0;
- returnLastInputTime = 0;
- // 关闭所有对话框
- showSelectDeviceDialog.value = false;
- showSettlementDialog.value = false;
- showAbnormalDialog.value = false;
- showViewAbnormalDialog.value = false;
- // 重置当前异常数据
- currentAbnormalData.value = {
- damage_type: 0,
- condition: '',
- photos: []
- };
- // 发出关闭事件
- emit('update:visible', false);
- }
- // 提交时合并数据
- function onSubmit() {
- if(isCollect.value){
- // 验证是否有设备信息
- const hasDevicesInFirstTab = form.value.items && form.value.items.length > 0;
- const hasDevicesInSecondTab = deviceList.value && deviceList.value.length > 0;
-
- if (!hasDevicesInFirstTab && !hasDevicesInSecondTab) {
- ElMessage.warning('请添加设备信息后再提交');
- activeName.value = 'second'; // 自动切换到借用列表标签页
- return;
- }
- // 验证设备数量
- const hasInvalidQuantityInFirstTab = form.value.items.some(item => !item.quantity || item.quantity <= 0);
- const hasInvalidQuantityInSecondTab = deviceList.value.some(item => !item.borrow_count || item.borrow_count <= 0);
- if (hasInvalidQuantityInFirstTab || hasInvalidQuantityInSecondTab) {
- ElMessage.warning('请确保所有设备的数量大于0');
- activeName.value = 'second'; // 自动切换到借用列表标签页
- return;
- }
- // 合并两个标签页的设备数据
- const allDevices = [
- ...deviceList.value.map(item => ({
- condition: remark.value,
- quantity: item.borrow_count,
- device_id: Number(item.device_no) || 0
- }))
- ];
-
- const submitData = {
- id:form.value.id,
- item_id:form.value.id,
- device_assignments: allDevices,
- remark:remark.value,
- pre_borrow_accessories: collectAccessories.value,
- };
- CollectEquipment(submitData).then((res: ApiResponse) => {
- if(res.code===2000){
- ElMessage.success("领取成功");
- // 准备结算单数据
- settlementData.value = {
- ...form.value,
- items: deviceList.value.map(item => ({
- ...item,
- device_category_name: item.device_type,
- device_name: item.device_name,
- device_specification: item.device_specification,
- device_storage_location: item.warehouse,
- remark: item.device_type,
- quantity: item.borrow_count,
- device_id: item.device_no,
- device_category: item.device_type,
- device_code: item.device_no,
- borrow_type: form.value.borrow_type,
- borrower_dept: form.value.borrower_dept,
- emergency_contact: form.value.emergency_contact,
- emergency_phone: form.value.emergency_phone,
- team_type: form.value.team_type,
- })),
- accessory_info: accessoryInfo.value,
- pre_borrow_accessories:collectAccessories.value,
- remark: remark.value,
- expected_start_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
- };
-
- // 先触发提交事件进行页面刷新
- emit('submit');
-
- // 关闭当前对话框
- emit('update:visible', false);
-
- // 使用 nextTick 确保在 DOM 更新后再显示结算单
- nextTick(() => {
- borrowForm.value = {...settlementData.value,mode: 'settlement' };
- showSettlementDialog.value = true;
- });
- }
- });
- } else {
- // 归还逻辑修改
- // 使用所有设备列表而不是选中的设备
- const allDevices = returnDeviceList.value
- .filter(item => item.is_return === true) // 只选择 return_status 为 2 的设备
- .map(item => ({
- device: item.device_no,
- quantity: item.borrow_count,
- remark: returnRemark.value,
- device_id: Number(item.device_no) || 0,
- // 添加异常相关字段
- condition: item.condition, // 异常说明
- damage_type:item.damage_type,
- photo_urls: item.photos || [], // 异常照片
- }));
-
- const submitData = {
- id: form.value.id,
- items: allDevices,
- status: returnStatus.value,
- pre_borrow_accessories: form.value.pre_borrow_accessories,
- };
-
- ReturnEquipment(submitData).then(async (res: ApiResponse) => {
- if(res.code===2000){
- ElMessage.success("归还成功");
- try {
- if (form.value.id) {
- const detailRes = await api.GetApplicationDetail(form.value.id);
- if (detailRes.code === 2000 && detailRes.data) {
- returnStatus.value = detailRes.data.status_label || returnStatus.value;
- }
- }
- } catch (e) {
- ElMessage.error('获取最新状态失败');
- }
- emit('submit');
- emit('update:visible', false);
- }
- });
- }
- }
- function clickReturn(){
- returnStatus.value = '已归还';
- // 自动选择所有设备
- const tableRef = document.querySelector('.el-table__header-wrapper th.el-table__cell.is-leaf .el-checkbox');
- if (tableRef) {
- (tableRef as HTMLElement).click();
- }
- }
- // 组件卸载时清理定时器和状态
- onBeforeUnmount(() => {
- clearRFIDInputTimer();
- rfidInputBuffer.value = '';
- consecutiveInputCount = 0;
- lastInputTime = 0;
- // 清理归还流程定时器和状态
- clearReturnRFIDInputTimer();
- returnRfidInputBuffer.value = '';
- returnConsecutiveInputCount = 0;
- returnLastInputTime = 0;
- });
- /* formRef.value.validate((valid: boolean) => {
- if (valid) {
- form.value.items = form.value.items.map(item => ({
- ...item,
- quantity: Number(item.quantity) || 0
- }));
- const firstLocation = form.value.items[0]?.location || '';
- form.value.return_location = firstLocation;
- form.value.expected_start_time = now;
- form.value.expected_end_time = dayjs(form.value.expected_end_time).format('YYYY-MM-DD HH:mm:ss')|| now;
- form.team_members_count=Number(form.team_members_count)||1;
- emit('submit', { ...form.value });
- emit('update:visible', false);
- ElMessage.success("添加成功!");
- }
- }); */
-
- </script>
- <style>
- .avatar-uploader .el-upload {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- }
- .avatar-uploader .el-upload:hover {
- border-color: #409EFF;
- }
- .avatar-uploader-icon {
- font-size: 28px;
- color: #8c939d;
- width: 178px;
- height: 178px;
- line-height: 178px;
- text-align: center;
- }
- .avatar {
- width: 178px;
- height: 178px;
- display: block;
- }
- .device-code-input {
- padding: 8px 12px;
- font-size: 14px;
- border: 1px solid #dcdfe6;
- border-radius: 4px;
- outline: none;
- resize: vertical;
- transition: all 0.3s;
- font-family: 'Microsoft YaHei', sans-serif;
- line-height: 1.5;
- }
- .device-code-input:focus {
- border-color: #409EFF;
- box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
- }
- .device-code-input:disabled {
- background-color: #f5f7fa;
- cursor: not-allowed;
- }
- </style>
|