<template>
    <div class="borderless" v-loading="pageLoading">
        <div class="customer-head">
            <div class="customer-back">
                <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
                           @click="backToList">返回列表
                </el-button>
            </div>
            <div class="add-customer-btn">
                <el-button  size="small" type="warning" plain  style="margin-right: 8px" :disabled="!form.id" v-if="form.isCleared == 1"
                            :loading="saveLoading" @click="finstlbillsRevokeSettlementfun">撤销结算
                </el-button>
                <el-button  size="small" type="success" plain  style="margin-right: 8px" :disabled="!form.id" v-else
                            :loading="saveLoading" @click="finstlbillsConfirmSettlementfun">确认结算
                </el-button>
                <el-button  size="small" type="primary" style="margin-right: 8px" :disabled="form.isCleared == 1" v-if="editSave"
                            :loading="saveLoading" @click="editHandle">编 辑
                </el-button>
                <el-button  size="small" type="primary" style="margin-right: 8px" :disabled="form.isCleared == 1" v-else
                            :loading="saveLoading" @click="editCustomer">保 存
                </el-button>
            </div>
        </div>

        <div style="margin: 55px 5px 0px 5px;'">
            <el-card class="box-card">
                <el-form :model="form" ref="form" label-width="90px" class="demo-ruleForm">
                    <el-row>
                        <el-row>
                            <el-col :span="5">
                                <el-form-item label="结算单号" prop="checkNo">
                                    <el-input style="width: 100%;" v-model="form.billNo"
                                              size="small" autocomplete="off"
                                              :disabled="true"
                                              clearable placeholder="请输入结算单号" >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="结算日期" prop="billDate">
                                    <el-date-picker v-model="form.billDate" clearable
                                                    style="width: 100%;"
                                                    type="date" size="small"
                                                    :disabled="editSave"
                                                    value-format="yyyy-MM-dd HH:mm"
                                                    placeholder="选择结算日期">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="限定金额" prop="billDate">
                                    <el-input style="width: 100%;" v-model="form.limitedAmount"
                                              size="small" autocomplete="off"
                                              :disabled="editSave"
                                              clearable placeholder="请输入限定金额" >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="审核期间" prop="etd">
                                    <el-date-picker
                                        v-model="form.approvedDate"
                                        type="datetimerange"
                                        range-separator="至"
                                        start-placeholder="开始日期"
                                        end-placeholder="结束日期"
                                        style="width: 100%;"
                                        size="small"
                                        :disabled="editSave"
                                        format="yyyy-MM-dd"
                                        value-format="yyyy-MM-dd"
                                        placeholder="选择对账日期">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="4">
                                <el-form-item label="申请单号" prop="billNo">
                                    <el-input style="width: 100%;" v-model="form.requestNo"
                                              size="small" autocomplete="off"
                                              :disabled="editSave"
                                              clearable placeholder="请输入单号" >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="10">
                                <el-form-item label="结算单位" prop="corpCnName">
                                    <el-col :span="11">
                                        <search-query :datalist="corpData"
                                                      :selectValue="form.corpCnName"
                                                      :clearable="true"
                                                      :disabled="editSave"
                                                      :filterable="true"
                                                      :remote="true"
                                                      :buttonIf="false"
                                                      :forParameter="{ key:'id', label:'cnName', value:'cnName'}"
                                                      @corpChange="corpChange($event,'corpCnName')"
                                                      @remoteMethod="corpBcorpsListfun"
                                                      @corpFocus="corpBcorpsListfun" >
                                        </search-query>
                                    </el-col>
                                    <el-col :span="12" :offset="1">
                                        <el-input style="width: 100%;" v-model="form.corpEnName"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入" >
                                        </el-input>
                                    </el-col>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="业务类型" prop="businessTypes" >
                                    <search-query :datalist="businessTypesData"
                                                  :selectValue="form.businessTypes"
                                                  :clearable="true"
                                                  :disabled="editSave"
                                                  :buttonIf="false"
                                                  :multiple="true"
                                                  @corpChange="corpChange($event,'businessTypes')">
                                    </search-query>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="查询金额" prop="queryAmount">
                                    <el-input style="width: 100%;" v-model="form.queryAmount"
                                              size="small" autocomplete="off"
                                              :disabled="editSave"
                                              clearable placeholder="请输入查询金额" >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="4">
                                <el-form-item label="币别" prop="curCode">
                                    <search-query :datalist="curCodeData"
                                                  :selectValue="form.curCode"
                                                  :clearable="true"
                                                  :disabled="editSave"
                                                  :buttonIf="false"
                                                  :filterable="true"
                                                  :remote="true"
                                                  :forParameter="{ key:'id', label:'code', value:'code'}"
                                                  @corpChange="corpChange($event,'curCode')"
                                                  @remoteMethod="getRateListfun"
                                                  @corpFocus="getRateListfun" >
                                    </search-query>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <expand :showBtn="true" :showSpan="true">
                            <el-row>
                                <el-col :span="5">
                                    <el-form-item label="JOB NO" prop="businessNo">
                                        <el-input style="width: 100%;" v-model="form.businessNo"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入JOB NO" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="ACCT NO" prop="accountNo">
                                        <el-input style="width: 100%;" v-model="form.accountNo"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入ACCT NO" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="MBL NO" prop="mblno">
                                        <el-input style="width: 100%;" v-model="form.mblno"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入MBL NO" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="HBL NO" prop="hblno">
                                        <el-input style="width: 100%;" v-model="form.hblno"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入HBL NO" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label="CHK NO" prop="checkNo">
                                        <el-input style="width: 100%;" v-model="form.checkNo"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入CHK NO" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="财务日期" prop="accountDate">
                                        <el-date-picker
                                            v-model="form.accountDate"
                                            type="datetimerange"
                                            range-separator="至"
                                            start-placeholder="开始日期"
                                            end-placeholder="结束日期"
                                            style="width: 100%;"
                                            size="small"
                                            :disabled="editSave"
                                            format="yyyy-MM-dd"
                                            value-format="yyyy-MM-dd"
                                            placeholder="选择财务日期">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="签收日期" prop="signforDateList">
                                        <el-date-picker
                                            v-model="form.signforDateList"
                                            type="datetimerange"
                                            range-separator="至"
                                            start-placeholder="开始日期"
                                            end-placeholder="结束日期"
                                            style="width: 100%;"
                                            size="small"
                                            :disabled="editSave"
                                            format="yyyy-MM-dd"
                                            value-format="yyyy-MM-dd"
                                            placeholder="选择签收日期">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="船 名" prop="vesselCnName" >
                                        <el-input style="width: 100%;" v-model="form.vesselCnName"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请选择船名" ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="5">
                                    <el-form-item label="航 次" prop="voyageNo" >
                                        <el-input style="width: 100%;" v-model="form.voyageNo"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请选择航次" ></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="4">
                                    <el-form-item label="预收帐款" prop="receivableAdvance" >
                                        <el-input style="width: 100%;" v-model="form.receivableAdvance"
                                                  size="small" autocomplete="off"
                                                  :disabled="editSave"
                                                  clearable placeholder="请输入预收帐款" ></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </expand>

                        <el-row>
                            <el-col span="24">
                                <div style="text-align: right">
                                    <el-button  size="small" type="" style="margin-right: 8px"
                                                :loading="saveLoading" @click="ResetFilter">重置条件
                                    </el-button>
                                    <el-button  size="small" type="primary"  style="margin-right: 8px"
                                                :loading="saveLoading" @click="finstlbillslistAccBillV1fun" >检 索
                                    </el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </el-row>
                </el-form>
            </el-card>

            <el-card style="margin-top: 10px">
                <el-row>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">¥</div>-->
                            <!--    <div>RMB</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>税后应收RMB:</span>
                                    <span class="weightnum">¥{{form.amountDrNet || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>税后应付RMB:</span>
                                    <span class="weightnum">¥{{form.amountCrNet || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">$</div>-->
                            <!--    <div>USD</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>税后应收USD:</span>
                                    <span class="weightnum">${{form.amountDrUsdNet || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>税后应付USD:</span>
                                    <span class="weightnum">${{form.amountCrUsdNet || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">¥</div>-->
                            <!--    <div>税后RMB</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>税后应收合计:</span>
                                    <span class="weightnum">¥{{form.amountDrLocNet || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>税后应付合计:</span>
                                    <span class="weightnum">¥{{form.amountCrLocNet || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">$</div>-->
                            <!--    <div>税后USD</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>应收RMB:</span>
                                    <span class="weightnum">${{form.amountDr || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>应付RMB:</span>
                                    <span class="weightnum">${{form.amountCr || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">$</div>-->
                            <!--    <div>税后USD</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>应收USD:</span>
                                    <span class="weightnum">${{form.amountDrUsd || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>应付USD:</span>
                                    <span class="weightnum">${{form.amountCrUsd || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">$</div>-->
                            <!--    <div>税后USD</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>应付合计:</span>
                                    <span class="weightnum">${{form.amountDrLoc || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>应收合计:</span>
                                    <span class="weightnum">${{form.amountCrLoc || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="3">
                        <div class="bottomFlex" style="justify-content: space-around">
                            <!--<div style="text-align: center">-->
                            <!--    <div class="weightfont">$</div>-->
                            <!--    <div>税后USD</div>-->
                            <!--</div>-->
                            <div>
                                <div style="color: #81B337">
                                    <span>销项税合计:</span>
                                    <span class="weightnum">${{form.amountDrLoc || 0}}元</span>
                                </div>
                                <div style="color: #6BBCD1">
                                    <span>进项税合计:</span>
                                    <span class="weightnum">${{form.amountCrLoc || 0}}元</span>
                                </div>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </el-card>

            <el-card style="margin-top: 10px">
                <div style="margin-bottom: 10px">
                    <el-button  size="small" type="info" style="margin-right: 8px" :disabled="editSave"
                                :loading="saveLoading" @click="SelectedRows">确认选定行
                    </el-button>
                </div>

                <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
                    <el-tab-pane label="核销明细" name="first">
                        <finstlbillsitems :tableData="tableData"
                                          :handleSelectionData="handleSelectionData"
                                          :whetherAuditing="whetherAuditing"
                                          @handleSelectionChange="handleSelectionChange">
                        </finstlbillsitems>
                    </el-tab-pane>
                    <el-tab-pane label="凭证明细" name="second">凭证明细</el-tab-pane>
                </el-tabs>
            </el-card>
        </div>

    </div>
</template>

<script>
    import SearchQuery from "@/components/iosbasic-data/searchquery.vue";
    import {getRateList} from "@/api/iosBasicData/rateManagement";
    import {getBcorpslistByType} from "@/api/iosBasicData/bcorps";
    import {
        approveDetail,
        finstlbillsConfirmSettlement,
        finstlbillsConfirmSignFor,
        finstlbillsDetail,
        finstlbillslistAccBillV1,
        finstlbillsRevokeSettlement,
        finstlbillsRevokeSignFor,
        finstlbillsSubmit
    } from '@/api/iosBasicData/finstlbills'
    import expand from "@/components/basic-container/expand.vue";
    import finstlbillsitems from "@/views/iosBasicData/PaymentSettlement/assembly/finstlbillsitems.vue";
    import {isProcurement} from "@/api/basicData/configuration";

    export default {
        components: {SearchQuery,expand,finstlbillsitems},
        props:{
            // 编辑还是保存
            editSave:{
                type:Boolean,
                default:true
            }
        },
        data(){
            return {
                whetherAuditing:'', // 判断检索
                activeName:'first', // tabs 切换数据
                tableData:[],
                pageLoading:false, // 全屏加载动画
                saveLoading:false, // 按钮动画
                // 绑定的数据
                form:{
                    auditStatus:'3'
                },
                handleSelectionData:[], // 表格选择的数据
                corpData:[], // 结算单位 数据
                curCodeData:[],// 币别
                srcforParameter:{},
                // 业务类型
                businessTypesData:[
                    {
                        label:'海运出口',
                        value:'SE'
                    },{
                        label:'海运进口',
                        value:'SI'
                    }
                ],
            }
        },
        watch:{

            // // 监听业务类型 如果不是分单 可以编辑分单号
            // form:{
            //     // 执行方法
            //     handler(oldValue,newValue) {
            //         // 只要分单不能编辑
            //         console.log(this.form,619)
            //         if (!newValue || JSON.stringify(newValue) == '{}') {
            //             return
            //         }
            //         delete this.form.id
            //         this.tableData = []
            //         this.form.finStlBillsItemsList = []
            //         console.log(newValue)
            //
            //
            //     },
            //     deep: true, // 深度监听
            //     immediate: true  // 第一次改变就执行
            // },
        },
        created() {
            this.isProcurementfun()
        },
        methods:{
            // 下拉回调
            corpChange(value,name){
                // 结算单位
                if (name == 'corpCnName') {
                    if (!value) {
                        this.$set(this.form,'corpId','')
                        this.$set(this.form,'corpCnName','')
                        this.$set(this.form,'corpEnName','')
                        this.$set(this.form,'corpArgreementNo','')
                    }
                    for(let item of this.corpData) {
                        if (item.cnName == value) {
                            this.$set(this.form,'corpId',item.id)
                            this.$set(this.form,'corpCnName',item.cnName)
                            this.$set(this.form,'corpEnName',item.enName)
                            this.$set(this.form,'corpArgreementNo',item.enName)
                        }
                    }
                }
                else {
                    this.$set(this.form,name,value)
                }
            },
            // 编辑
            editHandle(){
                this.editSave = false
            },
            // 保存
            editCustomer(){
                // 对账单位
                if (!this.form.corpId) {
                    this.$message.warning('请选择结算单位');
                    return
                }
                // // 业务类型
                if (!this.form.businessTypes) {
                    this.$message.warning('请选择业务类型');
                    return
                }
                if (!this.form.id) {
                    // 是否选择从表数据
                    if (this.handleSelectionData.length == 0) {
                        this.$message.warning('请选择结算数据');
                        return;
                    }
                }
                this.saveLoading = true // 加载动画
                this.form.billNoFormat = 'HYFF'
                this.form.businessTypeCode = 'HYFF'
                this.form.businessType = 'STL' // 结算单
                this.form.dc = 'C' // 付
                this.form.businessTypes = this.form.businessTypes.join(',') // 业务类型

                if (this.whetherAuditing == '0') {
                    for (let item of this.handleSelectionData) {
                        if (!item.currentStlCurCode) {
                            this.$message.warning('请选择本次结算币种');
                            return;
                        }
                        if (!item.currentStlAmount) {
                            this.$message.warning('请选择本次结算金额');
                            return;
                        }
                    }
                    if (!this.form.id) {
                        this.form.finStlBillsItemsList = this.handleSelectionData.map((item,index)=>{
                            item.lineNo = index
                            item.pType = item.businessType
                            item.accBillId = item.id
                            item.accBillNo = item.billNo
                            item.accDate = item.billDate
                            item.dc = item.accountDc // 收付
                            if (item.currentStlCurCode == 'CNY') {
                                item.currentStlAmount = item.currentStlAmountRMB
                            }else {
                                item.currentStlAmount = item.currentStlAmountUSD
                            }
                            delete item.businessType
                            if (!this.form.id) {
                                delete item.id
                            }
                            delete item.billNo
                            delete item.billDate
                            delete item.accountDc
                            return item
                        })
                    }
                }else {
                    this.form.finStlBillsItemsList = this.handleSelectionData
                }
                finstlbillsSubmit(this.form).then(res=>{
                    this.saveLoading = false
                    this.$message.success('操作成功');
                    this.finstlbillsDetailfun(res.data.data.id)
                })
            },
            // 申请单号
            approveDetailfun(billNo){
                approveDetail({billNo}).then(res=>{
                    this.tableData = res.data.data.finStlBillsItemsList.map(item=>{
                        item.id = ''
                        item.pid = ''
                        item.stlTtlAmountNet = Number(item.stlTtlAmount) - (Number(item.stlTtlAmount) * (Number(item.taxRate) + Number(item.surchargeRate)))
                        if(item.curCode == 'CNY') {
                            this.$set(item,'currentInvoiceAmountRMB',item.currentInvoiceAmount)
                            this.$set(item,'amountRMB',item.amount)
                            this.$set(item,'amountNetRMB',item.amountNet)
                            this.$set(item,'stlTtlAmountRMB',item.stlTtlAmount)
                            this.$set(item,'stlTtlAmountNetRMB',item.stlTtlAmountNet)
                            this.$set(item,'currentStlAmountRMB',item.unsettledAmount) // 未结算金额
                            this.$set(item,'currentStlAmountNetRMB',item.currentStlAmountNet)
                        }else {
                            this.$set(item,'currentInvoiceAmountUSD',item.currentInvoiceAmount)
                            this.$set(item,'amountUSD',item.amount)
                            this.$set(item,'amountNetUSD',item.amountNet)
                            this.$set(item,'stlTtlAmountNetUSD',item.stlTtlAmountNet)
                            this.$set(item,'stlTtlAmountUSD',item.stlTtlAmount)
                            this.$set(item,'currentStlAmountUSD',item.unsettledAmount) // 未结算金额
                            this.$set(item,'currentStlAmountNetUSD',item.currentStlAmountNet)
                        }
                        return item
                    })
                })
            },
            // 判断检索
            isProcurementfun(){
                isProcurement({"param":"whether.auditing"}).then(res=>{
                    // res.data.data === '1'
                    this.whetherAuditing = res.data.data
                })
            },
            // 详情接口
            finstlbillsDetailfun(id){
                this.pageLoading = true
                finstlbillsDetail(id).then(res=>{
                    this.form = res.data.data
                    this.form.businessTypes = this.form.businessTypes.split(',') // 业务类型转换成数组显示
                    this.tableData = this.form.finStlBillsItemsList.map(item=>{
                        item.stlTtlAmountNet = Number(item.stlTtlAmount) - (Number(item.stlTtlAmount) * (Number(item.taxRate) + Number(item.surchargeRate)))
                        item.currentStlAmountNet = Number(item.unsettledAmount) - (Number(item.unsettledAmount) * (Number(item.taxRate) + Number(item.surchargeRate)))
                        if(item.curCode == 'CNY') {
                            this.$set(item,'currentInvoiceAmountRMB',item.currentInvoiceAmount)
                            this.$set(item,'amountRMB',item.amount)
                            this.$set(item,'amountNetRMB',item.amountNet)
                            this.$set(item,'stlTtlAmountRMB',item.stlTtlAmount)
                            this.$set(item,'stlTtlAmountNetRMB',item.stlTtlAmountNet)

                            this.$set(item,'currentStlAmountRMB',item.unsettledAmount) // 未结算金额
                            this.$set(item,'currentStlAmountNetRMB',item.currentStlAmountNet)
                        }else {
                            this.$set(item,'currentInvoiceAmountUSD',item.currentInvoiceAmount)
                            this.$set(item,'amountUSD',item.amount)
                            this.$set(item,'amountNetUSD',item.amountNet)
                            this.$set(item,'stlTtlAmountNetUSD',item.stlTtlAmountNet)
                            this.$set(item,'stlTtlAmountUSD',item.stlTtlAmount)

                            this.$set(item,'currentStlAmountUSD',item.unsettledAmount) // 未结算金额
                            this.$set(item,'currentStlAmountNetUSD',item.currentStlAmountNet)
                        }
                        return item
                    })
                    this.pageLoading = false
                }).catch(err=>{
                    this.pageLoading = false
                })
            },
            // 重置条件
            ResetFilter(){
                this.form = {}
            },
            // 检索接口
            finstlbillslistAccBillV1fun(){
                // 对账单位
                if (!this.form.corpId) {
                    this.$message.warning('请选择对账单位');
                    return
                }
                if (this.whetherAuditing == '1') {
                    if (!this.form.requestNo) {
                        this.$message.warning('请输入申请单号');
                        return;
                    }
                }
                // 业务类型
                if (!this.form.businessTypes) {
                    this.$message.warning('请选择业务类型');
                    return
                }
                delete this.form.id
                // let obj = JSON.parse(JSON.stringify(this.form))
                let obj = {}
                obj.type = '2'
                obj.dc = 'C' // 付
                obj.corpCnName = this.form.corpId // 结算单位
                obj.curCode = this.form.curCode // 币别
                obj.accBillNo = this.form.accountNo // 账单编号  ACCT NO
                obj.billNo = this.form.businessNo // 单据编号  JOB NO
                obj.checkBillNo = this.form.checkNo // CHK NO
                obj.mblno = this.form.mblno // MB/L NO
                obj.hblno = this.form.hblno // HB/L NO
                obj.queryAmount = this.form.queryAmount // 查询金额
                obj.businessType = this.form.businessTypes?this.form.businessTypes.join(','):'' // 业务类型
                obj.vesselCnName = this.form.vesselCnName // 中文船名
                obj.receivableAdvance = this.form.receivableAdvance // 预收帐款
                obj.voyageNo = this.form.voyageNo // 航次
                obj.signforDateList = this.form.signforDateList // 签收日期
                obj.billNo = this.form.requestNo // 申请单号

                // 审核期间
                if (this.form.approvedDate) {
                    obj.approveTimeList = this.form.approvedDate
                }
                // 财务期间
                if (this.form.accountDate) {
                    obj.billDateList = this.form.accountDate
                }

                if (this.whetherAuditing == '1') {
                    this.approveDetailfun(obj.billNo)
                }else {
                    finstlbillslistAccBillV1(obj).then(res=>{
                        console.log(res.data.data,709)
                        this.tableData = res.data.data.map(item=>{
                            item.stlTtlAmountNet = Number(item.stlTtlAmount) - (Number(item.stlTtlAmount) * (Number(item.taxRate) + Number(item.surchargeRate)))
                            if(item.curCode == 'CNY') {
                                this.$set(item,'currentInvoiceAmountRMB',item.currentInvoiceAmount)
                                this.$set(item,'amountRMB',item.amount)
                                this.$set(item,'amountNetRMB',item.amountNet)
                                this.$set(item,'stlTtlAmountRMB',item.stlTtlAmount)
                                this.$set(item,'stlTtlAmountNetRMB',item.stlTtlAmountNet)
                                this.$set(item,'currentStlAmountRMB',item.unsettledAmount) // 未结算金额
                                this.$set(item,'currentStlAmountNetRMB',item.currentStlAmountNet)
                            }else {
                                this.$set(item,'currentInvoiceAmountUSD',item.currentInvoiceAmount)
                                this.$set(item,'amountUSD',item.amount)
                                this.$set(item,'amountNetUSD',item.amountNet)
                                this.$set(item,'stlTtlAmountNetUSD',item.stlTtlAmountNet)
                                this.$set(item,'stlTtlAmountUSD',item.stlTtlAmount)
                                this.$set(item,'currentStlAmountUSD',item.unsettledAmount) // 未结算金额
                                this.$set(item,'currentStlAmountNetUSD',item.currentStlAmountNet)
                            }
                            return item
                        })
                    })
                }
            },
            // 结算确认
            finstlbillsConfirmSettlementfun(){
                this.$confirm("确定进行结算操作?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(()=>{
                    this.pageLoading = true
                    this.form.businessTypes = this.form.businessTypes.join(',') // 业务类型
                    finstlbillsConfirmSettlement(this.form).then(res=>{
                        this.pageLoading = false
                        this.$message.success('操作成功');
                        this.finstlbillsDetailfun(res.data.data.id)
                    }).catch(err=>{
                        this.pageLoading = false
                    })
                })
            },
            // 结算撤销
            finstlbillsRevokeSettlementfun(){
                this.$confirm("确定进行撤销结算操作?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(()=>{
                    this.pageLoading = true
                    this.form.businessTypes = this.form.businessTypes.join(',') // 业务类型
                    finstlbillsRevokeSettlement(this.form).then(res=>{
                        this.pageLoading = false
                        this.$message.success('操作成功');
                        this.finstlbillsDetailfun(res.data.data.id)
                    })
                }).catch(err=>{
                    this.pageLoading = false
                })
            },
            // 确认选定行
            SelectedRows(){
                this.editCustomer()
            },
            // 下面表格多选
            handleSelectionChange(arr){
                this.handleSelectionData = arr
            },
            //返回列表
            backToList() {
                this.$emit('goBack')
            },
            // 请求的接口
            // 获取币别数据
            getRateListfun(cnName){
                getRateList({current:1,size:10,cnName}).then(res=>{
                    this.curCodeData = res.data.data.records
                })
            },
            // 获取结算单位数据
            corpBcorpsListfun(cnName){
                getBcorpslistByType(1,10,{cnName}).then(res=>{
                    this.corpData = res.data.data.records
                })
            },

        }
    }
</script>

<style scoped>
::v-deep.el-form-item {
    margin-bottom: 0;
}
.bottomFlex {
    display: flex;
    align-items: center;
}
.weightfont {
    font-size: 20px;
    font-weight: bold;
}
.weightnum {
    font-size: 15px;
    font-weight: 500;
}
</style>
