<template>
  <!-- 管理账户 -->
  <div class="account_info_manager"
       :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>
        {{getUserName()}}
      </span>
      <BtnList :btnList="firstBtn" />
    </div>

    <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" />
            </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" />
          </a-collapse-panel>
        </a-collapse>
      </a-collapse-panel>
    </a-collapse>
    <Add @refresh="handleBtnAction"
         :tableList="tableList" />
    <Modify :tableList="tableList"
            @refresh="handleBtnAction"
            :selectedData="moreModelData" />
    <Cancel @refresh="handleBtnAction"
            :selectedData="moreModelData" />
    <Locked @refresh="handleBtnAction"
            :selectedData="moreModelData" />
    <Unlocked @refresh="handleBtnAction"
              :selectedData="moreModelData" />
    <Reset @refresh="handleBtnAction"
           :selectedData="moreModelData" />
    <Detail :selectedData="moreModelData" />
    <AddPermission />
    <Permission />
  </div>
</template>

<script lang="ts">
import { defineComponent, initData, contextMenu, BtnList, _getBtnList } from '@/common/export/table';
import filterCustomTable from '@/views/information/goods/components/filterTable/index.vue';
import { getLoginStatusEnumItemName } from '@/common/constants/enumsName';
import { getAccountStatus, handleModalData, handleTableList } from '../setup';
import { getUserName } from '@/services/bus/user';
import Add from '../../compoments/add-managers/index.vue';
import Modify from '../../compoments/modify-managers/index.vue';
import Detail from '../../compoments/detail-managers/index.vue';
import Cancel from '../../compoments/cancel-managers/index.vue';
import Locked from '../../compoments/locked-managers/index.vue';
import Unlocked from '../../compoments/unlocked-managers/index.vue';
import Reset from '../../compoments/reset-managers/index.vue';
import AddPermission from '../../compoments/add-managers-permission/index.vue';
import Permission from '../../compoments/managers-permission/index.vue';
import { ErmcpLoginUser, ErmcpLoginUserEx } from '@/services/go/ermcp/account/interface';
import { openModal } from '@/common/setup/modal';
import { handlerManagerList } from '@/common/setup/user';
import { ref } from 'vue';

export default defineComponent({
    name: 'account_info_manager',
    components: {
        contextMenu,
        BtnList,
        filterCustomTable,
        Add,
        Modify,
        Detail,
        Cancel,
        Locked,
        Unlocked,
        Reset,
        AddPermission,
        Permission,
    },
    setup() {
        // 加载状态
        const loading = ref<boolean>(false);
        const { tableList, queryTable } = handlerManagerList(loading, 3);
        const [firstBtn, secondBtn, thirdBtn] = _getBtnList('account_info_manager', true).value;
        // 新增弹窗
        const { selectedData: addModelData, openAction } = handleModalData<ErmcpLoginUserEx>();
        // 修改 重置密码、详情等弹窗
        const { selectedData: moreModelData, openAction: moreOptenAction } = handleModalData<ErmcpLoginUser>();
        // 处理根据状态显示对应按钮
        function handleBtnAction() {
            handleTableList(queryTable, tableList, thirdBtn);
        }
        initData(() => {
            handleBtnAction();
        });

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

        return {
            firstBtn,
            secondBtn,
            thirdBtn,
            loading,
            search,
            tableList,
            getAccountStatus,
            getUserName,
            getLoginStatusEnumItemName,
            addModelData,
            openAction,
            moreModelData,
            moreOptenAction,
            handleBtnAction,
        };
    },
});
</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>
