index.vue 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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.itemCategory" 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. itemCategory: 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. itemCategory: '',
  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 序列化大数防精度丢失),统一转 string 匹配 storeOptions
  749. if (form.value.storeId !== undefined && form.value.storeId !== null) {
  750. form.value.storeId = String(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. // scanEnabled 后端返 '1'/'0' 字符串,el-switch 严格 boolean,统一转
  757. if (form.value.scanEnabled !== undefined && form.value.scanEnabled !== null) {
  758. form.value.scanEnabled = form.value.scanEnabled === '1' || form.value.scanEnabled === true;
  759. }
  760. // 恢复时间配置
  761. if (res.data?.timeSlot) {
  762. timeSlotList.value = res.data.timeSlot.split(',').filter((s: string) => s);
  763. }
  764. if (res.data?.dayOfWeek) {
  765. weekDayList.value = res.data.dayOfWeek.split(',').filter((s: string) => s);
  766. }
  767. if (res.data?.dayOfMonth) {
  768. monthDayList.value = res.data.dayOfMonth.split(',').filter((s: string) => s).map((n: string) => Number(n));
  769. }
  770. // 加载打卡项目
  771. try {
  772. const itemRes = await listInspectionItemByTask(row.id);
  773. form.value.itemList = (itemRes.data || []).map((it: RiskInspectionItemVo) => ({
  774. id: it.id,
  775. itemCategory: it.itemCategory || it.itemType || '',
  776. itemContent: it.itemContent,
  777. itemStandard: it.itemStandard,
  778. needPhoto: it.needPhoto === '1' || it.needPhoto === true
  779. }));
  780. } catch (e) {
  781. form.value.itemList = [];
  782. }
  783. dialog.visible = true;
  784. dialog.title = '编辑品控巡检任务';
  785. };
  786. const handleViewRecords = async (row: RiskInspectionTaskVo) => {
  787. recordLoading.value = true;
  788. try {
  789. const res = await listQualityInspectionRecordByTask(row.id);
  790. recordList.value = res.data || [];
  791. } finally {
  792. recordLoading.value = false;
  793. }
  794. recordDialog.visible = true;
  795. };
  796. const handleViewDetail = (row: RiskInspectionRecordVo) => {
  797. detailForm.value = { ...row, itemList: [] };
  798. detailDialog.visible = true;
  799. };
  800. // ============ 审核相关 ============
  801. const auditData = reactive({
  802. auditForm: {
  803. id: undefined as string | number | undefined,
  804. taskName: '',
  805. inspectorName: '',
  806. checkInTime: '',
  807. auditStatus: '审核通过',
  808. auditOpinion: ''
  809. },
  810. auditRules: {
  811. auditStatus: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
  812. auditOpinion: [
  813. {
  814. validator: (_rule: any, value: any, callback: any) => {
  815. if (auditData.auditForm.auditStatus === '审核不通过' && !value) {
  816. callback(new Error('审核不通过时必须填写原因'));
  817. } else {
  818. callback();
  819. }
  820. },
  821. trigger: 'blur'
  822. }
  823. ]
  824. }
  825. });
  826. const { auditForm, auditRules } = toRefs(auditData);
  827. /** 打卡记录列表 - 打开审核弹窗 */
  828. const handleAuditRecord = (row: RiskInspectionRecordVo) => {
  829. auditForm.value = {
  830. id: row.id,
  831. taskName: row.taskName || '',
  832. inspectorName: row.inspectorName || '',
  833. checkInTime: row.checkInTime || '',
  834. auditStatus: '审核通过',
  835. auditOpinion: ''
  836. };
  837. auditDialog.visible = true;
  838. };
  839. /** 审核弹窗 - 提交 */
  840. const submitAudit = () => {
  841. auditFormRef.value?.validate(async (valid: boolean) => {
  842. if (!valid) return;
  843. const submitData: RiskInspectionRecordBo = {
  844. id: auditForm.value.id,
  845. auditStatus: auditForm.value.auditStatus,
  846. auditOpinion: auditForm.value.auditOpinion
  847. };
  848. await auditInspectionRecord(submitData);
  849. proxy?.$modal.msgSuccess('审核成功');
  850. auditDialog.visible = false;
  851. // 刷新当前打卡记录列表(若弹窗开着则一起刷新)
  852. if (recordDialog.visible && recordList.value.length > 0) {
  853. const taskId = recordList.value[0]?.taskId;
  854. if (taskId) {
  855. const res = await listQualityInspectionRecordByTask(taskId);
  856. recordList.value = res.data || [];
  857. }
  858. }
  859. });
  860. };
  861. const cancelAudit = () => {
  862. auditDialog.visible = false;
  863. auditFormRef.value?.resetFields();
  864. };
  865. const closeAuditDialog = () => {
  866. auditDialog.visible = false;
  867. auditFormRef.value?.resetFields();
  868. };
  869. /** 审核状态 tag 颜色(待审核=warning/审核通过=success/审核不通过=danger) */
  870. const getAuditStatusTag = (s: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  871. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  872. 待审核: 'warning',
  873. 审核通过: 'success',
  874. 审核不通过: 'danger'
  875. };
  876. return (map[s] || 'info') as any;
  877. };
  878. const handleDelete = async (row: RiskInspectionTaskVo) => {
  879. await proxy?.$modal.confirm('是否确认删除任务 "' + row.taskName + '" ?');
  880. await delQualityInspectionTask(row.id);
  881. proxy?.$modal.msgSuccess('删除成功');
  882. await loadAll();
  883. };
  884. const submitForm = () => {
  885. formRef.value?.validate(async (valid: boolean) => {
  886. if (!valid) return;
  887. // 同步时间配置
  888. if (form.value.cycle === '每日') {
  889. form.value.timeSlot = timeSlotList.value.join(',');
  890. form.value.dayOfWeek = '';
  891. form.value.dayOfMonth = '';
  892. } else if (form.value.cycle === '每周') {
  893. form.value.dayOfWeek = weekDayList.value.join(',');
  894. form.value.timeSlot = '';
  895. form.value.dayOfMonth = '';
  896. } else if (form.value.cycle === '每月') {
  897. form.value.dayOfMonth = monthDayList.value.join(',');
  898. form.value.timeSlot = '';
  899. form.value.dayOfWeek = '';
  900. }
  901. // 构造提交 payload(不破坏 form.value 本身,避免下次打开状态不一致)
  902. const payload: any = {
  903. ...form.value,
  904. scanEnabled: form.value.scanEnabled ? '1' : '0',
  905. itemList: (form.value.itemList || []).map((it: any) => ({
  906. ...it,
  907. itemCategory: it.itemCategory || it.itemType || '',
  908. needPhoto: it.needPhoto ? '1' : '0'
  909. }))
  910. };
  911. if (form.value.id) {
  912. await updateQualityInspectionTask(payload as RiskInspectionTaskBo);
  913. proxy?.$modal.msgSuccess('修改成功');
  914. } else {
  915. await addQualityInspectionTask(payload as RiskInspectionTaskBo);
  916. proxy?.$modal.msgSuccess('新增成功');
  917. }
  918. dialog.visible = false;
  919. await loadAll();
  920. });
  921. };
  922. const cancel = () => {
  923. dialog.visible = false;
  924. resetForm();
  925. };
  926. const closeDialog = () => {
  927. dialog.visible = false;
  928. resetForm();
  929. };
  930. const getMethodTag = (m: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  931. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  932. 扫码: 'warning',
  933. 常规: 'primary'
  934. };
  935. return (map[m] || 'info') as any;
  936. };
  937. const getStatusTag = (s: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  938. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  939. 已打卡: 'success',
  940. 未打卡: 'danger',
  941. 异常打卡: 'warning'
  942. };
  943. return (map[s] || 'info') as any;
  944. };
  945. const getResultTag = (r: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
  946. const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
  947. 正常: 'success',
  948. 异常: 'danger'
  949. };
  950. return (map[r] || 'info') as any;
  951. };
  952. onMounted(async () => {
  953. await loadAll();
  954. await loadDeptChainUsers();
  955. await loadStores();
  956. });
  957. /** 加载门店下拉(集团总部 + dept_category='门店' 的所有门店) */
  958. const loadStores = async () => {
  959. try {
  960. const res: any = await listDept({});
  961. const list: any[] = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : [];
  962. storeOptions.value = list
  963. .filter((d: any) => d.deptCategory === '门店' || d.deptId === 100)
  964. .filter((d: any) => d.status === '0' || d.status === undefined || d.status === null)
  965. .map((d: any) => ({ label: d.deptName, value: String(d.deptId) }))
  966. .sort((a, b) => Number(a.value) - Number(b.value));
  967. } catch (e) {
  968. console.error('加载门店列表失败', e);
  969. storeOptions.value = [];
  970. }
  971. };
  972. </script>
  973. <style scoped lang="scss">
  974. .inspection-task-page {
  975. padding: 16px;
  976. height: 100%;
  977. overflow-y: auto;
  978. box-sizing: border-box;
  979. }
  980. .stat-card {
  981. border-radius: 8px;
  982. :deep(.el-card__body) { padding: 20px; }
  983. }
  984. .stat-card-content {
  985. display: flex;
  986. align-items: center;
  987. justify-content: space-between;
  988. }
  989. .stat-info { flex: 1; }
  990. .stat-title {
  991. font-size: 13px;
  992. color: #909399;
  993. margin-bottom: 8px;
  994. white-space: nowrap;
  995. }
  996. .stat-value {
  997. font-size: 28px;
  998. font-weight: 700;
  999. color: #303133;
  1000. line-height: 1.2;
  1001. }
  1002. .stat-icon {
  1003. width: 48px;
  1004. height: 48px;
  1005. border-radius: 8px;
  1006. display: flex;
  1007. align-items: center;
  1008. justify-content: center;
  1009. font-size: 24px;
  1010. color: #fff;
  1011. }
  1012. .stat-icon-blue { background: #ecf5ff; color: #409EFF; }
  1013. .stat-icon-orange { background: #fdf6ec; color: #E6A23C; }
  1014. .stat-icon-green { background: #f0f9eb; color: #67C23A; }
  1015. .stat-icon-red { background: #fef0f0; color: #F56C6C; }
  1016. .mb-2 { margin-bottom: 8px; }
  1017. .mt-2 { margin-top: 8px; }
  1018. .readonly-text {
  1019. color: #303133;
  1020. }
  1021. .audit-opinion.pass {
  1022. color: #67c23a;
  1023. }
  1024. .audit-opinion.reject {
  1025. color: #f56c6c;
  1026. }
  1027. </style>