var app = new Vue({
	el:"#wrapper",
	data:{
		storeState: null,
		storeName:null,
		state:null,
		endingTime: null,
		lastDays: null,
		logo: "",
		checkable : true,
		hostName: 'http://ypx.shenmikj.com/am_shop/Wechat/Store/',
		renewState: false,
		renewDay: 0
	},
	methods:{
		renewDetail: function(){
			window.location.href = this.hostName+'renewList'
		},
		stateSwitch: function(){
			var that = this
			var state = null
			if (this.checkable) {
				this.checkable = false
				setTimeout(function(){
					if (that.storeState) {
						state = 1
					}else{
						state = 2
					}
					console.log(that.storeState,state)
					// return
						$.ajax({
							method:'get',
							url:'http://ypx.shenmikj.com/am_shop/Wechat/Api/updateStoreStatus',
							data:{
								status:state
							},
							dataType:"json",
							async: false,
							success: function(res){
								console.log(res)
								that.checkable = true
							},
							error: function(res){
								console.log(res)
							}
						})
				},200)
			}
		},
		renew: function(){
			this.renewState = !this.renewState
			var that =this
		},
		close: function(){
			this.renewState = !this.renewState
		},
		confirmRenew: function(){
			alert('续期：'+this.renewDay*30+'天')
			this.renewState = false
		},
		update: function(){
			var days = this.renewList[this.renewDay].days,
			money = this.renewList[this.renewDay].money
			console.log(days,money)
			// return
			$.ajax({
				method:'post',
				url:'http://ypx.shenmikj.com/am_shop/Wechat/Store/storeCenter',
				dataType:"json",
				data:{
					days:days,
					money:money
				},
				async: false,
				success: function(res){
					
				},
				error: function(res){
					console.log(res)
				}
			})
		}
	},
	created(){
		var that = this,
		logo = ""
		$.ajax({
			method:'get',
			url:'http://ypx.shenmikj.com/am_shop/Wechat/Api/getStoreStatus',
			dataType:"json",
			async: false,
			success: function(res){
				console.log(res)
				if(res.status == 1){
					that.state = res.status
					that.storeState = true
				}else{
					that.state = res.status
					that.storeState = false
				}
				that.storeName = res.name
				that.logo = res.logo
				console.log(that.state,that.storeState)
			},
			error: function(res){
				console.log(res)
			}
		})
		// this.logo = logo
		$.ajax({
			method:'get',
			url:'http://ypx.shenmikj.com/am_shop/Wechat/Api/getStoresInvalidTime',
			dataType:"json",
			success: function(res){
				console.log(res)
				that.endingTime = res.invalid_time
				that.lastDays = res.days
			},
			error: function(res){
				console.log(res)
			}
		})
		$.ajax({
			method:'get',
			url:'http://ypx.shenmikj.com/am_shop/Wechat/Api/getStoreRenewTimeMoney',
			dataType:"json",
			async: false,
			success: function(res){
				console.log(res)
				that.renewList = res.data
			},
			error: function(res){
				console.log(res)
			}
		})
	}
})