let myPro = require("../../../utils/wxRequest.js");
let util = require("../../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
		imgUrl: getApp().globalData.imgUrl,
		begin_at: '',
		end_at: '',
		status: 1, // 
		is_ziti: 1,
		info: null, // 店铺详情
		showBegin: false, // 开店 时间pop
		currentBegin: '',
		showEnd: false, // 闭店 时间pop
		currentEnd: '',
		is_delivery: 1 // 1允许配送 0不允许
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
		let that = this;
    },

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

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
		var that = this
		that.getShopInfo();
    },

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

    },

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

    },

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

    },

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

    },
	onPageScroll: function (event) {
        // Do something when page scroll
		
    },
    onResize: function () {
        // Do something when page resize
    },
	// 获取店铺信息
	getShopInfo(){
		let that = this;
		myPro.wxRequest("store/info","GET",{}).then(res=>{
			that.setData({
				info: res.result,
				begin_at: res.result.begin_at,
				end_at: res.result.end_at,
				status: res.result.status,
				is_ziti: res.result.is_ziti,
				is_delivery: res.result.is_delivery
			});
		}).catch(err=>{
			console.log('报错信息',err)
			wx.showToast({
				title: err,
				icon: "none"
			});
		});
	},
	// 去个人资料
	goMyIndex(){
		wx.reLaunch({
            url: '/pages/user/index/index'
        })
	},
	// 是否营业
	onChangeSell(event){
		let that = this;
		that.setData({
			status: event.detail,
		});
		that.editShop()
	},
	// 是否自提
	onChangeZiti(event){
		let that = this;
		that.setData({
			is_ziti: event.detail,
		});
		that.editShop()
	},
	// 是否允许配送
	onChangeDelivery(event){
		let that = this;
		that.setData({
			is_delivery: event.detail,
		});
		that.editShop()
	},
	// 去门店订单
	goShopOrder(event){
		let that = this;
		let status = event.currentTarget.dataset.status
		// console.log('订单状态',event)
		wx.navigateTo({
            url: '/pages/shopRole/order/index?status='+ status
        })
	},
	// 开店时间
	beginTimeFun(){
		let that = this;
		that.setData({
			showBegin: true
		})
	},
	confirmBeginTime(event){
		// console.log('开始时间',event)
		let that = this;
		that.setData({
			begin_at: event.detail,
			showBegin: false
		})
		that.editShop()
	},
	closeBeginTimePop(){
		let that = this;
		that.setData({
			showBegin: false
		})
	},
	// 闭店时间
	endTimeFun(){
		let that = this;
		that.setData({
			showEnd: true
		})
	},
	confirmEndTime(event){
		// console.log('闭店时间',event)
		let that = this;
		that.setData({
			end_at: event.detail,
			showEnd: false
		})
		that.editShop()
	},
	closeEndTimePop(){
		let that = this;
		that.setData({
			showEnd: false
		})
	},
	// 编辑店铺信息
	editShop(){
		let that = this;
		let params = {
			status: that.data.status,
			is_ziti: that.data.is_ziti,
			begin_at: that.data.begin_at,
			end_at: that.data.end_at,
			is_delivery: that.data.is_delivery
		};
		myPro.wxRequest("store/editInfo","POST",params).then(res=>{
			wx.showToast({
				title: res.msg,
				icon: "none"
			});
			// 重新获取详情
			that.getShopInfo()
		}).catch(err=>{
			console.log('报错信息',err);
			wx.showToast({
				title: err,
				icon: "none"
			});
		})
	},
	// 提现
	goCashOut(){
		wx.navigateTo({
            url: '/pages/shopRole/cashout/index'
        })
	},
	// 提现记录
	goCashOutlog(){
		wx.navigateTo({
            url: '/pages/shopRole/cashoutlog/index'
        })
	},
	// 优惠券使用统计
	goShopCoupons(){
		let that = this;
		wx.navigateTo({
            url: '/pages/shopRole/usedcoupons/index'
        })
	},
	// 设置营业时间
	goBusinessTime(){
		let that = this;
		wx.navigateTo({
			url: "/pages/shopRole/businesstime/list/index"
		})
	}
})