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

  .opUl li {
      display: inline-block;
      margin: 10px 15px 10px 0;
  }
  .domesticCommissionUser .opUl li input{
      height: 34px !important;
  }
  .domesticCommissionUser .singeRowTable{
      /* position: absolute; */
  }
  .domesticCommissionUser .singeRowTable tr td {
      padding: 8px 5px;
  }

  .domesticCommissionUser .hoverSpan span:hover {
      cursor: pointer;
      text-decoration: underline;
      color: red;
  }
  .text-fixed{
      /* height: 100%;
      position: absolute;
      left: 0;
      top: 0; */
  }
  .cursor-p{
      cursor: pointer;
  }
  .cursor-p:hover{
      color: #409EFF;
  }
  .ITUDWageMoney-box{
      margin-top: 20px;
      margin-bottom: 10px;
  }
  .ITUDschedule-Box-box{
      display: flex;
      flex-direction: row;
      justify-content: space-between;
  }
  .ITUDschedule-box{
      flex: 1;
      display: flex;
      flex-direction: column;
  }
  .ITUD-title{
      margin-top: 10px;
      margin-bottom: 10px;
  }
  .progress-box{
      flex: 1;
      display: flex;
      flex-direction: row;

  }
  .relative-position{
      flex: 1;
      margin-right: 0;
      position: relative;
  }
  /deep/.relative-position .el-progress-bar__outer{
      border-radius: 0 !important;
  }
  /deep/.relative-position .el-progress-bar__inner{
      border-radius: 0 !important;
  }
  .ITUD-text-box{
      position: relative;
  }
  .ITUD-text{
      position: absolute;
      z-index: 999;
      color: red;
  }
  .rate-box {
      position: absolute;
      top: 30px;
      left: 50%;
      transform: translateX(-50%);
      color: #000;
      z-index: 9;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;

  }
.sanjiao {
    width: 0;
    height: 0;
    margin-left: 5%;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    border-bottom: 3px solid #CACACA;
  }
  .rate {
    min-width: 20px;
    padding: 2px 6px;
    background-color: #CACACA !important;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #666666;
    font-size: 0.62vw;
    font-family: PingFang SC;
    border-radius: 7px;
    line-height:12px;
    white-space:nowrap;
  }
  .active-rate{
    background-color: #FF7262 !important;
    color: #FFFFFF !important;
  }
  .clickCp{
      cursor: pointer;
      color: #2961fe;
  }
</style>
<template>
  <div class="flexOne domesticCommissionUser">
      <div class="productQuerySearch">
          <ul class="opUl">
              <li>
                  <em>{{$t('scen.sc_cp')}}</em>
                  <el-select filterable  size="mini" v-model='msg.OutBranchId'
                  @change='handleCurrentChange(1)' :disabled="disabled">
                  <el-option :label="$t('pub.unlimitedSel')" :value="-1" :key="-1"></el-option>
                  <el-option
                  v-for="item in companyList"
                  :label='item.BName'
                  :value='item.Id'
                  :key='item.Id'
                  ></el-option>
                  </el-select>
              </li>
              <li>
                  <em>{{$t('tips.qishu')}}</em>
                  <el-select v-model="msg.PeriodsId" size="mini" @change="handleCurrentChange(1)" filterable>
                      <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
                      <el-option v-for="(item,index) in PeroidsList" :key="item.index" :label="item.Periods"
                          :value="item.ID"></el-option>
                  </el-select>
              </li>
              <li>
                  <em>{{$t('system.query_company')}}</em>
                  <el-select filterable size="mini" v-model='msg.RB_Branch_Id'
                  @change='getDepartment();handleCurrentChange(1)' :disabled="disabled">
                  <el-option :label="$t('pub.unlimitedSel')" :value="-1" :key="-1"></el-option>
                  <el-option
                  v-for="item in companyList"
                  :label='item.BName'
                  :value='item.Id'
                  :key='item.Id'
                  ></el-option>
                  </el-select>
              </li>

              <li>
                  <em>{{$t('admin.admin_Department')}}</em>
                  <el-select filterable size="mini" v-model='msg.RB_Department_Id'
                  @change='getEmployee();handleCurrentChange(1)'>
                  <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
                  <el-option v-for='item in departmentList'
                      :label='item.DepartmentName'
                      :value='item.DepartmentID'
                      :key='item.DepartmentID'>
                  </el-option>
                  </el-select>
              </li>
              <li>
                  <em>{{$t('salesModule.Personnel')}}</em>
                  <el-select v-model="msg.EmployeeId" size="mini"
                  @change="handleCurrentChange(1)" :disabled="disabled" filterable>
                      <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
                      <el-option :label="$t('objFill.weitu')" :value="-2"></el-option>
                      <el-option v-for="(item,index) in searchList" :key="item.index" :label="item.name"
                          :value="item.empId"></el-option>
                  </el-select>
              </li>


              <li style="position: fixed;right: 0;top: 51px;">
                  <input type="button" class="normalBtn" :value="$t('visa.v_daochu')" @click="exportExcel">
              </li>

          </ul>
      </div>
      <table v-loading="loading" class="singeRowTable" border="0" cellspacing="0" cellpadding="0">
          <tr>
              <th>{{$t('sm.company')}}</th>
              <th>{{$t('admin.admin_Department')}}</th>
              <th>{{$t('objFill.v101.FinancialModule.yuangongxm')}}</th>
              <!-- <th>负责团数</th> -->
              <th>{{$t('objFill.v101.FinancialModule.tuanshujl')}}</th>
              <th width="120">出团公司分摊奖励</th>
              <th>{{$t('objFill.zongticeng')}}</th>
              <th>{{$t('objFill.v101.FinancialModule.chutuangstc')}}</th>
              <th>{{$t('tips.qishu')}}</th>
              <th width="25%">{{$t('system.label_info')}}</th>
              <th>{{$t('system.table_operation')}}</th>
          </tr>
          <tr v-for="item in dataList">
              <td>{{item.BranchName}}</td>
              <td>{{item.DeptName}}</td>
              <td>{{item.UserName}}</td>
              <!-- <td>{{item.PeopleNum?item.PeopleNum:'-'}}</td> -->
              <td>
                <span style="color: #409EFF;cursor: pointer;"
                @click="objNew=item,objNew.PeriodsId=msg.PeriodsId,isRewardDetail=true">
                  {{item.PeopleMoney?item.PeopleMoney:'-'}}
                </span>
                <!-- <span v-else>-</span> -->
              </td>
              <td>{{item.BranchBouns?item.BranchBouns:'-'}}</td>
              <td>{{item.TotalCMoney?item.TotalCMoney:'-'}}</td>
              <td>{{item.BranchCommission?item.BranchCommission:'-'}}</td>
              <td><span class="cursor-p" :style="{'color': '#409EFF'}" @click="openCommissionRate(item.EmployeeId,item.UserName)">{{item.Periods}}</span></td>
              <td>{{item.Description}}</td>
              <td>
                  <el-tooltip class="item" effect="dark" :content="$t('fnc.chakan')" placement="top">
                      <el-button type="primary" class="CM_look" @click="goUrl('OpComPersonDetails',item)"
                          icon="iconfont icon-chakan" circle></el-button>
                  </el-tooltip>


              </td>
          </tr>
      </table>
      <div v-if="dataList.length==0">
        <div style="text-align:center">{{$t('system.content_noData')}}</div>
      </div>
      <!-- 分页 -->
      <el-pagination background @current-change="handleCurrentChange" :current-page.sync="msg.pageIndex"
          layout="total,prev, pager, next, jumper" :page-size='msg.pageSize' :total='total'>
      </el-pagination>
      <RewardDetail v-if="isRewardDetail" :obj="objNew" @close="isRewardDetail=false"></RewardDetail>

      <el-dialog width="1000px" :title="DigName+'-'+$t('objFill.v101.FinancialModule.tichengbil')" :visible.sync="outerVisible" center>
        <div>{{$t('objFill.v101.FinancialModule.zhuyoptcyctrdd')}}</div>
            <div
                class="cm_content"
                style="width: 100%;margin-bottom: 5px; "
            >
                <table
                class="po_content singeRowTable"
                style="border:1px solid #E6E6E6;"
                cellspacing="0"
                cellpadding="0"
                v-loading="loading2">
                <tr>
                    <th>{{$t('ground.yuefen')}}</th>
                    <th>{{$t('advmanager.v_line')}}</th>
                    <th>{{$t('objFill.v101.FinancialModule.weiwangjt')}}</th>
                </tr>
                <tr v-for="item in rateDataList">
                    <td>{{item.Month}}</td>
                    <td>
                        <span v-for="qitem in item.List">
                            {{qitem.LineName}} &nbsp;&nbsp; {{$t('objFill.v101.FinancialModule.tuanshu')}}:{{qitem.TravelNum}} &nbsp;&nbsp; <span v-if="qitem.SinleNum>0">{{$t('objFill.v101.FinancialModule.danxiancp')}}:{{qitem.SinleNum}} &nbsp;&nbsp;</span> {{$t('ground.ljlr')}}:{{qitem.MonthProfit}} &nbsp;&nbsp; {{$t('objFill.v101.FinancialModule.dindangbl')}}:{{qitem.Rate}}% </br>
                        </span>
                    </td>
                    <td>{{item.NoCommissionTCID}}</td>
                </tr>
                <tr v-if="rateDataList.length==0">
                    <td style="text-align:center" colspan="3">{{$t('system.content_noData')}}</td>
                </tr>
                </table>
            </div>
    <div slot="footer" class="dialog-footer">
        <button class="hollowFixedBtn" @click="outerVisible = false">{{$t('pub.cancelBtn')}}</button> &nbsp;
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import moment from "moment"
  import RewardDetail from "./RewardDetail";
  export default {
      components:{
        RewardDetail
      },
      data() {
          return {
              isRewardDetail: false,
              objNew:{},
              outerVisible:false,//提成比例弹窗
              Month: moment().format("YYYY-MM"),
              msg: {
                  pageIndex: 1,
                  pageSize: 20,
                  PeriodsId: -1,
                  EmployeeId: -1,
                  RB_Department_Id: -1,//部门ID
                  RB_Branch_Id: -1,//公司ID
                  OutBranchId: -1,//出团公司ID
              },

              loading: false,
              loading2: false,
              //数据源
              dataList: [],
              total: 0,
              disabled: true,
              PeroidsList:[],
              searchList: [],
              departMentList:[],
              titleList:[
                  {name:this.$t('pub.unlimitedSel'),id:'-1'},
                  {name: this.$t('objfill.yingliu'),id:'2'},
                  {name: this.$t('visat.sale'),id:'1'}
              ],
              departmentList:[],
              companyList: [],
              getCompanyMsg:{
                  RB_Group_Id:'0',
                  Status:'0',
              },
              departmentMsg: {
        RB_Group_Id: '0',
        RB_Branch_Id:'0',
        Status:'0',
        ParentId:'-1',
        Tier:'0',
              },
              disabled:true,
              rateDataList: [],
                DigName:''
          }
      },
      created(){
          let userInfo = this.getLocalStorage();
          this.getCompanyMsg.RB_Group_Id=userInfo.RB_Group_id;    //集团ID
          this.departmentMsg.RB_Group_Id = userInfo.RB_Group_id; //集团
          this.departmentMsg.RB_Branch_Id = userInfo.RB_Branch_Id;

      },
      mounted() {
          let userInfo = this.getLocalStorage();
          let ActionMenuCode = userInfo.ActionMenuCode;

          this.msg.PeriodsId = this.$route.query.PeriodId?Number(this.$route.query.PeriodId):-1
          // this.msg.OutBranchId = this.$route.query.RB_Branch_Id?Number(this.$route.query.RB_Branch_Id):Number(userInfo.RB_Branch_id)
          // this.msg.EmployeeId = this.$route.query.UserId?Number(this.$route.query.UserId):Number(userInfo.EmployeeId)
          if (ActionMenuCode.indexOf('S_CheckBranchOrder') != -1
          ||ActionMenuCode.indexOf('S_CheckAllOrder')!=-1
          ||ActionMenuCode.indexOf('F_Query_AllIncomPay')!=-1) {//是否有看所有人的权限
              this.disabled = false;
              this.msg.OutBranchId = this.$route.query.OutBranchId?Number(this.$route.query.OutBranchId):-1
              // this.msg.RB_Branch_Id = -1
              this.msg.RB_Branch_Id = this.$route.query.RB_Branch_Id?Number(this.$route.query.RB_Branch_Id):-1
              // this.msg.RB_Department_Id = -1
              this.msg.EmployeeId = this.$route.query.UserId?Number(this.$route.query.UserId):-1
          }else{
              this.disabled = true;
              this.msg.OutBranchId = this.$route.query.OutBranchId?Number(this.$route.query.OutBranchId):-1
              this.msg.RB_Branch_Id = this.$route.query.RB_Branch_Id?Number(this.$route.query.RB_Branch_Id):Number(userInfo.RB_Branch_id)
              this.msg.EmployeeId = this.$route.query.UserId?Number(this.$route.query.UserId):Number(userInfo.EmployeeId)
          }
          this.GetCommissionPeroidsList()//期数
          this.getEmployee()//人员
          this.getDepartment()
          this.getCompany()

      },
      methods: {
          getDepartment() {
              this.departmentMsg.RB_Branch_Id = this.msg.RB_Branch_Id
      this.apipost('admin_get_DepartmentGetList', this.departmentMsg, res => {
        if(res.data.resultCode == 1) {
          this.departmentList = res.data.data;
        }
      }, err => {})

    },
          getCompany(){
              this.apipost('admin_get_BranchGetList',this.getCompanyMsg,res=>{
                  if(res.data.resultCode==1){
                      this.companyList=res.data.data;
                  }else{}
              },err=>{})
          },
          GetCommissionPeroidsList() { //期数下拉
              this.apipost(
                  "opcommission_GetNewOPCommissionPeroidsList",{},res => {
                  if (res.data.resultCode == 1) {
                      this.PeroidsList = res.data.data;
                      if(!this.$route.query.PeriodId){
                          this.msg.PeriodsId = this.PeroidsList[0].ID
                      }
                      this.getList()
                  } else {
                      this.Error(res.data.message);
                  }
                  }
              );
          },
          getEmployee() {//所有人员下拉
              let employeeMsg = {
                  RB_Group_id: "0",
                  RB_Branch_id: "-1",
                  departmentId: this.msg.RB_Department_Id>1?this.msg.RB_Department_Id:"0",
                  IsLeave: "-1"
              }
              this.apipost(
                  "app_get_company_employee",
                  employeeMsg,
                  res => {
                      if (res.data.resultCode == 1) {
                          this.searchList = res.data.data;
                      }
                  },
                  err => { }
              );
          },

          handleCurrentChange(val) {
              this.msg.pageIndex = val;
              this.getList();
          },
          goUrl(path, item) {
              this.$router.push({
                  path: path,
                  query: {
                      PeriodId: this.$route.query.PeriodId,
                    //   OutBranchId: item.RB_Branch_Id,
                      UserId: item.EmployeeId,
                      blank: 'y',
                      tab: '同业提现详情'
                  }
              });
          },
          //获取数据
          getList() {
              this.loading = true;
              this.apipost(
                  "opcommission_GetNewOPCommissionEmpPageList",
                  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
              );
          },
          exportExcel() { //导出
              let msg = JSON.parse(JSON.stringify(this.msg))
              let userInfo = this.getLocalStorage();
              msg.EmployeeIdUser = userInfo.EmployeeId
              var fileName = this.$t('objFill.v101.FinancialModule.opticfzb')+".xls";
              this.GetLocalFile("opcommission_GetNewOPCommissionEmpListToExcel", msg, fileName);
          },
          openCommissionRate(userId,name){
                this.DigName = name;
                this.outerVisible = true;
                this.getCommissionRateData(userId);
            },
            getCommissionRateData(userId){
                this.loading2 = true;
                this.apipost(
                    "opcommission_GetOPCommissionGrade",
                    {UserId : userId},
                    res => {
                        this.loading2 = false;
                        if (res.data.resultCode == 1) {
                            this.rateDataList = res.data.data;
                        } else {
                            this.Error(res.data.message);
                        }
                    },
                    null
                );
            }
      }
  }
</script>