Ben Lin
2024-05-27 62f0e403c98fb76d39b8f1150d2bf2f026423b85
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
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
490
491
492
493
494
495
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
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
<template>
  <PageWrapper
    class="high-form"
    :title="t('盘点管理')"
    :content="t('这是盘点管理页面。')"
    @back="goBack"
  >
    <a-card :title="t('盘点信息')" :bordered="false">
      <BasicForm @register="register">
        <template #add="{ field }">
          <a-button
            v-if="field"
            class="mt-1 ml-1"
            size="small"
            @click="handleSelectItem"
            preIcon="search|svg"
          />
          <ItemModal @register="registerItemAdd" @success="handleSuccess" />
        </template>
      </BasicForm>
      <div class="ml-10">
        <a-button type="primary" @click="handleStartCount"> {{ t('盘点启动') }} </a-button>
        &nbsp;
        <a-button type="primary" @click="handleStopCount"> {{ t('盘点暂停') }} </a-button>
        &nbsp;
        <a-button type="primary" @click="handleEndCount"> {{ t('盘点结束') }} </a-button>
        &nbsp;
        <a-button type="primary" @click="handleRevokeCount"> {{ t('盘点作废') }} </a-button>
      </div>
    </a-card>
    <a-card :title="t('盘点明细')" :bordered="false" class="!mt-5">
      <div>
        <!-- :columns="dtlColumns"
        :dataSource="data" -->
        <PageWrapper dense contentFullHeight contentClass="flex">
          <WareHouseTree
            class="w-1/4 xl:w-1/5"
            :disabledTree="disabledTree"
            @select="handleSelect"
            @gettree="handleCheck"
          />
          <BasicTable
            class="w-3/4 xl:w-4/5"
            :columns="dtlColumns"
            :dataSource="count_data"
            ref="tableRef"
            :canResize="canResize"
            :loading="Tableloading"
            :striped="striped"
            :bordered="border"
            :pagination="pagination"
            showTableSetting
          >
            <template #toolbar>
              <a-button type="primary" @click="handleCreate"> {{ t('预览') }} </a-button>
              <a-button type="primary" @click="handleMdtl"> {{ t('物品明细') }} </a-button>
              <!-- <a-button type="primary" @click="handleLdtl"> {{ t('储位明细') }} </a-button> -->
              <a-button type="primary" @click="handleSum"> {{ t('结果汇总') }} </a-button>
              <CountLdtlModal @register="registerCountLdtl" @success="handleSuccess" />
              <CountMdtlModal @register="registerCountMdtl" @success="handleSuccess" />
              <CountSumModal @register="registerCountSum" @success="handleSuccess" />
            </template>
            <template #action="{ record }">
              <TableAction
                :actions="[
                  {
                    icon: 'clarity:note-edit-line',
                    onClick: handleEdit.bind(null, record),
                  },
                  {
                    icon: 'ant-design:delete-outlined',
                    color: 'error',
                    popConfirm: {
                      title: '是否确认删除?',
                      placement: 'left',
                      confirm: handleDelete.bind(null, record),
                    },
                  },
                ]"
              />
            </template>
          </BasicTable>
        </PageWrapper>
      </div>
    </a-card>
 
    <template #rightFooter>
      <a-button class="mr-4" type="info" @click="cancel"> {{ t('取消') }} </a-button>
      <a-button type="primary" @click="submitAll"> {{ t('提交') }} </a-button>
    </template>
    <!-- <CheckruleDrawer @register="registerDrawer" @success="handleSuccess" /> -->
    <Loading :loading="loading" :tip="tip" />
  </PageWrapper>
</template>
<script lang="ts">
  import { BasicForm, useForm } from '/@/components/Form';
  import { defineComponent, onMounted, reactive, ref, unref, toRefs } from 'vue';
  import { useRoute, useRouter } from 'vue-router';
  import { PageWrapper } from '/@/components/Page';
  import { Card } from 'ant-design-vue';
  import { useGo } from '/@/hooks/web/usePage';
  import { useDrawer } from '/@/components/Drawer';
  import { BasicTable, TableAction, TableActionType } from '/@/components/Table';
  import { dtlColumns, newFormSchema } from './inventory.data';
  import { useTabs } from '/@/hooks/web/useTabs';
 
  import { useMultipleTabStore } from '/@/store/modules/multipleTab';
  import { getWHList } from '/@/api/tigerapi/wms/house';
  import WareHouseTree from './WareHouseTree.vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import ItemModal from '/@/views/components/ItemModal.vue';
  import CountLdtlModal from './CountLdtlModal.vue';
  import CountMdtlModal from './CountMdtlModal.vue';
  import CountSumModal from './CountSumModal.vue';
  import { useModal } from '/@/components/Modal';
  import {
    SaveInventory,
    GenerateCount,
    SummaryCount,
    getInventorytByPage,
    CreateBillCode,
  } from '/@/api/tigerapi/wms/inventory';
  import { iV_ITEM_COUNT } from '/@/api/tigerapi/model/warehoueseModel';
  import { formatToDateTime } from '/@/utils/dateUtil';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { Loading } from '/@/components/Loading';
 
  export default defineComponent({
    name: 'CountDetail',
    components: {
      BasicForm,
      BasicTable,
      PageWrapper,
      //CheckruleDrawer,
      [Card.name]: Card,
      TableAction,
      WareHouseTree,
      ItemModal,
      CountLdtlModal,
      CountMdtlModal,
      CountSumModal,
      Loading,
    },
    setup(props) {
      const compState = reactive({
        absolute: false,
        loading: false,
        tip: '加载中...',
      });
      const count = useRoute();
      const { t } = useI18n('WMS.Count');
      const go = useGo();
      const { createMessage } = useMessage();
 
      const tableRef = ref<Nullable<TableActionType>>(null);
      const CountObj = ref(JSON.parse(decodeURI(count.params?.id as string)));
      const { setTitle } = useTabs();
      const canResize = ref(false);
      const Tableloading = ref(false);
      const striped = ref(true);
      const border = ref(true);
      const pagination = ref<any>(false);
      var disabledTree = ref(0);
      const tabStore = useMultipleTabStore();
      const router = useRouter();
      const [registerItemAdd, { openModal: openItemModal }] = useModal();
      const [registerCountLdtl, { openModal: openCountLdtlModal }] = useModal();
      const [registerCountMdtl, { openModal: openCountMdtlModal }] = useModal();
      const [registerCountSum, { openModal: openCountSumModal }] = useModal();
 
      const { currentRoute } = router;
      function getCurrentTab() {
        const route = unref(currentRoute);
        return tabStore.getTabList.find((item) => item.fullPath === route.fullPath)!;
      }
      const currentTab = getCurrentTab();
      var _title = CountObj.value.ITEM_CODE == '0' ? t('新增盘点') : t('编辑盘点'); // + RuleObj.value.RULE_CODE;
      setTitle(_title);
      const [registerDrawer, { openDrawer }] = useDrawer();
      const [register, { resetFields, setFieldsValue, validateFields, getFieldsValue, validate }] =
        useForm({
          labelWidth: 120,
          baseColProps: {
            span: 24,
          },
          schemas: newFormSchema,
          showActionButtonGroup: false,
        });
      const [
        registerTest,
        {
          //getFieldsValue: getFieldsValueTest,
          //validate: validateTestForm,
        },
      ] = useForm({
        labelWidth: 120,
        baseColProps: {
          span: 24,
        },
        //schemas: testSchemas,
        showActionButtonGroup: false,
      });
      // const params: CheckRuleDtlParams = {
      //   RULE_ID: RuleObj.value.RULE_CODE == '0' ? '' : (RuleObj.value.ID as string),
      // };
      //const data = ref([] as iBAS_CODE_DTL[]);
      var checkeds = ref();
      var treeCode = ref([]);
      var count_one = ref([]);
      onMounted(async () => {
        const billCode = await CreateBillCode();
 
        treeCode.value = [];
        resetFields();
        pagination.value = { pageSize: 12 };
        //data.value = (await getRuleDtl(params)).Items;
 
        //根据单据查回数据
        count_one.value = await getInventorytByPage(CountObj.value.ID);
        if (billCode != null) {
          setFieldsValue({
            COUNT_NO: billCode,
          });
        }
 
        if (count_one.value != undefined) {
          setFieldsValue(count_one.value[0]);
          if (
            count_one.value[0]?.WH_IDS != undefined ||
            count_one.value[0]?.REGION_IDS != undefined ||
            count_one.value[0]?.SHELF_IDS != undefined
          ) {
            var wh = count_one.value[0].WH_IDS.split(',');
            var region = count_one.value[0].REGION_IDS.split(',');
            var shelf = count_one.value[0].SHELF_IDS.split(',');
 
            var sum = wh.concat(region);
            sum = sum.concat(shelf);
            treeCode.value.push(sum as never);
            checkeds.value.setCheckedKeys(treeCode.value[0]);
            // var check = checkeds.getCheckedKeys()
            // if (check != '') {
            //   handleCreate();
            // }
            var data = await validateFields();
            count_data.value = await SummaryCount(data);
            if (count_one.value[0].STATUS != 0) {
              disabledTree.value = count_one.value[0].STATUS;
            }
            Tableloading.value = false;
          }
        }
      });
      function getTableAction() {
        const tableAction = unref(tableRef);
        if (!tableAction) {
          throw new Error('tableAction is null');
        }
        return tableAction;
      }
 
      var keys = ref([]);
      var count_data = ref([] as iV_ITEM_COUNT[]);
      //提交
      async function submitAll() {
        var data = await validateFields();
        if (disabledTree.value === 0) {
          try {
            compState.absolute = true;
            compState.loading = true;
            //var data = await validateFields();
            keys.value = [];
            checkeds.value.getCheckedKeys().forEach((element) => {
              keys.value.push(checkeds.value.getNodeById(element) as never);
            });
            var wh = [];
            var region = [];
            var shelf = [];
            keys.value.forEach((key) => {
              if (key != null) {
                if (key.houseType == 'Warehouse') {
                  wh.push(key.id as never);
                }
                if (key.houseType == 'Region') {
                  region.push(key.id as never);
                }
                if (key.houseType == 'Shelf') {
                  shelf.push(key.id as never);
                }
              }
            });
            data.WH_IDS = wh.join(',');
            data.REGION_IDS = region.join(',');
            data.SHELF_IDS = shelf.join(',');
            var Apiaction = await SaveInventory(data, false);
            if (Apiaction.IsSuccessed) {
              createMessage.info(data.COUNT_NO + ':' + t('盘点单保存成功'));
            }
            if (keys.value[0] != '') {
              var apiaction = await GenerateCount(data);
              if (apiaction.IsSuccessed) {
                createMessage.info(data.COUNT_NO + ':' + t('盘点单明细保存成功'));
              }
              compState.loading = false;
            }
          } catch (error) {
            compState.loading = false;
          }
        } else {
          createMessage.error(data.COUNT_NO + ':' + t('该盘点已经开始盘点,无法提交修改'));
        }
      }
      async function cancel() {
        try {
          tabStore.closeTab(currentTab, router);
        } catch (error) {}
      }
      //生成
      async function handleCreate() {
        if (disabledTree.value === 0) {
          Tableloading.value = true;
          keys.value = [];
          var data = await validateFields();
 
          //data.MIRROR_DATE=now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate()+' '+now.getHours()+':'+now.getMinutes()+':'+now.getSeconds()
          checkeds.value.getCheckedKeys().forEach((element) => {
            keys.value.push(checkeds.value.getSelectedNode(element) as never);
          });
          var wh = [];
          var region = [];
          var shelf = [];
          var location = [];
          keys.value.forEach((key) => {
            if (key?.houseType == 'Warehouse') {
              wh.push(key.id as never);
            }
            if (key?.houseType == 'Region') {
              region.push(key.id as never);
            }
            if (key?.houseType == 'Shelf') {
              shelf.push(key.id as never);
            }
            if (key?.houseType == 'Location') {
              location.push(key.id as never);
            }
          });
          data.WH_IDS = wh.join(',');
          data.REGION_IDS = region.join(',');
          data.SHELF_IDS = shelf.join(',');
          data.LOCATION_IDS = location.join(',');
          count_data.value = await SummaryCount(data);
          setFieldsValue({
            MIRROR_DATE: formatToDateTime(new Date()),
          });
          if (count_data.value.length > 0) {
            createMessage.info(data.COUNT_NO + ':' + t('已生成'));
            Tableloading.value = false;
          } else {
            createMessage.info(data.COUNT_NO + ':' + t('没有数据生成'));
          }
        }
      }
 
      async function handleCheck(data) {
        checkeds.value = data;
      }
 
      function handleEdit(record: Recordable) {
        openDrawer(true, {
          record,
          isUpdate: true,
        });
      }
 
      function handleDelete(record: Recordable) {
        // var _data = data.value.map((item) => {
        //       return item;
        //     });
      }
      //获取物料列表
      function handleSuccess(d, u) {
        setFieldsValue({
          ITEM_CODE_LIST: d.values.values,
        });
      }
      //获取树结构
      var WareHouse = ref(false);
      var Region = ref(false);
      var Shelf = ref(false);
      async function handleSelect(WareHouseCode) {
        // WareHouse.value=false;
        // Region.value=false;
        // Shelf.value=false;
        await handleTree(WareHouseCode);
        WareHouse.value = WareHouseCode.slice(0, 1) == 'W' ? true : false;
        Region.value = WareHouseCode.slice(0, 1) == 'R' ? true : false;
        Shelf.value = WareHouseCode.slice(0, 1) == 'S' ? true : false;
 
        console.log(WareHouseCode, 15);
        //reload();
      }
      //点击打开物料列表框
      function handleSelectItem() {
        openItemModal(true, {
          data: 'content',
          info: 'Info',
        });
      }
      var Wdata = ref();
      var Rdata = ref();
      var Sdata = ref();
      async function handleTree(record: string) {
        var Code = record;
        var data = await getWHList(Code);
        if (record.slice(0, 1) == 'W') {
          Wdata.value = data;
          WareHouse.value = false;
        }
        if (record.slice(0, 1) == 'R') {
          Rdata.value = data;
          Region.value = false;
        }
        if (record.slice(0, 1) == 'S') {
          Sdata.value = data;
          Shelf.value = false;
        }
      }
      function goBack() {
        // 本例的效果时点击返回始终跳转到账号列表页,实际应用时可返回上一页
        go('/inventory');
      }
      //按类型盘点:物品
      async function handleMdtl() {
        var data = await validateFields();
        openCountMdtlModal(true, {
          data: data,
          info: 'Info',
        });
      }
      //储位
      async function handleLdtl() {
        var data = await validateFields();
        openCountLdtlModal(true, {
          data: data,
          info: 'Info',
        });
      }
      //汇总
      async function handleSum() {
        var data = await validateFields();
        openCountSumModal(true, {
          data: data,
          info: 'Info',
        });
      }
      //启动盘点
      async function handleStartCount() {
        undefined;
        if (disabledTree.value === 0 || disabledTree.value === 2) {
          var data = await validateFields();
          data.STATUS = 1;
          data.BEGIN_DATE = formatToDateTime(new Date());
          var apiAction = await SaveInventory(data, true);
          if (apiAction.IsSuccessed) {
            createMessage.info(data.COUNT_NO + ':' + t('启动成功'));
            disabledTree.value = 1;
          }
        } else {
          createMessage.error(t('启动失败,单据不是新建状态'));
        }
      }
      //暂停
      async function handleStopCount() {
        if (disabledTree.value === 1) {
          var data = await validateFields();
          data.STATUS = 2;
          var apiAction = await SaveInventory(data, true);
          if (apiAction.IsSuccessed) {
            createMessage.info(data.COUNT_NO + ':' + t('已暂停'));
            disabledTree.value = 2;
          }
        } else {
          createMessage.error(t('暂停失败,单据没启动'));
        }
      }
      //结束
      async function handleEndCount() {
        if (disabledTree.value === 1) {
          var data = await validateFields();
          data.STATUS = 3;
          data.END_DATE = formatToDateTime(new Date());
          var apiAction = await SaveInventory(data, true);
          if (apiAction.IsSuccessed) {
            createMessage.info(data.COUNT_NO + ':' + t('结束成功'));
            disabledTree.value = 3;
          }
        } else {
          createMessage.error(t('结束失败,单据没启动'));
        }
      }
      //作废
      async function handleRevokeCount() {
        var data = await validateFields();
        data.STATUS = 4;
        var apiAction = await SaveInventory(data, true);
        if (apiAction.IsSuccessed) {
          createMessage.info(data.COUNT_NO + ':' + t('作废成功'));
          disabledTree.value = 4;
        }
      }
      return {
        t,
        dtlColumns,
        register,
        registerTest,
        resetFields,
        setFieldsValue,
        getFieldsValue,
        validate,
        CountObj,
        handleCheck,
        //data,
        treeCode,
        count_data,
        canResize,
        Tableloading,
        striped,
        border,
        pagination,
        disabledTree,
        registerDrawer,
        submitAll,
        cancel,
        tableRef,
        goBack,
        handleCreate,
        handleEdit,
        handleDelete,
        handleSuccess,
        handleSelect,
        handleSelectItem,
        registerItemAdd,
        registerCountLdtl,
        registerCountMdtl,
        registerCountSum,
        handleSum,
        handleLdtl,
        handleMdtl,
        handleRevokeCount,
        handleEndCount,
        handleStartCount,
        handleStopCount,
        ...toRefs(compState),
      };
    },
  });
</script>
<style lang="less" scoped>
  .high-form {
    padding-bottom: 48px;
  }
</style>