<template>
	<view class="content">
		<!-- <u-navbar title="发布" :placeholder="true" rightText="记录" @rightClick="goToRecord" @leftClick="back()"> -->
		<!-- view class="u-nav-slot" slot="left">
				<u-icon name="arrow-left" size="19"></u-icon>
				<u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
				<u-icon name="home" size="20"></u-icon>
			</view> -->
		<!-- </u-navbar> -->
		<!-- <view class="fixed1"></view>
		<view class='title top-title flex'>
			<u-icon class="back" name="arrow-left" color="" size="20" @click="back"></u-icon>
			<view class="nav-title">发布</view>
			<view class="search" @click="goToRecord">
				<u-icon class="" name="order" color="" size="28"></u-icon>
				<view>
					记录
				</view>
			</view>
		</view> -->
		<view class="content1">
			<view class="row" @click="selectCargoOwner">

				<view class="left select-sf" :class='dataObj.cargoOwner?"":"select-sf1"'>{{dataObj.cargoOwner?dataObj.cargoOwner:'选择货主身份'}}</view>
				<view class="right"><image src="../../static/right.png" style="width: 22rpx;height: 22rpx;margin-top:14rpx;"></image></view>
			</view>
			<!-- 		<view class="row" @click="selectCargoOwner" v-if="dataObj.cargoOwner">
				<view class="left">{{dataObj.cargoOwner}}</view>
				<view class="right">></view>
			</view> -->
			<u-picker :show="show" :columns="columns" :closeOnClickOverlay='true' @close='selectCargoOwnerClose'
				@cancel='selectCargoOwnerClose' @confirm='confirmSelectCargoOwner'></u-picker>
		</view>
		<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>
				<!-- <input type="text" value="" class="input" placeholder="自动计算" v-model="dataObj.distance" disabled /> -->
				{{dataObj.distance }}
				km
			</view>
			<view class="row">
				<view class="left">货物类别</view>
				<view class="right" @click="goodstypeChange">{{dataObj.goodsType?dataObj.goodsType:"请选择货物类别"}}</view>
			</view>
			<view class="row">
				<view class="left">货名</view>
				<view class="right"><input type="text" class="input" value="" placeholder="输入货物名称"
						v-model="dataObj.goodsName" /></view>
			</view>
			<view class="row">
				<view class="left">收货方</view>
				<view class="right flex">
					<input type="text" value="" placeholder="输入收货人姓名或企业名" class="input" v-model="dataObj.receiver" />
				</view>
			</view>
			<view class="row">
				<view class="left">收货方手机号</view>
				<view class="right flex">
					<input type="number" maxlength="11" placeholder="输入收货方手机号" class="input"
						v-model="dataObj.receiverPhone" />
				</view>
			</view>
			<view class="row">
				<view style='width:120px;' class="left">收货方身份证号（选填）</view>
				<view class="right flex">
					<input type="number" maxlength="18" placeholder="输入收货人身份证号" class="input"
						v-model="dataObj.receiverIdcard" />
				</view>
			</view>
			<view class="row">
				<view  style='width:120px;' class="left">收货方信用代码（选填）</view>
				<view class="right flex">
					<input maxlength="18" placeholder="统一社会信用代码" class="input" v-model="dataObj.receiverCreditCode" />
				</view>
			</view>
			<view class="flex row">
				<view class="left-text">运费计算方式</view>
				<u-radio-group placement="row" v-model="dataObj.billingMethod" class="select-type">
					<u-radio :customStyle="radioCustomStyle" v-for="(item, index) in radiolist1" :key="index"
						:label="item.name" :name="item.name" @change="radioChange">
					</u-radio>
				</u-radio-group>
			</view>
			<view class="row">
				<view class="left">运费单价</view>
				<view class="right"><input type="number" value="" placeholder="输入运费单价" class="input"
						v-model="dataObj.freightPrice" /></view>
			</view>
			<view v-if='freightAdvance' class="row">
				<view class="left">该任务申请运费垫付</view>
				<view class="right">
					<u-switch v-model="dataObj.freightAdvance" @change="change" size="20"></u-switch>
				</view>
			</view>
		</view>
		<view class="content4 flex">
			<view class="title">以下为附加信息</view>
			<view class="btn-text">选填</view>
		</view>
		<view class="content5">
			<view class="row">
				<view class="left">发货联系人</view>
				<view class="right flex">
					<input type="text" value="" placeholder="输入发货联系人姓名" class="input" v-model="dataObj.sender" />
				</view>
			</view>
			<view class="row">
				<view class="left">发货人手机号</view>
				<view class="right flex">
					<input type="number" maxlength="11" value="" placeholder="输入发货联系人手机号" class="input"
						v-model="dataObj.senderPhone" />
				</view>
			</view>

			<view class="row">
				<view class="left">重量（吨）</view>
				<view class="right flex">
					<input type="number" value="" placeholder="输入预计发运重量" class="number" v-model="dataObj.weight"
						style="text-align: right;" />
				</view>
			</view>
			<view class="flex row" @click="selectValidityPeriod(0)">
				<view class="left-text">预计装车日期起</view>
				<view :class="!dataObj.loadingDateStart?'select-data':''">
					{{dataObj.loadingDateStart?dataObj.loadingDateStart:'选择有效截止日期>'}}
				</view>
			</view>
			<view class="flex row" @click="selectValidityPeriod(1)">
				<view class="left-text">预计装车日期止</view>
				<view :class="!dataObj.loadingDateEnd?'select-data':''">
					{{dataObj.loadingDateEnd?dataObj.loadingDateEnd:'选择有效截止日期>'}}
				</view>
			</view>
			<view class="row">
				<view class="left">车长要求（米）</view>
			</view>
			<view class="row flex-space-between row-bgc">
				<view class="car-row">
					<input type="number" value="" placeholder="最短不限" class="" v-model="dataObj.carLengthSmall"
						class="car-input" />
					<view>m</view>
				</view>

				<view class="car-line">-</view>
				<view class="car-row">
					<input type="number" value="" placeholder="最长不限" class="" v-model="dataObj.carLength"
						class="car-input" />
					<view>m</view>
				</view>

			</view>
			<view class="row">
				<view class="left">载重要求（吨）</view>
			</view>
			<view class="row flex-space-between row-bgc">
				<view class="car-row">
					<input type="number" value="" placeholder="最小不限" class="car-input"
						v-model="dataObj.loadWeightSmall" />
					<view>吨</view>
				</view>
				<view class="car-line">-</view>
				<view class="car-row">
					<input type="number" value="" placeholder="最大不限" class="car-input" v-model="dataObj.loadWeight" />
					<view>吨</view>
				</view>
			</view>
			<view class="row">
				<view class="left">车型要求</view>
			</view>
			<view class="row">
				<u-checkbox-group v-model="checkboxValue1" placement="row" @change="checkboxChange">
					<u-checkbox :customStyle="radioCustomStyle" v-for="(item, index) in checkboxList1" :key="index"
						:label="item.name" :name="item.name">
					</u-checkbox>
				</u-checkbox-group>
			</view>
			<view class="row">
				<view class="left">任务描述</view>
			</view>
			<view class="row">
				<u--textarea v-model="dataObj.taskDescription" placeholder="请输入内容" :count='true' maxlength='200'>
				</u--textarea>
			</view>


			<view class="flex row noborder" @click="selectValidityPeriodcq">
				<view class="left-text">任务有效期</view>
				<view :class="dataObj.taskValidity?'':'select-data'">
					{{dataObj.taskValidity?dataObj.taskValidity:'选择任务有效期>'}}
				</view>
			</view>
			<itmister-date-picker :overdueContent="'任务已过期'" :dateStatus="1" :periodOfValidity="true" :startYear='2022' ref="dateEl" :endDate="array" :futureYear="30" @dateConfirm="confirmValidityPeriodcq"></itmister-date-picker>
		</view>
		<view class="submit" @click="submit">立即发布</view>
		<!-- <u-picker :show="isShowValidity" ref="uPicker" :columns="validityPeriod" @confirm="confirmValidityPeriod"
			:closeOnClickOverlay='true' @close='isShowValidity=false' @cancel='isShowValidity=false'>
		</u-picker> -->
		<itmister-date-picker :dateStatus="2" :startYear='2022' ref="datezc" :futureYear="30" @dateConfirm="confirmValidityPeriod"></itmister-date-picker>
		<!-- //货物类别 -->
		<u-picker :show="isGoodsType" ref="uPicker" :columns="goodsList" keyName="constValue" @confirm="goodsSubmit"
			:closeOnClickOverlay='true' @close='isGoodsType=false' @cancel='isGoodsType=false'>
		</u-picker>
		<u-modal :show="isShowAlert" :title="alertTitle" :content='alertContent' :closeOnClickOverlay='false'
			:showCancelButton='showCancelButton' confirmColor='#2772FB' @confirm="$u.throttle(confirmClick(), 5000)" @close="cancelClick"
			@cancel="cancelClick"></u-modal>
		<u-modal :show="isShowAlert1" :title="alertTitle" :confirmText='confirmText' :content='alertContent'
			:closeOnClickOverlay='false' :showCancelButton='showCancelButton' confirmColor='#2772FB'
			@confirm="$u.throttle(confirmClick(), 5000)" @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 {
				showCancelButton: true,
				qyList: [],
				isShowAlert: false,
				alertTitle: '确定发布运输任务？',
				alertContent: null,
				radioCustomStyle: {
					margin: '0 0 0 20rpx'
				},
				show: false,
				columns: [
					[]
				],
				array:{},
				freightAdvance: false,
				dataObj: {
					commonId: '',
					cargoOwner: '',
					sendPrivate: '',
					sendCity: '',
					sendArea: '',
					sendDetailedAddress: '',
					unloadPrivate: '',
					unloadCity: '',
					unloadArea: '',
					unloadDetailedAddress: '',
					distance: '',
					goodsName: '',
					billingMethod: '元/吨',
					freightPrice: '',
					freightAdvance: false,
					sender: '',
					senderPhone: '',
					receiver: '',
					receiverPhone: '',
					weight: '',
					loadingDateStart: '',
					loadingDateEnd: '',
					carLengthSmall: '',
					carLength: '',
					loadWeightSmall: '',
					loadWeight: '',
					carModel: '',
					taskDescription: '',
					taskValidity: '',
					sendLongitude: '',
					sendLatitude: '',
					unsendLongitude: '',
					unsendLatitude: '',
				},
				confirmText: '',
				isShowAlert1: false,
				checkboxValue1: ['不限'],
				checkboxList1: [{
						name: '不限',
						disabled: false
					},
					{
						name: '高栏',
						disabled: false
					},
					{
						name: '集装箱',
						disabled: false
					},
					{
						name: '自卸车',
						disabled: false
					}
				],
				value: true,
				ValidityPeriodType: '',
				dataDetails: {
					type: '元/吨'
				},
				radiolist1: [{
						name: '元/吨',
						disabled: false
					},
					{
						name: '元/车',
						disabled: false
					},

				],
				// 货物类别
				isGoodsType:false,
				goodsList:[]
			}
		},
		onNavigationBarButtonTap(e) {
			console.log("success")
			this.goToRecord()
		},
		onShow() {
			var datetime = new Date().getTime()
			var datetime1 = datetime + (24 * 60 * 60 * 1000 * 30 * 6)
			var date=new Date(datetime1)
			this.array={year:date.getFullYear(),month:date.getMonth() + 1,day:date.getDate()}
			_this = this
			// #ifdef APP-PLUS
			// let _status = this.$request.baseRequest('get', '/cargoOwnerInfo/firstAuthentication', {
			// 	phone: this.userInfo.phone
			// }).then(res => {
			// 	uni.setStorageSync("firstAuthentication",res.data)
			// 	return res.data.authenticationStatus
			// })
			// if (_status == '已禁用') {
			// 	this.isShowAlert = true
			// 	this.alertTitle = '账号审核中'
			// 	this.confirmText = '退出APP'
			// 	this.showCancelButton = false
			// 	return
			// } else {
			// }
			// #endif
			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
				}
			})

			this.validityPeriod = this.$helper.makeValidityPeriod(0, '随时')
			let _faddress = uni.getStorageSync('storage_faddress');
			let _saddress = uni.getStorageSync('storage_saddress');
			if (_faddress) {
				this.dataObj.sendCity = _faddress.city
				this.dataObj.sendArea = _faddress.area
				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 = _saddress.city
				this.dataObj.unloadArea = _saddress.area
				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.distance = this.$helper.getDistance(this.dataObj.unsendLatitude, this.dataObj
					.unsendLongitude,
					this.dataObj.sendLatitude, this.dataObj.sendLongitude)
			}
			this.dataObj.loadingDateStart = '随时'
			this.dataObj.loadingDateEnd = '随时'
			this.dataObj.taskValidity = '长期'
			this.getSFList()
			
		},
		async onLoad() {
			//货物类别(默认上一次)
			this.queryGoodsList() // 查询货物类别
			let goods = uni.getStorageSync("goodsType")
			if(goods){
				this.dataObj.goodsType = goods.name
				this.dataObj.goodsTypeKey = goods.key
			}
			

			// _this = this
			// // #ifdef APP-PLUS
			// let _status = await this.$request.baseRequest('get', '/cargoOwnerInfo/firstAuthentication', {
			// 	phone: this.userInfo.phone,
			// }).then(res => {
			// 	if(res.data){
			// 		return res.data.authenticationStatus
			// 	}

			// })
			// if (_status == '已禁用') {
			// 	this.isShowAlert = true
			// 	this.alertTitle = '账号审核中'
			// 	this.confirmText = '退出APP'
			// 	this.showCancelButton = false
			// 	return
			// } else {}
			// // #endif

		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			queryGoodsList(){
				this.$request.baseRequest('get', '/commonSysParameter/getInfo', {
						constId: "CON1"
					}).then(res => {
						this.goodsList.push(res.data)
						console.log(this.goodsList)
					})
			},
			goodstypeChange(){
				this.isGoodsType = true
			},
			goodsSubmit(e){
				this.dataObj.goodsType = e.value[0].constValue
				this.dataObj.goodsTypeKey = e.value[0].constKey
				let _obj={
					name:e.value[0].constValue,
					key:e.value[0].constKey
				}
				uni.setStorageSync("goodsType",_obj)
				this.isGoodsType = false
			},
			getSFList() {
				this.dataObj.commonId = this.userInfo.id
				this.$request.baseRequest('get', '/cargoOwnerCompInfo/cargoOwnerList', {
						commonId: this.userInfo.id
					}).then(res => {
						if (uni.getStorageSync('releaseCargoOwner')) {
							this.dataObj.cargoOwner = uni.getStorageSync('releaseCargoOwner')
							this.dataObj.compId =uni.getStorageSync('releasecompId')
							
						}
						// 可用企业货主
						this.qyList = []
						// 自己法人
						// let _self = res.data.companyInfoList
						let _self = res.data.hyCompanyInfoList
						//代理货主
						// let _dlhz = res.data.cargoOwnerCompInfoList
						let _dlhz = res.data.hyCargoOwnerCompInfoList
						if (!_dlhz) _dlhz = []
						if (!_self) _self = []
						if (_self.length > 0) {
							for (let i = 0; i < _self.length; i++) {
								_self[i].compStatus='wd'
								if (_self[i].status == '已认证') {
									this.qyList.push(_self[i])
								}
							}
						}
						if (_dlhz.length > 0) {
							for (let i = 0; i < _dlhz.length; i++) {
								_dlhz[i].compStatus='ss'
								if (_dlhz[i].status == '已认证') {
									this.qyList.push(_dlhz[i])
								}
							}
						}
						this.columns = [
							[]
						]
						let obj = uni.getStorageSync("firstAuthentication")
						if (obj && obj.authenticationStatus == '已认证') {
							this.columns[0].push("个人货主")
						}
						for (let i = 0; i < this.qyList.length; i++) {
							this.columns[0].push(this.qyList[i].company ? this.qyList[i].company : this.qyList[i]
								.companyName)
						}
						this.$forceUpdate()
					})
					.catch(res => {});


			},
			validate() {
				if (uni.$u.test.isEmpty(this.dataObj.cargoOwner)) {
					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.goodsType)) {
					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.chinese(this.dataObj.goodsName)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "货名输入错误！",
					})
					return true
				}
				console.log(this.dataObj.receiver,"收货方")
				console.log(this.dataObj.receiverPhone,"收货方手机号")
				if (uni.$u.test.isEmpty(this.dataObj.receiver)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "收货方不能为空！",
					})
					return true
				}
				if (uni.$u.test.isEmpty(this.dataObj.receiverPhone)) {
					this.$refs.uToast.show({
						type: 'error',
						message: "收货方手机号不能为空！",
					})
					return true
				}

				// if (uni.$u.test.isEmpty(this.dataObj.receiverIdcard)) {
				// 	this.$refs.uToast.show({
				// 		type: 'error',
				// 		message: "收货人身份证不能为空！",
				// 	})
				// 	return true
				// }
				if (!this.dataObj.receiverIdcard && !this.dataObj.receiverCreditCode) {
					this.$refs.uToast.show({
						type: 'error',
						message: "信用代码和身份证号码至少填写一个！",
						duration:2000
					})
					return true
				}
				// if(this.dataObj.receiverIdcard&&!uni.$u.test.rangeLength(this.dataObj.receiverIdcard, [18, 18])){
				// 	this.$refs.uToast.show({
				// 		type: 'error',
				// 		message: "身份证号输入错误！",
				// 	})
				// 	return true
				// }
				if(this.dataObj.receiverIdcard&&this.dataObj.receiverIdcard.length!=18){
					this.$refs.uToast.show({
							type: 'error',
							message: "身份证号输入错误！",
						})
						return true
				}
				if(this.dataObj.receiverCreditCode&&this.dataObj.receiverCreditCode.length!=18){
					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 (this.dataObj.weight) {
					if (
						this.dataObj.weight < 0.1 || this.dataObj.weight > 10000000 || (
							String(this.dataObj.weight).indexOf('.') != -1 && String(tthis.dataObj.weight).length -
							(String(this.dataObj.weight).indexOf(
								'.') + 1) > 2)
					) {
						uni.showToast({
							title: '重量输入错误！',
							duration: 2000,
							icon: "none",
						});
						return true
					}
				}
				if (this.dataObj.carLengthSmall) {
					if (this.dataObj.carLengthSmall < 2 || this.dataObj.carLengthSmall > 30) {
						uni.showToast({
							title: '最小车长输入错误！',
							duration: 2000,
							icon: "none",
						});
						return true
					}
				}
				if (this.dataObj.carLength) {
					if (this.dataObj.carLength < 2 || this.dataObj.carLength > 30) {
						uni.showToast({
							title: '最大车长输入错误！',
							duration: 2000,
							icon: "none",
						});
						return true
					}
				}
				if (this.dataObj.carLengthSmall && this.dataObj.carLength && (Number(this.dataObj.carLengthSmall) > Number(
						this.dataObj
						.carLength))) {
					uni.showToast({
						title: '最小车长应小于最大车长！',
						duration: 2000,
						icon: "none",
					});
					return true
				}

				if (this.dataObj.loadWeightSmall) {
					if (
						this.dataObj.loadWeightSmall < 0.1 || this.dataObj.loadWeightSmall > 100 || (
							String(this.dataObj.loadWeightSmall).indexOf('.') != -1 && String(tthis.dataObj
								.loadWeightSmall).length -
							(String(this.dataObj.loadWeightSmall).indexOf(
								'.') + 1) > 3)
					) {
						uni.showToast({
							title: '载量输入错误！',
							duration: 2000,
							icon: "none",
						});
						return true
					}
				}
				if (this.dataObj.loadWeight) {
					if (
						this.dataObj.loadWeight < 0.1 || this.dataObj.loadWeight > 100 || (
							String(this.dataObj.loadWeight).indexOf('.') != -1 && String(tthis.dataObj.loadWeight).length -
							(String(this.dataObj.loadWeight).indexOf(
								'.') + 1) > 3)
					) {
						uni.showToast({
							title: '载量输入错误！',
							duration: 2000,
							icon: "none",
						});
						return true
					}
				}
				if (this.dataObj.loadWeightSmall && this.dataObj.loadWeight && (Number(this.dataObj.loadWeightSmall) >
						Number(this.dataObj
							.loadWeight))) {
					uni.showToast({
						title: '最小载重应小于最大载重！',
						duration: 2000,
						icon: "none",
					});
					return true
				}
			},
			confirmClick() {
				uni.$u.throttle(this.requestdata, 500)
			},
			requestdata(){
				console.log(this.dataObj)
				// // #ifdef APP-PLUS
				// if (this.alertTitle == '账号审核中') {
				// 	if (uni.getSystemInfoSync().platform == 'ios') {
				// 		plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
				// 	} else if (uni.getSystemInfoSync().platform == 'android') {
				// 		plus.runtime.quit();
				// 	}
				// 	return
				// }
				// // #endif
				
				// if (this.alertTitle == '身份信息未认证，去认证?') {
				// 	uni.switchTab({
				// 		url: '/pages/mine/index'
				// 	})
				// 	return
				// }
				// this.isShowAlert = false
				
				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=''
				}
				let _list = []
				for (let i = 0; i < this.checkboxValue1.length; i++) {
					if (this.checkboxValue1[i] == '不限') {
						_list.push(1)
					} else if (this.checkboxValue1[i] == '高栏') {
						_list.push(2)
					} else if (this.checkboxValue1[i] == '集装箱') {
						_list.push(3)
					} else if (this.checkboxValue1[i] == '自卸车') {
						_list.push(4)
					}
				}
				this.dataObj.carModel = _list.toString()
				this.dataObj.commonId = this.userInfo.id
				this.$request.baseRequest('post', '/publishTaskInfo/api/addTask', this.dataObj).then(res => {
						uni.removeStorage({
							key: 'storage_saddress'
						});
						uni.removeStorage({
							key: 'storage_faddress'
						});
						uni.removeStorage({
							key: 'releaseCargoOwner'
						});
						uni.removeStorage({
							key: 'releasecompId'
						});
						this.$refs.uToast.show({
							type: 'success',
							message: "发布成功",
							complete() {
								_this.dataObj = {
									commonId: '',
									cargoOwner: '',
									sendPrivate: '',
									sendCity: '',
									sendArea: '',
									sendDetailedAddress: '',
									unloadPrivate: '',
									unloadCity: '',
									unloadArea: '',
									unloadDetailedAddress: '',
									distance: '',
									goodsName: '',
									billingMethod: '元/吨',
									freightPrice: '',
									freightAdvance: true,
									sender: '',
									senderPhone: '',
									receiver: '',
									receiverPhone: '',
									weight: '',
									loadingDateStart: '',
									loadingDateEnd: '',
									carLengthSmall: '',
									carLength: '',
									loadWeightSmall: '',
									loadWeight: '',
									carModel: '',
									taskDescription: '',
									taskValidity: '',
									sendLongitude: '',
									receiverIdcard:'',
									sendLatitude: '',
									receiverCreditCode:'',
									unsendLongitude: '',
									unsendLatitude: '',
								}
								_this.checkboxValue1 = ['不限']
								// uni.$u.route("/pages/release/record")
							}
						})
						this.isShowAlert = false
				
					})
					.catch(res => {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						})
					});
			},
			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.distance = 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

				// if (columnIndex === 0) {
				// 	
				// 	if (e.index != 0) {
				// 		picker.setColumnValues(1, this.validityPeriod[1].shift())
				// 	}

				// } else if (columnIndex === 1) {
				// 	if (e.index != 0) {
				// 		picker.setColumnValues(2, this.validityPeriod[2].shift())
				// 	}
				// }
			},
			selectCargoOwnerClose() {
				this.show = false
			},
			confirmSelectCargoOwner(e) {
				this.dataObj.cargoOwner = e.value[0]
				for (let i = 0; i < this.qyList.length; i++) {
					let _name = this.qyList[i].company ? this.qyList[i].company : this.qyList[i].companyName
					if (_name == e.value[0]) {
						if(e.value[0]!='个人货主'){
							this.freightAdvance=true
							if(this.qyList[i].compStatus=='ss'){
								this.dataObj.compId=this.qyList[i].compId
							}else{
								this.dataObj.compId=this.qyList[i].id
							}
							// console.log(this.qyList[i].compStatus,this.dataObj.compId)
							uni.setStorageSync('releasecompId', this.dataObj.compId)
						}else{
							this.freightAdvance=false
						}
						this.freightAdvance= this.qyList[i].advanceFreightService == 1 ? true : false
						this.dataObj.freightAdvance = this.qyList[i].advanceFreightService == 1 ? true : false
					}
				}
				
				uni.setStorageSync('releaseCargoOwner', this.dataObj.cargoOwner)
				this.show = false
			},
			selectCargoOwner() {
				this.show = true
			},
			selectAddress(type) {
				// uni.removeStorage({
				// 	key: 'storage_faddress'
				// });
				// uni.removeStorage({
				// 	key: 'storage_saddress'
				// });
				uni.$u.route('/pages/release/selectAddress', {
					type: type,
				});
			},
			checkboxChange(n) {
				if (n.length > 1 && n.length < 4 && n.includes('不限')) {
					n.shift(0)
				} else if (n.length == 4) {
					this.checkboxValue1 = n.splice(1, 4)
				}
			},
			selectValidityPeriodcq() {
				this.$refs.dateEl.show();
			},
			confirmValidityPeriod(date) {
			
			switch (this.ValidityPeriodType) {
				case 0:
					this.dataObj.loadingDateStart = date.date
					break
				case 1:
					this.dataObj.loadingDateEnd =date.date
					break
			}
			},
			getTime: function() {

				var date = new Date().getTime()
				year = date.getFullYear(),
					month = date.getMonth() + 1,
					day = date.getDate(),

					month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				var timer = year + '-' + month + '-' + day
				return timer;
			},
			confirmValidityPeriodcq(date) {
				this.dataObj.taskValidity=date.date
			},
			selectValidityPeriod(type) {
				this.ValidityPeriodType = type
				this.$refs.datezc.show()
				// this.isShowValidity = true
			},
			change(e) {
				console.log('change', e);
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			goToRecord() {
				uni.$u.route('/pages/release/record');
			},
			radioChange(n) {
				console.log(n)
				this.dataDetails.type = n
			},
			submit() {
				if (this.validate()) return
				if (this.dataObj.cargoOwner == '个人货主') {
					this.dataObj.compId = ""
					this.dataObj.freightAdvance = 0
				} else {
					for (let i = 0; i < this.qyList.length; i++) {
						if (this.dataObj.cargoOwner == this.qyList[i].companyName) {
							this.dataObj.compId = this.qyList[i].id
							break
						}
					}
				}
				this.isShowAlert = true;
			},
		}
	}
</script>

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

	.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;
			}
		}
	}

	.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;
		}

		.collect {
			width: 40rpx;
			height: 40rpx;
			line-height: 40rpx;
			background: #2772FB;
			color: white;
			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 {}

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

		.title {
			color: #999999;
		}

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

	.submit {
		width: 90%;
		margin: 100rpx auto;
		font-size: 36rpx;
		font-weight: 500;
		color: #FFFFFF;
		background: #2772FB;
		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;
	}
</style>
