<template>
  <div class="containe">
    <div class="tableWrap">
      <div class="titleWrap">
        <span class="title"></span>
        <a-button type="primary" @click="handleAdd">新增</a-button>
      </div>
      <a-table :dataSource="dataSource" :columns="productColumns" :pagination="false">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'action'">
            <a-button type="link">编辑</a-button>
            <a-button type="link">删除</a-button>
          </template>
        </template>
      </a-table>
    </div>
    <a-modal v-model:visible="visible" title="新增" @ok="handleSubmit">
      <a-form
        :model="formData"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
        autocomplete="off"
        ref="formRef"
        :rules="productRulesRef"
      >
        <a-form-item label="产品编号" name="code">
          <a-input v-model:value="formData.code" />
        </a-form-item>
        <a-form-item label="数量" name="number">
          <a-input v-model:value="formData.number" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { productColumns, productRulesRef } from '../schema';

  const visible = ref(false);
  const dataSource = ref();
  const formRef = ref();
  const formData = ref({
    code: '',
    number: '',
  });

  const handleAdd = () => {
    visible.value = true;
  };

  const handleSubmit = () => {
    formRef.value.validate().then(() => {
      visible.value = false;
    });
  };
</script>

<style lang="less" scoped>
  @import url('/@/style/index.less');
</style>
