patrolSubTasks.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="app-container p-2">
  3. <el-row :gutter="20">
  4. <!-- 基础信息 -->
  5. <el-col :lg="30" :xs="24" style="">
  6. <el-form-item>
  7. <div class="back-btn" @click="goBack">
  8. <el-icon><Back /></el-icon>
  9. 返回上一级
  10. </div>
  11. </el-form-item>
  12. <el-row :span="24" :gutter="10">
  13. <el-col :span="20" label="任务名称">
  14. <h2 key="business" style="font-weight: bolder">{{ detailData.business }}</h2>
  15. </el-col>
  16. <el-col :span="1.5">
  17. <el-button type="primary" @click="handleUpdate()"> 编辑 </el-button>
  18. </el-col>
  19. <el-col :span="1.5">
  20. <el-button type="primary" @click="handlefinal()"> 完成任务 </el-button>
  21. </el-col>
  22. <el-col :span="1.5">
  23. <el-button type="danger" @click="handleDelete()"> 删除 </el-button>
  24. </el-col>
  25. </el-row>
  26. <div class="line" style="background: #e7e7e7; width: auto; height: 0.6px; position: relative"></div>
  27. <h3>基础信息</h3>
  28. <el-card style="margin-top: 10px" shadow="hover">
  29. <el-descriptions title="">
  30. <el-descriptions-item key="task_number" label="任务编号:">{{ detailData.task_number }}</el-descriptions-item>
  31. <el-descriptions-item key="business" label="巡查业务:">{{ detailData.business }}</el-descriptions-item>
  32. <el-descriptions-item key="create_by" label="创建人:">{{ detailData.create_by }}</el-descriptions-item>
  33. <el-descriptions-item key="create_time" label="创建时间:">{{ detailData.create_time }}</el-descriptions-item>
  34. <el-descriptions-item key="task_time" label="巡查时间范围:">{{ detailData.task_time }}</el-descriptions-item>
  35. <el-descriptions-item key="cycle" label="巡查周期:">{{ detailData.cycle }}</el-descriptions-item>
  36. <el-descriptions-item key="inspection_range" label="巡查范围:">{{ detailData.inspection_range }}</el-descriptions-item>
  37. <el-descriptions-item key="task_status" label="任务状态:">{{ detailData.task_status }}</el-descriptions-item>
  38. </el-descriptions>
  39. </el-card>
  40. </el-col>
  41. <el-col :lg="30" :xs="24">
  42. <h3>子任务记录</h3>
  43. <el-card style="margin-top: 10px" shadow="hover">
  44. <el-table ref="multipleTable" v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
  45. <el-table-column label="巡查业务" align="center" :formatter="(row) => businessMap[row.business]" />
  46. <el-table-column label="要求巡查时间" align="center" prop="task_time" />
  47. <el-table-column label="巡查周期" align="center" :formatter="(row) => cycleMap[row.cycle]" />
  48. <el-table-column label="巡查范围" align="center" :formatter="(row) => inspectionRangeMap[row.inspection_range]" />
  49. <el-table-column label="执行日期" align="center" prop="create_time" />
  50. <el-table-column label="已完成" align="center" prop="completed_num">
  51. <template #default="scope">
  52. <el-text class="common-btn-text-primary" @click="handleCompletedClick(scope.row)">{{ scope.row.completed_num }}</el-text>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="未完成" align="center" prop="incomplete_num">
  56. <template #default="scope">
  57. <el-text class="common-btn-text-primary" @click="handleIncompletedClick(scope.row)">{{ scope.row.incomplete_num }}</el-text>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  61. <template #default="scope">
  62. <el-text class="common-btn-text-primary" @click="handleResult(scope.row)">巡查结果</el-text>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <pagination
  67. v-show="total > 0"
  68. v-model:page="queryParams.page"
  69. v-model:limit="queryParams.pageSize"
  70. :total="total"
  71. @pagination="fetchSubTasks"
  72. />
  73. </el-card>
  74. </el-col>
  75. </el-row>
  76. </div>
  77. <PatrolSubResult v-if="patrolSubResultState.show" :event-id="patrolSubResultState.eventId" @close="handleCancel" />
  78. <PatrolTaskEdit v-if="patrolTaskEditState.show" :event-id="patrolTaskEditState.eventId" @close="handleCancel" @refresh-parent="refreshBoth" />
  79. <Completed v-if="completedState.show" :event-id="completedState.eventId" @close="handleCancel" />
  80. <Incompleted v-if="incompletedState.show" :event-id="incompletedState.eventId" @close="handleCancel" />
  81. </template>
  82. <script setup lang="ts">
  83. import { workDetail, workSubList, updatetask, deleteRisk } from '@/api/inspectionWork/inspector';
  84. import { reactive, ref } from 'vue';
  85. import { ElMessageBox } from 'element-plus';
  86. import PatrolSubResult from './patrolSubResult.vue';
  87. import PatrolTaskEdit from './patrolTaskEdit.vue';
  88. import Completed from './completed.vue';
  89. import Incompleted from './incompleted.vue';
  90. import { to } from 'await-to-js';
  91. const props = defineProps<{ eventId: string }>();
  92. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  93. const total = ref(0);
  94. const tableData = ref([]);
  95. const multiple = ref(true);
  96. const ids = ref<Array<number | string>>([]);
  97. const single = ref(true);
  98. const emits = defineEmits(['close']);
  99. const detailData = ref({
  100. task_number: '',
  101. business: '',
  102. task_time: '',
  103. cycle: '',
  104. id: '',
  105. inspection_range: '',
  106. task_status: '',
  107. create_time: '',
  108. create_by: ''
  109. });
  110. const initFormData = reactive({
  111. finished: '',
  112. business: '',
  113. task_time: '',
  114. cycle: '',
  115. id: '',
  116. inspection_range: '',
  117. run_time: '',
  118. unfinished: ''
  119. });
  120. const data = reactive({
  121. form: { ...initFormData },
  122. queryParams: {
  123. page: 1,
  124. pageSize: 10
  125. }
  126. });
  127. const { queryParams, form } = toRefs(data);
  128. // 映射表
  129. const businessMap = {
  130. 0: '城市隐患巡查',
  131. 1: '森林防火巡查',
  132. 2: '重点危化企业巡查',
  133. 3: '重点水库水位巡查'
  134. };
  135. const cycleMap = {
  136. 0: '每年',
  137. 1: '每月',
  138. 2: '每周',
  139. 3: '每日',
  140. 4: '一次'
  141. };
  142. const inspectionRangeMap = {
  143. 0: '市级',
  144. 1: '区县级',
  145. 2: '镇街级',
  146. 3: '村居级'
  147. };
  148. const taskStatusMap = {
  149. 0: '未开始',
  150. 1: '进行中',
  151. 2: '未完成',
  152. 3: '已完结'
  153. };
  154. let patrolTaskEditState = reactive({
  155. show: false,
  156. eventId: ''
  157. });
  158. let patrolSubResultState = reactive({
  159. show: false,
  160. eventId: ''
  161. });
  162. let completedState = reactive({
  163. show: false,
  164. eventId: ''
  165. });
  166. let incompletedState = reactive({
  167. show: false,
  168. eventId: ''
  169. });
  170. const handleCancel = () => {
  171. patrolTaskEditState.show = false;
  172. patrolSubResultState.show = false;
  173. completedState.show = false;
  174. incompletedState.show = false;
  175. };
  176. const handleUpdate = () => {
  177. patrolTaskEditState.eventId = props.eventId; // 假设eventId是id字段
  178. patrolTaskEditState.show = true;
  179. };
  180. const handleResult = (row) => {
  181. if (row) {
  182. patrolSubResultState.eventId = row.id; // 假设eventId是id字段
  183. patrolSubResultState.show = true;
  184. }
  185. };
  186. const handleCompletedClick = (row) => {
  187. if (row) {
  188. completedState.eventId = row.id; // 假设eventId是id字段
  189. completedState.show = true;
  190. }
  191. };
  192. const handleIncompletedClick = (row) => {
  193. if (row) {
  194. incompletedState.eventId = row.id; // 假设eventId是id字段
  195. incompletedState.show = true;
  196. }
  197. };
  198. const loading = ref(false);
  199. const fetchWorkDetail = () => {
  200. loading.value = true;
  201. workDetail(props.eventId) // 使用从父组件接收到的eventId
  202. .then((res) => {
  203. if (res.code === 200) {
  204. let data = res.data;
  205. // 转换business
  206. data.business = businessMap[data.business] || '未知';
  207. // 转换cycle
  208. data.cycle = cycleMap[data.cycle] || '未知';
  209. // 转换inspection_range
  210. data.inspection_range = inspectionRangeMap[data.inspection_range] || '未知';
  211. // 转换task_status
  212. data.task_status = taskStatusMap[data.task_status] || '未知';
  213. detailData.value = data; // 将转换后的数据赋值给detailData
  214. } else {
  215. console.error(res.msg);
  216. }
  217. })
  218. .finally(() => {
  219. loading.value = false;
  220. });
  221. };
  222. const fetchSubTasks = () => {
  223. return workSubList(props.eventId, queryParams.value)
  224. .then((res) => {
  225. if (res.code === 200) {
  226. tableData.value = res.data;
  227. total.value = res.total;
  228. console.log('Fetched subtasks data:', tableData.value);
  229. } else {
  230. console.error(res.msg);
  231. }
  232. })
  233. .catch((error) => {
  234. console.error('Error fetching sub tasks:', error);
  235. });
  236. };
  237. const handleDelete = async () => {
  238. const [err] = await to(proxy?.$modal.confirm('是否确认删除?') as any);
  239. if (!err) {
  240. await deleteRisk([props.eventId]);
  241. proxy?.$modal.msgSuccess('删除成功');
  242. emits('close');
  243. emits('refreshsub');
  244. }
  245. };
  246. const handleSelectionChange = (selection) => {
  247. ids.value = selection.map((item) => item.id);
  248. single.value = selection.length != 1;
  249. multiple.value = !selection.length;
  250. };
  251. const handlefinal = async () => {
  252. try {
  253. const confirmed = await ElMessageBox.confirm('确定要完结任务吗?', '提示', {
  254. confirmButtonText: '确定',
  255. cancelButtonText: '取消',
  256. type: 'warning'
  257. });
  258. if (confirmed) {
  259. try {
  260. await updatetask({ id: props.eventId, task_status: '3' });
  261. console.log(`任务 ${props.eventId} 已完结`);
  262. fetchWorkDetail();
  263. } catch (error) {
  264. console.error(`任务 ${props.eventId} 完结失败:`, error);
  265. }
  266. } else {
  267. console.log(`任务 ${props.eventId} 未完结`);
  268. }
  269. } catch (error) {
  270. console.error('确认对话框处理失败:', error);
  271. }
  272. };
  273. const goBack = () => {
  274. emits('close');
  275. };
  276. const refreshBoth = () => {
  277. fetchWorkDetail();
  278. fetchSubTasks();
  279. };
  280. onMounted(() => {
  281. fetchWorkDetail(); // 在组件挂载后调用此函数以获取数据
  282. fetchSubTasks();
  283. });
  284. </script>