<template>
  <a-modal v-model:open="visible" :title="title" @ok="handleOk" width="50%">
    <a-form :model="form" layout="vertical">
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="所属合同" name="contractName">
            <a-select
              v-model:value="form.contractName"
              :options="projectNameOptions"
              placeholder="请选择"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="项目名称" name="projectName">
            <a-input v-model:value="form.projectName" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="项目编号" name="projectCode">
            <a-input v-model:value="form.projectCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="项目类别" name="projectType">
            <a-select
              v-model:value="form.projectType"
              :options="projectNameOptions"
              placeholder="请选择"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="故障大类" name="faultCategory">
            <a-select
              v-model:value="form.faultCategory"
              :options="projectNameOptions"
              placeholder="请选择"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="12">
          <a-form-item label="接单超期时间" name="orderTakingOverTime">
            <a-input v-model:value="form.orderTakingOverTime" placeholder="接单超期时间(小时)" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="接单超期扣款" name="orderTakingCost">
            <a-input v-model:value="form.orderTakingCost" placeholder="接单超期扣款(元/小时)" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="12">
          <a-form-item label="处理超期时间" name="handleOverTime">
            <a-input v-model:value="form.handleOverTime" placeholder="处理超期时间(小时)" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="处理超期扣款" name="handleCost">
            <a-input v-model:value="form.handleCost" placeholder="处理超期扣款(元/小时)" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="项目概要" name="projectContent">
            <a-textarea v-model:value="form.projectContent" :rows="4" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="项目图标" name="icon">
            <a-upload
              v-model:file-list="form.icon"
              action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
            >
              <a-button type="primary"> 上传 </a-button>
            </a-upload>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]">
        <a-col :span="24">
          <a-form-item label="附件" name="attachment">
            <a-upload
              v-model:file-list="form.attachment"
              action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
            >
              <a-button type="primary"> 上传 </a-button>
            </a-upload>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script>
  import { reactive, ref } from 'vue';
  import { getInfo } from './api';
  // import { message } from 'ant-design-vue';
  export default {
    setup() {
      const title = ref('新增');
      const visible = ref(false);
      const form = reactive({
        contractName: '',
        contractCode: '',
        projectCode: '',
        projectType: '',
        faultCategory: '',
        orderTakingOverTime: '',
        orderTakingCost: '',
        handleOverTime: '',
        handleCost: '',
        projectContent: '',
        icon: [],
        attachment: [],
        id: null,
      });
      //下拉框
      const projectNameOptions = [
        {
          value: '1',
          label: 'a',
        },
        {
          value: '2',
          label: 'b',
        },
        {
          value: '3',
          label: 'c',
        },
      ];
      const showModal = async (type, id) => {
        if (type == 1) {
          title.value = '新增';
        } else if (type == 2) {
          title.value = '编辑';
          const data = await getInfo(id);
          for (let i in form) {
            form[i] = data[i];
          }
          console.log(id);
        }
        visible.value = true;
      };

      const handleOk = () => {
        console.log('Form Data:', form);
        // 在此处可以添加表单验证逻辑
        visible.value = false;
      };

      return {
        visible,
        title,
        form,
        showModal,
        handleOk,
        projectNameOptions,
      };
    },
  };
</script>

<style scoped>
  /* 可选样式调整 */
  .ant-modal-body {
    max-width: 600px;
    margin: 0 auto;
  }
</style>
