<template>
  <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="cp名称" prop="cp_name"
      :rules="[{ required: true, message: 'cp名称必须填写' }]">
      <el-input v-model="formData.cp_name" v-if="formData.cp_id" readonly name="cp_name" clearable />
      <el-input v-model="formData.cp_name" v-else name="cp_name" clearable />
      <!-- <label style="color: red;">注意：cp名称必须以zy_开头</label> -->
    </el-form-item>
    <el-form-item label="cp简称" prop="cp_nick" :rules="[{ required: true, message: 'cp简称必须填写' }]">
      <el-input v-model="formData.cp_nick" name="cp_nick" clearable />
    </el-form-item>
    <el-form-item label="所属公司" prop="cp_company" :rules="[{ required: true, message: '所属公司必须填写' }]">
      <el-input v-model="formData.cp_company" name="cp_company" clearable />
    </el-form-item>
    <el-form-item label="联系人" prop="manager" :rules="[]">
      <el-input v-model="formData.manager" name="manager" clearable />
    </el-form-item>
    <el-form-item label="联系电话" prop="phone" :rules="[ { pattern: /^1[3456789]\d{9}$/, message: '联系电话号码格式不正确', trigger: 'blur' }]">
      <el-input v-model="formData.phone" name="phone" clearable />
    </el-form-item>
    <el-form-item label="电子邮箱" prop="email" :rules="[
        {
          type: 'email',
          message: '邮箱格式不正确',
        },
      ]">
      <el-input v-model="formData.email" name="email" clearable />
    </el-form-item>
    <el-form-item label="分成比例:" prop="share_per" :rules="[{ required: true, message: '分成比例必须填写' }]">
      <el-input type="number" v-model="formData.share_per" name="share_per" clearable />
      <label style="color: red;">注意：分成比例为百分比,请输入0到100之间的数字，最小为0最大是100</label>
    </el-form-item>
    <el-form-item label="公司地址" prop="address" :rules="[{ required: true, message: '公司地址必须填写' }]">
      <el-input v-model="formData.address" name="address" clearable />
    </el-form-item>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
// import { InfoFilled } from '@element-plus/icons-vue';
import { useCreate } from '@/hook/curd/useCreate';
import { useShow } from '@/hook/curd/useShow';

import { onMounted } from 'vue';

const props = defineProps({
  primary: String | Number,
  api: String
});

const { formData, form, loading, submitForm, close } = useCreate(
  props.api,
  props.primary
);

formData.value.status = 1;
formData.value.sort = 1;

if (props.primary) {
  useShow(props.api, props.primary, formData);
}
const emit = defineEmits(['close']);

onMounted(() => {
  close(() => emit('close'));
});

</script>

<style lang="scss" scoped></style>
