<template>
  <!-- 业务账户 -->
  <div class="account_info_business"
       :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>
    </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 :btnList="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>
            <BtnList :btnList="sub.btnList"
                     :record="sub"
                     @click="openComponent" />
          </a-collapse-panel>
        </a-collapse>
      </a-collapse-panel>
    </a-collapse>
    <component :is="componentId"
               v-if="componentId"
               :selectedRow="selectedData"
               @cancel="closeComponent"></component>
  </div>
</template>

<script lang="ts">
import { BtnList, contextMenu, defineAsyncComponent, defineComponent, ModalEnum } 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 { getUserName } from '@/services/bus/user';
import { _handleTableList } from '../setup';
import { ref } from 'vue';
import { handleModalComponent } from '@/common/setup/asyncComponent';
import { getBtnList_ } from '@/common/setup/table/button';
import { EnumRouterName } from '@/common/constants/enumRouterName';

const Add = defineAsyncComponent(() => import('../../compoments/add-business/index.vue'));
const Modify = defineAsyncComponent(() => import('../../compoments/modify-business/index.vue'));
const Reset = defineAsyncComponent(() => import('../../compoments/reset-business/index.vue'));
const Locked = defineAsyncComponent(() => import('../../compoments/locked-business/index.vue'));
const Cancel = defineAsyncComponent(() => import('../../compoments/cancel-business/index.vue'));
const Detail = defineAsyncComponent(() => import('../../compoments/detail-business/index.vue'));
const Unlocked = defineAsyncComponent(() => import('../../compoments/unlocked-business/index.vue'));

export default defineComponent({
    name: 'account_info_business',
    components: {
        contextMenu,
        BtnList,
        filterCustomTable,
        [ModalEnum.detail]: Detail,
        [ModalEnum.account_info_business_btn_modify]: Modify,
        [ModalEnum.account_info_business_btn_add]: Add,
        [ModalEnum.account_info_business_btn_reset]: Reset,
        [ModalEnum.account_info_business_btn_locked]: Locked,
        [ModalEnum.account_info_business_btn_cancel]: Cancel,
        [ModalEnum.account_info_business_btn_unlocked]: Unlocked,
    },
    setup() {
        // 加载状态
        const loading = ref<boolean>(false);
        const { tableList, queryTable } = handlerManagerList(loading, 1);
        const [firstBtn, secondBtn] = getBtnList_(EnumRouterName.account_info_business, true).value;
        // 处理根据状态显示对应按钮
        function handleBtnAction() {
            _handleTableList(queryTable, tableList, secondBtn);
        }
        // 弹窗选中的数据
        const selectedData = ref<ErmcpLoginUserEx>();
        // 控制异步组件
        const { componentId, closeComponent, openComponent } = handleModalComponent(handleBtnAction, selectedData);
        initData(() => {
            handleBtnAction();
        });
        // 查询
        function search(value: any) {}
        return {
            selectedData,
            firstBtn,
            secondBtn,
            loading,
            search,
            tableList,
            getLoginStatusEnumItemName,
            handleBtnAction,
            getUserName,
            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>
