<template>
	<view class="box">
		<view class="conmsg">
			<view class="conmsg-lab">
				<view class="conmsg-lab-1">
					客户信息
				</view>
				<view class="conmsg-lab-2">
					<!-- 李先生/12385945986 -->
					{{str}}
				</view>
			</view>
			<view class="conmsg-lab" style="border: none;">
				<view class="conmsg-lab-1">
					提醒时间
				</view>
				<view class="conmsg-lab-3">
					<!-- 请选择提醒时间（必填) -->
					<KXDateTime :date='date' :end='enddate' :start='startdate' @rundata='kxdatetime' default='start' placeholder='请选择时间'></KXDateTime>
				</view>
				<view class="conmsg-lab-4">
					<image class="screen-sel-img" src="../../../static/images/right.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="conent">
			<u-input v-model="value" type="textarea"  height="148" :auto-height="true" />
		</view>
		<view class="btn" @click="add">
			添加提醒
		</view>
	</view>
</template>

<script>
	var util = require("../../../utils/util.js");
	import KXDateTime from "@/components/kx-datetime/kx-datetime.vue"
	export default{
		data(){
			return{
				str:'',
				date: '',
				// startdate:new Date().toLocaleDateString()+'00:00',
				startdate:'2021-01-01 00:00',
				enddate: '2025-12-30 23:59',
				code:'',
				customerId:'',
				value:'',
			}
		},
		components:{
			KXDateTime
		},
		methods:{
			kxdatetime(e) {
				console.log(e)
				this.date = e
			},
			add(){
				// console.log(new Date().toLocaleDateString())
				// return
				if(!this.date){
					uni.showToast({
						title:'请选择时间',
						icon:'none'
					})
					return
				}
				if(!this.value){
					uni.showToast({
						title:'请填写备注',
						icon:'none'
					})
					return
				}
				const that = this; // 检测是否已经授权，有授权直接弹窗，没授权弹出授权
				
				uni.getSetting({
					withSubscriptions: true,
					success(res) {
						console.log(res);
						if (res && res.subscriptionsSetting && res.subscriptionsSetting.itemSettings && res
							.subscriptionsSetting
							.itemSettings['cBnJvhkMPHp0ReUiSdpM_Pd2usGeEEW6wx-5s6X4hEI'] == 'accept') {
								that.addFlag()
						} else {
							uni.requestSubscribeMessage({
								tmplIds: ['cBnJvhkMPHp0ReUiSdpM_Pd2usGeEEW6wx-5s6X4hEI'],
								success(res) {
									that.addFlag()
								},
								fail(res) {
									console.log(res);
									util.showNone("请授权");
								}
				
							});
						}
					},
				
					fail(res) {
						console.log(res);
					}
				
				});
			},
			addFlag(){
				var that = this;
				var params = {
					customerId: that.customerId,
					orderRemindTime: that.date + ':00',
					code: that.code,
					remarks:this.value,
					OrderRemindDesc:this.value
				};
				this.$u.post("/customer/settingTime", params).then(data => {
					uni.showToast({
						title: '操作成功'
					});
					uni.navigateBack()
				// 	var data = that.orderRemindDate + ':00';
				// 	var setData = new Date(data).getTime();
				// 	var newData = new Date().getTime();
				// 	console.log(setData, newData);
				
				// 	if (setData < newData) {
				// 		this.setData({
				// 			overdue: true
				// 		});
				// 	} else {
				// 		this.setData({
				// 			overdue: false
				// 		});
				// 	}
				
				// 	this.setData({
				// 		show: false,
				// 		value: [this.year, Number(this.month) - 1, Number(this.day) - 1, this.hour, this
				// 			.minute
				// 		],
				// 		orderRemindDate1: that.orderRemindDate + ':00'
				// 	});
				});
			},
		},
		onLoad(e) {
			// console.log(e)
			this.str=e.str
			this.customerId=e.customerId||''
			const that = this;
			let num=new Date().toLocaleDateString().split('/').join('-')+' '+new Date().getHours()+':'+ new Date().getMinutes()
			this.startdate=num
			console.log(num)
			uni.login({
				success(res) {
					if (res.code) {
						that.code=res.code
					} else {
						console.log('登录失败！' + res.errMsg);
					}
				}
			});
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100%;
		height: 100%;
		background: #F8F8F8;
	}
	.conmsg{
		border-top: 1px solid #E0E0E0;
		padding: 0 30rpx;
		background: #fff;
		height: 208rpx;
		.conmsg-lab{
			display: flex;
			border-bottom: 1px solid #E0E0E0;
			height: 102rpx;
			font-size: 30rpx;
			font-weight: 400;
			line-height: 102rpx;
			color: #333333;
			.conmsg-lab-1{
				margin-right: 60rpx;
			}
			.conmsg-lab-3{
				color: #B2B2B2;
			}
			.conmsg-lab-4{
				width: 14rpx;
				height: 30rpx;
				margin-top: 6rpx;
				margin-left: auto;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
	.conent{
		margin-top: 20rpx;
		min-height: 208rpx;
		background: #FFFFFF;
		box-sizing: border-box;
		padding: 30rpx;
		margin-bottom: 20rpx;
	}
	.btn{
		position: fixed;
		width: 690rpx;
		height: 88rpx;
		background: #2671E2;
		border-radius: 8px;
		line-height: 88rpx;
		text-align: center;
		color: #FFFFFF;
		bottom: 108rpx;
		left: 30rpx;
	}
	
</style>
