<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="title" :footer="null" width="60%">
    <BasicForm @register="registerForm">
      <template #qrcode="{ model, field }">
        <QrCode :value="model[field]" :width="150" />
      </template>
    </BasicForm>
  </BasicModal>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { FormSchema } from '/@/components/Table';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { QrCode } from '/@/components/Qrcode/index';

  const formSchemas: FormSchema[] = [
    {
      label: '检查对象名称',
      field: 'jcdxmc',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '属地执法人员',
      field: '',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '经度',
      field: 'jd',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '纬度',
      field: 'wd',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '任务类型',
      field: 'rwlxmc',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '任务/问题描述',
      field: '',
      component: 'InputTextArea',
      colProps: { span: 24 },
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '任务类附件型',
      field: '',
      component: 'JUpload',
      colProps: { span: 24 },
      componentProps: () => {
        return {
          showUploadList: false,
          disabled: true,
          tipArr: ['支持50MB以内文件'],
        };
      },
    },
    {
      label: '检查小结',
      field: 'jcxj',
      component: 'InputTextArea',
      colProps: { span: 24 },
      componentProps: {
        disabled: true,
      },
    },
    {
      label: '二维码',
      field: 'qrcode',
      component: 'Input',
      colProps: { span: 24 },
      slot: 'qrcode',
    },
  ];
  //表单配置
  const [registerForm, { resetFields, setFieldsValue }] = useForm({
    //注册表单列
    schemas: formSchemas,
    //不显示查询和重置按钮
    showActionButtonGroup: false,
    baseColProps: { span: 12 },
    labelWidth: 180,
  });
  //表单赋值
  const [registerModal, { setModalProps }] = useModalInner(async (data) => {
    //重置表单
    await resetFields();
    setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
    //表单赋值
    await setFieldsValue({
      ...data.record,
    });
  });
  //设置标题
  const title = ref('查看基本信息');
</script>

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