<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 == 1 && item.upStatus == 1">
						<text class="icon">&#xe830;</text>
						<text>未上架</text>
					</view>
					<view class="state" v-else-if="item.finishStatus == 1 && item.upStatus == 3">
						<text class="icon">&#xe830;</text>
						<text>已下架</text>
					</view>
					<view class="state" v-else-if="item.finishStatus == 1 && item.upStatus == 2 && item.resaleStatus == 0">
						<text class="icon">&#xe830;</text>
						<text>未转售</text>
					</view>
					<view class="state" v-else>
						<text class="icon" style="color: #13ce66">&#xe830;</text>
						<text>已完成</text>
					</view>
				</view>
				<view class="title">{{ item.phone }}</view>
				<view>
					<view style="font-size: 15px;color: #a0a2a6;">
						订单 {{ item.tradeNo }}
					</view>
					<view style="padding-top: 4px;font-size: 15px;color: #a0a2a6;">
						{{ item.goodsNames }} {{ item.totalWeight }}{{ item.goodsUnit }}
					</view>
					<view style="padding-top: 6px;font-size: 17px;color: #ff5722;font-weight: bold;">¥ {{ 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 {
				tab: [
					{
						name: '全部',
						finishStatus: '', //订单完成状态
						upStatus: '', 	  //订单上架状态(1=未上架，2=上架,3=已下架）
						resaleStatus: '', //订单转售状态
					},
					{
						name: '未上架',
						finishStatus: 1,
						upStatus: 1,
					},
					{
						name: '已下架',
						finishStatus: 1,
						upStatus: 3,
					},
					{
						name: '未转售',
						finishStatus: 1,
						upStatus: 2,
						resaleStatus: 0
					}
				],
				param: {
					pageNo: 1,
					pageSize: 10,
					finishStatus: 1,
					upStatus: 1,
				},
				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;
		text-decoration: none;
	}
	.state {
		margin-right: -70px;
	}
</style>
