<template>
	<!-- 记工记账 -->
	<view class="page">
		<navbar title="记账" 
		bgColor="#F9FEFE"
		leftClick @leftClick="$utils.navigateBack" />
		
		<uv-cell
		title="选择日期"
		rightIconStyle="fontSize: 30rpx;"
		:value="form.billDate || '请选择选择日期'"
		@click="$refs.datetimePicker.open()"
		isLink
		></uv-cell>
		
		
		<view class="form-sheet-cell">
			<view class="label">
				类型
			</view>
			<uv-radio-group v-model="form.type">
				<view class="price">
					<uv-radio
						:customStyle="{margin: '8px'}" 
						v-for="(item, index) in typeList" 
						:key="index" 
						iconSize="30rpx"
						size="40rpx"
						labelSize="26rpx"
						:label="item.name" 
						:name="item.index">
					</uv-radio>
				</view>
			</uv-radio-group>
		</view>
		
		<view class="form-sheet-cell">
			<view class="label">
				金额
			</view>
			<input placeholder="请输入金额" 
			type="number"
			v-model="form.amount" />
		</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 : {
					billDate : '',
					amount : '',
					type : 0,
					remarks:''
				},
				id : 0,
				dateValue : new Date().getTime(),
				typeList : [
					{
						name : '收入',
						index:0
					},
					{
						name : '支出',
						index:1
					},
				],
			}
		},
		onLoad({id}) {
			this.id = id
			this.form.notebookId = id;
		},
		onShow() {},
		methods: {
			datetimePickerConfim(e){
				this.form.billDate = this.$dayjs(e.value).format('YYYY-MM-DD')
			},
			submit(){
				if(this.$utils.verificationAll(this.form, {
					billDate : '请输入记工日期',//
					amount:'请输入金额',
				})){
					return
				}
				
				this.$api('addBillInfo', 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>