<style>
    .page_CompanyAccDetail .query-box li label{display: inline-block;min-width: 80px;text-align: right;font-style: normal;margin: 0 20px 0 0;}
    ._shoufu_date input.el-input__inner{padding: 0px 0 0 27px;}
    .page_CompanyAccDetail .el-date-editor .el-range-separator{width: 9% !important;}
    .page_CompanyAccDetail .el-date-editor--daterange.el-input__inner{width: auto !important;}
    ._bg__{
        border-radius: 4px;
        cursor: pointer;
        text-decoration: underline;
    }
    ._bg__ .CAcc_bg_red:hover{
        color: rgb(230, 97, 97);
    }
    ._bg__ .CAcc_bg_green:hover{
        color:rgb(66, 182, 132);
    }
    ._bg__ .CAcc_bg_bule:hover{
        color:rgb(10, 99, 233);
    }
    .page_CompanyAccDetail .CAcc_bg_red{color: #E95252;}
    .page_CompanyAccDetail .CAcc_bg_green{color: #2BB87C}
    .page_CompanyAccDetail .CAcc_bg_bule{color: blue}
    ._addChuNa_tit{color: gray;margin-bottom: 10px;}
    ._addChuNa_tit span{ color:#333333}
    .page_CompanyAccDetail ._addUpload_box{
      display: block;
      margin-top: 20px;
      width:590px;
    }
    .page_CompanyAccDetail ._addUpload_box>div{
      float: left;
      width: 138px;
      height: 92px;
      border: 1px dashed rgba(210,210,210,1);
      border-radius: 2px;
      cursor: pointer;
      padding: 5px;
      margin:0 10px 10px 0;
      position: relative;
    }
    .page_CompanyAccDetail .el-upload-dragger {
        width: 126px!important;
        height: 80px!important;
    }
    .page_CompanyAccDetail ._addUpload_box .icon-guanbi1 {
        font-size: 12px;
        color: white;
        display: inline-block;
        margin-left: 15px;
        position: absolute;
        right: -6px;
        top: -9px;
        background-color: #f56c6c;
        border-radius: 50%;
        height: 20px;
        width: 20px;
        text-align: center;
        line-height: 20px;
    }
    .page_CompanyAccDetail ._addUpload_box .icon-guanbi1:hover {
        font-size: 12px;
        color: #c94052;
    }

    .page_CompanyAccDetail .totalStat ul{
      list-style-type: none;
    padding: 0;
    margin: 0;
    display: flex; /* 设定为flex容器 */
    }
    .page_CompanyAccDetail .totalStat li{
      display: inline; /* 将列表项显示为行内元素 */
    margin-right: 10px; /* 添加右边距，可调整间距 */
    }

</style>
<template>
    <div  class='flexOne page_CompanyAccDetail'>
        <div class='query-box' @keyup.enter="getList()">
            <el-form class="_info_box clearfix"  label-width="110px">
                <el-row style="padding: 10px 0 0 0;">
                  <el-col :span="4">
                      <el-form-item :label="$t('objFill.v101.FinancialModule.yuangongs')">
                          <el-select  filterable  v-model='msg.RB_Branch_Id'  class="">
                              <el-option v-for='item in CompanyList'
                                  :label='item.BName'
                                  :value='item.Id'
                                  :key='item.Id'>
                              </el-option>
                          </el-select>
                      </el-form-item>
                  </el-col>
                  <el-col :span="4">
                      <el-form-item :label="$t('objFill.daishou')+'/'+$t('objFill.v101.FinancialModule.fugongs')">
                          <el-select  filterable  v-model='msg.HelpBranchId' class="">
                              <el-option v-for='item in CompanyList'
                                  :label='item.BName'
                                  :value='item.Id'
                                  :key='item.Id'>
                              </el-option>
                          </el-select>
                      </el-form-item>
                  </el-col>
                  <el-col :span="3">
              <el-form-item :label="$t('fnc.bzleixing')">
                <el-select filterable v-model='msg.CurrencyId'>
                  <el-option key="0" value="0" :label="$t('pub.unlimitedSel')"></el-option>
                  <el-option v-for="item in currencyTypeList" :key="item.ID" :value="item.ID" :label="item.Name">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="3">
            <el-form-item :label="$t('objFill.settlementstatus')">
              <el-select v-model='msg.IsSelectAduiting'>
                <el-option v-for='item in SelectAduitingList' :label='item.Name' :value='item.Id' :key='item.Id'>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
                    <el-col :span="8" :gutter="35">
                        <el-form-item :label="$t('fnc.a_hkfkriqi')">
                                <StartDateLimit :clearable="false" :dateTime="productionDate" @change="(startDate,endDate)=>{msg.sTradeDate=startDate,msg.eTradeDate=endDate}"></StartDateLimit>
                            </el-form-item>
                    </el-col>
                  <el-col :span="10">
                    <span style="font-size: 12px;">*{{$t('objFill.v101.FinancialModule.zhuyuewzs')}}</span>
                  </el-col>
                </el-row>
            </el-form>
			<ul>
				<li>
          <input type="button" class="hollowFixedBtn" :value="$t('pub.searchBtn')" @click="getList()"/>
          <input type="button" class="normalBtn" :value="$t('visa.v_daochu')"  @click="Export"/>
          <button class="normalBtn" @click="GenerateDocuments()">{{$t('objFill.v101.FinancialModule.shengcjsdj')}}</button>
          </li>
			</ul>
		</div>
    <div class="totalStat">
      {{$t('ground.jinezongji')}}
      <ul>
        <li v-for="(item,index) in CurrencyStat">{{item.CurrencyName}}：{{moneyFormat(item.Money)}}</li>
        </ul>
      </div>

      <div style="display: flex;flex-wrap: nowrap; padding: 10px;">
        <div style="display: flex;flex-wrap: wrap;">
          <span>{{$t('objFill.selecteddata')}}：</span>
          <template v-if="DataList.filter(citem => citem.check).length>0">
            <el-tag v-if="x.check" size="mini" closable style="margin-right: 5px;margin-bottom: 5px;"
              v-for="(x,index) in DataList" :key="x.FrID" @close="handleClose(x)"
              :type="x.ImportType == 1 ||x.ImportType == 4 || x.ImportType == 5||x.ImportType == 8?'success':'danger'">
                {{x.FrID}}/{{x.CostTypeIdStr}}:{{x.WBMoney}}{{x.CurrencyName}}
            </el-tag>
          </template>
          <template v-else>
            {{$t('fnc.no')}}
          </template>
        </div>
        <div style="margin-left: 20px;flex-shrink: 0;">
          {{$t('objFill.yixuanzheje')}}：
          <ul>
            <li v-for="sitem in getMoney()">{{moneyFormat(sitem.Money)}}/{{sitem.CurrencyName}}</li>
          </ul>
          <!--<span v-for="sitem in getMoney()">{{sitem.Money}}/{{sitem.CurrencyName}} &nbsp;&nbsp;</span>-->
        </div>
      </div>

        <div class="cm_content">
            <table class="po_content singeRowTable" style="border:1px solid #E6E6E6;" cellspacing="0" cellpadding="0" v-loading="loadingTable">
                <tr>
                    <th width="60"><input type="checkbox" v-model="isCheckAll" @change="checkAllOrder()"/></th>
                    <th>{{$t('fnc.jiaoyiriqi')}}</th>
                    <th>{{$t('fnc.djleixing')}}</th>
                    <th>{{$t('fnc.danhao')}}</th>
                    <th width="100">{{$t('objFill.v101.FinancialModule.guanljsd')}}</th>
                    <th>{{$t('fnc.feiyongleixing')}}</th>
                    <th width="340">{{$t('objFill.v101.FinancialModule.shoufkdx')}}</th>
                    <th>{{$t('hotel.hotel_Currency')}}</th>
                    <th>{{$t('objFill.v101.FinancialModule.fangxiang')}}</th>
                    <th>{{$t('fnc.bwbjine')}}</th>
                    <th>{{$t('objFill.daifu')}}</th>
                    <th>{{$t('objFill.daishou')}}</th>
                </tr>
                <tr>
                    <td :colspan="10">{{$t('fnc.a_heji')}}（{{$t('hotel.hotel_totalRoom')}}{{ DataList.length }} {{$t('hotel.hotel_item')}}）</td>
                    <td>{{ OutMoney == 0 ? '-' : moneyFormat(OutMoney) }}</td>
                    <td>{{ InMoney == 0 ? '-' : moneyFormat(InMoney) }}</td>
                </tr>
                <tr v-for="(item,index) in DataList">
                    <td>
                      <input type="checkbox" :disabled="item.disabled" v-model="item.check"
                      @change="getNewCheck()">
                    </td>
                    <td>{{item.TradeDate}}</td>
                    <td>{{(item.FType==1?$t('restaurant.res_income'):item.FType==2?$t('restaurant.res_outcome'):item.FType==4?$t('objFill.tiaobo'):'-')}}</td>
                    <td>
                      <span class="cursorpointer" :class="item.FType === 1 ? 'CAcc_bg_green' :item.FType === 2 ? 'CAcc_bg_red':'CAcc_bg_bule'" @click="goUrlNew(item.FType,item.FrID)">{{item.FrID}}</span>
                    </td>
                    <td>{{item.CallBackReFrId>0?item.CallBackReFrId:item.IsSpecial==1?'结算单':''}}</td>
                    <td>{{item.CostTypeIdStr}}</td>
                    <td>{{item.RemitterName}}</td>
                    <td>{{item.CurrencyName}}</td>
                    <td>{{item.ImportType<=4?$t('objFill.v101.FinancialModule.zheng'):$t('objFill.v101.FinancialModule.fan')}}</td>
                    <td>{{ moneyFormat(item.Money) }}</td>
                    <td>{{ item.ImportType == 2 ||item.ImportType == 3 || item.ImportType == 6||item.ImportType == 7 ? moneyFormat(item.WBMoney) : '' }}</td>
                    <td>{{ item.ImportType == 1 ||item.ImportType == 4 || item.ImportType == 5||item.ImportType == 8 ? moneyFormat(item.WBMoney) : '' }}</td>
                </tr>
                <!-- <tr>
                      <td :colspan="10">{{$t('fnc.a_heji')}}（{{$t('hotel.hotel_totalRoom')}}{{ DataList.length }} {{$t('hotel.hotel_item')}}）</td>
                      <td>{{ OutMoney == 0 ? '-' : moneyFormat(OutMoney) }}</td>
                      <td>{{ InMoney == 0 ? '-' : moneyFormat(InMoney) }}</td>
                 </tr>-->
                 <tr></tr>
            </table>
        </div>

    </div>
</template>
<script>
import moment from "moment"
import StartDateLimit from '../../public/StartDateLimit.vue';
export default {
    components: {StartDateLimit},
    data(){
        return{
            msg:{
              CurrencyId:3,
              RB_Branch_Id:0,
              HelpBranchId:1218,
              sTradeDate:'',
              eTradeDate:'',
              IsSelectAduiting:'2'
            },
            Type:1,
            AccountId:'',
            DataList:[],
            CurrencyStat:[],
            StartMoney:0,
            AccountTypeList:[],
            AccList:[],
            GetAccountType:[],
            accountList:[],
            productionDate:[],
            SelectAduitingList: [{
                Name: this.$t('pub.unlimitedSel'),
                Id: '0'
              },
              {
                Name: this.$t('objFill.havealreadysettled'),
                Id: '1'
              },
              {
                Name: this.$t('objFill.unsettled'),
                Id: '2'
              },
            ],
            CompanyList:[
              {Id:0,BName:this.$t('objFill.chengduo')},
              {Id:1218,BName:this.$t('objFill.v101.FinancialModule.riben')},
              {Id:1220,BName:this.$t('objFill.v101.FinancialModule.taiwan')},
              {Id:1248,BName:this.$t('objFill.v101.FinancialModule.chehang')},
              {Id:1252,BName:this.$t('objFill.v101.FinancialModule.yinni')},
            ],
            currencyTypeList: [],
            BranchAccountList: [],
            loadingTable:false,
            loading:false,
            date:'',
            accType:'',
            tradeWay:1,
            allMoney:0,
            OutMoney:0,
            InMoney:0,
            InMoneyB: 0,
            OutMoneyB: 0,
            count:0,
            allBPrice:0,
            allWPrice:0,
            userInfo:{},
            //是否全选
            isCheckAll:false,
        }
    },
    created(){
      this.GetSupperOrderEditAuth()
      this.userInfo = this.getLocalStorage();
    this.financeinfo_post_GetList();
  },
  methods:{
    getNewCheck(){
      this.$forceUpdate()
    },
    GetSupperOrderEditAuth() {
        var actionCode = this.$AuthCode.isQueryHistoryData;
        this.CheckUserAuth(actionCode, res => {
          if (res.data.resultCode == 1 && res.data.data == 1) {

          }else{
            let StartDate = this.getBeforeDate(186, new Date().Format("yyyy-MM-dd"))
            let EndDate = this.getBeforeDate(-1, new Date().Format("yyyy-MM-dd"))
            this.productionDate = [StartDate, EndDate]
            this.msg.sTradeDate = this.productionDate[0];
            this.msg.eTradeDate = this.productionDate[1];
          }
        });

     },
        Export(){
            let msg=this.msg;
            msg.EmployeeId = this.userInfo.EmployeeId;
            var fileName = this.$t('objFill.v101.FinancialModule.daisdfmx')+'.xls';
            this.GetLocalFile("Financial_post_GetNewCollectingOrPayToExcel", msg, fileName);
        },
        goUrlNew(FType,FrId){
              if(FType ==4){
                  this.$router.push({ name: "CapitalAllocationDetail",query:{"id":FrId,blank:'y'} })
              }else{
                  this.$router.push({ name: "FinancialDocumentsDetail",query:{"id":FrId,blank:'y'} })
              }
          },
        goUrl(path,id){
            this.$router.push({ name: path,query:{"id":id,blank:'y'} })
        },
        timeAdd(){  // 日期格式
            if(!this.productionDate){
                this.msg.sTradeDate = '';
                this.msg.eTradeDate = '';
                return
            }
            this.msg.sTradeDate = this.productionDate[0];
            this.msg.eTradeDate = this.productionDate[1];
        },
        getList(){ //获取列
          this.loadingTable = true;
            this.apipost('Financial_post_GetNewCollectingOrPayPageList',this.msg,res=>{
                 if(res.data.resultCode==1){
                  this.StartMoney = res.data.data.InitialBalance;
                  this.allMoney = res.data.data.EndingBalance;
                            this.InMoney = res.data.data.CollectionTotal;
                            this.OutMoney = res.data.data.PayTotal;
                            this.DataList = res.data.data.List;
                            this.CurrencyStat = res.data.data.CurrencyStat;

                            this.DataList.forEach((x)=>{  //  循环改变check disabled 状态
                              if(x.CallBackReFrId>0 || x.IsSpecial==1){
                                x.disabled=true
                              }
                            });

                            this.loadingTable = false;
                }else{
                  this.loadingTable = true;
                    this.Error(res.data.message)
                }
            },err=>{})
        },
        //点击全选
        checkAllOrder(){
          if(this.isCheckAll){
            this.DataList.forEach(x=>{
              if(!x.disabled){
                x.check=true;
              }
            })
          }else{
            this.DataList.forEach(x=>{
              if(!x.disabled){
                x.check=false;
              }
            })
          }
        },
        handleClose(item){
          item.check=false;
        },
        getMoney(){
          let CurrencyST=[];
          if(this.DataList.filter(citem => citem.check).length>0){
          let currArr = [];
          this.DataList.filter(citem => citem.check).forEach(x=>{
              if(!currArr.find(z=>z==x.CurrencyName)){
                currArr.push(x.CurrencyName);
              }
            });

            currArr.forEach(x=>{
              let cmoney=0;
              this.DataList.filter(citem => citem.check&& citem.CurrencyName==x).forEach(qitem=>{
                if(qitem.ImportType == 2 ||qitem.ImportType == 3 || qitem.ImportType == 6||qitem.ImportType == 7){
                  cmoney+=qitem.WBMoney;
                }else{
                  cmoney-=qitem.WBMoney;
                }
              })
              CurrencyST.push({'CurrencyName':x,'Money':cmoney});
            });
          }
          return CurrencyST;
        },
        financeinfo_post_GetList() { // 币种类型
          this.apipost('financeinfo_post_GetList', {
            Name: ''
          }, res => {
            if (res.data.resultCode == 1) {
              this.currencyTypeList = res.data.data;
            } else {

            }
          }, err => {})
        },
        addCheckbox(item){
          
        },
        GenerateDocuments() {
          if(this.DataList.filter(citem => citem.check).length == 0) {
            this.Error(this.$t('objFill.pleaseselectdocuments'));
            return;
          }

          // if(!(this.msg.RB_Branch_Id==1252&&(this.msg.HelpBranchId==0||this.msg.HelpBranchId==1218))){
          //   this.Error('暂不支持生成结算单，请联系管理员');
          //   return;
          // }
          let TemplateId2=35;let FBranchId=-1;

          if(this.msg.RB_Branch_Id==0&&this.msg.HelpBranchId==1218){TemplateId2=35;FBranchId=1218;}
          if(this.msg.RB_Branch_Id==1218&&this.msg.HelpBranchId==0){TemplateId2=35;FBranchId=1218;}

          if(this.msg.RB_Branch_Id==1252&&this.msg.HelpBranchId==0){TemplateId2=35;FBranchId=1252;}
          if(this.msg.RB_Branch_Id==1252&&this.msg.HelpBranchId==1218){TemplateId2=292;}
          if(this.msg.RB_Branch_Id==0&&this.msg.HelpBranchId==1252){TemplateId2=35;FBranchId=1252;}
          if(this.msg.RB_Branch_Id==1218&&this.msg.HelpBranchId==1252){TemplateId2=292;}

          if(this.msg.RB_Branch_Id==1248||this.msg.HelpBranchId==1248){TemplateId2=289;FBranchId=1248;}
          if(this.msg.RB_Branch_Id==1220||this.msg.HelpBranchId==1220){TemplateId2=285;FBranchId=1220;}

          let ids = this.DataList.filter(citem => citem.check).map(x=>{ return x.FrID})
          this.$router.push({
            name: 'addCapitalAllocation',
              query: {
                'settlementFrIds': ids.join(','),
                'IsAirTicketSelect': TemplateId2,
                'settlementBranchId':FBranchId,
                'tab': '新增资金调拨',
                'blank': "y"
              }
          });
      }
    }
}
</script>
