<template>
	<view :style="getHeight" style="background-color: #F5F5F5;">
		<!-- 头部 -->
		<view class="carInfo w-100 px-3 box-sizing">
			<view class="d-flex">
				<view class="icon iconfont icon-tree-round-car flex-shrink topLeft"></view>
				<view class="topRight d-flex flex-1 p-3 flex-column" style="color: #FFFFFF;">
					<view class="d-flex flex-1">
						<view class="font-lg d-flex a-center">{{this.carInfo.licenseNo}}
							<view class="icon iconfont icon-bianji1 ml-2" @tap="toCarInfo"></view>
						</view>
					</view>
					<view class="brandName">{{this.carInfo.modelcname}}</view>
				</view>
			</view>
			<view class="other d-flex j-sb px-3">
				<view class="d-flex flex-1 a-center">
					<view class="privilege d-flex a-center j-center flex-shrink px-2">特权</view>
					<view class="content">每月自动查违章，无违章领奖励</view>
				</view>
				<view class="flex-shrink icon iconfont icon-youjiantou d-flex a-center font-sm"></view>
			</view>
		</view>
		<!-- 报价方案 -->
		<view class="pageContent">
			<view class="quotePlan mx-3">
				<view class="header j-sb d-flex a-center px-3">
					<view class="title font-md">报价方案</view>
					<view class="adjustPlan main-text-color" @tap="toInsureItems">调整方案</view>
				</view>
				<view class="body">
					<view class="insurance">
						<template v-if="jqstartDate">
							<view class="row j-sb  d-flex a-center">
								<view>交强险</view>
								<view>投保</view>
							</view>
						</template>
						<template v-if="systartDate">
							<block v-for="(item,index) in insureList" :key="index">
								<template v-if="item.amount!=0">
									<view class="row j-sb  d-flex a-center">
										<view>{{item.kindName}}</view>
										<block v-for="(item2,index2) in item.amtList" :key="index2">
											<template v-if="item2.value == item.amount">
												<view>{{item2.label}}</view>
											</template>
										</block>
									</view>
								</template>
							</block>
						</template>
						<view class="d-flex" v-if="jqstartDate">
							<view>起保日期：</view>
							<view>
								<p class="date d-flex a-center font-md" style="color: #FFFFFF;" v-if="jqstartDate">
									交强险 {{this.jqstartDate}}
								</p>
								<p class="date  d-flex a-center font-md" style="color: #FFFFFF;" v-if="systartDate">商业险
									{{this.systartDate}}
								</p>
							</view>
						</view>
					</view>
					<view class="addedServices">
						<view class="row j-sb  d-flex a-center">
							<view>增值服务</view>
							<view>赠送</view>
						</view>
						<view style="padding: 15upx;color: #A6A6A6;font-size: 24upx;background-color: #F8FAFC;">
							注：包含道路救援/安全检测/代为驾驶/代为送检，投保以上商业主险免费赠送，各家保司各个地区旅游差异，具体以保单信息为准</view>
					</view>
				</view>
			</view>
			<view class="quoteCompany">
				<view class="header j-sb  d-flex a-center">
					<view class="title  d-flex">精选保险公司<view class="icon iconfont icon-Group-"></view>
					</view>
				</view>
				<block v-for="(totalitem,totalindex) in totalCompanyList" :key="index">
					<template>
						<view class="quoteCompanyItem">
							<view class="top dis  f-c">
								<ls-loading v-show="totalitem.quoteCode==1" text="掌柜正在为您报价，请稍等......"
									:animation="animation" fontSize="22" />
								<view class="companyIcon dis j-s  a-c">
									<view class="dis ">
										<!-- 勾选框 -->
										<u-checkbox
											@change="event=>checkboxChange(event,totalitem.id,totalitem.cnName, totalindex)"
											v-model="totalitem.checked" active-color="rgb(250, 53, 52)"></u-checkbox>
										<!-- logo -->
										<image :src="totalitem.logo"></image>
										<!-- 名称 -->
										<view class="companyName">{{totalitem.namesimple}}</view>
									</view>
									<!-- 价格 -->
									<text v-show="totalitem.quoteCode==200"
										class="sum">￥{{totalitem.result.sumPermium}}</text>
									<text
										v-show="(totalitem.quoteCode != '200') && (totalitem.quoteCode != '0') && (totalitem.quoteCode != '1')"
										class="sum" style="color: #999;font-size: 12px;"
										@click="ErrorMsg(totalitem.msg)">报价失败，请点击查看</text>
								</view>
								<view class="" v-if="totalitem.checked">
									<u-form-item label="报价协议选择" :prop="totalitem.agreementId" label-width="200"
										:border-bottom='false' style="width: 250px;padding: 0;">
										<u-input type="select" :select-open="totalitem.selectShow"
											v-model="totalitem.agreementName" placeholder="请选择协议"
											@click="totalitem.selectShow = true"></u-input>
										<u-select mode="single-column" :list="totalitem.agreement" value-name="id"
											label-name="agreementName" v-model="totalitem.selectShow"
											@confirm="val=>selectConfirm(val,totalindex)"></u-select>
									</u-form-item>
								</view>
								<button v-show="totalitem.quoteCode==200" type="default"
									class="d-flex a-center j-center btn"
									@tap="querydetial(totalitem.result.companyId)">查看详情</button>
							</view>

						</view>
					</template>
				</block>
			</view>
		</view>
		<wyb-popup ref="carTypePopup" type="center" :scrollY="true" mode="size-fixed" :maskClickClose="false"
			height="640" width="690" radius="6">
			<view class="popupBody">
				<block v-for="(item,index) in carTypeList" :key="index">
					<view class="carTypeItem d-flex " @tap="chooseCarType(item)">
						<view class="nav d-flex flex-1 flex-column">
							<view class="carseriesName">{{item.carseriesname}}</view>
							<view class="modelName">{{item.modelname}}</view>
							<view class="nav_box d-flex">
								<span class="zid">{{item.transmissiontype}}</span>
								<p class=" d-flex a-center">
									{{item.caryear}}{{item.caryear==""?"":"款 | "}}{{item.seatmax}}座
								</p>
							</view>
						</view>
						<view class="price d-flex a-center j-center">￥{{item.purchaseprice}}</view>
					</view>
				</block>
			</view>
		</wyb-popup>
		<view class="infoBottom d-flex a-center j-center j-sb">
			<button type="default" class="d-flex a-center j-center" @tap="toNext">保费计算</button>
		</view>
		<u-modal ref="uModal" v-model="msgshow" :content="content" :title-style="{fontWeight:'bold'}" title="报价提示">
		</u-modal>
	</view>
</template>
<script>
	import {
		mapState
	} from "vuex"
	import wybPopup from '@/components/common/wyb-popup/wyb-popup.vue'
	import lsLoading from '@/components/common/ls-loading/ls-loading.vue';
	export default {
		components: {
			wybPopup,
			lsLoading
		},
		computed: {
			...mapState(['userInfo']),
			getHeight() {
				let height = uni.getSystemInfoSync().windowHeight;
				return `minHeight: ${height}px;`;
			}
		},
		// 监听导航栏的按钮
		onNavigationBarButtonTap(e) {
			if (e.index == 0) {
				this.navigate({
					url: '/pages/index/index'
				}, "switchTab", true);
			}
		},
		data() {
			return {
				msgshow: false,
				content: "",
				agreementList: [],
				zmDrivingForm: {}, //中煤驾意险
				carInfoRmation: [], //车辆影像
				ownerInfoRmation: [], //车主影像
				policyHolderInfoRmation: [], //投保人影像
				insuredPersonInfoRmation: [], //被保人影像
				orderno: "", //订单号
				show1: false, //华农
				animation: 'twinkle', //动画类型
				jqjishi: false,
				syjishi: false,
				timeArray: [],
				jqTimeIndex: 0,
				syTimeIndex: 0,
				time1: "",
				time2: "",
				carTypeList: [], //车辆品牌型号列表
				msg: "",
				quoteno: "", //报价编号
				hasKindCodeA: false, //是否含有车损险
				carInfo: {}, //车辆信息
				ownerInfo: {}, //车主信息
				policyHolderInfo: {}, //投保人信息
				insuredPersonInfo: {}, //被保人信息
				riskList: [], //险种大类信息
				kindList: [], //商业险险别
				showCarInfo: false, //控制车辆信息显示
				showInsureDate: true, //控制险种时间显示
				jqstartDate: "", //交强险日期
				jqendDate: " ", //交强险日期
				systartDate: "", //商业险日期
				syendDate: "", //商业险日期
				insureList: [{
						amount: "0",
						amountDesc: "投保",
						amtList: [{
							"label": "不投保",

							"value": "0"
						}, {
							"label": "投保",
							"value": "1"
						}],
						kindCode: "A",
						isMainRisk: true,
						kindName: "机动车损失险",
						desc: "保险期间内，被保险人或被保险机动车驾驶人在使用被保险机动车过程中，因自然灾害、意外事故、机动车被盗窃、抢劫、抢夺等情况（详见保险条款）造成被保险机动车直接损失，且不属于免除保险人责任的范围，保险人依照本保险合同的约定负责赔偿的险种。"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
								label: "不投保",
								value: "0"
							},
							{
								label: "50万",
								value: "500000"
							},
							{
								label: "100万",
								value: "1000000"
							},
							{
								label: "150万",
								value: "1500000"
							},
							{
								label: "200万",
								value: "2000000"
							},
							{
								label: "250万",
								value: "2500000"
							},
							{
								label: "300万",
								value: "3000000"
							},
							{
								label: "500万",
								value: "5000000"
							},
							{
								label: "1000万",
								value: "10000000"
							}
						],
						kindCode: "B",
						isMainRisk: true,
						kindName: "第三者责任险",
						desc: "保险期间内，被保险人或其允许的驾驶人在使用被保险机动车过程中发生意外事故，致使第三者遭受人身伤亡或财产直接损毁，依法应当对第三者承担的损害赔偿责任，且不属于免除保险人责任的范围，保险人依照本保险合同的约定，对于超过机动车交通事故责任强制保险各分项赔偿限额的部分负责赔偿的险种。"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "1万",
							"value": "10000"
						}, {
							"label": "2万",
							"value": "20000"
						}, {
							"label": "5万",
							"value": "50000"
						}, {
							"label": "10万",
							"value": "100000"
						}, {
							"label": "15万",
							"value": "150000"
						}, {
							"label": "20万",
							"value": "200000"
						}],
						kindCode: "D3",
						isMainRisk: true,
						kindName: "司机责任险",
						desc: "保险期间内，被保险人或其允许的驾驶人在使用被保险机动车过程中发生意外事故，致使车上人员遭受人身伤亡，且不属于免除保险人责任的范围，依法应当对车上人员承担的损害赔偿责任，保险人依照本保险合同的约定负责赔偿的险种。"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "1万",
							"value": "10000"
						}, {
							"label": "2万",
							"value": "20000"
						}, {
							"label": "4万",
							"value": "40000"
						}, {
							"label": "5万",
							"value": "50000"
						}, {
							"label": "10万",
							"value": "100000"
						}, {
							"label": "15万",
							"value": "150000"
						}, {
							"label": "20万",
							"value": "200000"
						}],
						kindCode: "D4",
						isMainRisk: true,
						kindName: "乘客责任险",
						desc: "保险期间内，被保险人或其允许的驾驶人在使用被保险机动车过程中发生意外事故，致使车上人员遭受人身伤亡，且不属于免除保险人责任的范围，依法应当对车上人员承担的损害赔偿责任，保险人依照本保险合同的约定负责赔偿的险种。"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "2000",
							"value": "2000"
						}, {
							"label": "5000",
							"value": "5000"
						}, {
							"label": "1万",
							"value": "10000"
						}],
						desc: "保险期间内，被保险机动车在被保险人或被保险机动车驾驶人使用过程中，发生无明显碰撞痕迹的车身划痕损失，保险人按照保险合同约定负责赔偿的险种",
						isMainRisk: true,
						kindCode: "L",
						kindName: "车身划痕险",
						mainRiskCodeList: "A"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "5%",
							"value": "5"
						}, {
							"label": "10%",
							"value": "10"
						}, {
							"label": "15%",
							"value": "15"
						}, {
							"label": "20%",
							"value": "20"
						}],
						desc: "被保险机动车发生主险约定的保险事故，保险人按照主险的约定计算赔款后，扣减本特约条款约定的免赔的险种。",
						isMainRisk: true,
						kindCode: "MJ1",
						kindName: "绝对免赔率特约险（车损）",
						mainRiskCodeList: "A"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "5%",
							"value": "5"
						}, {
							"label": "10%",
							"value": "10"
						}, {
							"label": "15%",
							"value": "15"
						}, {
							"label": "20%",
							"value": "20"
						}],
						desc: "被保险机动车发生主险约定的保险事故，保险人按照主险的约定计算赔款后，扣减本特约条款约定的免赔的险种。",
						isMainRisk: true,
						kindCode: "MJ2",
						kindName: "绝对免赔率特约险（三者）",
						mainRiskCodeList: "B"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "5%",
							"value": "5"
						}, {
							"label": "10%",
							"value": "10"
						}, {
							"label": "15%",
							"value": "15"
						}, {
							"label": "20%",
							"value": "20"
						}],
						desc: "被保险机动车发生主险约定的保险事故，保险人按照主险的约定计算赔款后，扣减本特约条款约定的免赔的险种。",
						isMainRisk: true,
						kindCode: "MJ3",
						kindName: "绝对免赔率特约险（司机）",
						mainRiskCodeList: "D3"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
							"label": "不投保",
							"value": "0"
						}, {
							"label": "5%",
							"value": "5"
						}, {
							"label": "10%",
							"value": "10"
						}, {
							"label": "15%",
							"value": "15"
						}, {
							"label": "20%",
							"value": "20"
						}],
						desc: "被保险机动车发生主险约定的保险事故，保险人按照主险的约定计算赔款后，扣减本特约条款约定的免赔的险种。",
						isMainRisk: true,
						kindCode: "MJ4",
						kindName: "绝对免赔率特约险（乘客）",
						mainRiskCodeList: "D4"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						coveragePremium: 0,
						amtList: [{
								label: "不投保",
								value: "0"
							},
							{
								label: "1万",
								value: "10000"
							},
							{
								label: "2万",
								value: "20000"
							},
							{
								label: "5万",
								value: "50000"
							},
							{
								label: "10万",
								value: "100000"
							}
						],
						kindCode: "SY_FJ_YBW1",
						isMainRisk: true,
						kindName: "附加医保-三者",
						desc: "附加医保外医疗费用责任险（机动车第三者责任保险）"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						coveragePremium: 0,
						amtList: [{
								label: "不投保",
								value: "0"
							},
							{
								label: "1万",
								value: "10000"
							},
							{
								label: "2万",
								value: "20000"
							},
							{
								label: "5万",
								value: "50000"
							},
							{
								label: "10万",
								value: "100000"
							}
						],
						kindCode: "SY_FJ_YBW2",
						isMainRisk: true,
						kindName: "附加医保-座位险(乘客)",
						desc: "附加医保外医疗费用责任险（机动车第三者责任保险）"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						coveragePremium: 0,
						amtList: [{
								label: "不投保",
								value: "0"
							},
							{
								label: "1万",
								value: "10000"
							},
							{
								label: "2万",
								value: "20000"
							},
							{
								label: "5万",
								value: "50000"
							},
							{
								label: "10万",
								value: "100000"
							}
						],
						kindCode: "SY_FJ_YBW3",
						isMainRisk: true,
						kindName: "附加医保-座位险(司机)",
						desc: "附加医保外医疗费用责任险（机动车第三者责任保险）"
					},
					{
						amount: "0",
						amountDesc: "不投保",
						amtList: [{
								label: "不投保",
								value: "0"
							},
							{
								label: "50万",
								value: "500000"
							},
							{
								label: "100万",
								value: "1000000"
							},
							{
								label: "150万",
								value: "1500000"
							},
							{
								label: "200万",
								value: "2000000"
							},
							{
								label: "250万",
								value: "2500000"
							},
							{
								label: "300万",
								value: "3000000"
							},
							{
								label: "500万",
								value: "5000000"
							},
							{
								label: "1000万",
								value: "10000000"
							}
						],
						desc: "保险期间内，被保险人或其允许的驾驶人在法定节假日期间使用被保险机动车发生机动车第三者责任保险范围内的事故，并经公安部门或保险人查勘确认的，被保险机动车第三者责任保险所适用的责任限额在保险单载明的基础上增加一倍的险种",
						isMainRisk: true,
						kindCode: "BD",
						kindName: "法定节假日限额翻倍险",
						mainRiskCodeList: "B"
					}

				],

				totalCompanyList: [], //保险公司列表
				notStartedQuote: true, //未开始报价(true表示未开始报价，false表示已经报价结束)
				quoteCompanyCount: 0,
			}
		},
		async onLoad() {
			const eventChannel = this.getOpenerEventChannel()
			// 监听acceptData事件，获取上一页面通过eventChannel传送到当前页面的数据
			eventChannel.on('acceptData', async (data) => {
				console.log(data)
				this.carInfo = data.carInfo; //车辆信息
				this.ownerInfo = data.ownerInfo; //车主信息
				this.policyHolderInfo = data.policyHolderInfo; //投保人信息
				this.insuredPersonInfo = data.insuredPersonInfo; //被保人信息
				this.riskList = data.riskList; //险种大类
				this.kindList = data.kindList; //商业险险别
				this.orderno = data.orderno;
				this.quoteno = data.quoteno;
				if (this.riskList.length > 0) {
					for (let i = 0; i < this.riskList.length; i++) {
						if (this.riskList[i].riskCode == '0507') {
							this.jqstartDate = this.riskList[i].startDate;
						}
						if (this.riskList[i].riskCode == '0510') {
							this.systartDate = this.riskList[i].startDate;
							this.kindList.map(ele1 => {
								this.insureList.map(ele2 => {
									if (ele2.kindCode == ele1.kindCode) {
										switch (ele1.kindCode) {
											case 'D4':
											case 'SY_FJ_YBW2':
												ele2.amount = ele1.unitAmount;
												break;
											case "MJ1":
											case "MJ2":
											case "MJ3":
											case "MJ4":
												ele2.amount = ele1.deductibleRate;
												break;
											default:
												ele2.amount = ele1.amount;
										}
									}
								})
							})

						}
					}
				}
			})
			this.commpanyList();
		},
		methods: {
			//查看详情
			querydetial(id) {
				this.navigate({
						url: "/pages/carInsure1/quoteDetail1?companyId=" + id
					},
					"navigateTo", true);
			},
			//选择协议
			selectConfirm(e, index) {
				this.totalCompanyList[index].agreementId = e[0].value;
				this.totalCompanyList[index].agreementName = e[0].label;
				this.totalCompanyList[index].apiType = e[0].extra;
			},
			//获取保险公司列表
			async commpanyList() {
				let commpanykad = await this.$http.get('/insurance/order/getAgreementInsCompany');
				commpanykad.data.map(ele => {
					ele["result"] = {};
					ele["quoteCode"] = 0;
					ele["checked"] = false;
					ele["msg"] = "";
					ele["agreementId"] = "";
					ele["agreementName"] = "";
					ele["apiType"] = "";
					ele["selectShow"] = false;
				})
				this.totalCompanyList = commpanykad.data;
			},
			async toNext() {
				if (this.quoteno) {
					this.OrderStageProcessing();
				} else {
					let getquote = await this.$http.get('/ins/tool/getQuoteNo');
					this.quoteno = getquote.data;
					this.OrderStageProcessing();
				}
			},

			async OrderStageProcessing() {
				await this.$http.post('/ins/taskImage/uploadImages', {
					imageIdList: this.carInfoRmation,
					imageType: "C01",
					quoteNo: this.quoteno
				})
				await this.$http.post('/ins/taskImage/uploadImages', {
					imageIdList: this.ownerInfoRmation,
					imageType: "C02",
					quoteNo: this.quoteno
				})
				await this.$http.post('/ins/taskImage/uploadImages', {
					imageIdList: this.policyHolderInfoRmation,
					imageType: "C03",
					quoteNo: this.quoteno
				})
				await this.$http.post('/ins/taskImage/uploadImages', {
					imageIdList: this.insuredPersonInfoRmation,
					imageType: "C04",
					quoteNo: this.quoteno
				})
				let param = {
					userId: this.userInfo.sysUser.id,
					quoteno: this.quoteno,
					orderNo: this.orderno ? this.orderno : "",
					carInfo: this.carInfo,
					insuredPersonInfo: this.insuredPersonInfo,
					ownerInfo: this.ownerInfo,
					policyHolderInfo: this.policyHolderInfo,
					kindList: this.kindList,
					riskList: this.riskList
				};
				let orders = await this.$http.post('/insurance/order/generateOrder', param);
				if (orders.code == '200') {
					this.orderno = orders.data.orderno;
					this.totalCompanyList.map((ele, index) => {
						if (ele.checked) {
							//动态调用报价接口
							ele.quoteCode = "1";
							console.log(ele.quoteCode)
							this.ToolClickFun(ele.cnName, index, ele.id);
						}
					});
				}
			},
			//动态函数
			ToolClickFun(MethodName, Parameter, companyId) {
				this[`${MethodName}`](Parameter, companyId)
			},
			//永安报价
			async yongan(num, id) {
				let params = {
					orderNo: this.orderno,
					companyId: id
				};
				let quote = await this.$http('/order/yongAn/quote', params);
				if (quote.msg == "重复投保" && quote.code == "501") {
					if (!!quote.data.jqStartDate && !quote.data.syStartDate) {
						this.jqstartDate = quote.data.jqStartDate;
						this.jqendDate = quote.data.jqEndDate;
						if (this.riskList.length > 0) {
							for (let i = 0; i < this.riskList.length; i++) {
								if (this.riskList[i].riskCode == "0507") {
									this.riskList[i].startDate = quote.data.jqStartDate;
									this.riskList[i].endDate = quote.data.jqEndDate;
								}
							}
						}
						let param = {
							userId: this.userInfo.sysUser.id,
							quoteno: this.quoteno,
							orderNo: this.orderno,
							carInfo: this.carInfo,
							insuredPersonInfo: this.insuredPersonInfo,
							ownerInfo: this.ownerInfo,
							policyHolderInfo: this.policyHolderInfo,
							kindList: this.kindList,
							riskList: this.riskList
						};
						await this.$http.post('/insurance/order/generateOrder', param);
						return this.yongan(num, id);

					} else if (!!quote.data.syStartDate && !quote.data.jqStartDate) {


					} else if (!!quote.data.syStartDate && !!quote.data.jqStartDate) {

					} else {
						this.totalCompanyList[num].quoteCode = "3";
						this.totalCompanyList[num].msg = "重复投保";
					}

				} else if (quote.code == "500" || quote.code == "502" || quote.code == "-9999") {
					this.totalCompanyList[num].quoteCode = "-9999";
					this.totalCompanyList[num].msg = quote.msg;
				} else {
					this.totalCompanyList[num].quoteCode = 200;
					this.totalCompanyList[num].result = quote.data;
				}
			},
			//中煤报价
			async zhongmei(num, id) {
				let params = {
					accidentalDrivingVo: this.zmDrivingForm,
					orderNo: this.orderno,
					companyId: id,
					agreementId: this.totalCompanyList[num].agreementId,
				};

				let res = await this.$http.post('/order/zhongMeiApi/quote', params);
				this.totalCompanyList[num].msg = res.msg;
				if (!!res.msg && res.msg.indexOf("不存在有效协议") >= 0) {
					this.totalCompanyList[num].quoteCode = "4";
					this.totalCompanyList[num].msg = res.msg;
					return;
				} else if (
					res.data == null &&
					res.msg.indexOf("交强险平台返回") > -1 &&
					res.msg.indexOf(";终保日期") > -1
				) {
					let time =
						res.msg.substr(res.msg.indexOf(";终保日期 ") + 6, 16) + ":00";
					this.jqstartDate = time;
					this.jqendDate = this.oneYearPast(time);
					this.systartDate = time;
					this.syendDate = this.oneYearPast(time);
					if (this.riskList.length > 0) {
						for (let i = 0; i < this.riskList.length; i++) {
							if (this.riskList[i].riskCode == "0507") {
								this.riskList[i].startDate = time;
								this.riskList[i].endDate = this.oneYearPast(time);
							} else if (this.riskList[i].riskCode == "0510") {
								this.riskList[i].startDate = time;
								this.riskList[i].endDate = this.oneYearPast(time);
							}
						}
					}
					let param = {
						userId: this.userInfo.sysUser.id,
						quoteno: this.quoteno,
						orderNo: this.orderno,
						carInfo: this.carInfo,
						insuredPersonInfo: this.insuredPersonInfo,
						ownerInfo: this.ownerInfo,
						policyHolderInfo: this.policyHolderInfo,
						kindList: this.kindList,
						riskList: this.riskList
					};
					await this.$http.post('/insurance/order/generateOrder', param);
					return this.zhongmei(num, id);
				} else if (!!res.data) {
					this.totalCompanyList[num].quoteCode = 200;
					this.totalCompanyList[num].result = res.data;
				} else {
					this.totalCompanyList[num].quoteCode = "3";
					this.totalCompanyList[num].msg = res.msg;
					return;
				}
			},
			//永诚报价
			async yongcheng(num, id) {
				let accidentalDrivingVo = {};
				if (this.accidentForm.id) {
					let data = this.accidentDataList.find(
						val => val.id == this.accidentForm.accidentType
					);
					accidentalDrivingVo = {
						rideRiskCode: data.code ? data.code : "",
						rideRiskName: data.name ? data.name : "",
						quantity: this.accidentForm.fen ? this.accidentForm.fen : ""
					};
				}
				let params = {
					accidentalDrivingVo,
					orderNo: this.orderno,
					companyId: id,
					cqryCdeJq: this.cqryCdeJq,
					cqryCdeSy: this.cqryCdeSy,
					renewalCodeJq: this.renewalCodeJq,
					renewalCodeSy: this.renewalCodeSy
				};
				let res = await this.$http('/api/yongCheng/quote', params);
				this.totalCompanyList[num].msg = res.msg;
				if (!!res.msg && res.msg.indexOf("不存在有效协议") >= 0) {
					this.totalCompanyList[num].quoteCode = "4";
					this.totalCompanyList[num].msg = res.msg;
					return;
				} else if (
					res.data == null &&
					res.msg.indexOf("车险平台返回") > -1 &&
					res.msg.indexOf(";终保日期") > -1
				) {
					let time =
						res.msg.substr(res.msg.indexOf(";终保日期 ") + 6, 16) + ":00";
					let Aortime = this.transformTime2(time); //终保日期的后一天
					this.jqstartDate = Aortime;
					this.jqendDate = this.oneYearPast(Aortime);
					this.systartDate = Aortime;
					this.syendDate = this.oneYearPast(Aortime);
					if (this.riskList.length > 0) {
						for (let i = 0; i < this.riskList.length; i++) {
							if (this.riskList[i].riskCode == "0507") {
								this.riskList[i].startDate = Aortime;
								this.riskList[i].endDate = this.oneYearPast(Aortime);
							} else if (this.riskList[i].riskCode == "0510") {
								this.riskList[i].startDate = Aortime;
								this.riskList[i].endDate = this.oneYearPast(Aortime);
							}
						}
					}
					let param = {
						userId: this.userInfo.sysUser.id,
						quoteno: this.quoteno,
						orderNo: this.orderno,
						carInfo: this.carInfo,
						insuredPersonInfo: this.insuredPersonInfo,
						ownerInfo: this.ownerInfo,
						policyHolderInfo: this.policyHolderInfo,
						kindList: this.kindList,
						riskList: this.riskList
					};
					await this.$http.post('/insurance/order/generateOrder', param);
					return this.yongcheng(num, id);
				} else if (res.code == "200") {
					this.totalCompanyList[num].quoteCode = 200;
					this.totalCompanyList[num].result = res.data;
				} else if (res.code == "101") {
					this.totalCompanyList[num].quoteCode = "101";
					this.totalCompanyList[num].msg = res.msg;
					this.cqryCdeJq = res.data.cqryCdeJq;
					this.cqryCdeSy = res.data.cqryCdeSy;
					let jq = res.data.renewalCodeJq.replace(/[\r\n]/g, "");
					let jqBase64 = `data:image/png;base64,${jq}`;
					this.renewalCodeJqImg = jqBase64;
					if (res.data.renewalCodeSy) {
						let sy = res.data.renewalCodeSy.replace(/[\r\n]/g, "");
						let syBase64 = `data:image/png;base64,${sy}`;
						this.renewalCodeSyImg = syBase64;
					}
					this.renewalCodedialogVisible = true;
				} else {
					this.totalCompanyList[num].quoteCode = "3";
					this.totalCompanyList[num].msg = res.msg;
					return;
				}
			},
			//爬虫统一报价接口
			async quoteInsurance(num, id, apiType) {
				let api = apiType === 2 ? "/insurance/crawler/quote" : "anshengquote";
				let params = {
					orderNo: this.orderno,
					companyId: id,
					agreementId: this.totalCompanyList[num].agreementId,
				};

				let res = await this.$http.post(`${api}`, params);
				this.totalCompanyList[num].msg = res.msg;
				if (!!res.msg && res.msg.indexOf("不存在有效协议") >= 0) {
					this.totalCompanyList[num].quoteCode = "4";
					this.totalCompanyList[num].msg = res.msg;
					return;
				} else if (
					res.data == null &&
					res.msg.indexOf("交强险平台返回") > -1 &&
					res.msg.indexOf(";终保日期") > -1
				) {
					let time =
						res.msg.substr(res.msg.indexOf(";终保日期 ") + 6, 16) + ":00";
					this.jqstartDate = time;
					this.jqendDate = this.oneYearPast(time);
					this.systartDate = time;
					this.syendDate = this.oneYearPast(time);
					if (this.riskList.length > 0) {
						for (let i = 0; i < this.riskList.length; i++) {
							if (this.riskList[i].riskCode == "0507") {
								this.riskList[i].startDate = time;
								this.riskList[i].endDate = this.oneYearPast(time);
							} else if (this.riskList[i].riskCode == "0510") {
								this.riskList[i].startDate = time;
								this.riskList[i].endDate = this.oneYearPast(time);
							}
						}
					}
					let param = {
						userId: this.userInfo.sysUser.id,
						quoteno: this.quoteno,
						orderNo: this.orderno,
						carInfo: this.carInfo,
						insuredPersonInfo: this.insuredPersonInfo,
						ownerInfo: this.ownerInfo,
						policyHolderInfo: this.policyHolderInfo,
						kindList: this.kindList,
						riskList: this.riskList
					};
					await this.$http.post('/insurance/order/generateOrder', param);
					return this.quoteInsurance(num, id, apiType);
				} else if (!!res.data) {
					this.totalCompanyList[num].quoteCode = 200;
					this.totalCompanyList[num].result = res.data;
				} else {
					this.totalCompanyList[num].quoteCode = "3";
					this.totalCompanyList[num].msg = res.msg;
					return;
				}
			},
			//安盛天平
			ansheng(num, id) {
				this.quoteInsurance(num, id, this.totalCompanyList[num].apiType);
			},
			//众安
			zhongan(num, id) {
				this.quoteInsurance(num, id, this.totalCompanyList[num].apiType);
			},
			//人寿
			renshou(num, id) {
				this.quoteInsurance(num, id, this.totalCompanyList[num].apiType);
			},
			//恒邦
			hengbang(num, id) {
				this.quoteInsurance(num, id, this.totalCompanyList[num].apiType);
			},
			/**
			 * 选择保险公司方法
			 * @param {String} event  change选中事件
			 * @param {String} code 保险公司ID
			 * @param {String} name 保险公司主体全拼
			 * @param {String} index 选中下标
			 */
			checkboxChange(event, code, name, index) {

				this.totalCompanyList[index].checked = event.value;
				let arr = this.totalCompanyList[index].agreement;
				let list = [];
				list = arr.filter(item => {
					return item.licenseNo.length > 0 ? item.licenseNo.includes(this.carInfo.licenseNo.slice(
						0,
						2)) : "true"
				})
				list.map(ele => {
					ele.extra = ele.apiType;
					return ele;
				})
				this.agreementList = list;
			},
			// 重新选择车型
			toCarInfo() {
				this.navigate({
					url: '/pages/carInsure1/carInfo1',
					success: (res) => {
						res.eventChannel.emit("acceptData", {
							carInfo: this.carInfo,
							ownerInfo: this.ownerInfo,
							policyHolderInfo: this.policyHolderInfo,
							insuredPersonInfo: this.insuredPersonInfo,
							riskList: this.riskList,
							kindList: this.kindList
						})
					}
				}, "navigateTo", true);
			},
			// 重新选择方案
			toInsureItems() {
				this.navigate({
					url: '/pages/carInsure1/insureItems1',
					success: (res) => {
						res.eventChannel.emit("acceptData", {
							carInfo: this.carInfo,
							ownerInfo: this.ownerInfo,
							policyHolderInfo: this.policyHolderInfo,
							insuredPersonInfo: this.insuredPersonInfo,
							riskList: this.riskList,
							kindList: this.kindList,
							vehicleModel: this.vehicleModel,
						})
					}
				}, "navigateTo", true);
			},
			toQuoteDetail(orderno) {
				this.navigate({
					url: "/pages/carInsure1/quoteDetail1?orderno=" + orderno
				}, "navigateTo", true);
			},

			// 显示报错信息
			ErrorMsg(msg) {
				this.content = msg;
				this.msgshow = true;
			},

			//选择正确的车型
			async chooseCarType(item) {
				this.carInfo.brandName = item.modelname; //品牌型号
				this.carInfo.ciModelCode = item.vehiclecode; //行业车型编码
				this.carInfo.modelCode = item.modelcode;
				this.carInfo.seatCount = item.seatmax + '';
				this.carInfo.caryear = item.caryear;
				this.carInfo.exhaustScale = (item.exhaustscale * 1000) + '';
				this.carInfo.factory = item.factory;
				this.carInfo.factoryid = item.factorycode;
				this.carInfo.cimodelclass = item.inscarclassname;
				this.carInfo.powertype = item.powerType;
				this.carInfo.purchasePrice = item.purchaseprice + '';
				this.carInfo.modelcname = item.modelname;
				this.$refs.carTypePopup.hide()
				let a = await this.huanongquote(0);
				this.totalCompanyList[0].result = a;
				if (this.totalCompanyList[0].quoteCode != '4') {
					this.quoteCompanyCount++;


					let c = await this.zhongmeiquote(2);
					this.totalCompanyList[2].result = c;
					this.quoteCompanyCount++;
					let d = await this.tiananquote(1);
					this.totalCompanyList[1].result = d;
					this.quoteCompanyCount++;
					let b = await this.hengbangquote(3);
					this.totalCompanyList[3].result = b;
					this.quoteCompanyCount++;

				}
			},
			oneYearPast(time) {
				var date = new Date(time);
				date.setFullYear(date.getFullYear() + 1); //一年后
				date.setTime(date.getTime() - 24 * 60 * 60 * 1000); //一年后的前一天
				var strYear = date.getFullYear();
				var strMonth = date.getMonth() + 1;
				var strDay = date.getDate();
				var hh = date.getHours();
				if (hh < 10) {
					hh = "0" + hh;
				}
				if (strMonth < 10) {
					strMonth = "0" + strMonth;
				}
				if (strDay < 10) {
					strDay = "0" + strDay;
				}
				var datastr = strYear + "-" + strMonth + "-" + strDay + ' ' + hh + ':00:00';
				return datastr;
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';

	/* 头部车辆信息和特权Start */
	.carInfo {
		height: 330upx;
		background: -webkit-linear-gradient(0deg, rgba($themeColor, 0.6), rgba($themeColor, 0.8));
		background-size: 100% 100%;
	}

	.carInfo .topLeft {
		width: 120upx;
		font-size: 90upx;
		color: #FFFFFF;
	}

	.carInfo .topRight .brandName {
		width: 400upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.carInfo .other {
		background-color: #FFFFFF;
		height: 80upx;
		border-radius: 15upx;
		box-sizing: border-box;
	}

	.carInfo .other .privilege {
		background-color: rgba($themeColor, 0.6);
		font-size: 24upx;
		color: #FFFFFF;
		font-weight: bold;
	}

	.carInfo .other .content {
		width: 460upx;
		margin-left: 15upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.carInfo .other .icon {
		width: 30upx;
	}

	/* 头部车辆信息和特权End */
	.pageContent {
		position: relative;
		top: -50upx;
		padding-bottom: 100px;
	}

	/* 报价方案Start */
	.quotePlan {
		background: #FFFFFF;
		position: relative;
		border-radius: 20upx;
	}

	.quotePlan .header {
		height: 80upx;
		position: relative;
		border-bottom: 1px solid #E6E8EA;
	}

	.quotePlan .header .title {
		// font-size: 30upx;
		font-weight: bold;
		padding-left: 25upx;
	}

	.quotePlan .header .title:before {
		content: "";
		position: absolute;
		left: 30upx;
		top: 25upx;
		width: 8upx;
		height: 30upx;
		background-color: $themeColor;
	}

	.quotePlan .body {
		padding: 0 30upx 10upx;
	}

	.quotePlan .body .insurance {
		padding-bottom: 20upx;
		border-bottom: 1px dashed #E6E8EA;
	}






	.carTypeItem {
		padding: 0 30upx 20upx;
		border-bottom: 1px solid #e5e5e5;
		margin-top: 20upx;
		width: 100%;
		box-sizing: border-box;
	}

	.carTypeItem .nav .carseriesName {
		font-size: 34upx;
		width: 360upx;
		font-family: PingFangSC-Medium, PingFangSC;
		color: #4a4a4a;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.carTypeItem .nav .modelName {
		font-size: 26upx;
		width: 400upx;
		font-family: PingFangSC-Medium, PingFangSC;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.carTypeItem .nav .nav_box {
		margin: 10upx 0;
	}

	.carTypeItem .nav .nav_box .zid {
		display: inline-block;
		padding: 6upx 10upx;
		font-size: 24upx;
		height: 40upx;
		background: #AFC9F7;
		border-radius: 25upx;
		color: #007AFF;
		font-weight: bold;
		line-height: 40upx;
	}

	.carTypeItem .nav .nav_box>p {
		margin-left: 30upx;
		color: #999;
		font-size: 24upx;
	}

	.carTypeItem .price {
		font-size: 16px;
		width: 200upx;
		flex-shrink: 0;
		font-family: PingFangSC-Regular, PingFangSC;
		font-weight: 400;
		color: #007AFF;
	}


	.quotePlan .body .row {
		height: 70upx;
	}

	.quotePlan .body .date {
		background-color: $themeColor;
		color: $themeColor;
		font-size: 22upx;
		padding: 0upx 7upx;
		border-radius: 3upx;
		margin: 10upx;
		margin-right: 10upx;
	}

	/* 报价方案End */

	/* 报价公司Start */
	.quoteCompany {
		margin: 20upx 30upx;
		box-sizing: border-box;
		/* background:#FFFFFF; */
		position: relative;
		border-radius: 20upx;
	}

	.quoteCompany .header {
		height: 80upx;
		padding: 0 30upx;
		position: relative;
	}

	.quoteCompany .header .title {
		font-size: 30upx;
		font-weight: bold;
		padding-left: 25upx;
	}

	.quoteCompany .header .title:before {
		content: "";
		position: absolute;
		left: 30upx;
		top: 25upx;
		width: 8upx;
		height: 30upx;
		background-color: rgba($themeColor, 0.6);
	}

	.quoteCompany .header .title .icon {
		color: rgba($themeColor, 0.6);
		margin-left: 15upx;
	}

	.quoteCompanyItem {
		margin-bottom: 20upx;
		background: #FFFFFF;
		border-radius: 15upx;
		padding: 10px 20px;
		box-sizing: border-box;
		cursor: pointer;
	}

	.quoteCompanyItem .top {
		position: relative;
	}

	.quoteCompanyItem .top .companyIcon {
		flex-shrink: 0;
	}

	.quoteCompanyItem .top .companyIcon image {
		width: 34px;
		height: 34px;
		margin-right: 10px;
	}

	.quoteCompanyItem .top .companyName {
		font-size: 32upx;
		font-weight: bold;
		width: 180upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.quoteCompanyItem .top .totalMoney {
		font-size: 40upx;
		font-weight: bold;
		color: $themeColor;
		position: absolute;
		top: -15upx;
		right: 0;
	}

	.quoteCompanyItem .top .tip {
		font-size: 26upx;
		font-weight: bold;
		color: #999;
		position: absolute;
		top: 0upx;
		right: 0;
	}

	.sum {
		color: #ea552d;
		font-size: 22px;
		font-weight: bold;
	}

	.quoteCompanyItem .top .signs {
		width: 500upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.quoteCompanyItem .top .sign {
		height: 40upx;
		margin: 0upx 10upx;
		background: rgba($themeColor, 0.6);
		color: $themeColor;
		font-size: 20upx;
		margin-right: 10upx;
		border-radius: 6upx;
		padding: 0 2px;
		line-height: 40upx;
	}

	.jqsign {
		height: 20px;
		background: rgba(255, 177, 177, 0.55);
		color: #fd0a0a;
		font-size: 20upx;
		border-radius: 6upx;
		padding: 0 10px;
		box-sizing: border-box;
	}

	.quoteCompanyItem .body {
		padding: 20upx 0;
		flex-wrap: wrap;
	}

	.quoteCompanyItem .body>view {
		flex-shrink: 0;
		width: 50%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.quoteCompanyItem .body .icon-exchange {
		margin-right: 15upx;
		display: inline-block;
	}

	/* 报价公司End */


	/* 查看详情按钮Start */
	.btn {
		font-size: 16px;
		color: #fff;
		background-color: #ea552d;
		margin-top: 10px;
	}

	/* 底部的样式Start */
	.infoBottom {
		height: 140upx;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background: #FFFFFF;
		border-top: 1upx solid #EEEEEE;
		z-index: 99;
	}

	.infoBottom>button {
		// font-size: 30upx;
		background: $themeColor;
		color: #FFFFFF;
		flex: 1;
		margin: 0upx 30upx;
	}

	/* 查看详情按钮End */
</style>