index.vue 40 KB

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