work-order-completion.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <script lang="ts" setup>
  2. import { ref, onMounted } from 'vue'
  3. import dayjs from 'dayjs'
  4. import { useDebounceFn } from '@vueuse/core'
  5. import MiniBarChart from '@/components/WorkOrderCompletionBar/index.vue'
  6. import CountTo from '@/components/count-to1.vue'
  7. import { IotReportApi } from '@/api/pms/report'
  8. // 定义时间类型
  9. type TimeType = 'year' | 'month' | 'day'
  10. interface Query {
  11. deptId?: number
  12. createTime?: [string, string]
  13. type?: string
  14. pageNo: number
  15. pageSize: number
  16. }
  17. interface ChartDataItem {
  18. label: string
  19. num: number
  20. }
  21. interface StatItem {
  22. key: string
  23. title: string
  24. type: string
  25. icon: string
  26. total: number
  27. charts: ChartDataItem[]
  28. tb: number
  29. hb: number
  30. }
  31. // 选项配置数组
  32. const timeOptions: { label: string; value: TimeType }[] = [
  33. { label: '年', value: 'year' },
  34. { label: '月', value: 'month' },
  35. { label: '日', value: 'day' }
  36. ]
  37. const activeTimeType = ref<TimeType>('year')
  38. const query = ref<Query>({
  39. pageNo: 1,
  40. pageSize: 10
  41. })
  42. const defaultStats: StatItem[] = [
  43. {
  44. key: 'yx',
  45. title: '运行记录',
  46. type: '运行记录',
  47. icon: 'i-material-symbols:list-alt-outline',
  48. total: 0,
  49. charts: [],
  50. tb: 0,
  51. hb: 0
  52. },
  53. {
  54. key: 'rb',
  55. title: '生产日报',
  56. type: '日报',
  57. icon: 'i-material-symbols:calendar-today-outline',
  58. total: 0,
  59. charts: [],
  60. tb: 0,
  61. hb: 0
  62. },
  63. {
  64. key: 'wx',
  65. title: '维修工单',
  66. type: '维修工单',
  67. icon: 'i-material-symbols:home-repair-service-outline',
  68. total: 0,
  69. charts: [],
  70. tb: 0,
  71. hb: 0
  72. },
  73. {
  74. key: 'by',
  75. title: '保养工单',
  76. type: '保养工单',
  77. icon: 'i-material-symbols:construction-rounded',
  78. total: 0,
  79. charts: [],
  80. tb: 0,
  81. hb: 0
  82. },
  83. {
  84. key: 'xj',
  85. title: '巡检工单',
  86. type: '巡检工单',
  87. icon: 'i-material-symbols:warning-outline',
  88. total: 0,
  89. charts: [],
  90. tb: 0,
  91. hb: 0
  92. }
  93. ]
  94. const statList = ref<StatItem[]>(JSON.parse(JSON.stringify(defaultStats)))
  95. const dataLoading = ref(false)
  96. const list = ref<any[]>([])
  97. const loading = ref(false)
  98. const total = ref(0)
  99. const handleTimeChange = (type: TimeType, init = false) => {
  100. activeTimeType.value = type
  101. const formatStr = 'YYYY-MM-DD HH:mm:ss'
  102. const endTime = dayjs().endOf('day').format(formatStr)
  103. let startTime = ''
  104. switch (type) {
  105. case 'year':
  106. startTime = dayjs().startOf('year').format(formatStr)
  107. break
  108. case 'month':
  109. startTime = dayjs().startOf('month').format(formatStr)
  110. break
  111. case 'day':
  112. startTime = dayjs().startOf('day').format(formatStr)
  113. break
  114. }
  115. query.value.createTime = [startTime, endTime]
  116. console.log(`切换为[${type}]:`, query.value.createTime)
  117. if (!init) loadData()
  118. }
  119. const labelMap = {
  120. wxoareject: '审批不通过',
  121. wxoa: '审批中',
  122. wxclose: '关闭',
  123. wxfinished: '完成',
  124. wxtx: '待填写',
  125. xjtodo: '待执行',
  126. xjignore: '忽略',
  127. xjfinished: '已执行',
  128. yx0: '待填写',
  129. yx1: '已完成',
  130. yx2: '填写中',
  131. yx3: '忽略',
  132. by1: '未保养',
  133. by2: '已保养',
  134. rb0: '未完成',
  135. rb1: '已完成'
  136. }
  137. // 模拟数据加载
  138. const loadData = useDebounceFn(async function () {
  139. dataLoading.value = true
  140. const { pageNo, pageSize, type, ...other } = query.value
  141. const res = await IotReportApi.getOrderNumber({ ...other, timeType: activeTimeType.value })
  142. statList.value.forEach((item) => {
  143. const data = res[item.key] ?? {}
  144. item.total = data.total?.total ?? 0
  145. item.tb = data.total?.tb ?? 0
  146. item.hb = data.total?.hb ?? 0
  147. item.charts = data.status
  148. .filter((d) => d.num !== 0)
  149. .map((d) => ({
  150. label: labelMap[item.key + d.status],
  151. num: d.num
  152. }))
  153. })
  154. dataLoading.value = false
  155. }, 500)
  156. const loadList = useDebounceFn(async function () {
  157. loading.value = true
  158. const res = await IotReportApi.getOrderPage(query.value)
  159. // console.log('res :>> ', res)
  160. // const mockTableData = Array.from({ length: query.value.pageSize }).map((_, index) => {
  161. // const types = ['维修工单', '保养工单', '巡检工单', '运行记录', '生产日报']
  162. // const companies = ['第一工程公司', '第二工程公司', '总包单位']
  163. // const statuses = ['已完成', '未完成', '处理中']
  164. // return {
  165. // id: index + 1,
  166. // orderType: types[Math.floor(Math.random() * types.length)],
  167. // createTime: dayjs()
  168. // .subtract(Math.floor(Math.random() * 10), 'day')
  169. // .format('YYYY-MM-DD HH:mm:ss'),
  170. // companyName: companies[Math.floor(Math.random() * companies.length)],
  171. // projectDept: `项目部-${Math.floor(Math.random() * 10) + 1}`,
  172. // teamName: `作业队-${String.fromCharCode(65 + Math.floor(Math.random() * 5))}`,
  173. // status: statuses[Math.floor(Math.random() * statuses.length)],
  174. // deviceName: `设备-${Math.floor(Math.random() * 1000)}`
  175. // }
  176. // })
  177. list.value = res.list
  178. total.value = res.total
  179. loading.value = false
  180. }, 500)
  181. function handleSizeChange(val: number) {
  182. query.value.pageSize = val
  183. query.value.pageNo = 1
  184. loadList()
  185. }
  186. function handleCurrentChange(val: number) {
  187. query.value.pageNo = val
  188. loadList()
  189. }
  190. function handleQuery(setPage = true) {
  191. if (setPage) {
  192. query.value.pageNo = 1
  193. }
  194. loadList()
  195. loadData()
  196. }
  197. onMounted(() => {
  198. handleTimeChange('year', true)
  199. })
  200. watch(
  201. [() => query.value.createTime, () => query.value.deptId],
  202. () => {
  203. handleQuery()
  204. },
  205. { immediate: true }
  206. )
  207. function selectType(type: string) {
  208. query.value.type = type
  209. query.value.pageNo = 1
  210. loadList()
  211. }
  212. </script>
  213. <template>
  214. <div
  215. class="grid grid-cols-[15%_1fr] grid-rows-[208px_1fr] gap-4 h-[calc(100vh-20px-var(--top-tool-height)-var(--tags-view-height)-var(--app-footer-height))]"
  216. >
  217. <div class="p-4 bg-white dark:bg-[#1d1e1f] shadow rounded-lg row-span-2">
  218. <DeptTreeSelect
  219. :top-id="156"
  220. :deptId="156"
  221. v-model="query.deptId"
  222. :init-select="false"
  223. :show-title="false"
  224. />
  225. </div>
  226. <div class="flex flex-col gap-4 h-full">
  227. <div
  228. class="grid grid-cols-1 md:grid-cols-3 xl:grid-cols-5 gap-4 flex-1"
  229. v-loading="dataLoading"
  230. >
  231. <section
  232. v-for="item in statList"
  233. :key="item.key"
  234. class="bg-white dark:bg-[#1d1e1f] rounded-xl shadow flex justify-between items-stretch min-h-[140px] border border-gray-200 dark:border-gray-700/50 relative overflow-hidden group transition-colors duration-300 transition-transform hover:scale-105 duration-500"
  235. :class="{ 'scale-105': item.type === query.type }"
  236. @click="selectType(item.type)"
  237. >
  238. <div class="flex flex-col justify-between z-10 p-4 pb-2 pr-0 gap-1">
  239. <div class="text-gray-500 dark:text-gray-400 text-sm font-medium">
  240. {{ item.title }}
  241. </div>
  242. <div class="text-3xl font-bold tracking-tight text-gray-900! dark:text-white! mt-2">
  243. <count-to :start-val="0" :end-val="item.total" :duration="100">
  244. <span class="text-xs leading-9 text-[var(--el-text-color-regular)]">
  245. 暂无数据
  246. </span>
  247. </count-to>
  248. </div>
  249. <div class="flex flex-col gap-2 w-24">
  250. <div v-show="item.tb !== 0" class="flex items-center gap-1">
  251. <div
  252. class="px-2 py-0.5 rounded text-xs font-bold flex items-center space-x-1"
  253. :class="
  254. item.tb >= 0
  255. ? 'bg-emerald-100 text-emerald-600 dark:bg-emerald-500/20 dark:text-emerald-400'
  256. : 'bg-rose-100 text-rose-600 dark:bg-rose-500/20 dark:text-rose-400'
  257. "
  258. >
  259. <div
  260. :class="
  261. item.tb >= 0
  262. ? 'i-material-symbols:trending-up'
  263. : 'i-material-symbols:trending-down'
  264. "
  265. class="text-sm"
  266. ></div>
  267. <span>{{ Math.abs(item.hb) }}%</span>
  268. </div>
  269. <span class="w-6 text-xs text-gray-500 dark:text-gray-400">同比</span>
  270. </div>
  271. <div v-show="item.hb !== 0" class="flex items-center gap-1">
  272. <div
  273. class="px-2 py-0.5 rounded text-xs font-bold flex items-center space-x-1"
  274. :class="
  275. item.hb >= 0
  276. ? 'bg-emerald-100 text-emerald-600 dark:bg-emerald-500/20 dark:text-emerald-400'
  277. : 'bg-rose-100 text-rose-600 dark:bg-rose-500/20 dark:text-rose-400'
  278. "
  279. >
  280. <div
  281. :class="
  282. item.hb >= 0
  283. ? 'i-material-symbols:trending-up'
  284. : 'i-material-symbols:trending-down'
  285. "
  286. class="text-sm"
  287. ></div>
  288. <span>{{ Math.abs(item.hb) }}%</span>
  289. </div>
  290. <span class="min-w-8 text-xs text-gray-500 dark:text-gray-400">环比</span>
  291. </div>
  292. </div>
  293. </div>
  294. <!-- 右侧:ECharts图表 -->
  295. <div class="flex-1 h-full z-10 relative">
  296. <MiniBarChart :items="item.charts" :max="item.total" />
  297. </div>
  298. <!-- 背景装饰:颜色自适应 -->
  299. <div
  300. class="absolute -right-6 -bottom-6 opacity-[0.05] pointer-events-none transition-transform group-hover:scale-150 duration-500 text-black dark:text-white"
  301. >
  302. <div :class="item.icon" class="text-9xl"></div>
  303. </div>
  304. </section>
  305. </div>
  306. <div class="flex justify-between">
  307. <el-button-group size="default">
  308. <el-button
  309. v-for="item in timeOptions"
  310. :key="item.value"
  311. :type="activeTimeType === item.value ? 'primary' : ''"
  312. @click="handleTimeChange(item.value)"
  313. >
  314. {{ item.label }}
  315. </el-button>
  316. </el-button-group>
  317. <el-button size="default" type="primary">导出</el-button>
  318. </div>
  319. </div>
  320. <div class="bg-white dark:bg-[#1d1e1f] shadow rounded-lg p-4 flex flex-col">
  321. <div class="flex-1 relative">
  322. <el-auto-resizer class="absolute">
  323. <template #default="{ width, height }">
  324. <el-table
  325. :data="list"
  326. v-loading="loading"
  327. stripe
  328. class="absolute"
  329. :max-height="height"
  330. :height="height"
  331. show-overflow-tooltip
  332. :width="width"
  333. scrollbar-always-on
  334. >
  335. <el-table-column label="序号" type="index" width="60" align="center" />
  336. <el-table-column label="工单类别" prop="type" align="center" width="80" />
  337. <el-table-column
  338. label="生成日期"
  339. prop="createTime"
  340. align="center"
  341. width="160"
  342. :formatter="(row) => row.createTime.split(' ')[0]"
  343. />
  344. <el-table-column label="公司" prop="company" align="center" width="100" />
  345. <el-table-column label="项目部" prop="project" align="center" />
  346. <el-table-column label="队伍" prop="deptName" align="center" />
  347. <el-table-column label="状态" prop="status" align="center" width="80">
  348. <!-- <template #default="{ row }">
  349. <el-tag v-if="row.status === '已完成'" type="success" effect="dark" size="small"
  350. >已完成</el-tag
  351. >
  352. <el-tag
  353. v-else-if="row.status === '未完成'"
  354. type="danger"
  355. effect="dark"
  356. size="small"
  357. >未完成</el-tag
  358. >
  359. <el-tag v-else type="warning" effect="plain" size="small">{{
  360. row.status
  361. }}</el-tag>
  362. </template> -->
  363. </el-table-column>
  364. <el-table-column label="设备" prop="device" align="center" />
  365. </el-table>
  366. </template>
  367. </el-auto-resizer>
  368. </div>
  369. <div class="h-10 mt-4 flex items-center justify-end">
  370. <el-pagination
  371. size="default"
  372. v-show="total > 0"
  373. v-model:current-page="query.pageNo"
  374. v-model:page-size="query.pageSize"
  375. :background="true"
  376. :page-sizes="[10, 20, 30, 50, 100]"
  377. :total="total"
  378. layout="total, sizes, prev, pager, next, jumper"
  379. @size-change="handleSizeChange"
  380. @current-change="handleCurrentChange"
  381. />
  382. </div>
  383. </div>
  384. </div>
  385. </template>
  386. <style scoped>
  387. :deep(.el-table) {
  388. border-top-right-radius: 8px;
  389. border-top-left-radius: 8px;
  390. .el-table__cell {
  391. height: 52px;
  392. }
  393. .el-table__header-wrapper {
  394. .el-table__cell {
  395. background: var(--el-fill-color-light);
  396. }
  397. }
  398. }
  399. </style>