Blame view

pages-sub/problem/work-order-manage/distribution-order.vue 8.52 KB
fa775c6b   刘淇   养护计划调整
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  <template>
    <view class="page-container">
      <view class="work-order-form-content commonPageLRpadding">
        <up-form
            label-position="left"
            :model="workOrderForm"
            ref="workOrderFormRef"
            labelWidth="190rpx"
        >
          <!-- 1. 工单编号(从URL获取展示) -->
          <up-form-item
              label="工单编号"
              border-bottom
          >
            <up-input
                v-model="workOrderForm.orderNo"
                border="none"
                readonly
                placeholder="暂无工单编号"
            ></up-input>
          </up-form-item>
  
          <!-- 2. 养护员选择(必选,下拉框) -->
          <up-form-item
              label="养护员"
              prop="assigneeName"
              border-bottom
              required
              @click="handleActionSheetOpen('assignee'); hideKeyboard()"
          >
            <up-input
                v-model="workOrderForm.assigneeName"
                disabled
                disabled-color="#ffffff"
                placeholder="请选择养护员"
                border="none"
            ></up-input>
            <template #right>
              <up-icon name="arrow-right" size="16"></up-icon>
            </template>
          </up-form-item>
  
          <!-- 3. 处理意见(非必填,文本域) -->
          <up-form-item
              label="处理意见"
              prop="reason"
          >
            <up-textarea
                placeholder="请输入处理意见(可选,最多200字)"
                v-model.trim="workOrderForm.reason"
                count
                maxlength="200"
                rows="4"
            ></up-textarea>
          </up-form-item>
        </up-form>
      </view>
  
      <!-- 底部提交按钮 -->
      <view class="fixed-bottom-btn-wrap">
        <up-button
            type="primary"
            text="提交"
            @click="submitWorkOrder"
        ></up-button>
      </view>
  
      <!-- 养护员下拉弹窗 -->
      <up-action-sheet
          :show="showActionSheet"
          :actions="currentActionSheetData.list"
          :title="currentActionSheetData.title"
          @close="handleActionSheetClose"
          @select="handleActionSheetSelect"
      ></up-action-sheet>
    </view>
  </template>
  
  <script setup>
  import { ref, reactive } from 'vue'
  import { onLoad, onReady, onShow } from '@dcloudio/uni-app';
5059c4dd   刘淇   养护员提交养护工单
82
83
  import { getYlWorkersPage, universalApproval } from '@/api/work-order-manage/work-order-manage'
  import { nextStepMap } from '@/common/utils/common'
fa775c6b   刘淇   养护计划调整
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  import { useUserStore } from '@/pinia/user';
  const userStore = useUserStore();
  // ========== 表单Ref ==========
  const workOrderFormRef = ref(null)
  // ========== 页面状态 ==========
  const showActionSheet = ref(false)
  const currentActionSheetData = reactive({
    type: '',
    list: [],
    title: ''
  })
  // ========== 下拉列表数据 ==========
  const assigneeList = ref([]) // 养护员列表
  // ========== 工单表单数据(仅保留所需字段) ==========
  const workOrderForm = reactive({
dacff5e3   刘淇   养护员退回
99
    id:'',
3d474e84   刘淇   快速工单 加上业务线
100
    busiLine:'',
fa775c6b   刘淇   养护计划调整
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    taskId:'',
    orderNo: '',        // 工单编号(对应接口参数id)
    assigneeId: '',     // 养护员ID(对应接口参数nextAssignee)
    assigneeName: '',   // 养护员名称(显示用)
    reason: ''          // 处理意见(对应接口参数reason)
  })
  // ========== 表单校验规则(仅保留养护员必选校验) ==========
  const workOrderFormRules = reactive({
    assigneeName: [
      {type: 'string', required: true, message: '请选择养护员', trigger: ['change']}
    ],
    reason: [
      {type: 'string', max: 200, message: '处理意见最多200字', trigger: ['change', 'blur']}
    ]
  })
  // ========== 生命周期 ==========
  // onLoad - 获取URL中的工单编号
  onLoad((options) => {
    // 从URL参数中获取工单编号(参数名orderNo可根据实际修改)
    if (options && options.orderNo) {
      workOrderForm.orderNo = options.orderNo
      workOrderForm.taskId = options.taskId
dacff5e3   刘淇   养护员退回
123
      workOrderForm.id = options.id
3d474e84   刘淇   快速工单 加上业务线
124
125
126
      workOrderForm.busiLine = options.busiLine
  
  
fa775c6b   刘淇   养护计划调整
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    }
    console.log('从URL获取工单编号:', workOrderForm.orderNo)
  })
  onReady(() => {
    // 设置表单校验规则
    if (workOrderFormRef.value) {
      workOrderFormRef.value.setRules(workOrderFormRules)
    }
  })
  onShow(() => {
    // 加载养护员列表
    loadAssigneeList()
  })
  // ========== 加载养护员列表 ==========
  const loadAssigneeList = async () => {
    try {
      uni.showLoading({title: '获取养护员中...'})
      // 调用getYlWorkersPage接口(可根据接口要求传递参数,此处默认空对象)
      console.log(userStore.userInfo.user.busiLine)
      let queryData = {
        // roleCode:userStore.userInfo.roles,
3d474e84   刘淇   快速工单 加上业务线
148
149
        // roleCode: 'yl_worker',
        busiLine:  workOrderForm.busiLine,
fa775c6b   刘淇   养护计划调整
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
        // busiLine: userStore.userInfo.user.busiLine,
        pageNo: 1,
        pageSize: 100
      }
      const res = await getYlWorkersPage(queryData)
      uni.hideLoading()
      if (res.list.length > 0) {
        assigneeList.value = res.list.map(item => ({
          name: item.nickname,
          value: item.id,
          id: item.id
        }))
        console.log(currentActionSheetData.list)
      } else {
        uni.showToast({title: '所在班组暂无养护员,请先配置养护员', icon: 'none'})
      }
      console.log(currentActionSheetData.list)
    } catch (err) {
      uni.hideLoading()
      console.error('获取养护员列表失败:', err)
      uni.showToast({title: '获取养护员失败,请重试', icon: 'none'})
      assigneeList.value = []
    }
  }
  // ========== 方法定义 ==========
  /**
   * 打开养护员下拉弹窗
   */
  const handleActionSheetOpen = (type) => {
    // 判断养护员列表是否为空
    if (type === 'assignee' && assigneeList.value.length === 0) {
      uni.showToast({title: '暂无养护员数据可选', icon: 'none'})
      return
    }
    // 配置弹窗参数
    const configMap = {
      assignee: {
        title: '请选择养护员',
        list: assigneeList.value
      }
    }
    currentActionSheetData.type = type
    currentActionSheetData.title = configMap[type].title
    currentActionSheetData.list = configMap[type].list
    showActionSheet.value = true
  }
  /**
   * 关闭下拉弹窗
   */
  const handleActionSheetClose = () => {
    showActionSheet.value = false
    currentActionSheetData.type = ''
    currentActionSheetData.list = []
    currentActionSheetData.title = ''
  }
  /**
   * 养护员选择事件
   */
  const handleActionSheetSelect = (e) => {
    const {type} = currentActionSheetData
    if (type === 'assignee') {
      workOrderForm.assigneeName = e.name
      workOrderForm.assigneeId = e.value // 绑定养护员ID
      workOrderFormRef.value?.validateField('assigneeName')
    }
    showActionSheet.value = false
  }
  /**
   * 隐藏键盘
   */
  const hideKeyboard = () => {
    uni.hideKeyboard()
  }
  /**
   * 提交数据(使用ylTeamLeaderAssignWOrder接口,传递指定参数)
   */
  const submitWorkOrder = async () => {
    try {
      // 1. 表单校验(先校验养护员必选项)
      await workOrderFormRef.value.validate()
      // 2. 校验工单编号是否存在(避免无工单编号提交)
      if (!workOrderForm.orderNo) {
        uni.showToast({title: '工单编号不能为空', icon: 'none'})
        return
      }
      // 3. 构造接口所需参数
      const submitData = {
dacff5e3   刘淇   养护员退回
237
        workerDataId:workOrderForm.id,
5059c4dd   刘淇   养护员提交养护工单
238
239
240
241
        operateType: nextStepMap['ylTeamLeader'].operateTypePass,
        taskKey:'ylTeamLeader',
        agree:0,
        taskId: workOrderForm.taskId,        // 工单编码(对应接口参数id)
fa775c6b   刘淇   养护计划调整
242
243
244
245
246
247
248
        reason: workOrderForm.reason.trim(), // 处理建议(对应接口参数reason)
        nextAssignee: workOrderForm.assigneeId // 养护员ID(对应接口参数nextAssignee)
      }
      console.log('提交参数:', submitData)
      // 4. 显示加载提示
      uni.showLoading({title: '提交中...'})
      // 5. 调用指定接口 ylTeamLeaderAssignWOrder
5059c4dd   刘淇   养护员提交养护工单
249
      const res = await universalApproval(submitData)
fa775c6b   刘淇   养护计划调整
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
      // 6. 隐藏加载提示并给出成功反馈
      uni.hideLoading()
      uni.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 1000
      })
      // 7. 提交成功后返回上一页
      setTimeout(() => {
        uni.navigateTo({
          url: `/pages-sub/problem/work-order-manage/index`
        })
      }, 1000)
    } catch (error) {
      // 隐藏加载提示
      uni.hideLoading()
      // 区分表单校验失败和接口调用失败
      if (!Array.isArray(error)) {
        console.error('提交失败:', error)
        uni.showToast({
          title: '提交失败,请重试',
          icon: 'none',
          duration: 2000
        })
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  // 全局页面样式
  .page-container {
  
  }
  
  // 表单内容容器
  .work-order-form-content {
    background: #fff;
    margin-top: 10rpx;
  }
  
  
  </style>