干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2023-03-10 1fb197352b6a263646e4ccd3ed1c7854ede031dd
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
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit" width="70%">
    <a-form ref="formRef" :model="orderMainModel" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="validatorRules">
      <a-row class="form-row" :gutter="16">
        <a-col :lg="8">
          <a-form-item label="订单号" name="orderCode">
            <a-input v-model:value="orderMainModel.orderCode" placeholder="请输入订单号" />
          </a-form-item>
        </a-col>
        <a-col :lg="8">
          <a-form-item label="订单类型" name="ctype">
            <a-select placeholder="请选择订单类型" v-model:value="orderMainModel.ctype">
              <a-select-option value="1">国内订单</a-select-option>
              <a-select-option value="2">国际订单</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :lg="8">
          <a-form-item label="订单日期" name="orderDate">
            <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model:value="orderMainModel.orderDate" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row class="form-row" :gutter="16">
        <a-col :lg="8">
          <a-form-item label="订单金额" name="orderMoney">
            <a-input v-model:value="orderMainModel.orderMoney" placeholder="请输入订单金额" />
          </a-form-item>
        </a-col>
        <a-col :lg="8">
          <a-form-item label="订单备注" name="content">
            <a-input v-model:value="orderMainModel.content" placeholder="请输入订单备注" />
          </a-form-item>
        </a-col>
      </a-row>
      <!-- 子表单区域 -->
      <a-tabs v-model:activeKey="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="客户信息" key="tableRef1">
          <JVxeTable
            ref="tableRef1"
            stripe
            toolbar
            rowNumber
            rowSelection
            resizable
            keepSource
            :maxHeight="300"
            :checkbox-config="{ range: true }"
            :loading="table1.loading"
            :columns="table1.columns"
            :dataSource="table1.dataSource"
          ></JVxeTable>
        </a-tab-pane>
 
        <a-tab-pane tab="机票信息" key="tableRef2" forceRender>
          <JVxeTable
            ref="tableRef2"
            stripe
            toolbar
            rowNumber
            rowSelection
            resizable
            keepSource
            :maxHeight="300"
            :checkbox-config="{ range: true }"
            :loading="table2.loading"
            :columns="table2.columns"
            :dataSource="table2.dataSource"
          ></JVxeTable>
        </a-tab-pane>
      </a-tabs>
    </a-form>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, reactive, computed, unref } from 'vue';
  import { BasicModal, useModalInner } from '/src/components/Modal';
  import { JVxeTable } from '/src/components/jeecg/JVxeTable';
  import { columns, columns1 } from './jvxetable.data';
  import { orderCustomerList, orderTicketList, saveOrUpdate } from './jvxetable.api';
  import { useJvxeMethod } from '/@/hooks/system/useJvxeMethods.ts';
  export default defineComponent({
    name: 'JVexTableModal',
    components: { BasicModal, JVxeTable },
    emits: ['success', 'register'],
    setup(props, { emit }) {
      const isUpdate = ref(true);
      const tableRef1 = ref();
      const tableRef2 = ref();
      const refKeys = ref(['tableRef1', 'tableRef2']);
      const activeKey = ref('tableRef1');
      const tableRefs = { tableRef1, tableRef2 };
      const labelCol = reactive({
        xs: { span: 24 },
        sm: { span: 5 },
      });
      const wrapperCol = reactive({
        xs: { span: 24 },
        sm: { span: 16 },
      });
      // 客户信息
      const table1 = reactive({
        loading: false,
        dataSource: [],
        columns,
      });
      // 机票信息
      const table2 = reactive({
        loading: false,
        dataSource: [],
        columns: columns1,
      });
      const orderMainModel = reactive({
        id: null,
        orderCode: '',
        orderMoney: '',
        ctype: '',
        content: '',
        jeecgOrderCustomerList: [],
        jeecgOrderTicketList: [],
      });
      const [handleChangeTabs, handleSubmit, requestSubTableData, formRef] = useJvxeMethod(
        requestAddOrEdit,
        classifyIntoFormData,
        tableRefs,
        activeKey,
        refKeys
      );
      const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
        setModalProps({ confirmLoading: false });
        reset();
        isUpdate.value = !!data?.isUpdate;
        if (unref(isUpdate)) {
          Object.assign(orderMainModel, data.record);
          //加载子表数据
          let params = { id: orderMainModel.id };
          requestSubTableData(orderCustomerList, params, table1);
          requestSubTableData(orderTicketList, params, table2);
        }
      });
 
      const validatorRules = { orderCode: [{ required: true, message: '订单号不能为空', trigger: 'blur' }] };
      const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
 
      function classifyIntoFormData(allValues) {
        let orderMain = Object.assign(orderMainModel, allValues.formValue);
        return {
          ...orderMain, // 展开
          jeecgOrderCustomerList: allValues.tablesValue[0].tableData,
          jeecgOrderTicketList: allValues.tablesValue[1].tableData,
        };
      }
      function reset() {
        orderMainModel.id = null;
        orderMainModel.orderCode = '';
        orderMainModel.orderMoney = '';
        orderMainModel.orderDate = null;
        orderMainModel.ctype = '';
        orderMainModel.content = '';
        orderMainModel.jeecgOrderCustomerList = [];
        orderMainModel.jeecgOrderTicketList = [];
        table1.dataSource = [];
        table2.dataSource = [];
      }
      async function requestAddOrEdit(values) {
        setModalProps({ confirmLoading: true });
        //提交表单
        await saveOrUpdate(values, unref(isUpdate));
        //关闭弹窗
        closeModal();
        //刷新列表
        emit('success');
      }
      return {
        formRef,
        activeKey,
        table1,
        table2,
        tableRef1,
        tableRef2,
        getTitle,
        labelCol,
        wrapperCol,
        validatorRules,
        orderMainModel,
        registerModal,
        handleChangeTabs,
        handleSubmit,
      };
    },
  });
</script>
<style scoped></style>