<template>
  <!-- 账户管理 -->
  <div class="account_info_business 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>
    </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">
                <mtp-table-button :buttons="firstBtn" :record="item" @click="openComponent" />
              </a-col>
            </a-row>
          </template>
          <a-collapse class="busyCollapse" v-for="(sub, j) in item.userlist" :key="j + '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>
              <mtp-table-button :buttons="handleBtnList(secondBtn,sub)" :record="sub" @click="openComponent" />
            </a-collapse-panel>
          </a-collapse>
        </a-collapse-panel>
      </a-collapse>
    </div>
    <component :is="componentId" v-if="componentId" :selectedRow="selectedData" @cancel="closeComponent"></component>
  </div>
</template>

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

export default defineComponent({
  name: 'account_info_business',
  components: {
    contextMenu,
    MtpTableButton,
    filterCustomTable,
    detail: defineAsyncComponent(() => import('../../compoments/detail-business/index.vue')),
    account_spot_modify: defineAsyncComponent(() => import('../../compoments/modify-business/index.vue')),
    account_spot_add: defineAsyncComponent(() => import('../../compoments/add-business/index.vue')),
    account_spot_resetpwd: defineAsyncComponent(() => import('../../compoments/reset-business/index.vue')),
    account_spot_locked: defineAsyncComponent(() => import('../../compoments/locked-business/index.vue')),
    account_spot_unlocked: defineAsyncComponent(() => import('../../compoments/unlocked-business/index.vue')),
    account_spot_cancel: defineAsyncComponent(() => import('../../compoments/cancel-business/index.vue')),
  },
  setup() {
    // 加载状态
    const loading = ref<boolean>(false);
    const { tableList, queryTable } = handlerManagerList(loading, 1);

    const firstBtn = getTableButton(['account_spot_add']);
    const secondBtn = getTableButton(['account_spot_add'], true);

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

    // 弹窗选中的数据
    const selectedData = ref<ErmcpLoginUserEx>();

    // 控制异步组件
    const { componentId, closeComponent, openComponent } = handleModalComponent(queryTableAction, selectedData);
    initData(() => {
      queryTableAction();
    });

    // 查询
    function search(value: any) { }
    return {
      selectedData,
      firstBtn,
      secondBtn,
      loading,
      search,
      tableList,
      getLoginStatusEnumItemName,
      handleBtnList,
      getAreaUserName,
      componentId,
      closeComponent,
      openComponent,
    };
  },
});
</script>

<style lang="less">
.account_info_business {
    .tltLeft {
        padding-left: 12px;
    }
    .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>
