<template>
	<view class="container-main">
		<view class="list">
			<view class="list-item" v-for="(item, index) in list" :key="index" @click="getInfo(item.id)">
				<view class="item-state" :class="
            item.status == '未生效'
              ? 'state0'
              : item.status == '生效中'
              ? 'state1'
              : 'state2'
          ">
					{{ item.status }}
				</view>
				<view class="item-data">
					<view class="data-main">
						<view class="data-title">{{ item.productName }}</view>
						<view class="data-lable-value">
							<view class="row-item">
								<view class="item-lable">
									<view class="lable-icon">
										<image :src="baseImgUrl + 'liao-ning/icon_shijian.png'" mode=""></image>
									</view>
									<view class="lable-text">保险公司:</view>
								</view>
								<view class="item-value">{{ item.companyName }}</view>
							</view>
							<view class="row-item">
								<view class="item-lable">
									<view class="lable-icon">
										<image :src="baseImgUrl + 'liao-ning/icon_faburen.png'" mode=""></image>
									</view>
									<view class="lable-text">保险期间:</view>
								</view>
								<view class="item-value">{{ item.insurancePeriod }}至{{
                    item.insurancePeriodEnd
                  }}</view>
							</view>
							<view class="row-item">
								<view class="item-lable">
									<view class="lable-icon">
										<image :src="baseImgUrl + 'liao-ning/icon_danwei.png'" mode=""></image>
									</view>
									<view class="lable-text">保费合计:</view>
								</view>
								<view class="item-value" style="color: #3976f1; font-weight: 520">
									{{ item.totalPremium }}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" :load-text="loadText" color="#C4CCD8" font-size="24" />
		</view>
		<fixedButton title="我要投保" @click="clickSub" />
	</view>
</template>
<script>
	//查询企业详细信息
	//行政
	//根据统一社会信用代码查询产品
	import {
		getInfo,
		getAdministrative,
		getAllFoodList,
		insureSystem,
	} from "@/api/shianliaoning/enterpriseSEARCH.js";
	import fixedButton from "@/components/fixedButton/fixedButton.vue";
	import {
		getInsureList
	} from "@/api/shianliaoning/insure.js";
	import {
		ReactiveFlags
	} from "vue";
	import {
		getToken
	} from "@/utils/auth";
	export default {
		components: {
			fixedButton,
		},
		data() {
			return {
				data: {},
				baseImgUrl: getApp().globalData.config.iamgeBaseUrl,
				list: [],
				queryParms: {
					pageNum: 1,
					pageSize: 10,
					//统一社会信用代码
					code: "",
					//企业名称
					enterpriseName: "",
				},
				total: 0, //总数
				flag: true,
				loadText: {
					nomore: "已经到底了~",
					loading: "努力加载中",
				},
				status: "nomore",
				statusFlag: false,
				one: null,
				two: null,
				three: null,
			};
		},
		onLoad() {


			this.queryParms.code = uni.getStorageSync("USER_DATA").userDto.code;
			this.queryParms.enterpriseName =
				uni.getStorageSync("USER_DATA").userDto.enterpriseName;
			this.getList();
			//请求三个接口获取数据从而可以跳转
			this.httpThreeGet();
		},
		onReachBottom() {
			if (this.total > this.list.length) {
				if (this.statusFlag) {
					return;
				}
				this.queryParms.pageNum++;
				this.getList();
			}
		},
		methods: {
			//
			httpThreeGet() {
				let _this = this;
				this.one = new Promise((resolve, rejects) => {
					getInfo(this.queryParms.code).then((res) => {
						resolve(res.data.result);
					});
				});
				this.two = new Promise((resolve, rejects) => {
					getAdministrative(this.queryParms.code).then((res) => {
						resolve(res.data.result[0]);
					});
				});
				this.three = new Promise((resolve, rejects) => {
					getAllFoodList({
						uniscid: this.queryParms.code,
						pageNum: 1,
						pageSize: 1,
					}).then((res) => {
						resolve(res.data.result.list[0]);
					});
				});
				Promise.all([this.one, this.two, this.three]).then((res) => {
					_this.data = {
						address: res[0].address,
						appliName: res[0].mainName,
						busDesc: res[1].licContent,
						busEdate: res[1].valTo,
						//食品生产流通许可证号
						busLicenseNo: res[1].licNo,
						//食品经营许可证号
						// busSLicenseNo: res[1].licAuthCode,
						busSLicenseNo: null,
						//省市区
						province: null,
						//食品生产流通许可证起期
						busSdate: null,
						busType: res[0].entType,
						identifyNumber: res[0].uniscid,
					};
				});
			},
			//下拉加载效果
			reachStart() {
				this.statusFlag = true;
				this.status = "loading";
			},
			//下拉结束效果
			reachEnd() {
				this.statusFlag = false;
				this.status = "nomore";
			},
			//加载列表
			getList() {
				this.reachStart();
				getInsureList(this.queryParms).then((res) => {
					this.flag = false;
					this.list = [...this.list, ...res.rows];
					this.total = res.total;
					this.reachEnd();
				});
			},
			getInfo(e) {
				uni.navigateTo({
					url: `/sub-enterprise/toubao-xiangqing/toubao-xiangqing?id=${e}`,
				});
			},
			clickSub() {
				insureSystem(this.data).then((res) => {
					let token = getToken();
					window.location.href =
						`https://pay.tpi.cntaiping.com/weshop/dfs/lnsz/SN05/index#/?insureId=${res.data}&token=${token}`
					// window.location.href = `
					// 	`
					// https
					// 	: //testiapp.etaiping.com:7443/weshop/dfs/lnsz/SN05/index#/?insureId=${res.data}&token=${token}`;
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	uni-page-body,
	page {
		background: rgba(245, 247, 250, 1);
	}

	.list {
		padding: 30rpx 20rpx;
		// padding-bottom: 128rpx;

		.list-item {
			margin-bottom: 100rpx;

			position: relative;
		}

		.item-state {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 66rpx;
			line-height: 66rpx;
			box-sizing: border-box;
			padding-left: 30rpx;
			border-radius: 16rpx 16rpx 0 0;
			font-size: 28rpx;
			font-family: "PingFang SC-中黑体";
			font-weight: 500;
		}

		.state0 {
			background: linear-gradient(180deg,
					#bcd2ff 0%,
					rgba(206, 222, 255, 0) 100%);

			color: #3976f1;
		}

		.state1 {
			background: linear-gradient(180deg,
					#ffe7ac 0%,
					rgba(255, 231, 173, 0) 100%);

			color: #f5b923;
		}

		.state2 {
			background: linear-gradient(180deg,
					rgba(255, 168, 162, 0.4) 0%,
					rgba(247, 99, 89, 0) 100%);

			color: #f76359;
		}

		.item-data {
			position: relative;
			left: 0;
			top: 60rpx;
			z-index: 10;
			width: 100%;
			min-height: 100rpx;
			background: #fff;
			border-radius: 16rpx;

			.data-main {
				box-sizing: border-box;
				padding: 30rpx 37rpx;

				.data-title {
					font-size: 34rpx;
					font-weight: 600;
					color: #34373b;
					margin-bottom: 30rpx;
				}
			}

			.row-item {
				margin-bottom: 20rpx;
				display: flex;
				align-items: center;

				.item-lable {
					display: flex;
					align-items: center;
					min-width: 170rpx;

					.lable-icon {
						height: 26rpx;
						width: 26rpx;

						image {
							height: 100%;
							width: 100%;
							display: block;
						}
					}

					.lable-text {
						margin-left: 10rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #9da2ab;
					}
				}

				.item-value {
					flex: 1;
					font-size: 28rpx;
					font-weight: 400;
					color: #34373b;
				}
			}

			.data-lable-value {
				&>view:last-child {
					margin: 0;
				}
			}
		}

		.data-btn {
			border-top: 1px solid rgba(220, 227, 236, 1);
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			font-weight: 500;
			color: #3976f1;
		}
	}
</style>