index.vue 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799
  1. <template>
  2. <el-dialog v-model="visible" :title="isView ? '查看' : isCollect ? '领取' : '归还'" width="75%" :close-on-click-modal="false" @close="onCancel">
  3. <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
  4. <el-tab-pane label="借用单信息" name="first">
  5. <el-form :model="form" label-width="110px" label-position="top" :rules="rules" ref="formRef">
  6. <el-row :gutter="16">
  7. <el-col :span="8">
  8. <el-form-item label="借用单编号" prop="application_no">
  9. <el-input v-model="form.application_no" placeholder="自动生成" disabled />
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="8">
  13. <el-form-item label="借用人类型" prop="borrower_type">
  14. <el-select v-model="form.borrower_type" :placeholder="isView?'':'请选择借用人角色'" :disabled="true">
  15. <el-option label="管理员用户" :value=0 />
  16. <el-option label="应用用户" :value=1 />
  17. <el-option label="外部用户" :value=2 />
  18. </el-select>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="8" >
  22. <!-- <el-form-item label="借用人" prop="external_borrower_name" v-if="form.borrower_type !== 2">
  23. <el-input v-model="form.borrower_info.name" placeholder="请输入借用人" :disabled="true" />
  24. </el-form-item> -->
  25. <el-form-item label="借用人" prop="admin_borrower" v-if="form.borrower_type == 0">
  26. <el-select v-model="form.admin_borrower" :placeholder="isView?'':'请选择借用人'" :disabled="true" >
  27. <el-option :label="adminList.name" :value="adminList.id" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="借用人" prop="app_user_borrower" v-if="form.borrower_type == 1">
  31. <el-select v-model="form.app_user_borrower.id" :placeholder="isView?'':'请选择借用人'" :disabled="true" >
  32. <el-option v-for="item in allUserList" :key="item.id" :label="item.name" :value="item.id" />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="借用人" prop="external_borrower_name" v-if="form.borrower_type == 2">
  36. <el-input v-model="form.external_borrower_name" :placeholder="isView?'':'请输入借用人'" :disabled="true" />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8" v-if="form.borrower_type !== 2">
  40. <el-form-item label="学号/工号" prop="user_code" >
  41. <!-- {{ form.borrower_info.user_code }} -->
  42. <el-input v-model="form.app_user_borrower.user_code" :placeholder="isView?'':'请输入学号/工号'" :disabled="true"/>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="8">
  46. <el-form-item label="联系电话" v-if="form.borrower_type !== 2">
  47. <el-input v-model="form.app_user_borrower.mobile" :placeholder="isView?'':'请输入联系电话'" :disabled="true" />
  48. </el-form-item>
  49. <el-form-item label="联系电话" v-if="form.borrower_type == 2">
  50. <el-input v-model="form.external_borrower_phone" :placeholder="isView?'':'请输入联系电话'" :disabled="true" />
  51. </el-form-item>
  52. </el-col>
  53. <el-col :span="8">
  54. <el-form-item label="借用部门" prop="borrower_dept">
  55. <el-input v-model="form.borrower_dept" placeholder="请输入借用部门" :disabled="true" />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="8">
  59. <el-form-item label="预计归还时间" prop="expected_end_time">
  60. <el-date-picker v-model="form.expected_end_time" type="date"
  61. format="YYYY-MM-DD"
  62. value-format="YYYY-MM-DD"
  63. :disabledDate="disabledDate" placeholder="请选择预计归还时间" style="width: 100%" :disabled="true"/>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="4">
  67. <el-form-item label="个人/团队" prop="team_type" >
  68. <el-select v-model="form.team_type" placeholder="请选择" :disabled="true">
  69. <el-option label="个人" :value="0" />
  70. <el-option label="团队" :value="1" />
  71. </el-select>
  72. </el-form-item>
  73. </el-col>
  74. <el-col :span="4" v-show="form.team_type===1">
  75. <el-form-item label="团队人数" prop="team_members_count">
  76. <el-input v-model="form.team_members_count" :placeholder="isView?'':'请输入'" :disabled="true"/>
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="16" v-show="form.team_type===1">
  80. <el-form-item label="团队其他人员名单" prop="team_members">
  81. <el-input v-model="form.team_members" :placeholder="isView?'':'请输入团队其他人员名单'" :disabled="true"/>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="24">
  85. <el-form-item label="借用原因" prop="purpose">
  86. <el-input v-model="form.purpose" type="textarea" :placeholder="isView?'':'请输入借用原因'" :disabled="true" />
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="4">
  90. <!-- ||form.approver_info.name -->
  91. <el-form-item label="审批人" prop="applicant_remark_type">
  92. <el-input :model-value="displayApproverName" placeholder="-" :disabled="true" />
  93. </el-form-item>
  94. </el-col>
  95. <el-col :span="20">
  96. <el-form-item label="备注" prop="applicant_remark">
  97. <el-input v-model="form.applicant_remark" :placeholder="isView?'':'请输入备注'" :disabled="true"/>
  98. </el-form-item>
  99. </el-col>
  100. </el-row>
  101. <div style="margin: 16px 0 8px 0; font-weight: bold"> {{ isView ? '借用列表' : (isCollect ? '借用列表' : '归还列表') }}</div>
  102. <el-table :data="form.items.filter(item => item.device === null)" border style="width: 50%; margin-bottom: 12px">
  103. <el-table-column type="index" label="序号" width="60" />
  104. <el-table-column prop="device_category_name" label="设备分类" />
  105. <el-table-column :label="isView ? '数量' : (isCollect ? '借用数量' : '归还数量')">
  106. <template #default="{ row }">
  107. <el-input v-model="row.quantity" type="number" :min="1" prop="quantity" size="small" :disabled="true" />
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="操作" width="80">
  111. <template #default="{ $index }">
  112. <el-button type="text" style="color: red" @click="removeItem($index)" :disabled="true">移除</el-button>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <el-button type="primary" @click="addItem" v-if="!isView" :disabled="true">选择设备分类</el-button>
  117. <div style="margin: 16px 0 8px 0; font-weight: bold">预借配件信息</div>
  118. <el-input v-model="form.accessories" :placeholder="isView?'':'请输入预借配件信息'" :disabled="true"/>
  119. <div style="margin: 16px 0 8px 0; font-weight: bold" >附件</div>
  120. <!-- <el-upload
  121. action="#"
  122. drag
  123. :list-type="'picture'"
  124. accept=".bmp,.gif,.jpeg,.jpg,.png,‌.webp,.svg"
  125. multiple
  126. :show-file-list="true"
  127. :file-list="attachmentFileList"
  128. :on-success="handleUploadSuccess"
  129. :on-error="handleUploadError"
  130. :disabled="true"
  131. >
  132. <i class="el-icon-upload"></i>
  133. <div class="el-upload__text">将文件拖到此处,或 <em>点击上传</em></div>
  134. </el-upload> -->
  135. <el-upload
  136. :disabled="true"
  137. action="#"
  138. list-type="picture-card"
  139. :on-preview="handlePictureCardPreview"
  140. :on-remove="handleRemoves"
  141. :file-list="attachmentFileList"
  142. >
  143. <el-icon><Plus /></el-icon>
  144. </el-upload>
  145. <div v-if="isView && form.latest_renewal" style="margin-top: 8px;">
  146. <div style="font-weight: bold; margin-bottom: 8px">续借信息</div>
  147. <el-row :gutter="16">
  148. <el-col :span="4">
  149. <el-form-item label="续借天数">
  150. <el-input :model-value="form.latest_renewal?.renewal_days" :disabled="true">
  151. <template #append>天</template>
  152. </el-input>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="21">
  156. <el-form-item label="续借理由">
  157. <el-input :model-value="form.latest_renewal?.renewal_reason" type="textarea" :disabled="true" />
  158. </el-form-item>
  159. </el-col>
  160. </el-row>
  161. </div>
  162. </el-form>
  163. <!-- 审批信息流程展示 -->
  164. <!-- <div v-if="isView" style="margin-top: 24px; padding: 0 12px">
  165. <div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
  166. <el-steps :active="activeStep" align-center>
  167. <el-step
  168. title="创建申请"
  169. :description="`创建时间:${ timeline.create }`"
  170. icon="CircleCheck"
  171. :status="activeStep >= 1 ? 'finish' : 'wait'"
  172. />
  173. <el-step
  174. title="待审批"
  175. description="待审批人审批"
  176. icon="CircleCheck"
  177. :status="activeStep >= 2 ? 'finish' : 'wait'"
  178. />
  179. <el-step
  180. title="审批通过"
  181. :description="`审批人:${timeline.approver},时间:${timeline.approve}`"
  182. icon="CircleCheck"
  183. :status="activeStep >= 3 ? 'finish' : 'wait'"
  184. />
  185. <el-step
  186. title="流程完成"
  187. description="流程已结束"
  188. icon="CircleCheck"
  189. :status="activeStep >= 4 ? 'finish' : 'wait'"
  190. />
  191. </el-steps>
  192. </div> -->
  193. <div v-if="isView" style="margin-top: 24px; padding: 0 12px">
  194. <div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
  195. <el-steps :active="steps.length" align-center>
  196. <el-step
  197. v-for="(step, index) in steps"
  198. :key="index"
  199. :title="step.title"
  200. :description="step.description"
  201. icon="CircleCheck"
  202. :status="step.status"
  203. />
  204. </el-steps>
  205. </div>
  206. </el-tab-pane>
  207. <el-tab-pane v-if="isCollect && !shouldHideDeviceList" label="设备清单" name="second">
  208. <el-form :model="form" label-width="110px">
  209. <el-row :gutter="16">
  210. <el-col :span="24">
  211. <div style="margin: 8px 0">
  212. <textarea
  213. ref="searchInputRef"
  214. v-model="searchText"
  215. class="device-code-input"
  216. placeholder="设备编号(支持扫码枪/RFID批量录入)"
  217. :disabled="loading"
  218. autocomplete="off"
  219. rows="1"
  220. style="width: 300px; vertical-align: top;"
  221. @input="handleDeviceInput"
  222. @keydown="handleRFIDKeydown"
  223. @blur="handleDeviceBlur"
  224. @keydown.enter.prevent="handleDeviceEnter"
  225. ></textarea>
  226. <el-button type="primary" style="margin-left: 16px" @click="handleAdd">手动借用</el-button>
  227. </div>
  228. <el-table :data="deviceList" border style="width: 100%">
  229. <el-table-column type="index" label="序号" width="60" align="center" />
  230. <el-table-column prop="device_code" label="设备编号" align="center" />
  231. <el-table-column prop="device_type" label="设备分类" align="center" />
  232. <el-table-column prop="device_name" label="设备名称" align="center" />
  233. <el-table-column prop="borrow_count" label="借用数量" align="center" width="150">
  234. <template #default="{ row }">
  235. <el-input-number v-model="row.borrow_count" :disabled="isView" :min="1" :max="row.available_quantity" size="small" />
  236. </template>
  237. </el-table-column>
  238. <el-table-column prop="brand" label="品牌" align="center" />
  239. <el-table-column prop="device_specification" label="规格型号" align="center" />
  240. <!-- <el-table-column prop="warehouse" label="存放仓库" align="center" /> -->
  241. <el-table-column label="操作" width="80" align="center">
  242. <template #default="{ $index }">
  243. <el-button type="text" style="color: red" :disabled="isView" @click="handleRemove($index)">移除</el-button>
  244. </template>
  245. </el-table-column>
  246. </el-table>
  247. </el-col>
  248. </el-row>
  249. <el-row :gutter="16" style="margin-top: 16px">
  250. <el-col :span="24">
  251. <div style="font-weight: bold; margin-bottom: 8px">实借配件信息</div>
  252. <el-input v-if="isCollect" v-model="collectAccessories" :disabled="isView" type="textarea" :placeholder="isView?'':'请输入实借配件信息'" />
  253. <el-input v-else v-model="form.pre_borrow_accessories" :disabled="isView" type="textarea" :placeholder="isView?'':'请输入实借配件信息'" />
  254. </el-col>
  255. <el-col :span="24" style="margin-top: 16px">
  256. <div style="font-weight: bold; margin-bottom: 8px">备注</div>
  257. <el-input v-model="remark" type="textarea" :disabled="isView" :placeholder="isView?'':'请输入备注'" />
  258. </el-col>
  259. </el-row>
  260. <el-row :gutter="16" style="margin-top: 16px">
  261. <el-col :span="24">
  262. <div style="font-weight: bold; margin-bottom: 8px">异常记录 <span>{{
  263. abnormalList?.length ?
  264. abnormalList.reduce((sum, item) => sum + (Number(item?.condition) || 0), 0)
  265. : 0
  266. }}</span> 次</div>
  267. <el-table v-if="abnormalList.length > 0" :data="abnormalList" border style="width: 100%">
  268. <!-- <el-table-column type="index" label="序号" width="60" align="center" />
  269. <el-table-column prop="application_no" label="借用单编号" align="center" /> -->
  270. <el-table-column prop="operator_name" label="借用人" align="center" />
  271. <el-table-column prop="user_code" label="学号" align="center" />
  272. <el-table-column prop="emergency_phone" label="借用人电话" align="center" />
  273. <!-- <el-table-column prop="time" label="发生时间" align="center" /> -->
  274. <el-table-column prop="type" label="异常" align="center">
  275. <template #default="{ row }">
  276. {{ row.type }}
  277. </template>
  278. </el-table-column>
  279. <el-table-column prop="condition" label="数量" align="center">
  280. <template #default="{ row }">
  281. {{ row.condition }}
  282. </template>
  283. </el-table-column>
  284. </el-table>
  285. </el-col>
  286. </el-row>
  287. </el-form>
  288. </el-tab-pane>
  289. <el-tab-pane v-else-if="!shouldHideDeviceList" label="设备清单" name="third">
  290. <el-form :model="form" label-width="110px">
  291. <el-row :gutter="16">
  292. <el-col :span="24">
  293. <div style="margin: 8px 0" v-if="!isView" >
  294. <textarea
  295. ref="returnSearchInputRef"
  296. v-model="returnSearchText"
  297. class="device-code-input"
  298. placeholder="设备编号(支持扫码枪/RFID批量录入)"
  299. :disabled="loading"
  300. autocomplete="off"
  301. rows="1"
  302. style="width: 300px; vertical-align: top;"
  303. @input="handleReturnDeviceInput"
  304. @keydown="handleReturnRFIDKeydown"
  305. @blur="handleReturnDeviceBlur"
  306. @keydown.enter.prevent="handleReturnDeviceEnter"
  307. ></textarea>
  308. <el-button type="primary" style="margin-left: 16px" @click="handleAdd" :disabled="isView">手动归还</el-button>
  309. </div>
  310. <el-table :data="sortedReturnDeviceList" border style="width: 100%" >
  311. <!-- <el-table-column type="selection" width="55" align="center" />@selection-change="handleSelectionChange" -->
  312. <el-table-column type="index" label="序号" width="60" align="center" />
  313. <el-table-column prop="device_code" label="设备编号" align="center" />
  314. <!-- <el-table-column prop="device_type" label="设备分类" align="center" /> -->
  315. <el-table-column prop="device_name" label="设备名称" align="center" />
  316. <el-table-column label="已归还数量" width="110" align="center">
  317. <template #default="{ row }">
  318. {{ row.returned_quantity ?? 0 }}
  319. </template>
  320. </el-table-column>
  321. <el-table-column
  322. v-if="showUnreturnedReturnTableColumns"
  323. label="未归还可还"
  324. width="110"
  325. align="center"
  326. >
  327. <template #default="{ row }">
  328. {{ row.available_quantity ?? 0 }}
  329. </template>
  330. </el-table-column>
  331. <el-table-column
  332. v-if="showUnreturnedReturnTableColumns"
  333. prop="borrow_count"
  334. label="归还数量"
  335. align="center"
  336. width="150"
  337. >
  338. <template #default="{ row }">
  339. <el-input-number
  340. v-if="!isView && isReturnLinePendingReturn(row)"
  341. v-model="row.borrow_count"
  342. :min="0"
  343. :max="(row.available_quantity ?? 0) > 0 ? (row.available_quantity ?? 0) : 0"
  344. :disabled="(row.available_quantity ?? 0) <= 0"
  345. size="small"
  346. @change="() => clampReturnBorrowCount(row)"
  347. />
  348. <span
  349. v-else-if="isView && isReturnLinePendingReturn(row)"
  350. class="return-cell-text"
  351. >{{ row.borrow_count ?? 0 }}</span>
  352. <span v-else class="return-cell-placeholder">—</span>
  353. </template>
  354. </el-table-column>
  355. <el-table-column prop="brand" label="品牌" align="center" />
  356. <el-table-column prop="model" label="规格型号" align="center" />
  357. <!-- <el-table-column prop="warehouse" label="存放仓库" align="center" /> -->
  358. <el-table-column prop="status" label="状态" align="center">
  359. <template #default="{ row }">
  360. {{ row.return_status.label }}
  361. <!-- <el-tag v-if="!isView" :type="row.status === '已归还' ? 'success' : 'warning'">{{ row.status }}</el-tag>
  362. <el-tag v-else-if="['已领取', '已归还'].includes(form.status_label)">{{ form.status_label }}</el-tag> -->
  363. <!-- <span v-else>{{ form.status_label }}</span> -->
  364. </template>
  365. </el-table-column>
  366. <el-table-column prop="status" label="归还时间" align="center">
  367. <template #default="{ row }">
  368. {{ 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') : '') }}
  369. </template>
  370. </el-table-column>
  371. <el-table-column label="操作" width="120" align="center">
  372. <template #default="{ row }">
  373. <!-- && (!returnDeviceList[$index]?.condition || returnDeviceList[$index]?.photos?.length==0)&& row.problem_records?.length ==0 -->
  374. <el-button :disabled="isView" type="text" style="color: red;"
  375. v-if="!isView"
  376. @click="handleAbnormal(row)">异常操作</el-button>
  377. <el-button
  378. type="text"
  379. style="color: #409EFF;margin-left:0"
  380. @click="handleViewAbnormal(row)"
  381. v-if="row.problem_records?.length || row.condition || row.photos?.length"
  382. >查看异常</el-button>
  383. <!-- <el-button type="text" v-if="!isView" :disabled="isView" style="color: red" @click="handleReturnRemove($index)">移除</el-button> -->
  384. </template>
  385. </el-table-column>
  386. </el-table>
  387. </el-col>
  388. </el-row>
  389. <el-row :gutter="16" style="margin-top: 16px">
  390. <el-col :span="16">
  391. <div style="font-weight: bold; margin-bottom: 8px">实借配件信息</div>
  392. <el-input v-model="form.pre_borrow_accessories" :disabled="true" :placeholder="isView?'':'请输入实借配件信息'" />
  393. </el-col>
  394. <el-col :span="8">
  395. <div style="font-weight: bold; margin-bottom: 8px">当前状态</div>
  396. <el-input v-model="returnStatus" v-if="!isView" :disabled="true" placeholder="" style="width: 150px" />
  397. <el-input :value="form.status==7?'已归还':returnStatus" v-else :disabled="true" placeholder="" style="width: 150px" />
  398. <el-button type="primary" v-if="!isView" style="margin-left: 16px" @click="clickReturn"
  399. :disabled="returnStatus=='已归还'||isView">归还</el-button>
  400. </el-col>
  401. <el-col :span="24" style="margin-top: 16px">
  402. <div style="font-weight: bold; margin-bottom: 8px">备注</div>
  403. <el-input
  404. v-model="displayReturnRemark"
  405. type="textarea"
  406. :disabled="isView"
  407. :placeholder="isView?'':'请输入备注'"
  408. />
  409. </el-col>
  410. </el-row>
  411. <el-row :gutter="16" style="margin-top: 16px">
  412. <el-col :span="24">
  413. <div style="font-weight: bold; margin-bottom: 8px">异常记录 <span>{{
  414. returnAbnormalList?.length ?
  415. returnAbnormalList.reduce((sum, item) => sum + (Number(item?.condition) || 0), 0)
  416. : 0
  417. }}</span> 次</div>
  418. <el-table v-if="returnAbnormalList?.length > 0" :data="returnAbnormalList" border style="width: 100%">
  419. <!-- <el-table-column type="index" label="序号" width="60" align="center" />
  420. <el-table-column prop="application_no" label="借用单编号" align="center" /> -->
  421. <el-table-column prop="operator_name" label="借用人" align="center" />
  422. <el-table-column prop="user_code" label="学号" align="center" />
  423. <el-table-column prop="emergency_phone" label="借用人电话" align="center" />
  424. <!-- <el-table-column prop="time" label="发生时间" align="center" /> -->
  425. <el-table-column prop="type" label="异常" align="center">
  426. <template #default="{ row }">
  427. {{ row.type }}
  428. </template>
  429. </el-table-column>
  430. <el-table-column prop="condition" label="数量" align="center">
  431. <template #default="{ row }">
  432. {{ row.condition }}
  433. </template>
  434. </el-table-column>
  435. </el-table>
  436. </el-col>
  437. </el-row>
  438. </el-form>
  439. </el-tab-pane>
  440. </el-tabs>
  441. <template #footer>
  442. <el-button @click="onCancel">关闭</el-button>
  443. <el-button type="primary" @click="onSubmit" v-if="!isView"> {{ isCollect ? '提交' : '确认' }}</el-button>
  444. </template>
  445. </el-dialog>
  446. <SelectDeviceDialog
  447. v-model:visible="showSelectDeviceDialog"
  448. @confirm="onDeviceSelected"
  449. :device-ids="unreturnedDeviceIds"
  450. :return-mode="activeName === 'third'"
  451. :device-status-map="deviceStatusMap"
  452. :selected-device-codes="selectedDeviceCodes"
  453. :disabled-device-ids="disabledDeviceIds"
  454. />
  455. <SettlementDialog v-model:visible="showSettlementDialog" :settlement-data="settlementData" :modelValue="borrowForm" />
  456. <AbnormalDialog v-model:visible="showAbnormalDialog" @confirm="onAbnormalConfirm" />
  457. <ViewAbnormalDialog
  458. v-model:visible="showViewAbnormalDialog"
  459. :abnormal-data="currentAbnormalData"
  460. />
  461. <!-- 图片预览对话框 -->
  462. <el-dialog v-model="dialogVisible" title="图片预览" width="auto" center>
  463. <img width="100%" :src="dialogImageUrl" alt="Preview Image" style="max-width: 100%; max-height: 80vh;" />
  464. </el-dialog>
  465. </template>
  466. <script setup lang="ts">
  467. import { ref, watch, defineProps, defineEmits, onMounted, onBeforeUnmount, computed, nextTick } from 'vue';
  468. import SelectDeviceDialog from './SelectDeviceDialog/index.vue';
  469. import SettlementDialog from './SettlementDialog.vue';
  470. import AbnormalDialog from './AbnormalDialog/index.vue';
  471. import ViewAbnormalDialog from './ViewAbnormalDialog/index.vue';
  472. import dayjs from 'dayjs';
  473. import { ElMessage } from 'element-plus';
  474. import * as api from '../../api';
  475. import * as deviceApi from '../../../device/api';
  476. import { CollectEquipment, ReturnEquipment } from '../../api';
  477. import type { TabsPaneContext } from 'element-plus';
  478. import { getUserInfo } from '../../../login/api';
  479. import { request } from '/@/utils/service';
  480. // 禁止选择今天之前的日期
  481. const disabledDate = (time: Date) => {
  482. // 获取今天的开始时间(准确到日)
  483. const today = new Date()
  484. today.setHours(0, 0, 0, 0)
  485. // 返回true表示禁用,禁用今天之前的所有日期
  486. return time.getTime() < today.getTime()
  487. }
  488. /* 获取管理员列表 */
  489. const adminList = ref([]);
  490. async function getAdminList() {
  491. const res = await getUserInfo();
  492. adminList.value = res.data;
  493. console.log("adminList.value:::",adminList.value)
  494. }
  495. /* */
  496. /* 获取所有用户 */
  497. const allUserList = ref([]);
  498. let allUserLoaded = false;
  499. const allUserLoading = ref(false);
  500. async function getAllUserList() {
  501. if (allUserLoaded || allUserLoading.value) return;
  502. allUserLoading.value = true;
  503. try {
  504. // 分页拉取,避免一次性超大 limit 硬编码
  505. const pageSize = 100;
  506. let page = 1;
  507. const users: any[] = [];
  508. while (true) {
  509. const res = await api.GetAllUser({ page, limit: pageSize });
  510. const list = Array.isArray(res?.data) ? res.data : [];
  511. users.push(...list);
  512. if (list.length < pageSize) break;
  513. page += 1;
  514. }
  515. allUserList.value = users;
  516. // 设置默认选择(仅在当前未有选中时)
  517. if ((!form.value.app_user_borrower || !form.value.app_user_borrower.id) && allUserList.value.length > 0) {
  518. const first: any = allUserList.value[0];
  519. form.value.app_user_borrower = {
  520. id: first.id,
  521. name: first.name,
  522. user_code: first.user_code,
  523. mobile: first.mobile
  524. };
  525. }
  526. allUserLoaded = true;
  527. } catch (e) {
  528. /* empty */
  529. } finally {
  530. allUserLoading.value = false;
  531. }
  532. }
  533. interface ApiResponse {
  534. code: number;
  535. data?: any;
  536. message?: string;
  537. }
  538. // 用户最小结构用于表单回显
  539. interface AppUserBorrower {
  540. id: number | string;
  541. name?: string;
  542. user_code?: string;
  543. mobile?: string;
  544. }
  545. // 定义接口
  546. interface Device {
  547. id: string | number;
  548. category_name: string;
  549. name?: string;
  550. brand?: string;
  551. model?: string;
  552. warehouse: string;
  553. device_specification?: string;
  554. device_name?: string;
  555. }
  556. interface DeviceListItem {
  557. device_no: string | number;
  558. device_code?: string;
  559. device_type: string;
  560. device_name?: string; // 改为可选
  561. borrow_count: number;
  562. brand: string;
  563. model?: string; // 改为可选
  564. warehouse: string;
  565. status?: string;
  566. return_status?: {
  567. value?: number;
  568. label?: string;
  569. };
  570. return_time?: string;
  571. is_return?: boolean;
  572. condition?: string;
  573. photos?: Array<{
  574. filename: string;
  575. data: string;
  576. }>;
  577. device_specification?: string;
  578. /** 归还页签:可归还上限,来自 items.pending_quantity */
  579. available_quantity?: number;
  580. /** 截止当前已在库登记归还的数量,来自 items.returned_quantity */
  581. returned_quantity?: number;
  582. problem_records?: any[];
  583. damage_type?: number;
  584. /** 借用单明细行接口返回的更新时间,用于列表排序 */
  585. line_update_at?: string;
  586. /** 本页对行做了归还/数量等操作时的排序时间戳,与 line_update_at 取较大者参与排序 */
  587. sort_touched_at?: number;
  588. }
  589. interface FormItem {
  590. device: string | number;
  591. remark: string;
  592. quantity: number;
  593. location: string;
  594. device_name?: string;
  595. device_specification?: string;
  596. condition?: string;
  597. photos?: Array<{
  598. filename: string;
  599. data: string;
  600. }>;
  601. }
  602. interface FormData {
  603. application_no: string;
  604. emergency_contact: string;
  605. emergency_phone: string;
  606. app_user_borrower: AppUserBorrower | any;
  607. team_type: number;
  608. team_members_count: number;
  609. team_members: string;
  610. expected_start_time: string;
  611. expected_end_time: string;
  612. borrower_dept: string;
  613. purpose: string;
  614. applicant_remark_type: string;
  615. applicant_remark: string;
  616. items: FormItem[];
  617. accessory_info: string;
  618. borrow_type: number;
  619. return_location: string;
  620. status_label?: string;
  621. id?: number;
  622. records?: any[];
  623. borrower_info?: {
  624. user_code: string;
  625. };
  626. borrower_damage_count?: number;
  627. borrower_overdue_count?:number;
  628. accessories?: string;
  629. pre_borrow_accessories?:string;
  630. latest_renewal?: {
  631. renewal_days?: number | string;
  632. renewal_reason?: string;
  633. };
  634. problem_remarks?: string[];
  635. }
  636. interface AbnormalData {
  637. damage_type:number;
  638. condition: string;
  639. photos: Array<{
  640. filename: string;
  641. data: string;
  642. }>;
  643. }
  644. interface AbnormalRecord {
  645. application_no: string;
  646. operator_name: string;
  647. user_code: string;
  648. emergency_phone: string;
  649. type: '损坏' | '逾期';
  650. condition: number;
  651. create_time: string;
  652. }
  653. const now = dayjs().format('YYYY-MM-DD HH:mm:ss');
  654. const props = defineProps<{ visible: boolean; modelValue?: any }>();
  655. const isEdit = computed(() => props.modelValue?.mode === 'edit');
  656. const isView = computed(() => props.modelValue?.mode === 'view');
  657. const isAdd = computed(() => props.modelValue?.mode === 'add');
  658. const isCollect = computed(() => props.modelValue?.mode === 'collect');
  659. const isReturn = computed(() => props.modelValue?.mode === 'return');
  660. // 获取待审批人显示名称(与 buildSteps 中逻辑一致)
  661. // 待审批时显示当前环节审批人;审批完成后显示全部环节(老师、学院领导、管理员)的审批人
  662. function getPendingApproverDisplay(data: any): string {
  663. if (!data) return '';
  664. const adminInfo = data.admin_approver_info;
  665. const status = data.status;
  666. // 审批完成后:按实际审批顺序(老师→学院领导→管理员)显示
  667. // 优先用 approval_records 的审批顺序;否则用 all_steps_status 按 step_order
  668. if (status >= 2 && status !== 3) {
  669. const approvedRecords = data.approval_records?.filter((r: any) => r.status === 1) || [];
  670. if (approvedRecords.length) {
  671. const sorted = [...approvedRecords].sort(
  672. (a: any, b: any) => (a.step_order ?? 0) - (b.step_order ?? 0)
  673. );
  674. const names = sorted
  675. .map((r: any) => (r.approver_name || r.app_user_approver_name || r.name || '').trim())
  676. .filter(Boolean);
  677. if (names.length) return names.join('、');
  678. }
  679. if (adminInfo?.all_steps_status?.length) {
  680. const allNames: string[] = [];
  681. const seen = new Set<string>();
  682. const sortedSteps = [...adminInfo.all_steps_status].sort(
  683. (a: any, b: any) => (a.step_order ?? 0) - (b.step_order ?? 0)
  684. );
  685. for (const step of sortedSteps) {
  686. if (step.approvers?.length) {
  687. for (const a of step.approvers) {
  688. const name = (a.name || '').trim();
  689. if (name && !seen.has(name)) {
  690. seen.add(name);
  691. allNames.push(name);
  692. }
  693. }
  694. }
  695. }
  696. if (allNames.length) return allNames.join('、');
  697. }
  698. }
  699. // 待审批时:取当前待审批环节,排除已通过的步骤(API 可能将已通过步骤仍标为 is_current)
  700. const isApproved = (s: any) => s.status === 'approved' || s.status_label === '已通过';
  701. const isPendingOrCurrent = (s: any) =>
  702. !isApproved(s) && (
  703. s.status === 'pending' || s.status_label === '待审核' ||
  704. s.status === 'current' || s.status_label === '当前步骤' || s.is_current === true
  705. );
  706. const candidateSteps = adminInfo?.all_steps_status?.filter(isPendingOrCurrent) || [];
  707. const sortedCandidates = [...candidateSteps].sort((a: any, b: any) => (a.step_order ?? 0) - (b.step_order ?? 0));
  708. const pendingStep = sortedCandidates[0];
  709. if (pendingStep?.approvers?.length) {
  710. const stepName = pendingStep.step_name || '';
  711. let approvers = pendingStep.approvers;
  712. if (stepName.includes('老师')) {
  713. // 老师环节:仅显示 type 为 app_user 的审批人(老师姓名)
  714. approvers = approvers.filter((a: any) => a.type === 'app_user');
  715. } else if (stepName.includes('管理员')) {
  716. // 二级管理员/管理员环节:仅显示 type 为 admin 的审批人(超级管理员)
  717. approvers = approvers.filter((a: any) => a.type === 'admin');
  718. }
  719. const names = approvers.map((a: any) => a.name).filter((n: string) => n && n.trim());
  720. if (names.length) return names.join('、');
  721. }
  722. const currentApprovers = adminInfo?.current_step?.approvers;
  723. if (Array.isArray(currentApprovers) && currentApprovers.length) {
  724. const names = currentApprovers.map((a: any) => a.name).filter((n: string) => n && n.trim());
  725. if (names.length) return names.join('、');
  726. }
  727. const currentStep = adminInfo?.all_steps_status?.find((s: any) => s.is_current);
  728. if (currentStep?.approvers?.length) {
  729. const names = currentStep.approvers.map((a: any) => a.name).filter((n: string) => n && n.trim());
  730. if (names.length) return names.join('、');
  731. }
  732. if (data.approval_records?.length) {
  733. const pendingRecords = data.approval_records.filter(
  734. (item: any) => (status === 1 ? item.status !== 1 : item.status !== 0)
  735. );
  736. const names = pendingRecords
  737. .map((item: any) => item.approver_name || item.app_user_approver_name || item.name)
  738. .filter((name: string) => name && name.trim());
  739. if (names.length) return names.join('、');
  740. }
  741. return data.approver_info?.name || '未知';
  742. }
  743. // 表单审批人显示:待审批时与流程步骤一致,审批完成后显示管理员
  744. const displayApproverName = computed(() => {
  745. const data = form.value as any;
  746. if (!data?.id) return '';
  747. const status = data.status;
  748. if (status >= 2 && status !== 3) return '管理员'; // 审批通过
  749. if (status >= 4) return '管理员'; // 流程完成
  750. if (status === 1) return getPendingApproverDisplay(data); // 待审批
  751. if (status === 3) {
  752. const rejectNames = data.approval_records
  753. ?.filter((item: any) => item.status === 2)
  754. ?.map((item: any) => item.approver_name || item.app_user_approver_name || item.name)
  755. ?.filter((name: string) => name && name.trim()) || [];
  756. return rejectNames.join('、') || data.approver_info?.name || '未知';
  757. }
  758. return data.approver_info?.name || data.admin_approver_info?.name || '';
  759. });
  760. // 计算是否应该隐藏设备清单标签页
  761. const shouldHideDeviceList = computed(() => {
  762. if (!isView.value) return false;
  763. // 检查状态
  764. const status = (form.value as any).status;
  765. const statusLabel = (form.value as any).status_label;
  766. // 审批拒绝:隐藏设备清单
  767. const isRejected = status === 3 || (typeof statusLabel === 'string' && statusLabel.includes('拒绝'));
  768. if (isRejected) {
  769. return true;
  770. }
  771. // 强制显示:状态大于 5 或状态标签为"已借出"
  772. if ((typeof status === 'number' && status > 5) || statusLabel === '已借出') {
  773. return false;
  774. }
  775. // 审批通过:隐藏设备清单(不影响已借出/更高级状态的强制显示)
  776. const isApproved = typeof statusLabel === 'string' && statusLabel.includes('已批准');
  777. if (isApproved) {
  778. return true;
  779. }
  780. // 待审批状态:隐藏设备清单
  781. const isPendingApproval = status < 2 || statusLabel === '待审批';
  782. // 其他情况默认显示
  783. return isPendingApproval;
  784. });
  785. // 计算设备状态映射
  786. const deviceStatusMap = computed(() => {
  787. const statusMap: Record<string | number, any> = {};
  788. returnDeviceList.value.forEach(device => {
  789. if (device.device_no && device.return_status) {
  790. statusMap[device.device_no] = device.return_status;
  791. }
  792. });
  793. return statusMap;
  794. });
  795. const emit = defineEmits(['update:visible', 'update:modelValue', 'submit']);
  796. const visible = ref(props.visible);
  797. const formRef = ref();
  798. // 图片预览相关
  799. const dialogImageUrl = ref('');
  800. const dialogVisible = ref(false);
  801. const timeline = ref({
  802. create: '',
  803. approve: '',
  804. approver: ''
  805. });
  806. // const activeStep = ref(1);
  807. const activeName = ref('first');
  808. const returnStatus = ref('未归还'); // 添加独立的状态变量
  809. // 输入框引用
  810. const searchInputRef = ref<any>(null);
  811. const returnSearchInputRef = ref<any>(null);
  812. // 借用列表相关数据
  813. const searchText = ref('');
  814. const deviceList = ref<DeviceListItem[]>([]);
  815. const accessoryInfo = ref('');
  816. const remark = ref('');
  817. // 领取模式下的"实借配件信息"本地输入,不回显历史
  818. const collectAccessories = ref('');
  819. // RFID高速扫码缓冲相关
  820. const rfidInputBuffer = ref('');
  821. // RFID标签数组,用于收集批量识别的标签
  822. const rfidTagArray = ref<string[]>([]);
  823. // 当前正在输入的标签
  824. const currentRfidTag = ref('');
  825. // 正在处理的标签集合,用于去重
  826. const processingTags = ref<Set<string>>(new Set());
  827. // 是否正在处理标签数组
  828. const isProcessingTagArray = ref(false);
  829. // 待提交的设备编号数组(参考 InventoryDialog 实现)
  830. const pendingDeviceCodes = ref<string[]>([]);
  831. // 是否正在自动循环提交
  832. const isAutoSubmitting = ref(false);
  833. let rfidInputTimer: ReturnType<typeof setTimeout> | null = null;
  834. // 统一的标签数组处理延迟定时器,避免多次触发
  835. let processTagArrayTimer: ReturnType<typeof setTimeout> | null = null;
  836. const loading = ref(false);
  837. // 记录最后一次输入时间,用于检测是否是高速扫码输入
  838. let lastInputTime = 0;
  839. // 记录连续输入次数,用于判断是否是扫码输入
  840. let consecutiveInputCount = 0;
  841. // RFID读取规则配置(简化版,可根据需要扩展)
  842. const readRuleConfig = ref({
  843. enableRFIDBuffer: true, // 是否启用RFID缓冲
  844. rfidInputTimeout: 120, // RFID缓冲判定时间(ms)
  845. separator: ' ', // 分隔符
  846. minInputSpeed: 30, // 最小输入速度(ms),低于此值认为是扫码输入
  847. tagSeparatorTimeout: 100, // 标签分隔判定时间(ms),超过此时间认为是一个新标签
  848. });
  849. // 归还设备相关数据
  850. const returnSearchText = ref('');
  851. const returnDeviceList = ref<DeviceListItem[]>([]);
  852. const returnAccessoryInfo = ref('');
  853. const returnRemark = ref('');
  854. const selectedDevices = ref<DeviceListItem[]>([]); // 添加选中设备列表
  855. // 归还流程 RFID高速扫码缓冲相关
  856. const returnRfidInputBuffer = ref('');
  857. // 归还流程 RFID标签数组,用于收集批量识别的标签
  858. const returnRfidTagArray = ref<string[]>([]);
  859. // 归还流程当前正在输入的标签
  860. const returnCurrentRfidTag = ref('');
  861. // 归还流程正在处理的标签集合,用于去重
  862. const returnProcessingTags = ref<Set<string>>(new Set());
  863. // 归还流程是否正在处理标签数组
  864. const isProcessingReturnTagArray = ref(false);
  865. let returnRfidInputTimer: ReturnType<typeof setTimeout> | null = null;
  866. // 统一的归还标签数组处理延迟定时器,避免多次触发
  867. let returnProcessTagArrayTimer: ReturnType<typeof setTimeout> | null = null;
  868. // 记录归还流程最后一次输入时间,用于检测是否是高速扫码输入
  869. let returnLastInputTime = 0;
  870. // 记录归还流程连续输入次数,用于判断是否是扫码输入
  871. let returnConsecutiveInputCount = 0;
  872. // 备注显示值计算属性:查看模式下显示 problem_remarks[0],否则显示 returnRemark
  873. const displayReturnRemark = computed({
  874. get: () => {
  875. if (isView.value && form.value.problem_remarks?.[0]) {
  876. return form.value.problem_remarks[0];
  877. }
  878. return returnRemark.value;
  879. },
  880. set: (val: string) => {
  881. if (!isView.value) {
  882. returnRemark.value = val;
  883. }
  884. }
  885. });
  886. /** 从借用单明细行解析待归还数量:优先用 pending_quantity,缺省时用借出-已还推算(与后端 items 一致,避免硬编码) */
  887. function getPendingUnreturnedFromItem(item: any): number {
  888. if (item == null) return 0;
  889. const raw = item.pending_quantity;
  890. if (raw !== undefined && raw !== null && String(raw) !== '') {
  891. const n = Math.floor(Number(raw));
  892. if (!Number.isNaN(n)) return Math.max(0, n);
  893. }
  894. const borrowed = Number(item.borrowed_quantity) || 0;
  895. const returned = Number(item.returned_quantity) || 0;
  896. return Math.max(0, borrowed - returned);
  897. }
  898. /** 从借用单 items 行解析「明细更新时间」(兼容常见后端字段名,避免写死单一路径) */
  899. function getItemLineUpdateTimeForSort(item: any): string | undefined {
  900. if (item == null || typeof item !== 'object') return undefined;
  901. const v =
  902. item.update_datetime ?? item.update_time ?? item.modified_time ?? item.update_at;
  903. if (v == null || v === '') return undefined;
  904. return String(v);
  905. }
  906. function getReturnRowSortMs(row: DeviceListItem): number {
  907. const serverRaw = row.line_update_at;
  908. const serverMs =
  909. serverRaw && dayjs(serverRaw).isValid() ? dayjs(serverRaw).valueOf() : 0;
  910. const localMs = row.sort_touched_at ?? 0;
  911. return Math.max(serverMs, localMs);
  912. }
  913. function touchReturnRowSort(row: DeviceListItem) {
  914. row.sort_touched_at = Date.now();
  915. }
  916. /** 将 form.items 单行映射为归还列表行:上限为待归还;归还数量由扫码/手工录入,从 0 起算 */
  917. function mapFormItemToReturnDeviceListRow(item: any): DeviceListItem {
  918. const pending = getPendingUnreturnedFromItem(item);
  919. const lineUpdate = getItemLineUpdateTimeForSort(item);
  920. return {
  921. device_no: item.device,
  922. device_code: item.device_code,
  923. device_type: item.remark,
  924. device_name: item.device_name,
  925. borrow_count: 0,
  926. brand: item.brand || item.device_brand || '',
  927. model: item.device_specification,
  928. warehouse: item.location || item.device_storage_location || '',
  929. problem_records: item.problem_records,
  930. return_status: item.return_status,
  931. return_time: item.return_times,
  932. available_quantity: pending,
  933. returned_quantity: Math.max(0, Number(item.returned_quantity) || 0),
  934. line_update_at: lineUpdate,
  935. sort_touched_at: 0
  936. };
  937. }
  938. function clampReturnBorrowCount(row: DeviceListItem) {
  939. const max = row.available_quantity ?? 0;
  940. if (max <= 0) {
  941. row.borrow_count = 0;
  942. return;
  943. }
  944. let n = Number(row.borrow_count) || 0;
  945. if (n < 0) n = 0;
  946. if (n > max) n = max;
  947. row.borrow_count = n;
  948. touchReturnRowSort(row);
  949. }
  950. /** 是否仍有待归还(有未归还可还):用于表格列在「只展示已归还」与「展示待还+本次归还」间切换 */
  951. function isReturnLinePendingReturn(row: DeviceListItem) {
  952. return (Number(row.available_quantity) || 0) > 0;
  953. }
  954. /**
  955. * 扫码命中列表中的设备时:归还数量 +1,不超过待归还数。
  956. * 成功返回 null;失败返回提示文案。不在此调用 ElMessage,由扫码/RFID 批处理处统一只弹一次。
  957. */
  958. function tryApplyReturnScanIncrement(row: DeviceListItem): string | null {
  959. const cap = row.available_quantity ?? 0;
  960. if (cap <= 0) {
  961. return '该设备无待归还数量';
  962. }
  963. const current = Number(row.borrow_count) || 0;
  964. if (current >= cap) {
  965. return '该设备归还数量已达待归还上限';
  966. }
  967. row.borrow_count = current + 1;
  968. if (row.borrow_count >= cap) {
  969. row.is_return = true;
  970. row.return_time = dayjs().format('YYYY-MM-DD HH:mm:ss');
  971. }
  972. touchReturnRowSort(row);
  973. return null;
  974. }
  975. // 统一判定「该明细是否已把本次可归还数记满」:用于选设备白名单/全部完成判断(不依赖硬编码业务状态值)
  976. const isDeviceReturned = (device: any) => {
  977. const cap = Number(device?.available_quantity) || 0;
  978. if (cap <= 0) return true;
  979. return (Number(device?.borrow_count) || 0) >= cap;
  980. };
  981. // 过滤未归还设备的 device_no 列表,用于设备选择弹窗的排除
  982. const unreturnedDeviceIds = computed(() =>
  983. returnDeviceList.value
  984. .filter((d) => !isDeviceReturned(d))
  985. .map((d) => d.device_no)
  986. );
  987. // 是否全部已归还(仅在归还页签生效)
  988. const allReturned = computed(() => unreturnedDeviceIds.value.length === 0);
  989. /** 列表中是否仍有「待归还」行:为 false 时整表隐藏「未归还可还」「归还数量」两列(仅保留已归还数量等) */
  990. const showUnreturnedReturnTableColumns = computed(() =>
  991. returnDeviceList.value.some((d) => (Number(d.available_quantity) || 0) > 0)
  992. );
  993. /** 归还设备表按「明细/本页最近修改时间」降序,最近在前 */
  994. const sortedReturnDeviceList = computed(() =>
  995. [...returnDeviceList.value].sort(
  996. (a, b) => getReturnRowSortMs(b) - getReturnRowSortMs(a)
  997. )
  998. );
  999. //审批步骤
  1000. const steps = ref<any[]>([]);
  1001. // 仓库映射(id -> name)
  1002. const warehouseMap = ref<Record<string, string>>({});
  1003. async function loadWarehouses() {
  1004. try {
  1005. const res = await request({
  1006. url: '/api/system/warehouse/',
  1007. method: 'get',
  1008. params: { page: 1, limit: 999 }
  1009. });
  1010. if (res?.code === 2000 && Array.isArray(res.data)) {
  1011. warehouseMap.value = Object.fromEntries(
  1012. res.data.map((w: any) => [String(w.id), w.name])
  1013. );
  1014. }
  1015. } catch (e) {
  1016. /* empty */
  1017. }
  1018. }
  1019. function getWarehouseName(id: any) {
  1020. const key = id != null ? String(id) : '';
  1021. return warehouseMap.value[key] ?? id;
  1022. }
  1023. /** 从 Promise.allSettled 单条结果安全取出 success/message,避免解构 undefined 导致整批 try 抛错、误报「处理批次时发生错误」 */
  1024. function readSettledListStepResult(
  1025. result: PromiseSettledResult<unknown>,
  1026. codeLabel: string
  1027. ): { success: boolean; message?: string } {
  1028. if (result.status === 'rejected') {
  1029. const err = result.reason instanceof Error ? result.reason.message : String(result.reason);
  1030. return { success: false, message: `处理设备编号 ${codeLabel} 时发生错误: ${err}` };
  1031. }
  1032. const v = result.value as { success?: boolean; message?: string } | null | undefined;
  1033. if (v == null || typeof v !== 'object' || typeof v.success !== 'boolean') {
  1034. return { success: false, message: `处理设备编号 ${codeLabel} 时返回数据异常` };
  1035. }
  1036. return { success: v.success, message: v.message };
  1037. }
  1038. /**
  1039. * 从设备查询接口解析可借/可用数量(领取页扫码):先取根字段,再取 inventory.available_quantity
  1040. */
  1041. function getDeviceAvailableQuantityForBorrow(device: any): number {
  1042. if (device == null) return 0;
  1043. const top = device.available_quantity;
  1044. if (top !== undefined && top !== null && String(top) !== '') {
  1045. const n = Number(top);
  1046. if (!Number.isNaN(n)) return Math.max(0, Math.floor(n));
  1047. }
  1048. const inv = device.inventory?.available_quantity;
  1049. if (inv !== undefined && inv !== null && String(inv) !== '') {
  1050. const n = Number(inv);
  1051. if (!Number.isNaN(n)) return Math.max(0, Math.floor(n));
  1052. }
  1053. return 0;
  1054. }
  1055. // 添加结算单相关的状态
  1056. const showSettlementDialog = ref(false);
  1057. const settlementData = ref<any>(null);
  1058. const borrowForm = ref<any>(null);
  1059. // 添加异常操作相关的状态
  1060. const showAbnormalDialog = ref(false);
  1061. const currentAbnormalDeviceNo = ref<string | number | null>(null);
  1062. // 添加查看异常相关的状态
  1063. const showViewAbnormalDialog = ref(false);
  1064. const currentAbnormalData = ref<AbnormalData>({
  1065. damage_type:0,
  1066. condition: '',
  1067. photos: []
  1068. });
  1069. //审批
  1070. function buildSteps(data: any) {
  1071. steps.value = [
  1072. {
  1073. title: '创建申请',
  1074. description: `创建时间:${data.create_datetime ? dayjs(data.create_datetime).format('YYYY-MM-DD HH:mm:ss') : ''}`,
  1075. status: 'finish'
  1076. },
  1077. {
  1078. title: '待审批',
  1079. description: `待审批人:${getPendingApproverDisplay(data)} 审批`,
  1080. status: data.status >= 2 ? 'finish' : 'process'
  1081. }
  1082. ];
  1083. const approverinfo = data.approver_info ?? data.admin_approver_info
  1084. if (data.status >= 2&&data.status!=3 && data.borrow_type!=1) {
  1085. // 将审批记录倒序排列
  1086. const reversedApprovalRecords = [...data.approval_records]
  1087. // 先找出所有审批通过的记录
  1088. const approvedRecords = reversedApprovalRecords.filter((item:any) => item.status === 1)
  1089. const lastApprovedIndex = approvedRecords.length - 1
  1090. reversedApprovalRecords.forEach((item:any,index:number) => {
  1091. if(item.status === 1){
  1092. // 找到当前记录在审批通过记录中的索引
  1093. const currentApprovedIndex = approvedRecords.findIndex((record:any) => record === item)
  1094. // 判断是否是最后一个审批通过的记录
  1095. const isLastApproved = currentApprovedIndex === lastApprovedIndex
  1096. /* if(index == 1){1
  1097. steps.value.push({
  1098. title: '审批通过',
  1099. description: `审批人:${item.approver_name||item.app_user_approver_name},时 间:${item.approve_time}`,
  1100. status: 'finish'
  1101. });
  1102. }else{ */
  1103. // 只在最后一个审批通过的记录中显示领取仓库
  1104. const warehouseInfo = isLastApproved ? `,领取仓库:${getWarehouseName(data.warehouse)||'暂无仓库'}` : ''
  1105. steps.value.push({
  1106. title: '审批通过',
  1107. description: `审批人:${item.approver_name||item.app_user_approver_name},时 间:${item.create_datetime ? dayjs(item.create_datetime).format('YYYY-MM-DD HH:mm:ss') : ''}${warehouseInfo}`,
  1108. status: 'finish'
  1109. });
  1110. /* } */
  1111. }
  1112. });
  1113. } else if (data.status === 3) {
  1114. // console.log("data.approver_name:::",data.approver_info.name)
  1115. const rejectNames = data.approval_records
  1116. .filter((item:any) => item.status === 2)
  1117. .map((item:any) => item.approver_name || item.app_user_approver_name || item.name)
  1118. .filter((name:any) => name && name.trim());
  1119. const rejectReason = data.approval_records
  1120. .filter((item:any) => item.status === 2)
  1121. .map((item:any) => item.approve_remark)
  1122. .filter((reason:any) => reason && reason.trim());
  1123. const rejectTime = data.approval_records
  1124. .filter((item:any) => item.status === 2)
  1125. .map((item:any) => item.approve_time)
  1126. .filter((time:any) => time && time.trim());
  1127. steps.value.push({
  1128. title: '审批拒绝',
  1129. description: `审批人:${rejectNames.join('、')},拒绝原因: ${rejectReason.join('、')},时间:${rejectTime.join('、')}`,
  1130. status: 'error'
  1131. });
  1132. }
  1133. if (data.status >= 4 ||data.borrow_type==1) {
  1134. steps.value.push({
  1135. title: '流程完成',
  1136. description: '流程已结束',
  1137. status: 'finish'
  1138. });
  1139. }
  1140. }
  1141. // 处理异常操作(按 device_no 定位,避免与「按时间排序的表格」下标错位)
  1142. const handleAbnormal = (row: DeviceListItem) => {
  1143. currentAbnormalDeviceNo.value = row.device_no;
  1144. showAbnormalDialog.value = true;
  1145. };
  1146. // 处理异常操作确认
  1147. const onAbnormalConfirm = (data: { condition: string; photos: any[]; damage_type?: number }) => {
  1148. const key = currentAbnormalDeviceNo.value;
  1149. if (key != null && key !== '') {
  1150. const device = returnDeviceList.value.find((d) => d.device_no === key);
  1151. if (device) {
  1152. device.condition = data.condition;
  1153. device.photos = data.photos;
  1154. device.damage_type = data.damage_type;
  1155. touchReturnRowSort(device);
  1156. ElMessage.success('异常信息已保存');
  1157. }
  1158. }
  1159. currentAbnormalDeviceNo.value = null;
  1160. };
  1161. // 处理查看异常
  1162. const handleViewAbnormal = (row: DeviceListItem) => {
  1163. const device = row;
  1164. console.log("device:::",device);
  1165. if (device) {
  1166. if(device.problem_records?.length){
  1167. console.log(device.problem_records?.[0].damage_type.value)
  1168. currentAbnormalData.value = {
  1169. damage_type: Number(device.problem_records?.[0].damage_type.value) || 0,/* ||device.damage_type.value */
  1170. condition: device.problem_records?.[0].device_condition_after ||'',
  1171. photos: device.problem_records?.[0].returned_images.map((item:any)=>item.image_url) ||[]
  1172. };
  1173. }else{
  1174. currentAbnormalData.value = {
  1175. damage_type: device.damage_type ||0,
  1176. condition: device.condition ||'',
  1177. photos: device.photos ||[]
  1178. };
  1179. }
  1180. showViewAbnormalDialog.value = true;
  1181. }
  1182. };
  1183. // 清理RFID输入定时器
  1184. const clearRFIDInputTimer = () => {
  1185. if (rfidInputTimer) {
  1186. clearTimeout(rfidInputTimer);
  1187. rfidInputTimer = null;
  1188. }
  1189. };
  1190. // 清理标签数组处理延迟定时器
  1191. const clearProcessTagArrayTimer = () => {
  1192. if (processTagArrayTimer) {
  1193. clearTimeout(processTagArrayTimer);
  1194. processTagArrayTimer = null;
  1195. }
  1196. };
  1197. // 清理归还流程RFID输入定时器
  1198. const clearReturnRFIDInputTimer = () => {
  1199. if (returnRfidInputTimer) {
  1200. clearTimeout(returnRfidInputTimer);
  1201. returnRfidInputTimer = null;
  1202. }
  1203. };
  1204. // 清理归还标签数组处理延迟定时器
  1205. const clearReturnProcessTagArrayTimer = () => {
  1206. if (returnProcessTagArrayTimer) {
  1207. clearTimeout(returnProcessTagArrayTimer);
  1208. returnProcessTagArrayTimer = null;
  1209. }
  1210. };
  1211. // 处理RFID标签数组,逐个检索并提交
  1212. // 自动循环提交待提交的设备编号(参考 InventoryDialog 实现)
  1213. const autoSubmitPendingCodes = async () => {
  1214. // 如果正在提交或没有待提交的设备编号,直接返回
  1215. if (isAutoSubmitting.value || pendingDeviceCodes.value.length === 0) {
  1216. return;
  1217. }
  1218. isAutoSubmitting.value = true;
  1219. try {
  1220. // 复制待提交的设备编号数组并清空,避免在处理过程中被修改
  1221. const codesToSubmit = [...pendingDeviceCodes.value];
  1222. pendingDeviceCodes.value = [];
  1223. console.log(`[autoSubmitPendingCodes] 开始自动提交,共 ${codesToSubmit.length} 个设备编号:`, codesToSubmit);
  1224. // 逐个循环提交,每个设备编号独立处理,不受成功或失败影响
  1225. for (let i = 0; i < codesToSubmit.length; i++) {
  1226. const code = codesToSubmit[i];
  1227. if (!code || !code.trim()) continue;
  1228. const trimmedCode = code.trim();
  1229. try {
  1230. // 查询设备信息
  1231. const res = await deviceApi.GetList({
  1232. page: 1,
  1233. limit: 1,
  1234. code: trimmedCode,
  1235. status: 1
  1236. });
  1237. if (res.data && res.data.length > 0) {
  1238. const device = res.data[0];
  1239. const avail = getDeviceAvailableQuantityForBorrow(device);
  1240. if (avail <= 0) {
  1241. const label = [device.name, device.code].filter(Boolean).join(' ') || trimmedCode;
  1242. ElMessage.warning(`设备 ${label}(${trimmedCode})库存不足`);
  1243. continue;
  1244. }
  1245. // 检查设备是否已存在于列表中
  1246. const existingDevice = deviceList.value.find(d => d.device_no === device.id);
  1247. if (existingDevice) {
  1248. // 如果已存在,增加借用数量
  1249. existingDevice.borrow_count++;
  1250. console.log(`设备 ${trimmedCode} 已存在,借用数量+1`);
  1251. } else {
  1252. // 如果不存在,添加到列表
  1253. deviceList.value.push({
  1254. device_no: device.id,
  1255. device_code: device.code,
  1256. device_type: device.category_name,
  1257. device_name: device.name || '',
  1258. borrow_count: 1,
  1259. brand: device.brand || device.device_brand || '',
  1260. device_specification: device.specification,
  1261. model: device.model || '',
  1262. warehouse: device.warehouse,
  1263. available_quantity: avail
  1264. });
  1265. console.log(`设备 ${trimmedCode} 已添加到列表`);
  1266. }
  1267. } else {
  1268. console.warn(`未找到设备编号: ${trimmedCode}`);
  1269. }
  1270. } catch (error) {
  1271. // 即使某个设备编号处理失败,也继续处理下一个,不受影响
  1272. console.error(`处理设备编号 ${trimmedCode} 失败:`, error);
  1273. }
  1274. // 每个设备编号处理完后稍作延迟,避免请求过快
  1275. if (i < codesToSubmit.length - 1) {
  1276. await new Promise(resolve => setTimeout(resolve, 50));
  1277. }
  1278. }
  1279. console.log(`[autoSubmitPendingCodes] 自动提交完成,共处理 ${codesToSubmit.length} 个设备编号`);
  1280. } catch (error) {
  1281. console.error(`[autoSubmitPendingCodes] 自动提交过程中发生错误:`, error);
  1282. } finally {
  1283. isAutoSubmitting.value = false;
  1284. // 如果还有待提交的设备编号,继续处理
  1285. if (pendingDeviceCodes.value.length > 0) {
  1286. setTimeout(() => {
  1287. autoSubmitPendingCodes();
  1288. }, 100);
  1289. }
  1290. }
  1291. };
  1292. const processRfidTagArray = async () => {
  1293. if (rfidTagArray.value.length === 0 || isProcessingTagArray.value) return;
  1294. isProcessingTagArray.value = true;
  1295. // 使用 try-finally 确保状态总是被重置
  1296. try {
  1297. // 复制标签数组并清空,避免在处理过程中被修改
  1298. const tagsToProcess = [...rfidTagArray.value];
  1299. rfidTagArray.value = [];
  1300. console.log(`[processRfidTagArray] 开始处理,收到 ${tagsToProcess.length} 个标签:`, tagsToProcess);
  1301. // 去重处理:过滤掉正在处理或已处理的标签
  1302. // 注意:不要在这里就添加到 processingTags,而是在实际开始处理时才添加
  1303. const uniqueTagsToProcess = tagsToProcess.filter(tag => {
  1304. const trimmedTag = tag.trim();
  1305. if (!trimmedTag) return false;
  1306. // 只跳过正在处理的标签,不在这里添加
  1307. const shouldProcess = !processingTags.value.has(trimmedTag);
  1308. if (!shouldProcess) {
  1309. console.log(`[processRfidTagArray] 标签 ${trimmedTag} 正在处理中,跳过`);
  1310. }
  1311. return shouldProcess;
  1312. });
  1313. console.log(`[processRfidTagArray] 去重后需要处理 ${uniqueTagsToProcess.length} 个标签:`, uniqueTagsToProcess);
  1314. // 将所有标签分割后的设备编号先缓存到 pendingDeviceCodes 数组
  1315. const allCodes: string[] = [];
  1316. for (const tag of uniqueTagsToProcess) {
  1317. const trimmedTag = tag.trim();
  1318. if (!trimmedTag) continue;
  1319. // 分割标签,可能包含多个设备编号
  1320. const codes = splitDeviceCodes(trimmedTag);
  1321. const uniqueCodes = Array.from(new Set(codes.map(code => code.trim()))).filter(Boolean);
  1322. // 添加到缓存数组(去重)
  1323. uniqueCodes.forEach(code => {
  1324. if (!allCodes.includes(code) && !pendingDeviceCodes.value.includes(code)) {
  1325. allCodes.push(code);
  1326. }
  1327. });
  1328. }
  1329. // 将设备编号添加到待提交列表
  1330. if (allCodes.length > 0) {
  1331. pendingDeviceCodes.value.push(...allCodes);
  1332. console.log(`[processRfidTagArray] 已将 ${allCodes.length} 个设备编号添加到待提交列表:`, allCodes);
  1333. // 触发自动循环提交
  1334. if (!isAutoSubmitting.value) {
  1335. autoSubmitPendingCodes();
  1336. }
  1337. }
  1338. // 所有标签处理完成后,清理处理标志并重新聚焦输入框
  1339. console.log(`[processRfidTagArray] 所有标签已缓存到待提交列表,共 ${allCodes.length} 个设备编号`);
  1340. console.log(`[processRfidTagArray] 当前待提交列表中的设备编号数量:`, pendingDeviceCodes.value.length);
  1341. } catch (outerError) {
  1342. // 捕获整个处理过程中的任何未预期错误,确保状态被重置
  1343. console.error(`[processRfidTagArray] 处理过程中发生未预期错误:`, outerError);
  1344. ElMessage.error('处理标签时发生错误,但已尝试处理所有标签');
  1345. } finally {
  1346. // 确保无论发生什么,状态都被重置
  1347. isProcessingTagArray.value = false;
  1348. loading.value = false;
  1349. searchText.value = '';
  1350. // 清理处理中的标签标记(延迟清理,避免立即重复处理)
  1351. setTimeout(() => {
  1352. processingTags.value.clear();
  1353. }, 1000);
  1354. nextTick(() => {
  1355. if (searchInputRef.value) {
  1356. searchInputRef.value.focus();
  1357. searchInputRef.value.select();
  1358. }
  1359. });
  1360. }
  1361. };
  1362. // 提交RFID缓冲区内容
  1363. const submitRFIDBuffer = () => {
  1364. if (!readRuleConfig.value.enableRFIDBuffer) {
  1365. // 如果未启用RFID缓冲,直接使用 searchText 进行搜索
  1366. if (searchText.value.trim()) {
  1367. handleScanSearch();
  1368. }
  1369. return;
  1370. }
  1371. // 如果有标签数组,优先处理标签数组
  1372. if (rfidTagArray.value.length > 0) {
  1373. clearRFIDInputTimer();
  1374. consecutiveInputCount = 0;
  1375. lastInputTime = 0;
  1376. processRfidTagArray();
  1377. return;
  1378. }
  1379. if (!rfidInputBuffer.value && !currentRfidTag.value) {
  1380. // 如果没有缓冲内容,使用 searchText 进行搜索
  1381. if (searchText.value.trim()) {
  1382. handleScanSearch();
  1383. }
  1384. return;
  1385. }
  1386. // 如果有当前标签,先添加到标签数组(去重)
  1387. if (currentRfidTag.value.trim()) {
  1388. const tag = currentRfidTag.value.trim();
  1389. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1390. rfidTagArray.value.push(tag);
  1391. }
  1392. currentRfidTag.value = '';
  1393. }
  1394. // 如果有缓冲内容,也添加到标签数组(去重)
  1395. if (rfidInputBuffer.value.trim()) {
  1396. const tag = rfidInputBuffer.value.trim();
  1397. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1398. rfidTagArray.value.push(tag);
  1399. }
  1400. rfidInputBuffer.value = '';
  1401. }
  1402. clearRFIDInputTimer();
  1403. consecutiveInputCount = 0;
  1404. lastInputTime = 0;
  1405. // 处理标签数组
  1406. if (rfidTagArray.value.length > 0) {
  1407. processRfidTagArray();
  1408. }
  1409. };
  1410. // 调度RFID缓冲区提交(延迟提交)
  1411. const scheduleRFIDBufferSubmit = () => {
  1412. if (!readRuleConfig.value.enableRFIDBuffer) return;
  1413. clearRFIDInputTimer();
  1414. const delay = Math.max(readRuleConfig.value.rfidInputTimeout || 120, 30);
  1415. rfidInputTimer = setTimeout(() => {
  1416. console.log(`[scheduleRFIDBufferSubmit] 延迟提交触发,当前状态:`, {
  1417. currentRfidTag: currentRfidTag.value,
  1418. rfidInputBuffer: rfidInputBuffer.value,
  1419. searchText: searchText.value,
  1420. rfidTagArray: rfidTagArray.value
  1421. });
  1422. // 如果 searchText 中有内容,优先检查是否包含多个标签(通过换行、回车等分隔)
  1423. if (searchText.value.trim()) {
  1424. const codes = splitDeviceCodes(searchText.value);
  1425. console.log(`[scheduleRFIDBufferSubmit] searchText 分割得到 ${codes.length} 个代码:`, codes, '原始内容长度:', searchText.value.length);
  1426. // 无论有多少个标签,都添加到标签数组
  1427. if (codes.length > 0) {
  1428. codes.forEach(code => {
  1429. const trimmedCode = code.trim();
  1430. if (trimmedCode && !rfidTagArray.value.includes(trimmedCode) && !processingTags.value.has(trimmedCode)) {
  1431. rfidTagArray.value.push(trimmedCode);
  1432. console.log(`[scheduleRFIDBufferSubmit] 添加标签到数组: ${trimmedCode}`);
  1433. }
  1434. });
  1435. searchText.value = '';
  1436. }
  1437. }
  1438. // 如果当前标签有内容,先保存到标签数组(去重)
  1439. if (currentRfidTag.value.trim()) {
  1440. const tag = currentRfidTag.value.trim();
  1441. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1442. rfidTagArray.value.push(tag);
  1443. console.log(`[scheduleRFIDBufferSubmit] 添加当前标签到数组: ${tag}`);
  1444. }
  1445. currentRfidTag.value = '';
  1446. }
  1447. // 如果有缓冲内容,也添加到标签数组(去重)
  1448. if (rfidInputBuffer.value.trim()) {
  1449. const tag = rfidInputBuffer.value.trim();
  1450. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1451. rfidTagArray.value.push(tag);
  1452. console.log(`[scheduleRFIDBufferSubmit] 添加缓冲标签到数组: ${tag}`);
  1453. }
  1454. rfidInputBuffer.value = '';
  1455. }
  1456. console.log(`[scheduleRFIDBufferSubmit] 延迟提交时,标签数组共有 ${rfidTagArray.value.length} 个标签:`, rfidTagArray.value);
  1457. // 处理标签数组,使用统一的延迟处理机制
  1458. if (rfidTagArray.value.length > 0) {
  1459. // 清除之前的延迟处理定时器(如果存在)
  1460. clearProcessTagArrayTimer();
  1461. // 设置统一的延迟处理,确保所有标签都被收集后再处理
  1462. processTagArrayTimer = setTimeout(() => {
  1463. processTagArrayTimer = null;
  1464. if (rfidTagArray.value.length > 0 && !isProcessingTagArray.value) {
  1465. console.log(`[scheduleRFIDBufferSubmit] 延迟处理,最终标签数组:`, rfidTagArray.value);
  1466. processRfidTagArray();
  1467. }
  1468. }, 300); // 增加延迟时间到300ms,确保所有标签都被收集
  1469. }
  1470. }, delay);
  1471. };
  1472. // 处理设备输入(用于同步 textarea 内容,仅在缓冲模式下使用)
  1473. const handleDeviceInput = () => {
  1474. // 如果启用了RFID缓冲,检查 searchText 中是否包含多个标签(通过换行、回车等分隔)
  1475. if (readRuleConfig.value.enableRFIDBuffer && searchText.value.trim()) {
  1476. // 检查是否包含换行符或回车符
  1477. if (/[\r\n]/.test(searchText.value)) {
  1478. // 如果包含换行符,说明可能有多个标签
  1479. const codes = splitDeviceCodes(searchText.value);
  1480. console.log(`[handleDeviceInput] 检测到换行符,分割得到 ${codes.length} 个代码:`, codes, '原始内容长度:', searchText.value.length, '原始内容:', searchText.value.substring(0, 200));
  1481. // 无论有多少个标签,都添加到标签数组(包括单个标签的情况)
  1482. if (codes.length > 0) {
  1483. codes.forEach(code => {
  1484. const trimmedCode = code.trim();
  1485. if (trimmedCode && !rfidTagArray.value.includes(trimmedCode) && !processingTags.value.has(trimmedCode)) {
  1486. rfidTagArray.value.push(trimmedCode);
  1487. console.log(`[handleDeviceInput] 添加标签到数组: ${trimmedCode}`);
  1488. }
  1489. });
  1490. console.log(`[handleDeviceInput] 标签数组共有 ${rfidTagArray.value.length} 个标签:`, rfidTagArray.value);
  1491. // 清空 searchText,避免重复处理
  1492. searchText.value = '';
  1493. // 清空当前标签和缓冲区,因为已经添加到数组了
  1494. currentRfidTag.value = '';
  1495. rfidInputBuffer.value = '';
  1496. // 如果有标签数组且当前没有在处理,使用统一的延迟处理机制
  1497. if (rfidTagArray.value.length > 0 && !isProcessingTagArray.value) {
  1498. clearRFIDInputTimer();
  1499. // 清除之前的延迟处理定时器(如果存在)
  1500. clearProcessTagArrayTimer();
  1501. // 设置统一的延迟处理,确保所有标签都被收集后再处理
  1502. processTagArrayTimer = setTimeout(() => {
  1503. processTagArrayTimer = null;
  1504. if (rfidTagArray.value.length > 0 && !isProcessingTagArray.value) {
  1505. console.log(`[handleDeviceInput] 延迟处理,最终标签数组:`, rfidTagArray.value);
  1506. processRfidTagArray();
  1507. }
  1508. }, 300); // 增加延迟时间到300ms,确保所有标签都被收集
  1509. }
  1510. return;
  1511. }
  1512. }
  1513. }
  1514. // 如果缓冲区有内容,确保 textarea 显示与缓冲区一致
  1515. // 这主要用于处理退格键等操作后的同步
  1516. if (currentRfidTag.value || rfidInputBuffer.value) {
  1517. const displayValue = currentRfidTag.value || rfidInputBuffer.value;
  1518. if (searchText.value !== displayValue) {
  1519. searchText.value = displayValue;
  1520. }
  1521. }
  1522. // 注意:正常输入时,不干预 textarea 的内容,让默认行为处理
  1523. };
  1524. // 检测是否是高速扫码输入(通过输入速度判断)
  1525. // 返回值:{ isHighSpeed: boolean, isFirstInput: boolean, isNormalInput: boolean, timeSinceLastInput: number }
  1526. const checkInputSpeed = () => {
  1527. const now = Date.now();
  1528. const timeSinceLastInput = lastInputTime > 0 ? now - lastInputTime : 0;
  1529. const isFirstInput = lastInputTime === 0;
  1530. if (!isFirstInput) {
  1531. lastInputTime = now;
  1532. }
  1533. return {
  1534. isFirstInput,
  1535. timeSinceLastInput,
  1536. isHighSpeed: timeSinceLastInput > 0 && timeSinceLastInput < readRuleConfig.value.minInputSpeed,
  1537. isNormalInput: timeSinceLastInput > 200
  1538. };
  1539. };
  1540. // 处理RFID键盘输入(高速扫码)
  1541. const handleRFIDKeydown = (event: KeyboardEvent) => {
  1542. // 如果未启用RFID缓冲,直接返回,不拦截
  1543. if (!readRuleConfig.value.enableRFIDBuffer) {
  1544. return;
  1545. }
  1546. // 不拦截修饰键组合(如 Ctrl+C, Ctrl+V 等)
  1547. if (event.ctrlKey || event.metaKey || event.altKey) {
  1548. return;
  1549. }
  1550. // 处理回车键
  1551. if (event.key === 'Enter') {
  1552. // 回车键由 @keydown.enter.prevent="handleDeviceEnter" 处理
  1553. // 这里不处理,让 handleDeviceEnter 统一处理
  1554. return;
  1555. }
  1556. // 处理退格键
  1557. if (event.key === 'Backspace') {
  1558. // 如果有当前标签或缓冲内容,处理缓冲
  1559. if (currentRfidTag.value || rfidInputBuffer.value) {
  1560. event.preventDefault();
  1561. if (currentRfidTag.value) {
  1562. currentRfidTag.value = currentRfidTag.value.slice(0, -1);
  1563. rfidInputBuffer.value = currentRfidTag.value;
  1564. } else {
  1565. rfidInputBuffer.value = rfidInputBuffer.value.slice(0, -1);
  1566. }
  1567. searchText.value = rfidInputBuffer.value || currentRfidTag.value;
  1568. }
  1569. // 否则让默认行为处理
  1570. return;
  1571. }
  1572. // 处理普通字符输入
  1573. if (event.key.length === 1) {
  1574. const inputInfo = checkInputSpeed();
  1575. const { isFirstInput, isHighSpeed, isNormalInput, timeSinceLastInput } = inputInfo;
  1576. // 如果是第一次输入,不拦截,让默认行为处理,只记录时间戳
  1577. if (isFirstInput) {
  1578. lastInputTime = Date.now();
  1579. // 不拦截,让字符正常输入到 textarea
  1580. return;
  1581. }
  1582. // 如果检测到是正常输入(间隔 > 200ms),处理之前的缓冲内容
  1583. if (isNormalInput) {
  1584. // 如果之前有当前标签或缓冲内容,先保存到标签数组(去重)
  1585. if (currentRfidTag.value.trim()) {
  1586. const tag = currentRfidTag.value.trim();
  1587. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1588. rfidTagArray.value.push(tag);
  1589. }
  1590. currentRfidTag.value = '';
  1591. }
  1592. if (rfidInputBuffer.value.trim()) {
  1593. const tag = rfidInputBuffer.value.trim();
  1594. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1595. rfidTagArray.value.push(tag);
  1596. }
  1597. rfidInputBuffer.value = '';
  1598. }
  1599. // 如果有标签数组,处理它们
  1600. if (rfidTagArray.value.length > 0) {
  1601. processRfidTagArray();
  1602. }
  1603. // 重置状态
  1604. consecutiveInputCount = 0;
  1605. lastInputTime = Date.now();
  1606. // 不拦截,让字符正常输入到 textarea
  1607. return;
  1608. }
  1609. // 如果检测到是高速输入(间隔 < 30ms),使用缓冲模式
  1610. if (isHighSpeed) {
  1611. event.preventDefault();
  1612. event.stopPropagation(); // 阻止事件冒泡,避免影响其他元素
  1613. // 如果输入间隔超过标签分隔时间,说明是一个新标签的开始
  1614. // 需要保存之前的标签到数组
  1615. if (timeSinceLastInput > readRuleConfig.value.tagSeparatorTimeout) {
  1616. // 保存当前标签到数组(如果存在且去重)
  1617. if (currentRfidTag.value.trim()) {
  1618. const tag = currentRfidTag.value.trim();
  1619. if (!rfidTagArray.value.includes(tag)) {
  1620. rfidTagArray.value.push(tag);
  1621. }
  1622. currentRfidTag.value = '';
  1623. }
  1624. // 保存缓冲内容到数组(如果存在且去重)
  1625. if (rfidInputBuffer.value.trim()) {
  1626. const tag = rfidInputBuffer.value.trim();
  1627. if (!rfidTagArray.value.includes(tag)) {
  1628. rfidTagArray.value.push(tag);
  1629. }
  1630. rfidInputBuffer.value = '';
  1631. }
  1632. // 如果 textarea 中有内容,检查是否需要添加到数组(去重)
  1633. if (searchText.value.trim()) {
  1634. const codes = splitDeviceCodes(searchText.value);
  1635. codes.forEach(code => {
  1636. const trimmedCode = code.trim();
  1637. if (trimmedCode && !rfidTagArray.value.includes(trimmedCode) && !processingTags.value.has(trimmedCode)) {
  1638. rfidTagArray.value.push(trimmedCode);
  1639. }
  1640. });
  1641. searchText.value = ''; // 清空 searchText,避免重复处理
  1642. }
  1643. // 重置,开始新标签
  1644. currentRfidTag.value = event.key;
  1645. rfidInputBuffer.value = event.key;
  1646. searchText.value = event.key;
  1647. } else {
  1648. // 如果是第一次检测到高速输入(之前没有缓冲内容),需要将 textarea 中已有的内容也加入当前标签
  1649. if (currentRfidTag.value === '' && rfidInputBuffer.value === '' && searchText.value) {
  1650. // textarea 中已经有内容(第一个字符已经通过默认行为输入了)
  1651. // 将整个内容作为当前标签的初始值,然后追加当前字符
  1652. currentRfidTag.value = searchText.value + event.key;
  1653. } else {
  1654. // 否则直接追加当前字符到当前标签
  1655. currentRfidTag.value += event.key;
  1656. }
  1657. // 同时更新缓冲区和显示
  1658. rfidInputBuffer.value = currentRfidTag.value;
  1659. searchText.value = currentRfidTag.value;
  1660. }
  1661. consecutiveInputCount++;
  1662. scheduleRFIDBufferSubmit();
  1663. return;
  1664. }
  1665. // 如果输入间隔在 30-200ms 之间,可能是正常输入,不拦截
  1666. // 但如果之前有缓冲内容,说明高速输入已结束,先保存当前标签(去重)
  1667. if (currentRfidTag.value.trim() || rfidInputBuffer.value.trim()) {
  1668. if (currentRfidTag.value.trim()) {
  1669. const tag = currentRfidTag.value.trim();
  1670. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1671. rfidTagArray.value.push(tag);
  1672. }
  1673. currentRfidTag.value = '';
  1674. }
  1675. if (rfidInputBuffer.value.trim()) {
  1676. const tag = rfidInputBuffer.value.trim();
  1677. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1678. rfidTagArray.value.push(tag);
  1679. }
  1680. rfidInputBuffer.value = '';
  1681. }
  1682. // 处理标签数组
  1683. if (rfidTagArray.value.length > 0) {
  1684. processRfidTagArray();
  1685. }
  1686. consecutiveInputCount = 0;
  1687. }
  1688. lastInputTime = Date.now();
  1689. // 不拦截,让字符正常输入到 textarea
  1690. }
  1691. };
  1692. // 处理输入框失焦
  1693. const handleDeviceBlur = (event: FocusEvent) => {
  1694. // 如果焦点转移到其他输入元素(如表单输入框),不自动聚焦
  1695. const relatedTarget = event.relatedTarget as HTMLElement;
  1696. if (relatedTarget && (
  1697. relatedTarget.tagName === 'INPUT' ||
  1698. relatedTarget.tagName === 'TEXTAREA' ||
  1699. relatedTarget.closest('.el-input') ||
  1700. relatedTarget.closest('.el-textarea') ||
  1701. relatedTarget.closest('form')
  1702. )) {
  1703. // 如果有缓冲内容,先提交
  1704. if (rfidInputBuffer.value) {
  1705. submitRFIDBuffer();
  1706. }
  1707. return;
  1708. }
  1709. // 其他情况(如点击按钮等),延迟后自动聚焦
  1710. setTimeout(() => {
  1711. if (searchInputRef.value && !loading.value) {
  1712. searchInputRef.value.focus();
  1713. }
  1714. }, 10);
  1715. };
  1716. // 处理回车键
  1717. const handleDeviceEnter = (event: KeyboardEvent) => {
  1718. if (event.shiftKey) return;
  1719. event.preventDefault();
  1720. // 如果启用了RFID缓冲,先检查是否有当前标签或缓冲内容
  1721. if (readRuleConfig.value.enableRFIDBuffer) {
  1722. // 如果有当前标签,先保存到标签数组(去重)
  1723. if (currentRfidTag.value.trim()) {
  1724. const tag = currentRfidTag.value.trim();
  1725. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1726. rfidTagArray.value.push(tag);
  1727. }
  1728. currentRfidTag.value = '';
  1729. }
  1730. // 如果有缓冲内容,也添加到标签数组(去重)
  1731. if (rfidInputBuffer.value.trim()) {
  1732. const tag = rfidInputBuffer.value.trim();
  1733. if (!rfidTagArray.value.includes(tag) && !processingTags.value.has(tag)) {
  1734. rfidTagArray.value.push(tag);
  1735. }
  1736. rfidInputBuffer.value = '';
  1737. }
  1738. }
  1739. // 检查 searchText 中是否包含多个标签(通过换行、回车等分隔)
  1740. if (searchText.value.trim()) {
  1741. const codes = splitDeviceCodes(searchText.value);
  1742. console.log(`[handleDeviceEnter] 回车键提交时,searchText 分割得到 ${codes.length} 个代码:`, codes, '原始内容长度:', searchText.value.length, '原始内容:', searchText.value.substring(0, 500));
  1743. // 将所有标签添加到数组(包括单个标签的情况)
  1744. codes.forEach(code => {
  1745. const trimmedCode = code.trim();
  1746. if (trimmedCode && !rfidTagArray.value.includes(trimmedCode) && !processingTags.value.has(trimmedCode)) {
  1747. rfidTagArray.value.push(trimmedCode);
  1748. console.log(`[handleDeviceEnter] 添加标签到数组: ${trimmedCode}`);
  1749. }
  1750. });
  1751. searchText.value = '';
  1752. }
  1753. console.log(`[handleDeviceEnter] 回车键提交时,标签数组共有 ${rfidTagArray.value.length} 个标签:`, rfidTagArray.value);
  1754. // 如果有标签数组,使用统一的延迟处理机制,避免多次触发
  1755. if (rfidTagArray.value.length > 0) {
  1756. clearRFIDInputTimer();
  1757. consecutiveInputCount = 0;
  1758. lastInputTime = 0;
  1759. // 清除之前的延迟处理定时器(如果存在)
  1760. if (processTagArrayTimer) {
  1761. clearTimeout(processTagArrayTimer);
  1762. processTagArrayTimer = null;
  1763. }
  1764. // 设置统一的延迟处理,确保所有标签都被收集后再处理
  1765. processTagArrayTimer = setTimeout(() => {
  1766. processTagArrayTimer = null;
  1767. if (rfidTagArray.value.length > 0 && !isProcessingTagArray.value) {
  1768. console.log(`[handleDeviceEnter] 延迟处理,最终标签数组:`, rfidTagArray.value);
  1769. processRfidTagArray();
  1770. }
  1771. }, 300); // 增加延迟时间到300ms,确保所有标签都被收集
  1772. return;
  1773. }
  1774. // 如果没有标签数组,使用 searchText 进行搜索
  1775. if (searchText.value.trim()) {
  1776. handleScanSearch();
  1777. }
  1778. };
  1779. // 分割多个设备编号(支持分隔符)
  1780. const splitDeviceCodes = (input: string): string[] => {
  1781. const trimmed = input.trim();
  1782. if (!trimmed) return [];
  1783. const { separator } = readRuleConfig.value;
  1784. // 优先处理换行符
  1785. if (/[\r\n]/.test(trimmed)) {
  1786. return trimmed.split(/[\r\n]+/).filter(code => code.trim());
  1787. }
  1788. // 处理配置的分隔符
  1789. if (separator && separator.trim() !== '') {
  1790. const escapedSeparator = separator.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  1791. const separatorPattern = new RegExp(escapedSeparator + '+', 'g');
  1792. return trimmed.split(separatorPattern).filter(code => code.trim());
  1793. }
  1794. // 处理空格分隔
  1795. if (/\s/.test(trimmed)) {
  1796. return trimmed.split(/\s+/).filter(code => code.trim());
  1797. }
  1798. // 单个设备编号
  1799. return [trimmed];
  1800. };
  1801. // 处理扫码搜索(支持批量,优化并发请求)
  1802. const handleScanSearch = async (event?: Event) => {
  1803. // 阻止默认行为,防止表单提交导致页面刷新
  1804. if (event) {
  1805. event.preventDefault();
  1806. event.stopPropagation();
  1807. }
  1808. // 如果启用了RFID缓冲,先提交缓冲区
  1809. if (readRuleConfig.value.enableRFIDBuffer) {
  1810. // 如果有当前标签,先保存到标签数组
  1811. if (currentRfidTag.value.trim()) {
  1812. if (!rfidTagArray.value.includes(currentRfidTag.value.trim())) {
  1813. rfidTagArray.value.push(currentRfidTag.value.trim());
  1814. }
  1815. currentRfidTag.value = '';
  1816. }
  1817. // 如果有缓冲内容,也添加到标签数组
  1818. if (rfidInputBuffer.value.trim()) {
  1819. if (!rfidTagArray.value.includes(rfidInputBuffer.value.trim())) {
  1820. rfidTagArray.value.push(rfidInputBuffer.value.trim());
  1821. }
  1822. rfidInputBuffer.value = '';
  1823. }
  1824. clearRFIDInputTimer();
  1825. // 如果 searchText 中包含多个标签,先分割并添加到数组(去重)
  1826. if (searchText.value.trim()) {
  1827. const codes = splitDeviceCodes(searchText.value);
  1828. codes.forEach(code => {
  1829. const trimmedCode = code.trim();
  1830. if (trimmedCode && !rfidTagArray.value.includes(trimmedCode) && !processingTags.value.has(trimmedCode)) {
  1831. rfidTagArray.value.push(trimmedCode);
  1832. }
  1833. });
  1834. searchText.value = '';
  1835. }
  1836. // 如果有标签数组,优先处理标签数组
  1837. if (rfidTagArray.value.length > 0) {
  1838. processRfidTagArray();
  1839. return;
  1840. }
  1841. }
  1842. if (!searchText.value.trim()) return;
  1843. // 分割多个设备编号
  1844. const codes = splitDeviceCodes(searchText.value);
  1845. if (codes.length === 0) return;
  1846. // 去重处理,避免重复请求同一个设备编号
  1847. const uniqueCodes = Array.from(new Set(codes.map(code => code.trim()))).filter(Boolean);
  1848. if (uniqueCodes.length === 0) return;
  1849. loading.value = true;
  1850. let successCount = 0;
  1851. let failCount = 0;
  1852. const errorMessages: string[] = [];
  1853. try {
  1854. // 批量并发处理设备编号(使用 Promise.allSettled 确保所有请求都完成)
  1855. // 限制并发数量,避免同时发起过多请求
  1856. const batchSize = 10; // 每批处理10个
  1857. const batches: string[][] = [];
  1858. for (let i = 0; i < uniqueCodes.length; i += batchSize) {
  1859. batches.push(uniqueCodes.slice(i, i + batchSize));
  1860. }
  1861. // 用于收集所有成功获取的设备数据,避免并发添加时的竞态条件
  1862. const deviceMap = new Map<number | string, any>();
  1863. const processedCodes = new Set<string>();
  1864. // 逐批处理,每批内部并发
  1865. for (const batch of batches) {
  1866. const promises = batch.map(async (code) => {
  1867. try {
  1868. const res = await deviceApi.GetList({
  1869. page: 1,
  1870. limit: 1,
  1871. code: code,
  1872. status: 1
  1873. });
  1874. if (res.data && res.data.length > 0) {
  1875. const device = res.data[0];
  1876. const avail = getDeviceAvailableQuantityForBorrow(device);
  1877. if (avail <= 0) {
  1878. return { success: false, code, message: `设备 ${code} 可借用数量为0,无法加入领取列表` };
  1879. }
  1880. // 收集设备数据,统一处理添加逻辑
  1881. deviceMap.set(device.id, {
  1882. device_no: device.id,
  1883. device_code: device.code,
  1884. device_type: device.category_name,
  1885. device_name: device.name || '',
  1886. borrow_count: 1,
  1887. brand: device.brand || device.device_brand || '',
  1888. device_specification: device.specification,
  1889. model: device.model || '',
  1890. warehouse: device.warehouse,
  1891. available_quantity: avail
  1892. });
  1893. processedCodes.add(code);
  1894. return { success: true, code, deviceId: device.id };
  1895. } else {
  1896. return { success: false, code, message: `未找到设备编号: ${code}` };
  1897. }
  1898. } catch (error) {
  1899. console.error(`处理设备编号 ${code} 失败:`, error);
  1900. return { success: false, code, message: `处理设备编号 ${code} 失败` };
  1901. }
  1902. });
  1903. // 等待当前批次完成
  1904. const results = await Promise.allSettled(promises);
  1905. // 统计结果(先不处理添加,只统计)
  1906. results.forEach((result, index) => {
  1907. const { success, message } = readSettledListStepResult(result, batch[index] ?? String(index));
  1908. if (success) {
  1909. /* 暂时不增加计数,等统一处理后再统计 */
  1910. } else {
  1911. failCount++;
  1912. if (message) {
  1913. errorMessages.push(message);
  1914. }
  1915. }
  1916. });
  1917. }
  1918. // 统一处理设备添加,避免并发竞态条件
  1919. deviceMap.forEach((deviceData, deviceId) => {
  1920. // 再次检查是否已存在(防止在并发过程中被其他请求添加)
  1921. const existingDevice = deviceList.value.find(d => d.device_no === deviceId);
  1922. if (existingDevice) {
  1923. // 如果已存在,增加借用数量
  1924. existingDevice.borrow_count++;
  1925. successCount++;
  1926. } else {
  1927. // 如果不存在,添加新设备
  1928. deviceList.value.push(deviceData);
  1929. successCount++;
  1930. }
  1931. });
  1932. // 显示批量处理结果
  1933. if (uniqueCodes.length > 1) {
  1934. if (successCount > 0 && failCount === 0) {
  1935. ElMessage.success(`成功添加 ${successCount} 个设备`);
  1936. } else if (successCount > 0 && failCount > 0) {
  1937. ElMessage.warning(`成功添加 ${successCount} 个设备,失败 ${failCount} 个`);
  1938. // 只显示前3个错误信息,避免消息过多
  1939. if (errorMessages.length > 0) {
  1940. console.warn('批量处理错误详情:', errorMessages.slice(0, 3));
  1941. }
  1942. } else if (failCount > 0) {
  1943. ElMessage.error(`添加失败,共 ${failCount} 个设备编号`);
  1944. }
  1945. } else if (successCount > 0) {
  1946. ElMessage.success('设备已添加到列表');
  1947. } else if (failCount > 0 && errorMessages.length > 0) {
  1948. ElMessage.warning(errorMessages[0]);
  1949. }
  1950. } catch (error) {
  1951. console.error('批量处理设备失败:', error);
  1952. ElMessage.error('搜索设备失败');
  1953. } finally {
  1954. searchText.value = ''; // 清空搜索框
  1955. loading.value = false;
  1956. // 重新聚焦输入框,保持选中状态
  1957. nextTick(() => {
  1958. if (searchInputRef.value) {
  1959. searchInputRef.value.focus();
  1960. searchInputRef.value.select();
  1961. }
  1962. });
  1963. }
  1964. };
  1965. // 处理归还流程RFID标签数组,逐个检索并提交
  1966. const processReturnRfidTagArray = async () => {
  1967. if (returnRfidTagArray.value.length === 0 || isProcessingReturnTagArray.value) return;
  1968. isProcessingReturnTagArray.value = true;
  1969. // 使用 try-finally 确保状态总是被重置
  1970. try {
  1971. // 复制标签数组并清空,避免在处理过程中被修改
  1972. const tagsToProcess = [...returnRfidTagArray.value];
  1973. returnRfidTagArray.value = [];
  1974. console.log(`[processReturnRfidTagArray] 开始处理归还标签,收到 ${tagsToProcess.length} 个标签:`, tagsToProcess);
  1975. // 去重处理:过滤掉正在处理或已处理的标签
  1976. // 注意:不要在这里就添加到 returnProcessingTags,而是在实际开始处理时才添加
  1977. const uniqueTagsToProcess = tagsToProcess.filter(tag => {
  1978. const trimmedTag = tag.trim();
  1979. if (!trimmedTag) return false;
  1980. // 只跳过正在处理的标签,不在这里添加
  1981. const shouldProcess = !returnProcessingTags.value.has(trimmedTag);
  1982. if (!shouldProcess) {
  1983. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 正在处理中,跳过`);
  1984. }
  1985. return shouldProcess;
  1986. });
  1987. console.log(`[processReturnRfidTagArray] 去重后需要处理 ${uniqueTagsToProcess.length} 个标签:`, uniqueTagsToProcess);
  1988. // 逐个处理标签
  1989. for (let i = 0; i < uniqueTagsToProcess.length; i++) {
  1990. const tag = uniqueTagsToProcess[i];
  1991. if (!tag || !tag.trim()) {
  1992. console.log(`[processReturnRfidTagArray] 跳过空标签: ${tag}`);
  1993. continue;
  1994. }
  1995. const trimmedTag = tag.trim();
  1996. // 在处理前检查并添加到 returnProcessingTags,防止重复处理
  1997. if (returnProcessingTags.value.has(trimmedTag)) {
  1998. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 正在处理中,跳过`);
  1999. continue;
  2000. }
  2001. returnProcessingTags.value.add(trimmedTag);
  2002. console.log(`[processReturnRfidTagArray] 开始处理归还标签 ${i + 1}/${uniqueTagsToProcess.length}: ${trimmedTag}`);
  2003. // 确保每个标签处理前状态都是干净的
  2004. returnSearchText.value = '';
  2005. loading.value = false;
  2006. try {
  2007. // 设置搜索文本
  2008. returnSearchText.value = trimmedTag;
  2009. // 分割多个设备编号
  2010. const codes = splitDeviceCodes(returnSearchText.value);
  2011. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 分割后得到 ${codes.length} 个代码:`, codes);
  2012. if (codes.length === 0) {
  2013. // 如果分割后没有有效代码,从 returnProcessingTags 中移除并继续处理下一个标签
  2014. returnProcessingTags.value.delete(trimmedTag);
  2015. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 分割后没有有效代码,跳过`);
  2016. continue;
  2017. }
  2018. const uniqueCodes = Array.from(new Set(codes.map(code => code.trim()))).filter(Boolean);
  2019. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 去重后得到 ${uniqueCodes.length} 个唯一代码:`, uniqueCodes);
  2020. if (uniqueCodes.length === 0) {
  2021. // 如果没有有效代码,从 returnProcessingTags 中移除并继续处理下一个标签
  2022. returnProcessingTags.value.delete(trimmedTag);
  2023. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 没有有效代码,跳过`);
  2024. continue;
  2025. }
  2026. loading.value = true;
  2027. let successCount = 0;
  2028. let failCount = 0;
  2029. const errorMessages: string[] = [];
  2030. // 批量并发处理设备编号(使用 Promise.allSettled 确保所有请求都完成)
  2031. const batchSize = 10;
  2032. const batches: string[][] = [];
  2033. for (let j = 0; j < uniqueCodes.length; j += batchSize) {
  2034. batches.push(uniqueCodes.slice(j, j + batchSize));
  2035. }
  2036. // 逐批处理,每批内部并发
  2037. for (const batch of batches) {
  2038. try {
  2039. const promises = batch.map(async (code) => {
  2040. try {
  2041. const res = await deviceApi.GetList({
  2042. page: 1,
  2043. limit: 1,
  2044. code: code,
  2045. status: 1
  2046. });
  2047. if (res.data && res.data.length > 0) {
  2048. const device = res.data[0];
  2049. // 检查是否已存在
  2050. const existingDeviceIndex = returnDeviceList.value.findIndex(d => d.device_no === device.id);
  2051. if (existingDeviceIndex !== -1) {
  2052. const row = returnDeviceList.value[existingDeviceIndex];
  2053. const errMsg = tryApplyReturnScanIncrement(row);
  2054. if (errMsg) {
  2055. return { success: false, code, message: errMsg };
  2056. }
  2057. return { success: true, code };
  2058. } else {
  2059. // 设备不存在于归还列表中
  2060. return {
  2061. success: false,
  2062. code,
  2063. message: `设备 ${device.code || device.category_name} 不在当前归还列表中,请先通过手动归还添加该设备`
  2064. };
  2065. }
  2066. } else {
  2067. return { success: false, code, message: `未找到设备编号: ${code}` };
  2068. }
  2069. } catch (error) {
  2070. console.error(`处理设备编号 ${code} 失败:`, error);
  2071. return { success: false, code, message: `处理设备编号 ${code} 失败` };
  2072. }
  2073. });
  2074. // 等待当前批次完成
  2075. const results = await Promise.allSettled(promises);
  2076. // 统计结果
  2077. results.forEach((result, index) => {
  2078. const { success, message } = readSettledListStepResult(result, batch[index] ?? String(index));
  2079. if (success) {
  2080. successCount++;
  2081. } else {
  2082. failCount++;
  2083. if (message) {
  2084. errorMessages.push(message);
  2085. }
  2086. }
  2087. });
  2088. } catch (batchError) {
  2089. // 即使某批处理失败,也继续处理下一批
  2090. console.error(`处理批次失败:`, batchError);
  2091. failCount += batch.length;
  2092. errorMessages.push(
  2093. `处理批次时发生错误${
  2094. batchError instanceof Error ? `:${batchError.message}` : ''
  2095. }`
  2096. );
  2097. }
  2098. }
  2099. // 显示处理结果
  2100. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 处理完成: 成功 ${successCount} 个,失败 ${failCount} 个`);
  2101. if (uniqueCodes.length > 1) {
  2102. if (successCount > 0 && failCount === 0) {
  2103. ElMessage.success(`标签 ${trimmedTag}: 成功增加 ${successCount} 个设备的归还数量`);
  2104. } else if (successCount > 0 && failCount > 0) {
  2105. ElMessage.warning(`标签 ${trimmedTag}: 成功增加 ${successCount} 个设备的归还数量,失败 ${failCount} 个`);
  2106. if (errorMessages.length > 0) {
  2107. console.warn('[processReturnRfidTagArray] 批量处理错误详情:', errorMessages.slice(0, 3));
  2108. }
  2109. } else if (failCount > 0) {
  2110. ElMessage.error(`标签 ${trimmedTag}: 处理失败,共 ${failCount} 个设备编号`);
  2111. }
  2112. } else if (successCount > 0) {
  2113. ElMessage.success(`标签 ${trimmedTag}: 已增加 1 个归还数量`);
  2114. } else if (failCount > 0 && errorMessages.length > 0) {
  2115. ElMessage.warning(`标签 ${trimmedTag}: ${errorMessages[0]}`);
  2116. }
  2117. // 处理成功后,从 returnProcessingTags 中移除,允许后续再次处理(如果需要)
  2118. // 但保留一段时间,防止立即重复处理
  2119. setTimeout(() => {
  2120. returnProcessingTags.value.delete(trimmedTag);
  2121. }, 5000);
  2122. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 处理完成,继续处理下一个标签`);
  2123. // 每个标签处理完后稍作延迟,避免请求过快
  2124. if (uniqueTagsToProcess.length > 1 && i < uniqueTagsToProcess.length - 1) {
  2125. await new Promise(resolve => setTimeout(resolve, 100));
  2126. }
  2127. } catch (error) {
  2128. // 即使某个标签处理失败,也要继续处理其他标签
  2129. console.error(`[processReturnRfidTagArray] 处理归还标签 ${trimmedTag} 失败:`, error);
  2130. const errorMsg = error instanceof Error ? error.message : String(error);
  2131. ElMessage.error(`处理标签 ${trimmedTag} 失败: ${errorMsg}`);
  2132. // 从 returnProcessingTags 中移除失败的标签,允许后续重试
  2133. returnProcessingTags.value.delete(trimmedTag);
  2134. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 处理失败,继续处理下一个标签`);
  2135. // 确保即使出错也继续处理下一个标签
  2136. } finally {
  2137. // 确保每个标签处理完后都重置状态,无论成功还是失败
  2138. try {
  2139. returnSearchText.value = '';
  2140. loading.value = false;
  2141. console.log(`[processReturnRfidTagArray] 归还标签 ${trimmedTag} 状态已重置,准备处理下一个标签`);
  2142. } catch (stateError) {
  2143. console.error(`[processReturnRfidTagArray] 重置状态失败:`, stateError);
  2144. }
  2145. }
  2146. }
  2147. // 所有标签处理完成后,清理处理标志并重新聚焦输入框
  2148. console.log(`[processReturnRfidTagArray] 所有归还标签处理完成,共处理 ${uniqueTagsToProcess.length} 个标签,标签列表:`, uniqueTagsToProcess);
  2149. console.log(`[processReturnRfidTagArray] 当前归还设备列表中的设备数量:`, returnDeviceList.value.length);
  2150. } catch (outerError) {
  2151. // 捕获整个处理过程中的任何未预期错误,确保状态被重置
  2152. console.error(`[processReturnRfidTagArray] 处理过程中发生未预期错误:`, outerError);
  2153. ElMessage.error('处理归还标签时发生错误,但已尝试处理所有标签');
  2154. } finally {
  2155. // 确保无论发生什么,状态都被重置
  2156. isProcessingReturnTagArray.value = false;
  2157. loading.value = false;
  2158. returnSearchText.value = '';
  2159. // 清理处理中的标签标记(延迟清理,避免立即重复处理)
  2160. setTimeout(() => {
  2161. returnProcessingTags.value.clear();
  2162. }, 1000);
  2163. }
  2164. nextTick(() => {
  2165. if (returnSearchInputRef.value) {
  2166. returnSearchInputRef.value.focus();
  2167. returnSearchInputRef.value.select();
  2168. }
  2169. });
  2170. };
  2171. // 提交归还流程RFID缓冲区内容
  2172. const submitReturnRFIDBuffer = () => {
  2173. if (!readRuleConfig.value.enableRFIDBuffer) {
  2174. // 如果未启用RFID缓冲,直接使用 returnSearchText 进行搜索
  2175. if (returnSearchText.value.trim()) {
  2176. handleReturnScanSearch();
  2177. }
  2178. return;
  2179. }
  2180. // 如果有标签数组,优先处理标签数组
  2181. if (returnRfidTagArray.value.length > 0) {
  2182. clearReturnRFIDInputTimer();
  2183. returnConsecutiveInputCount = 0;
  2184. returnLastInputTime = 0;
  2185. processReturnRfidTagArray();
  2186. return;
  2187. }
  2188. if (!returnRfidInputBuffer.value && !returnCurrentRfidTag.value) {
  2189. // 如果没有缓冲内容,使用 returnSearchText 进行搜索
  2190. if (returnSearchText.value.trim()) {
  2191. handleReturnScanSearch();
  2192. }
  2193. return;
  2194. }
  2195. // 如果有当前标签,先添加到标签数组(去重)
  2196. if (returnCurrentRfidTag.value.trim()) {
  2197. const tag = returnCurrentRfidTag.value.trim();
  2198. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2199. returnRfidTagArray.value.push(tag);
  2200. }
  2201. returnCurrentRfidTag.value = '';
  2202. }
  2203. // 如果有缓冲内容,也添加到标签数组(去重)
  2204. if (returnRfidInputBuffer.value.trim()) {
  2205. const tag = returnRfidInputBuffer.value.trim();
  2206. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2207. returnRfidTagArray.value.push(tag);
  2208. }
  2209. returnRfidInputBuffer.value = '';
  2210. }
  2211. clearReturnRFIDInputTimer();
  2212. returnConsecutiveInputCount = 0;
  2213. returnLastInputTime = 0;
  2214. // 处理标签数组
  2215. if (returnRfidTagArray.value.length > 0) {
  2216. processReturnRfidTagArray();
  2217. }
  2218. };
  2219. // 调度归还流程RFID缓冲区提交(延迟提交)
  2220. const scheduleReturnRFIDBufferSubmit = () => {
  2221. if (!readRuleConfig.value.enableRFIDBuffer) return;
  2222. clearReturnRFIDInputTimer();
  2223. const delay = Math.max(readRuleConfig.value.rfidInputTimeout || 120, 30);
  2224. returnRfidInputTimer = setTimeout(() => {
  2225. console.log(`[scheduleReturnRFIDBufferSubmit] 延迟提交触发,当前状态:`, {
  2226. returnCurrentRfidTag: returnCurrentRfidTag.value,
  2227. returnRfidInputBuffer: returnRfidInputBuffer.value,
  2228. returnSearchText: returnSearchText.value,
  2229. returnRfidTagArray: returnRfidTagArray.value
  2230. });
  2231. // 如果 returnSearchText 中有内容,优先检查是否包含多个标签(通过换行、回车等分隔)
  2232. if (returnSearchText.value.trim()) {
  2233. const codes = splitDeviceCodes(returnSearchText.value);
  2234. console.log(`[scheduleReturnRFIDBufferSubmit] returnSearchText 分割得到 ${codes.length} 个代码:`, codes, '原始内容长度:', returnSearchText.value.length);
  2235. // 无论有多少个标签,都添加到标签数组
  2236. if (codes.length > 0) {
  2237. codes.forEach(code => {
  2238. const trimmedCode = code.trim();
  2239. if (trimmedCode && !returnRfidTagArray.value.includes(trimmedCode) && !returnProcessingTags.value.has(trimmedCode)) {
  2240. returnRfidTagArray.value.push(trimmedCode);
  2241. console.log(`[scheduleReturnRFIDBufferSubmit] 添加标签到数组: ${trimmedCode}`);
  2242. }
  2243. });
  2244. returnSearchText.value = '';
  2245. }
  2246. }
  2247. // 如果当前标签有内容,先保存到标签数组(去重)
  2248. if (returnCurrentRfidTag.value.trim()) {
  2249. const tag = returnCurrentRfidTag.value.trim();
  2250. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2251. returnRfidTagArray.value.push(tag);
  2252. console.log(`[scheduleReturnRFIDBufferSubmit] 添加当前标签到数组: ${tag}`);
  2253. }
  2254. returnCurrentRfidTag.value = '';
  2255. }
  2256. // 如果有缓冲内容,也添加到标签数组(去重)
  2257. if (returnRfidInputBuffer.value.trim()) {
  2258. const tag = returnRfidInputBuffer.value.trim();
  2259. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2260. returnRfidTagArray.value.push(tag);
  2261. console.log(`[scheduleReturnRFIDBufferSubmit] 添加缓冲标签到数组: ${tag}`);
  2262. }
  2263. returnRfidInputBuffer.value = '';
  2264. }
  2265. console.log(`[scheduleReturnRFIDBufferSubmit] 延迟提交时,标签数组共有 ${returnRfidTagArray.value.length} 个标签:`, returnRfidTagArray.value);
  2266. // 处理标签数组,使用统一的延迟处理机制
  2267. if (returnRfidTagArray.value.length > 0) {
  2268. // 清除之前的延迟处理定时器(如果存在)
  2269. clearReturnProcessTagArrayTimer();
  2270. // 设置统一的延迟处理,确保所有标签都被收集后再处理
  2271. returnProcessTagArrayTimer = setTimeout(() => {
  2272. returnProcessTagArrayTimer = null;
  2273. if (returnRfidTagArray.value.length > 0 && !isProcessingReturnTagArray.value) {
  2274. console.log(`[scheduleReturnRFIDBufferSubmit] 延迟处理,最终标签数组:`, returnRfidTagArray.value);
  2275. processReturnRfidTagArray();
  2276. }
  2277. }, 300); // 增加延迟时间到300ms,确保所有标签都被收集
  2278. }
  2279. }, delay);
  2280. };
  2281. // 处理归还设备输入(用于同步 textarea 内容,仅在缓冲模式下使用)
  2282. const handleReturnDeviceInput = () => {
  2283. // 如果启用了RFID缓冲,检查 returnSearchText 中是否包含多个标签(通过换行、回车等分隔)
  2284. if (readRuleConfig.value.enableRFIDBuffer && returnSearchText.value.trim()) {
  2285. // 检查是否包含换行符或回车符
  2286. if (/[\r\n]/.test(returnSearchText.value)) {
  2287. // 如果包含换行符,说明可能有多个标签
  2288. const codes = splitDeviceCodes(returnSearchText.value);
  2289. console.log(`[handleReturnDeviceInput] 检测到换行符,分割得到 ${codes.length} 个代码:`, codes, '原始内容长度:', returnSearchText.value.length, '原始内容:', returnSearchText.value.substring(0, 200));
  2290. // 无论有多少个标签,都添加到标签数组(包括单个标签的情况)
  2291. if (codes.length > 0) {
  2292. codes.forEach(code => {
  2293. const trimmedCode = code.trim();
  2294. if (trimmedCode && !returnRfidTagArray.value.includes(trimmedCode) && !returnProcessingTags.value.has(trimmedCode)) {
  2295. returnRfidTagArray.value.push(trimmedCode);
  2296. console.log(`[handleReturnDeviceInput] 添加标签到数组: ${trimmedCode}`);
  2297. }
  2298. });
  2299. console.log(`[handleReturnDeviceInput] 标签数组共有 ${returnRfidTagArray.value.length} 个标签:`, returnRfidTagArray.value);
  2300. // 清空 returnSearchText,避免重复处理
  2301. returnSearchText.value = '';
  2302. // 清空当前标签和缓冲区,因为已经添加到数组了
  2303. returnCurrentRfidTag.value = '';
  2304. returnRfidInputBuffer.value = '';
  2305. // 如果有标签数组且当前没有在处理,使用统一的延迟处理机制
  2306. if (returnRfidTagArray.value.length > 0 && !isProcessingReturnTagArray.value) {
  2307. clearReturnRFIDInputTimer();
  2308. // 清除之前的延迟处理定时器(如果存在)
  2309. clearReturnProcessTagArrayTimer();
  2310. // 设置统一的延迟处理,确保所有标签都被收集后再处理
  2311. returnProcessTagArrayTimer = setTimeout(() => {
  2312. returnProcessTagArrayTimer = null;
  2313. if (returnRfidTagArray.value.length > 0 && !isProcessingReturnTagArray.value) {
  2314. console.log(`[handleReturnDeviceInput] 延迟处理,最终标签数组:`, returnRfidTagArray.value);
  2315. processReturnRfidTagArray();
  2316. }
  2317. }, 300); // 增加延迟时间到300ms,确保所有标签都被收集
  2318. }
  2319. return;
  2320. }
  2321. }
  2322. }
  2323. // 如果缓冲区有内容,确保 textarea 显示与缓冲区一致
  2324. // 这主要用于处理退格键等操作后的同步
  2325. if (returnCurrentRfidTag.value || returnRfidInputBuffer.value) {
  2326. const displayValue = returnCurrentRfidTag.value || returnRfidInputBuffer.value;
  2327. if (returnSearchText.value !== displayValue) {
  2328. returnSearchText.value = displayValue;
  2329. }
  2330. }
  2331. // 注意:正常输入时,不干预 textarea 的内容,让默认行为处理
  2332. };
  2333. // 检测归还流程是否是高速扫码输入(通过输入速度判断)
  2334. // 返回值:{ isHighSpeed: boolean, isFirstInput: boolean, timeSinceLastInput: number }
  2335. const checkReturnInputSpeed = () => {
  2336. const now = Date.now();
  2337. const timeSinceLastInput = returnLastInputTime > 0 ? now - returnLastInputTime : 0;
  2338. const isFirstInput = returnLastInputTime === 0;
  2339. if (!isFirstInput) {
  2340. returnLastInputTime = now;
  2341. }
  2342. return {
  2343. isFirstInput,
  2344. timeSinceLastInput,
  2345. isHighSpeed: timeSinceLastInput > 0 && timeSinceLastInput < readRuleConfig.value.minInputSpeed,
  2346. isNormalInput: timeSinceLastInput > 200
  2347. };
  2348. };
  2349. // 处理归还流程RFID键盘输入(高速扫码)
  2350. const handleReturnRFIDKeydown = (event: KeyboardEvent) => {
  2351. // 如果未启用RFID缓冲,直接返回,不拦截
  2352. if (!readRuleConfig.value.enableRFIDBuffer) {
  2353. return;
  2354. }
  2355. // 不拦截修饰键组合(如 Ctrl+C, Ctrl+V 等)
  2356. if (event.ctrlKey || event.metaKey || event.altKey) {
  2357. return;
  2358. }
  2359. // 处理回车键
  2360. if (event.key === 'Enter') {
  2361. // 回车键由 @keydown.enter.prevent="handleReturnDeviceEnter" 处理
  2362. // 这里不处理,让 handleReturnDeviceEnter 统一处理
  2363. return;
  2364. }
  2365. // 处理退格键
  2366. if (event.key === 'Backspace') {
  2367. // 如果有当前标签或缓冲内容,处理缓冲
  2368. if (returnCurrentRfidTag.value || returnRfidInputBuffer.value) {
  2369. event.preventDefault();
  2370. if (returnCurrentRfidTag.value) {
  2371. returnCurrentRfidTag.value = returnCurrentRfidTag.value.slice(0, -1);
  2372. returnRfidInputBuffer.value = returnCurrentRfidTag.value;
  2373. } else {
  2374. returnRfidInputBuffer.value = returnRfidInputBuffer.value.slice(0, -1);
  2375. }
  2376. returnSearchText.value = returnRfidInputBuffer.value || returnCurrentRfidTag.value;
  2377. }
  2378. // 否则让默认行为处理
  2379. return;
  2380. }
  2381. // 处理普通字符输入
  2382. if (event.key.length === 1) {
  2383. const inputInfo = checkReturnInputSpeed();
  2384. const { isFirstInput, isHighSpeed, isNormalInput, timeSinceLastInput } = inputInfo;
  2385. // 如果是第一次输入,不拦截,让默认行为处理,只记录时间戳
  2386. if (isFirstInput) {
  2387. returnLastInputTime = Date.now();
  2388. // 不拦截,让字符正常输入到 textarea
  2389. return;
  2390. }
  2391. // 如果检测到是正常输入(间隔 > 200ms),处理之前的缓冲内容
  2392. if (isNormalInput) {
  2393. // 如果之前有当前标签或缓冲内容,先保存到标签数组(去重)
  2394. if (returnCurrentRfidTag.value.trim()) {
  2395. const tag = returnCurrentRfidTag.value.trim();
  2396. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2397. returnRfidTagArray.value.push(tag);
  2398. }
  2399. returnCurrentRfidTag.value = '';
  2400. }
  2401. if (returnRfidInputBuffer.value.trim()) {
  2402. const tag = returnRfidInputBuffer.value.trim();
  2403. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2404. returnRfidTagArray.value.push(tag);
  2405. }
  2406. returnRfidInputBuffer.value = '';
  2407. }
  2408. // 如果有标签数组,处理它们
  2409. if (returnRfidTagArray.value.length > 0) {
  2410. processReturnRfidTagArray();
  2411. }
  2412. // 重置状态
  2413. returnConsecutiveInputCount = 0;
  2414. returnLastInputTime = Date.now();
  2415. // 不拦截,让字符正常输入到 textarea
  2416. return;
  2417. }
  2418. // 如果检测到是高速输入(间隔 < 30ms),使用缓冲模式
  2419. if (isHighSpeed) {
  2420. event.preventDefault();
  2421. event.stopPropagation(); // 阻止事件冒泡,避免影响其他元素
  2422. // 如果输入间隔超过标签分隔时间,说明是一个新标签的开始
  2423. // 需要保存之前的标签到数组
  2424. if (timeSinceLastInput > readRuleConfig.value.tagSeparatorTimeout) {
  2425. // 保存当前标签到数组(如果存在且去重)
  2426. if (returnCurrentRfidTag.value.trim()) {
  2427. const tag = returnCurrentRfidTag.value.trim();
  2428. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2429. returnRfidTagArray.value.push(tag);
  2430. }
  2431. returnCurrentRfidTag.value = '';
  2432. }
  2433. // 保存缓冲内容到数组(如果存在且去重)
  2434. if (returnRfidInputBuffer.value.trim()) {
  2435. const tag = returnRfidInputBuffer.value.trim();
  2436. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2437. returnRfidTagArray.value.push(tag);
  2438. }
  2439. returnRfidInputBuffer.value = '';
  2440. }
  2441. // 如果 textarea 中有内容,检查是否需要添加到数组(去重)
  2442. if (returnSearchText.value.trim()) {
  2443. const codes = splitDeviceCodes(returnSearchText.value);
  2444. codes.forEach(code => {
  2445. const trimmedCode = code.trim();
  2446. if (trimmedCode && !returnRfidTagArray.value.includes(trimmedCode) && !returnProcessingTags.value.has(trimmedCode)) {
  2447. returnRfidTagArray.value.push(trimmedCode);
  2448. }
  2449. });
  2450. returnSearchText.value = ''; // 清空 searchText,避免重复处理
  2451. }
  2452. // 重置,开始新标签
  2453. returnCurrentRfidTag.value = event.key;
  2454. returnRfidInputBuffer.value = event.key;
  2455. returnSearchText.value = event.key;
  2456. } else {
  2457. // 如果是第一次检测到高速输入(之前没有缓冲内容),需要将 textarea 中已有的内容也加入当前标签
  2458. if (returnCurrentRfidTag.value === '' && returnRfidInputBuffer.value === '' && returnSearchText.value) {
  2459. // textarea 中已经有内容(第一个字符已经通过默认行为输入了)
  2460. // 将整个内容作为当前标签的初始值,然后追加当前字符
  2461. returnCurrentRfidTag.value = returnSearchText.value + event.key;
  2462. } else {
  2463. // 否则直接追加当前字符到当前标签
  2464. returnCurrentRfidTag.value += event.key;
  2465. }
  2466. // 同时更新缓冲区和显示
  2467. returnRfidInputBuffer.value = returnCurrentRfidTag.value;
  2468. returnSearchText.value = returnCurrentRfidTag.value;
  2469. }
  2470. returnConsecutiveInputCount++;
  2471. scheduleReturnRFIDBufferSubmit();
  2472. return;
  2473. }
  2474. // 如果输入间隔在 30-200ms 之间,可能是正常输入,不拦截
  2475. // 但如果之前有缓冲内容,说明高速输入已结束,先保存当前标签(去重)
  2476. if (returnCurrentRfidTag.value.trim() || returnRfidInputBuffer.value.trim()) {
  2477. if (returnCurrentRfidTag.value.trim()) {
  2478. const tag = returnCurrentRfidTag.value.trim();
  2479. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2480. returnRfidTagArray.value.push(tag);
  2481. }
  2482. returnCurrentRfidTag.value = '';
  2483. }
  2484. if (returnRfidInputBuffer.value.trim()) {
  2485. const tag = returnRfidInputBuffer.value.trim();
  2486. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2487. returnRfidTagArray.value.push(tag);
  2488. }
  2489. returnRfidInputBuffer.value = '';
  2490. }
  2491. // 处理标签数组
  2492. if (returnRfidTagArray.value.length > 0) {
  2493. processReturnRfidTagArray();
  2494. }
  2495. returnConsecutiveInputCount = 0;
  2496. }
  2497. returnLastInputTime = Date.now();
  2498. // 不拦截,让字符正常输入到 textarea
  2499. }
  2500. };
  2501. // 处理归还输入框失焦
  2502. const handleReturnDeviceBlur = (event: FocusEvent) => {
  2503. // 如果焦点转移到其他输入元素(如表单输入框),不自动聚焦
  2504. const relatedTarget = event.relatedTarget as HTMLElement;
  2505. if (relatedTarget && (
  2506. relatedTarget.tagName === 'INPUT' ||
  2507. relatedTarget.tagName === 'TEXTAREA' ||
  2508. relatedTarget.closest('.el-input') ||
  2509. relatedTarget.closest('.el-textarea') ||
  2510. relatedTarget.closest('form')
  2511. )) {
  2512. // 如果有缓冲内容,先提交
  2513. if (returnRfidInputBuffer.value) {
  2514. submitReturnRFIDBuffer();
  2515. }
  2516. return;
  2517. }
  2518. // 其他情况(如点击按钮等),延迟后自动聚焦
  2519. setTimeout(() => {
  2520. if (returnSearchInputRef.value && !loading.value) {
  2521. returnSearchInputRef.value.focus();
  2522. }
  2523. }, 10);
  2524. };
  2525. // 处理归还回车键
  2526. const handleReturnDeviceEnter = (event: KeyboardEvent) => {
  2527. if (event.shiftKey) return;
  2528. event.preventDefault();
  2529. // 如果启用了RFID缓冲,先检查是否有当前标签或缓冲内容
  2530. if (readRuleConfig.value.enableRFIDBuffer) {
  2531. // 如果有当前标签,先保存到标签数组(去重)
  2532. if (returnCurrentRfidTag.value.trim()) {
  2533. const tag = returnCurrentRfidTag.value.trim();
  2534. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2535. returnRfidTagArray.value.push(tag);
  2536. }
  2537. returnCurrentRfidTag.value = '';
  2538. }
  2539. // 如果有缓冲内容,也添加到标签数组(去重)
  2540. if (returnRfidInputBuffer.value.trim()) {
  2541. const tag = returnRfidInputBuffer.value.trim();
  2542. if (!returnRfidTagArray.value.includes(tag) && !returnProcessingTags.value.has(tag)) {
  2543. returnRfidTagArray.value.push(tag);
  2544. }
  2545. returnRfidInputBuffer.value = '';
  2546. }
  2547. }
  2548. // 检查 returnSearchText 中是否包含多个标签(通过换行、回车等分隔)
  2549. if (returnSearchText.value.trim()) {
  2550. const codes = splitDeviceCodes(returnSearchText.value);
  2551. console.log(`[handleReturnDeviceEnter] 回车键提交时,returnSearchText 分割得到 ${codes.length} 个代码:`, codes, '原始内容长度:', returnSearchText.value.length, '原始内容:', returnSearchText.value.substring(0, 500));
  2552. // 将所有标签添加到数组(包括单个标签的情况)
  2553. codes.forEach(code => {
  2554. const trimmedCode = code.trim();
  2555. if (trimmedCode && !returnRfidTagArray.value.includes(trimmedCode) && !returnProcessingTags.value.has(trimmedCode)) {
  2556. returnRfidTagArray.value.push(trimmedCode);
  2557. console.log(`[handleReturnDeviceEnter] 添加标签到数组: ${trimmedCode}`);
  2558. }
  2559. });
  2560. returnSearchText.value = '';
  2561. }
  2562. console.log(`[handleReturnDeviceEnter] 回车键提交时,标签数组共有 ${returnRfidTagArray.value.length} 个标签:`, returnRfidTagArray.value);
  2563. // 如果有标签数组,使用统一的延迟处理机制,避免多次触发
  2564. if (returnRfidTagArray.value.length > 0) {
  2565. clearReturnRFIDInputTimer();
  2566. returnConsecutiveInputCount = 0;
  2567. returnLastInputTime = 0;
  2568. // 清除之前的延迟处理定时器(如果存在)
  2569. clearReturnProcessTagArrayTimer();
  2570. // 设置统一的延迟处理,确保所有标签都被收集后再处理
  2571. returnProcessTagArrayTimer = setTimeout(() => {
  2572. returnProcessTagArrayTimer = null;
  2573. if (returnRfidTagArray.value.length > 0 && !isProcessingReturnTagArray.value) {
  2574. console.log(`[handleReturnDeviceEnter] 延迟处理,最终标签数组:`, returnRfidTagArray.value);
  2575. processReturnRfidTagArray();
  2576. }
  2577. }, 300); // 增加延迟时间到300ms,确保所有标签都被收集
  2578. return;
  2579. }
  2580. // 如果没有标签数组,使用 returnSearchText 进行搜索
  2581. if (returnSearchText.value.trim()) {
  2582. handleReturnScanSearch();
  2583. }
  2584. };
  2585. // 处理归还扫码搜索(支持批量,优化并发请求)
  2586. const handleReturnScanSearch = async (event?: Event) => {
  2587. // 阻止默认行为,防止表单提交导致页面刷新
  2588. if (event) {
  2589. event.preventDefault();
  2590. event.stopPropagation();
  2591. }
  2592. // 如果启用了RFID缓冲,先提交缓冲区
  2593. if (readRuleConfig.value.enableRFIDBuffer && returnRfidInputBuffer.value) {
  2594. const bufferedValue = returnRfidInputBuffer.value;
  2595. returnRfidInputBuffer.value = '';
  2596. clearReturnRFIDInputTimer();
  2597. returnSearchText.value = bufferedValue;
  2598. }
  2599. if (!returnSearchText.value.trim()) return;
  2600. // 分割多个设备编号
  2601. const codes = splitDeviceCodes(returnSearchText.value);
  2602. if (codes.length === 0) return;
  2603. // 去重处理,避免重复请求同一个设备编号
  2604. const uniqueCodes = Array.from(new Set(codes.map(code => code.trim()))).filter(Boolean);
  2605. if (uniqueCodes.length === 0) return;
  2606. loading.value = true;
  2607. let successCount = 0;
  2608. let failCount = 0;
  2609. const errorMessages: string[] = [];
  2610. try {
  2611. // 批量并发处理设备编号(使用 Promise.allSettled 确保所有请求都完成)
  2612. // 限制并发数量,避免同时发起过多请求
  2613. const batchSize = 10; // 每批处理10个
  2614. const batches: string[][] = [];
  2615. for (let i = 0; i < uniqueCodes.length; i += batchSize) {
  2616. batches.push(uniqueCodes.slice(i, i + batchSize));
  2617. }
  2618. // 逐批处理,每批内部并发
  2619. for (const batch of batches) {
  2620. const promises = batch.map(async (code) => {
  2621. try {
  2622. const res = await deviceApi.GetList({
  2623. page: 1,
  2624. limit: 1,
  2625. code: code,
  2626. status: 1
  2627. });
  2628. if (res.data && res.data.length > 0) {
  2629. const device = res.data[0];
  2630. const existingDeviceIndex = returnDeviceList.value.findIndex(d => d.device_no === device.id);
  2631. if (existingDeviceIndex !== -1) {
  2632. const row = returnDeviceList.value[existingDeviceIndex];
  2633. const errMsg = tryApplyReturnScanIncrement(row);
  2634. if (errMsg) {
  2635. return { success: false, code, message: errMsg };
  2636. }
  2637. return { success: true, code };
  2638. } else {
  2639. // 设备不存在于归还列表中
  2640. return {
  2641. success: false,
  2642. code,
  2643. message: `设备 ${device.code || device.category_name} 不在当前归还列表中,请先通过手动归还添加该设备`
  2644. };
  2645. }
  2646. } else {
  2647. return { success: false, code, message: `未找到设备编号: ${code}` };
  2648. }
  2649. } catch (error) {
  2650. console.error(`处理设备编号 ${code} 失败:`, error);
  2651. return { success: false, code, message: `处理设备编号 ${code} 失败` };
  2652. }
  2653. });
  2654. // 等待当前批次完成
  2655. const results = await Promise.allSettled(promises);
  2656. // 统计结果
  2657. results.forEach((result, index) => {
  2658. const { success, message } = readSettledListStepResult(result, batch[index] ?? String(index));
  2659. if (success) {
  2660. successCount++;
  2661. } else {
  2662. failCount++;
  2663. if (message) {
  2664. errorMessages.push(message);
  2665. }
  2666. }
  2667. });
  2668. }
  2669. // 显示批量处理结果
  2670. if (uniqueCodes.length > 1) {
  2671. if (successCount > 0 && failCount === 0) {
  2672. ElMessage.success(`成功增加 ${successCount} 个设备的归还数量`);
  2673. } else if (successCount > 0 && failCount > 0) {
  2674. ElMessage.warning(`成功增加 ${successCount} 个设备的归还数量,失败 ${failCount} 个`);
  2675. // 只显示前3个错误信息,避免消息过多
  2676. if (errorMessages.length > 0) {
  2677. console.warn('批量处理错误详情:', errorMessages.slice(0, 3));
  2678. }
  2679. } else if (failCount > 0) {
  2680. ElMessage.error(`处理失败,共 ${failCount} 个设备编号`);
  2681. }
  2682. } else if (successCount > 0) {
  2683. ElMessage.success('已增加 1 个归还数量');
  2684. } else if (failCount > 0 && errorMessages.length > 0) {
  2685. ElMessage.warning(errorMessages[0]);
  2686. }
  2687. } catch (error) {
  2688. console.error('批量处理设备失败:', error);
  2689. ElMessage.error('搜索设备失败');
  2690. } finally {
  2691. returnSearchText.value = ''; // 清空搜索框
  2692. loading.value = false;
  2693. // 重新聚焦输入框,保持选中状态
  2694. nextTick(() => {
  2695. if (returnSearchInputRef.value) {
  2696. returnSearchInputRef.value.focus();
  2697. returnSearchInputRef.value.select();
  2698. }
  2699. });
  2700. }
  2701. };
  2702. // 异常记录列表数据
  2703. const abnormalList = ref([
  2704. /* {
  2705. borrowNo: '202409002',
  2706. borrower: '张同学',
  2707. time: '2024-09-12 10:21:32',
  2708. type: '逾期'
  2709. },
  2710. {
  2711. borrowNo: '202505013',
  2712. borrower: '张同学',
  2713. time: '2025-05-13 15:12:35',
  2714. type: '损坏'
  2715. } */
  2716. ]);
  2717. /* 归还设备异常记录 */
  2718. const returnAbnormalList = ref([
  2719. ]);
  2720. // 附件文件列表
  2721. const attachmentFileList = ref<any[]>([]);
  2722. // 查看异常记录详情
  2723. const handleView = (row: any) => {
  2724. console.log('查看异常记录:', row);
  2725. // 这里可以添加查看详情的逻辑
  2726. };
  2727. const selectedDeviceCodes = ref<any[]>([]);
  2728. // 计算已选中设备的ID列表(用于禁用已选中的设备)
  2729. const disabledDeviceIds = computed(() => {
  2730. if (activeName.value === 'first') {
  2731. // first tab: 从 form.value.items 中获取 device ID
  2732. return form.value.items.map((item: any) => item.device).filter(Boolean);
  2733. } else if (activeName.value === 'second') {
  2734. // second tab: 从 deviceList.value 中获取 device_no ID
  2735. return deviceList.value.map((item: any) => item.device_no).filter(Boolean);
  2736. }
  2737. // third tab (归还模式) 不需要禁用,因为已经有特殊的处理逻辑
  2738. return [];
  2739. });
  2740. // 借用列表相关方法
  2741. const handleAdd = () => {
  2742. if (activeName.value === 'third' && allReturned.value) {
  2743. ElMessage.info('当前列表设备均已归还,无可选择设备');
  2744. return;
  2745. }
  2746. if(activeName.value === 'third'){
  2747. selectedDeviceCodes.value = [];
  2748. returnDeviceList.value.forEach(item => {
  2749. console.log("item:::",item);
  2750. if(item.device_no){
  2751. selectedDeviceCodes.value.push(item.device_code);
  2752. }
  2753. });
  2754. console.log("selectedDeviceCodes.value:::",selectedDeviceCodes.value);
  2755. }
  2756. showSelectDeviceDialog.value = true;
  2757. };
  2758. const handleRemove = (index: number) => {
  2759. deviceList.value.splice(index, 1);
  2760. };
  2761. const handleReturnRemove = (index: number) => {
  2762. returnDeviceList.value.splice(index, 1);
  2763. };
  2764. // 处理表格多选变化
  2765. const handleSelectionChange = (selection: DeviceListItem[]) => {
  2766. selectedDevices.value = selection;
  2767. };
  2768. // 设备选择处理
  2769. function onDeviceSelected(devices: Device[]) {
  2770. console.log("devices:::",devices,"activeName:::",activeName.value);
  2771. if (activeName.value === 'first') {
  2772. // 获取已存在的设备ID列表
  2773. const existingIds = new Set(form.value.items.map((item: any) => item.device).filter(Boolean));
  2774. // 过滤掉已存在的设备,只添加新的
  2775. const newDevices = devices.filter((d) => !existingIds.has(d.id));
  2776. if (newDevices.length === 0) {
  2777. ElMessage.warning('所选设备已存在,未添加重复项');
  2778. return;
  2779. }
  2780. // 如果有部分重复,提示用户
  2781. if (newDevices.length < devices.length) {
  2782. ElMessage.warning(`已过滤 ${devices.length - newDevices.length} 个重复的设备`);
  2783. }
  2784. form.value.items.push(
  2785. ...newDevices.map((d) => ({
  2786. device: d.id,
  2787. device_code: d.code,
  2788. remark: d.category_name,
  2789. quantity: 1,
  2790. location: d.warehouse,
  2791. device_name: d.name,
  2792. device_specification: d.device_specification
  2793. }))
  2794. );
  2795. } else if (activeName.value === 'second') {
  2796. // 获取已存在的设备ID列表
  2797. const existingIds = new Set(deviceList.value.map((item: any) => item.device_no).filter(Boolean));
  2798. // 过滤掉已存在的设备,只添加新的
  2799. const newDevices = devices.filter((d) => !existingIds.has(d.id));
  2800. if (newDevices.length === 0) {
  2801. ElMessage.warning('所选设备已存在,未添加重复项');
  2802. return;
  2803. }
  2804. // 如果有部分重复,提示用户
  2805. if (newDevices.length < devices.length) {
  2806. ElMessage.warning(`已过滤 ${devices.length - newDevices.length} 个重复的设备`);
  2807. }
  2808. deviceList.value.push(
  2809. ...newDevices.map(d => ({
  2810. device_no: d.id,
  2811. device_code: d.code,
  2812. device_type: d.category_name,
  2813. device_name: d.name || '',
  2814. borrow_count: 1,
  2815. brand: d.brand || '',
  2816. model: d.model,
  2817. device_specification: d.specification,
  2818. warehouse: d.warehouse,
  2819. available_quantity:d.available_quantity
  2820. }))
  2821. );
  2822. }else if(activeName.value === 'third'){
  2823. // 在添加前检查每个设备是否已存在;手动选设备:将本次归还数量记满至「待归还」上限
  2824. devices.forEach(d => {
  2825. const existingDeviceIndex = returnDeviceList.value.findIndex(item => item.device_no === d.id);
  2826. if (existingDeviceIndex !== -1) {
  2827. const row = returnDeviceList.value[existingDeviceIndex];
  2828. const cap = row.available_quantity ?? 0;
  2829. if (cap <= 0) {
  2830. ElMessage.warning('该设备无待归还数量');
  2831. return;
  2832. }
  2833. row.borrow_count = cap;
  2834. row.is_return = true;
  2835. row.return_time = dayjs().format('YYYY-MM-DD HH:mm:ss');
  2836. row.brand = d.brand || row.brand || '';
  2837. if (row.return_status) {
  2838. row.return_status = { value: 2, label: '已归还' };
  2839. }
  2840. touchReturnRowSort(row);
  2841. ElMessage.success(`已将该设备本次归还记为 ${cap} 件`);
  2842. } else {
  2843. // 如果设备不存在,添加新记录
  2844. /* returnDeviceList.value.push({
  2845. device_no: d.id,
  2846. device_type: d.category_name,
  2847. device_name: d.name || '',
  2848. borrow_count: 1,
  2849. brand: d.brand || '',
  2850. model: d.model || '',
  2851. warehouse: d.warehouse,
  2852. status: '已归还'
  2853. }); */
  2854. /* ElMessage.success(`设备 ${d.category_name} 已添加到归还列表`); */
  2855. }
  2856. });
  2857. }
  2858. }
  2859. // 移除同步相关的 watch
  2860. // const handleClick = (tab: TabsPaneContext, event: Event) => {
  2861. // if (tab.props.name === 'second') {
  2862. // deviceList.value = form.value.items.map(item => ({
  2863. // device_no: item.device,
  2864. // device_type: item.remark,
  2865. // device_name: '',
  2866. // borrow_count: item.quantity,
  2867. // brand: '',
  2868. // model: '',
  2869. // warehouse: item.location
  2870. // }));
  2871. // }
  2872. // }
  2873. function handleClick(tab: TabsPaneContext) {
  2874. console.log('Tab clicked:', tab.props.name);
  2875. // 当切换到设备清单标签页时,自动聚焦输入框
  2876. if (tab.props.name === 'second') {
  2877. nextTick(() => {
  2878. if (searchInputRef.value) {
  2879. searchInputRef.value.focus();
  2880. searchInputRef.value.select();
  2881. }
  2882. });
  2883. } else if (tab.props.name === 'third') {
  2884. // 当切换到归还设备清单标签页时,自动聚焦输入框
  2885. nextTick(() => {
  2886. returnSearchInputRef.value?.focus?.();
  2887. });
  2888. }
  2889. }
  2890. function handleUploadSuccess(response: any, file: any, fileList: any) {
  2891. // eslint-disable-next-line no-console
  2892. console.log('上传成功:', file.name);
  2893. }
  2894. function handleUploadError(err: any, file: any, fileList: any) {
  2895. // eslint-disable-next-line no-console
  2896. console.error('上传失败:', file.name);
  2897. }
  2898. // 图片预览处理函数
  2899. const handlePictureCardPreview = (uploadFile: any) => {
  2900. dialogImageUrl.value = uploadFile.url || uploadFile.response?.url || form.value.attachments;
  2901. dialogVisible.value = true;
  2902. };
  2903. // 处理附件删除
  2904. const handleRemoves = (file: any, fileList: any) => {
  2905. // 由于是禁用状态,这里只是示例,实际不会执行删除
  2906. console.log('删除附件:', file.name);
  2907. };
  2908. const form = ref<FormData>({
  2909. borrower_info:{
  2910. user_code:'',
  2911. mobile:''
  2912. },
  2913. application_no: '',
  2914. emergency_contact: '',
  2915. emergency_phone: '',
  2916. app_user_borrower: { id: '', name: '', user_code: '', mobile: '' },
  2917. team_type: 0,
  2918. team_members_count: 1,
  2919. team_members: '',
  2920. expected_start_time:'',
  2921. expected_end_time: '',
  2922. borrower_dept: '',
  2923. purpose: '',
  2924. applicant_remark_type: "1",
  2925. applicant_remark: '',
  2926. items: [],
  2927. accessory_info: '',
  2928. borrow_type: 2,
  2929. return_location:'',
  2930. approver_info: {
  2931. name: ''
  2932. }
  2933. });
  2934. const showSelectDeviceDialog = ref(false);
  2935. const rules = {
  2936. emergency_contact: [
  2937. { required: true, message: '请输入借用人', trigger: 'change' },
  2938. ],
  2939. app_user_borrower: [
  2940. { required: true, message: '请输入学号或工号', trigger: 'change' },
  2941. ],
  2942. emergency_phone: [
  2943. { required: true, message: '请输入联系电话', trigger: 'change' },
  2944. ],
  2945. /* borrower_dept: [
  2946. { required: true, message: '请输入借用部门', trigger: 'change' },
  2947. ], */
  2948. expected_end_time: [
  2949. { required: true, message: '请输选择归还时间', trigger: 'change' },
  2950. ],
  2951. team_type: [
  2952. { required: true, message: '请选择个人或者团队', trigger: 'change' },
  2953. ],
  2954. purpose: [
  2955. { required: true, message: '请输入借用原因', trigger: 'change' },
  2956. ],
  2957. applicant_remark_type: [
  2958. { required: true, message: '请选择审批人', trigger: 'change' },
  2959. ],
  2960. applicant_remark: [
  2961. { required: false, message: '请输入备注', trigger: 'change' },
  2962. ],
  2963. };
  2964. // 自动填充用户信息
  2965. onMounted(() => {
  2966. loadWarehouses()
  2967. getAdminList()
  2968. getAllUserList()
  2969. try {
  2970. const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
  2971. if (userInfo) {
  2972. form.value.emergency_contact = userInfo.username || '';
  2973. // 借用人从用户列表加载完成后再统一回显/设置
  2974. form.value.emergency_phone = userInfo.mobile || '';
  2975. form.value.borrower_dept = userInfo.dept_info?.dept_name || '';
  2976. }
  2977. } catch (e) {
  2978. /* empty */
  2979. }
  2980. });
  2981. watch(
  2982. () => props.visible,
  2983. (v) => {
  2984. visible.value = v;
  2985. // 当对话框打开且当前标签页是设备清单时,自动聚焦输入框
  2986. if (v && activeName.value === 'second' && isCollect.value) {
  2987. nextTick(() => {
  2988. if (searchInputRef.value) {
  2989. searchInputRef.value.focus();
  2990. searchInputRef.value.select();
  2991. }
  2992. });
  2993. } else if (v && activeName.value === 'third' && !isView.value) {
  2994. // 当对话框打开且当前标签页是归还设备清单时,自动聚焦输入框
  2995. nextTick(() => {
  2996. returnSearchInputRef.value?.focus?.();
  2997. });
  2998. }
  2999. // 清理RFID缓冲状态
  3000. if (v) {
  3001. rfidInputBuffer.value = '';
  3002. currentRfidTag.value = '';
  3003. rfidTagArray.value = [];
  3004. clearRFIDInputTimer();
  3005. consecutiveInputCount = 0;
  3006. lastInputTime = 0;
  3007. // 清空待提交的设备编号数组
  3008. pendingDeviceCodes.value = [];
  3009. isAutoSubmitting.value = false;
  3010. // 清理归还流程RFID缓冲状态
  3011. returnRfidInputBuffer.value = '';
  3012. returnCurrentRfidTag.value = '';
  3013. returnRfidTagArray.value = [];
  3014. returnProcessingTags.value.clear();
  3015. isProcessingReturnTagArray.value = false;
  3016. clearReturnRFIDInputTimer();
  3017. returnConsecutiveInputCount = 0;
  3018. returnLastInputTime = 0;
  3019. }
  3020. }
  3021. );
  3022. watch(() => props.modelValue, async (val) => {
  3023. if (val && val.id) {
  3024. try {
  3025. const res = await api.GetApplicationDetail(val.id);
  3026. console.log("res:::::",res)
  3027. if (res.code === 2000 && res.data) {
  3028. const data = res.data;
  3029. Object.assign(form.value, data);
  3030. buildSteps(data);
  3031. // 领取模式下不回显历史配件内容
  3032. if (isCollect.value) {
  3033. collectAccessories.value = '';
  3034. }
  3035. timeline.value.create = data.create_datetime ? dayjs(data.create_datetime).format('YYYY-MM-DD HH:mm:ss') : '';
  3036. timeline.value.approve = data.approve_time || '';
  3037. const approverinfo = data.approver_info ?? data.admin_approver_info
  3038. timeline.value.approver = approverinfo?.name || '审批人'
  3039. // timeline.value.approver = data.admin_approver_info?.name || '审批人';
  3040. // console.log("data:::",form.value);
  3041. // activeStep.value = 1; // 创建
  3042. // if (data.status >= 1) activeStep.value = 2; // 待审批
  3043. // if (data.status >= 2) activeStep.value = 3; // 审批通过
  3044. // if (data.status >= 3) activeStep.value = 4; // 完成
  3045. // 同步 form.items 到 returnDeviceList
  3046. if (form.value.items && form.value.items.length > 0) {
  3047. returnDeviceList.value = (form.value.items as any[])
  3048. .filter((item) => item.device !== null)
  3049. .map(mapFormItemToReturnDeviceListRow);
  3050. }
  3051. // 同步 form.records 到 returnAbnormalList
  3052. if (form.value.records && form.value.records.length > 0) {
  3053. // 添加损坏类型记录
  3054. const damageRecord: AbnormalRecord = {
  3055. application_no: form.value.application_no,
  3056. operator_name: form.value.app_user_borrower?.name||form.value.external_borrower_name||'',
  3057. user_code: form.value.borrower_info?.user_code || form.value.app_user_borrower?.user_code||'',
  3058. emergency_phone: form.value.app_user_borrower?.mobile||form.value.external_borrower_phone || '',
  3059. type: '损坏',
  3060. condition: form.value.borrower_damage_count || 0,
  3061. create_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  3062. };
  3063. // 添加逾期类型记录
  3064. const overdueRecord: AbnormalRecord = {
  3065. application_no: form.value.application_no,
  3066. operator_name: form.value.app_user_borrower?.name||form.value.external_borrower_name||'',
  3067. user_code: form.value.borrower_info?.user_code || form.value.app_user_borrower?.user_code||'',
  3068. emergency_phone: form.value.app_user_borrower?.mobile||form.value.external_borrower_phone || '',
  3069. type: '逾期',
  3070. condition: form.value.borrower_overdue_count || 0, // 逾期数量设为1
  3071. create_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  3072. };
  3073. returnAbnormalList.value = [damageRecord, overdueRecord];
  3074. abnormalList.value = [damageRecord, overdueRecord];
  3075. }
  3076. // 处理附件回显
  3077. if (data.attachments) {
  3078. if (typeof data.attachments === 'string') {
  3079. // 如果attachments是字符串URL
  3080. attachmentFileList.value = [{
  3081. name: data.attachments.split('/').pop() || '附件',
  3082. url: data.attachments,
  3083. status: 'success'
  3084. }];
  3085. } else if (Array.isArray(data.attachments)) {
  3086. // 如果attachments是数组
  3087. attachmentFileList.value = data.attachments.map((item: any, index: number) => {
  3088. if (typeof item === 'string') {
  3089. return {
  3090. name: item.split('/').pop() || `附件${index + 1}`,
  3091. url: item,
  3092. status: 'success'
  3093. };
  3094. } else if (typeof item === 'object' && item.url) {
  3095. return {
  3096. name: item.name || item.url.split('/').pop() || `附件${index + 1}`,
  3097. url: item.url,
  3098. status: 'success'
  3099. };
  3100. }
  3101. return null;
  3102. }).filter(Boolean);
  3103. }
  3104. }
  3105. }
  3106. } catch (e) {
  3107. console.log("审判失败:::",e)
  3108. ElMessage.error('获取审批信息失败');
  3109. }
  3110. }else if(val&& isEdit.value){
  3111. try {
  3112. const res = await api.GetApplicationDetail(val.id);
  3113. if (res.code === 2000 && res.data) {
  3114. const data = res.data;
  3115. Object.assign(form.value, data);
  3116. // 同步 form.items 到 returnDeviceList
  3117. if (form.value.items && form.value.items.length > 0) {
  3118. returnDeviceList.value = (form.value.items as any[])
  3119. .filter((item) => item.device !== null)
  3120. .map(mapFormItemToReturnDeviceListRow);
  3121. }
  3122. // 处理附件回显 (编辑模式)
  3123. if (data.attachments) {
  3124. if (typeof data.attachments === 'string') {
  3125. attachmentFileList.value = [{
  3126. name: data.attachments.split('/').pop() || '附件',
  3127. url: data.attachments,
  3128. status: 'success'
  3129. }];
  3130. } else if (Array.isArray(data.attachments)) {
  3131. attachmentFileList.value = data.attachments.map((item: any, index: number) => {
  3132. if (typeof item === 'string') {
  3133. return {
  3134. name: item.split('/').pop() || `附件${index + 1}`,
  3135. url: item,
  3136. status: 'success'
  3137. };
  3138. } else if (typeof item === 'object' && item.url) {
  3139. return {
  3140. name: item.name || item.url.split('/').pop() || `附件${index + 1}`,
  3141. url: item.url,
  3142. status: 'success'
  3143. };
  3144. }
  3145. return null;
  3146. }).filter(Boolean);
  3147. }
  3148. }
  3149. }
  3150. } catch (e) {
  3151. ElMessage.error('获取审批信息失败');
  3152. }
  3153. }
  3154. }, { immediate: true });
  3155. // watch(
  3156. // () => props.modelValue,
  3157. // (v) => {
  3158. // if (v) {
  3159. // // eslint-disable-next-line no-console
  3160. // console.log("val:::::",v);
  3161. // Object.assign(form.value, v);
  3162. // }
  3163. // }, { immediate: true }
  3164. // );
  3165. // 监听借用人选择变化
  3166. watch(() => form.value.app_user_borrower?.id, (newId) => {
  3167. if (!newId || allUserList.value.length === 0) return;
  3168. const selectedUser: any = allUserList.value.find((u: any) => String(u.id) === String(newId));
  3169. if (selectedUser) {
  3170. form.value.app_user_borrower = {
  3171. id: selectedUser.id,
  3172. name: selectedUser.name,
  3173. user_code: selectedUser.user_code || '',
  3174. mobile: selectedUser.mobile || ''
  3175. };
  3176. }
  3177. });
  3178. function addItem() {
  3179. if (activeName.value === 'third' && allReturned.value) {
  3180. ElMessage.info('当前列表设备均已归还,无可选择设备');
  3181. return;
  3182. }
  3183. showSelectDeviceDialog.value = true;
  3184. }
  3185. function removeItem(index: number) {
  3186. form.value.items.splice(index, 1);
  3187. }
  3188. function onCancel() {
  3189. // 重置标签页到第一个
  3190. activeName.value = 'first';
  3191. // 清理异常记录列表
  3192. returnAbnormalList.value = [];
  3193. abnormalList.value = [];
  3194. // 清理设备列表
  3195. deviceList.value = [];
  3196. returnDeviceList.value = [];
  3197. // 清理RFID相关定时器和状态
  3198. clearRFIDInputTimer();
  3199. clearProcessTagArrayTimer();
  3200. clearReturnRFIDInputTimer();
  3201. clearReturnProcessTagArrayTimer();
  3202. rfidInputBuffer.value = '';
  3203. currentRfidTag.value = '';
  3204. rfidTagArray.value = [];
  3205. returnRfidInputBuffer.value = '';
  3206. returnCurrentRfidTag.value = '';
  3207. returnRfidTagArray.value = [];
  3208. processingTags.value.clear();
  3209. returnProcessingTags.value.clear();
  3210. isProcessingTagArray.value = false;
  3211. isProcessingReturnTagArray.value = false;
  3212. // 清空待提交的设备编号数组
  3213. pendingDeviceCodes.value = [];
  3214. isAutoSubmitting.value = false;
  3215. consecutiveInputCount = 0;
  3216. lastInputTime = 0;
  3217. returnConsecutiveInputCount = 0;
  3218. returnLastInputTime = 0;
  3219. // 清理搜索框
  3220. searchText.value = '';
  3221. returnSearchText.value = '';
  3222. // 清理备注
  3223. remark.value = '';
  3224. // 清理领取模式配件信息
  3225. collectAccessories.value = '';
  3226. returnRemark.value = '';
  3227. // 重置状态
  3228. returnStatus.value = '未归还';
  3229. // 清理选中的设备
  3230. selectedDevices.value = [];
  3231. // 清理附件文件列表
  3232. attachmentFileList.value = [];
  3233. // 清理RFID缓冲
  3234. rfidInputBuffer.value = '';
  3235. currentRfidTag.value = '';
  3236. rfidTagArray.value = [];
  3237. clearRFIDInputTimer();
  3238. consecutiveInputCount = 0;
  3239. lastInputTime = 0;
  3240. // 清理归还流程RFID缓冲
  3241. returnRfidInputBuffer.value = '';
  3242. returnCurrentRfidTag.value = '';
  3243. returnRfidTagArray.value = [];
  3244. returnProcessingTags.value.clear();
  3245. isProcessingReturnTagArray.value = false;
  3246. clearReturnRFIDInputTimer();
  3247. returnConsecutiveInputCount = 0;
  3248. returnLastInputTime = 0;
  3249. // 关闭所有对话框
  3250. showSelectDeviceDialog.value = false;
  3251. showSettlementDialog.value = false;
  3252. showAbnormalDialog.value = false;
  3253. showViewAbnormalDialog.value = false;
  3254. // 重置当前异常数据
  3255. currentAbnormalData.value = {
  3256. damage_type: 0,
  3257. condition: '',
  3258. photos: []
  3259. };
  3260. // 发出关闭事件
  3261. emit('update:visible', false);
  3262. }
  3263. // 提交时合并数据
  3264. function onSubmit() {
  3265. if(isCollect.value){
  3266. // 验证是否有设备信息
  3267. const hasDevicesInFirstTab = form.value.items && form.value.items.length > 0;
  3268. const hasDevicesInSecondTab = deviceList.value && deviceList.value.length > 0;
  3269. if (!hasDevicesInFirstTab && !hasDevicesInSecondTab) {
  3270. ElMessage.warning('请添加设备信息后再提交');
  3271. activeName.value = 'second'; // 自动切换到借用列表标签页
  3272. return;
  3273. }
  3274. // 验证设备数量
  3275. const hasInvalidQuantityInFirstTab = form.value.items.some(item => !item.quantity || item.quantity <= 0);
  3276. const hasInvalidQuantityInSecondTab = deviceList.value.some(item => !item.borrow_count || item.borrow_count <= 0);
  3277. if (hasInvalidQuantityInFirstTab || hasInvalidQuantityInSecondTab) {
  3278. ElMessage.warning('请确保所有设备的数量大于0');
  3279. activeName.value = 'second'; // 自动切换到借用列表标签页
  3280. return;
  3281. }
  3282. // 合并两个标签页的设备数据
  3283. const allDevices = [
  3284. ...deviceList.value.map(item => ({
  3285. condition: remark.value,
  3286. quantity: item.borrow_count,
  3287. device_id: Number(item.device_no) || 0
  3288. }))
  3289. ];
  3290. const submitData = {
  3291. id:form.value.id,
  3292. item_id:form.value.id,
  3293. device_assignments: allDevices,
  3294. remark:remark.value,
  3295. pre_borrow_accessories: collectAccessories.value,
  3296. };
  3297. CollectEquipment(submitData).then((res: ApiResponse) => {
  3298. if(res.code===2000){
  3299. ElMessage.success("领取成功");
  3300. // 准备结算单数据
  3301. settlementData.value = {
  3302. ...form.value,
  3303. items: deviceList.value.map(item => ({
  3304. ...item,
  3305. device_category_name: item.device_type,
  3306. device_name: item.device_name,
  3307. device_specification: item.device_specification,
  3308. device_storage_location: getWarehouseName(item.warehouse) || item.warehouse,
  3309. remark: item.device_type,
  3310. quantity: item.borrow_count,
  3311. device_id: item.device_no,
  3312. device_category: item.device_type,
  3313. device_code: item.device_no,
  3314. borrow_type: form.value.borrow_type,
  3315. borrower_dept: form.value.borrower_dept,
  3316. emergency_contact: form.value.emergency_contact,
  3317. emergency_phone: form.value.emergency_phone,
  3318. team_type: form.value.team_type,
  3319. })),
  3320. accessory_info: accessoryInfo.value,
  3321. pre_borrow_accessories:collectAccessories.value,
  3322. remark: remark.value,
  3323. expected_start_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
  3324. };
  3325. // 先触发提交事件进行页面刷新
  3326. emit('submit');
  3327. // 关闭当前对话框
  3328. emit('update:visible', false);
  3329. // 使用 nextTick 确保在 DOM 更新后再显示结算单
  3330. nextTick(() => {
  3331. borrowForm.value = {...settlementData.value,mode: 'settlement' };
  3332. showSettlementDialog.value = true;
  3333. });
  3334. }
  3335. });
  3336. } else {
  3337. // 归还:按每行「归还数量」提交,须大于 0 且不超过待归还
  3338. const toReturn = returnDeviceList.value.filter(
  3339. (item) => (Number(item.borrow_count) || 0) > 0
  3340. );
  3341. if (toReturn.length === 0) {
  3342. ElMessage.warning('请通过扫码/输入填写归还数量,或从手动归还中确认设备');
  3343. return;
  3344. }
  3345. const over = toReturn.find(
  3346. (item) => (Number(item.borrow_count) || 0) > (Number(item.available_quantity) || 0)
  3347. );
  3348. if (over) {
  3349. ElMessage.error('存在归还数量超过待归还数量,请检查');
  3350. return;
  3351. }
  3352. const allDevices = toReturn.map((item) => ({
  3353. device: item.device_no,
  3354. quantity: item.borrow_count,
  3355. remark: returnRemark.value,
  3356. device_id: Number(item.device_no) || 0,
  3357. condition: item.condition,
  3358. damage_type: item.damage_type,
  3359. photo_urls: item.photos || [],
  3360. }));
  3361. const submitData = {
  3362. id: form.value.id,
  3363. items: allDevices,
  3364. status: returnStatus.value,
  3365. pre_borrow_accessories: form.value.pre_borrow_accessories,
  3366. };
  3367. ReturnEquipment(submitData).then(async (res: ApiResponse) => {
  3368. if(res.code===2000){
  3369. ElMessage.success("归还成功");
  3370. try {
  3371. if (form.value.id) {
  3372. const detailRes = await api.GetApplicationDetail(form.value.id);
  3373. if (detailRes.code === 2000 && detailRes.data) {
  3374. returnStatus.value = detailRes.data.status_label || returnStatus.value;
  3375. }
  3376. }
  3377. } catch (e) {
  3378. ElMessage.error('获取最新状态失败');
  3379. }
  3380. emit('submit');
  3381. emit('update:visible', false);
  3382. }
  3383. });
  3384. }
  3385. }
  3386. function clickReturn(){
  3387. returnStatus.value = '已归还';
  3388. // 自动选择所有设备
  3389. const tableRef = document.querySelector('.el-table__header-wrapper th.el-table__cell.is-leaf .el-checkbox');
  3390. if (tableRef) {
  3391. (tableRef as HTMLElement).click();
  3392. }
  3393. }
  3394. // 组件卸载时清理定时器和状态
  3395. onBeforeUnmount(() => {
  3396. clearRFIDInputTimer();
  3397. clearProcessTagArrayTimer();
  3398. rfidInputBuffer.value = '';
  3399. currentRfidTag.value = '';
  3400. rfidTagArray.value = [];
  3401. consecutiveInputCount = 0;
  3402. lastInputTime = 0;
  3403. processingTags.value.clear();
  3404. isProcessingTagArray.value = false;
  3405. // 清空待提交的设备编号数组
  3406. pendingDeviceCodes.value = [];
  3407. isAutoSubmitting.value = false;
  3408. // 清理归还流程定时器和状态
  3409. clearReturnRFIDInputTimer();
  3410. clearReturnProcessTagArrayTimer();
  3411. returnRfidInputBuffer.value = '';
  3412. returnCurrentRfidTag.value = '';
  3413. returnRfidTagArray.value = [];
  3414. returnProcessingTags.value.clear();
  3415. isProcessingReturnTagArray.value = false;
  3416. returnConsecutiveInputCount = 0;
  3417. returnLastInputTime = 0;
  3418. });
  3419. /* formRef.value.validate((valid: boolean) => {
  3420. if (valid) {
  3421. form.value.items = form.value.items.map(item => ({
  3422. ...item,
  3423. quantity: Number(item.quantity) || 0
  3424. }));
  3425. const firstLocation = form.value.items[0]?.location || '';
  3426. form.value.return_location = firstLocation;
  3427. form.value.expected_start_time = now;
  3428. form.value.expected_end_time = dayjs(form.value.expected_end_time).format('YYYY-MM-DD HH:mm:ss')|| now;
  3429. form.team_members_count=Number(form.team_members_count)||1;
  3430. emit('submit', { ...form.value });
  3431. emit('update:visible', false);
  3432. ElMessage.success("添加成功!");
  3433. }
  3434. }); */
  3435. </script>
  3436. <style>
  3437. .avatar-uploader .el-upload {
  3438. border: 1px dashed #d9d9d9;
  3439. border-radius: 6px;
  3440. cursor: pointer;
  3441. position: relative;
  3442. overflow: hidden;
  3443. }
  3444. .avatar-uploader .el-upload:hover {
  3445. border-color: #409EFF;
  3446. }
  3447. .avatar-uploader-icon {
  3448. font-size: 28px;
  3449. color: #8c939d;
  3450. width: 178px;
  3451. height: 178px;
  3452. line-height: 178px;
  3453. text-align: center;
  3454. }
  3455. .avatar {
  3456. width: 178px;
  3457. height: 178px;
  3458. display: block;
  3459. }
  3460. .return-cell-placeholder {
  3461. color: #c0c4cc;
  3462. }
  3463. .return-cell-text {
  3464. color: #606266;
  3465. }
  3466. .device-code-input {
  3467. padding: 8px 12px;
  3468. font-size: 14px;
  3469. border: 1px solid #dcdfe6;
  3470. border-radius: 4px;
  3471. outline: none;
  3472. resize: vertical;
  3473. transition: all 0.3s;
  3474. font-family: 'Microsoft YaHei', sans-serif;
  3475. line-height: 1.5;
  3476. }
  3477. .device-code-input:focus {
  3478. border-color: #409EFF;
  3479. box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  3480. }
  3481. .device-code-input:disabled {
  3482. background-color: #f5f7fa;
  3483. cursor: not-allowed;
  3484. }
  3485. </style>