index.vue 39 KB

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