<template>
	<view class="page">
		<pyh-nv ref="nv" :config="nvConfig"></pyh-nv>
		<view class="listBox" :style="{'padding-top':(pageTop+'px')}">
		<view class="content">
			<view class="message-list">
				<view class="titleall-box">
					<view class="titleall-left"><view class="titleall-left-line"></view>遗体接运信息<text style="color: red;">（必填）</text></view>
				</view>
				<view class="info-box">
					<view class="info-box-list">
						<view class="info-box-width width100">
							<!-- <view @click="areashow = true">{{area}}</view> -->
							<view>
								<input v-model="area" class="input-text" type="text" placeholder="请输入详细地址" placeholder-class="inputtext" />
							</view>
							<view class="info-box-small">接运地点</view>
						</view>
					</view>
					<u-picker :show="areashow"  :columns="areacolumns" @confirm="areaconfirm" @close="areaclose"></u-picker>
					<view class="info-box-list">
						<view class="info-box-width width100">
							<view @click="timeshow = true">
								<label>{{accessTime}}</label>
							</view>
							<view class="info-box-small">接运时间</view>
						</view>
					</view>
					<view class="info-box-list">
						<view class="info-box-width width100">
							<view>
								<input v-model="remarks" class="input-text" type="text" placeholder="请输入" placeholder-class="inputtext" />
							</view>
							<view class="info-box-small">备注</view>
						</view>
					</view>
				</view>
			</view>
			<u-datetime-picker
			    :show="timeshow"
			    mode="datetime"
				v-model="accessTimeby"
				@confirm="xztime"
				@cancel="qxtime"
			></u-datetime-picker>
			<view class="page-footer">
			  <view class="footer-buy">
			    <view class="cart-add">
					<view><image src="../../static/btn2.png"></image></view>
					<view class="cart-add-text"><image src="../../static/phone.png"></image><text>联系电话</text></view>
			    </view>
			    <view class="buy-at" @click="funeralresult">
					<image src="../../static/btn1.png"></image>
			      <text>下一步</text>
			    </view>
			  </view>
			</view>
		</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				OrderType: 0,
				nvConfig:{
					title:"遗体接运",
					bgColor:"#ffffff",
					color:"#000000",
					fixedAssist:{
						hide:true,
					},
				},
				accessLocation:"",
				area:"",
				xxarea:"",
				areashow:false,
				areacolumns:[
					['地区1', '地区2']
				],
				
				accessTime:"请选择",
				accessTimeby:2,
				timeshow:false,
				remarks:"",
				info:{}
			};
		},
		onPageScroll(e) {this.$refs.nv.pageScroll(e)},
		computed:{
			pageTop(){return parseInt(88*uni.getSystemInfoSync().windowWidth/750) + uni.getSystemInfoSync().statusBarHeight}
		},
		onLoad(params) {
			const timestamp = Date.now();
			this.accessTime = this.timestampToTime(timestamp);
			
			console.log("params",params);
			this.info = JSON.parse(params.info)
			console.log(this.info);
			console.log("dh",uni.getStorageSync('dh'));
			
		},
		methods:{
			xztime(value){
				this.timeshow = false
				var that = this;
				let selectTime =this.timestampToTime(value.value);
				that.accessTime = selectTime;
			},
			qxtime(){
				this.timeshow = false
			},
			timestampToTime(timestamp) {
			    timestamp = timestamp ? timestamp : null;
			    let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
			    let Y = date.getFullYear() + '-';
			    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
			    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
			    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
			    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
			    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
			    return Y + M + D + h + m + s;
			},
			funeralresult(){
				this.info.accessLocation = this.area
				this.info.accessTime = this.accessTime
				// this.info.obituaryType = "网上报丧"
				if(uni.getStorageSync('dh') == 2){
					this.info.obituaryType = "电话报丧"
				}else{
					this.info.obituaryType = "网上报丧"
				}
				this.info.remarks = this.remarks
				this.info.userId = uni.getStorageSync("USERS_KEY").userId
				console.log(this.info);
				// return
				if(this.area != '请输入详细地址' && this.accessTime != "请选择" && this.remarks != ''){
					this.API.tjwsyy(this.info).then(res=>{
						console.log("网上报丧",res);
					})
					uni.navigateTo({
						url: '/pages/funeralresult/funeralresult',
					})
				}else{
					console.log(1123);
					this.$refs.uToast.show({
						type: 'error',
						title: '成功主题(带图标)',
						message: "提交失败请填写完整信息",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
					})
					
				}
			},
			// 地区选择确认回调
			areaconfirm(e){
				this.areashow = false
				this.area = e.value[0];
			},
			areaclose(){
				this.areashow = false
			},
			
			timeclose(){
				this.timeshow = false
			},
		}
	}
</script>

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