<template>
	<div class="g_pb_32">
		<div v-for="(item, index) in applyList">
			<div class="g_pb_8 g_pt_16 g_pl_16 g_border_e_b g_c_9" v-if="item.length > 0">
				{{ index == "near" ? "近三天" : "三天前" }}
			</div>
			<div class="g_flex_row_between flex_center i-items" style="padding: 20px 16px 8px" v-for="i in item" :key="item.id">
				<div class="g_mr_12">
					<img class="g_w_48 g_h_48 g_radius_50" :src="i.imgSrc || 'https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/dailibaoming/APP/default.svg'" alt="" />
				</div>
				<div class="g_flex_row_between flex_center g_flex_1 g_h_48">
					<div>
						<div class="g_fs_18">
							{{ i.applyUsername }}
						</div>
						<div class="g_fs_14 g_c_9 g_mt_4">
							{{ i.userName }}
						</div>
					</div>
					<div>
						<span v-if="i.past && i.status === 0" class="g_fs_14 g_c_9">已过期</span>
						<span v-else-if="i.status == 1" class="g_fs_14 g_c_9">已通过</span>
						<span v-else-if="i.status == 2" class="g_fs_14 g_c_9">已拒绝</span>
						<div class="g_flex_row_end" v-else>
							<div class="g_mr_8">
								<rh-button primaryColor='#3578f6' btnText="拒绝" fontSize="14" color="#000" customBgColor="#d8d8d8" size="height" type="disabled" height="24" width="50" @clickBtn="approve(i, 'reject')"></rh-button>
							</div>
							<div>
								<rh-button primaryColor='#3578f6' btnText="通过" type="primary" fontSize="14" size="height" height="24" width="50" @clickBtn="approve(i, 'resolve')"></rh-button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			applyList: [],
			query: { page: 1, size: 30 },
		};
	},
	onShow() {
		this.getUserApplyList();
		this.setTeamManagerStatus();
	},
	created() {},

	methods: {
		setTeamManagerStatus() {
			this.G.Get(this.api.order_updateApplyNumHasViewed, {}, (res) => {
        uni.$emit('updateMember')
      });
		},
		getUserApplyList() {
			let that = this;
			this.G.Post(this.api.order_getUserApplyList, { pageNum: that.query.page, pageSize: that.query.size }, (res) => {
				console.log("order_getUserApplyList", res);
				let obj = {
					near: [],
					far: [],
				};
				res.forEach((item) => {
					let diffTime = new Date().getTime() - item.createTime;
					if (diffTime <= 3 * 24 * 60 * 60 * 1000) {
						obj.near.push(item);
					} else {
						if (diffTime > 10 * 24 * 60 * 60 * 1000) {
							item.past = true;
						} else {
							item.past = false;
						}
						obj.far.push(item);
					}
				});
				that.applyList = obj;
			});
		},
		approve(_item, type) {
			console.log(_item);
			console.log(type);
			// return;
			this.G.Post(this.api.order_userApplyApprove, { id: _item.id, status: type == "reject" ? 2 : 1 }, (res) => {
				console.log(res);
				_item.status = type == "reject" ? 2 : 1;
				uni.showToast({
					title: "操作成功",
					icon: "none",
				});
			});
		},
	},
};
</script>

<style lang="scss">
.i-items {
	// border-bottom: 1px solid #eee;
	position: relative;
	&:not(:first-child):after {
		content: "";
		display: block;
		height: 1rpx;
		width: calc(100% - 76px);
		background: #eee;
		position: absolute;
		bottom: 0;
		right: 0;
	}
	// &:last-child:after {
	// 	border-bottom: none;
	// }
}
</style>
