restartIndex.uvue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <template>
  2. <view class="detail-page">
  3. <scroll-view class="detail-content" :scroll-y="true">
  4. <!-- 复运 -->
  5. <view class="info-section">
  6. <view class="section-title">
  7. <text class="section-title-text">工单信息</text>
  8. </view>
  9. <view class="info-card">
  10. <view class="info-item">
  11. <text class="info-label">工单编码</text>
  12. <text class="info-value">{{ workOrderProjectNo ?? '' }}</text>
  13. </view>
  14. <view class="info-item">
  15. <text class="info-label">风机编号</text>
  16. <text class="info-value">{{ pcsDeviceName ?? '' }}</text>
  17. </view>
  18. <view class="info-item">
  19. <text class="info-label">维保中心</text>
  20. <text class="info-value">{{ gxtCenter ?? '' }}</text>
  21. </view>
  22. <view class="info-item">
  23. <text class="info-label">场站</text>
  24. <text class="info-value">{{ pcsStationName ?? '' }}</text>
  25. </view>
  26. <view class="info-item">
  27. <text class="info-label">机型</text>
  28. <text class="info-value">{{ brand ?? '' }} {{ model ?? '' }}</text>
  29. </view>
  30. <view class="info-item">
  31. <text class="info-label">下发时间</text>
  32. <text class="info-value">{{ assignTime ?? '' }}</text>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="info-section">
  37. <view class="info-card">
  38. <view class="info-item">
  39. <view class="info-label">
  40. <text class="form-label required">恢复运行时间<text style="color: red;">*</text></text>
  41. </view>
  42. <view class="info-value">
  43. <view class="form-picker" @click="showshutdownTimePicker = true">
  44. <input
  45. class="input-field"
  46. placeholder="请选择恢复运行时间"
  47. v-model="restartTime"
  48. type="none"
  49. />
  50. </view>
  51. </view>
  52. </view>
  53. <view class="info-item">
  54. <view class="info-label">
  55. <text class="form-label required">损失电量(kWh)<text style="color: red;">*</text></text>
  56. </view>
  57. <view class="info-value">
  58. <input
  59. class="input-field"
  60. placeholder="请输入损失电量"
  61. v-model="lostPower"
  62. type="digit"
  63. @input="handleLostPowerInput"
  64. @blur="validateLostPower"
  65. />
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 时间选择器弹窗 -->
  71. <!-- Start Date Picker -->
  72. <l-popup v-model="showshutdownTimePicker" position="bottom">
  73. <l-date-time-picker
  74. title="选择恢复运行时间"
  75. :mode="1 | 2 | 4 | 8 | 16"
  76. format="YYYY-MM-DD HH:mm"
  77. :modelValue="restartTime"
  78. confirm-btn="确定"
  79. cancel-btn="取消"
  80. @confirm="onStartDateConfirm"
  81. @cancel="showshutdownTimePicker = false">
  82. </l-date-time-picker>
  83. </l-popup>
  84. </scroll-view>
  85. <!-- 接单按钮 -->
  86. <view class="accept-button-container" v-if="checkPermi(orderType == '2' ? ['gxt:maintenance:order:restart'] : ['gxt:repairOrder:restart'])">
  87. <button class="accept-button" @click="handleRestartOrderr">{{ isDealing ? '复运中...' : '复 运' }}</button>
  88. </view>
  89. <!-- 加载中状态 -->
  90. <view v-if="loading" class="loading-mask">
  91. <text class="loading-text">加载中...</text>
  92. </view>
  93. </view>
  94. </template>
  95. <script setup lang="uts">
  96. import { ref } from 'vue'
  97. import type { acceptOrderInfo } from '../../../types/order'
  98. import type { WorkOrderFlow } from '../../../types/flow'
  99. import { getOrderInfoById, getRepairOrderInfoById, restartOrder } from '../../../api/order/detail'
  100. import type { SysDictData } from '../../../types/dict'
  101. import { getDictDataByType } from '../../../api/dict/index'
  102. import type { UserInfo } from '../../../types/user'
  103. import {checkPermi} from '../../../utils/storage'
  104. const teamLeaderName = ref<string>("")
  105. const statusDictList = ref<SysDictData[]>([]) // 工单状态字典列表
  106. // 添加字典加载状态
  107. const dictLoaded = ref<boolean>(false)
  108. const restartTime = ref<string>("")
  109. const lostPower = ref<string>("")
  110. // 工单信息
  111. const orderId = ref<string>('')
  112. const workOrderProjectNo = ref<string>('')
  113. const workOrderStatus = ref<string>('')
  114. const orderType = ref<string>('')
  115. const pcsDeviceName = ref<string>('')
  116. const gxtCenter = ref<string>('')
  117. const pcsStationName = ref<string>('')
  118. const brand = ref<string>('')
  119. const model = ref<string>('')
  120. const assignTime = ref<string>('')
  121. const showshutdownTimePicker = ref<boolean>(false)
  122. // 输入过滤方法,只允许数字和小数点,并确保值大于0
  123. const handleLostPowerInput = () => {
  124. let value = lostPower.value;
  125. // 只保留数字和小数点
  126. value = value.replace(/[^\d.]/g, '');
  127. // 防止出现多个小数点
  128. const parts = value.split('.');
  129. if (parts.length > 2) {
  130. // 如果有多个小数点,只保留第一个小数点
  131. value = parts[0] + '.' + parts.slice(1).join('');
  132. }
  133. // 防止以多个小数点开头
  134. if (value.startsWith('..')) {
  135. value = value.substring(1);
  136. }
  137. // 防止以小数点开头但后面没有数字的情况(如单独的小数点)
  138. if (value === '.') {
  139. value = '';
  140. }
  141. // 更新值
  142. lostPower.value = value;
  143. };
  144. // 验证损失电量是否大于0
  145. const validateLostPower = () => {
  146. if (lostPower.value.trim() !== '') {
  147. const lostPowerNum = parseFloat(lostPower.value);
  148. if (isNaN(lostPowerNum) || lostPowerNum <= 0) {
  149. uni.showToast({
  150. title: '损失电量必须大于0',
  151. icon: 'none'
  152. });
  153. }
  154. }
  155. };
  156. function onStartDateConfirm(value: string) {
  157. // 检查结束时间是否小于新的恢复运行时间
  158. restartTime.value = value
  159. showshutdownTimePicker.value = false
  160. }
  161. // 获取工单状态字典列表
  162. const loadStatusDictList = async (): Promise<void> => {
  163. try {
  164. const result = await getDictDataByType('gxt_repair_order_flow_action_type')
  165. const resultObj = result as UTSJSONObject
  166. if (resultObj['code'] == 200) {
  167. const data = resultObj['data'] as any[]
  168. const dictData: SysDictData[] = []
  169. if (data.length > 0) {
  170. for (let i = 0; i < data.length; i++) {
  171. const item = data[i] as UTSJSONObject
  172. // 只提取需要的字段
  173. const dictItem: SysDictData = {
  174. dictValue: item['dictValue'] as string | null,
  175. dictLabel: item['dictLabel'] as string | null,
  176. dictCode: null,
  177. dictSort: null,
  178. dictType: null,
  179. cssClass: null,
  180. listClass: null,
  181. isDefault: null,
  182. status: null,
  183. default: null,
  184. createTime: null,
  185. remark: null
  186. }
  187. dictData.push(dictItem)
  188. }
  189. }
  190. statusDictList.value = dictData
  191. dictLoaded.value = true
  192. }
  193. } catch (e: any) {
  194. console.error('获取工单状态字典失败:', e.message)
  195. dictLoaded.value = true
  196. }
  197. }
  198. const isDealing = ref(false)
  199. const hasDealed = ref(false)
  200. // 处理接单操作
  201. const handleRestartOrderr = async (): Promise<void> => {
  202. if (restartTime.value.trim() === '') {
  203. uni.showToast({
  204. title: '请选择恢复运行时间',
  205. icon: 'none'
  206. })
  207. return
  208. }
  209. if (lostPower.value.trim() === '') {
  210. uni.showToast({
  211. title: '请输入损失电量',
  212. icon: 'none'
  213. })
  214. return
  215. }
  216. // 验证损失电量必须大于0
  217. const lostPowerNum = parseFloat(lostPower.value);
  218. if (isNaN(lostPowerNum) || lostPowerNum <= 0) {
  219. uni.showToast({
  220. title: '损失电量必须大于0',
  221. icon: 'none'
  222. })
  223. return
  224. }
  225. if (isDealing.value || hasDealed.value) return // 双重保险
  226. isDealing.value = true
  227. try {
  228. const submitData = {
  229. id: orderId.value,
  230. orderType: orderType.value,
  231. workOrderProjectNo: workOrderProjectNo.value,
  232. workOrderStatus: workOrderStatus.value,
  233. restartTime: restartTime.value,
  234. lostPower: lostPower.value
  235. } as UTSJSONObject;
  236. const result = await restartOrder(submitData)
  237. const resultObj = result as UTSJSONObject
  238. const code = resultObj['code'] as number
  239. if (code == 200) {
  240. uni.showToast({
  241. title: '复运成功',
  242. icon: 'success'
  243. })
  244. hasDealed.value = true
  245. // 使用事件总线通知列表页面刷新
  246. uni.$emit('refreshOrderList', {})
  247. uni.$emit('refreshAssignedCount')
  248. uni.$emit('refreshOverdueCount')
  249. uni.$emit('refreshApproveCount')
  250. uni.$emit('refreshSuspendedCount')
  251. // 接单成功后返回上一页
  252. setTimeout(() => {
  253. uni.navigateBack()
  254. }, 800)
  255. } else {
  256. // 处理业务错误
  257. uni.showToast({
  258. title: resultObj['msg'] as string,
  259. icon: 'none'
  260. })
  261. }
  262. } catch (error: any) {
  263. console.error('请求失败:', error);
  264. uni.showToast({
  265. title: error.message ?? '挂起失败',
  266. icon: 'none'
  267. })
  268. } finally {
  269. isDealing.value = false // 无论成功失败都解锁
  270. }
  271. }
  272. const loading = ref<boolean>(false)
  273. // 获取操作类型名称
  274. const getActionTypeName = (item: string | null): string | null => {
  275. if (item == null) return ''
  276. // const orderInfoItem = item as orderInfo
  277. const rawStatus = item
  278. if (rawStatus==null) return ''
  279. // 如果字典尚未加载,返回原始值
  280. if (!dictLoaded.value) {
  281. return rawStatus
  282. }
  283. // 查找字典中对应的标签
  284. const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
  285. return dictItem!=null ? dictItem.dictLabel : rawStatus
  286. }
  287. // 加载详情数据
  288. const loadDetail = async (id: string, orderType?: number): Promise<void> => {
  289. try {
  290. loading.value = true
  291. let result: any;
  292. // 根据orderType决定调用哪个API
  293. if (orderType == 1) {
  294. // 维修工单
  295. result = await getRepairOrderInfoById(id)
  296. } else {
  297. // 维保工单
  298. result = await getOrderInfoById(id)
  299. }
  300. // 提取响应数据
  301. const resultObj = result as UTSJSONObject
  302. const code = resultObj['code'] as number
  303. const data = resultObj['data'] as UTSJSONObject | null
  304. if (code == 200 && data != null) {
  305. orderId.value = id
  306. workOrderStatus.value = (data['workOrderStatus'] as string | null) ?? ''
  307. workOrderProjectNo.value = (data['workOrderProjectNo'] as string | null) ?? ''
  308. pcsDeviceName.value = (data['pcsDeviceName'] as string | null) ?? ''
  309. gxtCenter.value = (data['gxtCenter'] as string | null) ?? ''
  310. pcsStationName.value = (data['pcsStationName'] as string | null) ?? ''
  311. brand.value = (data['brand'] as string | null) ?? ''
  312. model.value = (data['model'] as string | null) ?? ''
  313. assignTime.value = (data['assignTime'] as string | null) ?? ''
  314. } else {
  315. const msg = resultObj['msg'] as string | null
  316. uni.showToast({
  317. title: msg ?? '加载失败',
  318. icon: 'none'
  319. })
  320. }
  321. } catch (e: any) {
  322. uni.showToast({
  323. title: e.message ?? '加载失败',
  324. icon: 'none'
  325. })
  326. } finally {
  327. loading.value = false
  328. }
  329. }
  330. // 页面加载
  331. onLoad((options: any) => {
  332. const params = options as UTSJSONObject
  333. const id = params['id'] as string | null
  334. const orderTypeParam = params['orderType'] as string | null
  335. if (id != null && orderTypeParam != null) {
  336. // 先尝试从参数中获取orderType
  337. const orderTypeNumber = parseInt(orderTypeParam)
  338. loadDetail(id, orderTypeNumber)
  339. }
  340. })
  341. // 初始化
  342. onMounted(() => {
  343. // loadStatusDictList()
  344. })
  345. </script>
  346. <style lang="scss">
  347. .detail-page {
  348. flex: 1;
  349. background-color: #e8f0f9;
  350. }
  351. .detail-content {
  352. flex: 1;
  353. padding: 20rpx 0;
  354. }
  355. .info-section {
  356. margin: 0 30rpx 24rpx;
  357. .section-title {
  358. position: relative;
  359. padding-left: 20rpx;
  360. margin-bottom: 20rpx;
  361. &::before {
  362. // content: '';
  363. position: absolute;
  364. left: 0;
  365. top: 50%;
  366. transform: translateY(-50%);
  367. width: 8rpx;
  368. height: 32rpx;
  369. background-color: #007aff;
  370. border-radius: 4rpx;
  371. }
  372. &-text {
  373. font-size: 32rpx;
  374. font-weight: bold;
  375. color: #333333;
  376. }
  377. }
  378. .info-card {
  379. background-color: #ffffff;
  380. border-radius: 16rpx;
  381. padding: 30rpx;
  382. .info-item {
  383. flex-direction: row;
  384. padding: 20rpx 0;
  385. border-bottom: 1rpx solid #f0f0f0;
  386. &:last-child {
  387. border-bottom: none;
  388. }
  389. &.full-width {
  390. flex-direction: column;
  391. .info-label {
  392. margin-bottom: 12rpx;
  393. }
  394. .info-value {
  395. line-height: 44rpx;
  396. }
  397. }
  398. .info-label {
  399. width: 240rpx;
  400. font-size: 28rpx;
  401. color: #666666;
  402. white-space: nowrap;
  403. }
  404. .info-value {
  405. flex: 1;
  406. font-size: 28rpx;
  407. color: #333333;
  408. text-align: left;
  409. &.highlight {
  410. color: #007aff;
  411. font-weight: bold;
  412. }
  413. &.input {
  414. text-align: left;
  415. border: 1rpx solid #e0e0e0;
  416. border-radius: 8rpx;
  417. padding: 10rpx;
  418. }
  419. }
  420. }
  421. .flow-item {
  422. padding: 20rpx 0;
  423. border-bottom: 1rpx solid #f0f0f0;
  424. &:last-child {
  425. border-bottom: none;
  426. }
  427. .flow-header {
  428. flex-direction: row;
  429. justify-content: space-between;
  430. margin-bottom: 10rpx;
  431. .flow-operator {
  432. font-size: 28rpx;
  433. color: #333333;
  434. font-weight: bold;
  435. }
  436. .flow-time {
  437. font-size: 24rpx;
  438. color: #999999;
  439. }
  440. }
  441. .flow-content {
  442. flex-direction: column;
  443. .flow-action {
  444. font-size: 26rpx;
  445. color: #666666;
  446. margin-bottom: 8rpx;
  447. }
  448. .flow-remark {
  449. font-size: 24rpx;
  450. color: #999999;
  451. background-color: #f5f5f5;
  452. padding: 10rpx;
  453. border-radius: 8rpx;
  454. }
  455. }
  456. }
  457. .no-data {
  458. text-align: center;
  459. padding: 40rpx 0;
  460. font-size: 28rpx;
  461. color: #999999;
  462. }
  463. }
  464. }
  465. .accept-button-container {
  466. padding: 30rpx 30rpx 50rpx;
  467. background-color: #ffffff;
  468. .accept-button {
  469. width: 100%;
  470. height: 80rpx;
  471. background-color: #007aff;
  472. color: #ffffff;
  473. font-size: 32rpx;
  474. border-radius: 16rpx;
  475. border: none;
  476. &:active {
  477. background-color: #0062cc;
  478. }
  479. }
  480. }
  481. .loading-mask {
  482. position: absolute;
  483. top: 0;
  484. left: 0;
  485. right: 0;
  486. bottom: 0;
  487. justify-content: center;
  488. align-items: center;
  489. background-color: rgba(0, 0, 0, 0.3);
  490. .loading-text {
  491. padding: 30rpx 60rpx;
  492. background-color: rgba(0, 0, 0, 0.7);
  493. color: #ffffff;
  494. font-size: 28rpx;
  495. border-radius: 12rpx;
  496. }
  497. }
  498. .picker-modal {
  499. position: fixed;
  500. top: 0;
  501. left: 0;
  502. right: 0;
  503. bottom: 0;
  504. z-index: 1000;
  505. }
  506. .modal-mask {
  507. position: absolute;
  508. top: 0;
  509. left: 0;
  510. right: 0;
  511. bottom: 0;
  512. background-color: rgba(0, 0, 0, 0.5);
  513. }
  514. .modal-content {
  515. position: absolute;
  516. bottom: 0;
  517. left: 0;
  518. right: 0;
  519. background-color: #ffffff;
  520. border-top-left-radius: 16rpx;
  521. border-top-right-radius: 16rpx;
  522. max-height: 700rpx;
  523. }
  524. .modal-header {
  525. flex-direction: row;
  526. justify-content: space-between;
  527. align-items: center;
  528. padding: 30rpx;
  529. border-bottom: 1rpx solid #f0f0f0;
  530. }
  531. .modal-title {
  532. font-size: 32rpx;
  533. font-weight: bold;
  534. color: #333333;
  535. }
  536. .modal-close {
  537. font-size: 28rpx;
  538. color: #007aff;
  539. }
  540. .modal-body {
  541. max-height: 600rpx;
  542. }
  543. .picker-option {
  544. flex-direction: row;
  545. justify-content: space-between;
  546. align-items: center;
  547. padding: 24rpx 30rpx;
  548. border-bottom: 1rpx solid #f0f0f0;
  549. }
  550. .picker-option.selected {
  551. background-color: #f8f9fa;
  552. }
  553. .option-text {
  554. font-size: 28rpx;
  555. color: #333333;
  556. }
  557. .option-check {
  558. font-size: 28rpx;
  559. color: #007aff;
  560. }
  561. .form-picker {
  562. flex: 1;
  563. }
  564. .picker-display {
  565. flex-direction: row;
  566. justify-content: space-between;
  567. align-items: center;
  568. min-height: 40rpx;
  569. }
  570. .selected-value {
  571. font-size: 28rpx;
  572. color: #333333;
  573. }
  574. .placeholder {
  575. font-size: 28rpx;
  576. color: #999999;
  577. }
  578. .arrow {
  579. font-size: 24rpx;
  580. color: #999999;
  581. margin-left: 12rpx;
  582. }
  583. .reject-reason-textarea {
  584. width: 100%;
  585. min-height: 100rpx;
  586. line-height: 1.5;
  587. }
  588. </style>