/*
 * @Descripttion: zx
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: zx
 * @Date: 2021-11-04 18:41:28
 * @LastEditors: zx
 * @LastEditTime: 2021-11-29 11:49:08
 */

const pageOptions = {
  // 页面数据
  data: {
    isFirstOnShow: true,
    form: [],
    index: 0,
    certificateType: [
      {
        type: "ID_Card",
        text: "中国居民身份证",
      },
      {
        type: "Passport",
        text: "护照",
      },
      {
        type: "HongKong_Macau_Pass",
        text: "港澳居民来往内地通行证",
      },
      {
        type: "Taiwan_Pass",
        text: "台湾居民来往大陆通行证",
      },
    ],
  },
  Change({ currentTarget: { dataset }, detail }) {
    const { key, formKey = "form", value} = dataset;
    this.setData({
      index: detail.value,
      [`${formKey}.${key}`]: typeof detail === "string" ? detail : value,
    });
    console.log(this.data.form);
  },
  // 输入
  onInputChange({ currentTarget: { dataset }, detail }) {
    const { key, formKey = "form" } = dataset;
    let { value } = detail;
    if (key === "sex") value = +value;
    this.setData({
      [`${formKey}.${key}`]: typeof detail === "string" ? detail : value,
    });
    console.log(this.data.form);
    console.log({ currentTarget: { dataset }, detail });
  },
  // 页面载入时
  onLoad(e) {
    this.init(e);
  },
  // 页面初始化
  init(e) {},
  // 页面准备好时
  onReady() {},
  // 页面显示时
  onShow() {
    const { isFirstOnShow } = this.data;

    if (isFirstOnShow) {
      // 首次执行时
      this.setData({
        isFirstOnShow: false,
      });
      return;
    }
  },
  // 页面隐藏时
  onHide() {},
  // 页面卸载时
  onUnload() {},
  // 下拉页面时
  onPullDownRefresh() {},
  // 到达页面底部时
  onReachBottom() {},
  // 页面滚动时
  onPageScroll() {},
  // 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
  onShareAppMessage() {
    /* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
  },
};

Page(pageOptions);
