| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531 |
- <template>
- <el-dialog v-model="visible" :title="isView ? '查看' : isCollect ? '领取' : '归还'" width="75%" :close-on-click-modal="false" @close="onCancel">
- <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
- <el-tab-pane label="借用单信息" name="first">
- <el-form :model="form" label-width="110px" label-position="top" :rules="rules" ref="formRef">
- <el-row :gutter="16">
- <el-col :span="8">
- <el-form-item label="借用单编号" prop="application_no">
- <el-input v-model="form.application_no" placeholder="自动生成" disabled />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="借用人类型" prop="borrower_type">
- <el-select v-model="form.borrower_type" :placeholder="isView?'':'请选择借用人角色'" :disabled="true">
- <el-option label="管理员用户" :value=0 />
- <el-option label="应用用户" :value=1 />
- <el-option label="外部用户" :value=2 />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8" >
- <!-- <el-form-item label="借用人" prop="external_borrower_name" v-if="form.borrower_type !== 2">
- <el-input v-model="form.borrower_info.name" placeholder="请输入借用人" :disabled="true" />
- </el-form-item> -->
- <el-form-item label="借用人" prop="admin_borrower" v-if="form.borrower_type == 0">
-
- <el-select v-model="form.admin_borrower" :placeholder="isView?'':'请选择借用人'" :disabled="true" >
- <el-option :label="adminList.name" :value="adminList.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="借用人" prop="app_user_borrower" v-if="form.borrower_type == 1">
- <el-select v-model="form.app_user_borrower.id" :placeholder="isView?'':'请选择借用人'" :disabled="true" >
- <el-option v-for="item in allUserList" :key="item.id" :label="item.name" :value="item.id" />
- </el-select>
- </el-form-item>
- <el-form-item label="借用人" prop="external_borrower_name" v-if="form.borrower_type == 2">
- <el-input v-model="form.external_borrower_name" :placeholder="isView?'':'请输入借用人'" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="8" v-if="form.borrower_type !== 2">
- <el-form-item label="学号/工号" prop="user_code" >
- <!-- {{ form.borrower_info.user_code }} -->
- <el-input v-model="form.app_user_borrower.user_code" :placeholder="isView?'':'请输入学号/工号'" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="联系电话" v-if="form.borrower_type !== 2">
- <el-input v-model="form.app_user_borrower.mobile" :placeholder="isView?'':'请输入联系电话'" :disabled="true" />
- </el-form-item>
- <el-form-item label="联系电话" v-if="form.borrower_type == 2">
- <el-input v-model="form.external_borrower_phone" :placeholder="isView?'':'请输入联系电话'" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="借用部门" prop="borrower_dept">
- <el-input v-model="form.borrower_dept" placeholder="请输入借用部门" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="预计归还时间" prop="expected_end_time">
- <el-date-picker v-model="form.expected_end_time" type="date"
- format="YYYY-MM-DD"
- value-format="YYYY-MM-DD"
- :disabledDate="disabledDate" placeholder="请选择预计归还时间" style="width: 100%" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="4">
- <el-form-item label="个人/团队" prop="team_type" >
- <el-select v-model="form.team_type" placeholder="请选择" :disabled="true">
- <el-option label="个人" :value="0" />
- <el-option label="团队" :value="1" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="4" v-show="form.team_type===1">
- <el-form-item label="团队人数" prop="team_members_count">
- <el-input v-model="form.team_members_count" :placeholder="isView?'':'请输入'" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="16" v-show="form.team_type===1">
- <el-form-item label="团队其他人员名单" prop="team_members">
- <el-input v-model="form.team_members" :placeholder="isView?'':'请输入团队其他人员名单'" :disabled="true"/>
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item label="借用原因" prop="purpose">
- <el-input v-model="form.purpose" type="textarea" :placeholder="isView?'':'请输入借用原因'" :disabled="true" />
- </el-form-item>
- </el-col>
- <el-col :span="4">
- <!-- ||form.approver_info.name -->
- <el-form-item label="审批人" prop="applicant_remark_type">
- <el-select v-model="form.approver_info.name" placeholder="请选择" :disabled="true" >
- <el-option label="管理员" value="1"/>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="20">
- <el-form-item label="备注" prop="applicant_remark">
- <el-input v-model="form.applicant_remark" :placeholder="isView?'':'请输入备注'" :disabled="true"/>
- </el-form-item>
- </el-col>
- </el-row>
- <div style="margin: 16px 0 8px 0; font-weight: bold"> {{ isView ? '借用列表' : (isCollect ? '借用列表' : '归还列表') }}</div>
- <el-table :data="form.items.filter(item => item.device === null)" border style="width: 50%; margin-bottom: 12px">
- <el-table-column type="index" label="序号" width="60" />
- <el-table-column prop="device_category_name" label="设备分类" />
- <el-table-column :label="isView ? '数量' : (isCollect ? '借用数量' : '归还数量')">
- <template #default="{ row }">
- <el-input v-model="row.quantity" type="number" :min="1" prop="quantity" size="small" :disabled="true" />
- </template>
- </el-table-column>
- <el-table-column label="操作" width="80">
- <template #default="{ $index }">
- <el-button type="text" style="color: red" @click="removeItem($index)" :disabled="true">移除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-button type="primary" @click="addItem" v-if="!isView" :disabled="true">选择设备分类</el-button>
- <div style="margin: 16px 0 8px 0; font-weight: bold">预借配件信息</div>
- <el-input v-model="form.accessories" :placeholder="isView?'':'请输入预借配件信息'" :disabled="true"/>
- <div style="margin: 16px 0 8px 0; font-weight: bold" >附件</div>
- <!-- <el-upload
- action="#"
- drag
- :list-type="'picture'"
- accept=".bmp,.gif,.jpeg,.jpg,.png,.webp,.svg"
- multiple
- :show-file-list="true"
- :file-list="attachmentFileList"
- :on-success="handleUploadSuccess"
- :on-error="handleUploadError"
- :disabled="true"
- >
- <i class="el-icon-upload"></i>
- <div class="el-upload__text">将文件拖到此处,或 <em>点击上传</em></div>
- </el-upload> -->
- <el-upload
- :disabled="true"
- action="#"
- list-type="picture-card"
- :on-preview="handlePictureCardPreview"
- :on-remove="handleRemoves"
- :file-list="attachmentFileList"
- >
- <el-icon><Plus /></el-icon>
- </el-upload>
- <div v-if="isView && form.latest_renewal" style="margin-top: 8px;">
- <div style="font-weight: bold; margin-bottom: 8px">续借信息</div>
- <el-row :gutter="16">
- <el-col :span="4">
- <el-form-item label="续借天数">
- <el-input :model-value="form.latest_renewal?.renewal_days" :disabled="true">
- <template #append>天</template>
- </el-input>
- </el-form-item>
- </el-col>
- <el-col :span="21">
- <el-form-item label="续借理由">
- <el-input :model-value="form.latest_renewal?.renewal_reason" type="textarea" :disabled="true" />
- </el-form-item>
- </el-col>
- </el-row>
- </div>
- </el-form>
-
- <!-- 审批信息流程展示 -->
- <!-- <div v-if="isView" style="margin-top: 24px; padding: 0 12px">
- <div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
- <el-steps :active="activeStep" align-center>
- <el-step
- title="创建申请"
- :description="`创建时间:${ timeline.create }`"
- icon="CircleCheck"
- :status="activeStep >= 1 ? 'finish' : 'wait'"
- />
- <el-step
- title="待审批"
- description="待审批人审批"
- icon="CircleCheck"
- :status="activeStep >= 2 ? 'finish' : 'wait'"
- />
- <el-step
- title="审批通过"
- :description="`审批人:${timeline.approver},时间:${timeline.approve}`"
- icon="CircleCheck"
- :status="activeStep >= 3 ? 'finish' : 'wait'"
- />
- <el-step
- title="流程完成"
- description="流程已结束"
- icon="CircleCheck"
- :status="activeStep >= 4 ? 'finish' : 'wait'"
- />
- </el-steps>
- </div> -->
- <div v-if="isView" style="margin-top: 24px; padding: 0 12px">
- <div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
- <el-steps :active="steps.length" align-center>
- <el-step
- v-for="(step, index) in steps"
- :key="index"
- :title="step.title"
- :description="step.description"
- icon="CircleCheck"
- :status="step.status"
- />
- </el-steps>
- </div>
- </el-tab-pane>
- <el-tab-pane v-if="isCollect && !shouldHideDeviceList" label="设备清单" name="second">
- <el-form :model="form" label-width="110px">
- <el-row :gutter="16">
- <el-col :span="24">
- <div style="margin: 8px 0">
- <el-input v-model="searchText" placeholder="请扫描设备条码添加" style="width: 300px" @keyup.enter="handleScanSearch" />
- <el-button type="primary" style="margin-left: 16px" @click="handleAdd">手动借用</el-button>
- </div>
- <el-table :data="deviceList" border style="width: 100%">
- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="device_code" label="设备编号" align="center" />
- <el-table-column prop="device_type" label="设备分类" align="center" />
- <el-table-column prop="device_name" label="设备名称" align="center" />
- <el-table-column prop="borrow_count" label="借用数量" align="center" width="150">
- <template #default="{ row }">
- <el-input-number v-model="row.borrow_count" :disabled="isView" :min="1" :max="row.available_quantity" size="small" />
- </template>
- </el-table-column>
- <el-table-column prop="brand" label="品牌" align="center" />
- <el-table-column prop="device_specification" label="规格型号" align="center" />
- <!-- <el-table-column prop="warehouse" label="存放仓库" align="center" /> -->
- <el-table-column label="操作" width="80" align="center">
- <template #default="{ $index }">
- <el-button type="text" style="color: red" :disabled="isView" @click="handleRemove($index)">移除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="24">
- <div style="font-weight: bold; margin-bottom: 8px">实借配件信息</div>
- <el-input v-if="isCollect" v-model="collectAccessories" :disabled="isView" type="textarea" :placeholder="isView?'':'请输入实借配件信息'" />
- <el-input v-else v-model="form.accessories" :disabled="isView" type="textarea" :placeholder="isView?'':'请输入实借配件信息'" />
- </el-col>
- <el-col :span="24" style="margin-top: 16px">
- <div style="font-weight: bold; margin-bottom: 8px">备注</div>
- <el-input v-model="remark" type="textarea" :disabled="isView" :placeholder="isView?'':'请输入备注'" />
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="24">
- <div style="font-weight: bold; margin-bottom: 8px">异常记录 <span>{{
- abnormalList?.length ?
- abnormalList.reduce((sum, item) => sum + (Number(item?.condition) || 0), 0)
- : 0
- }}</span> 次</div>
- <el-table v-if="abnormalList.length > 0" :data="abnormalList" border style="width: 100%">
- <!-- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="application_no" label="借用单编号" align="center" /> -->
- <el-table-column prop="operator_name" label="借用人" align="center" />
- <el-table-column prop="user_code" label="学号" align="center" />
- <el-table-column prop="emergency_phone" label="借用人电话" align="center" />
- <!-- <el-table-column prop="time" label="发生时间" align="center" /> -->
- <el-table-column prop="type" label="异常" align="center">
- <template #default="{ row }">
- {{ row.type }}
- </template>
- </el-table-column>
- <el-table-column prop="condition" label="数量" align="center">
- <template #default="{ row }">
- {{ row.condition }}
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- </el-form>
- </el-tab-pane>
- <el-tab-pane v-else-if="!shouldHideDeviceList" label="设备清单" name="third">
- <el-form :model="form" label-width="110px">
- <el-row :gutter="16">
- <el-col :span="24">
- <div style="margin: 8px 0" v-if="!isView" >
- <el-input :disabled="isView" v-model="returnSearchText" placeholder="请扫描设备条码添加" style="width: 300px" @keyup.enter="handleReturnScanSearch" />
- <el-button type="primary" style="margin-left: 16px" @click="handleAdd" :disabled="isView">手动归还</el-button>
- </div>
- <el-table :data="returnDeviceList" border style="width: 100%" >
- <!-- <el-table-column type="selection" width="55" align="center" />@selection-change="handleSelectionChange" -->
- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="device_code" label="设备编号" align="center" />
- <!-- <el-table-column prop="device_type" label="设备分类" align="center" /> -->
- <el-table-column prop="device_name" label="设备名称" align="center" />
- <el-table-column prop="borrow_count" label="借用数量" align="center" width="150">
- <template #default="{ row }">
- <el-input-number v-model="row.borrow_count" :min="1" :max="row.available_quantity" size="small" :disabled="true" />
- </template>
- </el-table-column>
- <el-table-column prop="brand" label="品牌" align="center" />
- <el-table-column prop="model" label="规格型号" align="center" />
- <!-- <el-table-column prop="warehouse" label="存放仓库" align="center" /> -->
- <el-table-column prop="status" label="状态" align="center">
- <template #default="{ row }">
- {{ row.return_status.label }}
- <!-- <el-tag v-if="!isView" :type="row.status === '已归还' ? 'success' : 'warning'">{{ row.status }}</el-tag>
- <el-tag v-else-if="['已领取', '已归还'].includes(form.status_label)">{{ form.status_label }}</el-tag> -->
- <!-- <span v-else>{{ form.status_label }}</span> -->
- </template>
- </el-table-column>
- <el-table-column prop="status" label="归还时间" align="center">
- <template #default="{ row }">
- {{ row.return_time ? dayjs(row.return_time).format('YYYY-MM-DD HH:mm:ss') : (row.return_status?.label === '已归还' ? dayjs().format('YYYY-MM-DD HH:mm:ss') : '') }}
- </template>
- </el-table-column>
- <el-table-column label="操作" width="120" align="center">
- <template #default="{ $index,row }">
- <!-- && (!returnDeviceList[$index]?.condition || returnDeviceList[$index]?.photos?.length==0)&& row.problem_records?.length ==0 -->
- <el-button :disabled="isView" type="text" style="color: red;"
- v-if="!isView"
- @click="handleAbnormal($index)">异常操作</el-button>
- <el-button
-
- type="text"
- style="color: #409EFF;margin-left:0"
- @click="handleViewAbnormal($index)"
- v-if="row.problem_records?.length || (returnDeviceList[$index]?.condition || returnDeviceList[$index]?.photos?.length)"
- >查看异常</el-button>
- <!-- <el-button type="text" v-if="!isView" :disabled="isView" style="color: red" @click="handleReturnRemove($index)">移除</el-button> -->
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="16">
- <div style="font-weight: bold; margin-bottom: 8px">实借配件信息</div>
- <el-input v-model="form.accessories" :disabled="isView" :placeholder="isView?'':'请输入实借配件信息'" />
- </el-col>
- <el-col :span="8">
- <div style="font-weight: bold; margin-bottom: 8px">当前状态</div>
- <el-input v-model="returnStatus" v-if="!isView" :disabled="true" placeholder="" style="width: 150px" />
- <el-input value="已归还" v-else :disabled="true" placeholder="" style="width: 150px" />
- <el-button type="primary" v-if="!isView" style="margin-left: 16px" @click="clickReturn"
- :disabled="returnStatus=='已归还'||isView">归还</el-button>
- </el-col>
- <el-col :span="24" style="margin-top: 16px">
- <div style="font-weight: bold; margin-bottom: 8px">备注</div>
- <el-input v-model="returnRemark" type="textarea" :disabled="isView" :placeholder="isView?'':'请输入备注'" />
- </el-col>
- </el-row>
- <el-row :gutter="16" style="margin-top: 16px">
- <el-col :span="24">
- <div style="font-weight: bold; margin-bottom: 8px">异常记录 <span>{{
- returnAbnormalList?.length ?
- returnAbnormalList.reduce((sum, item) => sum + (Number(item?.condition) || 0), 0)
- : 0
- }}</span> 次</div>
- <el-table v-if="returnAbnormalList?.length > 0" :data="returnAbnormalList" border style="width: 100%">
- <!-- <el-table-column type="index" label="序号" width="60" align="center" />
- <el-table-column prop="application_no" label="借用单编号" align="center" /> -->
- <el-table-column prop="operator_name" label="借用人" align="center" />
- <el-table-column prop="user_code" label="学号" align="center" />
- <el-table-column prop="emergency_phone" label="借用人电话" align="center" />
- <!-- <el-table-column prop="time" label="发生时间" align="center" /> -->
- <el-table-column prop="type" label="异常" align="center">
- <template #default="{ row }">
- {{ row.type }}
- </template>
- </el-table-column>
- <el-table-column prop="condition" label="数量" align="center">
- <template #default="{ row }">
- {{ row.condition }}
- </template>
- </el-table-column>
- </el-table>
- </el-col>
- </el-row>
- </el-form>
- </el-tab-pane>
- </el-tabs>
- <template #footer>
- <el-button @click="onCancel">关闭</el-button>
- <el-button type="primary" @click="onSubmit" v-if="!isView"> {{ isCollect ? '提交' : '确认' }}</el-button>
- </template>
- </el-dialog>
- <SelectDeviceDialog
- v-model:visible="showSelectDeviceDialog"
- @confirm="onDeviceSelected"
- :device-ids="returnDeviceList.map(item => item.device_no)"
- :return-mode="activeName === 'third'"
- :device-status-map="deviceStatusMap"
- />
- <SettlementDialog v-model:visible="showSettlementDialog" :settlement-data="settlementData" :modelValue="borrowForm" />
- <AbnormalDialog v-model:visible="showAbnormalDialog" @confirm="onAbnormalConfirm" />
- <ViewAbnormalDialog
- v-model:visible="showViewAbnormalDialog"
- :abnormal-data="currentAbnormalData"
- />
- <!-- 图片预览对话框 -->
- <el-dialog v-model="dialogVisible" title="图片预览" width="auto" center>
- <img width="100%" :src="dialogImageUrl" alt="Preview Image" style="max-width: 100%; max-height: 80vh;" />
- </el-dialog>
- </template>
- <script setup lang="ts">
- import { ref, watch, defineProps, defineEmits, onMounted, computed, nextTick } from 'vue';
- import SelectDeviceDialog from './SelectDeviceDialog/index.vue';
- import SettlementDialog from './SettlementDialog.vue';
- import AbnormalDialog from './AbnormalDialog/index.vue';
- import ViewAbnormalDialog from './ViewAbnormalDialog/index.vue';
- import dayjs from 'dayjs';
- import { ElMessage } from 'element-plus';
- import * as api from '../../api';
- import * as deviceApi from '../../../device/api';
- import { CollectEquipment, ReturnEquipment } from '../../api';
- import type { TabsPaneContext } from 'element-plus';
- import { getUserInfo } from '../../../login/api';
- import { request } from '/@/utils/service';
- // 禁止选择今天之前的日期
- const disabledDate = (time: Date) => {
- // 获取今天的开始时间(准确到日)
- const today = new Date()
- today.setHours(0, 0, 0, 0)
- // 返回true表示禁用,禁用今天之前的所有日期
- return time.getTime() < today.getTime()
- }
- /* 获取管理员列表 */
- const adminList = ref([]);
- async function getAdminList() {
- const res = await getUserInfo();
- adminList.value = res.data;
- console.log("adminList.value:::",adminList.value)
- }
- /* */
- /* 获取所有用户 */
- const allUserList = ref([]);
- async function getAllUserList() {
- const res = await api.GetAllUser({page:1,limit:60});
- allUserList.value = res.data;
- // 设置默认选择第一个用户
- if (allUserList.value.length > 0) {
- form.value.app_user_borrower = allUserList.value[0].id;
- }
- console.log("allUserList.value:::",allUserList.value)
- }
- interface ApiResponse {
- code: number;
- data?: any;
- message?: string;
- }
- // 定义接口
- interface Device {
- id: string | number;
- category_name: string;
- name?: string;
- brand?: string;
- model?: string;
- warehouse: string;
- device_specification?: string;
- device_name?: string;
- }
- interface DeviceListItem {
- device_no: string | number;
- device_type: string;
- device_name?: string; // 改为可选
- borrow_count: number;
- brand: string;
- model?: string; // 改为可选
- warehouse: string;
- status?: string;
- condition?: string;
- photos?: Array<{
- filename: string;
- data: string;
- }>;
- device_specification?: string;
- available_quantity?:number;
- }
- interface FormItem {
- device: string | number;
- remark: string;
- quantity: number;
- location: string;
- device_name?: string;
- device_specification?: string;
- condition?: string;
- photos?: Array<{
- filename: string;
- data: string;
- }>;
- }
- interface FormData {
- application_no: string;
- emergency_contact: string;
- emergency_phone: string;
- app_user_borrower: number;
- team_type: number;
- team_members_count: number;
- team_members: string;
- expected_start_time: string;
- expected_end_time: string;
- borrower_dept: string;
- purpose: string;
- applicant_remark_type: string;
- applicant_remark: string;
- items: FormItem[];
- accessory_info: string;
- borrow_type: number;
- return_location: string;
- status_label?: string;
- id?: number;
- records?: any[];
- borrower_info?: {
- user_code: string;
- };
- borrower_damage_count?: number;
- accessories?: string;
- latest_renewal?: {
- renewal_days?: number | string;
- renewal_reason?: string;
- };
- }
- interface AbnormalData {
- damage_type:number;
- condition: string;
- photos: Array<{
- filename: string;
- data: string;
- }>;
- }
- interface AbnormalRecord {
- application_no: string;
- operator_name: string;
- user_code: string;
- emergency_phone: string;
- type: '损坏' | '逾期';
- condition: number;
- create_time: string;
- }
- const now = dayjs().format('YYYY-MM-DD HH:mm:ss');
- const props = defineProps<{ visible: boolean; modelValue?: any }>();
- const isEdit = computed(() => props.modelValue?.mode === 'edit');
- const isView = computed(() => props.modelValue?.mode === 'view');
- const isAdd = computed(() => props.modelValue?.mode === 'add');
- const isCollect = computed(() => props.modelValue?.mode === 'collect');
- const isReturn = computed(() => props.modelValue?.mode === 'return');
- // 计算是否应该隐藏设备清单标签页
- const shouldHideDeviceList = computed(() => {
- if (!isView.value) return false;
- // 检查状态
- const status = (form.value as any).status;
- const statusLabel = (form.value as any).status_label;
- // 审批拒绝:隐藏设备清单
- const isRejected = status === 3 || (typeof statusLabel === 'string' && statusLabel.includes('拒绝'));
- if (isRejected) {
- return true;
- }
- // 强制显示:状态大于 5 或状态标签为"已借出"
- if ((typeof status === 'number' && status > 5) || statusLabel === '已借出') {
- return false;
- }
- // 待审批状态:隐藏设备清单
- const isPendingApproval = status < 2 || statusLabel === '待审批';
- // 其他情况默认显示
- return isPendingApproval;
- });
- // 计算设备状态映射
- const deviceStatusMap = computed(() => {
- const statusMap: Record<string | number, any> = {};
- returnDeviceList.value.forEach(device => {
- if (device.device_no && device.return_status) {
- statusMap[device.device_no] = device.return_status;
- }
- });
- return statusMap;
- });
- const emit = defineEmits(['update:visible', 'update:modelValue', 'submit']);
- const visible = ref(props.visible);
- const formRef = ref();
- // 图片预览相关
- const dialogImageUrl = ref('');
- const dialogVisible = ref(false);
- const timeline = ref({
- create: '',
- approve: '',
- approver: ''
- });
- // const activeStep = ref(1);
- const activeName = ref('first');
- const returnStatus = ref('未归还'); // 添加独立的状态变量
- // 借用列表相关数据
- const searchText = ref('');
- const deviceList = ref<DeviceListItem[]>([]);
- const accessoryInfo = ref('');
- const remark = ref('');
- // 领取模式下的“实借配件信息”本地输入,不回显历史
- const collectAccessories = ref('');
- // 归还设备相关数据
- const returnSearchText = ref('');
- const returnDeviceList = ref<DeviceListItem[]>([]);
- const returnAccessoryInfo = ref('');
- const returnRemark = ref('');
- const selectedDevices = ref<DeviceListItem[]>([]); // 添加选中设备列表
- //审批步骤
- const steps = ref<any[]>([]);
- // 仓库映射(id -> name)
- const warehouseMap = ref<Record<string, string>>({});
- async function loadWarehouses() {
- try {
- const res = await request({
- url: '/api/system/warehouse/',
- method: 'get',
- params: { page: 1, limit: 999 }
- });
- if (res?.code === 2000 && Array.isArray(res.data)) {
- warehouseMap.value = Object.fromEntries(
- res.data.map((w: any) => [String(w.id), w.name])
- );
- }
- } catch (e) {
- /* empty */
- }
- }
- function getWarehouseName(id: any) {
- const key = id != null ? String(id) : '';
- return warehouseMap.value[key] ?? id;
- }
- // 添加结算单相关的状态
- const showSettlementDialog = ref(false);
- const settlementData = ref<any>(null);
- const borrowForm = ref<any>(null);
- // 添加异常操作相关的状态
- const showAbnormalDialog = ref(false);
- const currentAbnormalIndex = ref(-1);
- // 添加查看异常相关的状态
- const showViewAbnormalDialog = ref(false);
- const currentAbnormalData = ref<AbnormalData>({
- damage_type:0,
- condition: '',
- photos: []
- });
- //审批
- function buildSteps(data: any) {
- steps.value = [
- {
- title: '创建申请',
- description: `创建时间:${data.create_datetime}`,
- status: 'finish'
- },
- {
- title: '待审批',
- description: `待审批人:${data.approval_records ?
- (() => {
- console.log('approval_records:', data.approval_records); // 调试信息
- const names = data.approval_records
- .map((item:any) => {
- console.log('item:', item, 'approver_name:', item.approver_name); // 调试信息
- // 支持多种字段名
- return item.approver_name || item.app_user_approver_name || item.name;
- })
- .filter(name => name && name.trim()); // 过滤空值和空字符串
- console.log('filtered names:', names); // 调试信息
- return names.join('、') || '暂无待审批人员';
- })()
- : '未知'} 审批`,
- status: data.status >= 2 ? 'finish' : 'process'
- }
- ];
- const approverinfo = data.approver_info ?? data.admin_approver_info
- if (data.status >= 2&&data.status!=3 && data.borrow_type!=1) {
- // 将审批记录倒序排列
- const reversedApprovalRecords = [...data.approval_records].reverse();
- reversedApprovalRecords.forEach((item:any,index:number) => {
- if(item.status === 1){
- if(index === 0){
- steps.value.push({
- title: '审批通过',
- description: `审批人:${item.app_user_approver_name},时 间:${item.approve_time},领取仓库:${getWarehouseName(data.warehouse)||'暂无仓库'}`,
- status: 'finish'
- });
- }else{
- steps.value.push({
- title: '审批通过',
- description: `审批人:${item.approver_name},时 间:${item.create_datetime}`,/* ,领取仓库:${getWarehouseName(data.warehouse)||'暂无仓库'} */
- status: 'finish'
- });
- }
- }
- });
- } else if (data.status === 3) {
- // console.log("data.approver_name:::",data.approver_info.name)
- const rejectNames = data.approval_records
- .filter((item:any) => item.status === 2)
- .map((item:any) => item.approver_name || item.app_user_approver_name || item.name)
- .filter((name:any) => name && name.trim());
- const rejectReason = data.approval_records
- .filter((item:any) => item.status === 2)
- .map((item:any) => item.approve_remark)
- .filter((reason:any) => reason && reason.trim());
- const rejectTime = data.approval_records
- .filter((item:any) => item.status === 2)
- .map((item:any) => item.approve_time)
- .filter((time:any) => time && time.trim());
- steps.value.push({
- title: '审批拒绝',
- description: `审批人:${rejectNames.join('、')},拒绝原因: ${rejectReason.join('、')},时间:${rejectTime.join('、')}`,
- status: 'error'
- });
- }
- if (data.status >= 4 ||data.borrow_type==1) {
- steps.value.push({
- title: '流程完成',
- description: '流程已结束',
- status: 'finish'
- });
- }
- }
- // 处理异常操作
- const handleAbnormal = (index: number) => {
- currentAbnormalIndex.value = index;
- showAbnormalDialog.value = true;
- console.log("showAbnormalDialog:::", showAbnormalDialog.value, "currentAbnormalIndex:::", currentAbnormalIndex.value);
- };
- // 处理异常操作确认
- const onAbnormalConfirm = (data: { condition: string; photos: any[] }) => {
- console.log("异常操作确认数据:", data);
- if (currentAbnormalIndex.value !== -1) {
- const device = returnDeviceList.value[currentAbnormalIndex.value];
- device.condition = data.condition;
- device.photos = data.photos;
- device.damage_type = data.damage_type;
- ElMessage.success('异常信息已保存');
- }
- };
- // 处理查看异常
- const handleViewAbnormal = (index: number) => {
- const device = returnDeviceList.value[index];
- console.log("device:::",device);
- if (device) {
- if(device.problem_records?.length){
- currentAbnormalData.value = {
- damage_type:device.problem_records?.[0].damage_type ||'',
- condition: device.problem_records?.[0].device_condition_after ||'',
- photos: device.problem_records?.[0].returned_images.map((item:any)=>item.image_url) ||[]
- };
- }else{
- currentAbnormalData.value = {
- damage_type: device.damage_type ||'',
- condition: device.condition ||'',
- photos: device.photos ||[]
- };
- }
- showViewAbnormalDialog.value = true;
- }
- };
- // 处理扫码搜索
- const handleScanSearch = async () => {
- if (!searchText.value.trim()) return;
-
- try {
- const res = await deviceApi.GetList({
- page: 1,
- limit: 1,
- code: searchText.value.trim(),
- status: 1
- });
-
- if (res.data && res.data.length > 0) {
- const device = res.data[0];
- if (device.available_quantity <= 0) {
- ElMessage.warning('该设备当前无可用数量');
- return;
- }
-
- // 检查是否已存在
- const existingDevice = deviceList.value.find(d => d.device_no === device.id);
- if (existingDevice) {
- existingDevice.borrow_count++;
- ElMessage.success('设备数量已更新');
- } else {
- // 添加新设备到列表
- deviceList.value.push({
- device_no: device.id,
- device_code: device.device_no,
- device_type: device.category_name,
- device_name: device.name || '',
- borrow_count: 1,
- brand: device.brand || '',
- device_specification: device.specification,
- model: device.model || '',
- warehouse: device.warehouse,
- available_quantity:device.available_quantity
- });
- ElMessage.success('设备已添加到列表');
- }
- } else {
- ElMessage.warning('未找到对应的设备');
- }
- } catch (error) {
- ElMessage.error('搜索设备失败');
- } finally {
- searchText.value = ''; // 清空搜索框
- }
- };
- // 处理归还扫码搜索
- const handleReturnScanSearch = async () => {
- if (!returnSearchText.value.trim()) return;
-
- try {
- const res = await deviceApi.GetList({
- page: 1,
- limit: 1,
- code: returnSearchText.value.trim(),
- status: 1
- });
-
- if (res.data && res.data.length > 0) {
- const device = res.data[0];
-
- // 检查是否已存在
- const existingDeviceIndex = returnDeviceList.value.findIndex(d => d.device_no === device.id);
- if (existingDeviceIndex !== -1) {
- // 如果设备已存在,更新其状态
- returnDeviceList.value[existingDeviceIndex].status = '已归还';
- ElMessage.success(`设备 ${device.category_name} 状态已更新为已归还`);
- } else {
- // 添加新设备到列表
- returnDeviceList.value.push({
- device_no: device.id,
- device_code: device.device_no,
- device_type: device.category_name,
- device_name: device.name || '',
- borrow_count: 1,
- brand: device.brand || '',
- model: device.model || '',
- warehouse: device.warehouse,
- return_status:device.return_status,
- return_time:device.return_times
- });
- console.log("returnDeviceList.value:::",returnDeviceList.value);
- ElMessage.success('设备已添加到列表');
- }
- } else {
- ElMessage.warning('未找到对应的设备');
- }
- } catch (error) {
- ElMessage.error('搜索设备失败');
- } finally {
- returnSearchText.value = ''; // 清空搜索框
- }
- };
- // 异常记录列表数据
- const abnormalList = ref([
- /* {
- borrowNo: '202409002',
- borrower: '张同学',
- time: '2024-09-12 10:21:32',
- type: '逾期'
- },
- {
- borrowNo: '202505013',
- borrower: '张同学',
- time: '2025-05-13 15:12:35',
- type: '损坏'
- } */
- ]);
- /* 归还设备异常记录 */
- const returnAbnormalList = ref([
-
- ]);
- // 附件文件列表
- const attachmentFileList = ref<any[]>([]);
- // 查看异常记录详情
- const handleView = (row: any) => {
- console.log('查看异常记录:', row);
- // 这里可以添加查看详情的逻辑
- };
- // 借用列表相关方法
- const handleAdd = () => {
- showSelectDeviceDialog.value = true;
- };
- const handleRemove = (index: number) => {
- deviceList.value.splice(index, 1);
- };
- const handleReturnRemove = (index: number) => {
- returnDeviceList.value.splice(index, 1);
- };
- // 处理表格多选变化
- const handleSelectionChange = (selection: DeviceListItem[]) => {
- selectedDevices.value = selection;
- };
- // 设备选择处理
- function onDeviceSelected(devices: Device[]) {
- console.log("devices:::",devices,"activeName:::",activeName.value);
- if (activeName.value === 'first') {
- form.value.items.push(
- ...devices.map((d) => ({
- device: d.id,
- device_code: d.code,
- remark: d.category_name,
- quantity: 1,
- location: d.warehouse,
- device_name: d.name,
- device_specification: d.device_specification
- }))
- );
- } else if (activeName.value === 'second') {
- deviceList.value.push(
- ...devices.map(d => ({
- device_no: d.id,
- device_code: d.code,
- device_type: d.category_name,
- device_name: d.name || '',
- borrow_count: 1,
- brand: d.brand || '',
- model: d.model,
- device_specification: d.specification,
- warehouse: d.warehouse,
- available_quantity:d.available_quantity
- }))
- );
- }else if(activeName.value === 'third'){
- // 在添加前检查每个设备是否已存在
- devices.forEach(d => {
- const existingDeviceIndex = returnDeviceList.value.findIndex(item => item.device_no === d.id);
- if (existingDeviceIndex !== -1) {
- // 如果设备已存在,更新其状态
- returnDeviceList.value[existingDeviceIndex].return_status.value = 2;
- returnDeviceList.value[existingDeviceIndex].return_status.label = '已归还';
- returnDeviceList.value[existingDeviceIndex].is_return = true;
- returnDeviceList.value[existingDeviceIndex].return_time = dayjs().format('YYYY-MM-DD HH:mm:ss');
- returnDeviceList.value[existingDeviceIndex].brand = d.brand || '';
- ElMessage.success(`设备 ${d.category_name} 状态已更新为已归还`);
- } else {
- // 如果设备不存在,添加新记录
- /* returnDeviceList.value.push({
- device_no: d.id,
- device_type: d.category_name,
- device_name: d.name || '',
- borrow_count: 1,
- brand: d.brand || '',
- model: d.model || '',
- warehouse: d.warehouse,
- status: '已归还'
- }); */
- /* ElMessage.success(`设备 ${d.category_name} 已添加到归还列表`); */
- }
- });
- }
- }
- // 移除同步相关的 watch
- // const handleClick = (tab: TabsPaneContext, event: Event) => {
- // if (tab.props.name === 'second') {
- // deviceList.value = form.value.items.map(item => ({
- // device_no: item.device,
- // device_type: item.remark,
- // device_name: '',
- // borrow_count: item.quantity,
- // brand: '',
- // model: '',
- // warehouse: item.location
- // }));
- // }
- // }
- function handleClick(tab: TabsPaneContext) {
- console.log('Tab clicked:', tab.props.name);
- }
- function handleUploadSuccess(response: any, file: any, fileList: any) {
- // eslint-disable-next-line no-console
- console.log('上传成功:', file.name);
- }
- function handleUploadError(err: any, file: any, fileList: any) {
- // eslint-disable-next-line no-console
- console.error('上传失败:', file.name);
- }
- // 图片预览处理函数
- const handlePictureCardPreview = (uploadFile: any) => {
- dialogImageUrl.value = uploadFile.url || uploadFile.response?.url || form.value.attachments;
- dialogVisible.value = true;
- };
- // 处理附件删除
- const handleRemoves = (file: any, fileList: any) => {
- // 由于是禁用状态,这里只是示例,实际不会执行删除
- console.log('删除附件:', file.name);
- };
- const form = ref<FormData>({
- borrower_info:{
- user_code:'',
- mobile:''
- },
- application_no: '',
- emergency_contact: '',
- emergency_phone: '',
- app_user_borrower: 1,
- team_type: 0,
- team_members_count: 1,
- team_members: '',
- expected_start_time:'',
- expected_end_time: '',
- borrower_dept: '',
- purpose: '',
- applicant_remark_type: "1",
- applicant_remark: '',
- items: [],
- accessory_info: '',
- borrow_type: 2,
- return_location:'',
- approver_info: {
- name: ''
- }
- });
- const showSelectDeviceDialog = ref(false);
- const rules = {
- emergency_contact: [
- { required: true, message: '请输入借用人', trigger: 'change' },
- ],
- app_user_borrower: [
- { required: true, message: '请输入学号或工号', trigger: 'change' },
- ],
- emergency_phone: [
- { required: true, message: '请输入联系电话', trigger: 'change' },
- ],
- /* borrower_dept: [
- { required: true, message: '请输入借用部门', trigger: 'change' },
- ], */
- expected_end_time: [
- { required: true, message: '请输选择归还时间', trigger: 'change' },
- ],
- team_type: [
- { required: true, message: '请选择个人或者团队', trigger: 'change' },
- ],
- purpose: [
- { required: true, message: '请输入借用原因', trigger: 'change' },
- ],
- applicant_remark_type: [
- { required: true, message: '请选择审批人', trigger: 'change' },
- ],
- applicant_remark: [
- { required: false, message: '请输入备注', trigger: 'change' },
- ],
- };
- // 自动填充用户信息
- onMounted(() => {
- loadWarehouses()
- getAdminList()
- getAllUserList()
- try {
- const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
- if (userInfo) {
- form.value.emergency_contact = userInfo.username || '';
- form.value.app_user_borrower = Number(userInfo.dept_info?.dept_id )|| 1;
- form.value.emergency_phone = userInfo.mobile || '';
- form.value.borrower_dept = userInfo.dept_info?.dept_name || '';
- }
- } catch (e) {
- /* empty */
- }
- });
- watch(
- () => props.visible,
- (v) => (visible.value = v)
- );
- watch(() => props.modelValue, async (val) => {
- if (val && val.id) {
- try {
- const res = await api.GetApplicationDetail(val.id);
- console.log("res:::::",res)
- if (res.code === 2000 && res.data) {
- const data = res.data;
- Object.assign(form.value, data);
- buildSteps(data);
- // 领取模式下不回显历史配件内容
- if (isCollect.value) {
- collectAccessories.value = '';
- }
- timeline.value.create = data.create_datetime || '';
- timeline.value.approve = data.approve_time || '';
- const approverinfo = data.approver_info ?? data.admin_approver_info
- timeline.value.approver = approverinfo?.name || '审批人'
- // timeline.value.approver = data.admin_approver_info?.name || '审批人';
- // console.log("data:::",form.value);
- // activeStep.value = 1; // 创建
- // if (data.status >= 1) activeStep.value = 2; // 待审批
- // if (data.status >= 2) activeStep.value = 3; // 审批通过
- // if (data.status >= 3) activeStep.value = 4; // 完成
- // 同步 form.items 到 returnDeviceList
- if (form.value.items && form.value.items.length > 0) {
- returnDeviceList.value = form.value.items
- .filter(item => item.device !== null)
- .map(item => ({
- device_no: item.device,
- device_code: item.device_code,
- device_type: item.remark,
- device_name: item.device_name,
- borrow_count: item.quantity,
- brand: item.brand || '',
- model: item.device_specification,
- warehouse: item.location,
- problem_records: item.problem_records,
- /* status: '未归还' */
- return_status:item.return_status,
- return_time:item.return_times
- }));
- }
- // 同步 form.records 到 returnAbnormalList
- if (form.value.records && form.value.records.length > 0) {
- // 添加损坏类型记录
- const damageRecord: AbnormalRecord = {
- application_no: form.value.application_no,
- operator_name: form.value.app_user_borrower?.name||form.value.external_borrower_name||'',
- user_code: form.value.borrower_info?.user_code || form.value.app_user_borrower?.user_code||'',
- emergency_phone: form.value.external_borrower_phone || form.value.app_user_borrower?.mobile||'',
- type: '损坏',
- condition: form.value.borrower_damage_count || 0,
- create_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
- };
- // 添加逾期类型记录
- const overdueRecord: AbnormalRecord = {
- application_no: form.value.application_no,
- operator_name: form.value.app_user_borrower?.name||form.value.external_borrower_name||'',
- user_code: form.value.borrower_info?.user_code || form.value.app_user_borrower?.user_code||'',
- emergency_phone: form.value.external_borrower_phone || form.value.app_user_borrower?.mobile||'',
- type: '逾期',
- condition: form.value.borrower_overdue_count || 0, // 逾期数量设为1
- create_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
- };
- returnAbnormalList.value = [damageRecord, overdueRecord];
- abnormalList.value = [damageRecord, overdueRecord];
- }
-
- // 处理附件回显
- if (data.attachments) {
- if (typeof data.attachments === 'string') {
- // 如果attachments是字符串URL
- attachmentFileList.value = [{
- name: data.attachments.split('/').pop() || '附件',
- url: data.attachments,
- status: 'success'
- }];
- } else if (Array.isArray(data.attachments)) {
- // 如果attachments是数组
- attachmentFileList.value = data.attachments.map((item: any, index: number) => {
- if (typeof item === 'string') {
- return {
- name: item.split('/').pop() || `附件${index + 1}`,
- url: item,
- status: 'success'
- };
- } else if (typeof item === 'object' && item.url) {
- return {
- name: item.name || item.url.split('/').pop() || `附件${index + 1}`,
- url: item.url,
- status: 'success'
- };
- }
- return null;
- }).filter(Boolean);
- }
- }
- }
- } catch (e) {
- console.log("审判失败:::",e)
- ElMessage.error('获取审批信息失败');
- }
- }else if(val&& isEdit.value){
- try {
- const res = await api.GetApplicationDetail(val.id);
- if (res.code === 2000 && res.data) {
- const data = res.data;
- Object.assign(form.value, data);
- // 同步 form.items 到 returnDeviceList
- if (form.value.items && form.value.items.length > 0) {
- returnDeviceList.value = form.value.items
- .filter(item => item.device !== null)
- .map(item => ({
- device_no: item.device,
- device_type: item.remark,
- device_name: item.device_name,
- borrow_count: item.quantity,
- brand: item.brand || '',
- model: item.device_specification,
- warehouse: item.location,
- problem_records: item.problem_records,
- return_status:item.return_status,
- return_time:item.return_times
- }));
- }
-
- // 处理附件回显 (编辑模式)
- if (data.attachments) {
- if (typeof data.attachments === 'string') {
- attachmentFileList.value = [{
- name: data.attachments.split('/').pop() || '附件',
- url: data.attachments,
- status: 'success'
- }];
- } else if (Array.isArray(data.attachments)) {
- attachmentFileList.value = data.attachments.map((item: any, index: number) => {
- if (typeof item === 'string') {
- return {
- name: item.split('/').pop() || `附件${index + 1}`,
- url: item,
- status: 'success'
- };
- } else if (typeof item === 'object' && item.url) {
- return {
- name: item.name || item.url.split('/').pop() || `附件${index + 1}`,
- url: item.url,
- status: 'success'
- };
- }
- return null;
- }).filter(Boolean);
- }
- }
- }
- } catch (e) {
- ElMessage.error('获取审批信息失败');
- }
- }
- }, { immediate: true });
- // watch(
- // () => props.modelValue,
- // (v) => {
- // if (v) {
- // // eslint-disable-next-line no-console
- // console.log("val:::::",v);
- // Object.assign(form.value, v);
- // }
- // }, { immediate: true }
- // );
- // 监听借用人选择变化
- watch(() => form.value.app_user_borrower, (newValue) => {
- if (newValue && allUserList.value.length > 0) {
- const selectedUser = allUserList.value.find(user => user.id === newValue);
- if (selectedUser) {
- form.value.user_code = selectedUser.user_code || '';
- form.value.mobile = selectedUser.mobile || '';
- }
- }
- });
- function addItem() {
- showSelectDeviceDialog.value = true;
- }
- function removeItem(index: number) {
- form.value.items.splice(index, 1);
- }
- function onCancel() {
- // 重置标签页到第一个
- activeName.value = 'first';
- // 清理异常记录列表
- returnAbnormalList.value = [];
- abnormalList.value = [];
- // 清理设备列表
- deviceList.value = [];
- returnDeviceList.value = [];
- // 清理搜索框
- searchText.value = '';
- returnSearchText.value = '';
- // 清理备注
- remark.value = '';
- // 清理领取模式配件信息
- collectAccessories.value = '';
- returnRemark.value = '';
- // 重置状态
- returnStatus.value = '未归还';
- // 清理选中的设备
- selectedDevices.value = [];
- // 清理附件文件列表
- attachmentFileList.value = [];
- // 关闭所有对话框
- showSelectDeviceDialog.value = false;
- showSettlementDialog.value = false;
- showAbnormalDialog.value = false;
- showViewAbnormalDialog.value = false;
- // 重置当前异常数据
- currentAbnormalData.value = {
- damage_type: 0,
- condition: '',
- photos: []
- };
- // 发出关闭事件
- emit('update:visible', false);
- }
- // 提交时合并数据
- function onSubmit() {
- if(isCollect.value){
- // 验证是否有设备信息
- const hasDevicesInFirstTab = form.value.items && form.value.items.length > 0;
- const hasDevicesInSecondTab = deviceList.value && deviceList.value.length > 0;
-
- if (!hasDevicesInFirstTab && !hasDevicesInSecondTab) {
- ElMessage.warning('请添加设备信息后再提交');
- activeName.value = 'second'; // 自动切换到借用列表标签页
- return;
- }
- // 验证设备数量
- const hasInvalidQuantityInFirstTab = form.value.items.some(item => !item.quantity || item.quantity <= 0);
- const hasInvalidQuantityInSecondTab = deviceList.value.some(item => !item.borrow_count || item.borrow_count <= 0);
- if (hasInvalidQuantityInFirstTab || hasInvalidQuantityInSecondTab) {
- ElMessage.warning('请确保所有设备的数量大于0');
- activeName.value = 'second'; // 自动切换到借用列表标签页
- return;
- }
- // 合并两个标签页的设备数据
- const allDevices = [
- ...deviceList.value.map(item => ({
- condition: remark.value,
- quantity: item.borrow_count,
- device_id: Number(item.device_no) || 0
- }))
- ];
-
- const submitData = {
- id:form.value.id,
- item_id:form.value.id,
- device_assignments: allDevices,
- remark:remark.value,
- accessories: collectAccessories.value,
- };
- CollectEquipment(submitData).then((res: ApiResponse) => {
- if(res.code===2000){
- ElMessage.success("领取成功");
- // 准备结算单数据
- settlementData.value = {
- ...form.value,
- items: deviceList.value.map(item => ({
- ...item,
- device_category_name: item.device_type,
- device_name: item.device_name,
- device_specification: item.device_specification,
- device_storage_location: item.warehouse,
- remark: item.device_type,
- quantity: item.borrow_count,
- device_id: item.device_no,
- device_category: item.device_type,
- device_code: item.device_no,
- borrow_type: form.value.borrow_type,
- borrower_dept: form.value.borrower_dept,
- emergency_contact: form.value.emergency_contact,
- emergency_phone: form.value.emergency_phone,
- team_type: form.value.team_type,
- })),
- accessory_info: accessoryInfo.value,
- remark: remark.value,
- expected_start_time: dayjs().format('YYYY-MM-DD HH:mm:ss')
- };
-
- // 先触发提交事件进行页面刷新
- emit('submit');
-
- // 关闭当前对话框
- emit('update:visible', false);
-
- // 使用 nextTick 确保在 DOM 更新后再显示结算单
- nextTick(() => {
- borrowForm.value = {...settlementData.value,mode: 'settlement' };
- showSettlementDialog.value = true;
- });
- }
- });
- } else {
- // 归还逻辑修改
- // 使用所有设备列表而不是选中的设备
- const allDevices = returnDeviceList.value
- .filter(item => item.is_return === true) // 只选择 return_status 为 2 的设备
- .map(item => ({
- device: item.device_no,
- quantity: item.borrow_count,
- remark: returnRemark.value,
- device_id: Number(item.device_no) || 0,
- // 添加异常相关字段
- condition: item.condition, // 异常说明
- damage_type:item.damage_type,
- photo_urls: item.photos || [], // 异常照片
- }));
-
- const submitData = {
- id: form.value.id,
- items: allDevices,
- status: returnStatus.value,
- accessories: form.value.accessories,
- };
-
- ReturnEquipment(submitData).then(async (res: ApiResponse) => {
- if(res.code===2000){
- ElMessage.success("归还成功");
- try {
- if (form.value.id) {
- const detailRes = await api.GetApplicationDetail(form.value.id);
- if (detailRes.code === 2000 && detailRes.data) {
- returnStatus.value = detailRes.data.status_label || returnStatus.value;
- }
- }
- } catch (e) {
- ElMessage.error('获取最新状态失败');
- }
- emit('submit');
- emit('update:visible', false);
- }
- });
- }
- }
- function clickReturn(){
- returnStatus.value = '已归还';
- // 自动选择所有设备
- const tableRef = document.querySelector('.el-table__header-wrapper th.el-table__cell.is-leaf .el-checkbox');
- if (tableRef) {
- (tableRef as HTMLElement).click();
- }
- }
- /* formRef.value.validate((valid: boolean) => {
- if (valid) {
- form.value.items = form.value.items.map(item => ({
- ...item,
- quantity: Number(item.quantity) || 0
- }));
- const firstLocation = form.value.items[0]?.location || '';
- form.value.return_location = firstLocation;
- form.value.expected_start_time = now;
- form.value.expected_end_time = dayjs(form.value.expected_end_time).format('YYYY-MM-DD HH:mm:ss')|| now;
- form.team_members_count=Number(form.team_members_count)||1;
- emit('submit', { ...form.value });
- emit('update:visible', false);
- ElMessage.success("添加成功!");
- }
- }); */
-
- </script>
- <style>
- .avatar-uploader .el-upload {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- }
- .avatar-uploader .el-upload:hover {
- border-color: #409EFF;
- }
- .avatar-uploader-icon {
- font-size: 28px;
- color: #8c939d;
- width: 178px;
- height: 178px;
- line-height: 178px;
- text-align: center;
- }
- .avatar {
- width: 178px;
- height: 178px;
- display: block;
- }
- </style>
|