<template>
	<view class="content">
		<view class="content2">
			<view class="row1">
				<view class="left">
					<view class="top" @click="selectAddress(0)">
						<view class="send">装</view>
						<view class="title">
							{{dataObj.sendArea?(dataObj.sendPrivate + dataObj.sendCity+dataObj.sendArea):'选择装货地区'}}
						</view>
					</view>
					<view class="bottom">
						<input type="text" value="" placeholder="输入详细地址" v-model="dataObj.sendDetailedAddress" />
					</view>
				</view>
				<view class="right" @click="selectAddress(0)" v-if="!dataObj.sendArea">
					<view v-if='dataObj.sendArea' class="right"></view>
					<view class="right" v-else>
						<image src="../../static/right.png" style="width: 22rpx;height: 22rpx;margin-top:14rpx;">
						</image>
					</view>
				</view>
			</view>
			<view class="row2">
				<view class="left">
					<view class="top" @click="selectAddress(1)">
						<view class="collect">卸</view>
						<view class="title">
							{{dataObj.unloadArea?(dataObj.unloadPrivate + dataObj.unloadCity+dataObj.unloadArea):'选择卸货地区'}}
						</view>
					</view>
					<view class="bottom">
						<input type="text" value="" placeholder="输入详细地址" v-model="dataObj.unloadDetailedAddress" />
					</view>
				</view>
				<view class="right" @click="selectAddress(1)" v-if="!dataObj.unloadArea">
					<view v-if='dataObj.unloadArea' class="right">{{(dataObj.unloadCity+dataObj.unloadArea)}}</view>
					<view class="right" v-else>
						<image src="../../static/right.png" style="width: 22rpx;height: 22rpx;margin-top:14rpx;">
						</image>
					</view>
				</view>
			</view>
		</view>
		<view class="content3">
			<view class="row">
				<view class="left">预估总里程</view>
				{{dataObj.cargoDistance }}
				km
			</view>
		</view>
		<view class="content3">
			<view class="row" @click="isShowPopup1=true">
				<view class="left">货物信息</view>
				<view class="right flex">
					{{dataObj.goodsName?dataObj.goodsName+'、'+dataObj.packageType+'、'+dataObj.weight:"完善货物信息"}}
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view>
			<view class="row" @click="isShowPopup2=true">
				<view class="left">车型车长</view>
				<view class="right flex">{{dataObj.carModel?dataObj.carModel+'、'+dataObj.carLength:"选择车型车长"}}<u-icon
						name="arrow-right" size="20"></u-icon></view>
			</view>
		</view>
		<view class="content3">
			<view class="row">
				<view class="left">运价单位</view>
				<view class="btn flex">
					<view class="price-item" :class="index==priceIndex?'active':''" v-for="(item,index) in priceBtnList"
						@click="selectPriceType(item,index)">
						<view class="">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
			<view class="row y-price flex">
				<view class="left">运价</view>
				<view class="right" v-if="priceBtnType==0">
					<input type="number" value="" placeholder="输入运费单价" class="input" v-model="dataObj.freightPrice" />
				</view>
				<view class="right" v-if="priceBtnType==1">
					<input type="number" value="" placeholder="输入车数" class="input" v-model="dataObj.freightPrice" />
				</view>
				<view class="right" v-if="priceBtnType==2">
					<input type="number" value="" placeholder="输入方数" class="input" v-model="dataObj.freightPrice" />
				</view>
			</view>
		</view>
		<view class="content3">
			<view class="row" @click="isShowPopup3=true">
				<view class="left">货站信息</view>
				<view class="right flex row-ellipsis">
					{{dataObj.contacts?dataObj.contacts+'、'+dataObj.contactsPhone+'、'+dataObj.freightStationName:"完善货站信息"}}
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view>
		</view>
		<view class="content5">
			<view class="flex row" @click="selectValidityPeriod(0)">
				<view class="left">装车日期</view>
				<view class="right flex">
					{{dataObj.loadingDate?dataObj.loadingDate:"选择装车日期"}}
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view>
			<view class="flex row" @click="selectValidityPeriod(1)">
				<view class="left-text">时段</view>
				<view class="right flex">
					{{dataObj.periodOfTime?dataObj.periodOfTime:'选择装时段'}}
					<u-icon name="arrow-right" size="20"></u-icon>
				</view>
			</view>
		</view>
		<view class="content5">
			<view class="row">
				<view class="left">备注（选填）</view>
			</view>
			<view class="row">
				<u--textarea v-model="dataObj.remark" placeholder="请输入内容" :count='true' maxlength='500'>
				</u--textarea>
			</view>
			<view class="cartype-item" style="font-size: 24rpx;" :class="item.checked?'active':''"
				v-for="(item,index) in remarkList" @click="selectRemarkType(item,index)">
				<view class="">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="content5">
			<view class="row">
				<view class="left">货站信息费</view>
				<view class="right flex"><input type="number" value="" placeholder="输入信息费金额" class="input"
						v-model="dataObj.stationFee" /><text style="width: 100rpx;">元/吨</text></view>
			</view>
		</view>
		<view class="">
			<view class="submit" @click="goodsSubmit">发布货源</view>
		</view>
		<u-popup :show="isShowPopup1" :round="10" closeable safeAreaInsetBottom @close="isShowPopup1=false">
			<view style="padding: 60rpx 40rpx;" class="popup">
				<view class="title">
					货物信息
				</view>
				<u--form labelPosition="left" :model="dataObj" ref="uForm">
					<u-form-item label="货名" prop="contacts" borderBottom labelWidth="140rpx">
						<u--input v-model="dataObj.goodsName" border="none" placeholder="输入货名"
							inputAlign='right'></u--input>
					</u-form-item>
					<u-form-item label="包装类型" prop="contacts" borderBottom labelWidth="140rpx">
						<view style="display: flex;justify-content: flex-end;width: 100%;">
							<view class="price-item" :class="index==bzIndex?'active':''"
								v-for="(item,index) in packageTypePickerColumns" @click="selectBzType(item,index)">
								<view class="">
									{{item}}
								</view>
							</view>
						</view>
					</u-form-item>
					<u-form-item label="计量方式" borderBottom labelWidth="140rpx">
						<view style="display: flex;justify-content: flex-end;width: 100%;">
							<view class="price-item" :class="item.checked?'active':''"
								v-for="(item,index) in measuringMethodList" @click="selectJlType(item,index)">
								<view class="">
									{{item.name}}
								</view>
							</view>
						</view>
					</u-form-item>
					<u-form-item label="货物重量" borderBottom labelWidth="140rpx" v-if="measuringMethodList[0].checked">
						<u--input v-model="dataObj.weight" border="none" placeholder="输入重量"
							inputAlign='right'></u--input><text style="margin-left: 10rpx;">吨</text>
					</u-form-item>
					<u-form-item label="货物体积" borderBottom labelWidth="140rpx" v-if="measuringMethodList[1].checked">
						<u--input v-model="dataObj.volume" border="none" placeholder="输入体积"
							inputAlign='right'></u--input><text style="margin-left: 10rpx;">方</text>
					</u-form-item>
					<u-form-item label="预计用车数量" labelWidth="200rpx">
						<u--input v-model="dataObj.expectedNum" border="none" placeholder="输入用车数量"
							inputAlign='right'></u--input><text style="margin-left: 10rpx;">辆</text>
					</u-form-item>
					<!-- <u-form-item label="货站名称" prop="contacts" borderBottom labelWidth="140rpx">
						<u--input v-model="dataObj.freightStationName" border="none" placeholder="输入货站名称,不超过10个字"
							inputAlign='right'></u--input>
					</u-form-item> -->
				</u--form>
				<view class="submit" @click="goodsInfoSubmit">完成</view>
			</view>
		</u-popup>
		<u-popup :show="isShowPopup2" :round="10" closeable safeAreaInsetBottom @close="isShowPopup2=false">
			<view style="padding: 60rpx 40rpx;" class="popup">
				<view class="title">
					车型车长
				</view>
				<view class="">
					选择车型 <text style="color:rgb(170, 170, 170);margin-left: 20rpx;">(1-3个)</text>
				</view>
				<view class="cartype-item" :class="item.checked?'active':''" v-for="(item,index) in carTypeList"
					@click="selectCarType(item,index)">
					<view class="">
						{{item.name}}
					</view>
				</view>
				<view class="" style="margin: 40rp 0;">
					选择车长 <text style="color:rgb(170, 170, 170);margin-left: 20rpx;">(1-3个)</text>
				</view>
				<view class="cartype-item" :class="item.checked?'active':''" v-for="(item,index) in carLengthList"
					@click="selectCarLength(item,index)">
					<view class="">
						{{item.name}}
					</view>
				</view>
				<view class="submit" @click="carInfoSubmit">完成</view>
			</view>
		</u-popup>
		<u-popup :show="isShowPopup3" :round="10" closeable safeAreaInsetBottom @close="isShowPopup3=false">
			<view style="padding: 60rpx 40rpx;" class="popup">
				<view class="title">
					货站信息
				</view>
				<u--form labelPosition="left" :model="dataObj" ref="uForm">
					<u-form-item label="联系人" borderBottom labelWidth="140rpx">
						<u--input v-model="dataObj.contacts" border="none" placeholder="输入联系人姓名"
							inputAlign='right'></u--input>
					</u-form-item>
					<u-form-item label="联系人电话" borderBottom labelWidth="160rpx">
						<u--input v-model="dataObj.contactsPhone" border="none" placeholder="输入联系人姓名"
							inputAlign='right'></u--input>
					</u-form-item>
					<u-form-item label="货站名称" labelWidth="140rpx">
						<u--input v-model="dataObj.freightStationName" border="none" placeholder="输入货站名称,不超过10个字"
							inputAlign='right'></u--input>
					</u-form-item>
				</u--form>
				<view class="submit" @click="isShowPopup3=false">完成</view>
			</view>
		</u-popup>
		<u-popup :show="isShowPopup4" :round="10" closeable safeAreaInsetBottom @close="isShowPopup4=false">
			<view style="padding: 60rpx 40rpx;" class="popup">
				<view class="title">
					装车时间
				</view>
				<u-line></u-line>
				<view class="select-date">
					<view class="title-two">
						选择日期
					</view>
					<view class="date-list">
						<view class="date-list-item" :class="item.checked?'active':''" v-for="(item,index) in dateList"
							@click="selectDate(item,index)">
							{{index==0?"今天"+item.date:item.date}}
						</view>
					</view>
					<view class="title-two">
						选择时段
					</view>
					<view class="row flex" style="margin-bottom: 20rpx;">
						<view class="" style="flex: 1;text-align: center;">
							开始时间
						</view>
						<view class="" style="flex: 1;text-align: center;">
							结束时间
						</view>
					</view>
					<picker-view class="picker" :value="value" @change="getime">
						<picker-view-column>
							<view class="hours" style="line-height:30px; text-align: center;"
								v-for="(item,index) in hoursList" :key="index">{{item}}</view>
						</picker-view-column>
						<picker-view-column>
							<view class="hours" style="line-height:30px; text-align: center;"
								v-for="(item,index) in hoursList" :key="index">{{item}}</view>
						</picker-view-column>
					</picker-view>
				</view>
				<view class="submit" @click="dateInfoSubmit" v-if="isCanBeSubmit">完成</view>
				<view class="fa-submit" v-if="!isCanBeSubmit">
					完成
				</view>
			</view>
		</u-popup>

		<!-- 	<u-modal :show="isShowAlert" :title="alertTitle" :content='alertContent' :closeOnClickOverlay='false'
			:showCancelButton='showCancelButton' confirmColor='#F5BA3C' @confirm="$u.throttle(confirmClick(), 1000)"
			@close="cancelClick" @cancel="cancelClick"></u-modal>
		<u-modal :show="isShowAlert1" :title="alertTitle" :confirmText='confirmText' :content='alertContent'
			:closeOnClickOverlay='false' :showCancelButton='showCancelButton' confirmColor='#F5BA3C'
			@confirm="$u.throttle(confirmClick(), 1000)" @close="cancelClick" @cancel="cancelClick"></u-modal> -->
		<u-toast ref="uToast"></u-toast>

	</view>
</template>

<script>
	var _this;
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				isCanBeSubmit: true,
				isEdit: false,
				isCopy: false,
				hoursList: [
					'00:00',
					'00:30',
					'01:00',
					'01:30',
					'02:00',
					'02:30',
					'03:00',
					'03:30',
					'04:00',
					'04:30',
					'05:00',
					'05:30',
					'06:00',
					'06:30',
					'07:00',
					'07:30',
					'08:00',
					'08:30',
					'09:00',
					'09:30',
					'10:00',
					'10:00',
					'11:00',
					'11:30',
					'12:00',
					'12:30',
					'13:00',
					'13:30',
					'14:00',
					'14:30',
					'15:00',
					'15:30',
					'16:00',
					'16:30',
					'17:00',
					'17:30',
					'18:00',
					'18:30',
					'19:00',
					'19:30',
					'20:00',
					'20:30',
					'21:00',
					'21:30',
					'22:00',
					'22:30',
					'23:00',
					'23:30'
				],
				value: ["18", "34"],
				checkTime: ["09:00", "17:00"],
				dateCheckList: [],
				dateList: [],
				jlLindex: 0,
				bzIndex: 0,
				priceIndex: 0,
				measuringMethodList: [{
						name: '重量（吨）',
						checked: true,
					},
					{
						name: '体积（方）',
						checked: false,
					}
				],
				jlCheckList: ['重量（吨）'],
				carLengthCheckList: ['不限'],
				carTypeCheckList: [],
				carLengthList: [{
						name: '不限',
						checked: false
					},
					{
						name: '2',
						checked: false
					},
					{
						name: '3',
						checked: false
					},
					{
						name: '4',
						checked: false
					},
					{
						name: '5',
						checked: false
					},
					{
						name: '6',
						checked: false
					},
					{
						name: '7',
						checked: false
					},
					{
						name: '8',
						checked: false
					},
					{
						name: '9',
						checked: false
					},
					{
						name: '10',
						checked: false
					},
					{
						name: '11',
						checked: false
					},
					{
						name: '12',
						checked: false
					},
					{
						name: '13',
						checked: false
					},
					{
						name: '14',
						checked: false
					},
					{
						name: '15',
						checked: false
					},
					{
						name: '16',
						checked: false
					},
					{
						name: '17',
						checked: false
					},
					{
						name: '18',
						checked: false
					}
				],
				carTypeList: [{
						name: '高栏',
						checked: false
					},
					{
						name: '集装箱',
						checked: false
					},
					{
						name: '平板',
						checked: false
					},
					{
						name: '厢式',
						checked: false
					},
					{
						name: '自卸',
						checked: false
					},
					{
						name: '冷藏车',
						checked: false
					},
					{
						name: '保温车',
						checked: false
					},
					{
						name: '轻型',
						checked: false
					}
				],
				packageTypePickerColumns: ['散装', '袋装', '其他'],
				packageTypePicker: false,
				isShowPopup1: false,
				isShowPopup2: false,
				isShowPopup3: false,
				isShowPopup4: false,
				remarkCheckList: [],
				remarkList: [{
						name: "到付",
						checked: false,
					},
					{
						name: "需防雨",
						checked: false,
					},
					{
						name: "不压车",
						checked: false,
					}, {
						name: "合规运输",
						checked: false,
					}
				],
				priceBtnType: '0',
				priceBtnList: [{
						name: '吨',
						index: 0
					},
					{
						name: '车',
						index: 1
					},
					{
						name: '方',
						index: 2
					}
				],

				showCancelButton: true,
				qyList: [],
				isShowAlert: false,
				alertTitle: '确定发布运输任务？',
				alertContent: null,
				radioCustomStyle: {
					margin: '0 0 0 20rpx'
				},
				freightAdvance: false,
				dataObj: {
					commonId: '',
					sendPrivate: '',
					sendCity: '',
					sendArea: '',
					sendDetailedAddress: '',
					unloadPrivate: '',
					unloadCity: '',
					unloadArea: '',
					unloadDetailedAddress: '',
					cargoDistance: '',
					goodsName: '',
					packageType: '散装',
					measuringMethod: '重量（吨）',
					weight: '',
					volume: '',
					expectedNum: '',
					carModel: '',
					carLength: '',
					billingMethod: '0',
					freightPrice: '',
					contacts: '',
					contactsPhone: '',
					freightStationName: '',
					loadingDate: '',
					periodOfTime: '',
					remark: '',
					stationFee: '',
					sendLongitude: '',
					sendLatitude: '',
					unsendLongitude: '',
					unsendLatitude: ''
				},
				confirmText: '',
				isShowAlert1: false,
				ValidityPeriodType: '',
			}
		},
		onShow() {
			if (!this.hasLogin) {
				uni.$u.route('/pages/public/login');
				return
			}
			this.$request.baseRequest('get', '/cargoOwnerInfo/firstAuthentication', {
				phone: this.userInfo.phone
			}).then(res => {
				uni.setStorageSync("firstAuthentication", res.data)
				let _obj = res.data
				if (_obj.authenticationStatus == '已认证') {
					uni.$u.route('/pages/components/empty/index');
				} else if (_obj.authenticationStatus == '审核中') {
					uni.showToast({
						title: '身份信息审核中',
						icon: 'none'
					})

				} else if (_obj.authenticationStatus == '已过期') {
					this.alertTitle = '身份信息已过期！'
					this.showCancelButton = false
					this.confirmText = '立即修改'
					this.isShowAlert1 = true
				} else {
					this.alertTitle = '身份信息未认证，去认证?'
					this.confirmText = '确认'
					this.showCancelButton = false
					this.isShowAlert = true
				}
			})
			if (!this.isEdit || !this.isCopy) {
				let _faddress = uni.getStorageSync('storage_faddress');
				let _saddress = uni.getStorageSync('storage_saddress');
				if (_faddress) {
					this.dataObj.sendCity = this.$helper.filterUrban(_faddress.city)
					this.dataObj.sendArea = this.$helper.filterArea(_faddress.area)
					this.dataObj.sendAdCode = _faddress.adCode
					this.dataObj.sendPrivate = _faddress.province
					this.dataObj.sendDetailedAddress = _faddress.detailedAddress
					this.dataObj.sendLongitude = _faddress.longitude
					this.dataObj.sendLatitude = _faddress.latitude
					if (_faddress.contactPhone) {
						this.dataObj.senderPhone = _faddress.contactPhone
					}
					if (_faddress.contacts) {
						this.dataObj.sender = _faddress.contacts
					}
				} else {
					this.getDefaultPlace(0)
				}
				if (_saddress) {
					this.dataObj.unloadDetailedAddress = _saddress.detailedAddress
					this.dataObj.unloadCity = this.$helper.filterUrban(_saddress.city)
					this.dataObj.unloadArea = this.$helper.filterArea(_saddress.area)
					this.dataObj.unsendAdCode = _faddress.adCode
					this.dataObj.unloadPrivate = _saddress.province
					this.dataObj.unsendLongitude = _saddress.longitude
					this.dataObj.unsendLatitude = _saddress.latitude
					if (_saddress.contacts) {
						this.dataObj.receiver = _saddress.contacts
					}
					if (_saddress.contactPhone) {
						this.dataObj.receiverPhone = _saddress.contactPhone
					}
				} else {
					this.getDefaultPlace(1)
				}
				if (this.dataObj.sendLatitude && this.dataObj.sendLongitude && this.dataObj.unsendLatitude && this.dataObj
					.unsendLongitude) {
					this.dataObj.cargoDistance = this.$helper.getDistance(this.dataObj.unsendLatitude, this.dataObj
						.unsendLongitude,
						this.dataObj.sendLatitude, this.dataObj.sendLongitude)
				}
			}


		},
		onLoad(options) {

			if (options.type == 1) {
				this.isCopy = true
			}
			if (options.type == 2) {
				this.isEdit = true
			}
			if (options.type == 1 || options.type == 2) {
				this.dataObj = uni.getStorageSync("selectGoodObj")
				if (this.dataObj.packageType == '散装') {
					this.bzIndex = 0
				} else if (this.dataObj.packageType == '袋装') {
					this.bzIndex = 1
				} else {
					this.bzIndex = 2
				}
				let _carModel = this.dataObj.carModel.split(',')
				for (let i = 0; i < this.carTypeList.length; i++) {
					for (let k = 0; k < _carModel.length; k++) {
						if (this.carTypeList[i].name == _carModel[k]) {
							this.carTypeList[i].checked = true
							this.carTypeCheckList.push(this.carTypeList[i])
						}
					}
				}
				let _carLength = this.dataObj.carLength.split(',')
				for (let i = 0; i < this.carLengthList.length; i++) {
					for (let k = 0; k < _carLength.length; k++) {
						if (this.carLengthList[i].name == _carLength[k]) {
							this.carLengthList[i].checked = true
							this.carLengthCheckList.push(this.carLengthList[i].name)
						}
					}
				}

				let _measuringMethod = this.dataObj.measuringMethod.split(',')
				this.jlCheckList = []
				for (let i = 0; i < this.measuringMethodList.length; i++) {
					this.measuringMethodList[i].checked = false
					for (let k = 0; k < _measuringMethod.length; k++) {
						if (this.measuringMethodList[i].name == _measuringMethod[k]) {
							this.measuringMethodList[i].checked = true
							this.jlCheckList.push(this.measuringMethodList[i].name)
						}
					}
				}
				this.priceIndex = this.dataObj.billingMethod
				let _loadingDate = this.dataObj.loadingDate.split(',')

			}
			_this = this
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			goodsSubmit() {
				this.dataObj.commonId = this.userInfo.id
				if (this.validate()) return
				uni.showLoading({
					mask: true,
					title: '加载中'
				})
				console.log("this.dataObj", this.dataObj)
				this.dataObj.headSculpture = this.userInfo.avatarUrl
				if (this.isEdit) {
					this.$request.baseRequest('post', '/hyReleaseGoodsInfo/api/editTask', this.dataObj).then(res => {
							uni.hideLoading()
							uni.navigateBack()
						})
						.catch(res => {});
				} else {
					this.$request.baseRequest('post', '/hyReleaseGoodsInfo/api/addTask', this.dataObj).then(res => {
							uni.hideLoading()
							uni.navigateBack()
						})
						.catch(res => {});
				}

			},
			getime(e) {
				let val = e.detail.value
				console.log(val)
				this.checkTime[0] = this.hoursList[val[0]]
				this.checkTime[1] = this.hoursList[val[1]]
				if (val[0] > val[1]) {
					uni.showToast({
						icon: 'none',
						title: "开始时间不能大于结束时间！"
					})
					this.isCanBeSubmit = false
					return
				} else {
					this.isCanBeSubmit = true
				}

				console.log(this.checkTime)

			},
			selectDate(val, index) {
				console.log("val--index", val, index)
				let _startCheckIndex = ''
				let _endCheckIndex = ''
				if (this.dateCheckList.length != 0) {
					_startCheckIndex = this.dateCheckList[0].index
					_endCheckIndex = this.dateCheckList[this.dateCheckList.length - 1].index
					console.log("选中开始", _startCheckIndex)
					console.log("选中结束", _endCheckIndex)
				}
				if (this.dateCheckList.length == 0) {
					val.checked = !val.checked
					if (val.checked) {
						this.dateCheckList.push(val)
					}
				} else if (this.dateCheckList.length == 1) {
					val.checked = !val.checked
					if (!val.checked) {
						this.dateCheckList = []
					} else {
						this.dateCheckList = []
						if (val.index < _startCheckIndex) {
							for (let i = val.index; i <= _startCheckIndex; i++) {
								this.dateList[i].checked = true
								this.dateCheckList.push(this.dateList[i])
							}
						} else if (val.index > _startCheckIndex) {
							for (let i = _startCheckIndex; i <= val.index; i++) {
								console.log(i)
								this.dateList[i].checked = true
								this.dateCheckList.push(this.dateList[i])
							}
						}
					}
				} else if (this.dateCheckList.length == 2) {
					//点开始或点结束
					val.checked = !val.checked
					if (val.index == _startCheckIndex) {
						this.dateCheckList.splice(0, 1)
					}
					if (val.index == _endCheckIndex) {
						this.dateCheckList.splice(1, 1)
					}
					if (val.index < _startCheckIndex) {
						this.dateCheckList = []
						for (let i = val.index; i <= _endCheckIndex; i++) {
							this.dateList[i].checked = true
							this.dateCheckList.push(this.dateList[i])
						}
					}
					if (val.index > _endCheckIndex) {
						this.dateCheckList = []
						for (let i = _startCheckIndex; i <= val.index; i++) {
							this.dateList[i].checked = true
							this.dateCheckList.push(this.dateList[i])
						}
					}
				} else {
					let _dateCheckList = JSON.parse(JSON.stringify(this.dateCheckList))
					if (val.index == _startCheckIndex || val.index == _endCheckIndex) {
						val.checked = !val.checked
						for (let i = 0; i < _dateCheckList.length; i++) {
							if (val.index == _dateCheckList[i].index) {
								this.dateCheckList.splice(i, 1)
							}
						}
					} else if (_startCheckIndex < val.index && val.index < _endCheckIndex) {
						for (let i = 0; i < this.dateList.length; i++) {
							this.dateList[i].checked = false
						}
						this.dateCheckList = []
					} else if (val.index < _startCheckIndex) {
						this.dateCheckList = []
						for (let i = val.index; i <= _endCheckIndex; i++) {
							this.dateList[i].checked = true
							this.dateCheckList.push(this.dateList[i])
						}

					} else if (val.index > _endCheckIndex) {
						this.dateCheckList = []
						for (let i = _startCheckIndex; i <= val.index; i++) {
							console.log(i)
							this.dateList[i].checked = true
							this.dateCheckList.push(this.dateList[i])
						}
					}
				}
				console.log("this.dateCheckList", this.dateCheckList)
			},
			selectJlType(val, index) {
				val.checked = !val.checked
				if (val.checked) {
					this.jlCheckList.push(val.name)
				} else {
					let _jlCheckList = JSON.parse(JSON.stringify(this.jlCheckList))
					for (let i = 0; i < _jlCheckList.length; i++) {
						if (_jlCheckList[i] == val.name) {
							this.jlCheckList.splice(i, 1)
							if (this.jlCheckList.length == 0 && val.name == '重量（吨）') {
								this.jlCheckList.push('体积（方）')
								this.measuringMethodList[1].checked = true
								this.measuringMethodList[0].checked = false
							}
							if (this.jlCheckList.length == 0 && val.name == '体积（方）') {
								this.jlCheckList.push('重量（吨）')
								this.measuringMethodList[0].checked = true
								this.measuringMethodList[1].checked = false
							}
						}
					}
				}
				console.log('this.jlCheckList', this.jlCheckList)
			},
			selectBzType(val, index) {
				this.bzIndex = index
				this.dataObj.packageType = val
			},
			selectPriceType(val, index) {
				this.priceIndex = index
				this.priceBtnType = index
				this.dataObj.billingMethod = index
			},
			carInfoSubmit() {
				if (this.carTypeCheckList.length == 0) {
					uni.showToast({
						icon: 'none',
						title: "至少选择1个车型！"
					})
					return
				}
				if (this.carLengthCheckList.length == 0) {
					uni.showToast({
						icon: 'none',
						title: "至少选择1个车长！"
					})
					return
				}
				this.dataObj.carLength = this.carLengthCheckList.toString()
				this.dataObj.carModel = this.carTypeCheckList.toString()
				this.isShowPopup2 = false
			},
			selectRemarkType(val, index) {
				this.dataObj.remark += val.name + ','
			},
			selectCarType(val, index) {
				if (this.carTypeCheckList.length > 2 && !val.checked) {
					uni.showToast({
						icon: 'none',
						title: "最多选择3个车型！"
					})
					return
				}
				val.checked = !val.checked
				if (val.checked) {
					this.carTypeCheckList.push(val.name)
				} else {
					let _carTypeCheckList = JSON.parse(JSON.stringify(this.carTypeCheckList))
					for (let i = 0; i < _carTypeCheckList.length; i++) {
						if (_carTypeCheckList[i] == val.name) {
							this.carTypeCheckList.splice(i, 1)
						}
					}
				}
				console.log("carTypeCheckList", this.carTypeCheckList)
			},
			selectCarLength(val, index) {
				if (this.carLengthCheckList.length > 2 && !val.checked && index != 0) {
					uni.showToast({
						icon: 'none',
						title: "最多选择3个车长！"
					})
					return
				}
				this.carLengthCheckList = []
				val.checked = !val.checked
				// this.carLengthList[0].checked = false
				console.log(val)
				if (index == 0 && val.checked) {
					this.carLengthCheckList = ['不限']
					for (let i = 1; i < this.carLengthList.length; i++) {
						this.carLengthList[i].checked = false
					}
					console.log("this.carLengthCheckList", this.carLengthCheckList)
					return
				} else {
					this.carLengthList[0].checked = false
				}
				for (let i = 0; i < this.carLengthList.length; i++) {
					if (this.carLengthList[i].checked) {
						this.carLengthCheckList.push(this.carLengthList[i].name)
					}
				}
			},
			packageTypeConfirm(val) {
				console.log(val)
				this.dataObj.packageType = val.value[0]
				this.packageTypePicker = false
			},
			goodsInfoSubmit() {
				this.dataObj.measuringMethod = this.jlCheckList.toString()
				this.isShowPopup1 = false
			},
			dateInfoSubmit() {
				let _dateList = []
				for (let i = 0; i < this.dateCheckList.length; i++) {
					_dateList.push(this.dateCheckList[i].date)
				}
				this.dataObj.loadingDate = _dateList.toString()
				this.dataObj.periodOfTime = this.checkTime.toString()
				this.isShowPopup4 = false
			},
			funDate() {
				let timestamp = new Date(new Date().toLocaleDateString()).getTime();
				let basetime = 24 * 60 * 60 * 1000;
				for (let i = 0; i < 8; i++) {
					let _date = timestamp + basetime * i
					let _obj = {
						date: new Date(_date).toLocaleDateString().substring(5).replace("/", "."),
						index: i,
						checked: false,
					}
					this.dateList.push(_obj)
					console.log("this.dateList", this.dateList)
				}
				console.log(this.dateList)

			},
			validate() {
				if (uni.$u.test.isEmpty(this.dataObj.commonId)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "货主不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.sendArea)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "请选择装货地区！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.sendDetailedAddress)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "装货详细地址不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.unloadArea)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "请选择卸货地区！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.unloadDetailedAddress)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "卸货详细地址不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.packageType)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "包装类型不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.goodsName)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "货名不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.measuringMethod)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "计量方式不能为空！",
					})
					return true
				}
				if (this.dataObj.measuringMethod == '重量（吨）') {
					if (uni.$u.test.isEmpty(this.dataObj.weight)) {
						this.$refs.uToast.show({
							type: 'error',
							message: "货物重量不能为空！",
						})
						return true
					}
				} else if (this.dataObj.measuringMethod == '体积（方）') {
					if (uni.$u.test.isEmpty(this.dataObj.volume)) {
						this.$refs.uToast.show({
							type: 'error',
							message: "货物体积不能为空！",
						})
						return true
					}
				} else {
					if (uni.$u.test.isEmpty(this.dataObj.volume) || uni.$u.test.isEmpty(this.dataObj.weight)) {
						this.$refs.uToast.show({
							type: 'error',
							message: "货物体积、货物重量不能为空！",
						})
						return true
					}
				}
				if (uni.$u.test.isEmpty(this.dataObj.expectedNum)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "预计用车数量不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.carModel)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "车型不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.carLength)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "车长不能为空！",
					})
					return true
				}

				if (uni.$u.test.isEmpty(this.dataObj.billingMethod)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "运价单位不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.freightPrice)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "运价不能为空！",
					})
					return true
				}
				if (
					this.dataObj.freightPrice < 0 || this.dataObj.freightPrice > 100000 || (
						String(this.dataObj.freightPrice).indexOf('.') != -1 && String(this.dataObj.freightPrice).length -
						(String(this.dataObj.freightPrice).indexOf(
							'.') + 1) > 2)
				) {
					uni.showToast({
						title: '运价输入错误！',
						duration: 2000,
						icon: "none",
					});
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.contacts)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "联系人不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.contactsPhone)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "联系人电话不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.freightStationName)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "货站名称不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.loadingDate)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "装车日期不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.periodOfTime)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "时段不能为空！",
					})
					return true
				}
				// if (uni.$u.test.isEmpty(this.dataObj.stationFee)) {
				// 	this.$refs.uToast.show({
				// 		type: 'error',
				// 		message: "货站信息费不能为空！",
				// 	})
				// 	return true
				// }
			},
			confirmClick() {
				uni.$u.throttle(this.requestdata, 500)
			},
			requestdata() {
				if (this.dataDetails.type == '元/吨') {
					this.dataObj.billingMethod = 0
				} else {
					this.dataObj.billingMethod = 1
				}
				if (this.dataObj.freightAdvance) {
					this.dataObj.freightAdvance = 1
				} else {
					this.dataObj.freightAdvance = 0
				}
				if (!this.dataObj.receiverIdcard) {
					this.dataObj.receiverIdcard = ''
				}
				if (!this.dataObj.receiverCreditCode) {
					this.dataObj.receiverCreditCode = ''
				}
				this.dataObj.carModel = this.carTypeCheckList.toString()
				this.dataObj.commonId = this.userInfo.id
				uni.$u.route('/pages/order/signContract', {
					obj: JSON.stringify(this.dataObj),
					type: 1
				});

			},
			cancelClick() {
				this.isShowAlert = false
			},
			//获取默认装货地、卸货地
			getDefaultPlace(type) {
				// 0时获取默认装货地址,1时获取默认卸货地址 通过选择获取的地址无需获取默认地址
				uni.showLoading({
					mask: true,
					title: '加载中...'
				})
				this.$request.baseRequest('get', '/cargoOwnerAddressInfo/addressList', {
						commonId: this.userInfo.id
					}).then(res => {
						uni.hideLoading()
						for (let i = 0; i < res.data.length; i++) {
							if (res.data[i].defaultShipment == 1 && type == 0) {
								this.dataObj.sendCity = res.data[i].city
								this.dataObj.sendArea = res.data[i].area
								this.dataObj.sendPrivate = res.data[i].province
								this.dataObj.sendDetailedAddress = res.data[i].detailedAddress
								this.dataObj.sendLongitude = res.data[i].longitude
								this.dataObj.sendLatitude = res.data[i].latitude
								this.dataObj.sender = res.data[i].contacts
								this.dataObj.senderPhone = res.data[i].contactPhone
							}
							if (res.data[i].defaultReceipt == 1 && type == 1) {
								this.dataObj.unloadDetailedAddress = res.data[i].detailedAddress
								this.dataObj.unloadCity = res.data[i].city
								this.dataObj.unloadArea = res.data[i].area
								this.dataObj.unloadPrivate = res.data[i].province
								this.dataObj.unsendLongitude = res.data[i].longitude
								this.dataObj.unsendLatitude = res.data[i].latitude
								this.dataObj.receiver = res.data[i].contacts
								this.dataObj.receiverPhone = res.data[i].contactPhone
							}
						}
						if (this.dataObj.sendLatitude && this.dataObj.sendLongitude && this.dataObj.unsendLatitude &&
							this.dataObj.unsendLongitude) {
							this.dataObj.cargoDistance = this.$helper.getDistance(this.dataObj.unsendLatitude, this
								.dataObj
								.unsendLongitude, this.dataObj.sendLatitude, this.dataObj.sendLongitude)
						}

					})
					.catch(res => {
						uni.hideLoading()
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						})
					});
			},
			changeHandler(e) {
				const {
					columnIndex,
					value,
					values,
					index,
					picker = this.$refs.uPicker
				} = e


			},
			selectAddress(type) {
				uni.$u.route('/pages/release/selectAddress', {
					type: type,
				});
			},
			selectValidityPeriod(type) {
				this.funDate()
				if (this.isEdit || this.isCopy) {

					let _loadingDate = this.dataObj.loadingDate.split(',')
					for (let i = 0; i < this.dateList.length; i++) {
						this.dateList[i].checked = false
						for (let k = 0; k < _loadingDate.length; k++) {
							if (this.dateList[i].date == _loadingDate[k]) {
								this.dateList[i].checked = true
								this.dateCheckList.push(this.dateList[i])
							}
						}
					}
				}
				this.isShowPopup4 = true
			},
		}
	}
</script>

<style scoped lang="scss">
	.input {
		text-align: right;
		width: 100%;
	}

	.content {
		height: 100vh;
		overflow: scroll;
	}

	.title {
		padding: 0 20rpx;
		display: flex;
		justify-content: center;
		position: relative;

		.nav-title {
			font-size: 32rpx;
		}

		.back {
			position: absolute;
			left: 20rpx;
		}

		.search {
			display: flex;
			align-items: center;
			position: absolute;
			right: 20rpx;
		}

	}


	.fixed1 {
		height: var(--status-bar-height);
	}

	.row {
		display: flex;
		justify-content: space-between;
	}

	.content1 {
		background: white;
		margin: 40rpx 20rpx 0 20rpx;
		border-radius: 20rpx;
		padding: 40rpx;

		.select-sf {
			color: #171717;
			font-size: 34rpx;
			font-weight: 600;
		}

		.select-sf1 {
			color: #999999;
		}

		.right {
			color: #CBCBCB
		}
	}

	.content2,
	.content3,
	.content5 {
		box-sizing: border-box;
		background: white;
		border-radius: 20rpx;
		padding: 20rpx;
		margin: 20rpx;

		.row {
			margin: 30rpx;
		}

		.row1,
		.row2 {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left .top {
				display: flex;
			}
		}
	}
	.content5{
		.left{
			width: 100px;
		}
		.right{
			overflow-x: auto;
		}
	}

	.select-type {
		display: flex;
		justify-content: flex-end;
	}

	.top-title {
		background: #fff;
		padding: 20rpx;
		position: fixed;
		z-index: 100;
		top: 0;
		box-sizing: border-box;
		width: 100%;
	}

	.content2 {
		padding: 40rpx;

		.row1,
		.row2 {
			.left {
				width: 100%;
			}

			.right {
				color: #CBCBCB
			}
		}

		.row2 {
			margin-top: 40rpx;
		}

		.top {
			display: flex;
			align-items: center;
		}

		.bottom {
			margin-top: 10rpx;
			padding-left: 72rpx;
		}

		.title {
			font-size: 36rpx;
			font-weight: 700;
			color: #171717;
			width: 90%;
			justify-content: flex-start;
			// text-align:left;
		}

		.collect {
			width: 40rpx;
			height: 40rpx;
			line-height: 40rpx;
			background: #F5BA3C;
			color: white;
			// font-size:1px;
			padding: 6rpx;
			border-radius: 50%;
			text-align: center;
		}

		.send {
			width: 40rpx;
			height: 40rpx;
			line-height: 40rpx;
			background: #101010;
			color: white;
			padding: 6rpx;
			border-radius: 50%;
			text-align: center;
		}
	}

	.content3 {
		.left {
			width: 160rpx;
		}
	}

	.content4 {
		margin: 20rpx;
		padding-left: 20rpx;

		.title {
			color: #999999;
		}

		.btn-text {
			color: #F5BA3C;
			border: 1px solid #F5BA3C;
			border-radius: 40rpx;
			padding: 0rpx 10rpx;
			box-sizing: border-box;
		}
	}

	.submit {
		width: 90%;
		margin: 50rpx auto;
		font-size: 36rpx;
		font-weight: 500;
		color: #FFFFFF;
		background: #F5BA3C;
		text-align: center;
		padding: 20rpx 0;
		border-radius: 50rpx;
	}

	.fa-submit {
		width: 90%;
		margin: 50rpx auto;
		font-size: 36rpx;
		font-weight: 500;
		color: #FFFFFF;
		background: rgb(153, 153, 153);
		text-align: center;
		padding: 20rpx 0;
		border-radius: 50rpx;
	}

	.select-data {
		color: #999999;
	}

	.row-bgc {
		background: #F7F8FA;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
	}

	.car-input {

		// padding:20rpx;
		// box-sizing: border-box;
		// border-radius: 10px;
	}

	.car-line {
		margin: 0 20rpx;

	}

	.car-row {
		display: flex;
		background: white;
		padding: 20rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
	}

	uni-navigator {
		display: inline-block;
		color: #F5BA3C;
	}

	.popup .title {
		position: relative;
		top: -30rpx;
		font-size: 36rpx;
		font-weight: 700;
	}

	.price-item {
		display: inline-block;
		background: rgb(243, 243, 243);
		border: 1px solid rgb(243, 243, 243);
		text-align: center;
		margin-left: 20rpx;
		padding: 14rpx 30rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		border-radius: 10rpx;
	}

	.cartype-item {
		display: inline-block;
		width: calc(25% - 40rpx);
		background: rgb(243, 243, 243);
		border: 1px solid rgb(243, 243, 243);
		text-align: center;
		margin: 20rpx;
		padding: 14rpx 10rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		border-radius: 10rpx;
	}

	.active {
		background: rgb(251, 240, 229) !important;
		border: 1px solid rgb(255, 134, 0) !important;
		color: rgb(255, 134, 0);
	}

	.y-price {
		justify-content: space-between;

		.left {
			width: 320rpx;
		}

		.right {
			width: 100%;
		}
	}

	.date-list-item {
		display: inline-block;
		background: rgb(243, 243, 243);
		border: 1px solid rgb(243, 243, 243);
		box-sizing: border-box;
		width: calc(25% - 20rpx);
		text-align: center;
		margin: 10rpx;
		padding: 10rpx 0;
		border-radius: 10rpx;
	}

	.title-two {
		margin: 20rpx 0;
	}

	.time1 {
		width: 100%;
		margin: 0 auto;
		background-color: #FFFFFF;
		color: #000;
		height: 450rpx;

		.top {
			width: 690rpx;
			margin: 0 auto;
			height: 100rpx;
			line-height: 100rpx;

			text {
				font-weight: bold;

				&:nth-child(1) {
					font-size: 28rpx;
					color: #999;
				}

				&:nth-child(2) {
					font-size: 28rpx;
					color: #0A84FF;
				}
			}
		}

		.tip12 {
			width: 100%;
			height: 100rpx;

			view {
				width: 50%;
				text-align: center;
				line-height: 100rpx;
				font-size: 40rpx;
				color: #000000;
			}
		}

		.hours {
			font-size: 30rpx;
			font-weight: bold;
			color: #000;
		}

		.minutes {
			font-size: 30rpx;
			font-weight: bold;
			color: #000;
		}
	}

	.picker {
		width: 100%;
		height: 300rpx;
	}

	.row-ellipsis {
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
	}
</style>