<template>
  <BasicModal
    v-bind="$attrs"
    @register="register"
    title="备件入库"
    width="700px"
    @cancel="resetFields"
    :confirmLoading="loading"
    @ok="handleSubmit"
  >
    <div class="pt-2px pr-3px">
      <BasicTable @register="registerTable"></BasicTable>
    </div>
  </BasicModal>
</template>
<script lang="ts">
import { defineComponent, reactive, ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm } from '/@/components/Form/index';
import { useMessage } from '/@/hooks/web/useMessage';
import { partInStockLog, partInStock } from '/@/api/spares';
import { useI18n } from '/@/hooks/web/useI18n';
import { useTable, BasicTable, BasicColumn } from '/@/components/Table';

const { t } = useI18n();
export default defineComponent({
  components: { BasicModal, BasicTable },
  props: {
    userData: { type: Object },
  },
  emits: ['update', 'register'],
  setup(props, { emit }) {
    const fileFlow = reactive({
      file: null,
      type: 2, //2-普通发票，3-专用发票
    });
    const loading = ref(false);
    const { createMessage } = useMessage();
    const columns: BasicColumn[] = [
      {
        title: '备件编号',
        dataIndex: 'partId',
        width: 80,
      },
      {
        title: '备件名称',
        dataIndex: 'partName',
        width: 180,
      },
      {
        title: '入库数量',
        dataIndex: 'count',
        width: 80,
      },
      {
        title: '操作人',
        dataIndex: 'sysUserName',
        width: 100,
      },
      {
        title: '操作时间',
        dataIndex: 'createTime',
        width: 150,
      },
    ];

    const [registerTable, { reload }] = useTable({
      api: partInStockLog,
      columns,
      useSearchForm: false,
      showTableSetting: true,
      bordered: true,
      showIndexColumn: false,
      canResize: true,
      fetchSetting: {
        pageField: 'pageNum',
        sizeField: 'pageSize',
        listField: 'list',
        totalField: 'total',
      },
    });
    const [register, { closeModal }] = useModalInner((data) => {
        data && onDataReceive(data);
      });
    function onDataReceive(data) {
      reload();
    }
    const handleSubmit = async () => {
      closeModal()
    };
    return {
      register,
      registerTable,
      fileFlow,
      handleSubmit,
      loading,
      t,
    };
  },
});
</script>
