index.vue 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. <template>
  2. <div class="p-2 inspection-task-page">
  3. <!-- 顶部数据卡片 -->
  4. <el-row :gutter="20" class="mb-2">
  5. <el-col :span="6">
  6. <el-card shadow="hover" class="stat-card">
  7. <div class="stat-card-content">
  8. <div class="stat-info">
  9. <div class="stat-title">今日应打卡</div>
  10. <div class="stat-value">{{ stats.todayShould || 0 }}</div>
  11. </div>
  12. <div class="stat-icon stat-icon-blue">
  13. <el-icon><Calendar /></el-icon>
  14. </div>
  15. </div>
  16. </el-card>
  17. </el-col>
  18. <el-col :span="6">
  19. <el-card shadow="hover" class="stat-card">
  20. <div class="stat-card-content">
  21. <div class="stat-info">
  22. <div class="stat-title">今日已打卡</div>
  23. <div class="stat-value">{{ stats.todayChecked || 0 }}</div>
  24. </div>
  25. <div class="stat-icon stat-icon-green">
  26. <el-icon><Check /></el-icon>
  27. </div>
  28. </div>
  29. </el-card>
  30. </el-col>
  31. <el-col :span="6">
  32. <el-card shadow="hover" class="stat-card">
  33. <div class="stat-card-content">
  34. <div class="stat-info">
  35. <div class="stat-title">异常打卡</div>
  36. <div class="stat-value">{{ stats.abnormal || 0 }}</div>
  37. </div>
  38. <div class="stat-icon stat-icon-orange">
  39. <el-icon><Warning /></el-icon>
  40. </div>
  41. </div>
  42. </el-card>
  43. </el-col>
  44. <el-col :span="6">
  45. <el-card shadow="hover" class="stat-card">
  46. <div class="stat-card-content">
  47. <div class="stat-info">
  48. <div class="stat-title">未打卡</div>
  49. <div class="stat-value">{{ stats.unchecked || 0 }}</div>
  50. </div>
  51. <div class="stat-icon stat-icon-red">
  52. <el-icon><Clock /></el-icon>
  53. </div>
  54. </div>
  55. </el-card>
  56. </el-col>
  57. </el-row>
  58. <!-- 搜索区域 -->
  59. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  60. <div v-show="showSearch" class="mb-[10px]">
  61. <el-card shadow="hover">
  62. <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="80">
  63. <el-form-item label="任务名称" prop="taskName">
  64. <el-input v-model="queryParams.taskName" placeholder="请输入任务名称" clearable style="width: 200px" @keyup.enter="handleQuery" />
  65. </el-form-item>
  66. <el-form-item label="巡检类型" prop="taskType">
  67. <el-select v-model="queryParams.taskType" placeholder="全部" clearable style="width: 180px">
  68. <el-option v-for="dict in inspection_type_dict" :key="dict.value" :label="dict.label" :value="dict.value" />
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="门店" prop="storeName">
  72. <el-input v-model="queryParams.storeName" placeholder="请输入门店" clearable style="width: 180px" @keyup.enter="handleQuery" />
  73. </el-form-item>
  74. <el-form-item label="打卡状态" prop="recordStatus">
  75. <el-select v-model="queryParams.recordStatus" placeholder="全部" clearable style="width: 180px">
  76. <el-option v-for="dict in inspection_status_dict" :key="dict.value" :label="dict.label" :value="dict.value" />
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item label="打卡结果" prop="checkResult">
  80. <el-select v-model="queryParams.checkResult" placeholder="全部" clearable style="width: 180px">
  81. <el-option v-for="dict in inspection_result_dict" :key="dict.value" :label="dict.label" :value="dict.value" />
  82. </el-select>
  83. </el-form-item>
  84. <el-form-item>
  85. <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
  86. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  87. </el-form-item>
  88. </el-form>
  89. </el-card>
  90. </div>
  91. </transition>
  92. <!-- 数据表格区域 -->
  93. <el-card shadow="hover" class="list-card">
  94. <div class="list-toolbar">
  95. <span class="list-total">共 {{ total }} 条记录</span>
  96. <div class="toolbar-actions">
  97. <el-button type="primary" plain icon="Plus" @click="handleAdd">新增巡检打卡</el-button>
  98. <right-toolbar v-model:show-search="showSearch" @query-table="getList" style="margin-left: 8px;" />
  99. </div>
  100. </div>
  101. <el-table v-loading="loading" :data="taskList" border>
  102. <el-table-column label="巡检任务名称" align="center" prop="taskName" :show-overflow-tooltip="true" />
  103. <el-table-column label="巡检类型" align="center" prop="taskType" width="160" :show-overflow-tooltip="true" />
  104. <el-table-column label="打卡方式" align="center" prop="checkMethod" width="100">
  105. <template #default="scope">
  106. <el-tag :type="getMethodTag(scope.row.checkMethod)">{{ scope.row.checkMethod || '常规' }}</el-tag>
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="门店" align="center" prop="storeName" width="140" :show-overflow-tooltip="true" />
  110. <el-table-column label="打卡地点" align="center" prop="location" width="160" :show-overflow-tooltip="true" />
  111. <el-table-column label="责任人" align="center" prop="inspectorName" width="100" />
  112. <el-table-column label="打卡状态" align="center" prop="recordStatus" width="100">
  113. <template #default="scope">
  114. <el-tag :type="getStatusTag(scope.row.recordStatus)">{{ scope.row.recordStatus || '未打卡' }}</el-tag>
  115. </template>
  116. </el-table-column>
  117. <el-table-column label="打卡结果" align="center" prop="checkResult" width="100">
  118. <template #default="scope">
  119. <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ scope.row.checkResult }}</el-tag>
  120. <span v-else>-</span>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="操作" fixed="right" align="center" width="240" class-name="small-padding fixed-width">
  124. <template #default="scope">
  125. <el-button link type="primary" icon="Document" @click="handleViewRecords(scope.row)">打卡记录</el-button>
  126. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">编辑</el-button>
  127. <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
  132. </el-card>
  133. <!-- 新增/编辑对话框 -->
  134. <el-dialog v-model="dialog.visible" :title="dialog.title" width="900px" append-to-body @close="closeDialog">
  135. <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
  136. <el-row :gutter="20">
  137. <el-col :span="12">
  138. <el-form-item label="任务名称" prop="taskName">
  139. <el-input v-model="form.taskName" placeholder="请输入巡检任务名称" maxlength="100" />
  140. </el-form-item>
  141. </el-col>
  142. <el-col :span="12">
  143. <el-form-item label="巡检类型" prop="taskType">
  144. <el-select v-model="form.taskType" placeholder="请选择巡检类型" style="width: 100%">
  145. <el-option v-for="dict in inspection_type_dict" :key="dict.value" :label="dict.label" :value="dict.value" />
  146. </el-select>
  147. </el-form-item>
  148. </el-col>
  149. </el-row>
  150. <el-row :gutter="20">
  151. <el-col :span="12">
  152. <el-form-item label="门店" prop="storeName">
  153. <el-input v-model="form.storeName" placeholder="请输入门店/总部名称" maxlength="100" />
  154. </el-form-item>
  155. </el-col>
  156. <el-col :span="12">
  157. <el-form-item label="位置区域" prop="location">
  158. <el-input v-model="form.location" placeholder="巡检点物理名称(如XX车间XX工位)" maxlength="200" />
  159. </el-form-item>
  160. </el-col>
  161. </el-row>
  162. <el-row :gutter="20">
  163. <el-col :span="12">
  164. <el-form-item label="巡检周期" prop="cycle">
  165. <el-select v-model="form.cycle" placeholder="请选择巡检周期" style="width: 100%" @change="onCycleChange">
  166. <el-option v-for="dict in inspection_cycle_dict" :key="dict.value" :label="dict.label" :value="dict.value" />
  167. </el-select>
  168. </el-form-item>
  169. </el-col>
  170. <el-col :span="12">
  171. <el-form-item label="开启扫码打卡" prop="scanEnabled">
  172. <el-switch v-model="form.scanEnabled" active-text="是" inactive-text="否" @change="onScanChange" />
  173. </el-form-item>
  174. </el-col>
  175. <el-col v-if="form.scanEnabled" :span="12">
  176. <el-form-item label="打卡设备编码" prop="punchDeviceCode">
  177. <el-input
  178. v-model="form.punchDeviceCode"
  179. placeholder="请输入巡检点设备编码(与现场二维码一致)"
  180. maxlength="200"
  181. show-word-limit
  182. />
  183. </el-form-item>
  184. </el-col>
  185. </el-row>
  186. <el-row :gutter="20">
  187. <el-col :span="12">
  188. <el-form-item label="纬度" prop="lat">
  189. <el-input-number v-model="form.lat" :precision="6" :min="-90" :max="90" controls-position="right" style="width: 100%" />
  190. </el-form-item>
  191. </el-col>
  192. <el-col :span="12">
  193. <el-form-item label="经度" prop="lng">
  194. <el-input-number v-model="form.lng" :precision="6" :min="-180" :max="180" controls-position="right" style="width: 100%" />
  195. </el-form-item>
  196. </el-col>
  197. </el-row>
  198. <!-- 巡检时间:根据周期动态适配 -->
  199. <el-form-item label="巡检时间" prop="timeConfig">
  200. <div v-if="form.cycle === '每日' || !form.cycle">
  201. <el-tag v-for="(t, idx) in timeSlotList" :key="idx" closable @close="removeTimeSlot(idx)" style="margin-right: 8px">
  202. {{ t }}
  203. </el-tag>
  204. <el-button size="small" type="primary" plain @click="openAddTimeSlot">添加时间段</el-button>
  205. </div>
  206. <div v-else-if="form.cycle === '每周'">
  207. <el-checkbox-group v-model="weekDayList">
  208. <el-checkbox v-for="d in weekDayOptions" :key="d.value" :label="d.value">{{ d.label }}</el-checkbox>
  209. </el-checkbox-group>
  210. </div>
  211. <div v-else-if="form.cycle === '每月'">
  212. <el-select v-model="monthDayList" multiple placeholder="选择执行日期" style="width: 100%">
  213. <el-option v-for="d in 31" :key="d" :label="`${d}号`" :value="d" />
  214. </el-select>
  215. </div>
  216. </el-form-item>
  217. <el-row :gutter="20">
  218. <el-col :span="12">
  219. <el-form-item label="责任人" prop="inspectorId">
  220. <el-select
  221. v-model="form.inspectorId"
  222. placeholder="请选择责任人(本部门及下级部门)"
  223. style="width: 100%"
  224. filterable
  225. clearable
  226. @change="onInspectorChange"
  227. >
  228. <el-option v-for="u in deptChainUserOptions" :key="String(u.userId)" :label="u.nickName" :value="u.userId" />
  229. </el-select>
  230. </el-form-item>
  231. </el-col>
  232. <el-col :span="12">
  233. <el-form-item label="审核人" prop="auditorId">
  234. <el-select
  235. v-model="form.auditorId"
  236. placeholder="请选择审核人(本部门及下级部门)"
  237. style="width: 100%"
  238. filterable
  239. clearable
  240. @change="onAuditorChange"
  241. >
  242. <el-option v-for="u in deptChainUserOptions" :key="String(u.userId)" :label="u.nickName" :value="u.userId" />
  243. </el-select>
  244. </el-form-item>
  245. </el-col>
  246. </el-row>
  247. <!-- 打卡项目:多行 -->
  248. <el-divider content-position="left">
  249. <span style="font-weight: bold">打卡项目</span>
  250. <el-button link type="primary" icon="Plus" @click="addInspectionItem">添加项目</el-button>
  251. </el-divider>
  252. <el-table :data="form.itemList" border>
  253. <el-table-column label="序号" align="center" width="60">
  254. <template #default="scope">{{ scope.$index + 1 }}</template>
  255. </el-table-column>
  256. <el-table-column label="项目大类" align="center" width="160">
  257. <template #default="scope">
  258. <el-select v-model="scope.row.itemType" placeholder="请选择" size="small" style="width: 100%">
  259. <el-option v-for="dict in inspection_item_type_dict" :key="dict.value" :label="dict.label" :value="dict.value" />
  260. </el-select>
  261. </template>
  262. </el-table-column>
  263. <el-table-column label="巡检内容" align="center">
  264. <template #default="scope">
  265. <el-input v-model="scope.row.itemContent" placeholder="请输入巡检内容" size="small" />
  266. </template>
  267. </el-table-column>
  268. <el-table-column label="巡检标准" align="center">
  269. <template #default="scope">
  270. <el-input v-model="scope.row.itemStandard" placeholder="请输入巡检标准" size="small" />
  271. </template>
  272. </el-table-column>
  273. <el-table-column label="是否拍照" align="center" width="80">
  274. <template #default="scope">
  275. <el-switch v-model="scope.row.needPhoto" />
  276. </template>
  277. </el-table-column>
  278. <el-table-column label="操作" align="center" width="80">
  279. <template #default="scope">
  280. <el-button link type="danger" size="small" icon="Delete" @click="removeInspectionItem(scope.$index)">删除</el-button>
  281. </template>
  282. </el-table-column>
  283. </el-table>
  284. </el-form>
  285. <template #footer>
  286. <div class="dialog-footer">
  287. <el-button type="primary" @click="submitForm">保存巡检任务</el-button>
  288. <el-button @click="cancel">取 消</el-button>
  289. </div>
  290. </template>
  291. </el-dialog>
  292. <!-- 添加时间段弹窗 -->
  293. <el-dialog v-model="timeSlotDialog.visible" title="添加时间段" width="420px" append-to-body>
  294. <el-form label-width="80px">
  295. <el-form-item label="开始时间">
  296. <el-time-picker v-model="timeSlotForm.start" placeholder="开始时间" value-format="HH:mm" format="HH:mm" style="width: 100%" />
  297. </el-form-item>
  298. <el-form-item label="结束时间">
  299. <el-time-picker v-model="timeSlotForm.end" placeholder="结束时间" value-format="HH:mm" format="HH:mm" style="width: 100%" />
  300. </el-form-item>
  301. </el-form>
  302. <template #footer>
  303. <el-button @click="timeSlotDialog.visible = false">取消</el-button>
  304. <el-button type="primary" @click="confirmAddTimeSlot">确定</el-button>
  305. </template>
  306. </el-dialog>
  307. <!-- 打卡记录对话框 -->
  308. <el-dialog v-model="recordDialog.visible" title="打卡记录" width="900px" append-to-body>
  309. <el-table v-loading="recordLoading" :data="recordList" border>
  310. <el-table-column label="打卡时间" align="center" prop="checkInTime" width="180" />
  311. <el-table-column label="打卡人" align="center" prop="inspectorName" width="100" />
  312. <el-table-column label="打卡地点" align="center" prop="checkInLocation" :show-overflow-tooltip="true" />
  313. <el-table-column label="问题数" align="center" prop="problemCount" width="80" />
  314. <el-table-column label="总数" align="center" prop="totalCount" width="80" />
  315. <el-table-column label="打卡状态" align="center" width="100">
  316. <template #default="scope">
  317. <el-tag :type="getStatusTag(scope.row.recordStatus)">{{ scope.row.recordStatus }}</el-tag>
  318. </template>
  319. </el-table-column>
  320. <el-table-column label="打卡结果" align="center" width="100">
  321. <template #default="scope">
  322. <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ scope.row.checkResult }}</el-tag>
  323. <span v-else>-</span>
  324. </template>
  325. </el-table-column>
  326. <el-table-column label="审核状态" align="center" prop="auditStatus" width="100">
  327. <template #default="scope">
  328. <el-tag v-if="scope.row.auditStatus" :type="getAuditStatusTag(scope.row.auditStatus)">{{ scope.row.auditStatus }}</el-tag>
  329. <span v-else>-</span>
  330. </template>
  331. </el-table-column>
  332. <el-table-column label="操作" align="center" width="180" fixed="right">
  333. <template #default="scope">
  334. <el-button link type="primary" @click="handleViewDetail(scope.row)">查看详情</el-button>
  335. <el-button
  336. v-if="!scope.row.auditStatus || scope.row.auditStatus === '待审核'"
  337. v-hasPermi="['risk:inspectionRecord:review']"
  338. link
  339. type="primary"
  340. @click="handleAuditRecord(scope.row)"
  341. >审核</el-button>
  342. </template>
  343. </el-table-column>
  344. </el-table>
  345. <template #footer>
  346. <el-button @click="recordDialog.visible = false">关 闭</el-button>
  347. </template>
  348. </el-dialog>
  349. <!-- 打卡详情对话框 -->
  350. <el-dialog v-model="detailDialog.visible" title="打卡详情" width="700px" append-to-body>
  351. <el-descriptions :column="1" border>
  352. <el-descriptions-item label="任务名称">{{ detailForm.taskName }}</el-descriptions-item>
  353. <el-descriptions-item label="打卡时间">{{ detailForm.checkInTime }}</el-descriptions-item>
  354. <el-descriptions-item label="打卡人">{{ detailForm.inspectorName }}</el-descriptions-item>
  355. <el-descriptions-item label="打卡状态">
  356. <el-tag :type="getStatusTag(detailForm.recordStatus)">{{ detailForm.recordStatus }}</el-tag>
  357. </el-descriptions-item>
  358. <el-descriptions-item label="打卡结果">
  359. <el-tag v-if="detailForm.checkResult" :type="getResultTag(detailForm.checkResult)">{{ detailForm.checkResult }}</el-tag>
  360. <span v-else>-</span>
  361. </el-descriptions-item>
  362. <el-descriptions-item label="打卡地点">{{ detailForm.checkInLocation }}</el-descriptions-item>
  363. <el-descriptions-item label="问题数/总数">{{ detailForm.problemCount || 0 }}/{{ detailForm.totalCount || 0 }}</el-descriptions-item>
  364. <el-descriptions-item label="审核状态">
  365. <el-tag v-if="detailForm.auditStatus" :type="getAuditStatusTag(detailForm.auditStatus)">{{ detailForm.auditStatus }}</el-tag>
  366. <span v-else>-</span>
  367. </el-descriptions-item>
  368. <el-descriptions-item v-if="detailForm.auditorName" label="审核人">{{ detailForm.auditorName }} ({{ detailForm.auditTime || '-' }})</el-descriptions-item>
  369. <el-descriptions-item v-if="detailForm.auditOpinion" label="审核意见" :span="1">
  370. <span :class="['audit-opinion', detailForm.auditStatus === '审核不通过' ? 'reject' : 'pass']">
  371. {{ detailForm.auditOpinion }}
  372. </span>
  373. </el-descriptions-item>
  374. </el-descriptions>
  375. <h4 style="margin: 16px 0 8px">巡检项目明细</h4>
  376. <el-table :data="detailForm.itemList" border size="small">
  377. <el-table-column label="项目大类" prop="itemType" width="120" />
  378. <el-table-column label="巡检内容" prop="itemContent" />
  379. <el-table-column label="巡检结果" prop="checkResult" width="100">
  380. <template #default="scope">
  381. <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)" size="small">{{ scope.row.checkResult }}</el-tag>
  382. <span v-else>-</span>
  383. </template>
  384. </el-table-column>
  385. <el-table-column label="照片" width="80">
  386. <template #default="scope">
  387. <span v-if="scope.row.checkPhotos">{{ scope.row.checkPhotos }}</span>
  388. <span v-else>-</span>
  389. </template>
  390. </el-table-column>
  391. </el-table>
  392. <template #footer>
  393. <el-button @click="detailDialog.visible = false">关 闭</el-button>
  394. </template>
  395. </el-dialog>
  396. <!-- 审核弹窗 -->
  397. <el-dialog
  398. v-model="auditDialog.visible"
  399. title="巡检打卡审核"
  400. width="520px"
  401. append-to-body
  402. :close-on-click-modal="false"
  403. @close="closeAuditDialog"
  404. >
  405. <el-form ref="auditFormRef" :model="auditForm" :rules="auditRules" label-width="100px">
  406. <el-form-item label="任务名称">
  407. <span class="readonly-text">{{ auditForm.taskName }}</span>
  408. </el-form-item>
  409. <el-form-item label="打卡人">
  410. <span class="readonly-text">{{ auditForm.inspectorName }}</span>
  411. </el-form-item>
  412. <el-form-item label="打卡时间">
  413. <span class="readonly-text">{{ auditForm.checkInTime }}</span>
  414. </el-form-item>
  415. <el-form-item label="审核结果" prop="auditStatus">
  416. <el-radio-group v-model="auditForm.auditStatus">
  417. <el-radio value="审核通过">通过</el-radio>
  418. <el-radio value="审核不通过">不通过</el-radio>
  419. </el-radio-group>
  420. </el-form-item>
  421. <el-form-item v-if="auditForm.auditStatus === '审核不通过'" label="不通过原因" prop="auditOpinion">
  422. <el-input
  423. v-model="auditForm.auditOpinion"
  424. type="textarea"
  425. :rows="4"
  426. placeholder="请输入不通过原因"
  427. maxlength="500"
  428. show-word-limit
  429. />
  430. </el-form-item>
  431. </el-form>
  432. <template #footer>
  433. <div class="dialog-footer">
  434. <el-button @click="cancelAudit">取消</el-button>
  435. <el-button v-hasPermi="['risk:inspectionRecord:review']" type="primary" @click="submitAudit">确认审核</el-button>
  436. </div>
  437. </template>
  438. </el-dialog>
  439. </div>
  440. </template>
  441. <script setup name="InspectionTask" lang="ts">
  442. import { ref, reactive, toRefs, onMounted, getCurrentInstance } from 'vue';
  443. import {
  444. listInspectionTask,
  445. getInspectionTask,
  446. addInspectionTask,
  447. updateInspectionTask,
  448. delInspectionTask,
  449. getInspectionStats,
  450. listInspectionRecordByTask
  451. } from '@/api/risk/inspectionTask';
  452. import { listInspectionItemByTask } from '@/api/risk/inspectionItem';
  453. import { auditInspectionRecord, listInspectionRecordItemByRecord } from '@/api/risk/inspectionRecord';
  454. import type {
  455. RiskInspectionTaskBo,
  456. RiskInspectionTaskVo,
  457. RiskInspectionItemVo,
  458. RiskInspectionRecordVo,
  459. RiskInspectionRecordBo,
  460. RiskInspectionRecordItemVo,
  461. InspectionStatsVo
  462. } from '@/api/risk/types';
  463. import { listByCurrentDeptChainUsers } from '@/api/system/user';
  464. import type { UserVO } from '@/api/system/user/types';
  465. import { FormInstance } from 'element-plus';
  466. import type { ComponentInternalInstance } from 'vue';
  467. import { Calendar, Check, Warning, Clock } from '@element-plus/icons-vue';
  468. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  469. interface InspectionItemForm {
  470. id?: number;
  471. itemType: string;
  472. itemContent: string;
  473. itemStandard: string;
  474. needPhoto: boolean;
  475. }
  476. const taskList = ref<RiskInspectionTaskVo[]>([]);
  477. const loading = ref(true);
  478. const showSearch = ref(true);
  479. const total = ref(0);
  480. const queryFormRef = ref<FormInstance>();
  481. const formRef = ref<FormInstance>();
  482. const recordList = ref<RiskInspectionRecordVo[]>([]);
  483. const recordLoading = ref(false);
  484. // 责任人/审核人选择器数据(当前登录用户所在部门及所有下级部门用户)
  485. const deptChainUserOptions = ref<UserVO[]>([]);
  486. // 字典
  487. const {
  488. risk_inspection_type: inspection_type_dict,
  489. risk_inspection_method: inspection_method_dict,
  490. risk_inspection_status: inspection_status_dict,
  491. risk_inspection_result: inspection_result_dict,
  492. risk_inspection_item_type: inspection_item_type_dict,
  493. risk_inspection_cycle: inspection_cycle_dict
  494. } = toRefs<any>(
  495. proxy?.useDict(
  496. 'risk_inspection_type',
  497. 'risk_inspection_method',
  498. 'risk_inspection_status',
  499. 'risk_inspection_result',
  500. 'risk_inspection_item_type',
  501. 'risk_inspection_cycle'
  502. )
  503. );
  504. // 统计
  505. const stats = ref<InspectionStatsVo>({
  506. todayShould: 0,
  507. todayChecked: 0,
  508. abnormal: 0,
  509. unchecked: 0
  510. });
  511. // 时间配置
  512. const timeSlotList = ref<string[]>([]);
  513. const weekDayList = ref<string[]>([]);
  514. const monthDayList = ref<number[]>([]);
  515. const weekDayOptions = [
  516. { value: '1', label: '周一' },
  517. { value: '2', label: '周二' },
  518. { value: '3', label: '周三' },
  519. { value: '4', label: '周四' },
  520. { value: '5', label: '周五' },
  521. { value: '6', label: '周六' },
  522. { value: '7', label: '周日' }
  523. ];
  524. const timeSlotDialog = reactive({ visible: false });
  525. const timeSlotForm = reactive({ start: '', end: '' });
  526. const data = reactive<any>({
  527. form: {
  528. id: undefined,
  529. taskName: '',
  530. taskType: '',
  531. storeName: '',
  532. location: '',
  533. cycle: '每日',
  534. scanEnabled: false,
  535. checkMethod: '常规',
  536. punchDeviceCode: '',
  537. lng: undefined,
  538. lat: undefined,
  539. inspectorName: '',
  540. auditorName: '',
  541. dayOfWeek: '',
  542. dayOfMonth: '',
  543. timeSlot: '',
  544. itemList: [] as InspectionItemForm[]
  545. } as any,
  546. queryParams: {
  547. pageNum: 1,
  548. pageSize: 10,
  549. taskName: '',
  550. taskType: '',
  551. storeName: '',
  552. recordStatus: '',
  553. checkResult: ''
  554. },
  555. rules: {
  556. taskName: [{ required: true, message: '请输入任务名称', trigger: 'blur' }],
  557. taskType: [{ required: true, message: '请选择巡检类型', trigger: 'change' }],
  558. cycle: [{ required: true, message: '请选择巡检周期', trigger: 'change' }],
  559. storeName: [{ required: true, message: '请输入门店', trigger: 'blur' }],
  560. location: [{ required: true, message: '请输入位置区域', trigger: 'blur' }],
  561. inspectorId: [{ required: true, message: '请选择责任人', trigger: 'change' }],
  562. auditorId: [{ required: true, message: '请选择审核人', trigger: 'change' }]
  563. }
  564. });
  565. const { queryParams, form, rules } = toRefs(data);
  566. const dialog = reactive<DialogOption>({ visible: false, title: '' });
  567. const recordDialog = reactive<DialogOption>({ visible: false, title: '打卡记录' });
  568. const detailDialog = reactive({ visible: false });
  569. const detailForm = ref<any>({ itemList: [] });
  570. const auditDialog = reactive({ visible: false, title: '巡检打卡审核' });
  571. const auditFormRef = ref<FormInstance>();
  572. const getList = async () => {
  573. loading.value = true;
  574. try {
  575. const res = await listInspectionTask(queryParams.value);
  576. taskList.value = res.rows || [];
  577. total.value = res.total || 0;
  578. } finally {
  579. loading.value = false;
  580. }
  581. };
  582. const loadStats = async () => {
  583. const res = await getInspectionStats();
  584. if (res.data) {
  585. stats.value = res.data;
  586. }
  587. };
  588. const loadAll = async () => {
  589. await Promise.all([getList(), loadStats()]);
  590. };
  591. const handleQuery = () => {
  592. queryParams.value.pageNum = 1;
  593. getList();
  594. };
  595. const resetQuery = () => {
  596. queryFormRef.value?.resetFields();
  597. queryParams.value.pageNum = 1;
  598. handleQuery();
  599. };
  600. const resetForm = () => {
  601. form.value = {
  602. id: undefined,
  603. taskName: '',
  604. taskType: '',
  605. storeName: '',
  606. location: '',
  607. cycle: '每日',
  608. scanEnabled: false,
  609. checkMethod: '常规',
  610. punchDeviceCode: '',
  611. lng: undefined,
  612. lat: undefined,
  613. inspectorId: undefined,
  614. inspectorName: '',
  615. auditorId: undefined,
  616. auditorName: '',
  617. dayOfWeek: '',
  618. dayOfMonth: '',
  619. timeSlot: '',
  620. itemList: [] as InspectionItemForm[]
  621. };
  622. timeSlotList.value = [];
  623. weekDayList.value = [];
  624. monthDayList.value = [];
  625. formRef.value?.resetFields();
  626. };
  627. /**
  628. * 拉取当前登录用户所在部门及所有下级部门的用户列表(责任人/审核人选择器数据源)
  629. */
  630. const loadDeptChainUsers = async () => {
  631. try {
  632. const res = await listByCurrentDeptChainUsers();
  633. deptChainUserOptions.value = res.data || [];
  634. } catch (e) {
  635. deptChainUserOptions.value = [];
  636. }
  637. };
  638. /**
  639. * 选择责任人后,同步回填 inspectorName 字段(便于提交到后端)
  640. */
  641. const onInspectorChange = (val: string | number | undefined) => {
  642. if (val === undefined || val === null || val === '') {
  643. form.value.inspectorName = '';
  644. return;
  645. }
  646. const user = deptChainUserOptions.value.find((u) => String(u.userId) === String(val));
  647. form.value.inspectorName = user?.nickName || user?.userName || '';
  648. };
  649. /**
  650. * 选择审核人后,同步回填 auditorName 字段
  651. */
  652. const onAuditorChange = (val: string | number | undefined) => {
  653. if (val === undefined || val === null || val === '') {
  654. form.value.auditorName = '';
  655. return;
  656. }
  657. const user = deptChainUserOptions.value.find((u) => String(u.userId) === String(val));
  658. form.value.auditorName = user?.nickName || user?.userName || '';
  659. };
  660. const onCycleChange = (val: string) => {
  661. timeSlotList.value = [];
  662. weekDayList.value = [];
  663. monthDayList.value = [];
  664. };
  665. const onScanChange = (val: boolean | string | number) => {
  666. form.value.checkMethod = val ? '扫码' : '常规';
  667. };
  668. const openAddTimeSlot = () => {
  669. timeSlotForm.start = '';
  670. timeSlotForm.end = '';
  671. timeSlotDialog.visible = true;
  672. };
  673. const confirmAddTimeSlot = () => {
  674. if (!timeSlotForm.start || !timeSlotForm.end) {
  675. proxy?.$modal.msgWarning('请选择开始和结束时间');
  676. return;
  677. }
  678. timeSlotList.value.push(`${timeSlotForm.start}-${timeSlotForm.end}`);
  679. timeSlotDialog.visible = false;
  680. };
  681. const removeTimeSlot = (idx: number) => {
  682. timeSlotList.value.splice(idx, 1);
  683. };
  684. const addInspectionItem = () => {
  685. form.value.itemList.push({
  686. itemType: '',
  687. itemContent: '',
  688. itemStandard: '',
  689. needPhoto: false
  690. });
  691. };
  692. const removeInspectionItem = (idx: number) => {
  693. form.value.itemList.splice(idx, 1);
  694. };
  695. const handleAdd = () => {
  696. resetForm();
  697. dialog.visible = true;
  698. dialog.title = '新增巡检打卡';
  699. };
  700. const handleUpdate = async (row: RiskInspectionTaskVo) => {
  701. resetForm();
  702. // 编辑时,确保选择器数据源已加载(避免选择器中无对应选项)
  703. if (deptChainUserOptions.value.length === 0) {
  704. await loadDeptChainUsers();
  705. }
  706. const res = await getInspectionTask(row.id);
  707. Object.assign(form.value, res.data);
  708. // 恢复时间配置
  709. if (res.data?.timeSlot) {
  710. timeSlotList.value = res.data.timeSlot.split(',').filter((s: string) => s);
  711. }
  712. if (res.data?.dayOfWeek) {
  713. weekDayList.value = res.data.dayOfWeek.split(',').filter((s: string) => s);
  714. }
  715. if (res.data?.dayOfMonth) {
  716. monthDayList.value = res.data.dayOfMonth.split(',').filter((s: string) => s).map((n: string) => Number(n));
  717. }
  718. // 加载打卡项目
  719. try {
  720. const itemRes = await listInspectionItemByTask(row.id);
  721. form.value.itemList = (itemRes.data || []).map((it: RiskInspectionItemVo) => ({
  722. id: it.id,
  723. itemType: it.itemType,
  724. itemContent: it.itemContent,
  725. itemStandard: it.itemStandard,
  726. needPhoto: false
  727. }));
  728. } catch (e) {
  729. form.value.itemList = [];
  730. }
  731. dialog.visible = true;
  732. dialog.title = '编辑巡检任务';
  733. };
  734. const handleViewRecords = async (row: RiskInspectionTaskVo) => {
  735. recordLoading.value = true;
  736. try {
  737. const res = await listInspectionRecordByTask(row.id);
  738. recordList.value = res.data || [];
  739. } finally {
  740. recordLoading.value = false;
  741. }
  742. recordDialog.visible = true;
  743. };
  744. const handleViewDetail = async (row: RiskInspectionRecordVo) => {
  745. detailForm.value = { ...row, itemList: [] };
  746. detailDialog.visible = true;
  747. try {
  748. const res = await listInspectionRecordItemByRecord(row.id);
  749. detailForm.value.itemList = (res.data || []).map((it: RiskInspectionRecordItemVo) => ({
  750. itemType: it.itemType || it.itemCategory,
  751. itemContent: it.itemContent,
  752. itemStandard: it.itemStandard,
  753. checkResult: it.checkResult,
  754. remark: it.remark,
  755. checkPhotos: it.photos || it.checkPhotos,
  756. problemCount: it.problemCount
  757. }));
  758. } catch (e) {
  759. detailForm.value.itemList = [];
  760. }
  761. };
  762. // ============ 审核相关 ============
  763. const auditData = reactive({
  764. auditForm: {
  765. id: undefined as string | number | undefined,
  766. taskName: '',
  767. inspectorName: '',
  768. checkInTime: '',
  769. auditStatus: '审核通过',
  770. auditOpinion: ''
  771. },
  772. auditRules: {
  773. auditStatus: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
  774. auditOpinion: [
  775. {
  776. validator: (_rule: any, value: any, callback: any) => {
  777. if (auditData.auditForm.auditStatus === '审核不通过' && !value) {
  778. callback(new Error('审核不通过时必须填写原因'));
  779. } else {
  780. callback();
  781. }
  782. },
  783. trigger: 'blur'
  784. }
  785. ]
  786. }
  787. });
  788. const { auditForm, auditRules } = toRefs(auditData);
  789. /** 打卡记录列表 - 打开审核弹窗 */
  790. const handleAuditRecord = (row: RiskInspectionRecordVo) => {
  791. auditForm.value = {
  792. id: row.id,
  793. taskName: row.taskName || '',
  794. inspectorName: row.inspectorName || '',
  795. checkInTime: row.checkInTime || '',
  796. auditStatus: '审核通过',
  797. auditOpinion: ''
  798. };
  799. auditDialog.visible = true;
  800. };
  801. /** 审核弹窗 - 提交 */
  802. const submitAudit = () => {
  803. auditFormRef.value?.validate(async (valid: boolean) => {
  804. if (!valid) return;
  805. const submitData: RiskInspectionRecordBo = {
  806. id: auditForm.value.id,
  807. auditStatus: auditForm.value.auditStatus,
  808. auditOpinion: auditForm.value.auditOpinion
  809. };
  810. await auditInspectionRecord(submitData);
  811. proxy?.$modal.msgSuccess('审核成功');
  812. auditDialog.visible = false;
  813. // 刷新当前打卡记录列表(若弹窗开着则一起刷新)
  814. if (recordDialog.visible && recordList.value.length > 0) {
  815. const taskId = recordList.value[0]?.taskId;
  816. if (taskId) {
  817. const res = await listInspectionRecordByTask(taskId);
  818. recordList.value = res.data || [];
  819. }
  820. }
  821. });
  822. };
  823. const cancelAudit = () => {
  824. auditDialog.visible = false;
  825. auditFormRef.value?.resetFields();
  826. };
  827. const closeAuditDialog = () => {
  828. auditDialog.visible = false;
  829. auditFormRef.value?.resetFields();
  830. };
  831. /** 审核状态 tag 颜色(待审核=warning/审核通过=success/审核不通过=danger) */
  832. const getAuditStatusTag = (s: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  833. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  834. 待审核: 'warning',
  835. 审核通过: 'success',
  836. 审核不通过: 'danger'
  837. };
  838. return (map[s] || 'info') as any;
  839. };
  840. const handleDelete = async (row: RiskInspectionTaskVo) => {
  841. await proxy?.$modal.confirm('是否确认删除任务 "' + row.taskName + '" ?');
  842. await delInspectionTask(row.id);
  843. proxy?.$modal.msgSuccess('删除成功');
  844. await loadAll();
  845. };
  846. const submitForm = () => {
  847. formRef.value?.validate(async (valid: boolean) => {
  848. if (!valid) return;
  849. // 同步时间配置
  850. if (form.value.cycle === '每日') {
  851. form.value.timeSlot = timeSlotList.value.join(',');
  852. form.value.dayOfWeek = '';
  853. form.value.dayOfMonth = '';
  854. } else if (form.value.cycle === '每周') {
  855. form.value.dayOfWeek = weekDayList.value.join(',');
  856. form.value.timeSlot = '';
  857. form.value.dayOfMonth = '';
  858. } else if (form.value.cycle === '每月') {
  859. form.value.dayOfMonth = monthDayList.value.join(',');
  860. form.value.timeSlot = '';
  861. form.value.dayOfWeek = '';
  862. }
  863. form.value.scanEnabled = form.value.scanEnabled ? '1' : '0';
  864. if (form.value.id) {
  865. await updateInspectionTask(form.value as RiskInspectionTaskBo);
  866. proxy?.$modal.msgSuccess('修改成功');
  867. } else {
  868. await addInspectionTask(form.value as RiskInspectionTaskBo);
  869. proxy?.$modal.msgSuccess('新增成功');
  870. }
  871. dialog.visible = false;
  872. await loadAll();
  873. });
  874. };
  875. const cancel = () => {
  876. dialog.visible = false;
  877. resetForm();
  878. };
  879. const closeDialog = () => {
  880. dialog.visible = false;
  881. resetForm();
  882. };
  883. const getMethodTag = (m: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  884. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  885. 扫码: 'warning',
  886. 常规: 'primary'
  887. };
  888. return (map[m] || 'info') as any;
  889. };
  890. const getStatusTag = (s: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  891. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  892. 已打卡: 'success',
  893. 未打卡: 'danger',
  894. 异常打卡: 'warning'
  895. };
  896. return (map[s] || 'info') as any;
  897. };
  898. const getResultTag = (r: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  899. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  900. 正常: 'success',
  901. 异常: 'danger'
  902. };
  903. return (map[r] || 'info') as any;
  904. };
  905. onMounted(async () => {
  906. await loadAll();
  907. await loadDeptChainUsers();
  908. });
  909. </script>
  910. <style scoped lang="scss">
  911. .inspection-task-page {
  912. padding: 16px;
  913. height: 100%;
  914. overflow-y: auto;
  915. box-sizing: border-box;
  916. }
  917. .stat-card {
  918. border-radius: 8px;
  919. :deep(.el-card__body) { padding: 20px; }
  920. }
  921. .stat-card-content {
  922. display: flex;
  923. align-items: center;
  924. justify-content: space-between;
  925. }
  926. .stat-info { flex: 1; }
  927. .stat-title {
  928. font-size: 13px;
  929. color: #909399;
  930. margin-bottom: 8px;
  931. white-space: nowrap;
  932. }
  933. .stat-value {
  934. font-size: 28px;
  935. font-weight: 700;
  936. color: #303133;
  937. line-height: 1.2;
  938. }
  939. .stat-icon {
  940. width: 48px;
  941. height: 48px;
  942. border-radius: 8px;
  943. display: flex;
  944. align-items: center;
  945. justify-content: center;
  946. font-size: 24px;
  947. color: #fff;
  948. }
  949. .stat-icon-blue { background: #ecf5ff; color: #409EFF; }
  950. .stat-icon-orange { background: #fdf6ec; color: #E6A23C; }
  951. .stat-icon-green { background: #f0f9eb; color: #67C23A; }
  952. .stat-icon-red { background: #fef0f0; color: #F56C6C; }
  953. .mb-2 { margin-bottom: 8px; }
  954. .mt-2 { margin-top: 8px; }
  955. .readonly-text {
  956. color: #303133;
  957. }
  958. .audit-opinion.pass {
  959. color: #67c23a;
  960. }
  961. .audit-opinion.reject {
  962. color: #f56c6c;
  963. }
  964. .list-toolbar {
  965. display: flex;
  966. justify-content: space-between;
  967. align-items: center;
  968. margin-bottom: 12px;
  969. }
  970. .list-total {
  971. font-size: 13px;
  972. color: #606266;
  973. }
  974. .toolbar-actions {
  975. display: flex;
  976. align-items: center;
  977. }
  978. </style>