<template>
	<view>
		<view class="order">
			<view class="example">
				<u-form labelPosition="left" :model="parentOrderForm" :rules="rules" ref="form1" labelWidth='120'>
					<u-form-item :label="$t('order.companyName')" borderBottom prop="companyId"
						@click="showPopup('popupCompanyId')">
						<span>{{parentOrderForm.companyName}}</span>
						<view v-if="paymentOption && paymentOption.isShow=='1'"
									style="color: darkgreen;font-size: 9pt;">
									{{paymentOption.usableTotal}}
						</view>
						<!-- <u-input readonly v-model="parentOrderForm.companyName" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.companyName')">
							<template slot="suffix">
								<view v-if="paymentOption && paymentOption.isShow=='1'"
									style="color: darkgreen;font-size: 9pt;">
									{{paymentOption.total}}
								</view>
							</template>
						</u-input> -->
					</u-form-item>
					<view v-if="paymentOption && paymentOption.isShow=='1'"
										style="display: flex;flex-direction:justify-content:flex-end;flex-direction: column;
					text-align: end;">
										<view style="color: red;font-size: 9pt;">
											{{$t('order.allTotal')}}:{{paymentOption.total}}
										</view>
										<view style="color: red;font-size: 9pt;">
											{{$t('order.waitTotal')}}:{{paymentOption.waitTotal}}
										</view>
										<view style="color: red;font-size: 9pt;">
											{{$t('order.source')}}:{{paymentOption.companyName}}
										</view>
									</view>
					<view v-if="paymentOption && paymentOption.isShow=='1' && paymentOption.agentResponsible=='1'"
						style="display: flex;flex-direction: row-reverse;">
						<view style="color: red;font-size: 9pt;">{{$t('order.source')}}:{{paymentOption.companyName}}
						</view>
					</view>

					<!-- 下单日期 -->
					<u-form-item :label="$t('order.orderDate')" borderBottom prop="setDate">
						<u-input readonly v-model="parentOrderForm.setDate" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.orderDate')" />
					</u-form-item>
				<!-- <u-form-item :label="$t('order.vehicleType')" borderBottom prop="vehicleType">
					<u-radio-group v-model="parentOrderForm.vehicleType" @change="onVehicleTypeConfirm" placement="row"
						class="p-input">
						<u-radio :customStyle="{marginRight: '10px'}" v-for="item in vehicleTypeOption"
							:key="item.value" :label="item.text" :name="item.value">
						</u-radio>
					</u-radio-group>
				</u-form-item> -->
				<u-form-item :label="$t('order.vehicleType')" borderBottom prop="vehicleType">
					<view class="uni-list">
								<radio-group v-model="parentOrderForm.vehicleType" @change="onVehicleTypeConfirm" placement="row">
									<label class="uni-list-cell uni-list-cell-pd" v-for="item in vehicleTypeOption" :key="item.value" >
										<view>
											<radio style="transform:scale(0.8)" :value="item.value" :checked="item.value === parentOrderForm.vehicleType"/>{{item.text}}
										</view>
									</label>
								</radio-group>
					</view>
				</u-form-item>
					<u-form-item  v-if="parentOrderForm.vehicleType=='101'"
					:label="$t('order.salePoint')" borderBottom prop="projuctId"
					>
						<!-- <u-input readonly v-model="parentOrderForm.projectName" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.projuctName')" /> -->
							<span>{{parentOrderForm.saleBlockName}}</span>
					</u-form-item>
					<!-- <u-form-item  v-if="parentOrderForm.vehicleType=='102'"
					:label="$t('order.mine')" borderBottom prop="mineId"
						@click="showPopup('mineId')">
						<u-input readonly v-model="parentOrderForm.projectName" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.projuctName')" />
							<span>{{parentOrderForm.mineName}}</span>
					</u-form-item> -->
					<u-form-item 
					:label="$t('order.transportType')" borderBottom prop="transporterType"
						@click="showPopup('popupTransporterTypeId')">
						<!-- <u-input readonly v-model="parentOrderForm.transporterTypeName" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.transportType')" /> -->
							<span>{{parentOrderForm.transporterTypeName}}</span>
					</u-form-item>
					<u-form-item  :label="$t('order.transporter')" borderBottom
						prop="transporterId" @click="showPopup('popupTransporterId')">
						<!-- <u-input readonly v-model="parentOrderForm.transporterName" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.transporter')" /> -->
							<span>{{parentOrderForm.transporterName}}</span>
					</u-form-item>
					<!-- 备注 -->
					<u-form-item :label="$t('order.remarks')" borderBottom prop="remarks">
						<u-input v-model="parentOrderForm.remark" border="none"
							:placeholder="$t('base.common.placeholderI')+$t('order.remarks')" />
					</u-form-item>

				</u-form>
				<view style="margin: margin: 10px 0px 0px 0px;">
					<button @click="onAddOrderClick">{{$t('base.button.caradd')}}
					</button>
				</view>
			</view>

			<!-- 下单日期 -->
			<u-calendar color="#4680F9" round='25' :show="showSetDateCalendar" @confirm="onSetDateConfirm"
				@close="showSetDateCalendar=false"></u-calendar>

			<PopupSelect ref="popupCompanyId" :hasSearch='false' :option="companyOption"
				@onConfirm="onCompanyConfirm" />
			<PopupSelect ref="mineId" :hasSearch='false' :option="companyMineOption"
				@onConfirm="onCompanyMineConfirm" />
			<PopupSelect ref="popupTransporterId" :hasSearch='false' :option="transporterOption"
				@onConfirm="onTransporterConfirm" />
			<PopupSelect ref="popupTransporterTypeId" kind="m" value="102" :hasSearch='false' :option="transporterTypeOption"
				@onConfirm="onTransporterTypeConfirm" />
			<!-- <PopupSelect ref="popupprojectId" :hasSearch='false' :option="companyProductOption"
				@onConfirm="onCompanyProductConfirm" /> -->

				

		</view>
		<view class="item-order">
			<template v-if="batchOrderList.length">
				<u-list @scrolltolower="scrolltolower" :preLoadScreen="1.5">
					<u-list-item v-for="(item, index) in batchOrderList" :key="index">
						<view class="order-card">
							<view class="order-card-title">

								<span class="type">{{ item.companyName }}</span>
							</view>
							<view class="order-card-info">
								<view class="row">
									<p class="cell">
										<text class="info">{{ item.setDate || '' }}</text>
									</p>
									<p class="cell">
										<text class="info"
											v-if="item.vehicleType == '101'">{{ $t('order.saleOrder') }}</text>
										<text class="info"
											v-if="item.vehicleType == '102'">{{ $t('order.purchaseOrder') }}</text>

									</p>
								</view>
								<view class="row">
									<p class="cell">
										<text class="info">{{ item.materialName || '' }}</text>

										<text class="info hint">
											[{{item.addNumber}}{{ $t('customer_meter.unitN') }}]</text>

									</p>

								</view>
								<view class="row">
									<p class="cell">
										<text
											class="info">{{ item.vehicle || '无车号' }}-{{item.transporterTypeName}}</text>
									</p>
									<p class="cell">
										<text
											:style="'font-size: 9pt;font-weight: bold;'+(item.companyClientType=='109'?'color: green;':'color: red;')"
											class="info">{{ item.orderNumber || '' }}{{$t('customer_meter.unitT') }}</text>
									</p>

								</view>
							</view>
							<view class="order-card-bottom">
								<view class="btn">
									<button class="oper-btn" type='error' shape="circle" size="small"
										@click="onUpdateOrderClick(item,index)">{{ $t('base.button.update') }}
									</button>
								</view>
								<view class="btn" v-if="item.orderStatus!=4">
									<button class="oper-btn" type='primary' shape="circle" color='#4680F9' size="small"
										@click="onDeleteOrderClick(item,index)">
										{{ $t('base.button.delete') }}
									</button>
								</view>
							</view>
						</view>
					</u-list-item>
				</u-list>
			</template>
			<template v-else>
				<u-empty mode="orderTypeList" icon="https://cdn.uviewui.com/uview/empty/list.png">
				</u-empty>
			</template>
			<view class="bottom-content">
				<button class="bind-btn"
					@click="submit()">{{$t("base.common.submit")}}{{batchOrderList.length?` (${batchOrderList.length}) `:''}}</button>
			</view>
			<u-toast ref="loadingToast"></u-toast>
			<!-- 下单日期 -->
			<u-calendar color="#4680F9" round='25' :show="showSetDateCalendar" @confirm="onSetDateConfirm"
				@close="showSetDateCalendar=false"></u-calendar>
		</view>

		<u-modal :show="showAdd" @confirm="onSaveOrderCokck" ref="addModal" showCancelButton closeOnClickOverlay
			@cancel="showAdd = false" @close="showAdd = false" stlye="z-index:-1"  :cancelText="$t('settings.cancelText')"
      :confirmText="$t('settings.confirmText')">
			<view class="invite-box">
				<u-form labelPosition="left" :model="orderForm" ref="form1" labelWidth='100'>
					<u-form-item :label="$t('order.materialName')" borderBottom prop="materialId"
						@click="selectMater(index)">
						<!-- <u-input readonly v-model="orderForm.materialName" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.materialName')" /> -->
							<span>{{orderForm.materialName}}</span>
					</u-form-item>
					<!-- 订单数量 -->
					<u-form-item v-if="parentOrderForm.vehicleType != '102'" :label="$t('order.orderNumber')" borderBottom prop="orderNumber">
						<u--input v-model="orderForm.orderNumber" border="none" type='number'
							:placeholder="$t('base.common.placeholderI')+$t('order.orderNumber')"
							@focus="onOrderNumberFocus"></u--input>
					</u-form-item>
					<u-form-item :label="$t('order.vehicleNumber')" borderBottom prop="vehicleNumber">
						<u--input v-model="orderForm.addNumber" border="none" type='number'
							:placeholder="$t('base.common.placeholderI')+$t('order.vehicleNumber')"></u--input>
					</u-form-item>
					<u-form-item :label="$t('order.vehicle')" borderBottom prop="vehicle"
						@click="toSelectVehicle(index)">
						<!-- <u--input readonly v-model="orderForm.vehicle" border="none"
							:placeholder="$t('base.common.placeholderS')+$t('order.vehicle')"></u--input> -->
							<span>{{orderForm.vehicle}}</span>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item :label="$t('order.idcard')" borderBottom prop="idcard">
							<span>{{orderForm.idcard}}</span>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
				</u-form>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import PopupSelect from '../../components/popup-select/index'
	import dayjs from 'dayjs'
	import CarKeyboard from '../../components/carKeyboard/carKeyboard'
	import {
		getTenantCacheList
	} from '../../utils/util.js'

	import {
		orderBatchInsert,
		getOption,
		getMaterialsByCompany,
		getSalesMaterByCompany,
		getSalePointByCompany
	} from '../../api/order'
	export default {
		components: {
			CarKeyboard,
			PopupSelect
		},
		data() {
			return {
				showAdd: false,
				start: dayjs().format('YYYY-MM-DD'),
				batchOrderList: [],
				orderForm: {
					setDate: dayjs().format('YYYY-MM-DD'), //订单日期
					expirationDate: dayjs().add(30, 'day').format('YYYY-MM-DD'), //有效日期
					tenantId: '', //企业
					orderType: '1', //订单类型
					companyId: '', //客商
					addNumber: '1',
					orderNumber: "0", //数量
					materialId: "", //物料
					vehicle: '', //车号
					idcard:"",//身份证号
					vehicleType: '101',
					transporterType: '101',
					transporterTypeName: this.$t('base.common.selftrans'),
					tenantName: '',
					companyName: "", //客商
					materialName: "", //物料id
					transporterId: "",
					transporterName: "",
					projectId: "",
					mineId:"",
				},
				parentOrderForm: {
					setDate: dayjs().format('YYYY-MM-DD'), //订单日期
					expirationDate: dayjs().add(30, 'day').format('YYYY-MM-DD'), //有效日期
					tenantId: '', //企业
					orderType: '1', //订单类型
					companyId: '', //客商
					materialId: "", //物料
					orderNumber: "0", //数量
					vehicleType: '101',
					transporterType: '102',
					transporterTypeName: this.$t('base.common.selftrans'),
					tenantName: '',
					companyName: "", //客商
					materialName: "", //物料id
					transporterId: "",
					transporterName: "",
					// projectId: "",
					// projectName: "",
					saleBlockId:"",
					saleBlockName:"",
				},
				rules: {
					phone: [{
						required: true,
						message: this.$t('base.common.placeholderI') + this.$t('order.phone')
					}],
					transporterType: [{
						required: true,
						message: this.$t('base.common.placeholderS') + this.$t('order.transporterType')
					}],
					tenantId: [{
						required: true,
						message: this.$t('base.common.placeholderS') + this.$t('order.enterprise')
					}],
					companyId: [{
						required: true,
						message: this.$t('base.common.placeholderS') + this.$t('order.companyName')
					}],
					materialId: [{
						required: true,
						message: this.$t('base.common.placeholderS') + this.$t('order.materialName')
					}],
				},
				vehicleTypeOption: [{
					text: this.$t('base.common.noData'),
					value: null
				}, ],

				//产品选项
				materialOption: [{
					text: this.$t('base.common.noData'),
					value: null
				}],
				//客户选项
				companyOption: [{
					text: this.$t('base.common.noData'),
					compvalueanyId: null
				}],
				transporterOption: [{
					text: this.$t('base.common.noData'),
					compvalueanyId: null
				}],
				transporterTypeOption: [{
					value:"101",
					text: this.$t('base.common.selftrans')
				},
				{
					value:"102",
					text: this.$t('base.common.distribution')
				},
				
				// {
				// 	text: this.$t('base.common.noData'),
				// 	value: null,
				// },
				], //物料选项
				//供应商选项
				tenantOption: [{
					text: this.$t('base.common.noData'),
					value: null
				}], //企业选项
				showSetDateCalendar: false,
				showEndDateCalendar: false,
				defaultEndDate: new Date(dayjs().add(30, 'day').format('YYYY-MM-DD')), //默认有效日期
				//业务对应的客户信息
				vehicleTypeCompanyList: [],
				//客户对应的物料信息
				companyMaterialList: [],
				paymentOption: {},
				currentOrderIndex: -1,
				//参数
				appParameters: {},
				companyProductOption:[
					{
					text: this.$t('base.common.noData'),
					value: null
					},
				],
				companyMineOption:[
					{
					text: this.$t('base.common.noData'),
					value: null
					},
				],
				language:'zh-Hans'
			}
		},
		onLoad(options) {
			this.bindTenant()
			this.language = uni.getStorageSync('CURRENT_LANG')
		},
		methods: {
			onOrderNumberFocus() {
				if (this.orderForm.orderNumber == 0) {
					this.orderForm.orderNumber = null
				}
			},
			onUpdateOrderClick(item, index) {
				this.currentOrderIndex = index
				this.orderForm = Object.assign({}, this.batchOrderList[index])
				this.showAdd = true
			},
			onDeleteOrderClick(item, index) {
				this.batchOrderList.splice(index, 1)
			},
			//去选择司机
			toSelectVehicle(index) {
				this.index = index;
				uni.navigateTo({
					url: '/subpages/order/vehicle'
				})
			},
			//选择订单类型
			onVehicleTypeConfirm(value) {
				console.log(value)
				this.parentOrderForm.vehicleType = value.detail.value
				this.clear(false)
				this.bindCompany();
				this.bindMaterial();
			},
			//选择品种
			selectMater(index) {
				uni.navigateTo({
					url: `/subpages/order/materSelect?option=${JSON.stringify(this.materialOption)}`
				})
			},
			onAddOrderClick() {
				if (!this.parentOrderForm.companyId) {
					uni.showToast({
						title: this.$t("base.common.placeholderS")+this.$t("order.companyName"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				Object.keys(this.orderForm).forEach(key => (this.orderForm[key] = ""));
				this.orderForm.vehicleType = this.parentOrderForm.vehicleType
				this.orderForm.addNumber = '1'
				this.orderForm.orderNumber = "0" //数量
				this.showAdd = true
			},
			onSaveOrderCokck() {
				if (!this.orderForm.addNumber || parseInt(this.orderForm.addNumber) == 0) {
					uni.showToast({
						title: this.$t("order.addNotNumber"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				if (this.parentOrderForm.vehicleType !='102' && (!this.orderForm.orderNumber || parseInt(this.orderForm.orderNumber) == 0)) {
					uni.showToast({
						title: this.$t("order.orderNotNumber"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				if (!this.orderForm.materialId) {
					uni.showToast({
						title: this.$t("order.notMaterialName"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				if (!this.orderForm.vehicle) {
					uni.showToast({
						title: this.$t("order.notVehicle"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				var isCheckVehicle = true
				if (this.appParameters &&
					this.parentOrderForm.transporterType &&
					this.appParameters.VEHICLE_ALLOW_EMPTY_TRANSPORTER_TYPE &&
					this.appParameters.VEHICLE_ALLOW_EMPTY_TRANSPORTER_TYPE.indexOf(this.parentOrderForm.transporterType) >
					-1) {
					isCheckVehicle = false
				}
				if (!this.orderForm.vehicle && isCheckVehicle == true) {
					uni.showToast({
						title: this.$t("order.notVehicle"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				let newOrderInfo = Object.assign({}, this.orderForm);
				newOrderInfo.setDate = this.parentOrderForm.setDate
				newOrderInfo.remark = this.parentOrderForm.remark
				newOrderInfo.tenantId = this.parentOrderForm.tenantId
				newOrderInfo.companyId = this.parentOrderForm.companyId
				newOrderInfo.companyName = this.parentOrderForm.companyName
				newOrderInfo.transporterType = this.parentOrderForm.transporterType
				newOrderInfo.transporterTypeName = this.parentOrderForm.transporterTypeName
				newOrderInfo.transporterId = this.parentOrderForm.transporterId
				newOrderInfo.transporterName = this.parentOrderForm.transporterName
				newOrderInfo.projectId = this.parentOrderForm.projectId
				newOrderInfo.mineId = this.parentOrderForm.mineId
				newOrderInfo.remark = this.parentOrderForm.remark
				if (this.currentOrderIndex > -1) {
					this.batchOrderList[this.currentOrderIndex].addNumber = newOrderInfo.addNumber
					this.batchOrderList[this.currentOrderIndex].orderNumber = newOrderInfo.orderNumber
					this.batchOrderList[this.currentOrderIndex].vehicle = newOrderInfo.vehicle
					this.batchOrderList[this.currentOrderIndex].materialId = newOrderInfo.materialId
					this.currentOrderIndex = -1
				} else {
					this.batchOrderList.push(newOrderInfo)
				}
				this.showAdd = false
			},
			//选择订单类型后加载选项 //获取品种信息 101:销售，102：采购
			bindOption() {
				this.clear(true);
				console.log("订单租户信息、", this.parentOrderForm.tenantId);
				if (!this.parentOrderForm.tenantId) {
					console.log("订单业务租户信息");
					return;
				}
				var that = this;
				console.log("当前租户ID、", that.parentOrderForm.tenantId);
				if (that.parentOrderForm.tenantId) {
					let data = JSON.parse(JSON.stringify(that.parentOrderForm))
					getOption(data).then(res => {
						console.log("查询基础数据返回、", res);
						if (res.statusCode === 200) {
							console.log("用户业务类型、", res.data.data.appVehicleType)
							console.log("用户客户信息、", res.data.data.appCompany)
							console.log("用户品种信息、", res.data.data.appMaterial)
							if(that.language == 'zh-Hans'){
								that.vehicleTypeOption = res.data.data.appVehicleType;
							}else{
								that.vehicleTypeOption = res.data.data.appVehicleType.map(item=>{
									return{
										text:item.language,
										value:item.value
									}
								});
							}
							if (that.vehicleTypeOption && that.vehicleTypeOption.length > 0) {
								that.parentOrderForm.vehicleType = that.vehicleTypeOption[0].value
								that.appParameters = res.data.data.appParameters
								that.vehicleTypeCompanyList = res.data.data.appCompany
								that.bindCompany();
								
								// if (that.parentOrderForm.vehicleType == "101") {
								// 	that.transporterTypeOption = res.data.data.appTransportTypeList
								// 	if (that.transporterTypeOption && that.transporterTypeOption.length > 0) {
								// 		that.parentOrderForm.transporterType = that.transporterTypeOption[0].value
								// 		that.parentOrderForm.transporterTypeName = that.transporterTypeOption[0]
								// 			.text
								// 	}
								// }
							}
						}
					})
				}
			},
			//获取销售区域
			bindProject(){
				this.parentOrderForm.saleBlockId = ''
				this.parentOrderForm.saleBlockName = ''
				if (this.parentOrderForm.vehicleType != '102'){
					getSalePointByCompany(this.parentOrderForm.companyId).then(res=>{
						if (res.statusCode === 200) {
							this.parentOrderForm.saleBlockId = res.data.data.id
							this.parentOrderForm.saleBlockName = res.data.data.name
						}
					})
				}
			},
			bindCompany() {
				var vehicleType = this.parentOrderForm.vehicleType;
				if (vehicleType && this.vehicleTypeCompanyList) {
					this.companyOption = [{
						text: this.$t('order.notSelected'),
						value: null
					}] //物料选项
					var companyInfos = this.vehicleTypeCompanyList.filter(function(company) {
						return company.vehicleType == vehicleType;
					});
					if (companyInfos && companyInfos.length > 0) {
						companyInfos[0].companyList.forEach(item => {
							this.companyOption.push({
								text: item.companyName,
								value: item.companyId
							})
						})
						this.parentOrderForm.companyId = this.companyOption[1].value
						this.parentOrderForm.companyName = this.companyOption[1].text
						this.bindProject()
						this.bindMaterial();
					}
					console.log("客户信息、", this.companyOption);
				}
			},

			bindMaterial() {
				var companyId = this.parentOrderForm.companyId;
				this.paymentOption = {}
				if (companyId) {
					if(this.parentOrderForm.vehicleType == '101'){
						getSalesMaterByCompany(this.parentOrderForm).then(res => {
							if (res.data.code == 0) {
								this.paymentOption = res.data.hardInfo
								if (res.data.companyList) {
									res.data.companyList.forEach(item => {
										this.transporterOption.push({
											text: item.name,
											value: item.id
										})
									})
								}
								var materialInfos = res.data.data;
								if (materialInfos && materialInfos.length > 0) {
									this.materialOption = materialInfos.map(item => {
										return ({
											text: item.name,
											value: item.id,
											type: item.materTypeName ? item.materTypeName : '暂无分类',
										})
									})
								}
								var companyProductList=res.data.companyProductList;
								console.log("1111213213", companyProductList);
								if (companyProductList && companyProductList.length > 0) {
									this.companyProductOption = companyProductList.map(item => {
										return ({
											text: item.productName,
											value: item.id
										})
									})
									this.parentOrderForm.projectId = this.companyProductOption[0].value
									this.parentOrderForm.projectName = this.companyProductOption[0].text
								}else{
									this.companyProductOption = [{
										text: this.$t('base.common.noData'),
										value: null
									}] //项目选项
									this.parentOrderForm.projectId = ''
									this.parentOrderForm.projectName = ''
								}

								var companyMineList=res.data.companyMineList;
								if (companyMineList && companyMineList.length > 0) {
									this.companyMineOption = companyMineList.map(item => {
										return ({
											text: item.mineName,
											value: item.id
										})
									})
									this.parentOrderForm.mineId = this.companyMineOption[0].value
									this.parentOrderForm.mineName = this.companyMineOption[0].text
								}else{
									this.companyMineOption = [{
										text: this.$t('base.common.noData'),
										value: null
									}] //项目选项
									this.parentOrderForm.mineId = ''
									this.parentOrderForm.mineName = ''
								}

								
							}
						})
					}else{
						getMaterialsByCompany(this.parentOrderForm).then(res => {
							if (res.data.code == 0) {
								this.paymentOption = res.data.hardInfo
								if (res.data.companyList) {
									res.data.companyList.forEach(item => {
										this.transporterOption.push({
											text: item.name,
											value: item.id
										})
									})
								}
								var materialInfos = res.data.data;
								if (materialInfos && materialInfos.length > 0) {
									this.materialOption = materialInfos.map(item => {
										return ({
											text: item.name,
											value: item.id,
											type: item.materTypeName ? item.materTypeName : '暂无分类',
										})
									})
								}
								var companyProductList=res.data.companyProductList;
								console.log("1111213213", companyProductList);
								if (companyProductList && companyProductList.length > 0) {
									this.companyProductOption = companyProductList.map(item => {
										return ({
											text: item.productName,
											value: item.id
										})
									})
									this.parentOrderForm.projectId = this.companyProductOption[0].value
									this.parentOrderForm.projectName = this.companyProductOption[0].text
								}else{
									this.companyProductOption = [{
										text: this.$t('base.common.noData'),
										value: null
									}] //项目选项
									this.parentOrderForm.projectId = ''
									this.parentOrderForm.projectName = ''
								}

								var companyMineList=res.data.companyMineList;
								if (companyMineList && companyMineList.length > 0) {
									this.companyMineOption = companyMineList.map(item => {
										return ({
											text: item.mineName,
											value: item.id
										})
									})
									this.parentOrderForm.mineId = this.companyMineOption[0].value
									this.parentOrderForm.mineName = this.companyMineOption[0].text
								}else{
									this.companyMineOption = [{
										text: this.$t('base.common.noData'),
										value: null
									}] //项目选项
									this.parentOrderForm.mineId = ''
									this.parentOrderForm.mineName = ''
								}

								
							}
						})
					}
				}
			},

			//
			bindTenant() {
				this.tenantOption = getTenantCacheList();
				if (this.tenantOption.length > 0) {
					this.parentOrderForm.tenantId = this.tenantOption[0].value
					this.parentOrderForm.tenantName = this.tenantOption[0].text
				}
				this.bindOption();
			},
			formatOption(data) {
				let arr = []
				data.forEach(item => {
					arr.push({
						text: item.name || item.label,
						value: item.value || item.id
					})
				})
				if (arr.length) {
					arr.unshift({
						text: this.$t('order.notSelected'),
						value: null
					})
				} else {
					arr.unshift({
						text: this.$t('base.common.noData'),
						value: null
					})
				}
				return arr
			},
			//显示选择
			showPopup(refs) {
				this.$refs[refs].showPicker = true
			},
			//选择下单日期
			onSetDateConfirm(date) {
				this.parentOrderForm.setDate = dayjs(date).format('YYYY-MM-DD');
				this.showSetDateCalendar = false;
			},

			//选择客户
			onCompanyConfirm(value) {
				this.parentOrderForm.companyId = ''
				this.parentOrderForm.companyName = ''
				if (value.value) {
					this.parentOrderForm.companyId = value.value
					this.parentOrderForm.companyName = value.text
				}
				this.batchOrderList = []
				this.bindMaterial();
				this.bindProject()
			},
			onCompanyProductConfirm(value) {
				this.parentOrderForm.projectId = ''
				this.parentOrderForm.projectName = ''
				if (value.value) {
					this.parentOrderForm.projectId = value.value
					this.parentOrderForm.projectName = value.text
				}
				this.batchOrderList = []
			},
			onCompanyMineConfirm(value) {
				this.parentOrderForm.mineId = ''
				this.parentOrderForm.mineName = ''
				if (value.value) {
					this.parentOrderForm.mineId = value.value
					this.parentOrderForm.mineName = value.text
				}
				this.batchOrderList = []
			},


			
			onTransporterConfirm(value) {
				this.parentOrderForm.transporterId = ''
				this.parentOrderForm.transporterName = ''
				if (value.value) {
					this.parentOrderForm.transporterId = value.value
					this.parentOrderForm.transporterName = value.text
				}
				this.batchOrderList = []
			},
			onTransporterTypeConfirm(value) {
				console.log("选择的运输类型信息、", value);
				this.parentOrderForm.transporterType = ''
				this.parentOrderForm.transporterTypeName = ''
				if (value.value) {
					this.parentOrderForm.transporterType = value.value
					this.parentOrderForm.transporterTypeName = value.text
				}
				this.batchOrderList = []
			},
			clear(isVehicleType) {
				if (isVehicleType == true) {
					this.vehicleTypeOption = [{
						text: this.$t('base.common.noData'),
						value: null
					}]
					this.parentOrderForm.vehicleType = ''
				}
				this.companyOption = [{
					text: this.$t('base.common.noData'),
					value: null
				}] //客户选项
				this.materialOption = [{
					text: this.$t('base.common.noData'),
					value: null
				}] //物料选项
				this.companyProductOption = [{
					text: this.$t('base.common.noData'),
					value: null
				}] //项目选项
				this.companyMineOption = [{
					text: this.$t('base.common.noData'),
					value: null
				}] //矿点选项
				this.parentOrderForm.companyId = ''
				this.parentOrderForm.materialId = ''
				this.parentOrderForm.companyName = ''
				this.parentOrderForm.materialName = ''
				this.parentOrderForm.orderNumber = '0';
				this.parentOrderForm.projectId=''
				this.parentOrderForm.projectName=''
				this.parentOrderForm.mineId=''
				this.parentOrderForm.mineName=''
				

			},
			submit() {
				let that = this;
				console.log("当前保存的订单", that.batchOrderList);
				if (!that.batchOrderList || that.batchOrderList.length == 0) {
					uni.showToast({
						title: that.$t("base.common.placeholderM") + that.$t("order.info"),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				that.$refs.loadingToast.show({
					type: "loading",
					message: that.$t('base.common.loading'),
					duration: "1000000"
				})
				orderBatchInsert(that.batchOrderList).then(res => {
					console.log('okk', res);
					that.$refs.loadingToast.hide()
					if (res.statusCode == 200 && res.data.code == 0) {
						console.log('okk', res);
						
						uni.redirectTo({
							url: '/subpages/order/dealerList?index=0'
						})
					}
				}).catch(err => {
					console.log('err', err);
					that.$refs.loadingToast.hide()
				})

			},
		}
	}
</script>
<style lang="scss" scoped>
	@import '../../common/css/public.scss';
</style>
<style>
	page {
		background-color: #ffffff !important;
	}
</style>
<style lang="less" scoped>
	/deep/.order-card {
		padding: 8px !important;
	}

	.item-order {
		background-color: #f5f7fa;
	}

	.bottom-content {
		position: fixed;
		bottom: 10px;
		display: flex;
		align-items: center;
		line-height: 60rpx;
		width: 100%;
		justify-content: center;
		z-index: 1000 !important;
	}

	.bind-btn {
		width: 50%;
	}

	.order {
		padding: 32rpx;

		.picker-title {
			display: flex;
			padding: 0 32rpx;
			line-height: 84rpx;
			justify-content: space-between;

			.confirm {
				color: #4680F9;
			}
		}

		.picker-wrap {
			height: 440rpx;

			.picker-view {
				height: 100%;

				.item {
					display: flex;
					justify-content: space-between;
					height: 88rpx;
					line-height: 88rpx;
					padding: 0 32rpx;

					.text {
						width: 33%;
					}

					.text1 {
						width: 33%;
						text-align: center;
					}

					.text2 {
						width: 33%;
						text-align: right;
					}
				}

				.btn-item {
					display: flex;
					justify-content: center;
					height: 88rpx;
					line-height: 88rpx;
					padding: 0 32rpx;
					align-items: center;

					.add-vehicle {
						line-height: 64rpx;
						height: 64rpx;
						background: #4680F9;
						width: 25%;
						font-size: 28rpx;
					}
				}
			}
		}

		.form-wrap {
			height: 444rpx;
			padding: 0 32rpx;
		}
	}

	.uni-forms-item__inner {
		padding: 20rpx 0;
	}
</style>