<template>
  <!-- 仓库信息: 正常 -->
  <mtp-table-scroll>
    <template #header>
      <Filter @search="updateColumn">
        <mtp-table-button class="btn-list-sticky" :buttons="addButton" @click="openComponent" />
      </Filter>
    </template>
    <template #default="{ scroll }">
      <a-table :columns="isPingAnOem() ? pingan_cwarehousecolumn() : columns" class="srcollYTable" :scroll="scroll" :pagination="false" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :rowKey="(record,index)=>index" :data-source="tableList">
        <!-- 额外的展开行 -->
        <template #expandedRowRender="{ record }">
          <mtp-table-button class="btn-list-sticky" :buttons="buttons" :record="record" @click="openComponent" />
        </template>
        <template v-if="isPingAnOem()" #index="{ index }">
          <span>{{ index + 1 }}</span>
        </template>
        <template #warehousetype="{ text }">
          <span>{{ getWareHouseTypeName(text) }}</span>
        </template>
        <template #warehousestatus="{ text }">
          <span>{{ gerWareHouseStatusName(text) }}</span>
        </template>
        <!-- 所在地区 -->
        <template #provinceid="{ record }">
          <span>{{ getProvinceName(record.provinceid) + getCityName(record.cityid) + getDistrictName(record.districtid) }}</span>
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
  <!-- 右键 -->
  <contextMenu :contextMenu="contextMenu" @cancel="closeContext" :list="buttons"> </contextMenu>
  <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"> </component>
</template>

<script lang="ts">
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { ComposeTableParam, contextMenu, defineAsyncComponent, defineComponent, handleComposeTable, MtpTableButton, queryTableList } from '@/common/export/commonTable';
import { isPingAnOem } from '@/common/config/projectName';
import { pingan_cwarehousecolumn } from '../setup';
import { getWareHouseTypeName, gerWareHouseStatusName } from '../index';
import { QueryWareHouse } from '@/services/go/ermcp/warehouse-info/index';
import { ErmcpWareHouseInfo } from '@/services/go/ermcp/warehouse-info/interface';
import Filter from '../../compoments/filterTable/index.vue';
import { getTableButton } from '@/common/setup/table/button';
import { useRoute } from 'vue-router';
import { getAddress } from '@/services/go/adress';

export default defineComponent({
  name: 'warehouse-info-normal',
  components: {
    MtpTableScroll,
    contextMenu,
    MtpTableButton,
    Filter,
    detail: defineAsyncComponent(() => import('../../compoments/detail/index.vue')), // 详情
    add: defineAsyncComponent(() => import('../../compoments/add/index.vue')), // 新增
    modify: defineAsyncComponent(() => import('../../compoments/modify/index.vue')), // 修改
    disable: defineAsyncComponent(() => import('../../compoments/disable/index.vue')), // 停用
    recover: defineAsyncComponent(() => import('../../compoments/recover/index.vue')), // 恢复
  },
  setup() {
    const { name: routeName } = useRoute();
    // 新增权限按钮
    const addButton = getTableButton(['add']);
    // 表格权限按钮
    const buttons = getTableButton(['add'], true);
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<ErmcpWareHouseInfo>();

    // 获取列表数据
    const queryTableAction = () => {
      switch (routeName) {
        // 正常
        case 'warehouse_normal':
          queryTable(QueryWareHouse, '1');
          break;
        // 停用
        case 'warehouse_disabled':
          queryTable(QueryWareHouse, '2');
          break;
      }
    };

    // 表格通用逻辑
    const param: ComposeTableParam = {
      queryFn: queryTableAction,
      tableName: 'table_pcweb_warehouse',
    };

    return {
      ...handleComposeTable<ErmcpWareHouseInfo>(param),
      loading,
      tableList,
      getWareHouseTypeName,
      gerWareHouseStatusName,
      queryTable,
      isPingAnOem,
      pingan_cwarehousecolumn,
      buttons,
      addButton,
      ...getAddress(),

    };
  },
});
</script>