<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" @click="click" :lineHeight="5"></u-tabs>
		</view>
		<view class="goodsList">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="title">{{ item.buyUserName }}
					<view class="state" v-if="item.finishStatus == 0 && item.peopleConfirmStatus == 0">
						<text class="icon">&#xe830;</text>
						<text>未支付</text>
					</view>
					<view class="state" v-else-if="item.finishStatus == 0 && item.peopleConfirmStatus == 1 && item.applyConfirmStatus == 0">
						<text class="icon">&#xe830;</text>
						<text>未申报</text>
					</view>
					<view class="state" v-else-if="item.finishStatus == 0 && item.Sxb010Status == 1">
						<text class="icon" style="color: #13ce66">&#xe830;</text>
						<text>扣款成功</text>
					</view>
					<view class="state" v-else-if="item.finishStatus == 0 && item.Sxb010Status == 2">
						<text class="icon">&#xe830;</text>
						<text>扣款失败</text>
					</view>
					<view class="state" v-else>
						<text class="icon">&#xe830;</text>
						<text>扣款中</text>
					</view>
				</view>
				<view class="title">{{ item.phone }}</view>
				<view class="con">
					<view style="font-size: 16px;padding-top: 7px;color: #a0a2a6;">
						<text>订单 {{ item.tradeNo }}</text>
					</view>
					<view class="desc">
						<text>{{ item.goodsNames }} {{ item.totalWeight }}{{ item.goodsUnit }}</text>
					</view>
					<view class="price">¥ {{ item.totalPrice }}</view>
				</view>
				<view class="clear"></view>
				<view class="op">
					<view class="date">{{ item.createTime }}</view>
					<template v-if="item.phone">
						<!-- <view class="state" style="color: #3c9cff;" @click="callNumber(item.phone)">拨打电话</view> -->
						<a :href="'tel:'+item.phone" class="an down_btn">拨打电话</a>
					</template>
				</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		data() {
			return {
				user: {},
				tab: [{
						name: '全部',
						peopleConfirmStatus: '', //边民确认状态
						cooperEntrustStatus: '', //互助委托申报确认状态
						applyConfirmStatus: '',  //进口申报确认状态
						finishStatus: 0, //订单完成状态
						upStatus: '', 	  //订单上架状态
						resaleStatus: '', //订单转售状态
						Sxb010Status: '', //扣款回执状态
					},
					{
						name: '未支付',
						peopleConfirmStatus: 0,
						finishStatus: 0,
					},
					{
						name: '未申报',
						peopleConfirmStatus: 1,
						applyConfirmStatus: 0,
						finishStatus: 0,
					},
					{
						name: '扣款成功',
						Sxb010Status: 1,
						finishStatus: 0,
					},
					{
						name: '扣款失败',
						Sxb010Status: 2,
						finishStatus: 0,
					}
				],
				param: {
					pageNo: 1,
					pageSize: 10,
					finishStatus: 0
				},
				list: [],
				loadMore: true,
				id: '',
				flag: '',
			};
		},
		onShow() {
			this.getData();
		},
		methods: {
			getData() {
				this.http.request({
					url: '/level-one-server/app/TbOrder/getPeopleOrderList',
					loading: 'false',
					data: this.param,
					success: res => {
						this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
						if (res.data.data) {
							this.list = res.data.data;
						}
					}
				});
			},
			// 点击tab切换
			click(e) {
				console.log(e);
				this.param.peopleConfirmStatus = e.peopleConfirmStatus;
				this.param.cooperEntrustStatus = e.cooperEntrustStatus;
				this.param.applyConfirmStatus = e.applyConfirmStatus;
				this.param.finishStatus = e.finishStatus;
				this.param.resaleStatus = e.resaleStatus;
				this.param.upStatus = e.upStatus;
				this.param.Sxb010Status = e.Sxb010Status;
				this.refresh();
			},
			// 刷新数据
			refresh() {
				this.loadMore = true;
				this.param.pageNo = 1;
				this.list = [];
				this.getData();
			},
			callNumber(phone) {
				permision.gotoAppPermissionSetting();
				uni.makePhoneCall({
					phoneNumber: phone,
					success: function(ress) {
						console.log("拨打电话成功！",JSON.stringify(ress))
					},
					fail: function() {
						console.log("拨打电话失败！")
					}
				})
				/* plus.android.requestPermissions(
					["android.permission.CALL_PHONE"],
					function(resultObj) {
						var result = 0;
						for (var i = 0; i < resultObj.granted.length; i++) {
							var grantedPermission = resultObj.granted[i];
							console.log('已获取的权限：' + grantedPermission);
							result = 1
						}
						for (var i = 0; i < resultObj.deniedPresent.length; i++) {
							var deniedPresentPermission = resultObj.deniedPresent[i];
							console.log('拒绝本次申请的权限：' + deniedPresentPermission);
							result = 0
						}
						for (var i = 0; i < resultObj.deniedAlways.length; i++) {
							var deniedAlwaysPermission = resultObj.deniedAlways[i];
							console.log('永久拒绝申请的权限：' + deniedAlwaysPermission);
							result = -1
						}
						console.log(result);
						if(result == 1){
							uni.makePhoneCall({
								 phoneNumber: "10086",//电话号码
								success(ress) {
									console.log("拨打电话成功",JSON.stringify(ress))
								},
								fail(err) {
									console.log("拨打电话失败",'err')
								}
							});
						}else{
							uni.showToast({
								title:"请开启拨号权限",
								icon:"error",
							})
						}
					},
					function(error) {
						console.log('申请权限错误：' + error.code + " = " + error.message);
					}
				); */
			},
		},
		//下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.refresh();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		//上拉加载
		onReachBottom() {
			if (this.loadMore) {
				this.param.pageNo++;
				this.getData();
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: $pg;
	}
	.down_btn {
		color: #f0f4f7;
		width: 66px;
		background-color: #3c9cff;
		text-align: center;
		border-radius: 10px;
		font-size: 14px;
		padding: 3px 5px;
	}
	.state {
		margin-right: -70px;
	}
</style>
