车间能级提升-智能设备管理系统
zhuguifei
2025-04-24 f0610c371668b042d36d7772cb04b49a2afc69ea
eims-ui-mobile/src/pages/maint/order-detail.vue
@@ -1,25 +1,30 @@
<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: {
    navigationBarTitleText: '工单明细',
    navigationStyle: 'custom',
    navigationBarBackgroundColor: '#4D80F0',
    'app-plus': {
      titleNView: {
        buttons: [
          {
            text: '提交',
            fontSize: '14px',
            color: '#FFFFFF',
          },
          {
            text: '',
            fontSize: '24px',
            color: '#FFFFFF',
          },
        ],
      },
    },
  },
}
</route>
<template>
  <view class="bg-base h-[100vh]">
    <wd-navbar
      title="工单明细"
      left-arrow
      @click-left="goBack"
      right-text="提交"
      @click-right="handleClickRight"
      custom-style="background: #4D80F0;"
      safeAreaInsetTop
    ></wd-navbar>
  <view class="bg-base container" safeAreaInsetTopBottom>
    <wd-form ref="form" :model="order" :rules="rules">
      <wd-cell-group custom-class="group" title="设备信息" border>
        <wd-cell title="设备名称" title-width="200rpx" is-link>
@@ -40,24 +45,12 @@
        <wd-cell title="计划保养日期" title-width="200rpx" is-link>
          <text>{{ order?.planTime }}</text>
        </wd-cell>
        <wd-datetime-picker
          label="保养开始时间"
          label-width="200rpx"
          placeholder="请选择时间"
          prop="startTime"
          v-model="startTime"
          @open="openStartTime"
          @confirm="handleStartTime"
        />
        <wd-datetime-picker
          label="保养结束时间"
          label-width="200rpx"
          placeholder="请选择时间"
          prop="endTime"
          v-model="endTime"
          @open="openEndTime"
          @confirm="handleEndTime"
        />
        <wd-cell title="保养开始时间" title-width="200rpx" is-link>
          <text>{{ order?.startTime }}</text>
        </wd-cell>
        <wd-cell title="保养完成时间" title-width="200rpx" is-link>
          <text>{{ order?.endTime }}</text>
        </wd-cell>
        <wd-textarea
          label="工作描述"
@@ -89,25 +82,54 @@
          clearable
        />
      </wd-cell-group>
      <view class="h-[2px] w-full bg-base"></view>
      <!--是否显示管理员验证按钮 (工单状态为2-待验证  且登录人role-leader管理员角色)-->
      <wd-cell
        title="验证通过(管理员)"
        title-width="200px"
        v-if="order.status === '2' && isLeader()"
      >
        <view style="text-align: right">
          <wd-switch v-model="isVerify" />
        </view>
      </wd-cell>
      <!--是否显示操作工保养完成 (工单状态为1-保养中 且登录人role-操作工角色)-->
      <wd-cell
        title="保养完成(操作工)"
        title-width="200px"
        v-if="order.status === '1' && isOperatorOrRepair()"
      >
        <view style="text-align: right">
          <wd-switch v-model="isFinish" />
        </view>
      </wd-cell>
    </wd-form>
    <view class="h-[100rpx]"></view>
  </view>
</template>
<script setup lang="ts">
import { getMaintOrder, updateMaintOrder } from '@/service/maint'
import { formatDate } from '@/utils/DateUtils'
import { reactive } from 'vue'
import { reactive, onMounted } from 'vue'
import { FormRules } from 'wot-design-uni/components/wd-form/types'
import { useToast, useMessage } from 'wot-design-uni'
import { isLeader, isOperatorOrRepair } from '@/utils/RoleUtils'
const toast = useToast()
const message = useMessage()
const fileList = ref<[]>()
const startTime = ref<number>(0)
const endTime = ref<number>(0)
// 管理员验是否通过
const isVerify = ref(false)
// 操作工保养是完成
const isFinish = ref(false)
interface MaintOrder {
  id: string
  equName: string
  assetNo: string
  status: string
  maintCode: string
  maintName: string
  planTime: string
@@ -120,6 +142,8 @@
const order = reactive<MaintOrder>({
  id: '',
  equName: '',
  assetNo: '',
  status: '',
  maintCode: '',
  maintName: '',
  planTime: '',
@@ -149,23 +173,6 @@
    },
  ],
}
function openStartTime() {
  if (startTime.value === 0) {
    startTime.value = Date.now()
  }
}
function openEndTime() {
  if (endTime.value === 0) {
    endTime.value = Date.now()
  }
}
function handleStartTime(value) {
  order.startTime = formatDate(new Date(value.value))
}
function handleEndTime(value) {
  order.endTime = formatDate(new Date(value.value))
}
function handleFileChange({ fileList }) {}
@@ -173,33 +180,32 @@
  getMaintOrder(id)
    .then((res: any) => {
      Object.assign(order, res)
      startTime.value = new Date(order.startTime).getTime()
      endTime.value = new Date(order.endTime).getTime()
    })
    .catch((res) => {})
}
function updateOrder(resolve: any) {
  updateMaintOrder(order)
function updateOrder(data: any, resolve: any) {
  updateMaintOrder(data)
    .then((res: any) => {
      resolve(true)
      toastSucces()
      uni.$emit('maint-order-refresh')
    })
    .catch((res) => {
      console.error(res)
    })
}
const goBack = () => {
  uni.navigateBack()
function toastSucces() {
  toast.success('操作成功')
}
function handleClickRight() {
function handleClickRight(data: any) {
  message
    .confirm({
      msg: '确定提交?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        updateOrder(resolve)
        updateOrder(data, resolve)
      },
    })
    .then(() => {})
@@ -208,21 +214,64 @@
    })
}
onNavigationBarButtonTap((e) => {
  if (e.index === 0) {
    // 管理员角色 且待验证状态
    if (isLeader()) {
      switch (order.status) {
        case '0':
        case '1':
          toast.warning('当前工单等待操作工保养状态,不可操作')
          break
        case '2':
          // 勾选验证,可提交
          if (isVerify.value) {
            // 修改工单状态为已完成
            const data: any = Object.assign({}, { id: order.id, status: order.status })
            data.status = '3'
            handleClickRight(data)
          } else {
            toast.warning('请选择是否验证通过')
          }
          break
        case '3':
          toast.warning('当前工单完成状态,不可操作')
          break
      }
    } else if (isOperatorOrRepair()) {
      switch (order.status) {
        case '0':
          break
        case '1':
          {
            const data = Object.assign({}, order)
            // 勾选工单完成,改变状态
            if (isFinish.value) {
              // 修改工单状态为待验证
              data.status = '2'
            }
            handleClickRight(data)
          }
          break
        case '2':
          toast.warning('当前工单等待管理验证状态,不可操作')
          break
        case '3':
          toast.warning('当前工单完成状态,不可操作')
          break
      }
    }
  }
})
onMounted(() => {})
onLoad((options) => {
  initMaintOrder(options.id)
})
</script>
<style scoped lang="scss">
:deep(.wd-navbar__text) {
  font-size: 26rpx;
  color: white;
}
:deep(.wd-icon-arrow-left:before),
:deep(.wd-navbar__title) {
  color: white;
  font-weight: bold !important;
  font-size: 32rpx;
.container {
  height: 100vh;
}
</style>