<template>
  <!-- 库存审核 入库-->
  <div class="inventory_review_checkin"
       :loading="loading">
    <Filter @search="updateColumn"
            :inOrOut="'in'">
      <BtnList :btnList="commonBtn" />
    </Filter>
    <contextMenu :contextMenuList="forDataBtn">
      <a-table :columns="columns"
               class="topTable"
               :pagination="false"
               :expandedRowKeys="expandedRowKeys"
               :customRow="Rowclick"
               rowKey="key"
               :data-source="tableList">
        <!-- 额外的展开行 -->
        <template #expandedRowRender="{ record }">
          <BtnList :btnList="record.btnList" />
        </template>
        <!-- 状态 -->
        <template #applystatus="{ text }">
          <a>{{ getApplyStatusName(text) }}</a>
        </template>
        <!-- 现货合同类型 -->
        <template #contracttype="{ text }">
          <a>{{ getContractTypeName(text) }}</a>
        </template>
        <!-- 点价类型 -->
        <template #pricetype="{ text }">
          <a>{{ getPriceTypeName(text) }}</a>
        </template>
        <!-- 出入库类型 -->
        <template #inouttype="{ text }">
          <a>{{ InOutTypeName(text) }}</a>
        </template>

      </a-table>
    </contextMenu>
    <!-- 审核-->
    <CheckinAudit :selectedRow="selectedRow"
                  @refresh="getTableData" />
    <!-- 撤销 -->
    <CheckinCancel :selectedRow="selectedRow"
                   @refresh="getTableData" />
    <!-- 详情 -->
    <CheckinDetail :selectedRow="selectedRow"
                   @refresh="getTableData" />
  </div>
</template>

<script lang="ts">
import { defineComponent, initData, getTableColumns, getTableEvent, getBtnList, contextMenu, BtnList } from '@/common/export/table';

import { Filter, CheckinAudit, CheckinCancel, CheckinDetail } from '../../components';

import { queryTableList, Ermcp3AreaStockApply } from '../setup';
import { getContractTypeName, getPriceTypeName, getApplyStatusName } from '@/common/constants/enumsName';
import { operateApplyTypeName } from '@/views/manage/finance-review/setup';
import { InOutTypeName } from '@/views/manage/inventory-review/setup';
import { Column, ColumnType } from '@/common/setup/table';

export default defineComponent({
    name: 'inventory_review_checkin',
    components: {
        contextMenu,
        Filter,
        BtnList,
        CheckinAudit,
        CheckinCancel,
        CheckinDetail,
    },
    setup() {
        // 表头数据
        const { columns, registerColumn, updateColumn } = getTableColumns();
        // 表格事件
        const { expandedRowKeys, selectedRow, Rowclick } = getTableEvent<Ermcp3AreaStockApply>({});
        // 表格操作按钮列表
        const { commonBtn, forDataBtn } = getBtnList('inventory_review_checkin', true);
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList({ inouttype: '1,3' });
        function getTableData() {
            // 获取列表数据
            queryTable().then(() => {
                tableList.value.forEach((el) => {
                    if (el.applystatus === 1) {
                        // 1:待审核
                        Object.assign(el, { btnList: forDataBtn.value });
                    } else {
                        const item = forDataBtn.value.find((e) => e.lable === '详情');
                        item && Object.assign(el, { btnList: [item] });
                    }
                });
            });
        }
        initData(() => {
            // 获取列表数据
            getTableData();
            // 注册表头信息 过滤
            registerColumn('table_pcweb_stock_aduit_in', ['contracttype', 'contractno', 'deliverygoodsname'], (e: Column, item: ColumnType, filtered: any) => {
                if (e.columnfield === 'buyusernameOrsellusername') {
                    item.onFilter = (value: string, record: Ermcp3AreaStockApply) => {
                        const { contracttype, buyusername, sellusername } = record;
                        if (contracttype === 1) {
                            // 采购
                            return sellusername.includes(value);
                        } else {
                            return buyusername.includes(value);
                        }
                    };
                    item.filteredValue = filtered.buyusernameOrsellusername || null;
                }
            });
        });

        return {
            columns,

            expandedRowKeys,
            selectedRow,
            Rowclick,
            commonBtn,
            forDataBtn,
            loading,
            tableList,
            updateColumn,
            getApplyStatusName,
            getContractTypeName,
            operateApplyTypeName,
            getPriceTypeName,
            InOutTypeName,
            getTableData,
        };
    },
});
</script>

<style lang="less">
.inventory_review_checkin {
}
</style
>;

