<template>
  <!-- 单据查询 委托单-->
  <div class="platinum_document_query_order">
    <Filter @search="search" />
    <contextMenu :contextMenuList="firstBtn">
      <a-table :columns="columns"
               class="topOrderTable"
               :scroll="{ x: '100%', y: 'calc(100vh - 163px)' }"
               :pagination="false"
               :expandedRowKeys="expandedRowKeys"
               :customRow="Rowclick"
               rowKey="key"
               :data-source="tableList">
        <!-- 额外的展开行 -->
        <template #expandedRowRender="{ record }">
          <BtnList :btnList="firstBtn"
                   class="btn-list-sticky"
                   @onClick="btnClick(record)" />
        </template>
        <!-- 账户类型 -->
        <template #userinfotype="{ record }">
          <a>{{ record.userinfotype === 1 ? "个人" : "企业" }}</a>
        </template>
        <!-- 委托状态 -->
        <template #orderstatus="{ record }">
          <a>{{ getOrderStatusName(record.orderstatus) }}</a>
        </template>

      </a-table>
    </contextMenu>
    <!-- <ControlModal :selectedRow="selectedRow" /> -->
  </div>
</template>

<script lang="ts">
import { defineComponent, initData, getTableColumns, getTableEvent, contextMenu, BtnList, _getBtnList, queryTableList } from '@/common/export/table';
import { queryTradeOrderDetail } from '@/services/go/ermcp/qhj';
import { QueryTradeOrderDetailRsp } from '@/services/go/ermcp/order/interface';
import Filter from '../../compoments/filter/index.vue';
import { QueryTradeOrderDetailReq } from '@/services/go/ermcp/qhj/interface';
import { getUserId } from '@/services/bus/account';
import { getOrderStatusName } from '@/common/constants/enumsName';

export default defineComponent({
    name: 'platinum_document_query_order',
    components: { Filter, contextMenu, BtnList },
    setup() {
        // 表头数据
        const { columns, registerColumn, updateColumn } = getTableColumns();
        // 表格事件
        const { expandedRowKeys, selectedRow, Rowclick, btnClick } = getTableEvent<QueryTradeOrderDetailRsp>({});
        // 表格操作按钮列表
        const [firstBtn] = _getBtnList('platinum_document_query_order', false).value;
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList();
        function search(value: any) {
            const { includesub, goodsid, filtername, userid, ordertime, userinfotype } = value;
            const len = ordertime.length;
            const param: QueryTradeOrderDetailReq = {
                userid: userid[0] ? userid[0] : getUserId(),
                userinfotype: userinfotype[0] ? userinfotype[0] : 0,
                filtername: filtername[0],
                begindate: len > 1 ? ordertime[0] : '',
                enddate: len > 1 ? ordertime[len - 1] : '',
                goodsid: goodsid[0],
                includesub,
            };
            queryTable(queryTradeOrderDetail, param);
        }
        initData(() => {
            // 获取列表数据
            queryTable(queryTradeOrderDetail, { userid: getUserId() });
            // 注册表头信息 过滤
            registerColumn('table_pcweb_qhj_order', ['goodsid', 'ordertime', 'operatorid']);
        });

        return {
            columns,
            search,
            expandedRowKeys,
            selectedRow,
            Rowclick,
            firstBtn,
            loading,
            tableList,
            btnClick,
            getOrderStatusName,
        };
    },
});
</script>