<template>
	<view class="container mine clearfix">
		<!-- <cu-custom :navbar-data='nvabarData'  @navigateBack="hanldNavigateBack"></cu-custom> -->
		<view class="tui-header-box first"
			:style="{ height: isCmcustomClass == 'fiexd' ? CustomBar + 10 + 'px' : CustomBar + 30 + 'px' }"
			:class="isCmcustomClass">
			<view class="header-top" :style="{ paddingTop: top + 'px', lineHeight: CustomBar + 30 + 'px' }"></view>
			<view class="header-sit"> 
				<text class="iconfont icon-fanhui" @click.stop="this.$api.navigateBack(1)"></text>
				<text class="header-sit-text">子订单详情</text>
			</view>
		</view>
		<view class="tui-header-box"
			:style="{ height: CustomBar + 30 + 'px', backgroundImage: 'url(https://static.caimei365.com/app/crm/image/statistic_bg1.png)' }">
		</view>
		<view class="distinguish-section" :style="{ top: CustomBar - 14 + 'px', left: 0 + 'px' }">
			<view class="distinguish-section-conten">
				<view class="section-top">
					<view class="section-badges">
						<view class="list-title-tip">
							<text class="badges">{{ payment.orderType | formatOrderType }}</text>
						</view>
						<view class="list-title-num">{{ payment.confirmType | StateExpFormat }}</view>
					</view>
					<view class="button" @click="toNoSms('/pages/collection/list')"> 
						<text class="iconfont icon-wodedingdan"></text> 
						收款列表 
					</view>
				</view>
				<view class="section-mid">
					<view class="list-title">
						<view class="list-title-b">订单编号：{{ payment.number }} ( {{ payment.id }} )</view>
						<view class="list-title-b">下单日期：{{ payment.receiptDate }}</view>
						<view class="list-title-b">客户名称：{{ payment.userName }}</view>
						<view class="list-title-b">
							<view class="list-title-b-item ">
								订单金额：￥{{ payment.receiptAmount | NumFormat }}
							</view>
							<view class="list-title-b-item ">
								余额抵扣：￥{{ payment.receiptAmount | NumFormat }}
							</view>
						</view>
						<view class="list-title-b">
							<view class="list-title-b-item ">
								应收金额：￥{{ payment.receiptAmount | NumFormat }}
							</view>
							<view class="list-title-b-item ">
								已收金额：￥{{ payment.receiptAmount | NumFormat }}
							</view>
						</view>
						<view class="list-title-b">
							<view class="list-title-b-item ">
								剩余应收：￥{{ payment.receiptAmount | NumFormat }}
							</view>
							<view class="list-title-b-item ">
								待审金额：￥{{ payment.receiptAmount | NumFormat }}
							</view>
						</view>
						<view class="list-title-b">经理折扣：￥{{ payment.receiptAmount }}(原￥0.00，折扣取消￥0.00)</view>
						<view class="list-title-b">退货退款：￥{{ payment.receiptAmount }}(原￥0.00，折扣取消￥0.00)</view>
					</view>
				</view>
			</view>
		</view>
		<view class="distinguish-button" :style="{paddingBottom :isIphoneX ? '68rpx' : '24rpx'}">
			<view class="button" @click="confirmDistinguish">确认</view>
		</view>
		<!-- 弹窗提示 -->
		<tui-modal :show="modal" @click="handleClick" @cancel="hideMobel" :title="contentModalTitle"
			:content="contentModalText" :button="modalButton" color="#333" :size="32" shape="circle"
			:maskClosable="false">
		</tui-modal>
	</view>
</template>
<script>
	import wxLogin from '@/services/wxLogin.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'

	export default {
		data() {
			return {
				isIphoneX:this.$store.state.isIphoneX,
				nvabarData: {
					//顶部自定义导航
					showCapsule: 1, // 是否显示左上角图标  1表示显示  0表示不显示,
					showSearch: 0,
					title: '', // 导航栏 中间的标题
					haveBack: false,
					home: false,
					textLeft: this.$store.state.isIphone,
					bgColor: '#D33020',
					textColor: '#ffffff'
				},
				payment:{
					id: 6090,
					number: 'W164488903271223',
					receiptAmount: 5000, //收款金额
					associateAmount: 5000, //关联金额
					orderType: 1, //收款类型
					receiptDate: '2022-02-15 10:58:25', // 收款时间
					reviewDate: '2022-02-15 10:58:25', // 审核时间
					smsContent:
						'【中信银行】您尾号0897的中信卡于05月29日14:42，二代支付存入人民币99.00元，当前余额为人民币13871.67元。',
					confirmType: 11,
					userName: '采美网络信息有限公司',
					sourceType: 2,
					state: 1,
					isChecked: false
				},
				modalButton: [{
						text: '取消',
						type: 'gray',
						plain: true //是否空心
					},
					{
						text: '确认',
						customStyle: {
							color: '#fff',
							bgColor: '#4688fa'
						},
						plain: false
					}
				],
				params: {
					type: 1,
					banksType: 1,
					amount: '',
					chargeValue: '',
					remarks: '',
					time: this.$api.getNowFormatDate()
				},
				infoData: {},
				isCmcustomClass: 'left',
				CustomBar: this.CustomBar, // 顶部导航栏高度
				height: 64, //header高度
				top: 0, //标题图标距离顶部距离
				scrollH: 0, //滚动总高度
				opcity: 1,
				isCheckedCharge: false,
				contentModalTitle: '',
				contentModalText: '', //操作文字提示语句
				modal: false,
			}
		},
		onLoad() {
			let obj = {}
			// #ifdef MP-WEIXIN
			obj = wx.getMenuButtonBoundingClientRect()
			// #endif
			// #ifdef MP-BAIDU
			obj = swan.getMenuButtonBoundingClientRect()
			// #endif
			// #ifdef MP-ALIPAY
			my.hideAddToDesktopMenu()
			// #endif
			uni.getSystemInfo({
				success: res => {
					this.width = obj.left || res.windowWidth
					this.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44
					this.top = obj.top ? obj.top + (obj.height - 32) / 2 : res.statusBarHeight + 6
					this.scrollH = res.windowWidth * 0.6
				}
			})
		},
		filters: {
			formatOrderType(value) {
				switch (value) {
					case 1:
						return '自主订单'
						break
					case 2:
						return '协销订单'
						break
					case 3:
						return '客服订单'
						break
				}
			},
			StateExpFormat(state) {
				//订单状态文字和颜色
				var HtmlStateText = '',
					stateTextObject = {
						0: '待确认',
						4: '交易完成',
						5: '订单完成',
						6: '已关闭',
						7: '交易全退',
						77: '交易全退',
						11: '待付款待发货',
						12: '待付款部分发货',
						13: '待付款已发货',
						21: '部分付款待发货',
						22: '部分付款部分发货',
						23: '部分付款已发货',
						31: '已付款待发货',
						32: '已付款部分发货',
						33: '已付款已发货',
						111: '待付款待发货'
					}
				Object.keys(stateTextObject).forEach(function(key) {
					if (key == state) {
						HtmlStateText = stateTextObject[key]
					}
				})
				return HtmlStateText
			},
			NumFormat: function(text) {
				//处理金额
				return Number(text).toFixed(2)
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			bindPickerChange(type, e) {
				// 选择选项
				switch (type) {
					case 1:
						this.paymentTypeText = this.paymentActions[e.target.value].name
						this.params.type = this.paymentActions[e.target.value].value
						console.log('款项类型', this.paymentTypeText)
						console.log('款项类型', this.params.type)
						break
					case 2:
						this.banksTypeText = this.banksActions[e.target.value].name
						this.params.banksType = this.banksActions[e.target.value].value
						console.log('收款类型', this.params.banksType)
						break
				}
			},
			showTuiDateTime() {
				this.$refs.dateTime.show()
			},
			confirmDistinguish() {
				if (this.params.amount == '') {
					this.$util.msg('请输入收款金额', 2000)
					return
				}
				if (this.isCheckedCharge) {
					if (this.params.chargeValue == '') {
						this.$util.msg('请输入手续费', 2000)
						return
					}
				}
				if (this.params.remarks == '') {
					this.$util.msg('请填写收款备注', 2000)
					return
				}
				if (this.params.type == 1) {
					this.contentModalTitle = '确定收款吗？'
					this.contentModalText = '确认前请仔细检查各项数据是否正确，确认收款后将不能进行修改。' //操作文字提示语句
				} else if (this.params.type == 2) {
					this.contentModalTitle = ''
					this.contentModalText = '确定返佣收款吗？' //操作文字提示语句
				} else if (this.params.type == 3) {
					this.contentModalTitle = ''
					this.contentModalText = '确定供应商退款吗？' //操作文字提示语句
				}
				this.modal = true
				console.log('收款')
			},
			handleClick(e) {
				// 确认收款
				if (e.index == 1) {
					this.$api.navigateTo('/pages/collection/detail')
				}
				this.modal = false
			},
			hideMobel() {
				this.modal = false
			},
			checkedCharge() {
				// 勾选手续费
				this.isCheckedCharge = !this.isCheckedCharge
			},
			changeNumber(e) {
				// 校验输入为数字
				if (!this.$api.isNumber(e.detail.value)) {
					this.params.amount = ''
				} else {
					this.params.amount = e.detail.value
				}
			},
			toNoSms(url){
				this.$api.navigateTo(url)
			},
			formatColor(state) {
				//设置邀请码状态亚瑟
				let stateColor = '',
					stateColorObject = {
						0: '#f0ad4e',
						1: '#4cd964',
						2: '#dd524d',
						3: '#007aff'
					}
				Object.keys(stateColorObject).forEach(function(key) {
					if (key == state) {
						stateColor = stateColorObject[key]
					}
				})
				return stateColor
			},
		},
		onPageScroll(e) {
			//实时获取到滚动的值
			if (e.scrollTop > 30) {
				this.isCmcustomClass = 'fiexd'
			} else {
				this.isCmcustomClass = 'left'
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				// this.initSsoMemberCollectionList()
				uni.stopPullDownRefresh()
			}, 200)
		},
		onShow() {
			if (this.hasLogin) {
				this.GetDataInfo()
			}
		}
	}
</script>

<style lang="scss">
	@import '@/uni.scss';

	page {
		background: #fff;
	}

	.tui-header-box {
		width: 100%;
		background: #ffffff;
		z-index: 999;
		background-size: cover;

		&.fiexd {
			position: fixed;
			top: 0;
			left: 0;
			background: #4688fa;
			border-radius: 0 0 20rpx 20rpx;
		}

		&.first {
			background-image: url(https://static.caimei365.com/app/crm/image/statistic_bg2.png);
		}
	}

	.header-top {
		width: 100%;
		font-size: 16px;
		font-weight: 500;
		height: 32px;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		padding: 0 40rpx;
	}

	.header-sit {
		width: 100%;
		box-sizing: border-box;
		height: 80rpx;
		line-height: 80rpx;
		box-sizing: border-box;
		padding: 0 24rpx;
		color: #ffffff;
	
		.header-sit-text {
			text-align: left;
			font-size: $font-size-40;
			font-weight: 600;
			font-family: '正楷';
		}
	
		.icon-fanhui {
			font-size: 42rpx;
			margin-right: 10rpx;
		}
	
		.icon-iconfonticonfontsousuo1 {
			font-size: 42rpx;
			margin-left: 30rpx;
		}
	}

	.mine {
		width: 100%;
		height: 100%;
		position: relative;
	}

	.distinguish-section {
		width: 100%;
		position: absolute;
		padding: 40rpx 20rpx;
		box-sizing: border-box;
	}

	.distinguish-section-conten {
		width: 100%;
		height: auto;
		position: relative;
		background-color: #ffffff;
		border-radius: 20rpx;
		padding: 20rpx;
		box-shadow: 0 10rpx 10rpx 0 rgba(86, 119, 252, 0.2);
		.section-top {
			width: 100%;
			height: 66rpx;
			box-sizing: border-box;
			.section-badges {
				float: left;
				height: 66rpx;
				padding: 13rpx 0;
				.list-title-tip {
					float: left;
					.badges {
						display: block;
						float: left;
						padding: 0 15rpx;
						height: 40rpx;
						line-height: 40rpx;
						border-radius: 4rpx;
						background: radial-gradient(circle, rgba(255, 180, 39, 1) 0%, rgba(245, 142, 77, 1) 100%);
						font-size: $font-size-24;
						text-align: center;
						color: #ffffff;
					}
				}
				.list-title-num {
					float: left;
					text-align: left;
					color: #e15616;
					line-height: 40rpx;
					margin-left: 20rpx;
				}
			}
			.button {
				float: right;
				box-sizing: border-box;
				padding: 0 24rpx;
				height: 100%;
				line-height: 66rpx;
				background: $btn-confirm;
				border-radius: 8rpx;
				text-align: center;
				color: #ffffff;
			}
		}
		.section-mid{
			width: 100%;
			height: auto;
			display: flex;
			flex-direction: column;
			margin: 20rpx 0;
			position: relative;
			.list-title {
				width: 100%;
				height: auto;					
				.list-title-b {
					width: 100%;
					height: 50rpx;
					float: left;
					font-size: $font-size-24;
					line-height: 50rpx;
					color: #999999;
					text-align: left;
					.list-title-b-item {
						width: 50%;
						height: 100%;
						float: left;
					}
				}
			}
		}
	}

	.distinguish-button {
		width: 100%;
		padding-top: 20rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #FFFFFF;
		padding: 0 50rpx;
		.button {
			width: 100%;
			height: 80rpx;
			background: $btn-confirm;
			border-radius: 40rpx;
			text-align: center;
			color: #ffffff;
			line-height: 80rpx;
			font-size: $font-size-28;
			box-shadow: 0 10rpx 14rpx 0 rgba(86, 119, 252, 0.2);
		}
	}

	.uni-badge--small {
		-webkit-transform: scale(0.8);
		-ms-transform: scale(0.8);
		transform: scale(0.8);
		-webkit-transform-origin: center center;
		-ms-transform-origin: center center;
		transform-origin: center center;
	}

	.uni-badge {
		font-family: 'Helvetica Neue', Helvetica, sans-serif;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		font-size: 12px;
		line-height: 1;
		display: inline-block;
		padding: 3px 6px;
		color: #333;
		border-radius: 100px;
		background-color: #f1f1f1;
	}

	.uni-badge-error {
		color: #fff;
		background-color: #dd524d;
	}
</style>
