<template>
	<div class="effectiveDetail">
		<div v-if="effectiveShow && !loading">
			<div>
				<div class="contentTwo-head">
					<div>
						<div class="contentTwo-name"><span class="contentTwo-text" :class="{'scan-ico':effectiveDetail.SCAN_TYPE===1,'shouchi-ico':effectiveDetail.SCAN_TYPE===2,'jiekou-ico':effectiveDetail.SCAN_TYPE===3}">{{effectiveDetail.SHOPNAME}}</span></div>
						<div class="contentTwo-right" style="color: #ec9061;justify-content: flex-end;">
							{{effectiveDetail.TREATMENT_MARK}}
						</div>
					</div>
					<div  style="color: #979797;margin-bottom: 10px;"><span>{{effectiveDetail.SERVERPART_NAME}}</span></div>

					<view class="content-detail-box">
						<div class="content-effective">
							<div class="contentTwo-left"><i class="ico ico-user"></i><span class="fourth-name">结账人员：</span>{{effectiveDetail.WORKER_NAME}}</div>
							<div class="contentTwo-right"><i class="ico ico-sjx"></i><span>{{effectiveDetail.ENDACCOUNT_DATE}}</span></div>
						</div>
						<div class="content-line" v-if="effectiveDetail.DESCRIPTION_STAFF !== ''"></div>
						<div v-if="effectiveDetail.DESCRIPTION_STAFF !== ''">
							<div class="contentTwo-left"><i class="ico ico-user"></i><span class="fourth-name">校验人员：</span>{{effectiveDetail.DESCRIPTION_STAFF}}</div>
							<div class="contentTwo-right"><i class="ico ico-sjx"></i><span>{{effectiveDetail.DESCRIPTION_DATE}}</span></div>
						</div>
						<div v-if="effectiveDetail.DIFFERENCE_REASON !== ''" class="content-effective">
							<div class="lie_right2">
								<i class="ico ico-bz"></i>
								<div class="fourth-name">校验意见：</div><span>{{effectiveDetail.DIFFERENCE_REASON}}</span>
							</div>
						</div>
						<block v-if="effectiveDetail.APPROVE_STAFF !== ''&& effectiveDetail.TREATMENT_MARKSTATE!==1">
							
							<div class="content-line" ></div>
							<div>
								<div class="contentTwo-left"><i class="ico ico-user"></i><span class="fourth-name">{{effectiveDetail.TREATMENT_MARKSTATE===0? '驳回':'审核'}}人员：</span>{{effectiveDetail.APPROVE_STAFF}}</div>
								<div class="contentTwo-right"><i class="ico ico-sjx"></i><span>{{effectiveDetail.APPROVE_DATE}}</span></div>
							</div>
							<div class="content-effective">
								<div class="lie_right2">
									<i class="ico ico-bz"></i>
									<div class="fourth-name">{{effectiveDetail.TREATMENT_MARKSTATE===0? '驳回':'审核'}}意见：</div><span>{{effectiveDetail.APPROVED_INFO}}</span>
								</div>
							</div>
						</block>
						<block v-if="effectiveDetail.ENDACCOUNT_DESC !=='' ">
							
							<div class="content-line" ></div>
							<div >
								<div class="contentTwo-left"><i class="ico ico-user"></i><span class="fourth-name">主任名称：</span>{{zhur[0]}}</div>
								<div class="contentTwo-right"><i class="ico ico-sjx"></i><span>{{zhur[1]}}</span></div>
							</div>
							<div>
								<div class="lie_right2">
									<i class="ico ico-bz"></i>
									<div class="fourth-name">确认意见</div><span>{{zhur[2]}}</span>
								</div>
							</div>
						</block>
					</view>

				</div>
				<p class="commodityP">
					<span>营收详情</span>
					<span class="photo-btn" v-if="imagesList.length>0" @tap="showImg()">查看账单图片</span>
				</p>
				<div class="commodity">
					<div>
						<div class="commodityContent">
							<span class="color1">{{CASH}}</span>
							<div>
								<img src="/static/images/effective/ssje.png" />
								<span class="ctitle">现金支付</span>
							</div>
						</div>
						<div class="add">+</div>
						<div class="commodityContent zyborder">
							<span class="color1">{{MOBILEPAYMENT}}</span>
							<div>
								<img src="/static/images/effective/ydzf2.png" />
								<span class="ctitle">移动支付</span>
							</div>

						</div>
						<div>=</div>
						<div class="commodityContent">
							<span class="color1">{{TOTALSELLAMOUNT}}</span>
							<div>
								<img src="/static/images/effective/cdz.png" />
								<span class="ctitle">销售金额</span>
							</div>
						</div>
					</div>
					<div>
						<div class="commodityContent">
							<span class="color1">{{CASHPAY_DOWNLORD}}</span>
							<div>
								<img src="/static/images/effective/ssje.png" />
								<span class="ctitle">缴款金额</span>
							</div>
						</div>
						<div class="add">-</div>
						<div class="commodityContent zyborder">
							<span class="color1">{{CASH}}</span>
							<div>
								<img src="/static/images/effective/xjzf.png" />
								<span class="ctitle">现金支付</span>
							</div>

						</div>
						<div>=</div>
						<div class="commodityContent">
							<span class="color1">{{DIFFERENT_PRICE}}</span>
							<div>
								<img src="/static/images/effective/cdk.png" />
								<span class="ctitle">长短款额</span>
							</div>
						</div>
					</div>
					<div>
						<div class="commodityContent-cashpay">
							<span class="wid70" style="color: #333;">误差率：</span>
							<span class="color1" :class="cor">{{wcl}}%</span>
							<!-- <div>
								<img src="/static/images/effective/wcz.png" />
							</div> -->
						</div>
						<div style="color:#fff">-</div>
						<div class="commodityContent-cashpay">
							<span class="wid70">实收金额：</span>
							<input v-model="effectiveDetail.CASHPAY" class="cashpay" :disabled="isdisabled" @blur="checkNum($event,'CASHPAY')">
						</div>
					</div>
				</div>
				<view class="cashpay-box">
					<div>
						<img src="/static/images/effective/dpjl.png" alt="">
						<span class="cashpay-check">单品记录：</span>
						<uni-load-more v-if="isFACTAMOUNT_SALE==2" loadingType="1" :contentText="contentText"></uni-load-more>
						<img src="/static/images/effective/true.png" alt="" v-else-if="isFACTAMOUNT_SALE==1">
						<img src="/static/images/effective/false.png" alt="" v-else>
					</div>
					<div>
						<img src="/static/images/effective/jk.png" />
						<span class="cashpay-check">移动支付：</span>
						<uni-load-more v-if="isFACT_AMOUNT==2" loadingType="1" :contentText="contentText"></uni-load-more>
						<img src="/static/images/effective/true.png" alt="" v-else-if="isFACT_AMOUNT==1">
						<img src="/static/images/effective/false.png" alt="" v-else>
					</div>

					<div v-if="isTICKETCODE_CIGARETTE == true">
						<img src="/static/images/effective/xysj.png" alt="">
						<span class="cashpay-check">香烟数据：</span>
						<img src="/static/images/effective/true.png" alt="">
					</div>
					<div v-if="isSELLCOUNT_PROMOTION == true">
						<img src="/static/images/effective/zxsj.png" />
						<span class="cashpay-check">促销数据：</span>
						<img src="/static/images/effective/true.png" alt="">
					</div>
				</view>
			</div>
			<div v-show="showPopupMiddle" class="shenhe-mask" :style="{top:offsetTop + 'px'}" @click.stop="mask()">
			</div>
			<div class="opinion2" v-show="showPopupYj">
				<div >
					<p class="opinion2-title"><span>{{isback? '驳回':'确认'}}意见</span></p>
					<textarea v-model="PURCHASEDESC" :placeholder="'请填写'+(isback? '驳回':'确认')+'意见'" class="text-content check-reason" />
				</div>
				<div class="check-btn-box">
					<div class="check-btn" @click="examine()">确定</div>
					<div class="check-btn no-check" @click="mask">取消</div>
				</div>
				
				</div> 
				<div class="opinion2" v-show="showPopupCheck">
					<div v-if="ischeckOut">
						<p class="opinion2-title"><span>数据校验</span></p>
						<block v-if="isFACT_AMOUNT!=1">
							<div class="data-check">
								<div class="data-check-data" style="border:1px solid #64a0e6;">
									<input v-model="effectiveDetail.MOBILE_CORRECT"  style="border:none;text-align:center;" @blur="checkNum($event,'MOBILE_CORRECT')"/>
									
								</div>
								<div>=</div>
								<div class="data-check-data">
									<span class="color1">{{mobileChongzheng}}</span>
								</div>
								<div>+</div>
								<div class="data-check-data">
									<span class="color1">{{SALE_CORRECT}}</span>
								</div>
								
								
							</div>
							<div class="data-check">
								<span class="ctitle">移动冲正</span>
								<span class="ctitle">移动支付差额</span>
								<span class="ctitle">到账实差</span>
							</div>
						</block>
						<div class="data-check">
							<div class="data-check-data">
								<span class="color1">{{effectiveDetail.CASHPAY}}</span>	
							</div>
							<div>=</div>
							<div class="data-check-data">
								<span class="color1">{{effectiveDetail.TOTALSELLAMOUNT}}</span>
							</div>
							<div>+</div>
							<div class="data-check-data">
								<span class="color1">{{CORRECT_AMOUNT}}</span>	
							</div>
						</div>
						<div class="data-check">
							<span class="ctitle">实收金额</span>
							<span class="ctitle">销售金额</span>
							<span class="ctitle">冲正金额</span>
						</div>
						<div class="data-check">
							<div class="data-check-data">
								<span class="color1">{{CORRECT_AMOUNT}}</span>	
							</div>
							<div>=</div>
							<div class="data-check-data">
								<span class="color1">{{effectiveDetail.MOBILE_CORRECT||0}}</span>
							</div>
							<div>+</div>
							
							<div class="data-check-data" style="border:1upx solid #64a0e6;">
								<input v-model="effectiveDetail.CASH_CORRECT"  style="border:none;text-align:center;" @blur="checkNum($event,'CASH_CORRECT')" />
							</div>
							
						</div>
						<div class="data-check">
							<span class="ctitle">冲正金额</span>
							<span class="ctitle">移动冲正</span>
							<span class="ctitle">现金冲正</span>
						</div>
					</div>
					<div >
						<p class="opinion2-title"><span>校验原因</span></p>
						<textarea v-model="checkReason" placeholder="请填写校验原因" class="text-content check-reason" />
					</div>
					<div class="check-btn-box">
						<div class="check-btn" @click="checkSubmit">校验</div>
						<div class="check-btn no-check" @click="noCheck">取消</div>
					</div>
				</div>
				
			<div class="check-btn-box"  v-if="isCheck==2">
				
				<div class="check-btn" @click="menuImg(true)">
				
					<span>驳回</span>
				</div>
				<div class="check-btn" @click="menuImg(false)">
				
					<span>审核</span>
				</div>
			</div>
			<div class="check-btn-box" v-else-if="isCheck==1">
				
				<div class="check-btn" @click="correct" v-if="shouldCorrect">
				
					<span>一键冲正</span>
				</div>
				<div class="check-btn" @click="checkOut()">
				
					<span>校验</span>
				</div>
			</div>
		</div>
		
		<div v-else-if="!effectiveShow && !loading">
			<noFound :nodata="effectiveDetail.FACTAMOUNT_SALE ? false : true"/>
		</div>
		
	</div>
</template>

<script>

	import uniPopup from '@/components/uni-popup.vue';
	import uniLoadMore from '@/components/uni-load-more.vue';

	import {mapGetters} from "vuex";
	export default {
		data() {
			let offsetTop = 0;
		
			return {
				loading: true,
				offsetTop: offsetTop,
				showPopupMiddle: false,
				showPopupCheck: false,
				showPopupYj: false,
				isdisabled: true,
				ischeckOut: false,
				effectiveDetail: {},
				effectiveShow: false,
				ID: '', // 服务区ID
				SERVERPART_ID: '',
				Endaccount_ID: '',
				// Toexamine: false,
				isCheck: 0, // 0 不显示按钮 1 数据校验按钮 2 财务审核按钮
				PopupVisible3: false,
				Opinion: "", //意见
				trialani: false,
		
				PURCHASEDESC: "",
				examineType: "",
				opinionType: "",
				moneyJj: "",
				cans: [],
				zhur: [],
				wcl: "",
				cor: "",
				cashpay: "",
				cashCorrect: 0,
				FACTAMOUNT_SALE: '', //单品销售金额金额
				SELLCOUNT_SALE: '', //单品销售数量
				TICKETCODE_CIGARETTE: '', //香烟客单数量
				SELLCOUNT_CIGARETTE: '',//香烟销售数量
				FACTAMOUNT_CIGARETTE: '', // 香烟销售金额
				TICKETCOUNT: '', //移动客单数量
				FACT_AMOUNT: '',  //移动支付销售金额
				SELLCOUNT_PROMOTION: '', //促销数量
				FACTAMOUNT_PROMOTION: '', //促销金额
				mobileCorrect: 0, // 移动冲正
				mobileChongzheng: 0, // 移动冲正支付差额
				saleCorrect: 0, // 到账实差
				isFACTAMOUNT_SALE: 2, 
				isFACT_AMOUNT: 2,
				isTICKETCODE_CIGARETTE: false,
				isSELLCOUNT_PROMOTION: false,
				checkReason: "已确认", //校验原由
			
				loadingType: 1,
				loadType: 1,
				contentText: {
					contentdown: "",
					contentrefresh: "",
					contentnomore: ""
				},
				isback:false ,// 是否是驳回
				imagesList: []
			}
		},
		computed:{
			...mapGetters({
				'user':'getUser'
			}),
			// 金额格式化处理
			TOTALSELLAMOUNT(){
				return this.$util.fmoney(this.effectiveDetail.TOTALSELLAMOUNT)
			},
			CASHPAY_DOWNLORD(){
				return this.$util.fmoney(this.effectiveDetail.CASHPAY_DOWNLORD)
			},
			DIFFERENT_PRICE(){
				return this.$util.fmoney(this.effectiveDetail.DIFFERENT_PRICE)
			},
			CASHPAY(){
				return this.$util.fmoney(this.effectiveDetail.CASHPAY)
			},
			MOBILEPAYMENT(){
				return this.$util.fmoney(this.effectiveDetail.MOBILEPAYMENT)
			},
			CORRECT_AMOUNT(){ // 现金冲正
				let s1 = parseFloat(this.effectiveDetail.MOBILE_CORRECT)+''=='NaN' ? 0 : parseFloat(this.effectiveDetail.MOBILE_CORRECT)
				let s2 = parseFloat(this.effectiveDetail.CASH_CORRECT)+''=='NaN' ? 0 : parseFloat(this.effectiveDetail.CASH_CORRECT)
			
				return s1 + s2
			},
			SALE_CORRECT(){ // 现金冲正
			
				let s = parseFloat(this.effectiveDetail.MOBILE_CORRECT)+''=='NaN' ? 0 : parseFloat(this.effectiveDetail.MOBILE_CORRECT)
				return s - parseFloat(this.mobileChongzheng)
			},
		
			MOBILE_CORRECT(){
				return this.$util.fmoney(this.effectiveDetail.MOBILE_CORRECT)
			},
			CASH_CORRECT(){
				return this.$util.fmoney(this.effectiveDetail.CASH_CORRECT)
			},
			CASH(){
				return this.$util.fmoney(this.effectiveDetail.CASH)
			},
			moneyJjs(){
				return this.$util.fmoney(this.moneyJj)
			},
			shouldCorrect() { // 是否需要一键冲正
				return (this.isFACTAMOUNT_SALE==0 || this.isFACT_AMOUNT==0) && this.isCheck == 1 // 单品记录错误或移动数据错误 且该用户有处理权限
			}
		},
		components: {
			uniPopup,
			uniLoadMore
		
		},
		
		methods: {
			// 图片预览
			showImg() {
				let list = []
				this.imagesList.map(n=>{list.push(n.IMAGE_URL)})
				uni.previewImage({
					urls: list, 
					current: 0,
					loop: true,
					indicator: 'number'
				});
			},
	
	
			checkNum(event,s){
				let value = event.detail.value.match(/[+-]?\d+(\.\d{0,2})?/)
				if(value){
					value  = value[0]
				}else{
					value = 0
				}
				this.effectiveDetail[s] = value
			},
			// 获取单品数据、移动支付等校验数据
			getEndAccountDate(datatype) { // 获取更新过的数据校验数据
				let _this = this
				let _detail = this.effectiveDetail
				_this.$request.$get('GetEndAccountData',{
					serverpart_Id: _detail.SERVERPART_ID,
					serverpart_Code: _detail.SERVERPARTCODE,
					machine_Code: _detail.MACHINECODE,
					shop_Code: _detail.SHOPCODE,
					province_Code:  _detail.PROVINCE_CODE,
					endAccount_StartDate: _detail.ENDACCOUNT_STARTDATE,
					endAccount_Date: _detail.ENDACCOUNT_DATE,
					fact_Amount: _detail.FACT_AMOUNT,
					cash_Pay: _detail.CASHPAY,
					sale_Correct: _detail.SALE_CORRECT,
					mobile_Payment: _detail.MOBILEPAYMENT,
					mobile_Correct: _detail.MOBILE_CORRECT,
					endAccount_Id: _detail.ENDACCOUNT_ID,
					data_Type: datatype
				}).then(res => {
					// uni.hideLoading()
					let _data  = res.Result_Data
					if(datatype == 1){
						
						// 单品计算公式：FACTAMOUNT_SALE = TOTALSELLAMOUNT 或者 TOTALSELLAMOUNT = FACTAMOUNT_SALE + FACTAMOUNT
						_this.FACTAMOUNT_SALE = Number(_data.FactAmount_Sale) //单品金额
						_this.SELLCOUNT_SALE = _data.SellCount_Sale //单品金额
						if((_this.FACTAMOUNT_SALE == _detail.TOTALSELLAMOUNT) || (_detail.TOTALSELLAMOUNT==(_this.FACTAMOUNT_SALE+_detail.FACTAMOUNT))){
							_this.isFACTAMOUNT_SALE = 1
						}else{
							_this.isFACTAMOUNT_SALE = 0
						}
					}
					if(datatype == 2){
						_this.TICKETCODE_CIGARETTE = _data.TicketCode_Cigarette //香烟客单数量
						_this.SELLCOUNT_CIGARETTE = _data.SellCount_Cigarette
						_this.FACTAMOUNT_CIGARETTE = _data.FactAmount_Cigarette
						if(_this.TICKETCODE_CIGARETTE && _this.TICKETCODE_CIGARETTE!=NaN  && Number(_this.TICKETCODE_CIGARETTE)!== 0){
							_this.isTICKETCODE_CIGARETTE = true
						}
					}
					if(datatype == 3){
				
						_this.FACT_AMOUNT = Number(_data.Fact_Amount) //移动支付销售金额
						_this.TICKETCOUNT = _data.Ticket_Count //移动支付销售金额
						let saleCorrect = _detail.SALE_CORRECT || 0
						
						if((_this.FACT_AMOUNT+saleCorrect) == _detail.MOBILEPAYMENT){
							_this.isFACT_AMOUNT = 1
							_detail.MOBILE_CORRECT = 0
							_detail.SALE_CORRECT = 0
						}else{
							_this.isFACT_AMOUNT = 0
							_this.mobileChongzheng  = _this.FACT_AMOUNT - _detail.MOBILEPAYMENT // 移动冲正差额
							_detail.MOBILE_CORRECT = _detail.MOBILE_CORRECT ==='' ? _this.mobileChongzheng : _detail.MOBILE_CORRECT // 移动冲正
							_detail.SALE_CORRECT = _detail.SALE_CORRECT ==='' ? 0 : _detail.SALE_CORRECT // 到账实差
						}
					}
					if(datatype == 4){
						_this.SELLCOUNT_PROMOTION = _data.SellSount_Promotion //促销数量
						_this.FACTAMOUNT_PROMOTION = _data.FactAmount_Promotion //促销数量
						if(_this.SELLCOUNT_PROMOTION != 0){
							_this.isSELLCOUNT_PROMOTION = true
						}
					}
					
				})
			},
			// 数据校验门店列表
			getEffectiveDetail() {
				let _this = this
				this.$request.$get('GetEndaccountDetails',{
					Endaccount_ID: _this.ENDACCOUNT_ID
				}).then(res => {
					_this.loading = false
					uni.hideLoading()
					if (!res.Result_Code|| res.Result_Code!='100') return
					
						_this.imagesList = res.Result_Data.Image_List
						let _data = res.Result_Data.Endaccount_List
						
						_this.effectiveShow = true
						_this.effectiveDetail = _data
						_this.FACTAMOUNT_SALE = _data.FACTAMOUNT_SALE
						_this.SELLCOUNT_SALE = _data.SELLCOUNT_SALE
						_this.SELLCOUNT_CIGARETTE = _data.SELLCOUNT_CIGARETTE
						_this.FACTAMOUNT_CIGARETTE = _data.FACTAMOUNT_CIGARETTE
						_this.TICKETCOUNT = _data.TICKETCOUNT
						_this.FACT_AMOUNT = _data.FACT_AMOUNT
						_this.SELLCOUNT_PROMOTION = _data.SELLCOUNT_PROMOTION
						_this.FACTAMOUNT_PROMOTION = _data.FACTAMOUNT_PROMOTION
						_this.$forceUpdate()
						if(_data.FACTAMOUNT_SALE == ""){ // 单品记录z计算
							_this.getEndAccountDate(1)
							
						}else{
							// 单品计算公式：FACTAMOUNT_SALE = TOTALSELLAMOUNT 或者 TOTALSELLAMOUNT = FACTAMOUNT_SALE + FACTAMOUNT
							_this.FACTAMOUNT_SALE = _data.FACTAMOUNT_SALE
							let FACTAMOUNT = _data.FACTAMOUNT || 0
							
							if(_this.FACTAMOUNT_SALE == _data.TOTALSELLAMOUNT || (_this.FACTAMOUNT_SALE+FACTAMOUNT) == _data.TOTALSELLAMOUNT){
								_this.isFACTAMOUNT_SALE = 1
							}else{
								_this.isFACTAMOUNT_SALE = 0
							}
						}
							
							if(_data.TICKETCODE_CIGARETTE == ""){
								_this.getEndAccountDate(2)
								
							}else{
								_this.TICKETCODE_CIGARETTE = _data.TICKETCODE_CIGARETTE
								if(_this.TICKETCODE_CIGARETTE !== 0){
									_this.isTICKETCODE_CIGARETTE = true
								}
							}
							
							if(_data.FACT_AMOUNT == ""){ // 移动支付
								_this.getEndAccountDate(3)
								
							}else{
								
								let saleCorrect = _data.SALE_CORRECT || 0
							
								_this.FACT_AMOUNT = _data.FACT_AMOUNT
								if((_this.FACT_AMOUNT+saleCorrect) == _data.MOBILEPAYMENT){
									_this.isFACT_AMOUNT = 1
									_data.SALE_CORRECT = 0
									_data.MOBILE_CORRECT = 0
								}else{
									_this.isFACT_AMOUNT = 0
								}
							}
							
							if(_data.SELLCOUNT_PROMOTION == ""){
								_this.getEndAccountDate(4)
								
							}else{
								_this.SELLCOUNT_PROMOTION = _data.SELLCOUNT_PROMOTION
								if(_this.SELLCOUNT_PROMOTION !== 0){
									_this.isSELLCOUNT_PROMOTION = true
								}
							}
							_this.cashpay = _data.CASHPAY
							_this.cashCorrect = _data.CASH_CORRECT
							_this.zhur = _data.ENDACCOUNT_DESC.split("|");
							if (_data.TOTALSELLAMOUNT != 0) {
								let moj =parseFloat(_data.TOTALSELLAMOUNT)/parseFloat(_data.TICKETCOUNT);
								let l = moj.toString().indexOf(".") + 3;
								_this.moneyJj = moj.toString().substring(0, l);
								// console.log(this.moneyJj)
							} else {
								_this.moneyJj = "0";
							}
							if (_data.TOTALSELLAMOUNT == 0) {
								_this.wcl = "0.00";
							} else {
								let cdk;
								if (_data.DIFFERENT_PRICE < 0) {
									cdk = _data.DIFFERENT_PRICE * -1;
								} else {
									cdk = _data.DIFFERENT_PRICE;
								}
								_this.wcl = (
									cdk /
									_data.TOTALSELLAMOUNT *
									100
								).toFixed(2);
								if (_this.wcl > 0.3) {
									_this.cor = "cor";
								}
							}
							console.log(_data.TREATMENT_MARKSTATE)
						if(_data.PENDSTATE==0){
							if(_data.TREATMENT_MARKSTATE == 0){ // 待处理
								_this.isCheck = 1
								_this.isdisabled = false
							}
							if (_data.TREATMENT_MARKSTATE == 3) { // 主任复核
								 _this.isCheck = 2
								 // _this.Toexamine = true;
								 _this.examineType = "SubmitEndaccount"
							}else if(_data.TREATMENT_MARKSTATE == 1){ // 财务审核
								 _this.isCheck = 2
								 // _this.Toexamine = true;
								 _this.examineType = "ApproveEndaccount"
							}
						}
						else{ // 已审结
							_this.examineType = "";
							_this.isCheck = 0;
						}
					
				})
			},
			mask(){
				this.showPopupMiddle = false
				this.showPopupCheck = false
				this.showPopupYj = false
			},
			noCheck(){
				this.showPopupMiddle = false
				this.showPopupCheck = false
			},
			menuImg(isback) {
				this.isback = isback
				this.PURCHASEDESC = isback ? '' : "同意"
				this.showPopupMiddle = true
				this.showPopupYj = true
			},
			correct(){ // 一键冲正
				let _this = this
				_this.$request.$post('CorrectEndAccount',{
					endAccount_Id: _this.effectiveDetail.ENDACCOUNT_ID,
					factAmount_Sale: _this.FACTAMOUNT_SALE,
					mobile_Payment: _this.effectiveDetail.MOBILEPAYMENT,
					fact_Amount: _this.FACT_AMOUNT,
					cash_Pay: _this.effectiveDetail.CASHPAY,
				}).then(res=> {
					
					if(res.Result_Code=='100') {
						uni.showToast({
							icon: 'none',
							title: res.Result_Desc,
							duration: 1000
						});
						_this.getEffectiveDetail()
					}
				})
			},
			checkOut(){
				let _this = this
				if(_this.effectiveDetail.SCAN_TYPE!=1  && _this.isFACTAMOUNT_SALE===0) {
					uni.showToast({
						icon: 'none',
						title: '单品数据不一致，请冲正后重试',
						duration: 1000
					});
					return false
				}
				
				if( _this.effectiveDetail.SCAN_TYPE===1 || (_this.isFACTAMOUNT_SALE == 1 && _this.isFACT_AMOUNT == 1)){ // 扫码上传时 忽略
					_this.showPopupMiddle = true
					_this.showPopupCheck = true
					if(parseFloat(_this.effectiveDetail.CASHPAY) !== parseFloat(_this.effectiveDetail.TOTALSELLAMOUNT) + parseFloat(_this.effectiveDetail.CORRECT_AMOUNT)){
						
						_this.ischeckOut = true
						_this.effectiveDetail.CASH_CORRECT = Math.round( (_this.effectiveDetail.CASHPAY - _this.effectiveDetail.TOTALSELLAMOUNT)*100) /100// 默认现金冲正金额
					}else{
						_this.ischeckOut = false
					}
				}else if (_this.isFACTAMOUNT_SALE == 1 && _this.isFACT_AMOUNT == 0) { 
					_this.showPopupMiddle = true
					_this.showPopupCheck = true
					_this.ischeckOut = true
					_this.effectiveDetail.CASH_CORRECT =Math.round( (_this.effectiveDetail.CASHPAY - _this.effectiveDetail.TOTALSELLAMOUNT - _this.effectiveDetail.MOBILE_CORRECT) *100 ) /100// 默认现金冲正金额
				} else {
					uni.showToast({
						icon: 'none',
						title: '请确认移动支付和单品记录无误后再进行审核',
						duration:	 1000
					});
				}
			},
			checkSubmit(){ // 校验通过提交
				let _this = this
				let money1 = parseFloat(_this.effectiveDetail.CASHPAY) == parseFloat(_this.effectiveDetail.TOTALSELLAMOUNT) + parseFloat(_this.CORRECT_AMOUNT) // 实收金额 = 销售+冲正
				let money2 = parseFloat(_this.CORRECT_AMOUNT) == parseFloat(_this.effectiveDetail.MOBILE_CORRECT) + parseFloat(_this.effectiveDetail.CASH_CORRECT) // 冲正 = 移动冲正+现金冲正
				let money3 = parseFloat(_this.effectiveDetail.MOBILE_CORRECT) == parseFloat(_this.mobileChongzheng) + parseFloat(_this.effectiveDetail.SALE_CORRECT) // 移动冲正 = 移动支付差额+到账实差
				if( money1 && money2) {
					
					if(_this.isFACT_AMOUNT == 0 && !money3) {
						uni.showToast({
							icon: 'none',
							title: '请输入正确的移动支付冲正金额。',
							duration: 1000
						});
						return false
					}
					if(_this.checkReason !== ""){
						uni.showLoading()
						_this.$request.$post('SaveEndAccount',{
							
							serverpart_Id: _this.effectiveDetail.SERVERPART_ID,
							endAccount_StartDate: _this.effectiveDetail.ENDACCOUNT_STARTDATE,
							endAccount_Date: _this.effectiveDetail.ENDACCOUNT_DATE,
							endAccount_Id: _this.effectiveDetail.ENDACCOUNT_ID,
							sale_Correct: _this.effectiveDetail.SALE_CORRECT,
							mobile_Payment: _this.effectiveDetail.MOBILEPAYMENT,
							mobile_Correct: _this.effectiveDetail.MOBILE_CORRECT,
							sellcount_Sale: _this.SELLCOUNT_SALE,
							factAmount_Sale: _this.FACTAMOUNT_SALE,
							sellCount_Cigarette: _this.SELLCOUNT_CIGARETTE,
							factAmount_Cigarette: _this.FACTAMOUNT_CIGARETTE,
							ticket_Count: _this.TICKETCOUNT,
							fact_Amount: _this.FACT_AMOUNT,
							sellCount_Promotion: _this.SELLCOUNT_PROMOTION,
							factAmount_Promotion: _this.FACTAMOUNT_PROMOTION,
							correct_Amount: _this.CORRECT_AMOUNT,
							staff_Name: _this.user.UserName,
							reason: _this.checkReason,
							cash_Pay: _this.effectiveDetail.CASHPAY
						}).then(res => {
							uni.hideLoading()
							if(res.Result_Code == 100){
								uni.showToast({
									icon: 'none',
									title: '校验成功',
									duration: 3000,
									
								});
								_this.showPopupMiddle = false
								_this.showPopupCheck = false
								setTimeout(function() {
									uni.$emit('datasummary',true)
									
									uni.navigateBack({
										delta: 1
									})
								},1000)
								
								// _this.getEffectiveDetail()
								
							}else{
								
								uni.showModal({
									title:'温馨提示',
									content:res.Result_Desc,
									showCancel:false,
									success(res) {
										if(res.confirm) {
											_this.showPopupMiddle = false
											_this.showPopupCheck = false
										}
									}
								})
							}
							
						})
					}else{
						uni.showToast({
							icon: 'none',
							title: '校验原因不能为空',
							duration: 3000
						});
					}
				}else{
					uni.showToast({
						icon: 'none',
						title: '请确认现金冲正金额填写正确',
						duration: 3000
					});
				}
			},
			examine(){  // 提交 审核 或者主任确认
				let _this = this
				if(_this.PURCHASEDESC !== ''){
					if(this.isback === true) {
						this.toBack()
						return 
					}
					let JSON = {
					
						action_record: _this.user.Membership_Id,
						action_data: _this.effectiveDetail.ENDACCOUNT_ID,
					}
					if(_this.effectiveDetail.TREATMENT_MARKSTATE == 3){ // 主任确认
						JSON.DIRECTOR_INFO= _this.PURCHASEDESC
					}else if(_this.effectiveDetail.TREATMENT_MARKSTATE == 1){ // 审核
						JSON.APPROVED_INFO = _this.PURCHASEDESC
					}
					uni.showLoading()
					_this.$request.$post(_this.examineType,JSON).then(res => {
						uni.hideLoading()
						if(res.Result_Code == 100){
							_this.showPopupMiddle = false
							_this.showPopupYj = false
							_this.getEffectiveDetail()
							uni.showToast({
								icon: 'none',
								title: '审核通过',
								duration: 1000
							});
							
							uni.$emit('datasummary',true)
						}else{
							_this.showPopupMiddle = false
							_this.showPopupYj = false
							_this.getEffectiveDetail()
							uni.showModal({
								title:'温馨提示',
								content:res.Result_Desc,
								showCancel:false,
								success(res) {
									
								}
							})
							
						}
						
					})
				}else{
					uni.showToast({
						icon: 'none',
						title: '意见不能为空',
						duration: 2000
					});
				}
			},
			toBack(){ // 驳回
				let  _this = this
				uni.showLoading()
				_this.$request.$post('BackEndaccount',{
					
					action_data: _this.effectiveDetail.ENDACCOUNT_ID,  //结账信息内码
					action_record: _this.user.Membership_Id, //当前处理人会员内码
					Approved_Info: _this.PURCHASEDESC, //审批意见
				
				}).then(res => {
					uni.hideLoading()
					if(res.Result_Code == 100){
						_this.showPopupMiddle = false
						_this.showPopupYj = false
						_this.getEffectiveDetail()
						uni.showToast({
							icon: 'none',
							title: '提交成功',
							duration: 1000
						});
						uni.$emit('datasummary',true)
						
					}else {
						_this.showPopupMiddle = false
						_this.showPopupYj = false
						_this.getEffectiveDetail()
						uni.showToast({
							icon: 'none',
							title: res.Result_Desc,
							duration: 3000
						});
					}
						
				})
			}
		},
		onUnload() {
			this.$util.addUserBehavior()
		},
		onLoad(option) {
			if(option.SERVERPART_ID) {
				this.SERVERPART_ID = option.SERVERPART_ID
			}
			this.ENDACCOUNT_ID = option.ENDACCOUNT_ID
			uni.showLoading({
				title:'正在加载'
			})
			this.getEffectiveDetail()
		}
	}
</script>

<style scoped>
	*{
		box-sizing: border-box;
	}
	.effectiveDetail {
		width: 100%;
		box-sizing: border-box;
	}
	
	.contentTwo-head {
		width: 100%;
		box-sizing: border-box;
		padding: 20upx 30upx;
		background-color: #fff;
		position: relative;
		font-size: 24upx;
	}
	
	/* .content-detail-box{
		box-shadow: 0px 1px 8px 0.2px #e2e2e2;
		border-radius: 10upx;
		padding: 0 20upx;
		margin-bottom: 20upx;
	} */
	.content-detail-box span{
		font-size: 24upx;
	}
	.contentTwo-head>div,.content-detail-box>div{
		display: flex;
		justify-content: space-between;
		font-size: 24upx;
	}
	
	.content-detail-box .content-effective{
		align-items: center;
	}
	
	.content-detail-box>div:last-child{
		border-bottom: none;
	}
	
	.contentTwo-left {
		height: 60upx;
		line-height: 60upx;
		font-size:24upx;
		display: flex;
		align-items: center;
	}

	.fourth-name {
		width: 140upx;
		display: inline-block;
		color: #979797;
		font-size: 24upx;
	}

	.contentTwo-right {
		height: 60upx;
		line-height: 60upx;
		width: 280upx;
		display: flex;
		align-items: center;
	}

	.contentTwo-name {
		height: 60upx;
		line-height: 60upx;
	}

	.contentTwo-text {
		font-size: 32upx;
	}

	.lie_right2 {
		box-sizing: border-box;
		display: flex;
		align-items: center;
		line-height: 60upx; 
	}
	.check-btn-box {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 20upx;
		margin-bottom: 80upx;
	}
	.check-btn {
		flex:1;
		text-align: center;
		margin: 0 40upx;
		height: 80upx;
		line-height: 80upx;
		color: #fff;
		text-align: center;
		font-size: 30upx;
		background-color:#64a0e6;
		border-radius: 10upx;
	}
	.to-examine {
		width: 80%;
		margin: 0 auto;
		margin-top: 80upx;
		margin-bottom: 40upx;
		height: 80upx;
		line-height: 80upx;
		color: #fff;
		text-align: center;
		font-size: 30upx;
		background-color:#64a0e6;
		border-radius: 10upx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.to-examine span{
		margin-left: 10upx;
	}
	.opinion,.opinion2 {
		width: 100%;
		padding-top: 30upx;
		text-align: center;
		background-color: #fff;
		border-radius: 2px 2px 0 0;
		position: fixed;
		z-index: 999;
		width: 90%;
		left: 50%;
		top: 50%;
		transform: translate(-50%,-50%);
		border-radius: 12upx;
		box-sizing: border-box;
	}
	.opinion2{
		text-align: left;
		padding: 30upx;
		min-height: 400upx;
	}
	.opinion2-title{
		margin-bottom: 20upx;
	}
	.opinion-title,.opinion2-title {
		font-size: 16px;
	}
	
	.PURCHASE-DESC {
		width: 100%;
		border: none #fff;
		background-color: transparent;
		outline: none;
		color: #000;
	}

	.opinion-hr {
		width: 100%;
		color: black;
		margin: 0.35rem auto;
	}

	.buttton1 {
		width: 100%;
		background-color: #4c4b5b;
		border: none;
		color: #fff;
		height: 80upx;
		line-height: 80upx;
	}

	.commodityP {
		color: #b7b8ba;
		padding: 0.5rem;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.photo-btn {
		display: flex;
		align-items: center;
		
	}
	.photo-btn:after{
		content: '';
		display: block;
		/* position: absolute; */
		
		flex: 1;
		height: 24upx;
		width: 24upx;
		background: url(/static/images/effective/sj.png) no-repeat center right;
		background-size: contain;
	}
	.commodityContent {
		box-sizing: border-box;
		display: flex;
		align-items: center;
		width: 180upx;
		justify-content: center;
		/* padding-top: 6upx; */
		box-shadow: 0px 1upx 8upx 0.4upx #ccc;
		flex-direction: column;
		border-radius: 4upx;
	}
	.commodityContent span{
		/* font-size: 24upx; */
	}
	.wid70 {
		line-height: 60upx;
		font-size: 24upx;
		color: #333;
	}
	.add{
		width: 20upx;
		text-align: center;
	}
	.commodityContent-cashpay{
		/* width: 50%; */
		justify-content: flex-start;
		box-shadow: unset;
		display: flex;
		/* align-items: flex-end; */
	}
	.commodityContent img{
		margin-right: 10upx;
	}
	.commoditytitle {
		font-size: 20px;
		color: #ec9061;
		padding-left: 1rem;
		padding-top: 0.5rem;
	}

	.trialani {
		width: 10rem;
		height: 6rem;
		box-shadow: 0px 1px 8px 0.2px #e2e2e2;
		text-align: center;
		background-color: #fff;
		position: fixed;
		top: 42%;
		left: 50%;
		-webkit-transform: translate3d(-50%, -50%, 0);
		-moz-transform: translate3d(-50%, -50%, 0);
		-o-transform: translate3d(-50%, -50%, 0);
		-ms-transform: translate3d(-50%, -50%, 0);
		transform: translate3d(-50%, -50%, 0);
	}

	.commodity {
		width: 100%;
		background-color: #fff;
		padding: 30upx 20upx;
		box-sizing: border-box;
	}

	.commodity>div {
		display: flex;
		justify-content: space-around;
		font-size: 24upx;
		align-items: center;
		margin-bottom: 30upx;
		
	}
	.commodityContent>div {
		background: url('/static/images/effective/sjjy_jb.png') no-repeat center;
		width: 100%;
		text-align: center;
		background-size: contain;
		margin-top: 2upx;
	}
	.commodity>div:last-child{
		padding-top: 12upx;
		margin-bottom: 0;
	}
	.commodity img{
		display: none;
		width: 40upx;
		height: 40upx;
		/* display: inline-block; */
		vertical-align: middle;
	}
	.cashpay-box img,.to-examine img{
		width: 40upx;
		height: 40upx;
	}
	.color1 {
		display: block;
		text-align: left;
		color: #333;
		font-size:28upx;
		line-height: 60upx;
	}

	.ctitle {
		display: inline-block;
		text-align: left;
		vertical-align: middle;
		color: #63A0E5;
		font-size: 24upx;
	}

	.cor {
		color: #D13B3B;
		line-height: 60upx;
	}
	.shenhe-mask{
		position: fixed;
		z-index: 998;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: rgba(0, 0, 0, .6);
	}
	.text-content{
		height: 150upx;
		width: 100%;
		font-size: 28upx
	}
	.check-reason{
		border: 1upx solid #d2d2d2;
		padding: 20upx;
		box-sizing: border-box;
	}
	.text-box{
		padding: 30upx 30upx;
	}
	.cashpay{
		display: inline-block;
		border-bottom: 1upx solid #63a0e5;
		/* border-radius: 10upx; */
		/* margin-left: 10upx; */
		padding-left: 16upx;
		height: 60upx;
		line-height: 60upx;
		color: #878787;
		box-sizing: border-box;
		width: 160upx;
	}
	.cashpay-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #eeeeee;
		padding: 30upx;
		flex-wrap: wrap;
	}
	.cashpay-box>div{
		width: 50%;
		display: flex;
		align-items: center;
		height: 70upx;
	}
	.cashpay-check{
		margin: 0 20upx 0 10upx;
	}
	.data-check{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20upx;
	}
	.data-check>.ctitle{
		width: 30%;
		display: flex;
		justify-content: center;
		color: #999;
	}
	
	.data-check-data{
		box-sizing: border-box;
		display: flex;
		align-items: center;
		width: 28%;
		justify-content: center;
		padding: 8upx 0;
		box-shadow: 0px 1px 8px 0.2px #e2e2e2;
		height: auto;
		border-radius: 4upx ;
	}
	.data-check-data input{
		width: 90%;
	}
	
	.check-btn{
		width: 48%;
		background-color: #64a0e6;
		border: none;
		color: #fff;
		height: 80upx;
		line-height: 80upx;
		margin-top: 30upx;
		text-align: center;
		border-radius: 10upx;
	}
	.no-check{
		background-color: #fff;
		color: #666;
		border: 1px solid #d2d2d2;
	}
	
	.ico:before{
		height: 32upx;
	}
	
	.content-line{
		border-bottom: 1px dashed #eee;
		margin: 10upx 0;
	}
	.scan-ico, .shouchi-ico, .jiekou-ico,.weisc-ico {
		display: flex;
		align-items: center;
		
	}
	.scan-ico:after {
		content:'';
		display: block;
		margin-left: 16upx;
		width: 30upx;
		height: 30upx;
		background: url(/static/images/effective/ewm.png) no-repeat center;
		background-size: contain;
	}
	.shouchi-ico:after {
		content:'';
		display: block;
		margin-left: 16upx;
		width: 21upx;
		height: 29upx;
		background: url(/static/images/effective/scj.png) no-repeat center;
		background-size: contain;
	}
	.jiekou-ico:after {
		content:'';
		display: block;
		margin-left: 16upx;
		width: 29upx;
		height: 27upx;
		background: url(/static/images/effective/jkcs.png) no-repeat center;
		background-size: contain;
	}
	.ico-user:before{
		background-image: url('/static/images/tender/lxr.png');
	}
	.ico-sjx:before{
		background-image: url('/static/images/expense/sjx.png');
	}
</style>
