// pages/login/login.js
import WxValidate from '../../utils/wxValidate'
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 主体高度
        infoHeight: '',
        frameStyle: { useTop: true, name: '创建团队', leftArrow: true, useBar: false },
        form: {
            src: '/image/tou.png',
            ranks: '比赛第一名队',
            mechanism: '吉佳通达',
            type: ['乒乓球', '足球'],
            objectSex: [{ id: 0, name: '乒乓球' }, { id: 1, name: '足球' },],

        },
        lists: [
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
            {
                id: '1', text: '哈拉海队', logo: '/image/logo1.png', jian: '/image/jian.png '
            },
        ],
        index: 0,
    },
    //选择
    bindPickerChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index: e.detail.value
        })
    },
    back: function () {
        wx.navigateBack({ url: '/pages/me/index' })
    },
    //点击加号添加
    addList: function () {
        var lists = this.data.lists;
        var newData = {};
        lists.push(newData);//实质是添加lists数组内容，使for循环多一次
        this.setData({
            lists: lists,
        })
    },
    //点击减号删除
    delList: function () {
        var lists = this.data.lists;
        lists.pop();      //实质是删除lists数组内容，使for循环少一次
        this.setData({
            lists: lists,
        })
    },
    //提交
    formSubmit: function (e) {
        console.log('form发生了submit事件，携带数据为：', e.detail.value)
    },
    //上传图片
    afterRead: function (event) {
        const { file } = event.detail;
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式app.globalData.fileUrl：
        console.log(file);
        wx.uploadFile({
            url: `${app.globalData.imageUrl}/files/court/elimg/upload`,
            filePath: file.url,
            name: 'file',
            formData: {},
            success: (res) => {
                console.log(res);
                if (res.statusCode == '200') {
                    let data = [{ name: JSON.parse(res.data).name, url: `${app.globalData.imageUrl}` + JSON.parse(res.data).uri }]
                    const { fileList = [] } = this.data;
                    fileList.push({ ...file, url: res.data });
                    this.setData({ fileList });
                } else {
                    wx.showToast({ title: `${res.data.errmsg}`, icon: 'fail', duration: 2000 })
                }
            },
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // 计算高度
        this.searchHeight()
    },
    // 计算高度
    searchHeight: function () {
        let frameStyle = this.data.frameStyle;
        let client = app.globalData.client;
        // 减去状态栏
        let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
        // 是否减去底部菜单
        if (frameStyle.useBar) infoHeight = infoHeight - 50;
        if (infoHeight) this.setData({ infoHeight: infoHeight })
    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})