|
@@ -3,6 +3,7 @@
|
|
|
v-bind="$attrs"
|
|
|
@register="register"
|
|
|
title="设备"
|
|
|
+ @ok="saveTable"
|
|
|
@visible-change="handleVisibleChange"
|
|
|
>
|
|
|
<div class="pt-3px pr-3px">
|
|
@@ -13,21 +14,31 @@
|
|
|
<template #name="{ model, field }">
|
|
|
{{ model[field] }}
|
|
|
</template>
|
|
|
- <template #addeduser="{ model, field }">
|
|
|
- {{ model[field] || 10 }}
|
|
|
- <a-button type="primary" preIcon="ic:outline-person-add"> 新增子账号 </a-button>
|
|
|
+ <template #addeduser>
|
|
|
+ {{ myData.pagination.total || 0 }}
|
|
|
+ <a-button @click="openTargetModal()" type="primary" preIcon="ic:outline-person-add">
|
|
|
+ 新增子账号
|
|
|
+ </a-button>
|
|
|
</template>
|
|
|
</BasicForm>
|
|
|
<div class="table_list">
|
|
|
- <BasicTable @register="registerTable" :canResize="true">
|
|
|
+ <BasicTable
|
|
|
+ title="子账户列表"
|
|
|
+ :columns="columns"
|
|
|
+ :showIndexColumn="false"
|
|
|
+ :dataSource="myData.TableData"
|
|
|
+ :bordered="true"
|
|
|
+ :pagination="false"
|
|
|
+ :beforeEditSubmit="beforeEditSubmit"
|
|
|
+ >
|
|
|
<template #action="{ record }">
|
|
|
<TableAction
|
|
|
:actions="[
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- icon: 'mdi:account-edit-outline',
|
|
|
- onClick: handleDelete.bind(null, record, 'edit'),
|
|
|
- },
|
|
|
+ // {
|
|
|
+ // label: '编辑',
|
|
|
+ // icon: 'mdi:account-edit-outline',
|
|
|
+ // onClick: handleDelete.bind(null, record, 'edit'),
|
|
|
+ // },
|
|
|
{
|
|
|
label: '解绑',
|
|
|
icon: 'mdi:account-multiple-remove-outline',
|
|
@@ -37,65 +48,91 @@
|
|
|
/>
|
|
|
</template>
|
|
|
</BasicTable>
|
|
|
+ <AddModal @register="register4" />
|
|
|
</div>
|
|
|
</div>
|
|
|
<EditModal @register="registerEdit" />
|
|
|
</BasicModal>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
- import { defineComponent, ref, nextTick } from 'vue';
|
|
|
+ import {
|
|
|
+ defineComponent,
|
|
|
+ ref,
|
|
|
+ reactive,
|
|
|
+ nextTick,
|
|
|
+ onMounted,
|
|
|
+ unref,
|
|
|
+ ComponentOptions,
|
|
|
+ shallowRef,
|
|
|
+ computed,
|
|
|
+ } from 'vue';
|
|
|
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
|
|
|
- import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
|
|
|
+ import { BasicTable, BasicColumn, TableAction } from '/@/components/Table';
|
|
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
|
|
- import { selectUserList } from '/@/api/corporation/modal';
|
|
|
+ import { selectUserList, saveSubUsers } from '/@/api/corporation/modal';
|
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
import EditModal from './EditModal.vue';
|
|
|
+ import { tableState } from './types/hooks';
|
|
|
+ import AddModal from './AddModal.vue';
|
|
|
export default defineComponent({
|
|
|
- components: { BasicModal, BasicForm, BasicTable, TableAction, EditModal },
|
|
|
+ components: { BasicModal, BasicForm, BasicTable, AddModal, TableAction, EditModal },
|
|
|
props: {
|
|
|
userData: { type: Object },
|
|
|
},
|
|
|
- setup(props) {
|
|
|
- const { createConfirm } = useMessage();
|
|
|
+ emits: ['reload'],
|
|
|
+ setup(props, context) {
|
|
|
+ const { createConfirm, createMessage } = useMessage();
|
|
|
+ const currentModal = shallowRef<Nullable<ComponentOptions>>(null);
|
|
|
+ const [register4, { openModal: addopenModal }] = useModal();
|
|
|
const modelRef = ref({});
|
|
|
// const editList = ref({
|
|
|
// list:[]
|
|
|
// })
|
|
|
+ const myData = reactive<tableState>({
|
|
|
+ TableData: [],
|
|
|
+ subNum: null,
|
|
|
+ id: null,
|
|
|
+ pagination: {
|
|
|
+ total: 0,
|
|
|
+ pageSize: 9999,
|
|
|
+ current: 1,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ 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 columns: BasicColumn[] = [
|
|
|
{
|
|
|
title: '姓名',
|
|
|
dataIndex: 'memoName',
|
|
|
- width: 100,
|
|
|
+ edit: true,
|
|
|
+ editRule: true,
|
|
|
+ width: 200,
|
|
|
},
|
|
|
{
|
|
|
title: '手机号',
|
|
|
+ edit: true,
|
|
|
+ editRule: true,
|
|
|
+ width: 200,
|
|
|
dataIndex: 'phone',
|
|
|
- width: 150,
|
|
|
},
|
|
|
- ];
|
|
|
- const [registerTable, { setProps, reload }] = useTable({
|
|
|
- title: '子账户列表',
|
|
|
- api: selectUserList,
|
|
|
- pagination: false,
|
|
|
- columns: columns,
|
|
|
- rowKey: 'id',
|
|
|
- fetchSetting: {
|
|
|
- pageField: 'pageNum',
|
|
|
- sizeField: 'pageSize',
|
|
|
- listField: 'list',
|
|
|
- totalField: 'total',
|
|
|
- },
|
|
|
- afterFetch: (T) => {
|
|
|
- console.log('afterFetch', T);
|
|
|
- return T;
|
|
|
- },
|
|
|
- actionColumn: {
|
|
|
- width: 160,
|
|
|
+ {
|
|
|
title: '操作',
|
|
|
- dataIndex: 'action',
|
|
|
+ dataIndex: '',
|
|
|
slots: { customRender: 'action' },
|
|
|
+ width: 120,
|
|
|
},
|
|
|
- });
|
|
|
+ ];
|
|
|
const schemas: FormSchema[] = [
|
|
|
{
|
|
|
field: 'userName',
|
|
@@ -148,27 +185,21 @@
|
|
|
},
|
|
|
});
|
|
|
const [registerEdit, { openModal: EditModal }] = useModal();
|
|
|
- const [register] = useModalInner((data) => {
|
|
|
+ const [register, { closeModal }] = useModalInner((data) => {
|
|
|
data && onDataReceive(data);
|
|
|
});
|
|
|
|
|
|
function onDataReceive(data) {
|
|
|
console.log('Data Received', data.record);
|
|
|
// 方式1;
|
|
|
+ let { id, subNum } = data.record;
|
|
|
resetFields();
|
|
|
setFieldsValue({
|
|
|
...data.record,
|
|
|
});
|
|
|
-
|
|
|
- // // 方式2
|
|
|
- modelRef.value = { ...data.record };
|
|
|
- let { id } = data.record;
|
|
|
- setProps({
|
|
|
- searchInfo: {
|
|
|
- id,
|
|
|
- },
|
|
|
- });
|
|
|
- reload();
|
|
|
+ myData.id = id;
|
|
|
+ myData.subNum = subNum;
|
|
|
+ getApiList();
|
|
|
}
|
|
|
function numOnChange(event) {
|
|
|
console.log('numOnChange', event);
|
|
@@ -195,20 +226,78 @@
|
|
|
console.log('confirm', confirm);
|
|
|
}
|
|
|
}
|
|
|
+ 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({ record, index, key, value }) {
|
|
|
+ myData.TableData[index][key] = value;
|
|
|
+ console.log('单元格数据正在准备提交', record, myData.TableData[index]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
function handleVisibleChange(v) {
|
|
|
v && props.userData && nextTick(() => onDataReceive(props.userData));
|
|
|
}
|
|
|
-
|
|
|
+ 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('子账号数量已满!');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ async function saveTable() {
|
|
|
+ let res = await saveSubUsers({
|
|
|
+ id: myData.id,
|
|
|
+ subNum: myData.subNum,
|
|
|
+ subUsers: myData.TableData,
|
|
|
+ });
|
|
|
+ console.log('saveTable', res, context);
|
|
|
+ context.emit('reload');
|
|
|
+ closeModal();
|
|
|
+ }
|
|
|
+ onMounted(async () => {
|
|
|
+ myData.id && getApiList();
|
|
|
+ });
|
|
|
return {
|
|
|
register,
|
|
|
handleDelete,
|
|
|
registerEdit,
|
|
|
numOnChange,
|
|
|
- registerTable,
|
|
|
+ getApiList,
|
|
|
+ pageChange,
|
|
|
+ myData,
|
|
|
+ getPagination,
|
|
|
schemas,
|
|
|
+ columns,
|
|
|
registerForm,
|
|
|
modelRef,
|
|
|
handleVisibleChange,
|
|
|
+ beforeEditSubmit,
|
|
|
+ register4,
|
|
|
+ openTargetModal,
|
|
|
+ currentModal,
|
|
|
+ addopenModal,
|
|
|
+ saveTable,
|
|
|
+ closeModal,
|
|
|
};
|
|
|
},
|
|
|
});
|