Blame view

src/components/inspection/editInspectionPlan.vue 8.98 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
1d73dc48   wuxw   继续晚上巡检功能
2
    <el-dialog :title="$t('inspectionPlan.modify')" :visible.sync="visible" width="80%" @close="resetForm">
56c7fec9   wuxw   巡检功能测试完成
3
      <el-form ref="form" :model="formData" label-width="150px" class="text-left">
1d73dc48   wuxw   继续晚上巡检功能
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('inspectionPlan.planName')" prop="inspectionPlanName" required>
              <el-input v-model="formData.inspectionPlanName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('inspectionPlan.planRoute')" prop="inspectionRouteId" required>
              <el-select v-model="formData.inspectionRouteId" style="width:100%" @change="handleRouteChange">
                <el-option v-for="route in routeOptions" :key="route.inspectionRouteId" :label="route.routeName"
                  :value="route.inspectionRouteId" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('inspectionPlan.planCycle')" prop="inspectionPlanPeriod" required>
              <el-select v-model="formData.inspectionPlanPeriod" style="width:100%" @change="handlePeriodChange">
                <el-option label="月/天" value="2020022" />
                <el-option label="按周" value="2020023" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('inspectionPlan.taskAdvance')">
              <el-input-number v-model="formData.beforeTime" :min="1" />
              <span class="margin-left">{{ $t('editInspectionPlan.minutesGenerate') }}</span>
            </el-form-item>
          </el-col>
        </el-row>
  
        <!-- 月/天选择 -->
        <template v-if="formData.inspectionPlanPeriod === '2020022'">
          <el-row>
            <el-form-item :label="$t('editInspectionPlan.month')">
              <el-checkbox-group v-model="formData.months">
                <el-checkbox v-for="month in 12" :key="month" :label="month">
                  {{ month }}{{ $t('editInspectionPlan.month') }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
  
          <el-row>
            <el-form-item :label="$t('editInspectionPlan.day')">
              <el-checkbox-group v-model="formData.days">
                <el-checkbox v-for="day in 31" :key="day" :label="day">
                  {{ day }}{{ $t('editInspectionPlan.day') }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
        </template>
  
        <!-- 按周选择 -->
        <template v-if="formData.inspectionPlanPeriod === '2020023'">
          <el-row>
            <el-form-item :label="$t('editInspectionPlan.week')">
              <el-checkbox-group v-model="formData.workdays">
                <el-checkbox v-for="(day, index) in weekDays" :key="index" :label="index + 1">
                  {{ day }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-row>
        </template>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('editInspectionPlan.startDate')" required>
              <el-date-picker v-model="formData.startDate" type="date" value-format="yyyy-MM-dd" style="width:100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('editInspectionPlan.endDate')" required>
              <el-date-picker v-model="formData.endDate" type="date" value-format="yyyy-MM-dd" style="width:100%" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('editInspectionPlan.startTime')" required>
              <el-time-picker v-model="formData.startTime" value-format="HH:mm" style="width:100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('editInspectionPlan.endTime')" required>
              <el-time-picker v-model="formData.endTime" value-format="HH:mm" style="width:100%" />
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('editInspectionPlan.signMethod')" required>
              <el-select v-model="formData.signType" style="width:100%">
56c7fec9   wuxw   巡检功能测试完成
103
104
                <el-option v-for="sign in signTypeOptions" :key="sign.statusCd" :label="sign.name"
                  :value="sign.statusCd" />
1d73dc48   wuxw   继续晚上巡检功能
105
106
107
108
109
110
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('editInspectionPlan.allowRecheck')">
              <el-select v-model="formData.canReexamine" style="width:100%">
56c7fec9   wuxw   巡检功能测试完成
111
112
                <el-option :label="$t('addInspectionPlan.notAllowed')" value="1000"></el-option>
                <el-option :label="$t('addInspectionPlan.allowed')" value="2000"></el-option>
1d73dc48   wuxw   继续晚上巡检功能
113
114
115
116
117
118
119
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
  
        <el-row>
          <el-form-item :label="$t('editInspectionPlan.selectStaff')">
56c7fec9   wuxw   巡检功能测试完成
120
            <select-staff-div ref="selectStaffDiv" @selectStaffs="handleSelectStaffs" />
1d73dc48   wuxw   继续晚上巡检功能
121
122
123
124
125
126
127
128
129
130
131
132
133
134
          </el-form-item>
        </el-row>
      </el-form>
  
      <div slot="footer">
        <el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="savePlan">{{ $t('common.save') }}</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { updateInspectionPlan, listInspectionRoutes, listInspectionPlanStaffs } from '@/api/inspection/inspectionPlanApi'
  import SelectStaffDiv from '@/components/staff/selectStaffsDiv'
56c7fec9   wuxw   巡检功能测试完成
135
  import { getDict } from '@/api/community/communityApi'
1d73dc48   wuxw   继续晚上巡检功能
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  
  export default {
    name: 'EditInspectionPlan',
    components: {
      SelectStaffDiv
    },
    data() {
      return {
        visible: false,
        formData: {
          inspectionPlanId: '',
          inspectionPlanName: '',
          inspectionRouteId: '',
          inspectionPlanPeriod: '',
          startDate: '',
          endDate: '',
          beforeTime: 30,
          startTime: '',
          endTime: '',
          signType: '',
          canReexamine: '1000',
          months: [],
          days: [],
          workdays: [],
          staffs: []
        },
        routeOptions: [],
        signTypeOptions: [],
        weekDays: [
77f5558e   wuxw   v1.9 巡检计划中 修改巡检路线...
165
166
167
168
169
170
171
          this.$t('addInspectionPlan.monday'),
          this.$t('addInspectionPlan.tuesday'),
          this.$t('addInspectionPlan.wednesday'),
          this.$t('addInspectionPlan.thursday'),
          this.$t('addInspectionPlan.friday'),
          this.$t('addInspectionPlan.saturday'),
          this.$t('addInspectionPlan.sunday')
1d73dc48   wuxw   继续晚上巡检功能
172
173
174
175
176
        ]
      }
    },
    async created() {
      await this.loadDictData()
1d73dc48   wuxw   继续晚上巡检功能
177
178
179
180
181
182
183
184
185
186
187
188
    },
    methods: {
      async loadDictData() {
        try {
          this.signTypeOptions = await getDict('inspection_plan', 'sign_type')
        } catch (error) {
          console.error('Failed to load sign types:', error)
        }
      },
  
      async loadRoutes() {
        try {
77f5558e   wuxw   v1.9 巡检计划中 修改巡检路线...
189
          const { inspectionRoutes } = await listInspectionRoutes({
1d73dc48   wuxw   继续晚上巡检功能
190
191
192
            page: 1,
            row: 100
          })
77f5558e   wuxw   v1.9 巡检计划中 修改巡检路线...
193
          this.routeOptions = inspectionRoutes
1d73dc48   wuxw   继续晚上巡检功能
194
195
196
197
198
199
200
201
202
203
204
205
206
207
        } catch (error) {
          console.error('Failed to load routes:', error)
        }
      },
  
      open(plan) {
        this.formData = {
          ...this.formData,
          ...plan,
          months: plan.inspectionMonth ? plan.inspectionMonth.split(',').map(Number) : [],
          days: plan.inspectionDay ? plan.inspectionDay.split(',').map(Number) : [],
          workdays: plan.inspectionWorkday ? plan.inspectionWorkday.split(',').map(Number) : []
        }
        this.loadStaffs(plan.inspectionPlanId)
77f5558e   wuxw   v1.9 巡检计划中 修改巡检路线...
208
209
        this.loadRoutes()
  
1d73dc48   wuxw   继续晚上巡检功能
210
211
212
213
214
        this.visible = true
      },
  
      async loadStaffs(planId) {
        try {
56c7fec9   wuxw   巡检功能测试完成
215
          const { inspectionPlanStaffs } = await listInspectionPlanStaffs({ inspectionPlanId: planId, page: 1, row: 100 })
1d73dc48   wuxw   继续晚上巡检功能
216
217
218
219
          this.formData.staffs = inspectionPlanStaffs.map(item => ({
            userId: item.staffId,
            name: item.staffName
          }))
56c7fec9   wuxw   巡检功能测试完成
220
          this.$refs.selectStaffDiv.setStaffs(this.formData.staffs)
1d73dc48   wuxw   继续晚上巡检功能
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
        } catch (error) {
          console.error('Failed to load staffs:', error)
        }
      },
  
      handleSelectStaffs(staffs) {
        this.formData.staffs = staffs
      },
  
      handleRouteChange() {
        // 处理路线变更逻辑
      },
  
      handlePeriodChange() {
        // 处理周期变更逻辑
      },
  
      resetForm() {
        this.$refs.form.resetFields()
      },
  
      async savePlan() {
        try {
          // 获取选中的员工
          // 准备数据
          const payload = {
            ...this.formData,
            inspectionMonth: this.formData.months.join(','),
            inspectionDay: this.formData.days.join(','),
            inspectionWorkday: this.formData.workdays.join(',')
          }
  
          // 调用API
          await updateInspectionPlan(payload)
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
255
          this.$message.success(this.$t('common.operationSuccess'))
1d73dc48   wuxw   继续晚上巡检功能
256
257
258
          this.visible = false
          this.$emit('success')
        } catch (error) {
56c7fec9   wuxw   巡检功能测试完成
259
  
1d73dc48   wuxw   继续晚上巡检功能
260
261
262
263
264
265
266
267
268
269
270
271
          this.$message.error(this.$t('inspectionPlan.updateError'))
        }
      }
    }
  }
  </script>
  
  <style scoped>
  .margin-left {
    margin-left: 10px;
  }
  </style>