<!-- 用户编辑弹窗 -->
<template>
  <ele-modal
    width="75%"
    :visible="visible"
    :confirm-loading="loading"
    :title="'客户详情'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-form
      :label-col="{ md: { span: 4 }, sm: { span: 24 } }"
      :wrapper-col="{ md: { span: 19 }, sm: { span: 24 } }"
    >
      <div class="base-form" style="margin-bottom: 20px">
        <a-descriptions :title="customer.customerName" bordered>
          <a-descriptions-item label="客户名称">
            {{ customer.customerName }}
          </a-descriptions-item>
          <a-descriptions-item label="客户IP">
            {{ customer.customerCode }}
          </a-descriptions-item>
          <a-descriptions-item label="状态">
            <a-tag v-if="customer.status === '0'" color="green">正常</a-tag>
            <a-tag v-if="customer.status === '1'" color="red">禁用</a-tag>
          </a-descriptions-item>
          <a-descriptions-item label="排序">
            {{ customer.sortNumber }}
          </a-descriptions-item>
          <a-descriptions-item label="备注">
            {{ customer.comments }}
          </a-descriptions-item>
        </a-descriptions>
      </div>
    </a-form>
  </ele-modal>
</template>

<script lang="ts" setup>
  import { ref, reactive, watch } from 'vue';
  import { Form } from 'ant-design-vue';
  import { assignObject } from 'ele-admin-pro';
  import type { Customer } from '@/api/oa/customer/model';

  const useForm = Form.useForm;

  const props = defineProps<{
    // 弹窗是否打开
    visible: boolean;
    // 修改回显的数据
    data?: Customer | null;
  }>();

  const emit = defineEmits<{
    (e: 'done'): void;
    (e: 'update:visible', visible: boolean): void;
  }>();

  // 用户信息
  const customer = reactive<Customer>({
    createTime: '',
    customerName: '',
    customerCode: '',
    comments: '',
    sortNumber: undefined,
    status: undefined,
    customerId: 0
  });

  // 请求状态
  const loading = ref(true);

  const { resetFields } = useForm(customer);

  /* 更新visible */
  const updateVisible = (value: boolean) => {
    emit('update:visible', value);
  };

  /* 打开外部链接 */
  // const openUrl = (record) => {
  //   window.open(record.panel);
  // };

  watch(
    () => props.visible,
    (visible) => {
      if (visible) {
        if (props.data) {
          loading.value = false;
          assignObject(customer, props.data);
        }
      } else {
        resetFields();
      }
    }
  );
</script>
<style lang="less">
  .tab-pane {
    min-height: 100px;
  }
</style>
