<template>
  <a-list-layout
    ref="pageRef"
  >
    <template #search>
      <pro-query :searchParam="searchParam" @on-search="search"></pro-query>
    </template>
      <!-- 区域出入口列表 -->
    <pro-table ref="tableRef" :fetch="fetch" :columns="columns" :toolbar="toolbar" :operate="operate"
      :param="state.param" :pagination="pagination">
    </pro-table>
    <save :visible="state.visibleSave" @close="closeSave"></save>
    <edit :visible="state.visibleEdit" @close="closeEdit" :record="state.recordEdit"></edit>
  </a-list-layout>
</template>

<script>
  import save from './modal/save.vue';
  import edit from './modal/edit.vue';
  import {
    page
  } from "@/api/wms/inventoryStatistics";
  import {
    reactive,
    createVNode,
    ref
  } from 'vue';


  export default {
    components: {
      save,
      edit,
    },
    setup() {

      const tableRef = ref();
      /// 列配置
      const columns = [{
        dataIndex: "index",
        key: "index",
        title: "序号",
        width: 60,
        fixed: 'left',
        align: 'center'
      },
      {
          dataIndex: "skuType",
          key: "skuType",
          title: "物料类别",
        },
        {
          dataIndex: "skuCode",
          key: "skuCode",
          title: "物料编号",
          showSearch: true,
        },
        {
          dataIndex: "skuName",
          key: "skuName",
          title: "物料名称",
          showSearch: true,
        },
        {
          dataIndex: "skuQty",
          width: 120,
          align: 'right',
          key: "skuQty",
          title: "物料库存",
        }
      ];

      /// 数据来源 [模拟]
      const fetch = async (param) => {
        var response = await page(param);
        return {
          total: response.data.total,
          data: response.data.record,
        };
      };


      /// 工具栏
      const toolbar = [

      ];

      /// 行操作
      const operate = [

      ];

      /// 分页参数
      const pagination = {
        pageNum: 1,
        pageSize: 20,
        showSizeChanger: true, // 显示可改变每页条数
        pageSizeOptions: ["10", "20", "50", "100"], // 每页条数选项设置
        showTotal: total => `共 ${total} 条记录`, // 显示总条数
        showSizeChange: (current, pageSize) => (this.pageSize = pageSize) // 改变每页条数时更新显示
      }

      /// 外置参数 - 当参数改变时, 重新触发 fetch 函数
      const state = reactive({
        selectedRowKeys: [],
        param: {},
        visibleSave: false,
        visibleEdit: false,
        recordEdit: {},
        recordInfo: {},
      })

      //界面头部-查询框
      const searchParam = [{
        key: "skuType",
        type: "select",
        label: "物料类型",
        options: [{
          value: '包装箱',
          text: '包装箱',
        }, {
          value: '观察窗',
          text: '观察窗',
        }, {
          value: '台面',
          text: '台面',
        }, {
          value: '手把',
          text: '手把',
        }, {
          value: '前板',
          text: '前板',
        },{
          value: '内衬',
          text: '内衬',
        }, {
          value: 'KTP001',
          text: '空托盘',
        }]
      }, ]

      const search = function(value) {
        state.param = value
      }

      // const closeSave = function() {
      //   tableRef.value.reload();
      //   state.visibleSave = false
      // }

      // const closeEdit = function() {
      //   tableRef.value.reload();
      //   state.visibleEdit = false
      // }

      const onSelectChange = selectedRowKeys => {
        state.selectedRowKeys = selectedRowKeys;
      };

      return {
        state, // 状态共享
        fetch, // 数据回调
        toolbar, // 工具栏
        columns, // 列配置
        operate, // 行操作
        pagination, // 分页配置

        search,
        searchParam, // 查询参数

        // closeSave,
        // closeEdit,

        onSelectChange,
        tableRef
      };
    },
  };
</script>
