restartIndex.uvue 20 KB

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