<template>
	<view class="content">
		<view class="row row-bottom">
			<view class="left">日期</view>
			<picker mode="date" @change="bindDateChange">
				<view>{{param.date}}</view>
			</picker>
		</view>
		<view class="row row-bottom">
			<view class="left">类型</view>
			<radio-group @change="selectType">
				<label v-for="item in inOutType" :key="item">
					<radio :value="item" :checked="item==param.type" />{{item}}
				</label>
			</radio-group>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">班组</view>
			<picker @change="outtypeChange" :value="industryIndex" :range="list" range-key="name">
				{{industryIndex>0 ? list[industryIndex].name : industryIndex==0 ? list[0].name :'请选择班组'}}
			</picker>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">班次</view>
			<radio-group @change="chang">
				<label v-for="item in radioGroup" :key="item">
					<radio :value="item" :checked="item==param.banci" />{{item}}
				</label>
			</radio-group>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">巴西(吨)</view>
			<input v-model='param.filed1' class="right-bottom" type="number" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">中美洲(吨)</view>
			<input v-model='param.filed2' class="right-bottom" type="number" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">回溶(吨)</view>
			<input v-model='param.filed3' class="right-bottom" type="number" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">加工糖100%(吨)</view>
			<input v-model='param.filed4' class="right-bottom" type="number" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">非食用糖92%(吨)</view>
			<input v-model='param.filed5' class="right-bottom" type="number" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">国储(吨)</view>
			<input v-model='param.filed6' class="right-bottom" type="number" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='出库'" class="row row-bottom">
			<view class="left">合计(吨)</view>
			<input :disabled="true" v-model='total' class="right-bottom" placeholder="请输入"></input>
		</view>
		<view v-if="param.type=='入库'" class="row row-bottom">
			<view class="left">入库量(吨)</view>
			<input v-model='param.inNum' class="right-bottom" placeholder="请输入"></input>
		</view>
		<view  class="row row-bottom">
			<view class="left">密码（必填)</view>
			<input v-model='param.password' class="right-bottom"  type="password"  placeholder="请输入"></input>
		</view>
		<view class="bottom-btn">
			<button type="primary" class="submit" hover-class="none" @click="submit()">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				param: {
					filed1: '0',
					filed2: '0',
					filed3: '0',
					filed4: '0',
					filed5: '0',
					filed6: '0',
					total: '0',
					banci: '白班',
					banzu: '甲班',
					type: '出库',
					inNum: '0',
					password:'',
					date: this.getDate()
				},
				radioGroup: ['白班', '夜班'],
				inOutType: ['出库', '入库'],
				list: [{
						name: '甲班'
					},
					{
						name: '乙班'
					},
					{
						name: '丙班'
					}
				],
				industryIndex: 0,

			}
		},
		computed: {
			total() {
				return parseFloat(this.param.filed1) +
					parseFloat(this.param.filed2) +
					parseFloat(this.param.filed3) +
					parseFloat(this.param.filed4) +
					parseFloat(this.param.filed5) +
					parseFloat(this.param.filed6);
			}
		},
		onLoad() {

		},
		methods: {
			submit() {
				console.log(this.param,12)
				if (!this.param.password) {
				    uni.showToast({
				    	title: '密码不能为空',
						icon: 'none'
				    })
				    return false;

				  } 
				this.param.total = this.total;
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定提交？',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交',
								mask: true
							});
							uni.request({
								url: 'http://10.23.250.94:18087/v1/testTable',
								method: 'POST',
								data: that.param,
								success: (res) => {
									if(res.data.code!=200){
										uni.showToast({
											title: res.data.msg,
											mask: true,
											icon: 'error',
											duration: 2000
										})
									}
									else{
										uni.showToast({
											title: '提交成功',
											mask: true,
											icon: 'success',
											duration: 2000
										})
									}
								}
							})
							uni.hideLoading()
								.catch(res => {
									uni.hideLoading()
								})
						} else {
							// 执行取消后的操作
						}
					},
				})
			},

			chang(e) {
				this.banci = e.detail.value; //选中按钮的value值
				this.param.banci = e.detail.value;
			},
			selectType(e) {

				this.type = e.detail.value; //选中按钮的value值
				this.param.type = e.detail.value;
			},
			outtypeChange(e) {
				this.industryIndex = e.detail.value
				this.banzu = this.list[e.detail.value].name
				this.param.banzu =this.list[e.detail.value].name
			},
			getDate() {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindDateChange: function(e) {
				this.date = e.detail.value;
			}
		}
	}
</script>

<style scoped lang="scss">
	.content,
	.content1,
	.content2 {
		border-radius: 20rpx;
		background: white;
		padding: 20rpx;

		.title {
			font-size: 28rpx;
			font-weight: 600;
			color: #333333;
		}

		.row {
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #EEEEEE;
			padding: 21rpx 0;

			.right,
			input {
				font-size: 28rpx;
				color: #333333;
			}
		}

		.row-bottom {

			// border: 0;
			.right-bottom {
				width: 280rpx;
				text-align: right;
			}
		}
	}

	.right-bottom {
		width: 280rpx;
		text-align: right;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.bottom-btn {
		padding: 30rpx;
		background: #FFFFFF;
		width: 92%;
		position: fixed;
		bottom: 0rpx;
		display: flex;
	}
</style>