<template>
	<view class="tabs">
		<!-- <scroll-view id="tab-bar" class="scroll-h" :scroll-x="true" :show-scrollbar="false" :scroll-into-view="scrollInto">
			<view v-for="(tab, index) in tabBars" :key="tab.id" class="uni-tab-item" :id="tab.id" :data-current="index" @click="ontabtap">
				<text class="uni-tab-item-title" :class="tabIndex == index ? 'uni-tab-item-title-active' : ''">{{ tab.name }}</text>
			</view>
		</scroll-view> -->

		<view class="end-title">
			<!-- <view @tap="change(0)" :class="{ btna: btnnum == 0 }">我的奖券</view> -->
			<view @tap="change(1)" :class="{ btna: btnnum == 1 }">发布活动</view>
			<view @tap="change(2)" :class="{ btna: btnnum == 2 }">已发布活动</view>
			<view @tap="change(3)" :class="{ btna: btnnum == 3 }">中奖专区</view>
		</view>

		<view class="line-h"></view>

		<!-- 111111 -->
		<!-- <view class="head flex" v-show="btnnum == 0" v-for="(item,index) in sample" :key="index">
			<view class="flex1"><image class="head_1" src="../../static/Course/oppoicon.png" mode=""></image></view>
			<view class="head_2">
				<view class="head_2_1">已购买{{item.num}}张抽奖券</view>
				<view class="head_2_2 jus-b">
					<view>已使用{{item.use_number}}张</view>
					<view class="head_2_1">再次购买</view>
				</view>
			</view>
		</view> -->
		<!-- 2222222 -->
		<view class="head_1" v-show="btnnum == 1">
			<view data-var="0">
				<view style="display: flex;justify-content: space-between;align-items: center;font-weight: bold;font-size: 16px;">
					<view class="bonus">奖项一</view>
					<!-- <view data-num=0 @tap="switching">关闭奖项</view> -->
				</view>
				<view class="bonus_1">
					<view class="bonus_1_1">
						<view class="bonus_1_1_1">奖品名称</view>
						<view class="bonus_1_1_1_1"><input class="input" type="text" name="name_1" v-model="prize[0].title" placeholder="请输入奖品名称" /></view>

						<view class="input_1"></view>
					</view>

					<view class="line-h"></view>
					<view class="bonus_1_1">
						<view class="bonus_1_1_1">中奖名额</view>

						<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_2" v-model="prize[0].num" placeholder="请输入中奖名额" /></view>

						<view class="input_1">名</view>
					</view>

					<view class="line-h"></view>

					<view class="bonus_1_1">
						<view class="bonus_1_1_1">中奖概率</view>

						<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_3" v-model="prize[0].proportion" placeholder="请输入中奖概率" /></view>

						<view class="input_1">%</view>
					</view>

					<view class="line-h"></view>

					<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
						<view class="uni-list-cell uni-list-cell-pd jus-b">
							<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否为奖品</view>
							<switch checked @change="switchs(1)" />
							<view class="bonus_1_1_1_1 nome"><input class="input" type="text" name="name_4" :value="this.prize[0].status" placeholder="" /></view>
						</view>
					</view>
				</view>

				<view class="bonus_2">
					<robby-image-upload
						fileKeyName="img"
						:value="c_pics"
						:server-url="uploadurl1 + '/merchant.php/FileUpload/uploadify'"
						:form-data="c_formData"
						:server-url-delete-image="uploadurl1"
						@delete="c_delImage"
						@add="c_onImg"
						@move="onMove_c"
						:limit="1"
					></robby-image-upload>
					<!-- <view> -->
					<!-- <view class="jus-c"><image class="bonus_img" style="margin: auto;" src="../../static/picture.png" mode=""></image></view> -->
					<!-- <view class="">请添加奖品图片</view> -->
					<!-- </view> -->
				</view>
			</view>

			<!-- 二 -->
			<view>
				<view style="display: flex;justify-content: space-between;align-items: center;font-weight: bold;font-size: 16px;">
					<view class="bonus">奖项二</view>
					<!-- <view data-num=1 @tap="switching">关闭奖项</view> -->
				</view>
				<view class="bonus_1">
					<view class="bonus_1_1">
						<view class="bonus_1_1_1">奖品名称</view>
						<view class="bonus_1_1_1_1"><input class="input" type="text" name="name_5" v-model="prize[1].title" placeholder="请输入奖品名称" /></view>
						<view class="input_1"></view>
					</view>

					<view class="line-h"></view>
					<view class="bonus_1_1">
						<view class="bonus_1_1_1">中奖名额</view>
						<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_6" v-model="prize[1].num" placeholder="请输入中奖名额" /></view>
						<view class="input_1">名</view>
					</view>

					<view class="line-h"></view>

					<view class="bonus_1_1">
						<view class="bonus_1_1_1">中奖概率</view>
						<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_7" v-model="prize[1].proportion" placeholder="请输入中奖概率" /></view>
						<view class="input_1">%</view>
					</view>

					<view class="line-h"></view>

					<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
						<view class="uni-list-cell uni-list-cell-pd jus-b">
							<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否为奖品</view>
							<switch checked @change="switchs(2)" />
							<view class="bonus_1_1_1_1 nome"><input class="input" type="text" name="name_8" :value="this.prize[1].status" placeholder="" /></view>
						</view>
					</view>
				</view>
				<view class="bonus_2">
					<robby-image-upload
						fileKeyName="img"
						:value="c_picss"
						:server-url="uploadurl1 + '/merchant.php/FileUpload/uploadify'"
						:form-data="c_formData"
						:server-url-delete-image="uploadurl1"
						@delete="c_delImage"
						@add="c_onImgs"
						@move="onMove_c"
						:limit="1"
					></robby-image-upload>
					<!-- <view>
					<view class="jus-c"><image class="bonus_img" style="margin: auto;" src="../../static/picture.png" mode=""></image></view>
					<view class="bonus_2_1">请添加奖品图片</view>
				</view> -->
				</view>
			</view>
			<!-- 3333333 -->

			<view class="beack">
				<view>
					<view style="display: flex;justify-content: space-between;align-items: center;font-weight: bold;font-size: 16px;">
						<view class="bonus">奖项三</view>
						<!-- <view data-num=2 @tap="switching">关闭奖项</view> -->
					</view>
					<view class="bonus_1">
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">奖品名称</view>
							<view class="bonus_1_1_1_1"><input class="input" type="text" name="name_9" v-model="prize[2].title" placeholder="请输入奖品名称" /></view>
							<view class="input_1"></view>
						</view>

						<view class="line-h"></view>
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖名额</view>
							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_10" v-model="prize[2].num" placeholder="请输入中奖名额" /></view>

							<view class="input_1">名</view>
						</view>

						<view class="line-h"></view>

						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖概率</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_11" v-model="prize[2].proportion" placeholder="请输入中奖概率" /></view>

							<view class="input_1">%</view>
						</view>

						<view class="line-h"></view>

						<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
							<view class="uni-list-cell uni-list-cell-pd jus-b">
								<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否为奖品</view>
								<switch checked @change="switchs(3)" />
								<view class="bonus_1_1_1_1 nome"><input class="input" type="text" name="name_12" :value="this.prize[2].status" placeholder="" /></view>
							</view>
						</view>
					</view>
					<view class="bonus_2">
						<robby-image-upload
							fileKeyName="img"
							:value="c_picsss"
							:server-url="uploadurl1 + '/merchant.php/FileUpload/uploadify'"
							:form-data="c_formData"
							:server-url-delete-image="uploadurl1"
							@delete="c_delImage"
							@add="c_onImgss"
							@move="onMove_c"
							:limit="1"
						></robby-image-upload>
						<!-- <view>
					<view class="jus-c"><image class="bonus_img" style="margin: auto;" src="../../static/picture.png" mode=""></image></view>
					<view class="bonus_2_1">请添加奖品图片</view>
				</view> -->
					</view>
				</view>
			</view>
			<!-- 444444 -->

			<view class="beack">
				<view>
					<view style="display: flex;justify-content: space-between;align-items: center;font-weight: bold;font-size: 16px;">
						<view class="bonus">奖项四</view>
						<!-- <view data-num=3 @tap="switching">关闭奖项</view> -->
					</view>
					<view class="bonus_1">
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">奖品名称</view>

							<view class="bonus_1_1_1_1"><input class="input" type="text" name="name_13" v-model="prize[3].title" placeholder="请输入奖品名称" /></view>

							<view class="input_1"></view>
						</view>

						<view class="line-h"></view>
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖名额</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_14" v-model="prize[3].num" placeholder="请输入中奖名额" /></view>

							<view class="input_1">名</view>
						</view>

						<view class="line-h"></view>

						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖概率</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_15" v-model="prize[3].proportion" placeholder="请输入中奖概率" /></view>

							<view class="input_1">%</view>
						</view>

						<view class="line-h"></view>

						<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
							<view class="uni-list-cell uni-list-cell-pd jus-b">
								<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否为奖品</view>
								<switch checked @change="switchs(4)" />
								<view class="bonus_1_1_1_1 nome"><input class="input" type="text" name="name_16" :value="this.prize[3].status" placeholder="" /></view>
							</view>
						</view>
					</view>
					<view class="bonus_2">
						<robby-image-upload
							fileKeyName="img"
							:value="c_picssss"
							:server-url="uploadurl1 + '/merchant.php/FileUpload/uploadify'"
							:form-data="c_formData"
							:server-url-delete-image="uploadurl1"
							@delete="c_delImage"
							@add="c_onImgsss"
							@move="onMove_c"
							:limit="1"
						></robby-image-upload>
						<!-- <view>
						<view class="jus-c"><image class="bonus_img" style="margin: auto;" src="../../static/picture.png" mode=""></image></view>
						<view class="bonus_2_1">请添加奖品图片</view>
					</view> -->
					</view>
				</view>
			</view>

			<!-- 55555 -->
			<view v-show="additio == 3 || additio == 4">
				<view>
					<view style="display: flex;justify-content: space-between;align-items: center;font-weight: bold;font-size: 16px;">
						<view class="bonus">奖项五</view>
						<!-- <view data-num=4 @tap="switching">关闭奖项</view> -->
					</view>
					<view class="bonus_1">
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">奖品名称</view>

							<view class="bonus_1_1_1_1"><input class="input" type="text" name="name_17" v-model="prize[4].title" placeholder="请输入奖品名称" /></view>

							<view class="input_1"></view>
						</view>

						<view class="line-h"></view>
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖名额</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_18" v-model="prize[4].num" placeholder="请输入中奖名额" /></view>

							<view class="input_1">名</view>
						</view>

						<view class="line-h"></view>

						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖概率</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_19" v-model="prize[4].proportion" placeholder="请输入中奖概率" /></view>

							<view class="input_1">%</view>
						</view>

						<view class="line-h"></view>

						<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
							<view class="uni-list-cell uni-list-cell-pd jus-b">
								<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否为奖品</view>
								<switch checked @change="switchs(5)" />
								<view class="bonus_1_1_1_1 nome"><input class="input" type="text" name="name_20" :value="this.prize[4].status" placeholder="" /></view>
							</view>
						</view>
					</view>
					<view class="bonus_2">
						<robby-image-upload
							fileKeyName="img"
							:value="c_picsssss"
							:server-url="uploadurl1 + '/merchant.php/FileUpload/uploadify'"
							:form-data="c_formData"
							:server-url-delete-image="uploadurl1"
							@delete="c_delImage"
							@add="c_onImgssss"
							@move="onMove_c"
							:limit="1"
						></robby-image-upload>
						<!-- <view>
						<view class="jus-c"><image class="bonus_img" style="margin: auto;" src="../../static/picture.png" mode=""></image></view>
						<view class="bonus_2_1">请添加奖品图片</view>
					</view> -->
					</view>
				</view>
			</view>

			<!-- 66666 -->

			<view :class="{ beack: additio == 4 }" class="nome">
				<view>
					<view style="display: flex;justify-content: space-between;align-items: center;font-weight: bold;font-size: 16px;">
						<view class="bonus">奖项六</view>
						<!-- <view data-num=5 @tap="switching">关闭奖项</view> -->
					</view>
					<view class="bonus_1">
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">奖品名称</view>

							<view class="bonus_1_1_1_1"><input class="input" type="text" name="name_21" v-model="prize[5].title" placeholder="请输入奖品名称" /></view>

							<view class="input_1"></view>
						</view>

						<view class="line-h"></view>
						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖名额</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_22" v-model="prize[5].num" placeholder="请输入中奖名额" /></view>

							<view class="input_1">名</view>
						</view>

						<view class="line-h"></view>

						<view class="bonus_1_1">
							<view class="bonus_1_1_1">中奖概率</view>

							<view class="bonus_1_1_1_1"><input class="input" type="number" name="name_23" v-model="prize[5].proportion" placeholder="请输入中奖概率" /></view>

							<view class="input_1">%</view>
						</view>

						<view class="line-h"></view>

						<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
							<view class="uni-list-cell uni-list-cell-pd jus-b">
								<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否为奖品</view>
								<switch checked @change="switchs(6)" />
								<view class="bonus_1_1_1_1 nome"><input class="input" type="text" name="name_24" :value="this.prize[5].status" placeholder="" /></view>
							</view>
						</view>
					</view>
					<view class="bonus_2">
						<robby-image-upload
							fileKeyName="img"
							:value="c_picssssss"
							:server-url="uploadurl1 + '/merchant.php/FileUpload/uploadify'"
							:form-data="c_formData"
							:server-url-delete-image="uploadurl1"
							@delete="c_delImage"
							@add="c_onImgsssss"
							@move="onMove_c"
							:limit="1"
						></robby-image-upload>
						<!-- <view>
						<view class="jus-c"><image class="bonus_img" style="margin: auto;" src="../../static/picture.png" mode=""></image></view>
						<view class="bonus_2_1">请添加奖品图片</view>
					</view> -->
					</view>
				</view>
			</view>

			<view class="jus-c bonus_3" @tap="addition">
				<view class="bonus_3_1"><image class="bonus_1_2" src="../../static/attachment.png" mode=""></image></view>
				<view class="bonus_3_2">添加更多奖项</view>
			</view>

			<view class="bonus_4">
				<view class="box">
					<view class="box_1">请填写活动名称：</view>
					<view class="bonus_4_1" style="width: 400upx;text-align: center;">
						<input class="input" type="text" v-model="diameter.name" placeholder="请输入活动名称" />
					</view>
					<!-- <view class="box_2">名</view> -->
				</view>
				<view class="line-h"></view>
				<view class="box">
					<view class="box_1">满足抽奖资格金额：</view>
					<view class="bonus_4_1" style="width: 240upx;text-align: center;">
						<input class="input" type="number" v-model="diameter.condition_money" placeholder="例:满100元" />
					</view>
					<view class="box_2">元</view>
				</view>

				<!-- <view class="bonus_4_1"><input class="input" type="text" name="name_14"  placeholder="请设置抽奖金额条件（例：满100元即可抽奖）"  /></view> -->

				<view class="line-h"></view>
				<!-- <view class="bonus_4_1"><input class="input" type="text" name="name_15" placeholder="满()元即可抽奖"  /></view>

				<view class="line-h"></view> -->

				<!-- <view class="box">
						<view class="box_1">请设置抽奖满足金额</view>
						<view class="bonus_4_1" style="width: 240upx;text-align: center;">
							<input class="input" type="number" name="name_15" placeholder="例:20元" />
						</view>
						<view class="box_2">元</view>
					</view>
					
					<view class="line-h"></view> -->
				<!-- 领取结束时间 -->
				<view class="box">
					<view class="box_1">活动领取结束时间：</view>
					<view class="bonus_4_1" style="width: 240upx;text-align: center;">
						<input class="input" type="number" v-model="diameter.receive_endtime" placeholder="例:20小时" />
					</view>
					<view class="box_2">小时</view>
				</view>

				<view class="line-h"></view>
				<!-- 时间选择 -->
				<view style="display: flex;padding:20upx 20upx 20upx 0;">
					<view class="title" style="flex:3;font-size: 28upx;font-weight: bold;margin:auto;">活动时间:</view>
					<view class="inputbox" style="flex:4;border: 1upx solid rgba(102,102,102,1);text-align: center;margin: auto;" @tap="showtime(1)">
						<input type="text" class="inputs" value="" v-model="diameter.start_time" disabled="disabled" placeholder="开始时间" placeholder-class="plclass" />
						<image class="jiantouicon" v-show="parameter.start_time == ''" src="../../static/LuckDraw/jiantou_icon.png" mode=""></image>
					</view>
					<view style="margin-left: 10;line-height:50upx;">-</view>
					<view class="inputbox" style="flex:4;border: 1upx solid rgba(102,102,102,1);text-align: center;margin: auto;" @tap="showtime(2)">
						<input type="text" class="inputs" value="" v-model="diameter.end_time" disabled="disabled" placeholder="结束时间" placeholder-class="plclass" />
						<image class="jiantouicon" v-show="parameter.start_time == ''" src="../../static/LuckDraw/jiantou_icon.png" mode=""></image>
					</view>
				</view>

				<!-- <view class="bonus_4_1"><input class="input" type="text" name="name_15" placeholder="请填写活动到期时间（例：2020-8-31 13:00）" /></view> -->

				<view class="line-h"></view>

				<view style="font-size: 28upx;font-weight: bold;margin: 10px 0 10px 0;">活动描述</view>

				<textarea v-model="diameter.content" style="height:300upx;width:660upx ;" placeholder="请输入活动描述"></textarea>
			</view>
			<view class="uni-list" style="padding: 24upx 0 24upx 0;line-height: 66upx;">
				<view class="uni-list-cell uni-list-cell-pd jus-b">
					<view class="uni-list-cell-db " style="font-size:28upx;font-weight: bold;margin: 0 20upx 0 20upx;">是否开启活动</view>
					<switch checked @change="switch1Change" />
				</view>
			</view>

			<view class="bonus_5"><button class="bonus_5_1" @tap="formSubmi" v-show="diameter.status == 2">确认发布</button></view>
			<!-- </form> -->
		</view>

		<!-- 333333 -->
		<view class="head_2" v-show="btnnum == 2">
			<view class="goods_item" v-for="(item, index) in published" :key="index">
				<view v-for="(ind, index) in item.prize" :key="index" style="display: flex;margin: 40upx 0 40upx 0;padding-bottom:40upx;">
					<view class="thumbnail">
						<view class="pmimg"><image :src="staticUrl + ind.pic" mode=""></image></view>
					</view>
					<view class="body_goods">
						<view class="shopname twoline">
							<text class="twoline_s">{{ ind.title }}</text>
							<text v-if="ind.num > 0">中奖名额{{ ind.num }}名</text>
						</view>
						<!-- <view class="flex"><view class="hongkng">一等奖 中奖名额 2名 3500</view></view> -->

						<view class="goods_foot flex ali-f jus-b">
							<view class="prciebox flex ali-f"><view class="shuzi">奖品</view></view>
							<view class="gmbtn" v-if="ind.use_number > 0">已中{{ ind.use_number }}名</view>
						</view>
					</view>
				</view>

				<view class="base" v-show="published.length > 0">
					<view>
						活动到期时间
						<text style="margin: 0 18upx 0 40upx;">{{ item.end_time }}</text>
					</view>

					<view class="base_1" :class="{ opa: item.status == 1 }" :data-id="item.id" v-show="item.status == 1" @tap="showstatus">已关闭活动</view>
					<view class="base_1" :data-id="item.id" v-show="item.status == 2" @tap="showstatus">已开启活动</view>
					<view class="base_1" :data-id="item.id" v-show="item.status == 3">已结束</view>
					<!-- <view class="base_1" else>活动已关闭</view> -->
				</view>
			</view>
		</view>

		<!-- 444444 -->
		<view class="head_2" v-show="btnnum == 3">
			<view class="goods_item" style="display: flex;" v-for="(item, index) in winning" :key="index">
				<view class="thumbnail">
					<view class="pmimg"><image :src="staticUrl + item.prize_pic" mode=""></image></view>
				</view>
				<view class="body_goods">
					<view class="shopname twoline jus-b">
						<view>
							<text class="twoline_s">{{ item.prize_title }}</text>
						</view>
						<view class="gmbtns" v-if="item.order_status == 1" @tap="express" :data-order_id="item.order_id">待领奖</view>
						<view class="gmbtns" v-if="item.order_status == 3" @tap="express" :data-order_id="item.order_id">待收货</view>

						<view class="gmbtns" v-if="item.order_status == 4" @tap="express" :data-order_id="item.order_id">已完成</view>
					</view>
					<view style="font-size: 30upx;font-weight: bold;">{{ item.nickname }} {{ item.mobile }}</view>
					<!-- <view class="flex"><view class="hongkng">一等奖 中奖名额 2名 3500</view>
					</view> -->

					<view class="goods_foot flex ali-f jus-b">
						<view class="prciebox flex ali-f"><view class="shuzi">奖品</view></view>
						<!-- <view class="gmbtns" v-if="item.order_status==1" @tap="express" :data-order_id="item.order_id">待领奖</view> -->

						<view class="gmbtns" v-if="item.order_status == 2" @tap="express" :data-order_id="item.order_id">发货</view>

						<!-- 	<view class="gmbtns" v-if="item.order_status==3" @tap="express" :data-order_id="item.order_id">待收货</view>
						<view class="gmbtns" v-if="item.order_status==4" @tap="express" :data-order_id="item.order_id">已完成></view> -->
					</view>
				</view>
			</view>
		</view>

		<!-- 时间弹窗 -->
		<w-picker
			mode="range"
			startYear="2019"
			endYear="2025"
			:defaultVal="defaultVal"
			:current="true"
			@confirm="onConfirm"
			:selectList="[]"
			themeColor="#f64f15"
			ref="picker"
		></w-picker>
	</view>
</template>
<script>
import robbyImageUpload from '@/components/plan-image-upload/up_img'; //上传资质图片组件
import wPicker from '@/components/w-picker/w-picker.vue'; //时间弹窗
import { addTurntableActivity, getTurntableActivityList, getShopLuckDrawList, getBuyRecord, setTurntableActivityStatus } from '@/utils/api/merchant.js';
// 缓存每页最多
const MAX_CACHE_DATA = 100;
// 缓存页签数量
const MAX_CACHE_PAGE = 3;

export default {
	components: {
		robbyImageUpload,
		wPicker
	},
	data() {
		return {
			targets: [],
			prize: [
				{ title: '', num: '', proportion: '', status: 1 },
				{ title: '', num: '', proportion: '', status: 1 },
				{ title: '', num: '', proportion: '', status: 1 },
				{ title: '', num: '', proportion: '', status: 1 },
				{ title: '', num: '', proportion: '', status: 1 },
				{ title: '', num: '', proportion: '', status: 1 }
			],
			shop_id: '',
			statuslist: [],
			sample: [], //抽奖劵
			isoneload: true, //是否第一次加载进来
			id: '',
			status: 2,
			// 已发布活动
			published: [],
			// 中奖
			winning: [],

			radioItems: [
				{
					name: 'USA',
					value: '美国'
				},
				{
					name: 'CHN',
					value: '中国',
					checked: 'true'
				}
			],
			btnnum: 1,
			scrollTop: '',
			isshowtop: false,
			page: 0, //中奖区
			page_1: 0, //中奖区
			page_2: 0, //中奖区
			shopdata: {}, //传送数据
			//时间弹窗
			selectList: [],
			defaultVal: [],
			c_pics: [], //主图的数据
			newsList: [],
			cacheTab: [],
			fromname: [],
			index: 0,
			c_picss: [],
			c_picsss: [],
			c_picssss: [],
			c_picsssss: [],
			c_picssssss: [],
			diameter: {
				name: '',
				condition_money: '',
				receive_endtime: '',
				start_time: '',
				end_time: '',
				content: '',

				status: 2,

				condition_list: []
			},
			c_photos: [], //主图的数据 单张的 存储数据 提交的数据需要转换
			additio: 2,
			tabIndex: 1,
			//表单提交的参数
			parameter: {
				end_time: '', //结束时间
				start_time: '' //开始时间
			},
			tabBars: [
				{
					name: '我的奖券',
					id: 'guanzhu'
				},
				{
					name: '发布活动',
					id: 'tuijian'
				},
				{
					name: '已发布活动',
					id: 'tiyu'
				},
				{
					name: '中奖专区',
					id: 'redian'
				}
			],
			scrollInto: '',
			showTips: false,
			navigateFlag: false,
			pulling: false,
			order_id: ''
			// vendor:""
		};
	},

	//监听滚动
	onPageScroll(e) {
		this.scrollTop = e.scrollTop;
		// console.log(e.scrollTop)
		//处理返回顶部
	},

	computed: {
		uploadurl1() {
			return this.$store.state.uploadurl1;
		},

		staticUrl() {
			//静态资源地址
			return this.$store.state.staticUrl;
		},
		//上传图片传的参数
		c_formData() {
			let obj = {
				model: 'goods',
				user_token: this.$store.state.token
			};
			return obj;
		}
	},
	//下拉刷新事件
	onPullDownRefresh() {
		this.winning = [];
		this.page = 0;
		this.getShopLuckDrawList();
	},
	//滚动到最底部 加载更多
	onReachBottom() {
		// console.log('11');
		if (this.btnnum == 3) {
			if (!this.isallshow) {
				this.getShopLuckDrawList();
			}
		}
	},
	onShow() {
		// this.addTurntableActivity();
		// this.getTurntableActivityList();
		// this.getShopLuckDrawList();
		// this.getBuyRecord()
	},
	onLoad(e) {
		console.log(e);

		this.shop_id = e.shop_id;
		// this.setTurntableActivityStatus();
		// this.getTurntableActivityList();
		// this.getShopLuckDrawList();

		// var d = new Date();
		// this.defaultVal = [(d.getFullYear()).toString(),(d.getMonth()+1).toString()]
		// this.defaultVal= [(d.getFullYear()).toString(),(d.getMonth()+1).toString(),'01','-',(d.getFullYear()).toString(),(d.getMonth()+1).toString(),'01'];
		// setTimeout(() => {
		// 	this.tabBars.forEach(tabBar => {
		// 		this.newsList.push({
		// 			data: [],
		// 			isLoading: false,
		// 			refreshText: '',
		// 			loadingText: '加载更多...'
		// 		});
		// 	});
		// 	// this.getList(0);
		// }, 350);
	},
	// 66666
	methods: {
		express(e) {
			console.log(e);
			let num = e.currentTarget.dataset.order_id;
			this.winning.map((item, index, arr) => {
				if (num == item.order_id) {
					console.log(item);
					uni.redirectTo({
						url: '/pages/myStore/delivery?order_id=' + item.order_id + '&shop_id=' + this.shop_id
					});
				}
			});
		},

		totop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 200
			});
		},

		// switch6(e) {
		// 	console.log(e);
		// 	if (e.target.value == true) {
		// 		this.prize[5].status = 1;
		// 	} else {
		// 		this.prize[5].status = 2;
		// 	}
		// },
		// switch5(e) {
		// 	console.log(e);
		// 	if (e.target.value == true) {
		// 		this.prize[4].status = 1;
		// 	} else {
		// 		this.prize[4].status = 2;
		// 	}
		// },
		// switch4(e) {
		// 	console.log(e);
		// 	if (e.target.value == true) {
		// 		this.prize[3].status = 1;
		// 	} else {
		// 		this.prize[3].status = 2;
		// 	}
		// },
		// switch3(e) {
		// 	console.log(e);
		// 	if (e.target.value == true) {
		// 		this.prize[2].status = 1;
		// 	} else {
		// 		this.prize[2].status = 2;
		// 	}
		// },
		// switch2(e) {
		// 	console.log(e);
		// 	if (e.target.value == true) {
		// 		this.prize[1].status = 1;
		// 	} else {
		// 		this.prize[1].status = 2;
		// 	}
		// },
		// switch1(e) {
		// 	console.log(e);
		// 	if (e.target.value == true) {
		// 		this.prize[0].status = 1;
		// 	} else {
		// 		this.prize[0].status = 2;
		// 	}
		// },
		
	
		switchs(index) {
			console.log(index);
			if (index == 1) {
				if (this.prize[0].status == 1) {
					this.prize[0].status = 2;
				} else {
					this.prize[0].status = 1;
				}
			}else if (index == 2) {
					if (this.prize[1].status == 1) {
						this.prize[1].status = 2;
					} else {
						this.prize[1].status = 1;
					}
			}else if (index == 3) {
					if (this.prize[2].status == 1) {
						this.prize[2].status = 2;
					} else {
					
						this.prize[2].status = 1;
					}
			}else if(index == 4) {
					if (this.prize[3].status == 1) {
						this.prize[3].status = 2;
					} else {
						this.prize[3].status = 1;
					}
			}else if(index == 5) {
					if (this.prize[4].status == 1) {
						this.prize[4].status = 2;
					} else {
					
						this.prize[4].status = 1;
					}
			}else if(index == 6) {
					if (this.prize[5].status == 1) {
						this.prize[5].status = 2;
					} else {
						this.prize[5].status = 1;
					}
			}
		},
		switching(e) {
			// console.log(this.shopdata)
			// this.shopdata.map((item, index, arr) => {
			// 	if(item.title==""){
			// 		arr.splice(index,1)
			// 		console.log("哈哈",arr)
			// 	}
			// })
		},

		// 9999999
		showstatus(e) {
			// this.getTurntableActivityList()
			let num = e.currentTarget.dataset.id;
			this.published.map((item, index, arr) => {
				if (num == item.id) {
					console.log(item);
					console.log(this.published[index].status);
					if (item.status == 1) {
						item.status = 2;
					} else {
						item.status = 1;
					}
					this.id = item.id;
					this.status = item.status;
					this.setTurntableActivityStatus();
				}
			});

			console.log(e, this.id, this.status);
		},

		radioChange: function(e) {
			var checked = e.detail.value;
			console.log(checked);
		},

		change(e) {
			console.log(e);
			this.btnnum = e;
			// if(e==1){
			// 		this.addTurntableActivity();
			// }
			if (e == 2) {
				this.getTurntableActivityList();
			} else if (e == 3) {
				this.getShopLuckDrawList();
			}
		},
		// 77777
		switch1Change: function(e) {
			console.log(e.target.value);
			if (e.target.value == true) {
				this.diameter.status = 2;
				// this.addTurntableActivity();
			} else {
				this.diameter.status = 1;
				// this.formSubmit()
				// this.addTurntableActivity();
			}
		},
		onConfirm(e) {
			console.log(e);
			this.diameter.start_time = e.checkArr[0] + '-' + e.checkArr[1] + '-' + e.checkArr[2];
			this.diameter.end_time = e.checkArr[3] + '-' + e.checkArr[4] + '-' + e.checkArr[5];
		},
		showtime() {
			this.$refs.picker.show();
		},
		hiddetime() {
			this.$refs.picker.hide();
		},

		addition() {
			this.additio += 1;
			console.log(this.additio);
			if (this.additio > 4) {
				this.additio = 4;
				uni.showToast({
					title: '没有更多了...',
					duration: 2000
				});
			}
		},
		//图片上传
		c_delImage(e) {
			console.log(e, '哈哈');
			let arr = [];
			// for (let k in e.allImages) {
			// 	arr[k] = e.allImages[k].id
			// }
			this.c_photos = arr;
		},

		c_onImg(e) {
			console.info(e);
			this.c_pics = e.allImages;
			const obj = e.allImages;
			for (let index in obj) {
				let id = obj[index].data;

				this.c_photos[index] = id;
			}

			console.info(this.c_photos);
		},
		c_onImgs(e) {
			console.info(e);
			this.c_picss = e.allImages;
			const obj = e.allImages;
			for (let index in obj) {
				let id = obj[index].data;
				this.c_photos[1] = id;
			}

			console.info(this.c_photos);
		},
		c_onImgss(e) {
			console.info(e);
			this.c_picsss = e.allImages;
			const obj = e.allImages;
			for (let index in obj) {
				let id = obj[index].data;
				this.c_photos[2] = id;
			}

			console.info(this.c_photos);
		},
		c_onImgsss(e) {
			console.info(e);
			this.c_picssss = e.allImages;
			const obj = e.allImages;
			for (let index in obj) {
				let id = obj[index].data;
				this.c_photos[3] = id;
			}

			console.info(this.c_photos);
		},
		c_onImgssss(e) {
			console.info(e);
			this.c_picsssss = e.allImages;
			const obj = e.allImages;
			for (let index in obj) {
				let id = obj[index].data;
				this.c_photos[4] = id;
			}

			console.info(this.c_photos);
		},
		c_onImgsssss(e) {
			console.info(e);
			this.c_picssssss = e.allImages;
			const obj = e.allImages;
			for (let index in obj) {
				let id = obj[index].data;
				this.c_photos[5] = id;
			}

			console.info(this.c_photos);
		},
		onMove_c(e) {
			console.log(e);
			this.c_pics = e;
			const obj = e;
			for (let index in obj) {
				let id = obj[index].data;
				this.c_photos[index] = id;
			}
		},
		successvideo(e) {
			console.log(e);
		},

		// 66666666666
		formSubmi: function(e) {
			// this.fromname = e.detail.value;
			// let formdata = this.fromname;
			// console.log(this.prize)
			console.log(e);

			// let formdat = []; //对象转成后的数组["邱艺","1","邱艺2","1"]
			// for (let i in formdata) {
			// 	formdat.push(formdata[i]);
			// }

			// // console.log(formdat,'111111111111111')

			// let form = []; //将数组转为对象类型的数组

			// for (let i = 0; i < 24; i++) {
			// 	if (i % 4 == 0) {
			// 		//每两个值一组
			// 		let js = {
			// 			title: '',
			// 			num: '',
			// 			proportion: '',
			// 			status: ''
			// 		};

			// 		js.title = formdat[i]; //第一个值
			// 		js.num = formdat[i + 1]; //第二个值
			// 		js.proportion = formdat[i + 2]; //第二个值
			// 		js.status = formdat[i + 3]; //第三个值
			// 		// js.name_5= formdat[i + 4]; //第三个值
			// 		console.log(js,'aaaaaa')
			// 		form.push(js);
			// 	}
			// 	// console.log(form)

			// };
			// console.log(form)

			// let form = this.prize;
			// console.log(this.prize);
			// console.log(this.shop_id);

			// console.log(form);

			console.log(this.shopdata, '卧槽');
			console.log(this.prize, '卧槽');
			// this.shopdata==this.prize;
			let target = JSON.parse(JSON.stringify(this.prize));
			console.log(target);
			target[0].pic = this.c_photos[0] ? this.c_photos[0] : '';
			target[1].pic = this.c_photos[1] ? this.c_photos[1] : '';
			target[2].pic = this.c_photos[2] ? this.c_photos[2] : '';
			target[3].pic = this.c_photos[3] ? this.c_photos[3] : '';
			target[4].pic = this.c_photos[4] ? this.c_photos[4] : '';
			target[5].pic = this.c_photos[5] ? this.c_photos[5] : '';

			target.map((item, index) => {
				item.shop_id = this.shop_id;
			});

			console.log(target, 'aaa卧槽');
			if (this.shopdata.length != 0) {
				for (let i = target.length - 1; i >= 0; i--) {
					console.log('啧啧');
					if (target[i].proportion == '' && target[i].title == '' && target[i].num == '') {
						console.log(i, '哈哈');
						target.splice(i, 1);
					}
				}
				console.log(target);
			}
			console.info(target);

			if (target.length == 0) {
				uni.showModal({
					title: '提示',
					content: '请填写内容',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				// uni.showToast({
				// 	title: '请填写内容',
				// 	duration: 2000
				// });
			} else {
				let nums = 0;
				target.forEach((item, index) => {
					if (item.title == '' || item.proportion == '' || item.num == '' || item.pic == '') {
						console.log('啊啊啊啊');
						uni.showModal({
							title: '提示',
							content: '有奖项未填写完整',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						// uni.showToast({
						// 	title: '奖项未填写完整',
						// 	duration: 2000
						// });
					} else {
						nums++;
						console.log(target);
						this.targets = target;
						if (nums == target.length) {
							this.addTurntableActivity();
						}
					}
				});
			}

			// console.log(this.shopdata, this.shopdata.length);
		},

		// 77777
		async addTurntableActivity() {
			if (this.diameter.start_time == '' || this.diameter.end_time == '') {
				uni.showModal({
					title: '提示',
					content: '请选择活动时间',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				// uni.showToast({
				// 	title: '请选择活动时间',
				// 	duration: 2000
				// });
			} else if (this.diameter.start_time == this.diameter.end_time) {
				console.log('hah');
				uni.showModal({
					title: '提示',
					content: '活动开始与结束相同',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

				// uni.showToast({
				// 	title: '开始与结束相同',
				// 	duration: 2000
				// });
			} else {
				let param = {
					prize: this.targets,
					name: this.diameter.name,
					condition_money: Math.floor(this.diameter.condition_money),
					receive_endtime: Math.floor(this.diameter.receive_endtime),
					start_time: this.diameter.start_time,
					end_time: this.diameter.end_time,
					content: this.diameter.content,
					status: this.diameter.status
				};
				console.log(this.shopdata);
				let res = await addTurntableActivity(param);

				uni.showToast({
					title: res.msg,
					duration: 2000
				});
				if (res.code == 0) {
					if (this.scrollTop > 1500) {
						this.totop();
					}
					console.log('哈哈');
					this.btnnum = 2;
					this.getTurntableActivityList();
				}
			}
		},
		// 8888
		// 奖品专区
		async getTurntableActivityList() {
			let param = {
				shop_id: this.shop_id,
				page: this.page_1
			};

			let res = await getTurntableActivityList(param);

			this.published = res.data.list;

			console.info(res.data.list);
		},

		//中奖专区
		async getShopLuckDrawList() {
			console.log(this.page);

			this.page++;

			if (!this.isoneload) {
				// this.isoneload = true;
				uni.showLoading({
					title: '加载中...'
				});
			} else {
				this.isoneload = false;
			}

			let param = {
				shop_id: this.shop_id,
				page: this.page,

				pagesize: 10
			};

			let res = await getShopLuckDrawList(param);

			uni.hideLoading(); //结束加载
			this.isshowloading = false;

			this.winning = [...this.winning, ...res.data.list]; //列表
			console.log(this.winning);
			uni.stopPullDownRefresh(); //关闭下拉刷新

			if (res.data.list.length == 0) {
				this.$api.msg('没有更多了~');
			}

			console.info(res.data.list);
		},
		// 抽奖卷
		async getBuyRecord() {
			let res = await getBuyRecord({
				shop_id: this.shop_id,
				page: this.page_2
			});
			console.info(res);
			this.sample = res.data.list;
			console.info(this.sample);
		},
		// 88888
		async setTurntableActivityStatus() {
			let res = await setTurntableActivityStatus({ shop_id: this.shop_id, id: this.id, status: this.status });
			console.info(res);
			this.statuslist = res.data;
		},

		ontabtap(e) {
			let index = e.target.dataset.current || e.currentTarget.dataset.current;
			this.switchTab(index);
		},

		switchTab(index) {
			if (this.tabIndex === index) {
				return;
			}

			this.tabIndex = index;
			this.scrollInto = this.tabBars[index].id;

			// 释放 tabId
			if (this.cacheTab.length > MAX_CACHE_PAGE) {
				let cacheIndex = this.cacheTab[0];
				// this.clearTabData(cacheIndex);
				this.cacheTab.splice(0, 1);
				//console.log("remove cache index:: " + cacheIndex);
			}
		}
	}
};
</script>

<style lang="scss">
@import './details.scss';

page {
	width: 100%;
	min-height: 100%;
	display: flex;
}
::-webkit-input-placeholder {
	/* WebKit browsers */
	font-size: 14upx;
}

// 选项卡
.end-title {
	display: flex;
}
.end-title view {
	flex-grow: 1;
	text-align: center;
	height: 50px;
	line-height: 50px;
	font-size: 36upx;
	font-weight: bold;
	background: #ffffff;
}
.end-cont {
	display: none;
	background: #c8c7cc;
}
.btna {
	color: #f64f15;
	// background: #00A0FF;
}
.dis {
	display: block;
}

.show {
	display: block;
}
.tabs {
	flex: 1;
	flex-direction: column;
	overflow: hidden;
	/* background-color: #ffffff; */

	// height: 100vh;
}

.scroll-h {
	width: 750rpx;
	height: 80rpx;
	flex-direction: row;
	white-space: nowrap;
}

.line-h {
	height: 1rpx;
	background-color: rgba(205, 205, 205, 0.3);
}

.uni-tab-item {
	/* #ifndef APP-PLUS */
	display: inline-block;
	/* #endif */
	flex-wrap: nowrap;
	padding-left: 34rpx;
	padding-right: 34rpx;
}

.uni-tab-item-title {
	color: #555;
	font-size: 30rpx;
	height: 80rpx;
	line-height: 80rpx;
	flex-wrap: nowrap;
	/* #ifndef APP-PLUS */
	white-space: nowrap;
	/* #endif */
}

.uni-tab-item-title-active {
	color: #007aff;
}

.swiper-box {
	flex: 1;
}

.swiper-item {
	flex: 1;
	flex-direction: row;
}

.scroll-v {
	flex: 1;
	/* #ifndef MP-ALIPAY */
	flex-direction: column;
	/* #endif */
	width: 750rpx;
}

.update-tips {
	position: absolute;
	left: 0;
	top: 41px;
	right: 0;
	padding-top: 5px;
	padding-bottom: 5px;
	background-color: #fddd9b;
	align-items: center;
	justify-content: center;
	text-align: center;
}

.update-tips-text {
	font-size: 14px;
	color: #ffffff;
}

.refresh {
	width: 750rpx;
	height: 64px;
	justify-content: center;
}

.refresh-view {
	flex-direction: row;
	flex-wrap: nowrap;
	align-items: center;
	justify-content: center;
}

.refresh-icon {
	width: 30px;
	height: 30px;
	transition-duration: 0.5s;
	transition-property: transform;
	transform: rotate(0deg);
	transform-origin: 15px 15px;
}

.refresh-icon-active {
	transform: rotate(180deg);
}

.loading-icon {
	width: 20px;
	height: 20px;
	margin-right: 5px;
	color: #999999;
}

.loading-text {
	margin-left: 2px;
	font-size: 16px;
	color: #999999;
}

.loading-more {
	align-items: center;
	justify-content: center;
	padding-top: 10px;
	padding-bottom: 10px;
	text-align: center;
}

.loading-more-text {
	font-size: 28rpx;
	color: #999;
}
.nome {
	display: none;
}
.beack {
	display: block;
}
</style>
