<style>
  .CM_look {
    padding: 4px !important;
    position: relative;
    top: 1px;
  }

</style>
<template>
  <div class="flexOne">
    <div class="query-box">
      <ul>
        <li>
          <em>{{$t('scen.sc_cp')}}</em>
          <!-- S_CheckBranchOrder -->
          <el-select v-model="msg.OutBranchId" size="mini" @change="getList(1)"
          :disabled="false">
              <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
              <el-option v-for="(item,index) in BranchList" :key="item.index" :label="item.BName"
                  :value="item.Id"></el-option>
          </el-select>
      </li>
        <li>
          <input v-if="IsAuth==1" type="button" class="normalBtn" @click="CreateAirticketCommission()" :value="$t('objFill.v101.administrative.shenchengtcbb')" :disabled="isDisable"  />
        </li>
      </ul>
    </div>
    <table class="singeRowTable" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
      <tr>
        <th>{{$t('tips.qishu')}}</th>
        <th>{{$t('objFill.v101.administrative.ticehngzje')}}</th>
        <th>{{$t('objFill.v101.administrative.suoshugstc')}}</th>
        <th>{{$t('hotel.hotel_Order')}}</th>
        <th>{{$t('admin.admin_czPerson')}}</th>
        <th>{{$t('sm.Date')}}</th>
        <th>{{$t('system.table_operation')}}</th>
      </tr>
      <tr v-for="(item,index) in dataList" :key="index">
        <td>{{item.Periods}}</td>
        <td>{{item.SumPrice}}</td>
        <td>
          <template v-if="item.BranchCommission">
            {{item.BranchCommission}}
          </template>
        </td>
        <td>
          <template v-if="item.FinanceIdList">
            <span v-for="(x,y) in item.FinanceIdList" >
              <span style="cursor: pointer;text-decoration: underline;" @click='gofinancialdetail(x)'>
                  {{x}}
              </span>
              {{item.FinanceIdList.length == y+1 ?'':'、'}}
            </span>
          </template>
        </td>
        <td>{{item.CreateByName}}</td>
        <td>{{item.CreateTimeStr}}</td>
        <td>
          <el-tooltip class="item" effect="dark" :content="$t('fnc.chakan')" placement="top">
            <el-button type="primary" class="CM_look" @click="goUrl('AirticketCommissionDetail',item.ID)"
              icon="iconfont icon-chakan" circle></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="$t('objFill.preparedocument')" placement="top">
            <el-button type="primary" class="CM_look" @click="goUrlZD(item)" icon="iconfont icon-caidan-fill" circle></el-button>
          </el-tooltip>
        </td>
      </tr>
    </table>
    <!-- 分页 -->
    <el-pagination background @current-change="handleCurrentChange" :current-page.sync="currentPage"
      layout="total,prev, pager, next, jumper" :page-size='msg.PageSize' :total='total'>
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        BranchList: [],
        msg: {
          PageIndex: 1,
          PageSize: 20,
          OutBranchId: -1
        },
        loading: false,
        //数据源
        dataList: [],
        total: 0,
        currentPage: 1,
        isDisable:false,
        IsAuth:0,//生成票务提成权限
      }
    },
    mounted() {
      this.getCompanyList()
      this.GetAuth();
      this.getList();
    },
    methods: {
      gofinancialdetail(item){
          let arr = item.split('-')
          this.$router.push({
              name: 'FinancialDocumentsDetail',
              query: {
              id: arr[0],
              blank: 'y',
              tab: '单据详情'
              }
          })
      },
      //初始化公司
      getCompanyList() {
        let userInfo = this.getLocalStorage();
        var RB_Group_id = userInfo.RB_Group_id;
        let msg = {
            Status: 0,
            is_show: 0,
            RB_Group_Id: RB_Group_id
        };
        this.apipost(
          "admin_get_BranchGetList",
          msg,
          res => {
              if (res.data.resultCode == 1) {
                  this.BranchList = res.data.data;

              }
          },
          err => { }
        );
      },
      goUrlZD(item){
        let Money = item.BranchCommission
        if(this.msg.OutBranchId==-1){
          this.Error(this.$t('objFill.v101.administrative.qingxzctgzzzd'))
          return;
        }
        if(Money<=0){
          this.Error(this.$t('objFill.v101.administrative.shuosgstcsnbnzd'))
          return;
        }
        let orderObj = {
          isRB_Branch_Id: true,//制单禁止选公司
          RB_Branch_Id: this.msg.OutBranchId,
          OtherType: 78,
          ReFinanceId: item.Periods,
          OrderID: 0,
          OrderSource: 8,
          Obj: {},
          SourceID: 0,
          CostType:112,//194
          SelectState:true,
        }
        let id=[29,31];
        this.$router.push({
            name: 'ChoiceAddFinancialDocuments',
            query: {
              Type: 2,
              templateID: JSON.stringify(id),
              'blank': 'y',
              'orderObj': JSON.stringify(orderObj)
            }
          })
      },
      handleCurrentChange(val) {
        this.msg.PageIndex = val;
        this.getList();
      },
      goUrl(path, id) {
        this.$router.push({
          path: path,
          query: {
            ID: id,
            blank: 'y',
            tab: '票务业绩详情'
          }
        });
      },
      //获取数据
      getList(PageIndex) {
        if(PageIndex){
          this.msg.PageIndex = PageIndex
        }
        this.loading = true;
        this.apipost(
          "AirTicketRules_post_GetAirticketCommissionPageList",
          this.msg,
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.total = res.data.data.count;
            } else {
              this.Error(res.data.message);
            }
          },
          null
        );
      },
       GetAuth() {
        this.apipost('AirTicketRules_post_CreateAirticketCommissionAuthService', {}, res => {
          if (res.data.resultCode == 1) {
            this.IsAuth = res.data.data;
          } else {
            this.$message.error(res.data.message);
          }
        }, err => {})
      },
      //生成票务提成报表
      CreateAirticketCommission() {
        this.loading=true;
        this.isDisable=true;
        this.apipost(
          "AirTicketRules_post_CreateAirticketCommissionService", {},
          res => {
            this.loading=false;
            this.isDisable=false;
            if (res.data.resultCode == 1) {
              this.getList();
              this.Success(this.$t('objFill.v101.administrative.baobiaosccg'))
            } else {
              this.Error(res.data.message);
            }
          },
          null
        );
      }
    }
  }
</script>
