<template>
	<view class="container">
		<!-- <block v-if="TabCur==2"> -->
			<view class="cu-form-group">
				<view class="title">派车编号</view>
				<input disabled  name="input" v-model="goods.tranCarNo"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">车牌号</view>
				<input maxlength='7' placeholder="请输入车牌号" name="input" v-model="goods.carNo"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">司机手机号</view>
				<input placeholder="请输入司机身份认证的手机号" name="input" v-model="goods.driverPhone"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">毛重(吨)</view>
				<input placeholder="请输入毛重" type="mobile" name="input"  @input="grossWeightchange" v-model="goods.grossWeight"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">皮重(吨)</view>
				<input placeholder="请输入皮重" type="mobile" name="input"  @input="tarechange" v-model="goods.tare"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">净重(吨)</view>
				<input placeholder="自动计算" type="mobile" name="input" v-model="goods.loadNetWeight"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">发货日期</view>
				<picker mode="date"  :start="startDate" :end="endDate" :value="goods.sendDateStart"  @change="DateChange">
					<view class="picker">
						{{goods.sendDateStart}}
					</view>
				</picker>
			</view>
			<view class="cu-bar bg-white margin-top">
				<view class="action">
					上传磅单照片
				</view>
			</view>
			<view class="cu-form-group">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-if="goods.loadPoundImg != ''" @tap="ViewImage" :data-url="goods.loadPoundImg">
					 <image :src="goods.loadPoundImg" mode="aspectFit"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="0">
							<text class='cuIcon-close'></text>
						</view>
					</view>
					<view class="solids" @tap="ChooseImagePerson" v-if="goods.loadPoundImg == ''">
						<text class='cuIcon-cameraadd'></text>
					</view>
				</view>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn commit margin-tb-sm lg" @click="getList">提交</button>
			</view>
		<!-- </block> -->
	</view>
</template>

<script>
	import uploadImage from '@/components/ossutil/uploadFile.js';
	import {
		mapState
	} from 'vuex';
	export default {
			name: "trust",
			data() {
				return {
					goods: {
						tranCarNo:'',
						carNo:'',
						grossWeight:'',
						tare:'',
						loadNetWeight:'',
						loadPoundImg:'',
						 contractNo:'',
						 goodsName:'',
						 sendDateStart:'请选择'
						
					},
					carNo:'',
					PageCur: "trust",
					TabCur: 0,
					priceTypeIndex:-1,
					priceType: ['库内价', '到库价', '到港价'],
					unitPrice:0,
					price:'',
					seller:'',
					sellerPhone:'',
					minSale:'',
					exsitCount:0,
					origin:'',
					stock:'',
					goodsName:'',
					verifyCode:'',
					sendText0:'获取验证码',
					sendText1:'获取验证码',
					sendText2:'获取验证码',
					sendText3:'获取验证码',
					sendDisabled0: false,
					sendDisabled1: false,
					sendDisabled2: false,
					sendDisabled3: false,
					buyer:'',
					buyerPhone:'',
					level:'',
					sender:'',
					senderPhone:'',
					receiver:'',
					receiverPhone:'',
					total:0,
					startPlace:'',
					endPlace:'',
					driver:'',
					driverPhone:'',
					carNo:'',
					personNoImg:'',
					personNoImg1:'',
					driverNoImg:'',
					driverNoImg1:'',
					carNoImg:'',
					carNoImg1:'',
					showTran:true
				};
			},
			computed: {
				...mapState(['hasLogin','userInfo']),
					startDate() {
					//限制开始时间;
					//也可以直接限定为当天日期 var date= new Date(); return date
						return new Date(new Date(new Date().toLocaleDateString()).getTime()-(1*60*60*1000))
					},
					endDate() {
						return new Date()
					}
				},	
			onShow() {
			},
			onLoad(option) {
				this.goods.goodsName=option.goodsName
				this.goods.contractNo = option.contractNo
				this.goods.tranCarNo=option.tranCarNo
				
			},
			methods: {
				 DateChange(e) {
				 	this.goods.sendDateStart = e.detail.value
				 },
				commit1(item){
					uni.navigateTo({				
						url: `/pageB/contract/look?id=${item.id}&netWeight=${item.netWeight}&carNo=${item.carNo}&sendDateStart=${item.sendDateStart}`
					})
				},
				grossWeightchange(e) {
				      if (this.goods.grossWeight && this.goods.tare) {
				        this.goods.loadNetWeight = Number(
				          this.goods.grossWeight - this.goods.tare
				        )
				      }
				    },
				tarechange(e) {
				      if (this.goods.grossWeight && this.goods.tare) {
				        this.goods.loadNetWeight = Number(
				          this.goods.grossWeight - this.goods.tare
				        )
				      }
				    },
				getList(){
					// tranCarNo:'',
					// carNo:'',
					// grossWeight:'',
					// tare:'',
					// loadNetWeight:'',
					// loadPoundImg:'',
					//  contractNo:'',
					//  goodsName:'',
					if(this.goods.carNo.length==0){
						this.$api.msg('车牌号不能为空')
						return
					}
					if(this.goods.carNo.length!=7){
						this.$api.msg('车牌号输入错误')
						return
					}
					if(this.goods.driverPhone.length==0){
						this.$api.msg('手机号不能为空')
						return
					}
					if(this.goods.driverPhone.length!=11){
						this.$api.msg('司机手机号输入错误')
						return
					}
					if(this.goods.grossWeight>100){
						this.$api.msg('毛重输入错误')
						return
					}
					if(this.goods.tare>50){
						this.$api.msg('皮重输入错误')
						return
					}
				this.$api.doRequest('post','/tranCarInfo/api/addTranTask',this.goods).then(res => {
				    if(res.data.code==200){
						uni.showToast({
						 title: '添加发车信息成功',
						 icon:'none',
						 duration: 2000
						})
						uni.navigateBack();
					}else if(res.data.code==11015){
						uni.showToast({
						 title: '该司机未认证身份，请司机认证后再操作',
						 icon:'none',
						 duration: 2000
						})
					}
				    })
				    .catch(res => {
				     uni.showToast({
				      title: res.errmsg,
				      icon:'none',
				      duration: 2000
				     })
				    });
				   },
				ChooseImagePerson() {
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album','camera'], //从相册选择
						success: (res) => {
							//上传图片
							//图片路径可自行修改
							
							uploadImage(res.tempFilePaths[0], 'loadPoundImg/',
								result => {
	
								 	this.goods.loadPoundImg = result
								 uni.hideLoading();
								}
							)
						}
					});
				},
				ChooseImageDriver() {
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album','camera'], //从相册选择
						success: (res) => {
							//上传图片
							//图片路径可自行修改
							uploadImage(res.tempFilePaths[0], 'driverNoImg/',
								result => {
									if (this.driverNoImg.length != 0) {
										this.driverNoImg1 = result
									} else {
										this.driverNoImg = result
									}
									uni.hideLoading();
								}
							)
						}
					});
				},
				ChooseImageCar() {
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album','camera'], //从相册选择
						success: (res) => {
							//上传图片
							//图片路径可自行修改
							uploadImage(res.tempFilePaths[0], 'carNoImg/',
								result => {
									if (this.carNoImg.length != 0) {
										this.carNoImg1 = result
									} else {
										this.carNoImg = result
									}
									uni.hideLoading();
								}
							)
						}
					});
				},
				ViewImage(e) {
					var img = [];
					img = e.currentTarget.dataset.url.split(' ')
					uni.previewImage({
						current:0,
						urls: img
					});
				},
				DelImg(e) {
					uni.showModal({
						title: '提示',
						content: '确定要删除该照片吗？',
						cancelText: '取消',
						confirmText: '确定',
						success: res => {
							if (res.confirm) {
								if(e.currentTarget.dataset.index == 0){
									this.personNoImg = "";
								}
								else if(e.currentTarget.dataset.index == 1){
									this.personNoImg1 = "";
								}
								else if(e.currentTarget.dataset.index == 2){
									this.driverNoImg = "";
								}
								else if(e.currentTarget.dataset.index == 3){
									this.driverNoImg1 = "";
								}
								else if(e.currentTarget.dataset.index == 4){
									this.carNoImg = "";
								}
								else if(e.currentTarget.dataset.index == 5){
									this.carNoImg1 = "";
								}
								
							}
						}
					})
				},
			},
		}
</script>

<style scoped>
	.container{
		padding-bottom: 160rpx;
	}
	.cu-form-group input {
		text-align: right;
	}
	.text-white text{
		background: linear-gradient(45deg, #3DC146, #B2D612);
		padding:5px 10px;
		border-radius: 38rpx;
	}
	.cu-form-group textarea {
		text-align: right;
	}
	.commit{
		background: linear-gradient(45deg, #DF331C, #DA611A);
		color:#fff;
	}
</style>
