<template>
	<view class="">
		<!-- <u-subsection :list="list" fontSize='30' :current="current" @change="sectionChange"></u-subsection> -->
		<scroll-view :scroll-y="true" upper-threshold='100' @scrolltolower="loadMore">
			<view class="main" v-if="content.length">
				<block v-for="(item, index) in content" :key="index">
					<view class="list u-padding-10">
						<u-row gutter="16">
							<u-col span="4">
								<image class="img" :src="JSON.parse(item.upward_img).A006"></image>
							</u-col>
							<u-col span="8">
								<u-row align="center" class="center">
									<u-col>
										<view class="title">
											{{ item.license_name }}
										</view>
									</u-col>
									<u-col>
										<view class="date">
											进件日期： {{ item.account_date }}
										</view>
									</u-col>
									<u-col>
										<view class="status" style="display: flex;    justify-content: space-between;">
											<view class="">
												进件状态：<span :style="'color:'+item.color+';'">{{item.state==10?'资料上送':
													 item.state==11?'审核中':item.state==12?'审核失败'
													 :item.state==20?'待签约':item.state==21?'签约中':
													 item.state==22?'签约失败':item.state==30?'待实名认证':item.state==31?'实名认证中':
													 item.state==32?'实名认证失败':'已完成'}}</span>
											</view>
											<text @click="sign(item)" v-if="item.state==10"
												style="color:#11a5e8;">资料确认</text>
											<text @click="toSign(item)" v-if="item.state==20"
												style="color:#11a5e8;">申请签约</text>
											<text @click="realName(item)"
												v-if="item.state==30||item.state==31||item.state==32"
												style="color:#11a5e8;">实名认证</text>
											<text @click="realName(item)" v-if="item.state==40"
												style="color:#11a5e8;">实名认证结果</text>
											<!-- toSign -->
										</view>
									</u-col>
								</u-row>
							</u-col>
						</u-row>
					</view>
				</block>
			</view>
			<view class="" v-else style="margin-top: 200px; margin-left: 40%;">
				暂无数据
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		audit_info,
		sign_to_ys,
		account_list
	} from '@/utils/api.js'
	export default {
		data() {
			return { //审核中包含 1进件中（我们平台审核）、2审核中（银盛审核）、3待签约（银盛审核）、4已驳回、5已完成、6
				// list: ['审核中', '已审核', '已驳回'],
				current: 0,
				content: [],
				isSig: false,
				page: 1,
				size: 10
			}
		},
		onShow() {
			this.page = 1; // 初始化页码
			this.size = 10; // 初始化每页条数
			this.content = []; // 初始化内容列表
			this.getlist()
		},
		loadMore() {
			this.page += 1; // 翻到下一页
			this.getlist(); // 重新获取数据
		},
		methods: {
			//进件历史
			getlist() {
				const data = {
					promoter_id: uni.getStorageSync('userInfo').promoter_id || '',
					page: this.page,
					size: this.size
				}
				account_list(data).then(res => {
					if (res.data == null) {
						// 处理没有数据的情况
						console.log('没有更多数据');
					} else {
						// 处理正常数据
						if (res.data.count < this.size) {
							// 如果返回数据小于每页大小，表示数据加载完成
							this.content = this.content.concat(res.data.data); // 合并当前内容
							console.log('已加载所有数据');
						} else {
							this.content = this.content.concat(res.data.data); // 合并数据
						}
					}
					console.log(this.content);
				})
			},
			sectionChange(index) {
				this.current = index;
			},
			//申请签约
			sign(val) {
				//资料确认
				audit_info({
					audit_flag: "Y",
					sys_flow_id: val.sys_flow_id,
					account_id: val.account_id
				}).then(r => {
					if (r.code !== 200) {
						uni.hideLoading()
						this.$u.toast(r.msg)
						return
					} else {
						val.cust_id = r.data.cust_id
						this.toSign(val)
					}
				})
			},
			//签约页面跳转
			toSign(val) {
				if (!val.cust_id) {
					val.cust_id = JSON.parse(val.extend).cust_id
				}
				let _this = this
				const a = JSON.parse(val.rates)
				const params = {
					cust_id: val.cust_id,
					account_id: val.account_id,
					// cust_id:'2024111535691955',
					...a
				}
				sign_to_ys(params).then(result => {
					if (result.code !== 200) {
						_this.$u.toast(result.msg)
						return
					} else {
						_this.sigUrl = result.data.sign_url
						uni.showToast({
							title: "签约申请成功"
						})
						_this.isSig = true
						this.$u.route({
							url: '/pages/index/sign?sigUrl=' + this.sigUrl,
						})
					}

				})
			},
			//实名认证
			realName(val) {
				this.$u.route({
					url: '/pages/mine/auth?val=' + JSON.stringify(val),
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #f8f8f8 !important;
	}

	.center {
		align-items: center;
		justify-content: flex-start;
		display: flex !important;
		flex-direction: column !important;
		margin-left: 25rpx;
	}

	/deep/.u-subsection--button {
		position: fixed;
		z-index: 11;
	}

	.main {
		// background-color: #F4F4F4;
		// padding-top: 60rpx;
		// font-size: 26rpx;
	}

	.main .list {
		margin-top: 10rpx;
		background-color: #ffffff;
	}

	.main .list .img {
		width: 230rpx;
		height: 160rpx;
		border-radius: 14rpx;
	}

	.u-padding-10 {
		padding: 30rpx !important;
	}

	.main .list .title,
	.main .list .date,
	.main .list .status {
		height: 55rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		line-height: 55rpx !important;
		display: flex;
		align-items: center;
		font-size: 26rpx;
	}
</style>