<template>
	<div class="effectiveDetail">
		<div v-if="effectiveShow && !loading">

			<div class="contentTwo-head">

				<div class="uni-flex jc-between ">
					<span class="detail-title uni-ellipsis"
						:class="{'scan-ico':effectiveDetail.SCAN_TYPE===1,'shouchi-ico':effectiveDetail.SCAN_TYPE===2,'jiekou-ico':effectiveDetail.SCAN_TYPE===3}">{{effectiveDetail.SHOPNAME}}</span>
					<div class="detail-status"> {{effectiveDetail.TREATMENT_MARK}} </div>
				</div>

				<span style="color: #979797;">{{effectiveDetail.SERVERPART_NAME}}</span>

				<view class="content-detail-box">
					<div class="uni-flex ai-center jc-between">
						<div class="contentTwo-left">
							<span class="fourth-name">结账人员：</span>{{effectiveDetail.WORKER_NAME}}
						</div>
						<div class="contentTwo-right">{{effectiveDetail.ENDACCOUNT_DATE}}</div>
					</div>
					<template v-if="effectiveDetail.DESCRIPTION_STAFF !== ''">
						<div class="content-line uni-flex ai-center jc-between">
							<div class="contentTwo-left">
								<span class="fourth-name">校验人员：</span>{{effectiveDetail.DESCRIPTION_STAFF}}
								<span class="ico ico-yd" v-if="effectiveDetail.DESCRIPTION_MARK==2000"></span>
							</div>
							<div class="contentTwo-right"> {{effectiveDetail.DESCRIPTION_DATE}} </div>
						</div>
						
						<div class="desc-info">
							<div class="fourth-name ">校验意见：</div>
							<div>{{effectiveDetail.DIFFERENCE_REASON}}</div>
						</div>
					</template>
			
					<template v-if="effectiveDetail.APPROVE_STAFF !== '' && effectiveDetail.TREATMENT_MARKSTATE!==1">
						<div class="content-line uni-flex ai-center jc-between">
							<div class="contentTwo-left">
								<span class="fourth-name">{{effectiveDetail.TREATMENT_MARKSTATE===0? '驳回':'审核'}}人员：</span>{{effectiveDetail.APPROVE_STAFF}}
								<span class="ico ico-yd" v-if="effectiveDetail.APPROVE_MARK==2000"></span>
							</div>
							<div class="contentTwo-right">
								{{effectiveDetail.APPROVE_DATE}}
							</div>
						</div>

						<div class="desc-info">
							<div class="fourth-name">{{effectiveDetail.TREATMENT_MARKSTATE===0? '驳回':'审核'}}意见：</div>
							<div>{{effectiveDetail.APPROVED_INFO}}</div>
						</div>
					</template>
					
					<template v-if="effectiveDetail.ENDACCOUNT_DESC !=='' ">
						<div class="content-line uni-flex ai-center jc-between">
							<div class="contentTwo-left">
								<span class="fourth-name">主任名称：</span>{{endaccountMsg[0]}}
								<span class="ico ico-yd" v-if="effectiveDetail.MASTER_MARK==2000"></span>
							</div>
							<div class="contentTwo-right"><span>{{endaccountMsg[1]}}</span>
							</div>
						</div>
						
						<div class="desc-info">
							<div class="fourth-name">确认意见：</div><span>{{endaccountMsg[2]}}</span>
						</div>
					</template>
				</view>
			</div>
			<!-- 稽核信息 -->
			<template v-if="Audit_List.length>0">

				<view class="modle-title">
					<h2>稽核信息</h2>
				</view>

				<crashAuditItem v-for="(item, index) in Audit_List" :key="index" :item="item" @toPage="toPage(item)"></crashAuditItem>
			</template>

			<!-- 营收详情 -->
			<view class="modle-title">
				<h2>营收详情</h2>
				<span class="photo-btn" v-if="imagesList.length>0" @tap="showImg()">查看账单图片</span>
			</view>
			<div class="commodity">
				<div>
					<div class="commodityContent">
						<span class="color1">{{showCash}}</span>
						<div>
							<span class="ctitle">现金支付</span>
						</div>
					</div>
					<div class="add">+</div>
					<div class="commodityContent">
						<span class="color1">{{$util.fmoney(effectiveDetail.MOBILEPAYMENT)}}</span>
						<div>
							<span class="ctitle">移动支付</span>
						</div>

					</div>
					<div>=</div>
					<div class="commodityContent">
						<span class="color1">{{$util.fmoney(effectiveDetail.TOTALSELLAMOUNT)}}</span>
						<div>
							<span class="ctitle">销售金额</span>
						</div>
					</div>
				</div>
				<div>
					<div class="commodityContent">
						<span class="color1">{{$util.fmoney(effectiveDetail.CASHPAY_DOWNLORD)}}</span>
						<div>
							<span class="ctitle">缴款金额</span>
						</div>
					</div>
					<div class="add">-</div>
					<div class="commodityContent">
						<span class="color1">{{showCash}}</span>
						<div>
							<span class="ctitle">现金支付</span>
						</div>

					</div>
					<div>=</div>
					<div class="commodityContent">
						<span class="color1">{{$util.fmoney(effectiveDetail.DIFFERENT_PRICE)}}</span>
						<div>
							<span class="ctitle">长短款额</span>
						</div>
					</div>
				</div>
				<div>
					<div class="commodityContent-cashpay">
						<span class="wid70" style="color: #333;">误差率：</span>
						<span class="color1" :class="{'text-red': calcWuchalv > 0.3}">{{calcWuchalv}}%</span>
					</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>

				<view class="cashpay-box">
					<div>
						<image src="/static/images/effective/dpjl.png" >
						<span class="cashpay-check">单品记录：</span>
						<uni-load-more v-if="isFACTAMOUNT_SALE==2 " loadingType="1" :contentText="contentText" />
						<image src="/static/images/effective/true.png" v-else-if="isFACTAMOUNT_SALE==1 ">
						<image src="/static/images/effective/false.png"  v-else>
					</div>
					<div>
						<image src="/static/images/effective/jk.png" />
						<span class="cashpay-check">移动支付：</span>
						<uni-load-more v-if="isFACT_AMOUNT==2" loadingType="1" :contentText="contentText"/>
						<image src="/static/images/effective/true.png" v-else-if="isFACT_AMOUNT==1">
						<image src="/static/images/effective/false.png"  v-else>
					</div>

					<div v-if="isTICKETCODE_CIGARETTE == true">
						<image src="/static/images/effective/xysj.png" >
						<span class="cashpay-check">香烟数据：</span>
						<image src="/static/images/effective/true.png">
					</div>
					<div v-if="isSELLCOUNT_PROMOTION == true">
						<image src="/static/images/effective/zxsj.png" />
						<span class="cashpay-check">促销数据：</span>
						<image src="/static/images/effective/true.png">
					</div>
				</view>
			</div>


			<div v-show="showPopupYj||showPopupCheck" class="shenhe-mask" @click.stop="maskFn()"></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 no-check" @click="maskFn">取消</div>
					<div class="check-btn" @click="examine()">确定</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">{{mobliePayBalance}}</span>
							</div>
							<div>+</div>
							<div class="data-check-data">
								<span class="color1">{{saleCorrect}}</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">{{correctAmout}}</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">{{correctAmout}}</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:1rpx 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="img-box">

					<div class="upload-file-container">
						<div class="upload-file-unit" v-for="(item,index) in uploadImgList" :key="index">
							<span class="upload-file-remove" @click.stop="deleteImgFunc(index)">-</span>
							<image mode="aspectFill" :src="item" @tap="showUpImg(index)" />
						</div>
						<div class="upload-file-add" @click="chooseImage">
							<div class="upload-file-add-container"></div>
						</div>
					</div>
				</div>
				<div class="check-btn-box">
					<div class="check-btn no-check" @click="noCheck">取消</div>
					<div class="check-btn" @click="checkSubmit">校验</div>
				</div>
			</div>

			<div class="check-btn-box page-btn-box" v-if="isCheck!==0">
				<!-- 财务审核 -->
				<template v-if="isCheck==2">
					<div class="check-btn" @click="menuImg(true)">
						<span>驳回</span>
					</div>
					<div class="check-btn" @click="menuImg(false)">
						<span>审核</span>
					</div>
				</template>
				<!-- 数据校验 -->
				<template v-else-if="isCheck==1">
					<!-- 单品数据错误或移动支付错误 （isFACTAMOUNT_SALE == 0 || 单品数据不一致） -->
					<div class="check-btn" @click="correctFn" v-if=" isFACT_AMOUNT == 0">

						<span>一键冲正</span>
					</div>
					<div class="check-btn" @click="checkOutFn()">
						<span>校验</span>
					</div>
				</template>
			</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 crashAuditItem from './components/crashAuditItem.vue';
	import uniLoadMore from './components/uni-load-more.vue';

	import {mapState, mapGetters,mapMutations} from "vuex";
	export default {
		data() {
			return {
				loading: true,
				showPopupCheck: false,
				showPopupYj: false,
				isdisabled: true,
				ischeckOut: false,
				effectiveDetail: {},
				effectiveShow: false,
				SERVERPART_ID: '',// 服务区ID
				ENDACCOUNT_ID: '',
				isCheck: 0, // 0 不显示按钮 1 数据校验按钮 2 财务审核按钮
				PURCHASEDESC: "" ,//意见
				examineType: "", // 校验请求接口名称
				endaccountMsg: [], // 主任意见
				
				mobliePayBalance: 0, // 移动冲正支付差额
				isFACTAMOUNT_SALE: 2, // 2 正在加载，1单品数据一致，0单品数据不一致
				isFACT_AMOUNT: 2,
				isTICKETCODE_CIGARETTE: false,
				isSELLCOUNT_PROMOTION: false,
				checkReason: "已确认", //校验原由
				contentText: {
					contentdown: "",
					contentrefresh: "",
					contentnomore: ""
				},
				isback: false, // 是否是驳回
				imagesList: [],
				Audit_List: [],
				uploadImgList: [] //短款上传校验凭证的列表
			}
		},
		computed: {
			...mapState({
				user: (state)=>{ 
					let { UserName, Membership_Id } = state.userData
					return { UserName:UserName, Membership_Id:Membership_Id }
				}
			}),
			...mapGetters({
				reloading: 'shouldReLoadingList'
			}),
			// 金额格式化处理
			showCash() {
				return this.$util.fmoney(this.effectiveDetail.CASH)
			},
			correctAmout() { // 现金冲正
				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
			},
			saleCorrect() { // 到账实差
				let s = parseFloat(this.effectiveDetail.MOBILE_CORRECT) + '' == 'NaN' ? 0 : parseFloat(this.effectiveDetail.MOBILE_CORRECT)
				return s - parseFloat(this.mobliePayBalance)
			},
			calcWuchalv(){ // 误差率
				let _data = this.effectiveDetail
				if ( _data.CASH == 0 ) {
					if(_data.DIFFERENT_PRICE!=0) {
						return "100.00";
						
					}else {
						return "0.00";
					}
				} 
				else {
					
					return (Math.abs(_data.DIFFERENT_PRICE)  / _data.CASH * 100).toFixed(2);
				
				}
			}
		},
		components: {
			crashAuditItem,
			uniPopup,
			uniLoadMore
		},
		methods: {
			...mapMutations(['shouldReLoadingList']),
			// 图片预览
			showImg() {
				let list = []
				this.imagesList.map(n => {
					list.push(n.IMAGE_URL)
				})
				uni.previewImage({
					urls: list,
					current: 0,	
					loop: true,
					indicator: 'number'
				});
			},
			deleteImgFunc(index) {
				this.uploadImgList.splice(index, 1)
			},
			showUpImg(index) {
				uni.previewImage({
					urls: this.uploadImgList,
					current: index,
					loop: true,
					indicator: 'number'
				});
			},
			chooseImage() {
				let _this = this
				uni.chooseImage({
					sourceType: ['camera', 'album'],
					sizeType: 'compressed',
					cout: 1,
					success: (data) => {
						if (data.tempFilePaths.length > 0) {

							data.tempFilePaths.forEach(function(n) {
								uni.getFileSystemManager().readFile({
									filePath: n, //选择图片返回的相对路径
									encoding: 'base64', //编码格式
									success: function(res) { // 
										let base64 = 'data:image/jpeg;base64,' + res
											.data //.replace(/\+/ig,'%2B') //不加上这串字符，在页面无法显示的哦

										_this.uploadImgList.unshift(base64)
									}
								})
							})
						}
					},
				});
			},
			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 => {
				
					let _data = res.Result_Data
					if (datatype == 1) {
						_detail.FACTAMOUNT_SALE = _data.FactAmount_Sale = Number(_data.FactAmount_Sale) //单品金额
						_detail.SELLCOUNT_SALE = _data.SellCount_Sale //单品金额 

						_this.isFACTAMOUNT_SALE = _this.checkSinglePro(_detail)
					}
					
					if (datatype == 2) {
						_detail.TICKETCODE_CIGARETTE = _data.TicketCode_Cigarette //香烟客单数量
						_detail.SELLCOUNT_CIGARETTE = _data.SellCount_Cigarette
						_detail.FACTAMOUNT_CIGARETTE = _data.FactAmount_Cigarette

						_this.isTICKETCODE_CIGARETTE = _this.checkCigarette(_detail)
						
					}
					if (datatype == 3) {

						_detail.FACT_AMOUNT = Number(_data.Fact_Amount) //移动支付销售金额
						_detail.TICKETCOUNT = _data.Ticket_Count //移动支付销售金额
						
						_this.isFACT_AMOUNT = _this.checkMobileCorrect(_detail)
						
					}
					if (datatype == 4) {
						_detail.SELLCOUNT_PROMOTION = _data.SellSount_Promotion //促销数量
						_detail.FACTAMOUNT_PROMOTION = _data.FactAmount_Promotion //促销数量
						
						_this.isSELLCOUNT_PROMOTION = _this.checkPromotion(_detail)
						
					}
				})
			},
			//  单品数据判断
			checkSinglePro(_data) { // 单品计算公式：FACTAMOUNT_SALE = TOTALSELLAMOUNT 或者 TOTALSELLAMOUNT = FACTAMOUNT_SALE + FACTAMOUNT 或 (_data.TOTALSELLAMOUNT+FACTAMOUNT) == _this.FACTAMOUNT_SALE
				
				if (_data.FACTAMOUNT_SALE == _data.TOTALSELLAMOUNT || (_data.TOTALSELLAMOUNT + _data.FACTAMOUNT) == _data.FACTAMOUNT_SALE || _data.FACTAMOUNT_SALE == _data.CASHPAY) {
					return 1
				} else {
					return 0
				}
			},
			// 验证香烟数据
			checkCigarette(_data) {
				if (_data.TICKETCODE_CIGARETTE && _data.TICKETCODE_CIGARETTE != NaN && Number(_data.TICKETCODE_CIGARETTE) !== 0) {
					return true
				} else {
					return false
				}
			},
			// 验证移动支付
			checkMobileCorrect(_data){
				
				if ((_data.FACT_AMOUNT + _data.SALE_CORRECT) == _data.MOBILEPAYMENT) { // 公式： fa+sc=mp+mc; sc=mc-mpb
					_data.MOBILE_CORRECT = 0
					this.mobliePayBalance = - _data.SALE_CORRECT
					return 1
				} else {
					this.mobliePayBalance = _data.FACT_AMOUNT - _data.MOBILEPAYMENT // 移动冲正支付差额 实收金额-移动支付金额
					
					if(_data.MOBILE_CORRECT ==''){ // 默认到账差额为零，使等式成立
						this.effectiveDetail.MOBILE_CORRECT = this.mobliePayBalance // 移动冲正
						this.effectiveDetail.SALE_CORRECT = 0  // 到账实差
					}
					return 0 // 移动冲正 = 移动支付差额+到账实差
				
				}
			},
			// 验证促销数据
			checkPromotion(_data){
				if (_data.SELLCOUNT_PROMOTION != 0 && _data.SELLCOUNT_PROMOTION != '') {
					return true
				} else {
					return false
				}
			},
			// 数据校验门店列表
			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 ? res.Result_Data.Image_List.List : []
					if (res.Result_Data.Audit_List) { // 若稽核数据存在，则赋值
						_this.Audit_List = res.Result_Data.Audit_List.List
					}
					let _data = res.Result_Data.Endaccount_List

					_this.effectiveDetail = _data
					
					_this.endaccountMsg = _data.ENDACCOUNT_DESC.split("|");
					
					// 如果当前数据为日结校验状态，并且单品数据为空 则异步请求远程单品数据，移动支付数据，香烟数据、促销数据;否则，验证这些数据是否正确
					

					if (_data.SCAN_TYPE != 3) { // 若数据传输类型为接口传输 则不需要远程请求单品数据,默认单品销售金额=收银端销售金额， 移动支付实收金额 = 收银端移动支付
						if (_data.TREATMENT_MARKSTATE==0 && _data.FACTAMOUNT_SALE == "") {
							_data.FACTAMOUNT = _data.FACTAMOUNT == '' ? 0 : _data.FACTAMOUNT
							_data.SALE_CORRECT = _data.SALE_CORRECT == '' ? 0 : _data.SALE_CORRECT
							_this.getEndAccountDate(1) // 单品数据
							_this.getEndAccountDate(2) // 香烟数据
							_this.getEndAccountDate(3) // 移动支付
							_this.getEndAccountDate(4) //促销数据
						}else {
							_this.isFACTAMOUNT_SALE = _this.checkSinglePro(_data) // 单品数据 是否一致
							_this.isTICKETCODE_CIGARETTE = _this.checkCigarette(_data) // 香烟数据 
							_this.isFACT_AMOUNT = _this.checkMobileCorrect(_data) // 移动支付
							_this.isSELLCOUNT_PROMOTION = _this.checkPromotion(_data) // 促销数据
						}
						
					} else {
						_data.FACTAMOUNT_SALE = _data.TOTALSELLAMOUNT
						_data.FACT_AMOUNT = _data.MOBILEPAYMENT
						_this.isFACTAMOUNT_SALE = _this.checkSinglePro(_data) // 单品数据
						_this.isFACT_AMOUNT = _this.checkMobileCorrect(_data) // 移动支付
						_this.isTICKETCODE_CIGARETTE = _this.checkCigarette(_data) // 香烟数据
					}
					
					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;
					}
					
					_this.effectiveShow = true
					_this.$forceUpdate()
				})
			},
			
			maskFn() {
				this.showPopupCheck = false
				this.showPopupYj = false
			},
			noCheck() {
				this.showPopupCheck = false
			},
			menuImg(isback) {
				this.isback = isback
				this.PURCHASEDESC = isback ? '' : "同意"
				this.showPopupYj = true
			},
			correctFn() { // 一键冲正
				let _this = this
				uni.showLoading({
					title: "正在提交...",
					mask: true
				})
				_this.$request.$post('CorrectEndAccount', {
					endAccount_Id: _this.effectiveDetail.ENDACCOUNT_ID,
					factAmount_Sale: _this.effectiveDetail.FACTAMOUNT_SALE,
					mobile_Payment: _this.effectiveDetail.MOBILEPAYMENT,
					fact_Amount: _this.effectiveDetail.FACT_AMOUNT,
					cash_Pay: _this.effectiveDetail.CASHPAY,
					IsCommodity_Sale: _this.isFACTAMOUNT_SALE
				}).then(res => {
					uni.hideLoading()
					if (res.Result_Code == '100') {
						uni.showToast({
							icon: 'none',
							title: res.Result_Desc,
							duration: 1000,
							success() {
								_this.getEffectiveDetail()
								// _this.loading = true
								uni.showLoading({
									title: "正在刷新...",
									mask: true
								})
							}
						});
						// _this.getEffectiveDetail()
					} else {
						uni.showModal({
							title: '温馨提示',
							content: res.Result_Desc,
							success() {
								if (res.Result_State && res.Result_State == 1) {

									_this.getEffectiveDetail()
									_this.loading = true
									uni.showLoading({
										title: "正在刷新...",
										mask: true
									})
								}
							}
						})
					}

				})
			},
			checkOutFn() {
				let _this = this
				let effectiveDetail = this.effectiveDetail
				// if (_this.effectiveDetail.SCAN_TYPE != 3 && _this.isFACTAMOUNT_SALE === 0) { // 当数据信息为接口传输类型时,不校验单品数据是否正确
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '单品数据不一致，请冲正后重试',
				// 		duration: 1000
				// 	});
				// 	return false
				// }
				let hasNoAudit = _this.Audit_List.some(n =>  n.ERROR_RATE>0.2 && !n.CHECKACCOUNT_DESC)
				if (hasNoAudit) {
					uni.showToast({
						icon: 'none',
						title: '请确认稽核已完成再进行校验',
						duration: 1000
					});
					return false
				}


				if (effectiveDetail.SCAN_TYPE === 3 || _this.isFACT_AMOUNT == 1) { // 接口传输时 忽略   单品数据一致（_this.isFACTAMOUNT_SALE == 1 &&），移动支付一致
					
					_this.showPopupCheck = true
					if (effectiveDetail.CASHPAY !== effectiveDetail.TOTALSELLAMOUNT + effectiveDetail.CORRECT_AMOUNT) { // 校验 实收金额 = 销售+冲正 等式是否成立 不成立则

						_this.ischeckOut = true
						effectiveDetail.CASH_CORRECT = Math.round((effectiveDetail.CASHPAY - effectiveDetail.TOTALSELLAMOUNT) * 100) / 100 // 默认现金冲正金额
					} else {
						_this.ischeckOut = false
					}
				} else  { // 单品数据不一致（_this.isFACTAMOUNT_SALE == 1 &&），if ( _this.isFACT_AMOUNT == 0) 移动支付不一致  
					
					_this.showPopupCheck = true
					_this.ischeckOut = true
					effectiveDetail.CASH_CORRECT = Math.round((effectiveDetail.CASHPAY - effectiveDetail.TOTALSELLAMOUNT - effectiveDetail.MOBILE_CORRECT) * 100) / 100 // 默认现金冲正金额
				} 
				// else {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '请确认移动支付和单品记录无误后再进行审核',
				// 		duration: 1000
				// 	});
				// }
			},
			// 校验通过提交
			checkSubmit() {
				let _this = this
				let effectiveDetail = this.effectiveDetail
				
				// let money1 = parseFloat(effectiveDetail.CASHPAY) === parseFloat(effectiveDetail.TOTALSELLAMOUNT+_this.correctAmout) // 实收金额 = 销售+冲正
				// let money2 = parseFloat(_this.correctAmout) == parseFloat(effectiveDetail.MOBILE_CORRECT+effectiveDetail.CASH_CORRECT) // 冲正 = 移动冲正+现金冲正
				// let money3 = parseFloat(effectiveDetail.MOBILE_CORRECT) == parseFloat(_this.mobliePayBalance + _this.saleCorrect) // 移动冲正 = 移动支付差额+到账实差
			 
				// if (money1 && money2) {

				// 	if (_this.isFACT_AMOUNT == 0 && !money3) {
				// 		uni.showToast({
				// 			icon: 'none',
				// 			title: '请输入正确的移动支付冲正金额。',
				// 			duration: 1000
				// 		});
				// 		return false
				// 	}
					if (_this.checkReason !== "") {
						uni.showLoading({
							title: '正在提交...',
							mask: true
						})
						_this.$request.$post('SaveEndAccount', {

							serverpart_Id: effectiveDetail.SERVERPART_ID,
							endAccount_StartDate: effectiveDetail.ENDACCOUNT_STARTDATE,
							endAccount_Date: effectiveDetail.ENDACCOUNT_DATE,
							endAccount_Id: effectiveDetail.ENDACCOUNT_ID,
							sale_Correct: _this.saleCorrect,
							mobile_Payment: effectiveDetail.MOBILEPAYMENT,
							mobile_Correct: effectiveDetail.MOBILE_CORRECT,
							sellcount_Sale: effectiveDetail.SELLCOUNT_SALE,
							factAmount_Sale: effectiveDetail.FACTAMOUNT_SALE,
							sellCount_Cigarette: effectiveDetail.SELLCOUNT_CIGARETTE,
							factAmount_Cigarette: effectiveDetail.FACTAMOUNT_CIGARETTE,
							ticket_Count: effectiveDetail.TICKETCOUNT,
							fact_Amount: effectiveDetail.FACT_AMOUNT,
							sellCount_Promotion: effectiveDetail.SELLCOUNT_PROMOTION,
							factAmount_Promotion: effectiveDetail.FACTAMOUNT_PROMOTION,
							correct_Amount: _this.correctAmout,
							staff_Name: _this.user.UserName,
							reason: _this.checkReason,
							cash_Pay: effectiveDetail.CASHPAY,
							ImageArry: _this.uploadImgList.join('|')
						}).then(res => {
							uni.hideLoading()
							if (res.Result_Code == 100) {
								uni.showToast({
									icon: 'success',
									title: '校验成功',
									success() {
										// _this.showPopupMiddle = false
										_this.showPopupCheck = false
										setTimeout(function() {
											uni.$emit('datasummary', true)
											uni.navigateBack({
												delta: 1
											})
										}, 1000)

									}
								});
							} 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({
						title: '正在提交...',
						mask: true
					})
					_this.$request.$post(_this.examineType, JSON).then(res => {
						uni.hideLoading()
						if (res.Result_Code == 100) {
							uni.showToast({
								icon: 'success',
								title: '审核通过',
								duration:1000,
								success() {
									_this.showPopupYj = false
									_this.getEffectiveDetail()
									
								}
							});
							// _this.showPopupMiddle = false

							uni.$emit('datasummary', true)
						} else {
							uni.showModal({
								title: '温馨提示',
								content: res.Result_Desc,
								showCancel: false,
								success(res) {

								}
							})
							// _this.showPopupMiddle = false
							_this.showPopupYj = false
							_this.getEffectiveDetail()

						}

					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '意见不能为空',
						duration: 2000
					});
				}
			},
			// 驳回审核
			toBack() {
				let _this = this
				uni.showLoading({
					title: '正在提交...',
					mask: true
				})
				_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
						});
					}

				})
			},
			toPage(item) {
				this.$util.toNextRoute('navigateTo', '/pages/cashAudit/detail?id=' + item.CHECKACCOUNT_ID)
			}
		},
		onUnload() {
			this.$util.addUserBehavior()
		},
		onShow() {
			let _this = this

			if (this.reloading) {
				uni.showLoading({
					title: '正在加载',
					mask: true
				})
				this.getEffectiveDetail()
				this.shouldReLoadingList(false)
			}
		},
		onLoad(option) {
			let _this = this
			if (option.SERVERPART_ID) {
				this.SERVERPART_ID = option.SERVERPART_ID
			}
			this.ENDACCOUNT_ID = option.ENDACCOUNT_ID
			uni.showLoading({
				title: '正在加载',
				mask: true
			})
			this.getEffectiveDetail()

		}
	}
</script>

<style scoped>
	.effectiveDetail {
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 140rpx;
	}

	.contentTwo-head {
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx 26rpx 0 26rpx;
		position: relative;
		font-size: 24rpx;
	}

	.contentTwo-head span.detail-title {
		font-size: 30rpx;
	}

	.contentTwo-head .detail-status {
		font-size: 24rpx;
		color: #F4904E;
	}

	.content-detail-box {
		box-shadow: 0rpx 2rpx 8rpx 0px rgba(231, 231, 231, 0.67);
		border-radius: 7rpx;
		padding: 36rpx 24rpx 28rpx 24rpx;
		background-color: #fff;
		margin-top: 20rpx;
		font-size: 26rpx;
	}

	.content-detail-box span {
		font-size: 26rpx;
	}

	.content-line {
		border-top: 1px dashed #eee;
		margin-top: 16rpx;
		padding-top: 16rpx;
	}

	.contentTwo-left {
		/* height: 60rpx;
		line-height: 60rpx; */
		font-size: 26rpx;
		display: flex;
		align-items: center;
	}

	.fourth-name {
		min-width: 120rpx;
		max-width: 140rpx;
		color: #ADB2BF;
		font-size: 26rpx;
	}
	.ico-yd {
		display: flex;
		align-items: center;
	}
	.ico-yd:before {
		background-image: url('/static/images/contract/htsp_mobile.png');
		margin-right: 0rpx;
		height: 24rpx;
		background-position: center right;
	}
	.contentTwo-right {
		width: 228rpx;
		font-size: 26rpx;
		text-align: right;
	}

	.desc-info {
		display: flex;
		align-items: flex-start;
		margin-top: 8rpx;
	}

	.desc-info view:last-child {
		line-height: 1.5;
		font-size: 26rpx;
		padding-top: 2rpx;
	}

	.check-btn-box {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;

	}

	.page-btn-box {
		margin-bottom: 0;
		position: fixed;
		width: 100%;
		background-color: #fafafa;
		padding-bottom: 40rpx;
		bottom: 0;
		left: 0;
		z-index: 2;
	}

	.check-btn {
		flex: 1;
		text-align: center;
		margin: 0 40rpx;
		height: 80rpx;
		line-height: 80rpx;
		color: #fff;
		text-align: center;
		font-size: 30rpx;
		background-color: #64a0e6;
		border-radius: 10rpx;
	}

	/* 	.to-examine {
		width: 80%;
		margin: 0 auto;
		margin-top: 80rpx;
		margin-bottom: 40rpx;
		height: 80rpx;
		line-height: 80rpx;
		color: #fff;
		text-align: center;
		font-size: 30rpx;
		background-color: #64a0e6;
		border-radius: 10rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.to-examine span {
		margin-left: 10rpx;
	} */

	.opinion,
	.opinion2 {
		width: 100%;
		padding-top: 30rpx;
		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: 12rpx;
		box-sizing: border-box;
	}

	.opinion2 {
		text-align: left;
		padding: 30rpx;
		min-height: 400rpx;
	}

	.opinion2-title {
		margin-bottom: 20rpx;
	}

	.opinion-title,
	.opinion2-title {
		font-size: 26rpx;
		font-weight: bolder;
	}

	.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: 80rpx;
		line-height: 80rpx;
	}

	.modle-title {
		color: #000;
		padding: 36rpx 30rpx 24rpx 30rpx;
		font-size: 26rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.modle-title h2 {
		font-weight: bolder;
	}

	/* 账单图片标题 */
	.photo-btn {
		display: flex;
		align-items: center;
		color: #63A0E5;
	}

	.photo-btn:before {
		content: '';
		display: block;

		height: 42rpx;
		width: 42rpx;
		background: url(/static/images/fjtp.png) no-repeat center right;
		background-size: contain;
	}

	.photo-btn:after {
		content: '';
		display: block;
		/* flex: 1; */
		height: 24rpx;
		width: 24rpx;
		background: url(/static/images/effective/sj.png) no-repeat center right;
		background-size: contain;
	}

	/* end */


	.wid70 {
		line-height: 60rpx;
		font-size: 24rpx;
		color: #333;
	}

	/* .add {
		width: 20rpx;
		text-align: center;
	} */
	.commodityContent-cashpay {
	
		justify-content: flex-start;
		box-shadow: unset;
		display: flex;
		
	}

	/* 	.commoditytitle {
		font-size: 20px;
		color: #ec9061;
		padding-left: 1rem;
		padding-top: 0.5rem;
	}
 */

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

	.commodity>div {
		display: flex;
		justify-content: space-around;
		font-size: 24rpx;
		align-items: center;
		margin-bottom: 30rpx;

	}

	.commodityContent {
		box-sizing: border-box;
		display: flex;
		align-items: center;
		width: 180rpx;
		justify-content: center;
		/* padding-top: 6rpx; */
		box-shadow: 0px 1rpx 8rpx 0.4rpx #ccc;
		flex-direction: column;
		border-radius: 4rpx;
	}

	.commodityContent>div {
		background: url('/static/images/effective/sjjy_jb.png') no-repeat center;
		width: 100%;
		text-align: center;
		background-size: contain;
	}

	.commodity>div:last-child {
		padding-top: 12rpx;
		margin-bottom: 0;
	}

	/* .commodity img {
		display: none;
		width: 40rpx;
		height: 40rpx;
		vertical-align: middle;
	} */

	.cashpay-box image {
		width: 40rpx;
		height: 40rpx;
	}

	.color1 {
		color: #333;
		font-size: 28rpx;
		line-height: 56rpx;
	}

	.ctitle {
		color: #63A0E5;
		font-size: 24rpx;
	}

	.text-red {
		color: #D13B3B;
		line-height: 60rpx;
	}

	.shenhe-mask {
		position: fixed;
		z-index: 998;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: rgba(0, 0, 0, .6);
	}

	.text-content {
		max-height: 150rpx;
		height: 120rpx;
		width: 100%;
		font-size: 28rpx;
		line-height: 1.5;
	}

	.check-reason {
		background-color: #f8f9fa;
		padding: 16rpx 20rpx;
		box-sizing: border-box;
		border-radius: 14rpx 14rpx 0 0;
	}


	.cashpay {
		display: inline-block;
		border-bottom: 1rpx solid #63a0e5;

		padding-left: 16rpx;
		height: 60rpx;
		line-height: 60rpx;
		color: #878787;
		box-sizing: border-box;
		width: 160rpx;
	}

	.cashpay-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #f8f9fb;
		padding: 26rpx 0;
		flex-wrap: wrap;
		/* margin: 0 26rpx; */
	}

	.cashpay-box>div {
		width: 50%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		height: 70rpx;
		padding-left: 36rpx;
	}

	.cashpay-check {
		margin: 0 20rpx 0 10rpx;
	}

	.data-check {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.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: 8rpx 0;
		box-shadow: 0px 1px 8px 0.2px #e2e2e2;
		height: auto;
		border-radius: 4rpx;
	}

	.data-check-data input {
		width: 90%;
	}

	.check-btn {
		width: 48%;
		background-color: #64a0e6;
		border: none;
		color: #fff;
		height: 80rpx;
		line-height: 80rpx;
		margin-top: 30rpx;
		text-align: center;
		border-radius: 10rpx;
	}

	.no-check {
		background-color: #fff;
		color: #666;
		border: 1px solid #d2d2d2;
	}


	/* 传输方法的图标 */
	.scan-ico,
	.shouchi-ico,
	.jiekou-ico,
	.weisc-ico {
		display: flex;
		align-items: center;

	}

	.scan-ico:after {
		content: '';
		display: block;
		margin-left: 16rpx;
		width: 30rpx;
		height: 30rpx;
		background: url(/static/images/effective/ewm.png) no-repeat center;
		background-size: contain;
	}

	.shouchi-ico:after {
		content: '';
		display: block;
		margin-left: 16rpx;
		width: 21rpx;
		height: 29rpx;
		background: url(/static/images/effective/scj.png) no-repeat center;
		background-size: contain;
	}

	.jiekou-ico:after {
		content: '';
		display: block;
		margin-left: 16rpx;
		width: 29rpx;
		height: 27rpx;
		background: url(/static/images/effective/jkcs.png) no-repeat center;
		background-size: contain;
	}


	/* 图片上传 */
	.img-box {
		background: #f8f9fa;
		padding: 10rpx 0 20rpx 20rpx;
		border-radius: 0 0 14rpx 14rpx;
	}

	.upload-file-container {
		display: flex;
		align-items: center;
		width: 100%;
		/* min-height: 260rpx; */
		box-sizing: border-box;
		flex-wrap: wrap;
	}

	.upload-file-add-container {
		position: relative;
		border: 1rpx solid #ccc;
		width: 136rpx;
		height: 137rpx;
		border-radius: 6rpx;
		margin-bottom: 16rpx;
	}

	.upload-file-add-container::before {
		content: '';
		display: block;
		position: absolute;
		left: 40rpx;
		top: 50%;
		height: 2rpx;
		background-color: #ccc;
		width: 60rpx;
	}

	.upload-file-add-container::after {
		content: '';
		display: block;
		position: absolute;
		left: 50%;
		top: 40rpx;
		width: 2rpx;
		height: 60rpx;
		background-color: #ccc;
	}


	.upload-file-unit {
		position: relative;
		width: 137rpx;
		height: 136rpx;
		margin-right: 32rpx;
		margin-bottom: 16rpx;
		border-radius: 8rpx;
		border: 2rpx solid #ccc;
	}

	.upload-file-unit image {
		width: 136rpx;
		height: 136rpx;
		border-radius: 8rpx;
	}

	.upload-file-remove {
		position: absolute;
		top: -14rpx;
		right: -12rpx;
		display: inline-block;
		width: 37rpx;
		height: 37rpx;
		line-height: 30rpx;
		background-color: #ff0000;
		color: #ffffff;
		font-size: 30rpx;
		border-radius: 50%;
		text-align: center;
		z-index: 1;
	}
</style>
