# CardId 实名购票

实名购票 。

# 基础用法

<template>
  <qinui-card-id
    :getData="onGetList"
    :getOneData="onGetOneData"
    :beforeEdit="onBeforeEdit"
    :postData="onPostData"
    popup-title="选择观演人"
    createPopupTitle="添加观演人"
    editPopupTitle="编辑观演人"
    desc="请填写2张游客信息"
    maxlength="2"
    v-model="theIds"
    :errMsg="() => '添加证件数不能超过票数'"
    placeholder="点击填写游玩人信息"
    formLabelPrefix="游客"
    :formConf="theFormConf"
    :fieldNames="theFieldNames"
  />
</template>

<script setup lang="ts">
  import { onMounted, ref } from 'vue';

  // 数据相关 datas.ts start
  const theOneData = [
    {
      id: 212832822,
      idcardType: 'idcard',
      idcardNumber: '11************3409',
      idcardNumberUnique: '5ca63acda00aafcac7bb7125aa18ef22',
      idcardName: '\u674e\u601d\u8f89\u8f89',
      isDefault: 2,
      idcardTypeName: '\u8eab\u4efd\u8bc1',
    },
  ];

  const theItemData = {
    id: 22832829,
    idcardType: 'idcard',
    idcardNumber: '110103198910120631',
    idcardNumberUnique: '80a144de715bf83bc7dfcb79d53eec7a',
    idcardName:
      '\u6492\u4ea7\u751f\u7684\u64e6\u62ed\u7684\u64e6\u6389\u65f6\u64e6\u6253\u6492\u64e6\u6253\u6492\u64e6\u624b\u6253\u64e6',
    isDefault: 2,
    idcardTypeName: '\u8eab\u4efd\u8bc1',
  };
  // 数据相关 datas.ts end

  // 配置相关 conf.ts start
  const theFieldNames = {
    label: 'idcardName',
    value: 'id',
    num: 'idcardNumber',
    type: 'idcardType',
    typeLabel: 'idcardTypeName',
    isDefault: 'isDefault',
  };

  const theSelectConf = [
    {
      pattern:
        '^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|[Xx])$',
      example: '11010219******479X',
      value: 'idcard',
      label: '身份证',
    },
  ];

  const onFormConf = (theSelect: any) => {
    return [
      {
        field: theFieldNames.label,
        comp: 'Input',
        label: '姓名',
        labelWidth: '160rpx',
        compProps: {
          border: 'none',
          placeholder: '请填写观演人姓名',
        },
      },
      {
        field: theFieldNames.type,
        comp: 'Picker',
        label: '证件类型',
        labelWidth: '160rpx',
        compProps: {
          options: theSelect,
          fieldNames: {
            label: 'label',
            value: 'value',
          },
          placeholder: '请选择证件类型',
        },
      },
      {
        field: theFieldNames.num,
        comp: 'Input',
        label: '证件号码',
        labelWidth: '160rpx',
        compProps: {
          border: 'none',
          options: theSelect,
          placeholder: '请填写证件号码',
        },
      },
      {
        field: theFieldNames.isDefault,
        label: '设置默认',
        comp: 'Switch',
        labelWidth: '160rpx',
        compProps: {},
      },
    ];
  };
  // 配置相关 conf.ts end

  const theIds = ref([]);
  // ajax 获取数据
  const onGetList = (theParams: any) => {
    let theDatas = {};
    if (theParams._page === 1) {
      theDatas = theOneData;
    } else {
      theDatas = {
        data: [],
        pagination: {
          total: 8,
          lastPage: 1,
        },
      };
    }
    return theDatas;
  };
  // 编辑的时候获取详情
  const onGetOneData = () => {
    return theItemData;
  };

  // 提交 创建 | 编辑 数据
  const onPostData = (theData: any) => {
    console.log(theData, '提交数据');
  };

  // 提交报错验证
  const onBeforeEdit = (theData: any, theFieldItems: any) => {
    console.log(theData, theFieldItems, 'theData');
    return new Promise((resolve) => {
      resolve(true);
    });
  };

  const theFormConf = ref<any>([]);
  // 设置 from
  const onSetFormConf = () => {
    theFormConf.value = onFormConf(theSelectConf);
  };

  onMounted(() => {
    onSetFormConf();
  });
</script>

# API


# Props

参数 说明 类型 默认值 可选值
cardTitle 卡片标题 String 实名购票 -
cardRadius 卡片圆角 String | Array small large | default | small | none
cardBorder 卡片是否有边框 Boolean false -
cardPadding 卡片内边距 Array | String ['large', 'large', 'none', 'large'] large | default | none
desc 描述 string - -
placeholder 没有添加的文案 string - -
formLabelPrefix 选择之后前面的占位文案 string - -
fieldNames 字段映射,参考 Object {
label: 'idcardName',
value: 'id',
num: 'idcardNumber',
type: 'idcardType',
typeLabel: 'idcardTypeName'
}
-
errMsg 报错验证方法 Function - -
formatData 格式化数据方法 Function - -
maxlength 大输入长度,设置为 -1 的时候不限制最多选几张 String | Number -1 -
tagMaxlength 标签最大个数 Number 3 -
getOneData 编辑的时候获取详情接口方法 Function - -
getData 获取列表数据的接口方法 Function - -
beforeEdit 创建之前的校验 Function - -
postData 创建 | 编辑提交方法 Function - -
extData 跟随接口的透传参数 Object - -
formConf 创建 | 编辑的表单配置 Array - -
usePage 是否使用分页 Boolean false -
popupTitle 弹框标题 String - -
createPopupTitle 创建的弹框标题 String - -
editPopupTitle 编辑的弹框标题 String - -
propsZIndex 弹框层级 Number 997 -
diy-style 自定义外部样式 string - -

# FieldNames Props

参数 说明 类型 默认值 可选值
label 标签展示的名字 String idcardName -
value 提交的字段 String id -
num 身份证的标识 String idcardNumber -
type 证件类型英文标识 String idcardType -
typeLabel 证件类型中文标识 String idcardTypeName -