<template>
  <div>
    <div class="query-box" style="border-bottom: none;">
      <ul>
        <li>
          <span>
            <em>{{$t('system.table_ssLine')}}</em>
            <el-select class="w150" v-model="msg.LineId" filterable :placeholder="$t('pub.pleaseSel')"
              @change="getLineTeamList(msg.LineId)">
              <el-option :label="$t('pub.unlimitedSel')" :value="0"></el-option>
              <el-option v-for="item in LineList" :label="item.LineName" :value="item.LineID" :key="item.LineID">
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('advmanager.v_xilie')}}</em>
            <el-select v-model="msg.LineteamId" filterable :placeholder="$t('pub.pleaseSel')">
              <el-option :label="$t('pub.unlimitedSel')" :value='0'></el-option>
              <el-option v-for="item in LineTeamList" :label='item.LtName' :value='item.LtID' :key='item.LtID'>
              </el-option>
            </el-select>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('ground.hth')}}</em>
            <el-input v-model='msg.CombinationNum'></el-input>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('visa.v_tuanhao')}}</em>
            <el-input v-model='msg.TCNUM'></el-input>
          </span>
        </li>
        <li><span><em>{{$t('Operation.Op_chutuan')}}{{$t('sm.Date')}}</em>
            <!-- <el-date-picker v-model='msg.StartDate' class='w135' value-format="yyyy-MM-dd" type="date"></el-date-picker> -->
            <DateLimit :clearable="false" :StartGroupDate="msg.StartDate" :EndGroupDate="msg.EndDate" @change="(date)=> msg.StartDate = date"></DateLimit>
            -
            <el-date-picker v-model='msg.EndDate' class='w135' value-format="yyyy-MM-dd" type="date" :picker-options="pickerBeginDateStart" :placeholder="$t('admin.admin_choDate')"></el-date-picker>
          </span>
        </li>
        <li>

          <span>  <el-tooltip class="item" effect="dark" :content="$t('objFill.v101.daorugwyjsjrq')" placement="top">
            <em>{{$t('objFill.v101.daoruriqi')}}</em>
    </el-tooltip>
            <!-- <el-date-picker v-model='msg.CStartDate' class='w135' value-format="yyyy-MM-dd" type="date"></el-date-picker> -->
            <DateLimit :clearable="true" :StartGroupDate="msg.CStartDate" :EndGroupDate="msg.CEndDate" @change="(date)=> msg.CStartDate = date"></DateLimit>
            -
            <!-- <el-date-picker v-model='msg.CEndDate' class='w135' value-format="yyyy-MM-dd" type="date" :picker-options="pickerBeginDateAfter" :placeholder="$t('admin.admin_choDate')"></el-date-picker> -->
            <DateLimit :clearable="true" :StartGroupDate="msg.CEndDate" @change="(date)=> {msg.CEndDate = date,dataDui()}"></DateLimit>
          </span>
        </li>
        <li>
          <span>
            <em>{{$t('objFill.v101.zhikyidryjsjt')}}</em>
            <el-switch v-model="msg.IsQCommission" active-value="true" inactive-value="false">
            </el-switch>
          </span>
        </li>
        <li>
          <input type="button" class="normalBtn" :value="$t('pub.searchBtn')" @click="getList();resetPageIndex()" />
          <button class="hollowFixedBtn" @click="method5()">{{$t('visa.v_daochu')}}</button>
          <input type="button" class="normalBtn" :value="$t('objFill.v101.piliangzhiyjdan')" @click="MoreCreateBill()" />
          <input type="button" class="normalBtn" :value="$t('objFill.v101.FinancialModule.pilianscfj')" @click="UploadAttachment()" />
        </li>
      </ul>
    </div>
    <el-row style="margin-bottom: 20px;">
      <el-col :span="20" style="color:red;">{{$t('objFill.v101.shiylbmhzuiy')}} &nbsp;</el-col>
      <el-col :span="4" class="groupTourOrder_count_col">
        <div class="groupTourOrder_count_item">
          <div>
            <i class="iconfont icon-tongji1 groupTourOrder_count_gray"></i>
            <span>{{ $t("fnc.cwdjshuoming") }}</span>
          </div>
          <p>
            <span class="groupTourOrderByTuan_ico"><i
                style="background-color: #0000ff"></i><span>{{ $t("fnc.yidadan") }}</span></span>
            <span class="groupTourOrderByTuan_ico"><i
                style="background-color: #00ff00"></i><span>{{ $t("fnc.ptcnyshenhe") }}</span></span>
            <span class="groupTourOrderByTuan_ico"><i
                style="background-color: #ff0000"></i><span>{{ $t("fnc.yhcnyshenhe") }}</span></span>
            <span class="groupTourOrderByTuan_ico"><i
                style="background-color: #000000"></i><span>{{ $t("fnc.ytongguo") }}</span></span>
          </p>
        </div>
      </el-col>
    </el-row>
    <div style="width: 100%;  overflow-x: auto;padding-bottom: 10px; ">
      <table border="0" cellspacing="1" cellpadding="0" class="ShoppingTable"
        style="border: 1px solid rgb(230, 230, 230);min-width: 1600px" v-loading="loading">
        <tr>
          <th width="60">
            <el-checkbox v-model="checkAll" @change="getSelectAll()">{{$t('system.table_chekAll')}}</el-checkbox>
          </th>
          <th width="115">{{$t('active.ad_xuhao')}}</th>
          <th width="100">{{$t('sm.chufadi')}}</th>
          <th width="110">{{$t('salesModule.CompanyNum')}}</th>
          <th width="100">{{$t('leader.leader_Leader')}}</th>
          <th width="100">{{$t('leader.leader_Guide')}}</th>
          <th width="190">{{$t('ground.dm')}}</th>
          <th width="60">{{$t('ground.jdrs')}}</th>
          <th width="70">{{$t('sm.company')}}</th>
          <th width="70">{{$t('fnc.a_zongjine')}}</th>
          <th width="70">{{$t('objFill.v101.yongjinze')}}</th>
          <th width="80">{{$t('ground.ldyj')}}<br />({{$t('fnc.yingfu')}})</th>
          <th width="80">{{$t('ground.dyyj')}}<br />({{$t('fnc.yingfu')}})</th>
          <th width="80">{{$t('ground.picyj')}}<br />({{$t('fnc.yingfu')}})</th>
          <th width="80">{{$t('ground.gsyj')}}<br />({{$t('fnc.yingshou')}})</th>
          <th width="80">{{$t('ground.fyye')}}</th>
          <th width="80">{{$t('ground.fyzj')}}</th>
          <th width="80">{{$t('hotel.hotel_CurrentRate')}}</th>
          <th width="80">{{$t('objFill.v101.yutianheji')}}</th>
          <th width="80">{{$t('objFill.v101.shijiheji')}}</th>
          <th width="80">{{$t('ground.pinzheng')}}</th>
          <th width="100">{{$t('pub.pubRemark')}}</th>
          <!-- <th width="80">{{$t('hotel.hotel_Order')}}</th> -->
          <th width="80">{{$t('system.table_operation')}}</th>
        </tr>
        <tr v-if="shopDataList.length==0">
          <td colspan="22">{{$t('system.content_noData')}}</td>
        </tr>
        <tbody v-for="(outItem,outindex) in shopDataList" :class="{roomReservationsSplitTrCss:outindex%2!=0}"
          v-if="outItem.PriceShopList.length>0" :key="outindex+1500">
          <template v-for="(item,index) in outItem.PriceShopList">
            <template v-for="(subItem,subIndex) in item.ShopDetailsList">
              <tr>
                <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                  <el-checkbox @change="changeCheck(outItem)" v-model="outItem.IsCheck"
                    :disabled="outItem.IsCheckDisabled"></el-checkbox>
                </td>
                <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                  {{outItem.NewCombinationNum}}
                </td>
                <template v-if="outItem.TCList.length==1">
                  <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                    {{subItem.StartCityNames}}
                  </td>
                  <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                    {{subItem.TCNUMS}}({{subItem.TCID}})
                  </td>
                  <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                    {{subItem.LeaderName}}<span style="color:red;">{{subItem.IsLeaderDaiTuan==1?$t('objFill.v101.dmc.daituan'):$t('objFill.v101.dmc.budaituan')}}</span>
                  </td>
                  <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                    {{subItem.GuideName}}<span style="color:red;">{{subItem.IsGuideDaiTuan==1?$t('objFill.v101.dmc.daituan'):$t('objFill.v101.dmc.budaituan')}}</span>
                  </td>
                </template>
                <template v-else>
                  <td>
                    {{subItem.StartCityNames}}
                  </td>
                  <td>
                    {{subItem.TCNUMS}}({{subItem.TCID}})
                  </td>
                  <td>
                    {{subItem.LeaderName}}<span style="color:red;">{{subItem.IsLeaderDaiTuan==1?$t('objFill.v101.dmc.daituan'):$t('objFill.v101.dmc.budaituan')}}</span>
                  </td>
                  <td>
                    {{subItem.GuideName}}<span style="color:red;">{{subItem.IsGuideDaiTuan==1?$t('objFill.v101.dmc.daituan'):$t('objFill.v101.dmc.budaituan')}}</span>
                  </td>
                </template>
                <td :rowspan="item.ShopDetailsList.length" v-if='subIndex==0' width="180"
                  style="word-wrap:break-word ;">
                  {{item.ShopName}}
                </td>
                <td width="60">
                  {{subItem.EnterNum}}
                </td>
                <td width="70">
                  {{subItem.BName}}
                </td>
                <td width="70">
                  {{subItem.TotalMoney}}
                </td>
                <td> {{(subItem.LeaderCommission+subItem.GuideCommission+subItem.PICCommission+subItem.CompanyCommission).toFixed(2)}}</td>
                <td width="80">
                  {{subItem.LeaderCommission}}</br>
                  <!-- <span v-if="subItem.LeaderCommission>0&&subItem.LeaderCommissionFrId"
                  style="color:red;text-decoration: underline;cursor:pointer;"
                  @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',subItem.LeaderCommissionFrId)">
                  {{subItem.LeaderCommissionFrId}}</span> -->
                  <span class="cursor-p" v-if="subItem.LeaderFinanceList"
                    v-for="(item2, index2) in subItem.LeaderFinanceList" :key="index2"
                    @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',item2.FrID)">
                    <span v-if="item2.Status === 0||item2.Status === 1"
                      class="groupTourOrder_tickets_blue">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 2" class="groupTourOrder_tickets_green">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 3" class="groupTourOrder_tickets_red">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 4" class="groupTourOrder_tickets_black">{{ item2.FrID }}</span>
                  </span>
                </td>
                <td width="80">
                  {{subItem.GuideCommission}}</br>
                  <!-- <span v-if="subItem.GuideCommission>0&&subItem.GuideCommissionFrId"
                    style="color:red;text-decoration: underline;cursor:pointer;"
                    @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',subItem.GuideCommissionFrId)">
                    {{subItem.GuideCommissionFrId}}</span> -->
                  <span class="cursor-p" v-if="subItem.GuideFinanceList"
                    v-for="(item2, index2) in subItem.GuideFinanceList" :key="index2"
                    @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',item2.FrID)">
                    <span v-if="item2.Status === 0||item2.Status === 1"
                      class="groupTourOrder_tickets_blue">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 2" class="groupTourOrder_tickets_green">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 3" class="groupTourOrder_tickets_red">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 4" class="groupTourOrder_tickets_black">{{ item2.FrID }}</span>
                  </span>
                </td>
                <td width="80">
                  {{subItem.PICCommission}}</br>
                  <!-- <span v-if="subItem.PICCommission>0&&subItem.CompanyCommissionFrId"
                    style="color:red;text-decoration: underline;cursor:pointer;"
                    @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',subItem.CompanyCommissionFrId)">
                    {{subItem.CompanyCommissionFrId}}</span> -->
                  <span class="cursor-p" v-if="subItem.PICFinanceList" v-for="(item2, index2) in subItem.PICFinanceList"
                    :key="index2" @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',item2.FrID)">
                    <span v-if="item2.Status === 0||item2.Status === 1"
                      class="groupTourOrder_tickets_blue">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 2" class="groupTourOrder_tickets_green">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 3" class="groupTourOrder_tickets_red">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 4" class="groupTourOrder_tickets_black">{{ item2.FrID }}</span>
                  </span>
                </td>
                <td width="80">
                  {{subItem.CompanyCommission}}</br>
                  <!-- <span v-if="subItem.CompanyCommission>0&&subItem.PICCommissionFrId"
                    style="color:red;text-decoration: underline;cursor:pointer;"
                    @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',subItem.PICCommissionFrId)">
                    {{subItem.PICCommissionFrId}}</span> -->
                  <span class="cursor-p" v-if="subItem.CompanyFinanceList"
                    v-for="(item2, index2) in subItem.CompanyFinanceList" :key="index2"
                    @click="goUrlFinancial('财务单据','FinancialDocumentsDetail',item2.FrID)">
                    <span v-if="item2.Status === 0||item2.Status === 1"
                      class="groupTourOrder_tickets_blue">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 2" class="groupTourOrder_tickets_green">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 3" class="groupTourOrder_tickets_red">{{ item2.FrID }}</span>
                    <span v-else-if="item2.Status === 4" class="groupTourOrder_tickets_black">{{ item2.FrID }}</span>
                  </span>

                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  {{subItem.OtherDeduct}}
                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  {{subItem.BackTotalMoney}}
                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  {{subItem.DMCRate}}
                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  <template v-if="item.PreTotalMoney!=item.ActualTotalMoney">
                    <span style="color:red;">{{item.PreTotalMoney}}</span>
                  </template>
                  <template v-else>
                    {{item.PreTotalMoney}}
                  </template>
                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  <template v-if="item.PreTotalMoney!=item.ActualTotalMoney">
                    <span style="color:red;">{{item.ActualTotalMoney}}</span>
                  </template>
                  <template v-else>
                    {{item.ActualTotalMoney}}
                  </template>
                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  <p v-for="(img, imgIndex) in subItem.dmcImageList" :title="$t('objFill.v101.dianjixiaza')" @click="downLoadPZ(img)"
                    :key="imgIndex+500" v-if="img !== ''" style="cursor: pointer;color:blue;">{{ $t('ground.pingzheng') + (imgIndex + 1)}}
                  </p>
                </td>
                <td width="80" :rowspan="item.ShopDetailsList.length" v-if='subIndex==0'>
                  {{subItem.Remarks}}
                </td>
                <!-- <td :rowspan="item.ShopDetailsList.length" v-if='subIndex==0' style="">
                  <div>
                    <p style="cursor: pointer;color:blue;margin-top:10px;" @click="CreateHandBill(outItem)">
                      {{$t('ground.sdscdj')}}</p>
                  </div>
                </td> -->
                <td :rowspan="outItem.rowspanCount" v-if="index==0&&subIndex==0">
                  <!-- <p style="cursor: pointer;color:blue;"
                    @click="GenerateDocuments(outItem,subItem.LeaderId,subItem.GuideId)">
                    {{$t('ground.scdanju')}}
                  </p> -->
                  <p style="cursor: pointer;color:blue;margin-top:5px;"
                    @click="goHuiZhi(outItem.TCIDs, item.LeaderName, item.GuideName, item.StartCityNames, item.TCNUMS)">
                    {{$t('ground.xzgwd')}}</p>
                  <p style="cursor: pointer;color:blue;margin-top:10px"
                    @click="goUrlT('ShoppingReimbursementDetails',outItem.TCIDs,'购物报账详情')">
                    {{$t('system.table_operation')}}</p>
                </td>
              </tr>
            </template>
          </template>
        </tbody>
        <tbody v-else v-for="(outItem,outindex) in shopDataList" :key="outindex+100">
          <tr>
            <td>
              {{outItem.NewCombinationNum}}
            </td>
            <td>
            </td>
            <td>
            </td>
            <td>
            </td>
            <td>
            </td>
            <td width="180"></td>
            <td width="60"></td>
            <td width="70"></td>
            <td width="70"></td>
            <td width="80"></td>
            <td width="80"></td>
            <td width="80"></td>
            <td width="80"></td>
            <td width="80"> </td>
            <td width="80"> </td>
            <td width="80"></td>
            <td width="80"></td>
            <td width="80"></td>
            <td></td>
            <td></td>
            <td></td>
          </tr>
        </tbody>
      </table>
      <el-pagination background @current-change="handleCurrentChange" :current-page.sync="msg.currentPage"
        layout="total, sizes, prev, pager, next, jumper" :page-size="msg.pageSize" :page-sizes="[8, 10, 20, 30, 40,50]"
        @size-change="handleSizeChange" :total="msg.total">
      </el-pagination>
    </div>
    <a id='blankLink1' target="_blank" style="display:none">1</a>
    <el-dialog custom-class='w400' :title="$t('objFill.v101.qingxzxyzdthao')" :visible.sync="zhuanjiaoBox" center>
      <template>
        <el-form label-width="100px">
          <el-form-item :label="$t('visa.v_tuanhao')">
            <div v-for="(item,index) in CreateHandBillList" :key="index+1000">
              <el-radio v-model="CreateHandBillID" :key="item.id" :label="item.id"></el-radio>
            </div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <button class="hollowFixedBtn" @click="zhuanjiaoBox=false">{{$t('pub.cancelBtn')}}</button>
          <button class="normalBtn" type="primary" @click="goCreateHandBill()">{{$t('pub.sureBtn')}}</button>
        </div>
      </template>
    </el-dialog>
    <el-dialog :title="$t('objFill.generatedocuments')" :visible.sync="isShowFinaceDailog" custom-class='w400' center>
      <template>
        <el-form label-width="100px">
          <el-form-item :label="$t('fnc.fkfangshi')">
            <el-select v-model="PayType">
              <el-option :label="$t('ground.cgfukuan')" :value="1" :key="1"></el-option>
              <el-option :label="$t('ground.zjcfk')" :value="2" :key="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('objFill.v101.yongjinleix')">
            <el-select multiple v-model="FinanceTypes">
              <el-option v-for="(item,index) in FinanceTypeList" :label="item.Name" :value="item.Id" :key="item.Id"
                :disabled="getFinanceType(item)"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('objFill.v101.linduizhanghu')" v-if="LeaderAccountList && LeaderAccountList.length>0">
            <el-select v-model="LeaderAccountId">
              <el-option :value="0" :label="$t('system.ph_choice')"></el-option>
              <el-option v-for="(item,index) in LeaderAccountList" :label="item.Name" :value="item.ID" :key="item.ID">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('objFill.v101.daoyouzhanghu')" v-if="GuideAccountList && GuideAccountList.length>0">
            <el-select v-model="GuideAccountId">
              <el-option :value="0" :label="$t('system.ph_choice')"></el-option>
              <el-option v-for="(item,index) in GuideAccountList" :label="item.Name" :value="item.ID" :key="item.ID">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('objFill.v101.shengc550sxf')">
            <el-select v-model="IsFee">
              <el-option :label="$t('pub.yes')" :value="1" :key="1"></el-option>
              <el-option :label="$t('pub.no')" :value="2" :key="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <button class="hollowFixedBtn"
            @click="isShowFinaceDailog=false,CurrentOutItem={}">{{$t('pub.cancelBtn')}}</button>
          <el-button class="normalBtn" type="primary" @click="CreateBill()" :disabled="FinanceTypes.length==0">
            {{$t('pub.sureBtn')}}</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog :title="$t('objFill.generatedocuments')" :visible.sync="BOSSDialogText" class="Shopping_bossdialog">
      <template v-if="!BOSSDialog">
        <div style="margin-bottom: 30px;">
          <ul>
            <li style="float: left; margin-right: 30px;" v-for="(qitem,qindex) in LeaderGuideDefault">
              <span :style="qitem.IsAccount==0?'color:red':'color:black'">{{qitem.Name}} > {{(qitem.IsAccount==1?qitem.Bank:$t('objFill.v101.qingzfukdxgl'))}} <span style="color:red;">{{qitem.IsJapan==1?$t('objFill.v101.ribrnzhnaghu'):''}}</span></span>
            </li>
          </ul>
        </div>
        <br/>
        <div style="display: inline-block;" v-if="IsLGCommissionAccount==false">{{$t('objFill.v101.qingwanslddyzh')}}</div>
        <div style="display: inline-block;" v-else>
          <p>{{$t('objFill.v101.qingzysydjydsczcpl')}}</p>
          <p>{{$t('objFill.v101.linddysycgfkzf')}}</p>
          <p>{{$t('objFill.v101.zhuypzwtrccsczsy')}}</p>
        </div>
        <br/>
        <el-form label-width="110px">
          <el-row>
            <el-col :span="12" :gutter="35">
              <el-form-item :label="$t('objFill.shangchuanpz')">
                <div class="_addUpload_box clearfix">
                  <template v-for="(file,fIndex) in saveMsg">
                    <div v-if="file.Type==3">
                      <div style="width:100%;height:100%;overflow: hidden;">
                        <img style="width:100%;height:100%;" :src="file.Url?file.Url:file.Content"
                          @click="showUpLoadFile(file)">
                      </div>
                      <span class="iconfont icon-guanbi1" @click="deleteUploadFile(fIndex)"></span>
                    </div>
                    <div v-if="file.Type==1">
                      <div class="iconfont "
                        :class="file.Content.substring(file.Content.lastIndexOf('.')+1,file.Content.length).toUpperCase()=='PDF'? 'icon-pdf' : 'icon-excel'"
                        @click="showUpLoadFile(file)">

                      </div>
                      <span class="iconfont icon-guanbi1" @click="deleteUploadFile(fIndex)"></span>
                    </div>
                    <div v-if="file.Type==2">
                      <div class="iconfont icon-excel" @click="showUpLoadFile(file)">

                      </div>
                      <span class="iconfont icon-guanbi1" @click="deleteUploadFile(fIndex)"></span>
                    </div>
                  </template>
                  <div class="_pic_upload">
                    <el-upload drag :http-request="uploadFileBtn" :multiple="true" :show-file-list="false" action="">
                      <i class="el-icon-plus avatar-uploader-icon"></i>
                      <div class="el-upload__text">{{$t('active.ld_djscwj')}}</div>
                    </el-upload>
                  </div>
                </div>
              </el-form-item>
              <template v-if="IsJapan==1">
                <el-form-item :label="$t('objFill.v101.shengc550sxf')">
            <el-select v-model="nMsg.IsHaveFee">
              <el-option :label="$t('pub.yes')" :value="1" :key="1"></el-option>
              <el-option :label="$t('pub.no')" :value="2" :key="2"></el-option>
            </el-select>
          </el-form-item></template>

            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <button class="normalBtn" type="primary" v-if="IsLGCommissionAccount"
            @click="bossLen = 1, MoreSureCreateBill()">{{$t('pub.saveBtn')}}</button>
          <button class="hollowFixedBtn" @click="BOSSDialogText=false">{{$t('pub.cancelBtn')}}</button>
        </div>
      </template>
      <template v-else>
        <p class="boss_btn">{{$t('ios.gongji')}} {{selectedRowKeys.length}} {{$t('ios.tdqdi')}}
          <span>{{(bossLen>selectedRowKeys.length)?selectedRowKeys.length:bossLen}}</span>
          {{$t('ios.tiao')}}</p>
        <p class="boss_btn_tips">{{$t('objFill.v101.pilzdzqbyjxqtcz')}}</p>
      </template>

    </el-dialog>
    <!-- 批量上传附件 -->
    <attachments :show="isUploadAttachment"
    @cancel="isUploadAttachment=false"
    @success="isUploadAttachment=false,getList();resetPageIndex()"></attachments>
  </div>
</template>
<script>
  import attachments from "./components/attachments.vue";
  import DateLimit from '../public/DateLimit.vue';
  export default {
    components: {
      attachments,
      DateLimit
    },
    data() {
      return {
        pickerBeginDateStart: {
          disabledDate: time => {
            let startTime = new Date(this.msg.StartDate);
            return startTime.getTime() >= time.getTime();
          }
        },
        pickerBeginDateAfter: {
          disabledDate: time => {
            let startTime = new Date(this.msg.CStartDate);
            return startTime.getTime() >= time.getTime();
          }
        },
        saveUploadMsg: [],
        isUploadAttachment: false,
        FinanceTypeList: [{
            Name: this.$t('advmanager.v_all'),
            Id: 0
          },
          {
            Name: this.$t('ground.ldyj'),
            Id: 1
          },
          {
            Name: this.$t('ground.dyyj'),
            Id: 2
          },
          {
            Name: this.$t('ground.gsyj'),
            Id: 3
          },
          {
            Name: this.$t('ground.picyj'),
            Id: 4
          },
        ],

        checkAll: false, //全选状态
        selectedRowKeys: [], //选中的key
        FinanceTypes: [0], //佣金类型
        loading: false,
        PayType: 1, //付款方式
        LeaderAccountId: 0,
        GuideAccountId: 0,
        LeaderAccountList: [],
        GuideAccountList: [],
        IsFee: 1,
        IsJapan:0,
        msg: {
          pageIndex: 1,
          pageSize: 8,
          //购物店
          SelectType: 7,
          LineId: 0,
          LineteamId: 0,
          StartDate: '',
          EndDate: '',
          currentPage: 1,
          total: 0,
          CombinationNum: "", //合团号
          TCNUM: "", //团号
          IsQCommission: false,
          CStartDate: '',
          CEndDate: '',
        },
        LineList: [],
        LineTeamList: [],
        shopDataList: [],
        CreateHandBillList: [],
        zhuanjiaoBox: false,
        isShowFinaceDailog: false, //是否显示生成财务单据对话框
        CreateHandBillID: '',
        CreateHandObj: {},
        CurrentOutItem: {}, //当前选中的团
        bossLen: null,
        BOSSDialog: false,
        BOSSDialogText: false,
        //上传数组
        saveMsg: [],
        LeaderGuideDefault:[],
        IsLGCommissionAccount:true,
        userMenuCode: false,
        HandShow: false,
        nMsg: {
          TCIDs: "",
          PayType: 1,
          uid: 0,
          FinanceType: "0",
          LeaderAccountId: 0,
          GuideAccountId: 0,
          IsFee: 1,
          IsHaveFee:2,
          VoucherList: [],
          IsBatch: 1
        },
      }
    },
    methods: {
      dataDui() {
        if (this.msg.CStartDate > this.msg.CEndDate && this.msg.CEndDate !== "") {
          this.$message.error(this.$t('tips.jsrqbndyksriqi'));
          this.msg.CEndDate = "";
        }
      },
      UploadAttachment(){
        this.isUploadAttachment = true
      },

      GenerateDocuments(outItem, LeaderId, GuideId) {
        this.isShowFinaceDailog = true
        this.CurrentOutItem = outItem
        // 处理账户
        this.LeaderAccountList = [];
        this.LeaderAccountId = 0;
        this.GuideAccountList = [];
        this.GuideAccountId = 0;
        if (LeaderId && LeaderId > 0) {
          this.financeinfo_post_GetClientAccountList(LeaderId, 1);
        }
        if (GuideId && GuideId > 0) {
          this.financeinfo_post_GetClientAccountList(GuideId, 2);
        }
      },
      goCreateHandBill: function () {
        let obj = {}
        for (let i = 0; i < this.CreateHandBillList.length; i++) {
          if (this.CreateHandBillList[i].id == this.CreateHandBillID) {
            obj = this.CreateHandBillList[i]
          }
        }
        let orderObj = {
          OrderID: '',
          OrderSource: 8,
          Obj: {},
          SourceID: '',
          TCIDList: [obj.TCID]
        };
        this.$router.push({
          name: "ChoiceAddFinancialDocuments",
          query: {
            Type: 0,
            companyID: obj.OutBranchId, //公司id
            path: "",
            blank: "y",
            orderObj: JSON.stringify(orderObj)
          }
        });
        this.zhuanjiaoBox = false;
      },
      CreateHandBill: function (obj) {
        this.CreateHandObj = obj
        let newList = []
        for (let i = 0; i < obj.TCList.length; i++) {
          newList.push({
            TCID: obj.TCList[i].TCID,
            id: obj.TCList[i].TCNUMS,
            OutBranchId: obj.TCList[i].OutBranchId
          })
        }
        this.CreateHandBillList = newList
        this.zhuanjiaoBox = true
      },
      downLoadPZ: function (src) {
        let dom = document.querySelector("#blankLink1")
        dom.href = src;
        dom.click();
      },
      stringToArr(str) {
        return str.split(',')
      },
      getLineList() {
        this.apipost("line_post_GetAllList", {}, res => {
          if (res.data.resultCode == 1) {
            this.LineList = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        });
      },
      //获取系列列表
      getLineTeamList(lineId) {
        this.LineTeamList = [];
        this.apipost(
          "team_post_GetList", {
            lineID: lineId,
            isTOOP: 1
          },
          res => {
            if (res.data.resultCode == 1) {
              this.msg.LineteamId = 0;
              this.LineTeamList = res.data.data;
            }
          }
        );
      },
      goUrlR(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "ID": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      goUrlT(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "id": obj,
            blank: 'y',
            tab: title
          }
        })
      },
      goHuiZhi(TCIDS, LeaderName, GuideName, StartCityNames, TCIDEN) {
        this.$router.push({
          name: 'ShoppingReceipt',
          query: {
            LeaderName: LeaderName,
            GuideName: GuideName,
            StartCityNames: StartCityNames,
            blank: 'y',
            TCID: TCIDS,
            TCIDEN: TCIDEN
          }
        });
      },

      goUrlFinancial: function (name, path, id) {
        this.$router.push({
          name: path,
          query: {
            id: id,
            blank: 'y',
            tab: name
          }
        });
      },
      goUrl(path, obj, title) {
        this.$router.push({
          name: path,
          query: {
            "id": obj.TCIDS,
            'TCNUM': obj.TCNUMS,
            'flightTotal': obj.TotalSeat,
            'GuestNum': obj.CommonReport.HouseStatistics.RealityNum,
            'NewCombinationNum': obj.NewCombinationNum,
            blank: 'y',
            tab: title
          }
        })
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },

      handleSizeChange(val) {
        this.msg.pageIndex = 1;
        this.msg.pageSize = val;
        this.getList();
      },
      resetPageIndex() {
        this.msg.pageIndex = 1;
        this.currentPage = 1;
      },
      getList() {
        this.loading = true;
        this.apipost('dmcstatistics_post_GetShopCombinationNumService', this.msg, res => {
          this.loading = false
          if (res.data.resultCode == 1) {
            this.msg.total = res.data.data.count;
            this.shopDataList = res.data.data.pageData;
          } else {
            this.$message.error(res.data.message)
          }
        }, err => {})
      },
      getFinanceType(item) {
        if (this.FinanceTypes && this.FinanceTypes.length == 0) return false
        else if (this.FinanceTypes.length > 0 && this.FinanceTypes.indexOf(0) != -1) {
          if (item.Id != 0) {
            return true
          } else return false
        } else if (this.FinanceTypes.length > 0 && this.FinanceTypes.indexOf(0) == -1) {
          if (item.Id == 0) {
            return true
          } else {
            return false
          }
        }
      },
      //全选
      getSelectAll() {
        if (this.checkAll) {
          this.selectedRowKeys = [] // 判断是否已全部选中,是则清空已选列表
          this.checkAll = false;
          this.shopDataList.forEach((item) => {
            if (item.IsCheck)
              item.IsCheck = false;
          })
          this.$forceUpdate();
        } else {
          this.shopDataList.forEach((item) => {
            if (!this.selectedRowKeys.includes(item.TCIDs) && item.IsCheckDisabled == false) {
              item.IsCheck = true;
              this.selectedRowKeys.push(item.TCIDs) // 否则将未选中的全部加入已选列表中
            }
          })
          this.checkAll = true;
          this.$forceUpdate();
        }
      },
      changeCheck(row) {
        if (!this.selectedRowKeys.includes(row.TCIDs)) {
          row.IsCheck = true;
          this.selectedRowKeys.push(row.TCIDs);
        } else {
          row.IsCheck = false;
          let index = this.selectedRowKeys.indexOf(row.TCIDs);
          this.selectedRowKeys.splice(index, 1);
        }
        if (this.selectedRowKeys.length == this.shopDataList.length) {
          this.checkAll = true;
        } else {
          this.checkAll = false;
        }
        this.$forceUpdate();
      },
      //生成单据
      CreateBill() {
        var that = this;
        if (this.FinanceTypes && this.FinanceTypes.length == 0) {
          that.Error(this.$t('objFill.v101.qingxzzsygyjlx'));
          return
        }
        if (this.FinanceTypes && this.FinanceTypes.length >0 &&(this.FinanceTypes.includes(0)||this.FinanceTypes.includes(1)||this.FinanceTypes.includes(2))) {
         if(this.FinanceTypes.includes(0)||this.FinanceTypes.includes(1)){
              if (that.LeaderAccountId==0) {
                that.Error(this.$t('objFill.v101.qingxzldzhao'));
                return
            }
          }
          if(this.FinanceTypes.includes(0)||this.FinanceTypes.includes(2)){
            if (that.GuideAccountId==0) {
            that.Error(this.$t('objFill.v101.qingxzdyouzh'));
             return
          }
         }
        }
        if (this.FinanceTypes && this.FinanceTypes.length == 0) {
          that.Error(this.$t('objFill.v101.qingxzzsygyjlx'));
          return
        }
        this.$confirm(this.$t('objFill.v101.shifshccwdju'), this.$t('tips.tips'), {
          confirmButtonText: this.$t('pub.sureBtn'),
          cancelButtonText: this.$t('pub.cancelBtn'),
          type: 'warning'
        }).then(() => {
          var nMsg = {
            TCIDs: that.CurrentOutItem.TCIDs,
            PayType: that.PayType,
            uid: that.getLocalStorage().EmployeeId,
            FinanceType: this.FinanceTypes.join(','),
            LeaderAccountId: that.LeaderAccountId,
            GuideAccountId: that.GuideAccountId,
            IsFee: that.IsFee
          };
          that.loading = true;
          that.apipost("dmcstatistics_post_CheckShopDetailsDMCRate", nMsg, res => {
            if (res.data.resultCode == 1) {
              if (res.data.data.result == 0) {
                // that.Error("请检查汇率有为0的数据,请先在【操作】里面修改汇率再生成财务单据!");
                that.Error(res.data.data.errorMessage);
                that.loading = false;
                that.isShowFinaceDailog = false;
              } else {
                let fileName = this.$t('objFill.shengcheng')+"[" + that.CurrentOutItem.NewCombinationNum + "]"+this.$t('objFill.v101.gouowudiansj')+".xls";
                that.GetLocalFile("dmcstatistics_post_ShopCreateBillAndExport", nMsg, fileName,
                  res => {
                    that.loading = false;
                    this.isShowFinaceDailog = false;
                    that.Success(this.$t('objFill.v101.daoruchengg')+'!');
                    that.getList();
                  });
              }
            }
          });
        }).catch(() => {})
      },
      //生成单据
      increment() {
        if (this.bossLen && this.bossLen <= this.selectedRowKeys.length) {
          this.nMsg.uid = this.getLocalStorage().EmployeeId;
          this.nMsg.TCIDs = this.selectedRowKeys[this.bossLen - 1];
          this.apipost(
            "dmcstatistics_post_CheckShopDetailsDMCRate",
            this.nMsg,
            res => {
              if (res.data.resultCode == 1) {
                if (res.data.data.result == 0) {
                  this.$message.error(res.data.data.errorMessage);
                  this.loading = false;
                  this.selectedRowKeys = [];
                  this.getList();
                  this.saveMsg = [];
                  this.BOSSDialog = false;
                  this.BOSSDialogText = false;
                  return;
                } else {
                  this.apipost("dmcstatistics_post_BatchShopCreateBill", this.nMsg,
                    res => {
                      if (res.data.resultCode == 1) {
                        this.bossLen += 1;
                        this.increment();
                      } else {
                        this.$message.error(res.data.message);
                        // this.$message.error("单据生成失败,请稍后重试");
                        this.loading = false;
                        this.selectedRowKeys = [];
                        this.getList();
                        this.saveMsg = [];
                        this.BOSSDialog = false;
                        this.BOSSDialogText = false;
                      }
                    });
                }
              } else {
                this.$message.error(res.data.message);
                this.loading = false;
                this.selectedRowKeys = [];
                this.getList();
                this.saveMsg = [];
                this.BOSSDialog = false;
                this.BOSSDialogText = false;
              }
            },
            err => {}
          );
        } else {
          this.BOSSDialog = false;
          this.BOSSDialogText = false;
          this.saveMsg = [];
          this.selectedRowKeys = [];
          this.$message.success(this.$t('objFill.v101.pilianzdcgo'));
          this.loading = false;
          this.checkAll = false;
          this.getList();
        }
      },


      MoreCreateBill() {
        if (this.selectedRowKeys && this.selectedRowKeys.length == 0) {
          this.$message.error(this.$t('objFill.v101.qingxzzsyigtuan'));
          return;
        }

        let leaderIds=[];
        this.shopDataList.forEach((item) => {
            if (item.IsCheck){
              item.PriceShopList.forEach((x,i)=>{
                x.ShopDetailsList.forEach((y,index)=>{
                  let filter = []
                  filter = leaderIds.filter(z=>{return z==y.LeaderId})
                  let filter2 = []
                  filter2 = leaderIds.filter(z=>{return z==y.GuideId})
                  if((y.LeaderCommissionFrId==''||y.LeaderCommissionFrId=='0'||!y.LeaderCommissionFrId)&&y.LeaderCommission!='0'&&(filter.length==0||!filter)){
                    leaderIds.push(y.LeaderId);
                  }
                  if((y.GuideCommissionFrId==''||y.GuideCommissionFrId=='0'||!y.GuideCommissionFrId)&&y.GuideCommission!='0'&&(filter2.length==0||!filter2)){
                    leaderIds.push(y.GuideId);
                  }
                })
              })
              // leaderIds.push(item.LeaderGuideIds);
            }
          })
          if(leaderIds.length>0){
            this.loading = true;
            this.IsLGCommissionAccount=true;
            this.apipost(
                "dmcstatistics_post_GetShopLeaderGuideAccount",
                {LeaderGuideIds:leaderIds.join(',')},
                res => {
                  if (res.data.resultCode == 1) {
                    this.loading = false;
                    this.LeaderGuideDefault = res.data.data.BackAccountList;
                    this.IsJapan= res.data.data.IsJapan;
                    if(this.IsJapan==1){
                      this.nMsg.IsHaveFee=1;
                    }
                    this.LeaderGuideDefault.forEach(item=>{
                      if(item.IsAccount==0){
                        this.IsLGCommissionAccount=false;
                      }
                    });
                    this.saveMsg = [];
                    this.BOSSDialog = false;
                    this.BOSSDialogText = true;
                  } else {
                    this.$message.error(res.data.message);
                    this.loading = false;
                    this.BOSSDialog = false;
                    this.BOSSDialogText = false;
                  }
                },
                err => {}
              );

          }else{
            this.IsJapan = this.nMsg.IsHaveFee = 0
            this.saveMsg = [];
            this.BOSSDialog = false;
            this.BOSSDialogText = true;
          }
        },
      MoreSureCreateBill() {

        this.$confirm(this.$t('objFill.v101.shifpilsccwdju'), this.$t('tips.tips'), {
          confirmButtonText: this.$t('pub.sureBtn'),
          cancelButtonText: this.$t('pub.cancelBtn'),
          type: 'warning'
        }).then(() => {
          this.bossLen = 1;
          this.BOSSDialog = true;
          this.increment();
        }).catch(() => {});
      },
      showUpLoadFile(i) { // 预览上传文件
        if (i.Type == 3) {
          this.picObj.push(i.Url);
          this.imgList.push(i.Url);
          this.picIsShow = false;
          // this.hideFlashMan = true;
        } else {
          if (i.Content.substring(i.Content.lastIndexOf('.') + 1, i.Content.length).toUpperCase() == 'PDF') {
            this.previewPDF(i.Url)
          } else {
            window.open("https://view.officeapps.live.com/op/view.aspx?src=" + i.Url)
          }
        }
      },
      deleteUploadFile(i) { // 删除上传文件
        this.saveMsg.splice(i, 1);
        this.nMsg.VoucherList = this.saveMsg;
      },

      uploadFileBtn(file) { //上传
        if (file.file.size > 1024 * 1024 * 10) {
          this.Error(this.$t('tips.wjdxbncgsz'))
          return
        }
        //  1 文档  2 数据 3 图片
        let typeArr = [{
            stringArr: 'GIF|JPG|JPEG|PNG|BMP',
            type: 3
          },
          {
            stringArr: 'DOCX|DOC|XLSX|XLS|PPT|PPTX|PDF',
            type: 1
          },
        ]
        let ft = file.file.name.substring(file.file.name.lastIndexOf('.') + 1, file.file.name.length).toUpperCase();
        let fileTypeNumber = 2;
        let typeOk = false;
        typeArr.forEach(x => {
          if (x.stringArr.indexOf(ft) != '-1') {
            fileTypeNumber = x.type
            typeOk = true;
          }
        })
        if (!typeOk) return this.error(this.$t('tips.qscWEfile'));
        let newArr = [];
        newArr.push(file.file)
        let path = "/Upload/Temporary/"
        this.$message.info(this.$t('tips.shangchuanzhong'))
        this.UploadSelfFileT(path, newArr, x => {
          this.saveMsg.push({
            Content: x.data.FilePath,
            ID: 0,
            Type: fileTypeNumber,
            Url: this.domainManager().ViittoFileUrl + x.data.FilePath,
          })
          this.nMsg.VoucherList = this.saveMsg;
          this.Success(this.$t('tips.scchenggong'));
        });
      },
      financeinfo_post_GetClientAccountList(ObjID, type) { //获取付款 对象类型  新增用
        let msg = {
          ID: 0,
          Type: 7,
          ObjID: ObjID,
          IsJapanRan: true
        }
        this.apipost('financeinfo_post_GetClientAccountList', msg, res => {
          if (res.data.resultCode == 1) {
            let data = res.data.data;
            let ClientAccountList = [];
            let textName = this.$t('objFill.v101.morenyjzh')
            data.forEach(x => {
              let obj = {
                ID: x.ID,
                Name: x.AccountHolder + x.CardNum + `(${x.AccountAlias})`+(x.IsDefaultCommission==1?`{${textName}}`:''),
                IsDefaultCommission:x.IsDefaultCommission,
              }
              ClientAccountList.push(obj)
            })
            if (type == 1) {
              this.LeaderAccountList = ClientAccountList;
              if (ClientAccountList && ClientAccountList.length > 0) {
               for (let index = 0; index < ClientAccountList.length; index++) {
                const item = ClientAccountList[index];
                if (item.IsDefaultCommission==1) {
                  this.LeaderAccountId = ClientAccountList[index].ID;
                  break;
                }
               }
              }
            } else {
              this.GuideAccountList = ClientAccountList;
              if (ClientAccountList && ClientAccountList.length > 0) {
                for (let index = 0; index < ClientAccountList.length; index++) {
                const item = ClientAccountList[index];
                if (item.IsDefaultCommission==1) {
                  this.GuideAccountId = ClientAccountList[index].ID;
                  break;
                }
               }
              }
            }
          }
        }, err => {})
      },
      method5: function() {
      let msg = JSON.parse(JSON.stringify(this.msg));
      let userInfo = this.getLocalStorage();
      msg.EmployeeId = userInfo.EmployeeId;
      this.GetLocalFile(
        "dmcstatistics_post_GetShopCombinationNumServiceToExcel",
        msg,
        this.$t('objFill.v101.gouwuyongjin')+".xls"
      );
    },
    },
    mounted() {
      let myDate = new Date();
      let nowDate =
        myDate.getFullYear() +
        "-" +
        parseInt(myDate.getMonth() + 1) +
        "-" +
        myDate.getDate();
      this.msg.StartDate = nowDate;
      this.msg.LineId = 14; //默认日本线
      this.getLineList();
      this.getList();
    },
  }

</script>

<style scoped>
  .roomReservationsSplitTrCss td {
    background: #eee !important;
  }

  .more_td>div {
    height: 40px;
    border-bottom: 1px solid rgb(204, 204, 204);
  }

  .more_td>div:last-child {
    border-bottom: 0;
  }

  .ShoppingTable {
    width: 100%;
    font-size: 12px;
    color: #333;
    margin: auto;
    border-collapse: collapse;
    background-color: #fff;
  }

  .ShoppingTable td {
    border: 1px solid #d1d1d1;
    text-align: center;
    padding: 10px 0;
  }

  .ShoppingTable th {
    background-color: #E6E6E6;
  }

  .SponeTable td:first-child {
    border-left: 0;
  }

  .SponeTable td:last-child {
    border-right: 0;
  }


  .Shopping_bossdialog ._addUpload_box {
    display: initial;
    margin-top: 20px;
    width: 138px !important;
  }

  .Shopping_bossdialog ._addUpload_box>div {
    float: left;
    width: 138px;
    height: 92px;

    border-radius: 2px;
    cursor: pointer;
    padding: 5px;
    margin: 0 10px 10px 0;
    position: relative;
  }

  .Shopping_bossdialog ._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;
  }

  .Shopping_bossdialog ._addUpload_box .icon-guanbi1:hover {
    font-size: 12px;
    color: #c94052;
  }

  /deep/.Shopping_bossdialog ._pic_upload .el-upload-dragger {
    width: 126px !important;
    height: 80px !important;
  }

</style>