干燥机配套车间生产管理系统/云平台服务端
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
<template>
  <div class="p-4">
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #tableTitle>
        <a-dropdown>
          <template #overlay>
            <a-menu @click="handleCreate">
              <a-menu-item :key="1">一对一示例</a-menu-item>
              <a-menu-item :key="2">一对多示例</a-menu-item>
              <a-menu-item :key="3">一对多(JVexTable)</a-menu-item>
            </a-menu>
          </template>
          <a-button type="primary">新增 <DownOutlined /></a-button>
        </a-dropdown>
      </template>
      <template #ctype="{ text }">
        {{ text === '1' ? '国内订单' : text === '2' ? '国际订单' : text }}
      </template>
      <template #action="{ record }">
        <TableAction :actions="getAction(record)" :dropDownActions="getDropDownActions(record)" />
      </template>
    </BasicTable>
    <!--        <TableDrawer @register="registerDrawer" @success="handleSuccess" />-->
    <TableModal @register="registerModal" @success="handleSuccess" />
    <JVxeTableModal @register="registerVexTableModal" @success="handleSuccess"></JVxeTableModal>
    <OneToOneModal @register="registerOneToOneModal" @success="handleSuccess"></OneToOneModal>
  </div>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import TableDrawer from './drawer.vue';
  import TableModal from './modal.vue';
  import VexTableModal from './VexTableModal.vue';
  import JVxeTableModal from './jvxetable/JVxeTableModal.vue';
  import OneToOneModal from './OneToOneModal.vue';
  import { DownOutlined } from '@ant-design/icons-vue';
  import { useListPage } from '/@/hooks/system/useListPage';
 
  import { useModal } from '/@/components/Modal';
  import { columns } from './data';
  import { list, deleteOne } from './api';
  import { defHttp } from '/@/utils/http/axios';
 
  const [registerModal, { openModal }] = useModal();
  const [registerOneToOneModal, { openModal: openOneToOneModal }] = useModal();
  const [registerVexTableModal, { openModal: openVexTableModal }] = useModal();
 
  //定义表格行操作
  const getAction = (record) => {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
      },
    ];
  };
 
  const getDropDownActions = (record) => {
    let arr = [
      {
        label: '删除',
        popConfirm: {
          title: '是否删除?',
          confirm: handleDelete.bind(null, record),
        },
      },
    ];
    return arr;
  };
 
  // 列表页面公共参数、方法
  const { tableContext } = useListPage({
    tableProps: {
      api: list,
      columns: columns,
      useSearchForm: false,
      actionColumn: {
        width: 160,
        title: '操作',
        dataIndex: 'action',
        slots: { customRender: 'action' },
      },
    },
  });
 
  //注册table数据
  const [registerTable, { reload }, { rowSelection }] = tableContext;
  //新增类型
  //update-begin---author:wangshuai ---date:20220720  for:[VUEN-1661]一对多示例,编辑的时候,有时候是一对一,有时候是一对多,默认一对多------------
  const addType = ref(3);
  //update-end---author:wangshuai ---date:20220720  for:[VUEN-1661]一对多示例,编辑的时候,有时候是一对一,有时候是一对多,默认一对多--------------
  //添加事件
  function handleCreate(e) {
    addType.value = e.key;
    let type = addType.value;
    if (type == 1) {
      openOneToOneModal(true, {
        isUpdate: false,
      });
    }
    if (type == 2) {
      openModal(true, {
        isUpdate: false,
      });
    }
    if (type == 3) {
      openVexTableModal(true, {
        isUpdate: false,
      });
    }
  }
 
  //编辑事件
  function handleEdit(record: Recordable) {
    let type = addType.value;
    if (type == 1) {
      openOneToOneModal(true, {
        record,
        isUpdate: true,
      });
    }
    if (type == 2) {
      openModal(true, {
        record,
        isUpdate: true,
      });
    }
    if (type == 3) {
      openVexTableModal(true, {
        record,
        isUpdate: true,
      });
    }
  }
 
  async function handleDelete(record: Recordable) {
    await deleteOne({ id: record.id }, reload);
  }
 
  function handleSuccess() {
    reload();
  }
</script>