<template>
	<!-- 记工记账 -->
	<view class="page">
		<navbar title="记工" 
		bgColor="#F9FEFE"
		leftClick @leftClick="$utils.navigateBack" />
		
		<uv-cell
		title="选择日期"
		rightIconStyle="fontSize: 30rpx;"
		:value="form.workDate || '请选择选择日期'"
		@click="$refs.datetimePicker.open()"
		isLink
		></uv-cell>
		
		<view class="form-sheet-cell">
			<view class="label">
				上班时间
			</view>
			<!-- <input placeholder="请输入上班时间" 
			type="number"
			v-model="form.phone" /> -->
			
			<uv-number-box v-model="form.worktime"
			:step="0.5"
			:min="0.5"
			></uv-number-box>
		</view>
		
		<view class="form-sheet-cell">
			<view class="label">
				加班时间
			</view>
			<!-- <input placeholder="请输入上班时间" 
			type="number"
			v-model="form.phone" /> -->
			
			<uv-number-box v-model="form.overtime"
			:step="0.5"
			:min="0"
			></uv-number-box>
		</view>
		
		<view class="form-sheet-cell">
			<view class="label">
				备注
			</view>
			<uv-textarea
			v-model="form.remarks" 
			count 
			:maxlength="300" 
			autoHeight
			placeholder="请输入备注"></uv-textarea>
		</view>
		
		<view class="uni-color-btn"
		@click="submit">
			确认
		</view>
		
		<uv-datetime-picker 
		ref="datetimePicker" 
		mode="date" 
		v-model="dateValue"
		@confirm="datetimePickerConfim"/>
		
	</view>
</template>

<script>
	import mixinList from '@/mixins/list.js'
	export default {
		mixins : [mixinList],
		data() {
			return {
				form : {
					workDate : '',
					worktime : 0.5,
					remarks : '',
					overtime : 0,
				},
				id : 0,
				dateValue : new Date().getTime()
			}
		},
		onLoad({id}) {
			this.id = id
			this.form.notebookId = id;
		},
		onShow() {},
		methods: {
			datetimePickerConfim(e){
				this.form.workDate = this.$dayjs(e.value).format('YYYY-MM-DD')
			},
			submit(){
				this.form.overtime = String(this.form.overtime)
				if(this.$utils.verificationAll(this.form, {
					workDate : '请选择记工日期',//
					worktime : '请输入上班时长',//
					overtime : '请输入加班时长',
				})){
					return
				}
				
				this.$api('addWorkInfo', this.form, res => {
					if(res.code == 200){
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						setTimeout(uni.navigateBack,1000,-1)
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background-color: #fff;
		
		.form-sheet-cell{
			display: flex;
			background-color: #fff;
			padding: 20rpx 30rpx;
			align-items: center;
			.label{
				width: 160rpx;
			}
			.price{
				display: flex;
				text-align: center;
				input{
					width: 150rpx;
					border: 1px solid $uni-color;
					margin: 0 10rpx;
				}
			}
			input{
				flex: 1;
				background-color: rgba($uni-color, 0.1);
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
			}
			.right-icon{
				margin-left: auto;
			}
		}
		/deep/ .uv-textarea{
			background-color: rgba($uni-color, 0.1) !important;
			min-height: 400rpx;
		}
	}
</style>