const app = getApp()
const util = require("../../../utils/util");
const api = require('../../../api/api.js');
const user = require('../../../utils/user.js');
import moment from 'moment'



Page({
  data: {
		showPicker:false,
		teamList:[],
		 columns:[],
		 teamName:'',
		 teamId:''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getSchTeamList()
	},
	getSchTeamList(){
		util.request(api.getSchTeamList, {
		
		}, 'GET').then(res => {
			wx.hideLoading();
			if (res.errno === 0) {
				this.setData({
					teamList:res.data,
				});
				let columns=this.data.teamList.map(item=>{return item.teamName });
				this.setData({
					columns:columns
				});
			

			}
		}).catch(err => {
			wx.hideLoading();
		});
	},
	applyTeam(){
		if(this.data.teamName==''){
			wx.showToast({
				title: '请选择更换的班组',
				icon: 'none',
			});
			return false;
		}

		wx.showLoading({
			title: '加载中...',
		});
		util.request(api.applyTeam, {
		teamId:this.data.teamId,
		teamName:this.data.teamName
		}, 'POST').then(res => {
			wx.hideLoading();
			if (res.errno === 0) {
				wx.showModal({
					title: '',
					content: '操作成功',
					showCancel: false,
					success:res => {
						if (res.confirm) {
						   wx.navigateBack();
						}
				  }
				});		

			}
		}).catch(err => {
			wx.hideLoading();
		});
	},
	showSelect(){
		this.setData({
			showPicker:true
					 });
	},
	pickerCancel(e){
     this.setData({
showPicker:false
		 });
	},
	pickerConfirm(e){
		this.setData({
			showPicker:false,
			teamName:e.detail.value,
			teamId:this.data.teamList[e.detail.index].teamId
					 });
	},
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

  onUnload: function () {

  },


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

  },

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

  },

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

  },

})