|
@@ -8,15 +8,15 @@
|
|
|
@visible-change="handleVisibleChange"
|
|
|
>
|
|
|
<div class="pt-3px pr-3px">
|
|
|
- <BasicForm @register="registerForm" :model="modelRef">
|
|
|
+ <BasicForm @register="registerForm">
|
|
|
<template #userName="{ model, field }">
|
|
|
{{ model[field] }}
|
|
|
</template>
|
|
|
<template #name="{ model, field }">
|
|
|
{{ model[field] }}
|
|
|
</template>
|
|
|
- <template #addeduser>
|
|
|
- {{ myData.pagination.total || 0 }}
|
|
|
+ <template #addeduser="{ model, field }">
|
|
|
+ {{ model[field] || 0 }}
|
|
|
<a-button @click="openTargetModal()" type="primary" preIcon="ic:outline-person-add">
|
|
|
新增子账号
|
|
|
</a-button>
|
|
@@ -24,16 +24,9 @@
|
|
|
</BasicForm>
|
|
|
<div class="table_list">
|
|
|
<BasicTable
|
|
|
- title="子账户列表"
|
|
|
- ref="tableRef"
|
|
|
- rowKey="id"
|
|
|
- :columns="columns"
|
|
|
- :showIndexColumn="false"
|
|
|
- :dataSource="myData.TableData"
|
|
|
- :bordered="true"
|
|
|
- :pagination="false"
|
|
|
@register="registerSubtable"
|
|
|
:beforeEditSubmit="beforeEditSubmit"
|
|
|
+ :searchInfo="searchInfo"
|
|
|
>
|
|
|
<template #action="{ record }">
|
|
|
<TableAction
|
|
@@ -52,38 +45,21 @@
|
|
|
/>
|
|
|
</template>
|
|
|
</BasicTable>
|
|
|
- <AddModal @register="register4" @addtable="addTabledata" @update="reloadSubtable" />
|
|
|
+ <AddModal @register="registerModal" @submit="handleAddUser" />
|
|
|
</div>
|
|
|
</div>
|
|
|
<EditModal @register="registerEdit" />
|
|
|
</BasicModal>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
- import {
|
|
|
- defineComponent,
|
|
|
- ref,
|
|
|
- reactive,
|
|
|
- nextTick,
|
|
|
- onMounted,
|
|
|
- unref,
|
|
|
- ComponentOptions,
|
|
|
- shallowRef,
|
|
|
- computed,
|
|
|
- // inject,
|
|
|
- } from 'vue';
|
|
|
+ import { defineComponent, reactive, nextTick } from 'vue';
|
|
|
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
|
|
|
- import {
|
|
|
- BasicTable,
|
|
|
- useTable,
|
|
|
- BasicColumn,
|
|
|
- TableAction,
|
|
|
- TableActionType,
|
|
|
- } from '/@/components/Table';
|
|
|
+ import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
|
|
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
|
|
import { selectUserList, saveSubUsers } from '/@/api/corporation/modal';
|
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
import EditModal from './EditModal.vue';
|
|
|
- import { tableState } from './types/hooks';
|
|
|
+ // import { tableState } from './types/hooks';
|
|
|
import AddModal from './AddModal.vue';
|
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
|
export default defineComponent({
|
|
@@ -95,37 +71,17 @@
|
|
|
setup(props, { emit }) {
|
|
|
const { t } = useI18n();
|
|
|
const { createConfirm, createMessage } = useMessage();
|
|
|
- const currentModal = shallowRef<Nullable<ComponentOptions>>(null);
|
|
|
- const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
- const [register4, { openModal: addopenModal }] = useModal();
|
|
|
- const [registerSubtable, { reloadSubtable }] = useTable();
|
|
|
- const modelRef = ref({});
|
|
|
- // const reload = inject('tablereload');
|
|
|
- // const editList = ref({
|
|
|
- // list:[]
|
|
|
- // })
|
|
|
- const myData = reactive<tableState>({
|
|
|
- TableData: [],
|
|
|
- subNum: null,
|
|
|
- id: null,
|
|
|
- pagination: {
|
|
|
- total: 0,
|
|
|
- pageSize: 9999,
|
|
|
- current: 1,
|
|
|
- },
|
|
|
+
|
|
|
+ const [registerModal, { openModal: addopenModal }] = useModal();
|
|
|
+
|
|
|
+ const modelRef = reactive({
|
|
|
+ id: 0,
|
|
|
+ subNum: 0,
|
|
|
});
|
|
|
- const getPagination = computed(() => {
|
|
|
- const { total, pageSize, current } = myData.pagination;
|
|
|
- return {
|
|
|
- total: total,
|
|
|
- pageSize,
|
|
|
- //size: 'small',
|
|
|
- current: unref(current),
|
|
|
- onChange(page) {
|
|
|
- myData.pagination.current = page;
|
|
|
- getApiList();
|
|
|
- },
|
|
|
- };
|
|
|
+ const searchInfo = reactive({
|
|
|
+ limit: 9999,
|
|
|
+ id: 0,
|
|
|
+ page: 1,
|
|
|
});
|
|
|
const columns: BasicColumn[] = [
|
|
|
{
|
|
@@ -200,26 +156,51 @@
|
|
|
span: 24,
|
|
|
},
|
|
|
});
|
|
|
+
|
|
|
+ const [
|
|
|
+ registerSubtable,
|
|
|
+ { reload: reloadSubtable, deleteTableDataRecord, getDataSource, insertTableDataRecord },
|
|
|
+ ] = useTable({
|
|
|
+ title: '子账户列表',
|
|
|
+ rowKey: 'id',
|
|
|
+ api: selectUserList,
|
|
|
+ immediate: false,
|
|
|
+ columns: columns,
|
|
|
+ showIndexColumn: false,
|
|
|
+ bordered: true,
|
|
|
+ pagination: false,
|
|
|
+ });
|
|
|
+
|
|
|
const [registerEdit, { openModal: EditModal }] = useModal();
|
|
|
const [register, { closeModal }] = useModalInner((data) => {
|
|
|
data && onDataReceive(data);
|
|
|
});
|
|
|
|
|
|
- function onDataReceive(data) {
|
|
|
+ async function onDataReceive(data) {
|
|
|
console.log('Data Received', data.record);
|
|
|
// 方式1;
|
|
|
- let { id, subNum } = data.record;
|
|
|
+ const { id, subNum } = data.record;
|
|
|
resetFields();
|
|
|
setFieldsValue({
|
|
|
...data.record,
|
|
|
});
|
|
|
- myData.id = id;
|
|
|
- myData.subNum = subNum;
|
|
|
- getApiList();
|
|
|
+ modelRef.id = id;
|
|
|
+ modelRef.subNum = subNum;
|
|
|
+
|
|
|
+ searchInfo.id = id;
|
|
|
+ await reloadSubtable();
|
|
|
+
|
|
|
+ const total = getDataSource();
|
|
|
+ console.log('total', total);
|
|
|
+ setFieldsValue({
|
|
|
+ addeduser: total?.length || 0,
|
|
|
+ });
|
|
|
}
|
|
|
- function numOnChange(event) {
|
|
|
- myData.subNum = event;
|
|
|
- console.log('numOnChange', event);
|
|
|
+ function numOnChange(data) {
|
|
|
+ console.log('data', data);
|
|
|
+ modelRef.subNum = data;
|
|
|
+ // myData.subNum = event;
|
|
|
+ // console.log('numOnChange', event);
|
|
|
}
|
|
|
async function handleDelete(item, type) {
|
|
|
console.log('handleDelete', item, type);
|
|
@@ -237,27 +218,13 @@
|
|
|
title: '提示',
|
|
|
content: t('routes.devices.unbindWarning'),
|
|
|
onOk: async () => {
|
|
|
- tableRef.value.deleteTableDataRecord(item.id);
|
|
|
+ // tableRef.value.deleteTableDataRecord(item.id);
|
|
|
+ deleteTableDataRecord(item.id);
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- function pageChange(page, d, a) {
|
|
|
- console.log('pageChange', page, d, a);
|
|
|
- myData.pagination.current = page;
|
|
|
- getApiList();
|
|
|
- }
|
|
|
- async function getApiList() {
|
|
|
- const { current, pageSize } = myData.pagination;
|
|
|
- let res = await selectUserList({
|
|
|
- id: myData.id,
|
|
|
- page: current || 1,
|
|
|
- limit: pageSize || 10,
|
|
|
- });
|
|
|
- myData.TableData = res.list || [];
|
|
|
- myData.pagination.total = res.totalCount || 0;
|
|
|
- console.log('selectUserList', res, myData);
|
|
|
- }
|
|
|
+
|
|
|
async function beforeEditSubmit({ _, index, key, value }) {
|
|
|
myData.TableData[index][key] = value;
|
|
|
return true;
|
|
@@ -267,23 +234,14 @@
|
|
|
}
|
|
|
function openTargetModal() {
|
|
|
console.log('openTargetModal');
|
|
|
- addopenModal(true, {
|
|
|
- addList: (val) => {
|
|
|
- console.log('addList', val, myData.subNum > myData.pagination.total);
|
|
|
- if (myData.subNum > myData.pagination.total) {
|
|
|
- myData.TableData.push(val);
|
|
|
- console.log('addList', val, myData.TableData);
|
|
|
- } else {
|
|
|
- createMessage.error(t('routes.devices.excess'));
|
|
|
- }
|
|
|
- },
|
|
|
- });
|
|
|
+ addopenModal(true);
|
|
|
}
|
|
|
async function saveTable() {
|
|
|
- let tableData = tableRef.value.getDataSource() || [];
|
|
|
+ // let tableData = tableRef.value.getDataSource() || [];
|
|
|
+ let tableData = getDataSource();
|
|
|
let res = await saveSubUsers({
|
|
|
- id: myData.id,
|
|
|
- subNum: myData.subNum,
|
|
|
+ id: modelRef.id,
|
|
|
+ subNum: modelRef.subNum,
|
|
|
subUsers: tableData,
|
|
|
});
|
|
|
console.log('saveTable', res);
|
|
@@ -295,28 +253,29 @@
|
|
|
function addTabledata(val) {
|
|
|
console.log('addTabledata', val);
|
|
|
}
|
|
|
- onMounted(async () => {
|
|
|
- myData.id && getApiList();
|
|
|
- });
|
|
|
+
|
|
|
+ function handleAddUser(newUser) {
|
|
|
+ console.log('newUser', newUser);
|
|
|
+ insertTableDataRecord({
|
|
|
+ userName: newUser.managerPhone,
|
|
|
+ nickName: newUser.companyName,
|
|
|
+ });
|
|
|
+ }
|
|
|
return {
|
|
|
- tableRef,
|
|
|
register,
|
|
|
handleDelete,
|
|
|
registerEdit,
|
|
|
numOnChange,
|
|
|
- getApiList,
|
|
|
- pageChange,
|
|
|
- myData,
|
|
|
- getPagination,
|
|
|
+ modelRef,
|
|
|
schemas,
|
|
|
columns,
|
|
|
registerForm,
|
|
|
- modelRef,
|
|
|
+
|
|
|
handleVisibleChange,
|
|
|
beforeEditSubmit,
|
|
|
- register4,
|
|
|
+ registerModal,
|
|
|
openTargetModal,
|
|
|
- currentModal,
|
|
|
+
|
|
|
addopenModal,
|
|
|
saveTable,
|
|
|
closeModal,
|
|
@@ -324,6 +283,8 @@
|
|
|
t,
|
|
|
registerSubtable,
|
|
|
reloadSubtable,
|
|
|
+ searchInfo,
|
|
|
+ handleAddUser,
|
|
|
};
|
|
|
},
|
|
|
});
|