<template>
  <!-- 管理账户 -->
  <div class="account_info_manager account_info_container" :loading="loading">
    <filterCustomTable @search="search"></filterCustomTable>
    <div class="tltLeft">
      <span class="blue">
        <svg class="icon svg-icon" aria-hidden="true">
          <use xlink:href="#icon-shuzhuangtu"></use>
        </svg>
        {{ getAreaUserName() }}
      </span>
      <mtp-table-button :buttons="firstBtn" @click="openComponent" />
    </div>
    <div class="a-collapse-container">
      <a-collapse class="spotCollapse" v-for="(item, i) in tableList" :key="i + '11'" :bordered="false">
        <template #expandIcon="props">
          <svg class="icon svg-icon" aria-hidden="true" v-if="props.isActive == 0">
            <use xlink:href="#icon-shouqi1"></use>
          </svg>
          <svg class="icon svg-icon" aria-hidden="true" v-else>
            <use xlink:href="#icon-shouqi2"></use>
          </svg>
        </template>
        <a-collapse-panel>
          <template #header>
            <a-row class="headRow">
              <a-col :span="12">{{ item.rolename }}({{ item.userlist.length }}）</a-col>
              <a-col :span="12">
                <!-- <BtnList :selectedData="item" :btnList="secondBtn" @onClick="openAction" /> -->
                <mtp-table-button :buttons="secondBtn" :record="item" @click="openComponent" />
              </a-col>
            </a-row>
          </template>
          <a-collapse class="busyCollapse" v-for="(sub, i) in item.userlist" :key="i + '11'" :bordered="false">
            <a-collapse-panel :show-arrow="false">
              <template #header>
                <a-row class="contRow">
                  <a-col :span="12">{{ sub.loginname }}-{{ sub.logincode }}</a-col>
                  <a-col :span="12">{{ getLoginStatusEnumItemName(sub.loginstatus) }}</a-col>
                </a-row>
              </template>
              <!-- <BtnList :btnList="sub.btnList" :selectedData="sub" @onClick="moreOptenAction" /> -->
              <mtp-table-button :buttons="handleBtnList(thirdBtn,sub)" :record="sub" @click="openSecondBtnAction" />
            </a-collapse-panel>
          </a-collapse>
        </a-collapse-panel>
      </a-collapse>
    </div>
    <component :is="componentId" v-if="componentId" :tableList="tableList" :selectedData="selectedData" @cancel="closeComponent"></component>
  </div>
</template>

<script lang="ts">
import { defineAsyncComponent, defineComponent, MtpTableButton } from '@/common/export/commonTable';
import { initData } from '@/common/methods';
import filterCustomTable from '@/views/information/goods/components/filterTable/index.vue';
import { getLoginStatusEnumItemName } from '@/common/constants/enumsName';
import { getAccountStatus, handleTableList, handleBtnList, useSelectedData, useTaAccount } from '../setup';
import { getAreaUserName } from '@/services/bus/user';
import { ErmcpLoginUser } from '@/services/go/ermcp/account/interface';
import { handlerManagerList } from '@/common/setup/user';
import { ref, Ref } from 'vue';
import { handleModalComponent } from '@/common/setup/asyncComponent';
import { getTableButton } from '@/common/setup/table/button';

export default defineComponent({
  name: 'account_info_manager',
  components: {
    MtpTableButton,
    filterCustomTable,
    detail: defineAsyncComponent(() => import('../../compoments/detail-managers/index.vue')), // 详情
    account_manager_add: defineAsyncComponent(() => import('../../compoments/add-managers-permission/index.vue')), // 新增权限模板
    account_manager_setting: defineAsyncComponent(() => import('../../compoments/managers-permission/index.vue')), // 权限设置
    account_manager_child_add: defineAsyncComponent(() => import('../../compoments/add-managers/index.vue')), //  新增账户
    account_manager_child_modify: defineAsyncComponent(() => import('../../compoments/modify-managers/index.vue')), // 修改
    account_manager_child_cancel: defineAsyncComponent(() => import('../../compoments/cancel-managers/index.vue')), // 注销
    account_manager_child_locked: defineAsyncComponent(() => import('../../compoments/locked-managers/index.vue')), // 锁定
    account_manager_child_unlocked: defineAsyncComponent(() => import('../../compoments/unlocked-managers/index.vue')), // 解锁
    account_manager_child_reset: defineAsyncComponent(() => import('../../compoments/reset-managers/index.vue')), // 重置
  },
  setup() {
    // 加载状态
    const loading = ref<boolean>(false);
    const { tableList, queryTable } = handlerManagerList(loading, 3);

    const firstBtn = getTableButton(['account_manager_add', 'account_manager_setting']);
    const secondBtn = getTableButton(['account_manager_child_add']);
    const thirdBtn = getTableButton(['account_manager_child_modify', 'account_manager_child_reset', 'account_manager_child_locked', 'account_manager_child_unlocked', 'account_manager_child_cancel', 'detail']);

    // 获取列表数据
    function queryTableAction() {
      handleTableList(queryTable, tableList);
    }

    // 弹窗选中的数据
    const selectedData = ref<ErmcpLoginUser>();
    // 控制异步组件
    const { componentId, closeComponent, openComponent } = handleModalComponent<ErmcpLoginUser>(queryTableAction, selectedData as Ref<ErmcpLoginUser>);

    // 处理点击 二级按钮时候 选中的数据
    const { firstSelectedData, openSecondBtnAction } = useSelectedData(tableList, openComponent);

    // 期货账户
    const { updateTaAccount } = useTaAccount();
    initData(() => {
      queryTableAction();
      updateTaAccount();
    });

    // 查询
    function search(value: any) { }

    return {
      firstBtn,
      secondBtn,
      thirdBtn,
      loading,
      search,
      tableList,
      getAccountStatus,
      getAreaUserName,
      getLoginStatusEnumItemName,
      componentId,
      closeComponent,
      openComponent,
      firstSelectedData,
      openSecondBtnAction,
      handleBtnList,
      selectedData,
    };
  },
});
</script>

<style lang="less">
.account_info_manager {
    .tltLeft {
        padding-left: 12px;
        margin-top: 14px;
        .ant-btn.operBtn {
            height: 26px;
            line-height: 27px;
            margin-top: 0;
            margin-bottom: 0;
        }
    }
    .btn-list {
        .btnPrimary.ant-btn {
            height: 26px;
            line-height: 26px;
        }
    }
    .ant-collapse.spotCollapse.ant-collapse-borderless {
        padding-left: 43px;
        padding-right: 43px;
        .btnPrimary.ant-btn {
            margin-top: -3px;
        }
    }
    .ant-collapse.busyCollapse {
        .operBtn.ant-btn {
            margin-top: 0;
            margin-bottom: 0;
            height: 26px;
            line-height: 26px;
        }
    }
    .ant-row.headRow {
        .ant-col:nth-child(2) {
            text-align: right;
            .operBtn.ant-btn {
                float: right;
                margin-top: -3px;
                margin-bottom: 10px;
                height: 26px;
                line-height: 27px;
            }
        }
    }
}
</style>
