statistics.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <script lang="ts" setup>
  2. import { IotRdDailyReportApi } from '@/api/pms/iotrddailyreport'
  3. import { useTableComponents } from '@/components/ZmTable/useTableComponents'
  4. import { useUserStore } from '@/store/modules/user'
  5. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  6. import { rangeShortcuts } from '@/utils/formatTime'
  7. import { useDebounceFn } from '@vueuse/core'
  8. import IotRdDailyReportForm from './IotRdDailyReportForm.vue'
  9. import download from '@/utils/download'
  10. defineOptions({ name: 'IotRdDailyReport' })
  11. const { t } = useI18n()
  12. const router = useRouter()
  13. const message = useMessage()
  14. const userStore = useUserStore()
  15. const id = userStore.getUser.deptId
  16. const deptId = id
  17. interface Query {
  18. deptId?: number
  19. contractName?: string
  20. taskName?: string
  21. createTime?: string[]
  22. wellName?: string
  23. taskId?: number
  24. }
  25. const initQuery: Query = {
  26. deptId: id
  27. }
  28. const query = ref<Query>({ ...initQuery })
  29. const currentPage = ref(1)
  30. const pageSize = ref(10)
  31. interface ListItem {
  32. rdStatus: string
  33. period: string
  34. taskStartDate: string
  35. projectDeptName: string
  36. deptName: string
  37. wellName: string
  38. taskId: number
  39. items: any[]
  40. techniques: string
  41. workloadDesign: string
  42. totalDailyFuel: string
  43. nonProductionRate: number
  44. manufactureName: string
  45. }
  46. const allList = ref<ListItem[]>([])
  47. const total = ref(0)
  48. const loading = ref(false)
  49. const pagedList = computed(() => {
  50. const start = (currentPage.value - 1) * pageSize.value
  51. const end = start + pageSize.value
  52. return allList.value.slice(start, end)
  53. })
  54. const loadList = useDebounceFn(async function () {
  55. loading.value = true
  56. try {
  57. const data: any = await IotRdDailyReportApi.statistics(query.value)
  58. let rawList: ListItem[] = []
  59. rawList = data
  60. allList.value = rawList
  61. total.value = rawList.length
  62. } finally {
  63. loading.value = false
  64. }
  65. })
  66. const dynamicColumns = computed(() => {
  67. const units = new Set()
  68. allList.value.forEach((item) => {
  69. item.items.forEach((subItem) => {
  70. if (subItem.unit) {
  71. units.add(subItem.unit)
  72. }
  73. })
  74. })
  75. return Array.from(units) as string[]
  76. })
  77. const getWorkloadByUnit = (items: any[], unit: string) => {
  78. if (!items || !Array.isArray(items)) return ''
  79. const targetItem = items.find((item) => item.unit === unit)
  80. return targetItem ? targetItem.workload : ''
  81. }
  82. function handleSizeChange(val: number) {
  83. pageSize.value = val
  84. currentPage.value = 1
  85. }
  86. function handleCurrentChange(val: number) {
  87. currentPage.value = val
  88. }
  89. // 搜索事件
  90. function handleQuery() {
  91. currentPage.value = 1
  92. loadList()
  93. }
  94. function resetQuery() {
  95. query.value = { ...initQuery }
  96. handleQuery()
  97. }
  98. watch(
  99. [
  100. () => query.value.deptId,
  101. () => query.value.contractName,
  102. () => query.value.taskName,
  103. () => query.value.createTime
  104. ],
  105. () => {
  106. handleQuery()
  107. },
  108. { immediate: true }
  109. )
  110. const formRef = ref()
  111. const openForm = (type: string, id?: number) => {
  112. formRef.value.open(type, id)
  113. }
  114. const exportLoading = ref(false)
  115. async function handleExport() {
  116. try {
  117. await message.exportConfirm()
  118. exportLoading.value = true
  119. const res = await IotRdDailyReportApi.exportIotRdDailyReport(query.value)
  120. download.excel(res, '瑞都日报汇总.xlsx')
  121. } finally {
  122. exportLoading.value = false
  123. }
  124. }
  125. const { ZmTable, ZmTableColumn } = useTableComponents<ListItem>()
  126. function realValue(type: any, value: string) {
  127. const option = getDictOptions(type).find((item) => item.value === value)
  128. return option?.label || value
  129. }
  130. function handleWellNameClick(taskId: number) {
  131. if (!taskId) return
  132. router.push({
  133. name: 'IotRdDailyReport',
  134. query: {
  135. taskId: taskId
  136. }
  137. })
  138. }
  139. </script>
  140. <template>
  141. <div
  142. class="grid grid-cols-[auto_minmax(0,1fr)] grid-rows-[auto_minmax(0,1fr)] gap-4 h-[calc(100vh-20px-var(--top-tool-height)-var(--tags-view-height)-var(--app-footer-height))]">
  143. <DeptTreeSelect
  144. :top-id="163"
  145. :deptId="deptId"
  146. v-model="query.deptId"
  147. :show-title="false"
  148. class="row-span-2" />
  149. <!-- <div class="p-4 bg-white dark:bg-[#1d1e1f] shadow rounded-lg row-span-2"> </div> -->
  150. <el-form
  151. size="default"
  152. class="min-h-62px bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 py-3 gap-x-8 gap-y-3 flex flex-wrap items-center justify-between">
  153. <div class="min-w-0 flex flex-1 flex-wrap items-center gap-x-8 gap-y-3">
  154. <el-form-item label="项目">
  155. <el-input
  156. v-model="query.contractName"
  157. placeholder="请输入项目"
  158. clearable
  159. @keyup.enter="handleQuery()"
  160. class="!w-240px" />
  161. </el-form-item>
  162. <el-form-item label="任务">
  163. <el-input
  164. v-model="query.taskName"
  165. placeholder="请输入任务"
  166. clearable
  167. @keyup.enter="handleQuery()"
  168. class="!w-240px" />
  169. </el-form-item>
  170. <el-form-item label="创建时间" prop="createTime">
  171. <el-date-picker
  172. v-model="query.createTime"
  173. value-format="YYYY-MM-DD HH:mm:ss"
  174. type="daterange"
  175. start-placeholder="开始日期"
  176. end-placeholder="结束日期"
  177. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  178. class="!w-300px max-w-full"
  179. :shortcuts="rangeShortcuts" />
  180. </el-form-item>
  181. </div>
  182. <el-form-item class="daily-report-actions shrink-0">
  183. <div class="flex flex-wrap items-center justify-end gap-3">
  184. <el-button type="primary" @click="handleQuery()">
  185. <Icon icon="ep:search" class="mr-5px" /> 搜索
  186. </el-button>
  187. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" />重置</el-button>
  188. <el-button
  189. type="primary"
  190. plain
  191. @click="openForm('create')"
  192. v-hasPermi="['pms:iot-rd-daily-report:create']">
  193. <Icon icon="ep:plus" class="mr-5px" /> 新增
  194. </el-button>
  195. <el-button type="success" plain @click="handleExport" :loading="exportLoading">
  196. <Icon icon="ep:download" class="mr-5px" /> 导出
  197. </el-button>
  198. </div>
  199. </el-form-item>
  200. </el-form>
  201. <div class="min-h-0 bg-white dark:bg-[#1d1e1f] shadow rounded-lg flex flex-col p-4">
  202. <div class="flex-1 relative">
  203. <el-auto-resizer class="absolute">
  204. <template #default="{ width, height }">
  205. <zm-table
  206. :data="pagedList"
  207. :loading="loading"
  208. :width="width"
  209. :max-height="height"
  210. :height="height"
  211. show-border>
  212. <zm-table-column
  213. prop="rdStatus"
  214. :label="t('project.status')"
  215. :real-value="
  216. (row: ListItem) => realValue(DICT_TYPE.PMS_PROJECT_RD_STATUS, row.rdStatus ?? '')
  217. ">
  218. <template #default="scope">
  219. <dict-tag
  220. :type="DICT_TYPE.PMS_PROJECT_RD_STATUS"
  221. :value="scope.row.rdStatus ?? ''" />
  222. </template>
  223. </zm-table-column>
  224. <zm-table-column prop="period" label="施工周期(D)" />
  225. <zm-table-column prop="taskStartDate" label="任务开始日期" />
  226. <zm-table-column prop="projectDeptName" label="项目部" />
  227. <zm-table-column prop="deptName" label="队伍" />
  228. <zm-table-column prop="wellName" label="井号">
  229. <template #default="scope">
  230. <el-link
  231. type="primary"
  232. @click="handleWellNameClick(scope.row.taskId)"
  233. underline="never">
  234. {{ scope.row.wellName }}
  235. </el-link>
  236. </template>
  237. </zm-table-column>
  238. <zm-table-column prop="techniques" label="工艺" />
  239. <zm-table-column prop="workloadDesign" label="总工作量" />
  240. <zm-table-column prop="totalDailyFuel" label="油耗(L)" />
  241. <zm-table-column label="已完成工作量">
  242. <template v-for="(column, index) in dynamicColumns" :key="index">
  243. <zm-table-column :prop="column" :label="column">
  244. <template #default="scope">
  245. {{ getWorkloadByUnit(scope.row.items, column) }}
  246. </template>
  247. </zm-table-column>
  248. </template>
  249. </zm-table-column>
  250. <zm-table-column
  251. prop="nonProductionRate"
  252. label="非生产时效"
  253. cover-formatter
  254. :real-value="
  255. (row) => (Number(row.nonProductionRate ?? 0) * 100).toFixed(2) + '%'
  256. " />
  257. <zm-table-column prop="manufactureName" label="甲方" action />
  258. </zm-table>
  259. </template>
  260. </el-auto-resizer>
  261. </div>
  262. <div class="h-10 mt-4 flex items-center justify-end">
  263. <el-pagination
  264. size="default"
  265. v-show="total > 0"
  266. v-model:current-page="currentPage"
  267. v-model:page-size="pageSize"
  268. :background="true"
  269. :page-sizes="[10, 20, 30, 50, 100]"
  270. :total="total"
  271. layout="total, sizes, prev, pager, next, jumper"
  272. @size-change="handleSizeChange"
  273. @current-change="handleCurrentChange" />
  274. </div>
  275. </div>
  276. </div>
  277. <IotRdDailyReportForm ref="formRef" @success="loadList" />
  278. </template>
  279. <style scoped>
  280. :deep(.el-form-item) {
  281. margin-bottom: 0;
  282. }
  283. .daily-report-actions :deep(.el-button + .el-button) {
  284. margin-left: 0;
  285. }
  286. </style>