Ben Lin
2024-06-13 1b970c588245935181610e93e84a9a3a10d80ecd
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
<template>
  <BasicDrawer
    v-bind="$attrs"
    @register="CheckruleDrawer"
    showFooter
    :title="getTitle"
    width="1200px"
    @ok="handleSubmit"
  >
    <!-- <BasicForm @register="MaterialForm" /> -->
    <a-card title="班次明细" :bordered="false">
      <BasicForm @register="register" />
    </a-card>
    <a-card title="时段列表" :bordered="false" class="!mt-5">
      <div>
        <!-- <BasicTable
          :columns="dtlColumns"
          ref="tableRef"
          :dataSource="data"
          :canResize="canResize"
          :loading="loading"
          :striped="striped"
          :bordered="border"
          :actionColumn="actionColumn"
          :pagination="pagination"
          showTableSetting
        >
          <template #toolbar>
            <a-button type="primary" @click="handleCreate"> 新增班次 </a-button>
          </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> -->
      </div>
    </a-card>
  </BasicDrawer>
</template>
<script lang="ts">
  import { defineComponent, ref, computed, unref } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { formSchema } from './shift.data';              
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
 
  export default defineComponent({
    name: 'CheckruleDrawer',
    components: { BasicDrawer, BasicForm },
    emits: ['success', 'register'],
    setup(_, { emit }) {
      const isUpdate = ref(true);
 
      const [register, { resetFields, setFieldsValue, validate }] = useForm({
        labelWidth: 120,
        schemas: formSchema,
        actionColOptions: {
          span: 24,
        },
        showActionButtonGroup: false,
      });
 
      const [CheckruleDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
        resetFields();
        setDrawerProps({ confirmLoading: false });
        isUpdate.value = !!data?.isUpdate;
        // data.record.DATA_CASE=[data.record.DATA_CASE]
        if (unref(isUpdate)) {
          setFieldsValue({
            ...data.record,
          });
        } else {
          setFieldsValue({
            RULE_ID: data.RULE_ID,
          });
        }
      });
 
      const getTitle = computed(() => (!unref(isUpdate) ? '新增规则明细' : '编辑规则明细'));
 
      async function handleSubmit() {
        try {
          const values = await validate();
          setDrawerProps({ confirmLoading: true });
          // TODO custom api
          // //保存物料
          // const apiAction = SaveRegion(values, unref(isUpdate));
          // apiAction.then((action) => {
          //   if (action.IsSuccessed) {
          //     closeDrawer();
          //     emit('success');
          //   }
          // });
 
          closeDrawer();
          emit('success', values, { isUpdate: isUpdate.value });
        } finally {
          setDrawerProps({ confirmLoading: false });
        }
      }
 
      return {
        CheckruleDrawer,
        register,
        getTitle,
        handleSubmit,
      };
    },
  });
</script>