const app = getApp()
const util = require("../../utils/jmsUtil.js");
const api = require('../../api/jms.js');

import moment from 'moment'



Page({
  data: {
		bookno:'',
		recordList:[],
		showPicker:false,
		currentItem:'',
		supplyList:[{name:'',num:1},{name:'',num:1}],
		columns:['超时补差','携带大型设备'],

  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		if(options.bookno){
			this.setData({
				bookno:options.bookno
			});
			
		}
	},
	getDiffOrderList(){
		wx.showLoading({
			title: '加载中...',
		});
		util.request(api.getDiffOrderList, {
			bookDetailId:this.data.bookno
	
		}, 'GET').then(res => {
			wx.hideLoading();
			if (res.errno === 0) {
				this.setData({
					recordList:res.data
				});
			}
		}).catch(err => {
			wx.hideLoading();
		});
	 },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

	},
	goDetail(e){
		let id=e.currentTarget.dataset.id
		wx.navigateTo({
			url: '/pages/supplyDetail/supplyDetail?id='+id,
		})
	},
	goEdit(){
		wx.navigateBack();
	},
	minusNum(e){
		 let index=e.currentTarget.dataset.index;
		 let num=e.currentTarget.dataset.num;
		 if(num<=1){
			wx.showToast({
        title: '数量不能再少了',
        icon: 'none',
        duration: 3000
			});
			return false;
		 }else{
			let item='supplyList['+index+']'+'.num';
			this.setData({
				[item]:num-1,
			});
		 }
	},
	addNum(e){
		let index=e.currentTarget.dataset.index;
		let num=e.currentTarget.dataset.num;
	
		 let item='supplyList['+index+']'+'.num';
		 this.setData({
			 [item]:num+1,
		 });
		
 },
	delItem(e){
		let index=e.currentTarget.dataset.index;
		let supplyList=this.data.supplyList;
		supplyList.splice(index, 1);
    this.setData({
      supplyList: supplyList
    });
	},
	addItem(){
		this.setData({
			supplyList: this.data.supplyList.concat({name:''}),
		})
	},
	pickerCancel(){
		this.setData({
			showPicker:false
		});
	},
	showTypePicker(e){
		let index=e.currentTarget.dataset.index;
		this.setData({
			currentItem:index,
			showPicker:true
		})
	},
	pickerConfirm(e){
	let value=e.detail.value;
		let index=e.detail.index;
		let item1='supplyList['+this.data.currentItem+']'+'.name';
		this.setData({
			[item1]:value,
			showPicker:false,
		});
	},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
		this.getDiffOrderList();
  },
 
  onHide: function () {

  },

  onUnload: function () {

  },


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

  },

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

  },

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

  },

})