【项目难点】实现“请求-使用请求数据继续请求-数据展现”的功能

16 篇文章 0 订阅
7 篇文章 0 订阅

大概就是这样一个需求:首先通过一个id值来获取整个数据列表,然后为每一个数据项通过其数据项的id再去取归国状态,然后展现。
在这里插入图片描述
最后附上整个代码:

<template>
<view id="container">
		<view style="height:30rpx"></view>
        <view class="apply-card" v-for="(apply,index) in applys" :key="apply.application_abroad_id">
            <view >出国类型:{{apply.abroadType}}</view>
            <view >派出国家和地区:{{apply.sendingCountry}}</view>
            <view >国外单位:{{apply.abroadCompany}}</view>
            <view >出境日期:{{formatDate(apply.exitDate)}}</view>  						
			<view >归国状态:{{apply.returnApplyState}}</view>
			
			<view id="buttons">
				<button class="button-item delete"  @click="apply_handler(index)" >申请回国</button>
			</view>						           
        </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//这里
				applys:"",
				
				
			}
		},
		methods: {
			//把状态加到applys里的每个apply中
			getStateList(applys){
				
				for(let i = 0;i<applys.length;i++){
					console.log(i)
					uni.request({
						url:'http://localhost:8081/student/findReturnApplyByOutid',
						method:'GET',
						data:{out_id:applys[i].applicationAbroadId},
					}).then(res=>{
						console.log("for",res)
						if(res[1].data.msg=="查询失败"){
							console.log(i,"未申请归国")
							this.applys[i]['returnApplyState'] = "未申请回国";
							console.log("this.applys[i].returnApplyState",this.applys[i].returnApplyState)
						}else{
							console.log(i,res[1].data.data[0].state);
							this.applys[i]['returnApplyState'] = res[1].data.data[0].state;
							console.log("this.applys[i].returnApplyState",this.applys[i].returnApplyState)
						}	
					}
									
					);
					
				}
			},
			
			async returnState(applicationAbroadId){	
							var returnState;
							await uni.request({
							    url:'http://localhost:8081/student/findReturnApplyByOutid',
							    method:'GET',
								data:{out_id:applicationAbroadId},
							}).then(res=>{
								console.log(res)
								returnState =  res[1].data.data[0].state;});
							return returnState;
			},
			
			formatDate(date){
				var d = new Date(date);//格式化日期
				var formatDate = `${d.getFullYear()}${d.getMonth()+1}${d.getDate()}`	
				return formatDate
			},
			apply_handler(index){
			console.log("this.apply",this.applys[index])
			uni.setStorage({
				key:"return_info",
				data:this.applys[index],							
				success:function(){
					console.log('存储成功')
				}
			});	
				
			//跳转至修改页面
			uni.navigateTo({
				url:'/pages/student/student_abroad/return_info',
				success:function(){
					console.log('跳转出国')
				}
			})
			},
		
			},
		created(){					
					//请求出国申请信息
					      uni.request({
					          url:'http://localhost:8081/student/findSuccessfulGoOutApply',
					          method:'GET',
					      	data:{stu_id:201656777},
					      	success: (res) => {
					      	        console.log("sucess->",res);		      	        
					      	var array  = res.data.data								
							for(let i =0;i<array.length;i++){
								array[i]['returnApplyState'] = "";
							}														
							//调用																													
							this.getStateList(array)		
							//绑定					
							this.applys = array																
					      	    }
					      });
						  
						
											                 
						}
	}
</script>

<style>
    #container{
        display:flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    .apply-card{
        padding: 20rpx;
        border-radius: 20rpx;
        width: 90%;
        box-shadow: 0 0 40rpx -10rpx grey;
		margin-bottom: 10rpx;
    }
	#buttons{
		/* width: 20rpx; */
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		
		height: 50rpx;
	}
	.button-item{		
		width: 140rpx;
		height: 50rpx;
		line-height:50rpx;
		font-size: 20rpx;	
		color: black;
		
	}
	.delete{
		background-color: #55aaff;
		text-align: center;
	}
	.update{
		background-color: #55aaff;
	}
	.commit{
		background-color: #55aaff;
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值