<template>
	<view>
		<u-tabs
		 ref="jputabs"
		 class="jputabs" name="cate_name" gutter="200" bar-width="100" active-color="#101010"
			inactive-color="#A1A1A1" :list="tabList" :is-scroll="false" :current="current" @change="change"></u-tabs>

		<ujp-navbar title="收益核算" style="margin-bottom: 40px;">
			<view slot="right"  v-if="current==1&&info.applicationType==1">
				
				<view  @click="copyItem()"
				 style="margin-right: 10px;" >
					生成副表<u-icon name="plus"></u-icon>
				
				</view>
			</view>
		</ujp-navbar>

		<template v-if="current==0">
			<view class="withdraw">
				<view class="withdraw-head">
					<b class="asterisk"><text>*</text>申请站点</b>
					<span>
						<ujp-picker mode="selector" v-model="isswitchshow"
						 :range="stationList" range-key="name" 
						:default-selector="[stationObj.index]"
						 @confirm="switchBtn" ></ujp-picker>
						
						<view class="uni-input" @click="isswitchshow=true">
								<view class="input-text">
									{{stationObj.name?stationObj.name:'无站点'}}
								</view>
								<view class="iconfont more">
									&#xe600;
								</view>
							</view>


					</span>
				</view>
				<view class="withdraw-head">
					<b class="asterisk"><text>*</text>提现事由</b>
					<span>
						<picker @change="bindPickerChange2" range-key="name" :range="applicationList">
							<view class="uni-input">{{info.applicationTypeText}}<text
									class="iconfont more">
									&#xe600;
								</text></view>
						</picker>

					</span>
				</view>
				<view class="withdraw-head" v-if="info.applicationType!=3">
					<b class="asterisk"><text>*</text>提现账户</b>
					<span>
						<picker @change="bindPickerChange5" range-key="name" :range="userList">
							<view class="uni-input">{{selectAccUser.name?selectAccUser.name:'无账户'}}<text
									class="iconfont more">
									&#xe600;
								</text></view>
						</picker>
				
					</span>
				</view>
				
				<view class="withdraw-head">
					<b class="asterisk"><text>*</text>提现月份</b>
					<span>
						<picker @change="bindPickerChange3" mode="date" fields="month" 
							:value="thismonth">
							<view class="uni-input">{{showTime(thismonth)}}<text class="iconfont more">
									&#xe600;
								</text></view>
						</picker>

					</span>
				</view>
				
				<view >
					<!-- 个人桩 -->
					<view class="withdraw-head" v-if="!isSecond" >
						<b class="asterisk">抄表开始日期</b>
						<u-picker  
						:default-time="info.startTime2"
						ref="ucalendar" v-model="showcalendar2" 
						mode="time" :params="params" @confirm="bindPickerChange6"
						></u-picker>
						
						<span  >
							
								<view class="uni-input uni-time" @click="showcalendar2=true">{{showTime2(info.startTime2)}}<text class="iconfont more">
										&#xe600;
									</text>
							</view>
							
						</span>
						
					</view>
					<view class="withdraw-head"  v-else >
						<b class="asterisk">抄表开始日期</b>
						<span>
							<view class="uni-input uni-time">{{showTime2(info.startTime2)}}</view>
						</span>
					</view>
					<view class="withdraw-head" v-if="!isSecond" >
						<b class="asterisk">抄表截止日期</b>
						<u-picker  
						:default-time="info.endTime2"
						ref="ucalendar" v-model="showcalendar" 
						mode="time" :params="params" @confirm="bindPickerChange4"
						></u-picker>
						
						<span  >
							
								<view class="uni-input uni-time" @click="showcalendar=true">{{showTime2(info.endTime2)}}<text class="iconfont more">
										&#xe600;
									</text>
							</view>
							
						</span>
						
					</view>
					<view class="withdraw-head"  v-else >
						<b class="asterisk">抄表截止日期</b>
						<span>
							<view class="uni-input uni-time">{{showTime2(info.endTime2)}}</view>
						</span>
					</view>
				</view>
				
				<view class="withdraw-head " v-if="false">
					<b>充电收入</b><span class="classFFF">{{info.chargingIncome}}元</span>
				</view>
				<view class="withdraw-head border-n" v-if="info.applicationType==3">
					<b>分润提现明细</b><span class="download"  @click="ckdownload" >
						<u-icon name="download"></u-icon> 下载订单详情
					</span>
				</view>
			</view>

			<view class="withdraw" v-if="info.applicationType!=2">
				
				<view class="withdraw-head" v-if="info.applicationType==1" >
						<b class="asterisk"><text>*</text>物业是否交电费</b>
						<span>
							<u-radio-group  v-model="info.bearElecMoney">
					
								<u-radio v-for="(item, index) in list2" :key="index+'a'"
									:name="item.value"  active-color="blue">
					
									{{item.name}}
					
								</u-radio>
					
							</u-radio-group>
						</span>
				</view>
			
				
				<view class="withdraw-head" v-if="info.applicationType!=2&&!isSecond" >
					<b class="asterisk"><text>*</text>电价</b>
					<text class="unit" style="float: right;font-size: 16px;">元/度</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px" v-model="info.electricityPrice" 
						maxlength="10"
						placeholder="请填写价格" input-align="left"
							type="digit">

						</u-input>
					</span>
				</view>
				<view class="withdraw-head" v-else>
					<b class="asterisk">电价</b>
				
					<span class="withdraw-input classFFF" style="width: 63%;">
				
						{{info.electricityPrice}}元/度
				
					</span>
				
				</view>
				
				<view class="withdraw-head">
					<b class="asterisk">预估电量</b>
				
					<span class="withdraw-input classFFF" style="width: 63%;">
				
						{{info.estimateElectricQuantity}}度
				
					</span>
				
				</view>
			
				<view class="withdraw-head" v-if="info.applicationType!=2&&!isSecond" >
					<b class="asterisk">电量</b>
					<text class="unit" style="float: right;font-size: 16px;">度</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px" placeholder="请填写实际电量"
						 maxlength="10"
						  @input="ckInput_Q"
						 v-model="info.electricQuantity" input-align="left"
							type="digit">

						</u-input>


					</span>

				</view>
				<view class="withdraw-head" v-else>
					<b class="asterisk">电量</b>
				
					<span class="withdraw-input classFFF" style="width: 63%;">
						{{info.electricQuantity}}度		
					</span>
				
				</view>
				
				<view class=" "  v-if="info.applicationType!=2&&!isSecond" >
					 
					电费参考值(电量*电价)
					<span style="margin-left: 20rpx;" >
						
						<span class="classFFF" v-if="info.electricQuantity&&info.electricityPrice">{{info.electricQuantity*info.electricityPrice}}元</span>
						<span class="classFFF" v-else>自动计算出结果</span>
					</span>
				
				</view>
				
				<view class="withdraw-head" v-if="info.applicationType!=2&&!isSecond" >
					<b class="asterisk">电费</b>
					<text class="unit" style="float: right;font-size: 16px;">元</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px" placeholder="请填写实际电费"
						 maxlength="10"
						 
						 v-model="info.electricityCost" input-align="left"
							type="digit">
				
						</u-input>
				
				
					</span>
				
				</view>
				<view class="withdraw-head" v-else>
					<b class="asterisk">电费</b>
				
					<span class="withdraw-input classFFF" style="width: 63%;">
						{{info.electricityCost}}元		
					</span>
				
				</view>
				
				
				<view class="withdraw-head border-n" v-if="false">
					<b>电费</b>
					<text class="unit" style="float: right;font-size: 16px;"></text>
					<span class="withdraw-input" style="width: 63%;">
						<view class="classFFF" v-show="electricityPriceX">{{electricityPriceX}}元</view>
						<view class="classFFF" v-show="!electricityPriceX">自动计算出结果</view>
					</span>

				</view>

			</view>
			
			<view class="withdraw"  v-if="info.applicationType!=2">
			<view class="withdraw-head border-n">
				<b>桩主/站主总收入
				
				</b>
				<span  class="classFFF" >
				<view class="uni-input">	{{(info.chargingProfitAmount+info.monthlyCardIncome).toFixed(2)}}元</view> 
			
				</span>
			</view>
			<view class="withdraw-head border-n">
				<b>桩主/站主收益
				
				</b>
				<span  class="classFFF" >
					<view class="uni-input"  v-show="electricityPriceX">{{(info.chargingProfitAmount+info.monthlyCardIncome-electricityPriceX).toFixed(2)}}元
						<view class="tooltip tooltipleft">
							<u-icon name="info-circle"></u-icon>
							  <view class="tooltiptext" style="width: 280px;">桩主/站主收益=充电服务收入+折扣卡收入-电费</view>
						
						</view> 
					</view> 
					<view class="classFFF" v-show="!electricityPriceX">自动计算出结果</view>
					
					
				</span>
				
			</view>
			</view>
			<view class="withdraw"  v-if="info.applicationType!=2">

			
				<view class="withdraw-head">
					<b>充电收入</b>
					<span  class="classFFF" >
						{{info.chargingProfitAmount?info.chargingProfitAmount.toFixed(2):0}}元

					</span>
				</view>
				<view class="withdraw-head">
					<b>充电分润比例</b>
					<span  class="classFFF" >
						{{info.chargingPercent}}%
				
					</span>
				</view>
				<view class="withdraw-head border-n">
					<b>充电收益</b>
					<span>
						<view class="classFFF" v-show="electricityPriceX">{{(info.chargingProfitAmount-electricityPriceX).toFixed(2)}}元</view>
						<view class="classFFF" v-show="!electricityPriceX">自动计算出结果</view>			
					</span>
				</view>

			</view>
			<view class="withdraw"  v-if="info.applicationType!=2">

				<view class="withdraw-head">
					<b>折扣卡分润笔数</b>
					<span  class="classFFF"  >
						{{info.monthlyCardTotal}}笔

					</span>
				</view>
				<view class="withdraw-head border-n">
					<b>折扣卡收益</b>
					<span  class="classFFF" >
						{{info.monthlyCardIncome?info.monthlyCardIncome.toFixed(2):0}}元

					</span>
				</view>

			</view>

			<view class="withdraw"  v-if="info.applicationType==2"  >
				
				<view class="withdraw-head border-n">
					<b>桩主/站主收益
					
					</b>
					<span  class="classFFF" >
						<view class="uni-input"  v-show="electricityPriceX">{{(info.chargingProfitAmount+info.monthlyCardIncome-electricityPriceX).toFixed(2)}}元
							<view class="tooltip tooltipleft">
								<u-icon name="info-circle"></u-icon>
								  <view class="tooltiptext" style="width: 280px;">桩主/站主收益=充电服务收入+折扣卡收入-电费</view>
							
							</view> 
						</view> 
						<view class="classFFF" v-show="!electricityPriceX">自动计算出结果</view>
						
						
					</span>
					
				</view>
				
				<view class="withdraw-head" >
				
					<b class="asterisk"><text>*</text>市场奖励比例</b>
					<text class="unit" style="float: right;font-size: 16px;">%</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px" placeholder="请填写比例"
						 maxlength="10"
						 v-model="info.rewardProportion" input-align="left"
							type="digit">
					
						</u-input>
					</span>
				</view>
				
			
				<view class="withdraw-head border-n"  >
					<b>奖励提成</b>
					<span   >
						
						<view class="classFFF" v-if="electricityPriceX&&info.rewardProportion">
						{{((info.chargingProfitAmount+info.monthlyCardIncome-electricityPriceX)*info.rewardProportion/100).toFixed(2)}}元</view>
						<view class="classFFF" v-else>自动计算出结果</view>
						
					</span>
				</view>
				<view class="withdraw-head border-n">
					<b>大写金额</b>
				
					<span class="withdraw-input" style="width: 63%;">
				
						<view  class="classFFF" v-if="electricityPriceX&&info.rewardProportion">
						{{applicationAmountDX2(((info.chargingProfitAmount+info.monthlyCardIncome-electricityPriceX)*info.rewardProportion/100).toFixed(2))}}
						</view>
						<view class="classFFF" v-if="!(electricityPriceX&&info.rewardProportion)">自动转换</view>
				
				
				
					</span>
				</view>
				
			</view>	
			<view class="withdraw" v-if="info.applicationType==1">

					<view class="withdraw-head">
						<b>提现类型</b><span>
							<u-radio-group  v-model="info.withdrawalType">
					
								<u-radio v-for="(item, index) in list3"  :key="index+'a'"
									:name="item.value"  active-color="blue">
					
									{{item.name}}
					
								</u-radio>
					
							</u-radio-group>
						</span>
					</view>
					
				
				<view class="withdraw-head" v-show="info.withdrawalType==0">
					<b class="asterisk"><text>*</text>分润比例</b>
					<text class="unit" style="float: right;font-size: 16px;">%</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px" placeholder="请填写比例"
						 maxlength="10"
						 v-model="info.rewardProportion" input-align="left"
							type="digit">
					
						</u-input>
					
					
					</span>
				</view>
				<view class="withdraw-head border-n" v-show="info.withdrawalType==0" >
					<b class="asterisk"><text>*</text>物业分润收入</b>
					<span   >
						
						<view class="classFFF" v-if="electricityPriceX&&info.rewardProportion">
						{{((info.chargingProfitAmount+info.monthlyCardIncome-electricityPriceX)*info.rewardProportion/100).toFixed(2)}}元</view>
						<view class="classFFF" v-else>自动计算出结果</view>
						
					</span>
				</view>
				
				<view class="withdraw-head " v-show="info.withdrawalType==1">
					<b class="asterisk"><text>*</text>停车费</b>
					<text class="unit" style="float: right;font-size: 16px;">元</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px" v-model="info.parkingFee" maxlength="10" placeholder="请填写金额" input-align="left"
							type="digit">
				
						</u-input>
				
				
					</span>
				
				</view>
			</view>
		
			
			<view class="withdraw" v-if="info.applicationType==3&&(info.applyAmount1||info.applyAmount2||info.publicMaintenanceAmount)" >
			
				<view class="withdraw-head" v-if="info.applyAmount1">
					<b>物业可提现金额</b>
					<span>
						<view class="uni-input">{{info.applyAmount1}}元</view>
			
					</span>
				</view>
				<view class="withdraw-head border-n" v-if="info.applyAmount2">
					<b>市场可提现金额</b>
					<span>
						<view class="uni-input">{{info.applyAmount2}}元</view>
			
			
					</span>
				</view>
				<view class="withdraw-head" v-if="info.publicMaintenanceAmount">
					<b>公共维护费</b>
					<span>
						<view class="uni-input">{{info.publicMaintenanceAmount}}元</view>
							
					</span>
				</view>
				</view>
			<view class="withdraw" >


				<view class="withdraw-head">
					<b>是否开票</b><span>
						<u-radio-group  v-model="info.invoiceRequired">

							<u-radio v-for="(item, index) in list2" :key="index+'a'"
								:name="item.value"  active-color="blue">

								{{item.name}}

							</u-radio>

						</u-radio-group>
					</span>
				</view>
				<view class="withdraw-head" v-if="info.invoiceRequired=='1'" >
				
					<b  class="asterisk"><text>*</text>发票类型</b>
					<span>
						<u-radio-group  v-model="info.invoiceType" >

							<u-radio v-for="(item, index) in list1" :key="index+'a'" :name="item.value"
								:disabled="item.disabled" active-color="blue">

								{{item.name}}

							</u-radio>

						</u-radio-group>
					</span>
				</view>
				<view class="withdraw-head border-n"  v-if="info.invoiceRequired=='1'&&info.invoiceType==1">
				
					<b  class="asterisk"><text>*</text>发票税率</b>
					
				
					<text style="float: right;font-size: 16px;">%</text>
					<span class="withdraw-input" style="width: 58%;">
						<u-input height="20px"  v-model="info.taxRate"
						placeholder="请输入开票税率" input-align="left"
						 maxlength="10"
						 type="digit">
						</u-input>
					</span>

				</view>

			</view>
			
			
			<view class="withdraw"  v-if="info.applicationType!=2">
				
				<view class="withdraw-head " v-if="info.applicationType==3&&applicationAmountTest">
					<b class="asterisk">是否扣除电费</b>
					<span class="withdraw-input" style="width: 63%;">
						<u-button size="mini"  type="primary"  v-if="applicationAmountTestBl"
						 @click="coCost" >扣除电费</u-button>
						<u-button size="mini"  v-else
						 type="warning"  @click="reCost">还原金额</u-button>
					</span>
				</view>
				<view class="withdraw-head ">
					<b class="asterisk"><text>*</text>申请提现金额</b>
					<text class="unit" style="float: right;font-size: 16px;">元</text>
					<span class="withdraw-input" style="width: 63%;">
						<u-input height="20px"
						 @input="ckInput_f"
						 v-model="info.applicationAmount" maxlength="10" placeholder="请填写金额" input-align="left"
							type="digit">

						</u-input>


					</span>

				</view>
				<view class="withdraw-head border-n">
					<b>大写金额</b>

					<span class="withdraw-input" style="width: 63%;">

						<view  class="classFFF" v-show="applicationAmountDX">{{applicationAmountDX}}</view>
						<view class="classFFF" v-show="!applicationAmountDX">自动转换</view>



					</span>
				</view>
				
			
			</view>

		
			<view class="withdraw"  v-if="info.applicationType==3" >
				<view class="withdraw-head ">
					<b class="asterisk"><text>*</text>收款户名</b>
					<u-input class="textarea" type="textarea" 
					v-model="info.accountName"
					placeholder="请填写收款户名" height="96" cursor-spacing="8" />

				</view>
				<view class="withdraw-head ">
					<b class="asterisk"><text>*</text>收款银行</b>
					<u-input class="textarea" type="textarea"
					v-model="info.bankName"
					 placeholder="请填写收款银行全称" height="96" cursor-spacing="8" />

				</view>
				<view class="withdraw-head border-n">
					<b class="asterisk"><text>*</text>收款账号</b>
					<u-input class="textarea" v-model="info.accountNo"
					type="textarea" placeholder="请填写收款账号" height="96" cursor-spacing="8" />

				</view>
				<view class="withdraw-head">
					
					<b>是否为你自动申请提现</b>
					<span style="min-width: 30%;">
						<u-checkbox-group  >
				
							<u-checkbox 
							 	v-model="checked" 
							 active-color="blue">
				
								
				
							</u-checkbox>
				
						</u-checkbox-group>
					</span>
				</view>

			</view>

		</template>


		<template v-if="current==1">
			<view class="details withdrawHead" v-if="detailList.length&&info.applicationAmount">
				申请提现金额：{{info.applicationAmount}}元<br/>
				明细金额合计：<span :class="{
					red:itemApplicationAmountSum>parseFloat(info.applicationAmount)
				}">{{itemApplicationAmountSum}}元</span>
			</view>
			<view class="details" v-for="(item,i) in detailList" :key="i" >
				<view class="withdraw">
					<view class="withdraw-head">
						<b class="asterisk"><text>*</text>项目</b>
						<text class="unit" style="float: right;font-size: 16px;z-index: 99;"  @click="delItem(i)">
							<i class="ri-indeterminate-circle-fill" style="color: red;font-size: 24px;"></i>
						</text>
						<span class="withdraw-input" style="width: 80%;">
							<u-input height="20px" 
							v-model="item.itemName"
							placeholder="请填写项目名称" input-align="left" >

							</u-input>


						</span>

					</view>
					<view class="withdraw-head border-n">
						<b class="asterisk"><text>*</text>金额</b>
						<text class="unit" style="float: right;font-size: 16px;">元</text>
						<span class="withdraw-input" style="width: 80%;">
							<u-input height="20px"
							 v-model="item.itemAmount"
							 placeholder="请填写价格"
							  maxlength="10"
							  input-align="left" type="digit">

							</u-input>


						</span>

					</view>
					<view class="withdraw-head border-n">
						<b>备注</b>

						<span class="withdraw-input" style="width: 80%;">
							<u-input height="20px"
							 v-model="item.itemRemark"
							 placeholder="请填写备注信息" input-align="left">

							</u-input>


						</span>

					</view>
				</view>

			</view>
			<view class="add" @click="addItem" ><i class="ri-add-circle-fill"></i><text>增加项目</text></view>
		</template>
		<view class="applyBtn" v-if="isReady">
			<u-button class="save" @click="submit(-2)">保存草稿</u-button>
			<u-button class="submit" @click="submit(5)">提交核算结果</u-button>
		</view>
		<view class="applyBtn" v-else>
			
			<u-button class="submit2" @click="test" >请先核算[物业方结算]</u-button>
		</view>
	</view>
</template>


<script>
	import * as API from '@/apis/finance.js'
	import * as API_common from '@/apis/common.js'
	

	import {
		beforeTimeStamp,
		parseUnixTime,
		substrMb,
		DX,newDate
	} from '@/utils'
	export default {
		data() {
			return {
				checked:true,
				isSecond:false,
				showcalendar:false,
				showcalendar2:false,
				applicationAmountTest:0,
				applicationAmountTestBl:true,
				isswitchshow:false,
				id:'',
				uuid:'',
				isPt: false,
				detailList:[],
				info: {
					electricityPrice: '',
					electricQuantity: '',
					stationId: "",
					applicationType: '1'
				},
				applicationList: [
					
					{
						name: '物业方结算',
						value: "1"
					},
					{
						name: '市场奖励',
						value: "2"
					},
					{
						name: '公共维护费',
						value: "2.5"
					}
					,
					{
						name: '利润提现',
						value: "3"
					}
				],

				stationList: [],
				queryTime: '',
				nowTime: '',
				stationObj: {
					index:0
				},
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false,
					timestamp: false,
				},
				list1: [
					{
						name: '收据',
						value: "3"
					},{
					name: '普票',
					value: "1"
				},
				// {
				// 	name: '专票',
				// 	value: "2"
				// },
				],
				list2: [{
					name: '是',
					value: "1"
				}, {
					name: '否',
					value: "0"
				}],
				list3: [{
					name: '服务费提成',
					value: "0"
				}, {
					name: '停车费',
					value: "1"
				}],
				tabList: [{
					name: '申请单主表'
				}, {
					name: '提现明细'
				}],
				startTime:'',
				endTime:'',
				thismonth:'',
				userList:[],
				selectAccUser:{},
				isReady:true,
			}
		},
		onLoad(op){
			if(op.id){
				this.id=op.id
			}
			this.uuid=op.uuid;
		},
		onShow() {


		},
		onReady() {
			
			this.nowTime = parseUnixTime(new Date(), '{y}-{m}-{d}')
			var currentDate = new Date();
			var currentMonth=currentDate.getMonth();
			var lastMonthDate = new Date(currentDate.setMonth(currentMonth - 1));

			this.thismonth= parseUnixTime(lastMonthDate, '{y}-{m}')
			this.endTime =parseUnixTime(new Date(), '{y}-{m}-{d} {h}:{i}:00')
			this.getStationList()
		},
		computed: {
			 
			itemApplicationAmountSum(){
				if (this.info.applicationAmount&&this.detailList&&this.detailList.length) {
					var applicationAmount=0;
					for(var i in this.detailList){
						var obj=this.detailList[i]
						var itemAmount=obj.itemAmount?obj.itemAmount:0
						applicationAmount+=parseFloat(itemAmount)
					}
					 
 					if(applicationAmount){
						return parseFloat(applicationAmount).toFixed(2)
					}else {
						return '0'
					}
				}else{
					return '0'
				}
				
			},
			applicationAmountDX() {
				if (this.info.applicationAmount) {
					var c = DX(this.info.applicationAmount)
					return c
				} else {
					return ''
				}
			},
			
			electricityPriceX() {
				
				return  this.info.electricityCost
			}
		},
		watch:{
			
			detailList(nVal, oVal) {
				
				var obj=[
					{
						name: '申请单主表'
					}, {
						name: '提现明细'
					}
				]
			
				if(nVal&&nVal.length){
					obj[1].count=nVal.length
				}
			 
				this.tabList=obj
			
			
			
			}
			
		},
		methods: {
			coCost(){
				this.info.applicationAmount=(this.info.applicationAmount-(this.info.electricityCost?this.info.electricityCost:0)).toFixed(2)
				this.applicationAmountTestBl=false
			},
			reCost(){
				this.info.applicationAmount=this.applicationAmountTest
				this.applicationAmountTestBl=true
			},
			
			ckInput_Q(text) {
				if (text.indexOf('.') > 0) {
					
					var k =text.split(".")[1]
					if(k.length>=3){
						this.$nextTick(()=>{
							text=parseFloat(text).toFixed(2);
							this.info.electricQuantity= text
						})
					}
				}
				var t = Number(text);
				if (t < 0) {
					this.$nextTick(() => {
						this.info.electricQuantity = '';
					})
					
				}
				
			},
			
			ckInput_f(text) {
				if (text.indexOf('.') > 0) {
					
					var k =text.split(".")[1]
					if(k.length>=3){
						this.$nextTick(()=>{
							text=parseFloat(text).toFixed(2);
							this.info.applicationAmount= text
						})
					}
				}
				var t = Number(text);
				if (t < 0) {
					this.$nextTick(() => {
						this.info.applicationAmount = '';
					})
					
				}
				
			
			},
			applicationAmountDX2(val) {
				if (val) {
					var c = DX(val)
					return c
				} else {
					return ''
				}
			},
			test(){
				console.log(this.checked)
			},
			copyItem(){
				if(this.info.applicationType==1){
					
					if(this.detailList==null){
						this.detailList=[];
					}
					//var key=-1;
					var obj={};
					// for(var i in this.detailList){
					// 	var obj=this.detailList[i]
						
					// 	if(this.info.withdrawalType==0&&obj.itemName=="提成比例(自动生成)"){
					// 		key=i;
					// 	}
					// 	if(this.info.withdrawalType==1&&obj.itemName=="停车费(自动生成)"){
					// 		key=i;
					// 	}
					// }
					if(this.info.withdrawalType==0){
						var itemAmount=0;
						if(this.electricityPriceX&&this.info.rewardProportion){
							itemAmount=((this.info.chargingProfitAmount+this.info.monthlyCardIncome-this.electricityPriceX)*this.info.rewardProportion/100).toFixed(2);
						}
						var itemRemark=""
						if(this.info.rewardProportion){
							itemRemark="比例"+this.info.rewardProportion+"%"
						}
						obj={
							itemName:"提成比例",
							itemRemark:itemRemark,
							itemAmount:itemAmount,
						}
					}else{
						obj={
							itemName:"停车费",
							itemRemark:'',
							itemAmount:this.info.parkingFee,
						}
					}
					this.detailList.push(obj)
					
				
				}
			},
			addItem(){
				this.detailList.push({})
			},
			delItem(i){
				
				this.detailList.splice(i,1)
			},
			submit(status){
				this.info.isSecond=(this.isSecond?1:0)
				 this.info.applicationMonth= this.thismonth
				 
				 if(this.electricityPriceX){
					 this.info.electricityCost=this.electricityPriceX
					 
				 }
				
				if(this.info.applicationType==2){
					if(this.info.rewardProportion&&this.electricityPriceX){
						this.info.applicationAmount=((this.info.chargingProfitAmount+this.info.monthlyCardIncome-this.electricityPriceX)*this.info.rewardProportion/100).toFixed(2);
						
					}
				}
				if(this.info.applicationType!=3&&!this.selectAccUser.id){
						uni.showToast({
							title: "请选择提现账户"
						})
				
					return
				}
				if(this.info.applicationType!=3){
					this.info.merchantAccountId=this.selectAccUser.id;
				}
				
				if(status==5){
					
				//this.value=this.info.amount
				if(!this.stationObj.id){
						uni.showToast({
							title: "请选择站点"
						})
				
					return
				}
				
				
				
				
				
				if(this.info.applicationType==1){
					
				}else{
					if(!this.info.electricityPrice){
							uni.showToast({
								title: "请先核准物业电价成本"
							})
					
						return
					}
				}
				
				
				if(!this.info.electricityPrice){
						uni.showToast({
							title: "请输入成本电价"
						})
				
					return
				}
					
					
					if(!this.info.electricQuantity){
						this.info.electricQuantity=0
					}
					if(!this.info.electricityCost){
							this.info.electricityCost=0
					}
					
					if(!this.info.applicationAmount){
							uni.showToast({
								title: "请输入申请提现金额"
							})
						return
					}
					if(this.info.applicationType==1){
						
						if(this.info.withdrawalType==0&&(this.info.rewardProportion=="")){
								uni.showToast({
									title: "请输入提成比例"
								})
							return
						}
						if(this.info.withdrawalType==1&&!this.info.parkingFee){
								uni.showToast({
									title: "请输入停车费"
								})
							return
						}
					}
					if(this.info.applicationType==2){
						if(this.info.rewardProportion==""){
								uni.showToast({
									title: "请输入市场奖励比例"
								})
							return
						}
					}
					
					
					
						if(this.info.invoiceRequired=="1"){
							if(!this.info.invoiceType){
									uni.showToast({
										title: "请选择发票类型"
									})
							
								return
							}
							if(!this.info.taxRate&&this.info.invoiceType==1){
									uni.showToast({
										title: "请选择发票税率"
									})
							
								return
							}
						}
						
					if(this.info.applicationType==3){
						if(!this.info.accountName){
								uni.showToast({
									title: "请输入收款户名"
								})
							return
						}
						if(!this.info.bankName){
								uni.showToast({
									title: "请输入收款银行"
								})
							return
						}
						if(!this.info.accountNo){
								uni.showToast({
									title: "请输入收款账号"
								})
							return
						}
					}
					for(var i in this.detailList){
						var obj=this.detailList[i]
						
						if(!obj.itemName){
							uni.showToast({
								title: `请填写提现明细中第${parseInt(i)+1}项的项目名称`
							})
							return
						}
						if(!obj.itemAmount){
							uni.showToast({
								title: `请填写提现明细[${obj.itemName}]项目的金额`
							})
							return
						}
					}
					if(this.detailList&&this.detailList.length){
						
						
						if(!(this.itemApplicationAmountSum==parseFloat(this.info.applicationAmount))){
							uni.showToast({
								title: `[申请提现金额]与[明细金额合计]不相等`
							})
							return
						}
					}
					
			}
		
			if(status==5){
				for(var i in this.detailList){
						var obj=this.detailList[i]
						
						if(!obj.itemName){
							uni.showToast({
								title: `请填写提现明细中第${parseInt(i)+1}项的项目名称`
							})
							return
						}
						if(!obj.itemAmount){
							uni.showToast({
								title: `请填写提现明细[${obj.itemName}]项目的金额`
							})
							return
						}
					}
					if(this.detailList&&this.detailList.length){
						
						
						if(!(this.itemApplicationAmountSum==parseFloat(this.info.applicationAmount))){
							uni.showToast({
								title: `[申请提现金额]与[明细金额合计]不相等`
							})
							return
						}
					}
					
			}
			
			if(this.info.invoiceRequired!=''){
				this.info.invoiceRequired=this.info.invoiceRequired=='1'?true:false
			}
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				if(this.id){
					this.info.id=this.id;
				}
				if(this.info.applicationType==3){
				
					this.info.autoWithdrawal=(this.checked)?1:0
				}
				if(this.info.applicationType==1){
					this.info.bearElecMoney=(this.info.bearElecMoney=="1")?true:false
				}
				//checked
				this.info.status=status;
				
				//var str=JSON.stringify();
				API.applyAccounting({
					
					record:this.info,
					detailList:this.detailList
				
				}).then((res) => {
					
					this.carhelp.set("withdrawRecord",{
						uuid:this.uuid,
					})
					this.id=res.data;
					uni.hideLoading()
					if(status==-2){
						uni.showModal({
							title:"提示",
							content:"保存成功",
							showCancel:false
						})
					}else{
						uni.redirectTo({
							url:"/pagesFinance/user/withdrawal/applyResult?value="+this.info.applicationAmount
						})
					}
						
					
				}).catch(error => {
					uni.hideLoading()
					uni.showModal({
						title:"提示",
						content:error,
						showCancel:false
					})
				})
			},
			 
			ckdownload(){
				//this.value=this.info.amount
				if(!this.stationObj.id){
						uni.showToast({
							title: "请选择站点"
						})
				
					return
				}
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				var str1=this.info.startTime2;
				var str2=this.info.endTime2;
				if(str1.length!=19){
					str1=this.info.startTime2+":00"
				}
				if(str2.length!=19){
					str2=this.info.endTime2+":00"
				}
				API.profitDetailsExcelByAccounting({
					stationId:this.stationObj.id,
					startDate:str1,
					endDate:str2,
				}).then((resDown) => {
						uni.hideLoading()
					if(resDown.data){
						window.location.href=resDown.data
						
					}else{
						uni.showToast({
							title:"无文件下载"
						})
					}
				}).catch(error => {
					
					uni.showToast({
						title:error
					})
				})
				
			},
			showTime2(name) {
				if (!name) {
					return ''
				}
				return parseUnixTime(newDate(name), '{y}年{m}月{d}日{h}:{i}');
				
			},
			showTime(name) {
				if (!name) {
					return ''
				}
				return name.replace('-', '年') + '月';
			},

			queryWithdrawInfo(bl) {
				 
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				if(bl){
					this.endTime =parseUnixTime(new Date(),'{y}-{m}-{d} {h}:{i}:00')
				}
				var obj={
					stationId: this.stationObj.id,
					//startDate: ,
					endDate: this.endTime,
					yearMonth: this.thismonth,
					applicationType: this.info.applicationType
				}
				if(this.info.startTime2){
					obj.startDate=this.info.startTime2+":00"
				}
				if(this.id){
					obj.recordId=this.id
				}
				
				API.queryAmountDetailByStation(obj).then((res) => {
					
					this.isReady=true;
					this.info = res.data.record;
					this.isSecond=	this.info.isSecond
					this.thismonth=this.info.applicationMonth;
					
					if(this.info.haveBill){
						
					}
					
					for(var i in  this.stationList){
						if(this.stationList[i].id==this.info.stationId){
							this.stationObj = this.stationList[i];
							this.stationObj.index=i
						}
					}
					
					if(!this.isSecond&&this.id){
						this.info.endTime2=this.endTime;
					}else{
						//this.endTime=this.info.endTime2;
					}
					this.id=this.info.id
					
						if(this.info.invoiceRequired==null){
							this.info.invoiceRequired="1"
							this.info.invoiceType="3"
						}
					
					if(this.info.applicationType==1){
						if(this.info.bearElecMoney==null){
							this.info.bearElecMoney=1;
						}
					}
					if(this.info.applicationType==2){
						if(!this.info.electricityPrice){
							this.isReady=false;
							uni.showToast({
								title: "请先核算[物业方结算]电价、实际电量"
							})
						}
					}else{
						if(this.info.withdrawalType==0||this.info.withdrawalType==1){
							
						}else{
							this.info.withdrawalType=0
						}
						
					}
					var detailList = res.data.detailList;
					this.detailList=[];
					
					if(detailList==null){
						detailList=[];
					}
					for(var i in detailList){
						if(this.id){
							this.detailList.push(detailList[i])
						}else{
							this.detailList.push({
								itemName:detailList[i].itemName,
								itemRemark:detailList[i].itemRemark,
								itemAmount:'',
							})
						}
					}
					 
					if(bl&&this.info.applicationType!=3){
						this.queryAccountByStationIdAndType()
						
					}
					
					if(this.info.applicationType==3&&!this.info.applicationAmount){
						var applicationAmount=(this.info.chargingProfitAmount+this.info.monthlyCardIncome)
							if(this.info.applyAmount1){
								applicationAmount-=this.info.applyAmount1
							}
							if(this.info.applyAmount2){
								applicationAmount-=this.info.applyAmount2
							}
							this.info.applicationAmount=applicationAmount.toFixed(2)
							this.applicationAmountTest=applicationAmount.toFixed(2);
					}
					uni.hideLoading()

				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
			},
			queryAccountByStationIdAndType(userId){
				var bl=true;
				var obj={
					stationId: this.stationObj.id,
					
					applicationType: this.info.applicationType
				}
				API.queryAccountByStationIdAndType(obj).then((res2)=>{
					this.userList=res2.data.merchantAccountList
					
					if(userId){
						for(var i in this.userList){
							if(this.userList[i].id==userId){
								this.selectAccUser=this.userList[i];
								bl=false
							}
						}
					}
					if(bl){
						this.selectAccUser={}
						if(this.userList.length>0){
							this.selectAccUser=this.userList[0];
						}
					}
					
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
			},
			getInfo(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.getWithdrawInfoByAccounting(this.id).then((res) => {
					
					this.info=res.data.record
					this.id=this.info.id;
					this.thismonth=this.info.applicationMonth
					this.detailList=res.data.detailList
					for(var i in  this.stationList){
						if(this.stationList[i].id==this.info.stationId){
							this.stationObj = this.stationList[i];
							this.stationObj.index=i
						}
					}
					
					if(this.info.applicationType!=3){
						this.queryAccountByStationIdAndType()
					}else{
						
					}
					uni.hideLoading()
				
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
			},
			getStationList() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.stationList().then((res) => {
					this.stationList = res.data.stationList;
					
						if (this.stationList.length) {
							this.stationObj = this.stationList[0];
							this.stationObj.index=0
							if(this.id){
								this.getInfo()
							}else{
								this.queryWithdrawInfo(true)
							}
						
						}
					
					
					uni.hideLoading()
				
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
				
				// API_common.findByCatalogName2({
				// 	catalogName:"提现类型"
				// }).then((res) => {
				// 	this.applicationList= res.data.dataDictionaryList;
				// 	// this.applicationList =dataDictionaryList.map((item)=>{
				// 	// 	return {
				// 	// 		name:item.name,
				// 	// 		value:item.value
				// 	// 	}
				// 	// })
				// 	uni.hideLoading()

				// }).catch(error => {
				// 	uni.showToast({
				// 		title: error
				// 	})
				// })
			},
			switchBtn(e){
				
				
				
				if (this.stationList[e[0]]) {
					this.stationObj = this.stationList[e[0]];
					this.stationObj.index=e[0]
					this.info.startTime2="";
					this.queryWithdrawInfo(true)
				}
				
			},
			bindPickerChange1(e) {
				//切换站点
				if (this.stationList[e.detail.value]) {
					this.stationObj = this.stationList[e.detail.value];
					this.info.startTime2="";
					this.queryWithdrawInfo(true)
				}
			},
			bindPickerChange2(e) {
				//切换是由
				this.info.applicationType = this.applicationList[e.detail.value].value;
			
				this.queryWithdrawInfo(true)
			},
			bindPickerChange3(e) {
				//切换月份
				this.thismonth = e.detail.value;
				this.queryWithdrawInfo(true)
				 
			},
			bindPickerChange4(e) {
				
				var str=e.year+"-"+e.month+"-"+e.day+" "+e.hour+":"+e.minute+":00"
				var str2=e.year+"-"+e.month+"-"+e.day+" "+e.hour+":"+e.minute
				var startTime=newDate(this.info.startTime2)
				var nowTime=new Date()
				var result=newDate(str)
				
				if(result>nowTime){
					uni.showToast({
							title: "抄表时间不可大于当前时间"
						})
				}else if(result<startTime){
					uni.showToast({
							title: "抄表时间不可小于开始时间"
						})
				}else{
					this.endTime =str;
					this.info.endTime2= str;
					this.queryWithdrawInfo()
				}
					
				
			
			},
			bindPickerChange6(e) {
				
				var str=e.year+"-"+e.month+"-"+e.day+" "+e.hour+":"+e.minute+":00"
				var str2=e.year+"-"+e.month+"-"+e.day+" "+e.hour+":"+e.minute
				var endTime=newDate(this.info.endTime2)
				var nowTime=new Date()
				var result=newDate(str)
				
				if(result>nowTime){
					uni.showToast({
							title: "抄表时间不可大于当前时间"
						})
				}else if(result>endTime){
					uni.showToast({
							title: "抄表时间不可大于结束时间"
						})
				}else{
					//this.endTime =str;
					this.info.startTime2= str2;
					this.queryWithdrawInfo()
				}
					
				
			
			},
			bindPickerChange5(e) {	
				this.selectAccUser = this.userList[e.detail.value];			
			},
			change(index) {
				this.current = index;
			}



		}
	}
</script>
<style>
	page {
		background-color: #F7F7F7;
		padding-bottom: 65px;
	}
</style>
<style lang="scss" scoped>
	.jputabs {
		//position: absolute;
		position: fixed;
		background-color: #FFF;
		width: 100%;
		top: 45px;
		z-index: 99;
	}
	
	.classFFF {
		color: #607d8b  !important;
	}
	
	.download {
		color: #185AC6 !important;
	}
	.download5 {
		width: 160rpx !important;
		float: right;
		
		color: #185AC6 !important;
	}
	
	::v-deep.u-tab-bar {
		background-color: #0076FF !important;
	
	}
	
	::v-deep.u-tabs-scorll-flex {
		width: 56%;
		margin: 0 auto;
	}
	
	.withdraw-tips {
		margin: 24px 16px;
	
		p {
			color: #999;
			margin-top: 4px;
		}
	}
	
	.uni-input {
		font-size: 16px;
		color: #333333;
	
	
	}
	
	.withdraw {
		margin-bottom: 8px;
		background-color: #fff;
		padding: 0px 16px 0 16px;
		
		.withdraw-head {
			padding: 24rpx 0;
			border-bottom: 1px solid #E5E7EA;
	
			align-items: center;
			position: relative;
	
			.unit {
				position: absolute;
				top: 34rpx;
				right: 0;
	
			}
	
			
	
			b {
				font-weight: normal;
				color: rgba(119, 119, 119, 100);
				font-size: 36rpx;
			}
	
			span {
				max-width: 60%;
				min-width: 55%;
				
				float: right;
				text-align: left;
				font-size: 32rpx;
				color: #333333;
			}
	
			@media screen and (max-width:319px) {
				span {
					max-width: 60%;
					min-width: 50%;
				}
			}
	
		}
	
		.withdraw-main {
			border-top: 1px solid #f7f7f7;
			border-bottom: 1px solid #f7f7f7;
	
			margin: 16px 0;
			padding: 16px 0;
	
			.withdraw-input {
				width: 63%;
				margin-top: 64rpx;
				display: flex;
				align-items: center;
				font-size: 56rpx;
	
				::v-deep.uni-input-input {
					font-size: 28rpx;
				}
			}
		}
	
		.withdraw-foot {
			display: flex;
			align-items: center;
	
			p {
				color: #999
			}
	
			span {
				color: #2979FF;
				margin-left: 16px;
	
			}
		}
	}
	
	.more {
	
		color: #B3B3B3;
		font-size: 24px
	}
	
	.applyBtn {
		padding: 0 16px;
	
		display: flex;
		background-color: #FFF;
		font-size: 16px;
		line-height: 44px;
		height: 60px;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	
		.save {
			width: 33.6%;
			border-radius: 8px 0px 0px 8px;
			background-color: rgba(0, 185, 98, 100);
			color: rgba(255, 255, 255, 100);
		}
	
		.submit {
			width: 66.4%;
			border-radius: 0px 8px 8px 0px;
			background-color: rgba(24, 90, 198, 100);
			color: rgba(255, 255, 255, 100);
		}
		.submit2 {
		
			
			background-color: rgba(24, 90, 198, 100);
			color: rgba(255, 255, 255, 100);
		}
	}
	
	
	::v-deep.uni-input-input {
		text-align: start !important;
	}
	
	.border-n {
		//border: none !important;
	}
	
	.textarea {
		background-color: rgba(242, 242, 242, 100);
		margin-top: 12px;
		line-height: 20px;
		border-radius: 4px;
		color: rgba(136, 136, 136, 100);
	
		.uni-textarea-placeholder {
			padding: 0 16rpx;
	
		}
	
		::v-deep.uni-textarea-textarea {
			width: 90%;
			padding: 0 16rpx;
	
		}
	}
	.withdrawHead{
		padding: 15px;
		font-size: 14px;
		.red{
			color: red;
		}
	}
	.details {
		margin: 16px;
		border-radius: 8px;
		background-color: #fff;
		overflow: hidden;
	}
	
	.asterisk {
		position: relative;
	
		text {
			position: absolute;
			top: 0px;
			left: -14rpx;
			color: #EE3138;
		}
	}
	
	.add {
		text-align: center;
		font-size: 18px;
		color: #101010;
		display: flex;
		align-items: center;
		justify-content: center;
	
		.ri-add-circle-fill {
			font-size: 24px;
			color: #44B371;
			margin: auto 0;
			margin-right: 4rpx;
		}
	
	}
	
	::v-deep.u-input__input {
		font-size: 16px !important
	}
	.uni-time{
		font-size: 32rpx;
	}
	.uni-input {
		display: flex;
		justify-content: space-between;
	}
	
	.input-text {
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	
</style>
