<template>
	<view>
		<van-sticky>
			<view class="top-wrap">
				<view @click="handleBack">
					<van-search disabled use-left-icon-slot shape="round" :value="keyword" placeholder="客户名称/社会信用码">
						<view slot="left-icon">
							<image src="../static/search-icon.png" mode="aspectFill" class="search-icon"></image>
						</view>
					</van-search>
				</view>
			</view>
		</van-sticky>
		<van-empty description="暂无数据" :image="require('@/static/empty.png')" v-if="finished&&list.length===0"/>
		<view class="list-wrap" v-else>
			<approve-list-item v-for="item in list" :key="item.CompanyApprovalId" :data="item"></approve-list-item>
		</view>
	</view>
</template>

<script>
	import {apiCustomeList} from '@/api/approve/custome.js'
	import {apiSealApproveList} from '@/api/approve/seal.js'
	import approveListItem from '../components/approveListItem.vue'
	export default{
		components: {
			approveListItem
		},
		data() {
			return {
				type:'',
				keyword:'',
				list:[],
				page:1,
				finished:false
			}
		},
		onLoad(options) {
			this.type=options.type 
			this.keyword=options.val 
			if(options.type==='custome'){
				this.getCustomeList()
			}else if(options.type==='seal'){
				this.getSealList()
			}
		},
		onReachBottom() {
			if(this.finished) return
			this.page++
			
			if(this.type==='custome'){
				this.getCustomeList()
			}
		},
		methods: {
			handleBack(){
				uni.navigateBack({
					delta:1
				})
			},
			
			// 获取客户搜索数据
			async getCustomeList() {
				const res=await apiCustomeList({
					CurrentIndex:this.page,
					Status:'',
					KeywordEq:this.keyword
				})
				if(res.code===200){
					if(!res.data.List||res.data.List.length===0){
						this.finished=true
					}else{
						let arr=res.data.List.map(item=>{
							//申请类型：申请类型：1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户，5:正式客户申请服务更新
							let applyType=''
							switch(item.ApplyMethod){
								case 1:
									applyType='试用转正式'
									break;
								case 2:
									applyType='冻结转试用'
									break;
								case 3:
									applyType='试用延期'
									break;
								case 4:
									applyType='原销售申领'
									break;
								case 5:
									applyType='服务更新'
									break;	
							}
							return {
								title:item.CompanyName,
								saller:item.ApplyRealName,
								submitTime:item.ApprovalTime,
								approveTime:item.ApproveTime,
								backTime:'',
								cancelTime:'',
								status:item.ApproveStatus,
								applyType:applyType,
								id:item.CompanyApprovalId,
								type:'custome'
							}
						})
						this.list=[...this.list,...arr]
					}
				}
			},
		
			//获取用印数据
			async getSealList(){
				const res=await apiSealApproveList({
					CurrentIndex:this.page,
					Status:'',
					KeywordEq:this.keyword
				})
				if(res.code===200){
					if(!res.data.List||res.data.List.length===0){
						this.finished=true
					}else{
						let arr=res.data.List.map(item=>{
							return {
								title:item.CompanyName,
								saller:item.UserName,
								submitTime:item.CreateTime,
								approveTime:item.ApproveTime,
								cancelTime:item.InvalidTime,
								backTime:'',
								status:item.Status,
								applyType:item.SealType,
								ContractApprovalId:item.ContractApprovalId,
								ContractApprovalRecordId:item.ContractApprovalRecordId,
								type:'seal'
							}
						})
						this.list=[...this.list,...arr]
					}
				}
			}
		},
	}
</script>

<style lang="scss">
	.search-icon {
		width: 40rpx;
		height: 40rpx;
		display: block;
		position: relative;
		top: 4rpx;
		margin-right: 10rpx;
	}
	.list-wrap {
		padding: 20rpx;
	}
</style>
