IotInspectPlan.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  3. <ContentWrap>
  4. <el-form
  5. ref="formRef"
  6. :model="formData"
  7. :rules="formRules"
  8. style="margin-right: 4em; margin-left: 0.5em; margin-top: 1em"
  9. label-width="130px"
  10. >
  11. <div class="base-expandable-content">
  12. <el-row>
  13. <el-col :span="12">
  14. <el-form-item label="计划名称" prop="planTitle">
  15. <el-input v-model="formData.planTitle" placeholder="请输入计划名称" />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="12">
  19. <el-form-item label="单位" prop="planUnit">
  20. <el-select
  21. v-model="formData.planUnit"
  22. placeholder="请选择单位"
  23. :disabled="formType === 'update'"
  24. clearable
  25. >
  26. <el-option
  27. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_INSPECT_UNIT)"
  28. :key="dict.label"
  29. :label="dict.label"
  30. :value="dict.value"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="12">
  36. <el-form-item label="周期" prop="planCycle">
  37. <el-input
  38. type="number"
  39. v-model="formData.planCycle"
  40. :disabled="formType === 'update'"
  41. />
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="12">
  45. <el-form-item label="负责人" prop="charges">
  46. <el-select
  47. clearable
  48. filterable
  49. v-model="formData.charges"
  50. multiple
  51. style="width: 100%"
  52. >
  53. <el-option
  54. v-for="item in deptUsers"
  55. :key="item.id"
  56. :label="item.nickname"
  57. :value="item.id"
  58. />
  59. </el-select>
  60. </el-form-item>
  61. </el-col>
  62. <el-col :span="24">
  63. <el-form-item label="备注" prop="remark">
  64. <el-input type="textarea" v-model="formData.remark" />
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. </div>
  69. </el-form>
  70. </ContentWrap>
  71. <ContentWrap>
  72. <!-- 列表 -->
  73. <ContentWrap>
  74. <ContentWrap>
  75. <el-form
  76. class="-mb-15px"
  77. :model="queryParams"
  78. ref="queryFormRef"
  79. :inline="true"
  80. label-width="68px"
  81. >
  82. <el-form-item>
  83. <el-button @click="openForm" type="primary"
  84. ><Icon icon="ep:plus" class="mr-5px" /> 选择巡检设备</el-button
  85. >
  86. </el-form-item>
  87. </el-form>
  88. </ContentWrap>
  89. <ContentWrap>
  90. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  91. <el-table-column label="资产编号" align="center" prop="deviceCode" />
  92. <el-table-column label="设备名称" align="center" prop="deviceName" />
  93. <el-table-column label="路线名称" align="center" prop="routeName" />
  94. <el-table-column label="操作" align="center" min-width="120px">
  95. <template #default="scope">
  96. <div
  97. style="display: flex; justify-content: center; align-items: center; width: 100%"
  98. >
  99. <div style="margin-right: 10px">
  100. <Icon style="vertical-align: middle; color: #c36e5b" icon="ep:view" />
  101. <el-button
  102. style="vertical-align: middle"
  103. link
  104. type="warning"
  105. @click="viewRoute(scope.row.itemJson)"
  106. >
  107. 巡检路线
  108. </el-button>
  109. </div>
  110. <div>
  111. <Icon style="vertical-align: middle; color: #ea3434" icon="ep:zoom-out" />
  112. <el-button
  113. style="vertical-align: middle"
  114. link
  115. type="danger"
  116. @click="handleDelete(scope.row.code)"
  117. >
  118. 移除
  119. </el-button>
  120. </div>
  121. </div>
  122. </template>
  123. </el-table-column>
  124. </el-table>
  125. </ContentWrap>
  126. </ContentWrap>
  127. </ContentWrap>
  128. <ContentWrap>
  129. <el-form>
  130. <el-form-item style="float: right">
  131. <el-button @click="submitForm" type="primary" :disabled="formLoading">保 存</el-button>
  132. <el-button @click="close">取 消</el-button>
  133. </el-form-item>
  134. </el-form>
  135. </ContentWrap>
  136. <InspectItemList
  137. ref="inspectItemFormRef"
  138. :classify="formData.deviceClassify"
  139. :deviceId="formData.deviceId"
  140. @choose="inspectItemChoose"
  141. />
  142. <InspectRouteList ref="deviceFormRef" @choose="deviceChoose" />
  143. <RouteInspectItemDrawer
  144. ref="showDrawer"
  145. :model-value="drawerVisible"
  146. @update:model-value="(val) => (drawerVisible = val)"
  147. />
  148. </ContentWrap>
  149. </template>
  150. <script setup lang="ts">
  151. import * as UserApi from '@/api/system/user'
  152. import { useUserStore } from '@/store/modules/user'
  153. import { ref } from 'vue'
  154. import { useTagsViewStore } from '@/store/modules/tagsView'
  155. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  156. import InspectItemList from '@/views/pms/inspect/route/InspectItemList.vue'
  157. import InspectRouteList from '@/views/pms/inspect/plan/InspectRouteList.vue'
  158. import { IotInspectRouteVO } from '@/api/pms/inspect/route'
  159. import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
  160. import { IotInspectPlanApi, IotInspectPlanVO } from '@/api/pms/inspect/plan'
  161. import RouteInspectItemDrawer from '@/views/pms/inspect/plan/RouteInspectItemDrawer.vue'
  162. /** 维修工单 表单 */
  163. defineOptions({ name: 'InspectPlanAdd' })
  164. const { t } = useI18n() // 国际化
  165. const message = useMessage() // 消息弹窗
  166. const { delView } = useTagsViewStore() // 视图操作
  167. const { currentRoute, push } = useRouter()
  168. const dialogTitle = ref('') // 弹窗的标题
  169. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  170. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  171. const drawerVisible = ref<boolean>(false)
  172. const showDrawer = ref()
  173. const list = ref<IotInspectRouteVO[]>([]) // 列表的数据
  174. const { params, name } = useRoute() // 查询参数
  175. const id = params.id
  176. const productClassifyList = ref<Tree[]>([]) // 树形结构
  177. const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
  178. const formData = ref({
  179. id: undefined,
  180. planTitle: undefined,
  181. planCode: undefined,
  182. planCycle: undefined,
  183. planUnit: undefined,
  184. charge: undefined,
  185. charges: [],
  186. deviceIds: undefined,
  187. remark: undefined,
  188. deptId: undefined
  189. })
  190. const formRules = reactive({
  191. planTitle: [{ required: true, message: '巡检计划标题不能为空', trigger: 'blur' }],
  192. planCode: [{ required: true, message: '巡检计划编号不能为空', trigger: 'blur' }],
  193. planCycle: [{ required: true, message: '周期不能为空', trigger: 'blur' }],
  194. planUnit: [{ required: true, message: '单位不能为空', trigger: 'blur' }],
  195. charges: [{ required: true, message: '负责人不能为空', trigger: 'blur' }]
  196. })
  197. // 拖动状态管理
  198. const items = ref([])
  199. const deviceChoose = (rows) => {
  200. // formData.value.deviceId = row.id
  201. // formData.value.deviceName = row.deviceName
  202. // formData.value.deptId = row.deptId
  203. // deviceLabel.value = row.deviceName
  204. list.value = rows
  205. }
  206. const viewRoute = (itemJson) => {
  207. drawerVisible.value = true
  208. showDrawer.value.openDrawer(itemJson)
  209. }
  210. const formRef = ref() // 表单 Ref
  211. const inspectItemChoose = (rows) => {
  212. items.value = []
  213. items.value = rows
  214. }
  215. const deviceFormRef = ref()
  216. const openForm = () => {
  217. deviceFormRef.value.open()
  218. }
  219. const close = () => {
  220. delView(unref(currentRoute))
  221. push({ name: 'IotInspectPlan', params: {} })
  222. // delView(unref(currentRoute))
  223. // push({
  224. // name: 'IotInspectPlan',
  225. // query: {
  226. // date: new Date().getTime()
  227. // }
  228. // })
  229. }
  230. const { wsCache } = useCache()
  231. /** 提交表单 */
  232. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  233. const submitForm = async () => {
  234. // 校验表单
  235. await formRef.value.validate()
  236. // 提交请求
  237. formLoading.value = true
  238. try {
  239. const user = wsCache.get(CACHE_KEY.USER)
  240. formData.value.deviceIds = JSON.stringify(list.value)
  241. debugger
  242. const data = formData.value as unknown as IotInspectPlanVO
  243. if (formType.value === 'create') {
  244. formData.value.deptId = user.user.deptId
  245. await IotInspectPlanApi.createIotInspectPlan(data).then((res) => {
  246. // let cron = '';
  247. // if (formData.value.planUnit==='hour') {
  248. // // cron = '0 '+formData.value.planCycle+' * * * ?'
  249. // cron = '0 0/'+formData.value.planCycle+' * * * ?'
  250. // } else if (formData.value.planUnit==='day') {
  251. // cron = '0 0 0 */'+formData.value.planCycle+' * ?';
  252. // } else if (formData.value.planUnit==='month') {
  253. // cron = '0 0 0 1 */'+formData.value.planCycle+' ?'
  254. // }
  255. // debugger
  256. // const job = {
  257. // name: '巡检工单'+res,
  258. // status: 1,
  259. // handlerName: 'inspectCreateOrderJob',
  260. // handlerParam: res,
  261. // cronExpression: cron,
  262. // retryCount: 0,
  263. // retryInterval: 0,
  264. // monitorTimeout: 0
  265. // }
  266. // JobApi.createJob(job)
  267. })
  268. message.success(t('common.createSuccess'))
  269. close()
  270. } else {
  271. debugger
  272. console.log(JSON.stringify(data.charges))
  273. await IotInspectPlanApi.updateIotInspectPlan(data)
  274. message.success(t('common.updateSuccess'))
  275. close()
  276. }
  277. //创建定时任务
  278. // 发送操作成功的事件
  279. emit('success')
  280. } finally {
  281. formLoading.value = false
  282. }
  283. }
  284. /** 重置表单 */
  285. onMounted(async () => {
  286. const deptId = useUserStore().getUser.deptId
  287. deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
  288. if (id) {
  289. formType.value = 'update'
  290. const iotInspectPlan = await IotInspectPlanApi.getIotInspectPlan(id)
  291. formData.value = iotInspectPlan
  292. debugger
  293. list.value = JSON.parse(iotInspectPlan.deviceIds)
  294. } else {
  295. formType.value = 'create'
  296. }
  297. })
  298. const handleDelete = async (id: number) => {
  299. try {
  300. const index = list.value.findIndex((item) => item.code === id)
  301. if (index !== -1) {
  302. // 通过 splice 删除元素
  303. list.value.splice(index, 1)
  304. }
  305. } catch {}
  306. }
  307. </script>
  308. <style scoped>
  309. .base-expandable-content {
  310. overflow: hidden; /* 隐藏溢出的内容 */
  311. transition: max-height 0.3s ease; /* 平滑过渡效果 */
  312. }
  313. /* 横向布局容器 */
  314. </style>