<template>
	<div class="form-submit">
		<div class="i-layout-page-header">
			<PageHeader class="product_tabs" hidden-breadcrumb>
				<div slot="title">
					<router-link :to="{ path: `${roterPre}/store/checkRule/index` }">
						<div class="font-sm after-line">
							<span class="iconfont iconfanhui"></span>
							<span class="pl10">返回</span>
						</div>
					</router-link>
					<span v-text="$route.params.id ? '编辑打卡规则' : '添加打卡规则'" class="mr20 ml16"></span>
				</div>
			</PageHeader>
		</div>
		<Card :bordered="false" dis-hover class="ivu-mt">
			<Form :model="formData" :label-width="150">
				<FormItem label="规则名称" required>
					<Input v-model="formData.groupname" v-width="320"></Input>
				</FormItem>
				<FormItem label="打卡经度">
					<Input v-model="formData.loc_infos[0].lng" v-width="320"></Input>
					<span> （实际经度的1000000倍）</span>
				</FormItem>
				<FormItem label="打卡纬度">
					<Input v-model="formData.loc_infos[0].lat" v-width="320"></Input>
					<span> （实际纬度的1000000倍）</span>
				</FormItem>
				<FormItem label="打卡地名">
					<Input v-model="formData.loc_infos[0].loc_title" v-width="320"></Input>
					<span> （实际纬度的1000000倍）</span>
				</FormItem>
				<FormItem label="打卡详细地址">
					<Input v-model="formData.loc_infos[0].loc_detail" v-width="320"></Input>
					<span> （实际纬度的1000000倍）</span>
				</FormItem>
				<FormItem label="WiFi名称">
					<Input v-model="formData.wifimac_infos[0].wifiname" v-width="320"></Input>
					<span> </span>
				</FormItem>
				<FormItem label="无线路由器MAC地址">
					<Input v-model="formData.wifimac_infos[0].wifimac" v-width="320"></Input>
					<span> </span>
				</FormItem>
				<FormItem label="工作日" required>
					<Button  type="primary" style="margin-left: 20px;" v-for="item in workList" >{{item.table}}</Button>
				</FormItem>
				<template v-for="item in checkintime">
					<FormItem label="上班时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" :model-value="value1"/>
						<Button  type="primary" style="margin-left: 20px;" @click="addNewDk" >添加新上班时段</Button>
					</FormItem>
					<FormItem label="上班最早时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
					<FormItem label="上班最晚时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
					<FormItem label="上班提醒时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
					<FormItem label="下班时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
					<FormItem label="下班最早时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
					<FormItem label="下班最晚时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
					<FormItem label="下班提醒时间" required>
						<TimePicker :steps="[1, 5]" placeholder=""  v-width="320" format="HH:mm" />
					</FormItem>
				</template>
				
			</Form>
			<div style="width: 500px; display: flex;justify-content: center;">
				<Button type="primary" class="submission" @click="save" :disabled="disabled"
					v-if="!formData.id">立即创建</Button>
				<Button type="primary" class="submission" @click="save" :disabled="disabled" v-else>立即修改</Button>
			</div>
		</Card>
	</div>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import storeList from "@/components/storeList";
	import {
		couponCategoryApi,
		couponSaveApi,
		couponDetailApi,
		VipEditApi,
		serveAddApi,
		serveReadApi,
		createServeProduct
	} from "@/api/marketing";
	import {
		addCheckRule
	} from '@/api/store';
	import {
		brandList
	} from "@/api/product";
	// import { formatDate } from '@/utils/validate';
	import Setting from "@/setting";
	export default {
		name: "storeCouponCreate",
		components: {
			storeList
		},
		data() {
			return {
				value1: '09:41:00',
				chooseWd: [],//选择的上班日期
				workList: [
					{
						table: '星期一',
						value: 1
					},
					{
						table: '星期二',
						value: 2
					},
					{
						table: '星期三',
						value: 3
					},
					{
						table: '星期四',
						value: 4
					},
					{
						table: '星期五',
						value: 5
					},
					{
						table: '星期六',
						value: 6
					},
					{
						table: '星期日',
						value: 0
					}
				],
				checkintime: [
					{
						"time_id": 1,
						"work_sec": 36000,//上班时间（距0点秒数，整分钟）
						"off_work_sec": 43200,//下班时间
						"remind_work_sec": 35400,//上班提醒时间
						"remind_off_work_sec": 43200,//下班提醒时间
						"earliest_work_sec": 35040,//上班最早时间
						"latest_work_sec": 37020,//上班最晚时间
						"earliest_off_work_sec": 43140,//下班最早时间
						"latest_off_work_sec": 43800//	下班最晚时间
					}
				],
				value: '',
				id: '',
				work_sec: '',
				roterPre: Setting.roterPre,
				disabled: false,
				storesList: [],
				formData: {
					groupname: '',
					grouptype: 1, //规则类型: 1-固定时间上下班；2-按班次上下班；3-自由上下班
					type: 2, //	打卡方式 0-手机，2-考勤机，3-手机/考勤机
					loc_infos: [{
						lat: 30547030,
						lng: 104062890,
						loc_title: "腾讯成都大厦",
						loc_detail: "四川省成都市武侯区高新南区天府三街",
						distance: 300
					}],
					wifimac_infos: [{
						"wifiname": "Tencent-WiFi-1",
						"wifimac": "c0:7b:bc:37:f8:d3"
					}],
					range: {
						userid: [
							"qywx4633487382413312"
						]
					}, //打卡人员
					checkindate: [{
						workdays: [
							1,
							2,
							3,
							4,
							5
						],
						"checkintime": [{
							"time_id": 1,
							"work_sec": 36000,//上班时间（距0点秒数，整分钟）
							"off_work_sec": 43200,//下班时间
							"remind_work_sec": 35400,//上班提醒时间
							"remind_off_work_sec": 43200,//下班提醒时间
							"earliest_work_sec": 35040,//上班最早时间
							"latest_work_sec": 37020,//上班最晚时间
							"earliest_off_work_sec": 43140,//下班最早时间
							"latest_off_work_sec": 43800//	下班最晚时间
						}],
						"flex_on_duty_time": 0,
						"flex_off_duty_time": 0
					}]

				},
				id: 0,
				product_name: '',
				product_id: 0,
				store_name: '',
				repertory: '',
				card_price: '',
				explain: '',
				unit_name: '',
				image: '',
				images: '',
				modals: false,
			}
		},
		computed: {
			...mapState("admin/layout", ["isMobile", "menuCollapse"]),
		},
		created() {
			if (this.$route.query.id) {
				let query = this.$route.query
				this.formData.id = query.id;
				this.formData.store_name = query.store_name;
				this.formData.repertory = query.repertory;
				this.formData.slider_image = query.slider_image;
				this.formData.performance_value = query.performance_value;
				this.formData.craft_price = query.craft_price;
				this.formData.sales_commissions = query.sales_commissions
			}
			this.showTime(36000)
		},
		methods: {
			showTime(time) {
				
					let hh = '',mm = '';
					hh = Math.floor(time / 3600);
					hh = hh > 9 ? hh: ('0' + hh)
					mm = Math.floor((time % 3600) / 60);
					mm = mm > 9 ? mm: ('0' + mm)
					let str =  hh + ':' + mm + ':' + '00'
					console.log('str:',str)
					return str
				
				
			},
			addNewDk() {
				
			},
			// 
			onchangeTime(e) {
				console.log(e,'xuanz');
			},
			// 商品id
			getProductId(row) {
				console.log(row, '这个');
				this.modal_loading = false;
				this.modals = false;
				setTimeout(() => {
					this.formData.product_id = row.id
					this.formData.store_name = row.store_name
					this.formData.product_id = row.id
					this.formData.card_price = row.price
					this.formData.unit_name = row.unit_name
					this.formData.slider_image = row.image
					this.formData.price = row.price
					// this.formData.slider_image = row.slider_image
					// this.formData.is_show = 1
					this.formData.repertory = row.stock
					// this.formData.image = row.image
				}, 500);
			},
			// 选择商品
			changeGoods() {
				this.modals = true;
			},
			downTab() {
				// if (!this.formData.store_name) {
				// 	return this.$Message.error("请输入服务卡名称");
				// }
				// if (!this.formData.card_price) {
				// 	return this.$Message.error("请输入售价");
				// }
				// if (!this.formData.repertory) {
				// 	return this.$Message.error("请输入库存");
				// }
			},
			// 创建
			save() {
				this.downTab();
				console.log('这');
				addCheckRule({
						'group': this.formData
					})
					.then((res) => {
						this.disabled = true;
						this.$Message.success(res.msg);
						setTimeout(() => {
							this.$router.push({
								path: this.roterPre + "/store/checkRule/index",
							});
						}, 1000);
					})
					.catch((err) => {
						this.$Message.error(err.msg);
					});
			},
			// 使用有效期--时间段
			dateChange(time) {
				this.formData.start_use_time = time[0];
				this.formData.end_use_time = time[1];
			},
			// 限时
			timeChange(time) {
				this.formData.start_time = time[0];
				this.formData.end_time = time[1];
			},
			//对象数组去重；
			unique(arr) {
				const res = new Map();
				return arr.filter(
					(arr) => !res.has(arr.product_id) && res.set(arr.product_id, 1)
				);
			},
			cancel() {
				this.modals = false;
			},
			// 删除商品
			remove(productId) {
				for (let index = 0; index < this.productList.length; index++) {
					if (this.productList[index].product_id == productId) {
						this.productList.splice(index, 1);
					}
				}
				this.formData.product_id = "";
				this.productList.forEach((value) => {
					if (this.formData.product_id) {
						this.formData.product_id += `,${value.product_id}`;
					} else {
						this.formData.product_id += `${value.product_id}`;
					}
				});
			},
			// 获取详情
			getDetail() {
				serveReadApi(this.id).then(res => {
					console.log(res);
					let row = res.data.info.storeInfo
					this.formData = {
						id: row.id,
						product_id: row.id,
						store_name: row.store_name,
						card_price: row.card_price,
						explain: row.explain,
						unit_name: row.unit_name,
						image: row.image,
						images: row.slider_image,
						repertory: row.repertory,
						is_show: 1
					}
				})
			}
		},
	};
</script>

<style scoped lang="stylus">
	.tips {
		display: inline-bolck;
		font-size: 12px;
		font-weight: 400;
		color: #999999;
		margin-top: 10px;
	}

	.imgPic {
		.info {
			width: 60%;
			margin-left: 10px;
		}

		.pictrue {
			height: 36px;
			margin: 7px 3px 0 3px;

			img {
				height: 100%;
				display: block;
			}
		}
	}

	.productType {
		width: 120px;
		height: 60px;
		background: #FFFFFF;
		border-radius: 3px;
		border: 1px solid #E7E7E7;
		float: left;
		text-align: center;
		padding-top: 8px;
		position: relative;
		cursor: pointer;
		line-height: 23px;
		margin-right: 12px;

		&.on {
			border-color: #1890FF;
		}

		.name {
			font-size: 14px;
			font-weight: 600;
			color: rgba(0, 0, 0, 0.85);

			&.on {
				color: #1890FF;
			}
		}

		.title {
			font-size: 12px;
			font-weight: 400;
			color: #999999;
		}

		.jiao {
			position: absolute;
			bottom: 0;
			right: 0;
			width: 0;
			height: 0;
			border-bottom: 26px solid #1890FF;
			border-left: 26px solid transparent;
		}

		.iconfont {
			position: absolute;
			bottom: -3px;
			right: 1px;
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	.info {
		color: #888;
		font-size: 12px;
	}

	.ivu-input-wrapper {
		width: 320px;
	}

	.ivu-input-number {
		width: 160px;
	}

	.ivu-date-picker {
		width: 320px;
	}

	.ivu-icon-ios-camera-outline {
		width: 58px;
		height: 58px;
		border: 1px dotted rgba(0, 0, 0, 0.1);
		border-radius: 4px;
		background-color: rgba(0, 0, 0, 0.02);
		line-height: 58px;
		cursor: pointer;
		vertical-align: middle;
	}

	.upload-list {
		width: 58px;
		height: 58px;
		border: 1px dotted rgba(0, 0, 0, 0.1);
		border-radius: 4px;
		margin-right: 15px;
		display: inline-block;
		position: relative;
		cursor: pointer;
		vertical-align: middle;
	}

	.upload-list img {
		display: block;
		width: 100%;
		height: 100%;
	}

	.ivu-icon-ios-close-circle {
		position: absolute;
		top: 0;
		right: 0;
		transform: translate(50%, -50%);
	}

	.form-submit {
		/deep/.ivu-card {
			border-radius: 0;
		}

		margin-bottom: 79px;

		.fixed-card {
			position: fixed;
			right: 0;
			bottom: 0;
			left: 200px;
			z-index: 99;
			box-shadow: 0 -1px 2px rgb(240, 240, 240);

			/deep/ .ivu-card-body {
				padding: 15px 16px 14px;
			}

			.ivu-form-item {
				margin-bottom: 0;
			}

			/deep/ .ivu-form-item-content {
				margin-right: 124px;
				text-align: center;
			}

			.ivu-btn {
				height: 36px;
				padding: 0 20px;
			}
		}
	}

	/deep/.vxe-tree-cell {
		padding-left: 0 !important;
	}
</style>