<template>
    <view>
        <view class="mvxyck">
            <!-- <view class="vimgb">
                <image src="@/static/penlo1669267729817.png" mode="widthFix" class="the_path_168uy"></image>
                <view class="enjoy_a_clap_169iw">惊喜区</view>
                <image src="@/static/spvzc1669267807530.png" mode="widthFix" class="the_path_168uy"></image>
            </view> -->
            <image src="@/static/blrkv1669267657514.png" mode="widthFix" class="sybxn"></image>
			
			<view v-for="(item, index) in goodlist" :key="index">
				
			
            <view class="rectangular_54nz">
                <view class="rectangular_46ue">
                    <view class="ynusc">{{index+1}}</view>
                    <view class="the_warehouse">号仓</view>
                </view>
				<view class="box_fff">
					<view class="bnrmd">
						<view class="rectangular_67lk">{{item.name}}</view>
						<image :src="item.litpic" mode="widthFix" class="the_mask_73jy"></image>
						<view class="since">{{item.price}}起</view>
					</view>
					<view class="stwdcp">
						<view class="le_ticket">乐票：
							<view class="sfwitk">{{ item.lpnum }}&nbsp;/&nbsp;{{item.cgkc}}%</view>
						</view>
						<view class="cycle_day">周期：
							<view class="sfwitk">{{ item.tianshu }}天&nbsp;/&nbsp;{{ item.shouyi }}%</view>
						</view>
						<view class="ws60cef">{{ item.kssj}}&nbsp;~&nbsp;{{ item.jssj}}</view>
						<view class="fjpar">
							
							<view class="rectangular_61de_ismxl" @click="autoYuyue(item.id, 1, index)" v-if="item.zt1==0">自动一单</view>
							<view class="rectangular_61de"v-if="item.zt1==1">{{item.ztmc1}}</view>
							
							<view class="rectangular_61de_ismxl" @click="autoYuyue(item.id, 2, index)"  v-if="item.zt2==0">自动二单</view>
							<view class="rectangular_61de" v-if="item.zt2==1">{{item.ztmc2}}</view>
							
							<view class="rectangular_61de_ismxl" @click="autoYuyue(item.id, 0, index)"  v-if="item.zt3==0">手动预约</view>
							<view class="rectangular_61de" v-if="item.zt3==1">{{item.ztmc3}}</view>
						</view>
					</view>
				</view>
            </view>
            
			</view>
        </view>
	</view>
</template>
<script>
    export default {
    	data() {
    		return {
    			constants: {},
    			goodlist: [],
    			num: 0,
    			id: 0,
    			userinfo: null
    		};
    	},
    	onShow() {
    		var user = this.$api.getUserinfo();
    		if (user) {
    			this.userinfo = user;
    		} else {
    			this.userinfo = null;
    		}
    		this.getMhGoodlist();
    	},
    	filters: {
    		formatDate: function(value, args) {
    			var dt = new Date(value);
    			if (args == 'yyyy-M-d') {
    				// yyyy-M-d
    				let year = dt.getFullYear();
    				let month = dt.getMonth() + 1;
    				let date = dt.getDate();
    				return `${year}-${month}-${date}`;
    			} else if (args == 'yyyy-M-d H:m:s') {
    				// yyyy-M-d H:m:s
    				let year = dt.getFullYear();
    				let month = dt.getMonth() + 1;
    				let date = dt.getDate();
    				let hour = dt.getHours();
    				let minute = dt.getMinutes();
    				let second = dt.getSeconds();
    				return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
    			} else if (args == 'yyyy-MM-dd') {
    				// yyyy-MM-dd
    				let year = dt.getFullYear();
    				let month = (dt.getMonth() + 1).toString().padStart(2, '0');
    				let date = dt
    					.getDate()
    					.toString()
    					.padStart(2, '0');
    				return `${year}-${month}-${date}`;
    			} else if (args == 'HH:mm') {
    				// yyyy-MM-dd
    				let hour = dt
    					.getHours()
    					.toString()
    					.padStart(2, '0');
    				let minute = dt
    					.getMinutes()
    					.toString()
    					.padStart(2, '0');
    				return `${hour}:${minute}`;
    			} else {
    				// yyyy-MM-dd HH:mm:ss
    				let year = dt.getFullYear();
    				let month = (dt.getMonth() + 1).toString().padStart(2, '0');
    				let date = dt
    					.getDate()
    					.toString()
    					.padStart(2, '0');
    				let hour = dt
    					.getHours()
    					.toString()
    					.padStart(2, '0');
    				let minute = dt
    					.getMinutes()
    					.toString()
    					.padStart(2, '0');
    				let second = dt
    					.getSeconds()
    					.toString()
    					.padStart(2, '0');
    				return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
    			}
    		}
    	},
    	onLoad(option) {
    		// console.log(option);		
    	},
    	methods: {
    		autoYuyue(id, num, index) {
    			if (!this.userinfo) {
    				uni.showToast({
    					title: '请先登录',
    					icon: 'none'
    				});
    				return;
    			}
    			var that=this;			
    			var data = new Object();
    			data.cid = id;
    			data.uid = this.userinfo.id;
    			data.num = num;
    			this.$api
    				.MhGetModel(data, 'jingxi/yuyue')
    				.then(res => {
    					if (res.data.code != 0) {					
    						uni.showToast({
    							title: res.data.msg,
    							icon: 'none'
    						});
    						that.getMhGoodlist()
    						return;
    					} else {
    						uni.showToast({
    							title: res.data.msg,
    							icon: 'none'
    						});						
    					}
    				})
    				.catch(err => {
    					// console.log('request fail', JSON.stringify(err));
    				});
    		},
    		getMhGoodlist() {
    			var data = new Object();
    			data.uid = this.userinfo.id;
    			this.$api
    				.MhGetModel(data, 'jingxi/list')
    				.then(res => {
    					//// console.log(res.data.code)					
    						//// console.log('jingxi/list信息',JSON.stringify(res.data.data));
    						this.goodlist = res.data.data;
    					
    				})
    				.catch(err => {
    					// console.log('request fail', JSON.stringify(err));
    				});
    		}
    	}
    };
</script>
<style lang="scss" scoped>
    @import "index.scss";
</style>
<style>
	page{
		background: #f1f2f6;
	}
</style>