Blame view

src/views/resource/addItemOutList.vue 18.6 KB
fc7cb950   wuxw   开发完成采购功能
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
  <template>
    <div>
      <el-row>
        <el-col :span="24">
          <el-card class="box-card">
            <div slot="header" class="flex justify-between">
              <div>{{ $t('addItemOut.recipient') }}</div>
              <div class="ibox-tools">
                <el-button type="primary" size="small" @click="goBack">
                  <i class="el-icon-close"></i>
                  {{ $t('addItemOut.return') }}
                </el-button>
              </div>
            </div>
            <div class="">
              <el-form :model="addItemOutInfo" label-position="right" label-width="120px">
                <el-form-item :label="$t('addItemOut.warehouse')">
                  <el-select v-model="addItemOutInfo.shId" @change="_computeFlow" style="width:100%"
                    :placeholder="$t('addItemOut.warehousePlaceholder')">
                    <el-option v-for="(item, index) in addItemOutInfo.storehouses" :key="index" :label="item.shName"
                      :value="item.shId"></el-option>
                  </el-select>
                </el-form-item>
  
                <el-form-item :label="$t('addItemOut.recipient')">
                  <el-row>
                    <el-col :span="addItemOutInfo.canChooseEndUserOrNot ? 18 : 24">
                      <el-input :placeholder="$t('addItemOut.contactPlaceholder')"
                        v-model.trim="addItemOutInfo.endUserInfo.staffName" style="width:100%"></el-input>
                    </el-col>
                    <el-col :span="6" v-if="addItemOutInfo.canChooseEndUserOrNot">
                      <el-button type="primary" @click="chooseEndUser">
                        <i class="el-icon-search"></i> {{ $t('addItemOut.selectRecipient') }}
                      </el-button>
                    </el-col>
                  </el-row>
                </el-form-item>
  
                <el-form-item :label="$t('addItemOut.contactPhone')">
                  <el-input :placeholder="$t('addItemOut.phonePlaceholder')"
                    v-model.trim="addItemOutInfo.endUserInfo.staffTel" style="width:100%"></el-input>
                </el-form-item>
  
                <el-form-item :label="$t('addItemOut.applicationNote')">
                  <el-input type="textarea" :placeholder="$t('addItemOut.notePlaceholder')"
                    v-model.trim="addItemOutInfo.description" style="width:100%"></el-input>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
        </el-col>
      </el-row>
  
      <!-- 选择物品 -->
      <el-row>
        <el-col :span="24">
          <el-card class="box-card">
            <div slot="header" class="flex justify-between">
              <div>{{ $t('addItemOut.itemInfo') }}</div>
              <div class="ibox-tools">
                <el-button type="primary" size="small" style="margin-right:10px;"
                  @click="_openSelectResourceStoreInfoModel">
                  <i class="el-icon-plus"></i>
                  {{ $t('addItemOut.selectItem') }}
                </el-button>
              </div>
            </div>
b4962701   wuxw   测试采购相关功能
68
69
70
71
            <div class="">
              <table class="custom-table">
                <thead>
                  <tr>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
72
73
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
74
75
                      {{ $t('addItemOut.itemType') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
76
77
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
78
79
                      {{ $t('addItemOut.itemName') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
80
81
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
82
83
                      {{ $t('addItemOut.itemSpec') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
84
85
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
86
87
                      {{ $t('addItemOut.price') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
88
89
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
90
91
                      {{ $t('addItemOut.stock') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
92
93
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
94
95
                      {{ $t('addItemOut.applyQuantity') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
96
97
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
98
99
                      {{ $t('addItemOut.remark') }}
                    </th>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
100
101
                    <th
                      style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5; background-color: #fafafa;">
b4962701   wuxw   测试采购相关功能
102
103
104
105
106
                      {{ $t('addItemOut.operation') }}
                    </th>
                  </tr>
                </thead>
                <tbody>
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
107
108
                  <tr v-for="(item, index) in addItemOutInfo.resourceStores" :key="index"
                    style="border-bottom: 1px solid #ebeef5;">
b4962701   wuxw   测试采购相关功能
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      {{ item.parentRstName || '-' }} > {{ item.rstName || '-' }}
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      {{ item.resName }}({{ item.resCode }})
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      {{ item.rssName || '-' }}
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      <select v-model="item.timesId" @change="_changeTimesId($event, index)" class="custom-select">
                        <option value="">{{ $t('addItemOut.selectPrice') }}</option>
                        <option v-for="time in item.times" :key="time.timesId" :value="time.timesId">
                          {{ time.price }}
                        </option>
                      </select>
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      {{ _getTimesStock(item) }}{{ item.unitCodeName }}
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      <el-input v-model.trim="item.quantity" type="number"
                        :placeholder="$t('addItemOut.quantityPlaceholder')"
                        style="width:70%;display:inline-block;"></el-input>
                      &nbsp;&nbsp;{{ item.unitCodeName }}
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      <el-input v-model.trim="item.remark" type="text"
                        :placeholder="$t('addItemOut.remarkPlaceholder')"></el-input>
                    </td>
                    <td style="text-align: center; padding: 12px 8px; border: 1px solid #ebeef5;">
                      <el-button type="danger" size="small" @click="_removeSelectResourceStoreItem(item.resId)">
                        <i class="el-icon-delete"></i>
                        {{ $t('addItemOut.remove') }}
                      </el-button>
                    </td>
                  </tr>
                  <tr v-if="addItemOutInfo.resourceStores.length === 0">
                    <td colspan="8" style="text-align: center; padding: 20px; color: #909399;">
                      {{ $t('common.noData') }}
                    </td>
                  </tr>
                </tbody>
              </table>
fc7cb950   wuxw   开发完成采购功能
153
154
155
156
157
158
159
160
161
162
163
164
            </div>
          </el-card>
        </el-col>
      </el-row>
  
      <!-- 审批人 -->
      <el-row v-if="addItemOutInfo.audit.assignee === '-2'">
        <el-col :span="24">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <h5>{{ $t('addItemOut.approver') }}</h5>
            </div>
19bafb73   wuxw   v1.9 优化采购相关bug
165
            <div class="">
fc7cb950   wuxw   开发完成采购功能
166
167
168
              <el-form :model="addItemOutInfo" label-position="right" label-width="120px">
                <el-form-item :label="$t('addItemOut.approver')">
                  <el-row :gutter="20">
19bafb73   wuxw   v1.9 优化采购相关bug
169
                    <el-col :span="17">
caba9d96   wuxw   oa 中除了 工作办理没有测试其他...
170
171
                      <el-input :placeholder="$t('addItemOut.approverPlaceholder')"
                        v-model="addItemOutInfo.audit.staffName" disabled></el-input>
fc7cb950   wuxw   开发完成采购功能
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
                    </el-col>
                    <el-col :span="6">
                      <el-button type="primary" @click="chooseStaff">
                        <i class="el-icon-search"></i> {{ $t('addItemOut.select') }}
                      </el-button>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
        </el-col>
      </el-row>
  
      <el-row>
        <el-col :span="22" :offset="2" style="margin-bottom:20px; text-align:right">
          <el-button type="primary" @click="_finishStep">
            {{ $t('addItemOut.submit') }}
          </el-button>
        </el-col>
      </el-row>
  
      <choose-resource-store2 ref="chooseResourceStore2"
        @setSelectResourceStores="handleSetSelectResourceStores"></choose-resource-store2>
  
19bafb73   wuxw   v1.9 优化采购相关bug
197
      <select-staff ref="selectStaff" @selectStaff="handleStaffChange"></select-staff>
fc7cb950   wuxw   开发完成采购功能
198
199
200
201
202
203
    </div>
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
  import ChooseResourceStore2 from '@/components/resource/chooseResourceStore2'
19bafb73   wuxw   v1.9 优化采购相关bug
204
205
  import SelectStaff from '@/components/staff/SelectStaff'
  import { goodsCollection, listStorehouses, queryFirstAuditStaff } from '@/api/resource/addItemOutApi'
fc7cb950   wuxw   开发完成采购功能
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
237
238
239
240
241
242
243
244
245
246
247
248
249
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
  import { getUserName, getUserTel } from '@/api/user/userApi'
  
  export default {
    name: 'AddItemOutList',
    components: {
      ChooseResourceStore2,
      SelectStaff,
    },
    data() {
      return {
        addItemOutInfo: {
          resourceStores: [],
          resourceSuppliers: [],
          audit: {
            assignee: '',
            staffId: '',
            staffName: '',
            taskId: ''
          },
          endUserInfo: {
            assignee: '',
            staffId: '',
            staffName: '',
            taskId: '',
            staffTel: ''
          },
          description: '',
          endUserName: '',
          endUserTel: '',
          acceptStaffId: '',
          file: '',
          resOrderType: '20000',
          staffId: '',
          staffName: '',
          communityId: '',
          shId: '',
          storehouses: [],
          flowId: '',
          canChooseEndUserOrNot: false,
        }
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.addItemOutInfo.communityId = this.communityId
      this._reset()
      this.initPage()
    },
    mounted() {
    },
    beforeDestroy() {
    },
    methods: {
      _reset() {
        this.addItemOutInfo = {
          resourceStores: [],
          resourceSuppliers: [],
          audit: {
            assignee: '',
            staffId: '',
            staffName: '',
            taskId: ''
          },
          endUserInfo: {
            assignee: '',
            staffId: '',
            staffName: '',
            taskId: '',
            staffTel: ''
          },
          description: '',
          endUserName: '',
          endUserTel: '',
          acceptStaffId: '',
          file: '',
          resOrderType: '20000',
          staffId: '',
          staffName: '',
          communityId: this.communityId,
          shId: '',
          storehouses: [],
          flowId: '',
          canChooseEndUserOrNot: false,
        }
      },
      initPage() {
        const from = this.$route.query.from
        if (from === 'resourceStore') {
          this.addItemOutInfo.canChooseEndUserOrNot = true
        }
  
        this.addItemOutInfo.endUserInfo.staffName = getUserName() || ''
        this.addItemOutInfo.endUserInfo.staffTel = getUserTel() || ''
  
        this._loadResourceSuppliers()
        this._listPurchaseStorehouses()
      },
      goBack() {
        this.$router.go(-1)
      },
      _resourcesFromSameHouse(resourcesList) {
        if (!resourcesList || resourcesList.length < 2) return true
  
        let lastHouse = ''
        for (let i = 0; i < resourcesList.length; i++) {
          if (!lastHouse) {
            lastHouse = resourcesList[i].shId
            continue
          }
          if (lastHouse !== resourcesList[i].shId) {
            return false
          }
        }
        return true
      },
      _openSelectResourceStoreInfoModel() {
        if (!this.addItemOutInfo.shId) {
          this.$message.error(this.$t('addItemOut.warehouseRequired'))
          return
        }
        if (!this.addItemOutInfo.endUserInfo.staffName) {
          this.$message.error(this.$t('addItemOut.contactRequired'))
          return
        }
        if (!this.addItemOutInfo.endUserInfo.staffTel) {
          this.$message.error(this.$t('addItemOut.phoneRequired'))
          return
        }
        if (!this.addItemOutInfo.description) {
          this.$message.error(this.$t('addItemOut.noteRequired'))
          return
        }
  
        this.$refs.chooseResourceStore2.open({
          shId: this.addItemOutInfo.shId
        })
      },
      async _finishStep() {
        const resourceStores = this.addItemOutInfo.resourceStores
        if (!resourceStores || resourceStores.length === 0) {
          this.$message.error(this.$t('addItemOut.itemRequired'))
          return
        }
  
        if (!this._resourcesFromSameHouse(resourceStores)) {
          this.$message.error(this.$t('addItemOut.sameWarehouseRequired'))
          return
        }
  
b4962701   wuxw   测试采购相关功能
355
356
357
358
359
360
361
362
363
364
365
366
367
368
        //let validate = true
        // resourceStores.forEach(item => {
        //   const selectedStock = item.selectedStock || 0
        //   const quantity = parseFloat(item.quantity) || 0
        //   console.log('item', item, selectedStock, quantity)
        //   if (quantity > selectedStock) {
        //     validate = false
        //   }
        // })
  
        // if (!validate) {
        //   this.$message.error(this.$t('addItemOut.insufficientStock'))
        //   return
        // }
fc7cb950   wuxw   开发完成采购功能
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
  
        this.addItemOutInfo.endUserName = this.addItemOutInfo.endUserInfo.staffName
        this.addItemOutInfo.endUserTel = this.addItemOutInfo.endUserInfo.staffTel
        this.addItemOutInfo.acceptStaffId = this.addItemOutInfo.endUserInfo.staffId
  
        if (this.addItemOutInfo.canChooseEndUserOrNot) {
          this.addItemOutInfo.useSwitch = "OFF"
        }
  
        try {
          const res = await goodsCollection(this.addItemOutInfo)
          if (res.code === 0) {
            this.$message.success(this.$t('addItemOut.submitSuccess'))
            this.goBack()
          } else {
            this.$message.error(res.msg || this.$t('addItemOut.submitFailed'))
          }
        } catch (error) {
          this.$message.error(this.$t('addItemOut.submitError'))
          console.error(error)
        }
      },
      _loadResourceSuppliers() {
        // 实际调用API的方法
        // 这里保留占位,实际实现需要调用API
      },
      async _listPurchaseStorehouses() {
        try {
          const res = await listStorehouses({
            page: 1,
            row: 100,
            communityId: "",
            allowPurchase: 'ON'
          })
          this.addItemOutInfo.storehouses = res.data
        } catch (error) {
          console.error('请求失败:', error)
        }
      },
      _removeSelectResourceStoreItem(resId) {
        this.addItemOutInfo.resourceStores = this.addItemOutInfo.resourceStores.filter(
          item => item.resId !== resId
        )
      },
      _changeTimesId(value, index) {
        const times = this.addItemOutInfo.resourceStores[index].times
        times.forEach(item => {
          if (item.timesId === value) {
            this.addItemOutInfo.resourceStores[index].selectedStock = item.stock
          }
        })
b4962701   wuxw   测试采购相关功能
420
421
422
        this.$nextTick(() => {
          this.$forceUpdate()
        })
fc7cb950   wuxw   开发完成采购功能
423
424
425
426
427
428
429
430
431
432
433
      },
      _getTimesStock(resourceStore) {
        if (!resourceStore.timesId) return "-"
  
        let stock = 0
        resourceStore.times.forEach(item => {
          if (item.timesId === resourceStore.timesId) {
            stock = item.stock
          }
        })
  
fc7cb950   wuxw   开发完成采购功能
434
435
436
  
        return stock
      },
19bafb73   wuxw   v1.9 优化采购相关bug
437
      async _loadStaffOrg(flowId) {
fc7cb950   wuxw   开发完成采购功能
438
439
        // 实际调用API的方法
        // 这里保留占位,实际实现需要调用API
19bafb73   wuxw   v1.9 优化采购相关bug
440
441
442
443
444
445
446
447
448
449
450
451
        const res = await queryFirstAuditStaff({
          communityId: this.communityId,
          flowId: flowId
        })
        if (res.code != 0) {
          return;
        }
        let _data = res.data
        Object.assign(this.addItemOutInfo.audit, _data[0])
        if (!_data[0].assignee.startsWith('-')) {
          this.addItemOutInfo.audit.staffId = this.addItemOutInfo.audit.assignee;
        }
fc7cb950   wuxw   开发完成采购功能
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
      },
      chooseStaff() {
        this.$refs.selectStaff.open(this.addItemOutInfo.audit)
      },
      chooseEndUser() {
        this.$refs.selectStaff.open(this.addItemOutInfo.endUserInfo)
      },
      _computeFlow() {
        this.addItemOutInfo.resourceStores = []
        const storehouse = this.addItemOutInfo.storehouses.find(
          item => item.shId === this.addItemOutInfo.shId
        )
  
        if (storehouse) {
          this.addItemOutInfo.flowId = storehouse.useFlowId
          this._loadStaffOrg(storehouse.useFlowId)
        }
      },
      handleSetSelectResourceStores(resourceStores) {
        const oldList = this.addItemOutInfo.resourceStores
        const newList = [...resourceStores]
  
        newList.forEach((newItem, newIndex) => {
          newItem.rsId = ''
          newItem.timesId = ''
          if (newItem.times && newItem.times.length > 0) {
            newItem.timesId = newItem.times[0].timesId
          }
  
          oldList.forEach(oldItem => {
            if (oldItem.resId === newItem.resId && newItem.times && newItem.times.length < 2) {
              delete newList[newIndex]
            }
          })
        })
  
        const filteredList = newList.filter(item => item['resId'])
        this.addItemOutInfo.resourceStores = [...oldList, ...filteredList]
19bafb73   wuxw   v1.9 优化采购相关bug
490
491
492
493
494
495
      },
      handleStaffChange(staff) {
        this.addItemOutInfo.audit.staffId = staff.staffId
        this.addItemOutInfo.audit.staffName = staff.staffName
        this.addItemOutInfo.endUserInfo.staffId = staff.staffId
        this.addItemOutInfo.endUserInfo.staffName = staff.staffName
fc7cb950   wuxw   开发完成采购功能
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
      }
    }
  }
  </script>
  
  <style scoped>
  .box-card {
    margin-bottom: 20px;
  }
  
  .ibox-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .ibox-tools {
    position: relative;
    top: 10px;
  }
  
  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  
  .clearfix:after {
    clear: both;
  }
b4962701   wuxw   测试采购相关功能
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
  
  .custom-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #ebeef5;
  }
  
  .custom-table th {
    background-color: #fafafa;
    color: #606266;
    font-weight: 500;
    font-size: 14px;
  }
  
  .custom-table td {
    color: #606266;
    font-size: 14px;
  }
  
  .custom-table tr:hover {
    background-color: #f5f7fa;
  }
  
  .custom-select {
    width: 100%;
    height: 32px;
    line-height: 32px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    padding: 0 12px;
    font-size: 14px;
    color: #606266;
    background-color: #fff;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  }
  
  .custom-select:focus {
    outline: none;
    border-color: #409eff;
  }
  
  .custom-select:hover {
    border-color: #c0c4cc;
  }
fc7cb950   wuxw   开发完成采购功能
570
  </style>