// pages/application/index.js
import {
  ajax,
  ele_height
} from "../../utils/util";
const {
  globalData: {
    systemInfo
  }
} = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    multiIndex: [0, 0, 0],
    multiArray: [],
    uploadheight: 0,
    local_image_url: ''
  },
  area: [],
  changeSelectArea: [0, 0, 0],

  bindMultiPickerChange: function (e) {
    this.setData({
      multiIndex: e.detail.value
    })
  },
  uploadimg(e) {
    this.setData({
      uploadheight: ele_height(e, systemInfo.screenWidth * 0.8)
    })
  },
  upload() {
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success: e => {
        this.setData({
          local_image_url: e.tempFiles[0].tempFilePath
        })
      },
    })
  },
  delimg() {
    wx.showModal({
      title: "确定删除该图片？",
      content: "删除后需重新选择图片",
      success: (res) => {
        if (res.confirm) {
          this.setData({
            local_image_url: ''
          })
        }
      }
    })
  },
  bindMultiPickerColumnChange(e) {
    const {
      detail: {
        column,
        value
      }
    } = e;
    this.changeSelectArea[column] = value;
    const a0 = this.area[this.changeSelectArea[0]] || {
      child: []
    }
    const multiArray1 = a0.child.map(v => v.name);
    let multiArray2 = ((a0.child[this.changeSelectArea[1]] || {
      child: []
    }).child || []).map(v => v.name);
    this.setData({
      multiArray: [this.data.multiArray[0], multiArray1, multiArray2]
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    ajax({
      urlType: "fileurl",
      api: "/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/narea.json?data=" +
        Date.now()
    }).then(res => {
      this.area = res || [];
      const a0 = this.area[0] || {
        child: []
      }
      const multiArray0 = this.area.map(v => v.name);
      const multiArray1 = a0.child.map(v => v.name);
      const multiArray2 = (a0.child[0] || {
        child: []
      }).child.map(v => v.name);
      this.setData({
        multiArray: [multiArray0, multiArray1, multiArray2]
      })
    })
  },

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

  },

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

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})