// pages/createFile/createFile.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    choseAvatar: false,
    choseAvaSrc: '',
    sexIndex: '0',
    pickerText: '请选择',
    relativeText: '请选择',
    relativeRange: ['爸爸','妈妈', '爷爷', '奶奶']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 保存
   */
  handleSave() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    setTimeout(() => {
      wx.hideLoading({
        success: (res) => {},
      })
    }, 1400);
  },

  /**
   * 选择关系
   */
  bindReaPickerChange(e) {
    var value = this.data.relativeRange[e.detail.value]
    this.setData({
      relativeText: value
    })
  },

  /**
   * 用户选择生日
   */
  bindPickerChange(e) {
    this.setData({
      pickerText: e.detail.value
    })
  },

  /**
   * 切换性别
   */
  handleSex(e) {
    console.log(e.currentTarget.dataset.index);
    this.setData({
      sexIndex: e.currentTarget.dataset.index
    })
  },

  /**
   * 用户选择头像
   */
  handleChoseAvatar() {
    var that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        // tempFilePath可以作为 img 标签的 src 属性显示图片
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths);
        that.setData({
          choseAvatar: true,
          choseAvaSrc: tempFilePaths
        })
      }
    })
  }
})